org.apache.brooklyn.util.collections.MutableMap Java Examples

The following examples show how to use org.apache.brooklyn.util.collections.MutableMap. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CouchDBNodeLiveTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
@Test(groups = "Live", dataProvider = "virtualMachineData")
protected void testOperatingSystemProvider(String imageId, String provider, String region, String description) throws Exception {
    log.info("Testing CouchDB on {}{} using {} ({})", new Object[] { provider, Strings.isNonEmpty(region) ? ":" + region : "", description, imageId });

    Map<String, String> properties = MutableMap.of("imageId", imageId);
    Location testLocation = app.getManagementContext().getLocationRegistry()
            .getLocationManaged(provider + (Strings.isNonEmpty(region) ? ":" + region : ""), properties);

    CouchDBNode couchdb = app.createAndManageChild(EntitySpec.create(CouchDBNode.class)
            .configure("httpPort", "12345+")
            .configure("clusterName", "TestCluster"));
    app.start(ImmutableList.of(testLocation));
    EntityAsserts.assertAttributeEqualsEventually(couchdb, Startable.SERVICE_UP, true);

    JcouchdbSupport jcouchdb = new JcouchdbSupport(couchdb);
    jcouchdb.jcouchdbTest();
}
 
Example #2
Source File: TomcatSshDriver.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
@Override
public void launch() {
    Map<String, Integer> ports = MutableMap.of("httpPort", getHttpPort(), "shutdownPort", getShutdownPort());
    Networking.checkPortsValid(ports);

    // We wait for evidence of tomcat running because, using SshCliTool,
    // we saw the ssh session return before the tomcat process was fully running 
    // so the process failed to start.
    newScript(MutableMap.of(USE_PID_FILE, false), LAUNCHING)
            .body.append(
                    "mv "+getLogFileLocation()+" "+getLogFileLocation()+"-$(date +\"%Y%m%d.%H%M.%S\").log || true",
                    format("%s/bin/startup.sh >>$RUN/console 2>&1 </dev/null",getExpandedInstallDir()),
                    BashCommands.waitForFileExists(getLogFileLocation(), Duration.TEN_SECONDS, false)
                )
            .execute();
}
 
Example #3
Source File: WebAppRunnerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testStartSecondaryWar() throws Exception {
    TestResourceUnavailableException.throwIfResourceUnavailable(getClass(), "/hello-world.war");

    BrooklynWebServer server = createWebServer(
        MutableMap.of("port", "8091+", "war", null, "wars", MutableMap.of("hello", "hello-world.war")) );
    assertNotNull(server);
    
    try {
        server.start();

        assertRootPageAvailableAt("http://localhost:"+server.getActualPort()+"/");
        HttpAsserts.assertContentEventuallyContainsText("http://localhost:"+server.getActualPort()+"/hello",
            "This is the home page for a sample application");

    } finally {
        server.stop();
    }
}
 
Example #4
Source File: BasicTaskExecutionTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void runMultipleBasicTasks() throws Exception {
    data.put(1, 1);
    BasicExecutionManager em = new BasicExecutionManager("mycontext");
    for (int i = 0; i < 2; i++) {
        em.submit(MutableMap.of("tag", "A"), new BasicTask<Integer>(newIncrementCallable(1)));
        em.submit(MutableMap.of("tag", "B"), new BasicTask<Integer>(newIncrementCallable((1))));
    }
    int total = 0;
    for (Object tag : em.getTaskTags()) {
            log.debug("tag {}", tag);
            for (Task<?> task : em.getTasksWithTag(tag)) {
                log.debug("BasicTask {}, has {}", task, task.get());
                total += (Integer)task.get();
            }
        }
    assertEquals(10, total);
    //now that all have completed:
    assertEquals(5, data.get(1));
}
 
Example #5
Source File: DependentConfiguration.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
/** 
 * Method which returns a Future containing an escaped URL string (see {@link Urls#encode(String)}).
 * The arguments can be normal objects, tasks or {@link DeferredSupplier}s.
 * tasks will be waited on (submitted if necessary) and their results substituted.
 */
@SuppressWarnings("unchecked")
public static Task<String> urlEncode(final Object arg) {
    List<TaskAdaptable<Object>> taskArgs = Lists.newArrayList();
    if (arg instanceof TaskAdaptable) taskArgs.add((TaskAdaptable<Object>)arg);
    else if (arg instanceof TaskFactory) taskArgs.add( ((TaskFactory<TaskAdaptable<Object>>)arg).newTask() );
    
    return transformMultiple(
            MutableMap.<String,String>of("displayName", "url-escaping '"+arg), 
            new Function<List<Object>, String>() {
                @Override
                @Nullable
                public String apply(@Nullable List<Object> input) {
                    Object resolvedArg;
                    if (arg instanceof TaskAdaptable || arg instanceof TaskFactory) resolvedArg = Iterables.getOnlyElement(input);
                    else if (arg instanceof DeferredSupplier) resolvedArg = ((DeferredSupplier<?>) arg).get();
                    else resolvedArg = arg;
                    
                    if (resolvedArg == null) return null;
                    String resolvedString = resolvedArg.toString();
                    return Urls.encode(resolvedString);
                }
            },
            taskArgs);
}
 
Example #6
Source File: SanitizerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testSanitize() throws Exception {
    Map<String, Object> map = ImmutableMap.<String, Object>builder()
            .put("PREFIX_password_SUFFIX", "pa55w0rd")
            .put("PREFIX_PASSWORD_SUFFIX", "pa55w0rd")
            .put("PREFIX_passwd_SUFFIX", "pa55w0rd")
            .put("PREFIX_credential_SUFFIX", "pa55w0rd")
            .put("PREFIX_secret_SUFFIX", "pa55w0rd")
            .put("PREFIX_private_SUFFIX", "pa55w0rd")
            .put("PREFIX_access.cert_SUFFIX", "myval")
            .put("PREFIX_access.key_SUFFIX", "myval")
            .put("mykey", "myval")
            .build();
    Map<String, Object> expected = MutableMap.<String, Object>builder()
            .putAll(Maps.transformValues(map, Functions.constant("xxxxxxxx")))
            .put("mykey", "myval")
            .build();
    
    Map<String, Object> sanitized = Sanitizer.sanitize(ConfigBag.newInstance(map));
    assertEquals(sanitized, expected);
    
    Map<String, Object> sanitized2 = Sanitizer.sanitize(map);
    assertEquals(sanitized2, expected);
}
 
Example #7
Source File: RebindJmxFeedTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected void runJmxFeedIsPersisted(boolean preCreateJmxHelper) throws Exception {
    TestEntity origEntity = origApp.createAndManageChild(EntitySpec.create(TestEntity.class).impl(MyEntityWithJmxFeedImpl.class)
            .configure(MyEntityWithJmxFeedImpl.PRE_CREATE_JMX_HELPER, preCreateJmxHelper));
    origApp.start(ImmutableList.<Location>of());
    
    jmxService = new JmxService(origEntity);
    GeneralisedDynamicMBean mbean = jmxService.registerMBean(MutableMap.of(JMX_ATTRIBUTE_NAME, "myval"), OBJECT_NAME);
    
    EntityAsserts.assertAttributeEqualsEventually(origEntity, SENSOR_STRING, "myval");
    assertEquals(origEntity.feeds().getFeeds().size(), 1);

    newApp = rebind();
    TestEntity newEntity = (TestEntity) Iterables.getOnlyElement(newApp.getChildren());
    
    Collection<Feed> newFeeds = newEntity.feeds().getFeeds();
    assertEquals(newFeeds.size(), 1);
    
    // Expect the feed to still be polling
    newEntity.sensors().set(SENSOR_STRING, null);
    EntityAsserts.assertAttributeEqualsEventually(newEntity, SENSOR_STRING, "myval");
}
 
Example #8
Source File: SimpleJcloudsLocationUserLoginAndConfigLiveTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
@Test(groups="Live")
public void testJcloudsWithSpecificLoginUserAndNewUser() throws Exception {
    log.info("TEST testJcloudsWithSpecificLoginUserAndNewUser");
    JcloudsSshMachineLocation m1 = obtainMachine(MutableMap.of(
            "imageId", EC2_CENTOS_IMAGE,
            "loginUser", "ec2-user",
            "user", "newbob",
            "waitForSshable", 30*1000));

    Map details = MutableMap.of("id", m1.getJcloudsId(), "hostname", m1.getAddress().getHostAddress(), "user", m1.getUser());
    log.info("got machine "+m1+" at "+jcloudsLocation+": "+details+"; now trying to rebind");
    String result;
    // echo conflates spaces of arguments
    result = execWithOutput(m1, Arrays.asList("echo trying  m1", "hostname", "date"));
    Assert.assertTrue(result.contains("trying m1"));
    
    log.info("now trying rebind "+m1);
    JcloudsSshMachineLocation m2 = (JcloudsSshMachineLocation) jcloudsLocation.registerMachine(details);
    result = execWithOutput(m2, Arrays.asList("echo trying  m2", "hostname", "date"));
    Assert.assertTrue(result.contains("trying m2"));
    
    Assert.assertEquals(m2.getUser(), "newbob");
}
 
Example #9
Source File: AbstractWebAppFixtureIntegrationTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
/**
 * Checks an entity can start, set SERVICE_UP to true and shutdown again.
 */
@Test(groups = "Integration", dataProvider = "basicEntities")
public void testReportsServiceDownWhenKilled(final SoftwareProcess entity) throws Exception {
    this.entity = entity;
    log.info("test=testReportsServiceDownWithKilled; entity="+entity+"; app="+entity.getApplication());
    
    Entities.start(entity.getApplication(), ImmutableList.of(loc));
    EntityAsserts.assertAttributeEqualsEventually(MutableMap.of("timeout", 120*1000), entity, Startable.SERVICE_UP, true);

    // Stop the underlying entity, but without our entity instance being told!
    killEntityBehindBack(entity);
    log.info("Killed {} behind mgmt's back, waiting for service up false in mgmt context", entity);
    
    EntityAsserts.assertAttributeEqualsEventually(entity, Startable.SERVICE_UP, false);
    
    log.info("success getting service up false in primary mgmt universe");
}
 
Example #10
Source File: AbstractWebAppFixtureIntegrationTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
@Test(groups = "Integration", dataProvider = "entitiesWithWarAndURL")
public void initialNamedWarDeployments(final SoftwareProcess entity, final String war, 
        final String urlSubPathToWebApp, final String urlSubPathToPageToQuery) {
    this.entity = entity;
    log.info("test=initialNamedWarDeployments; entity="+entity+"; app="+entity.getApplication());
    
    URL resource = getClass().getClassLoader().getResource(war);
    assertNotNull(resource);
    
    entity.config().set(JavaWebAppService.NAMED_WARS, ImmutableList.of(resource.toString()));
    Entities.start(entity.getApplication(), ImmutableList.of(loc));

    Asserts.succeedsEventually(MutableMap.of("timeout", 60*1000), new Runnable() {
        @Override
        public void run() {
            // TODO get this URL from a WAR file entity
            HttpTestUtils.assertHttpStatusCodeEquals(Urls.mergePaths(entity.getAttribute(WebAppService.ROOT_URL), urlSubPathToWebApp, urlSubPathToPageToQuery), 200);
        }});
}
 
Example #11
Source File: AbstractWebAppFixtureIntegrationTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
/**
 * Checks an entity can start, set SERVICE_UP to true and shutdown again.
 */
@Test(groups = "Integration", dataProvider = "basicEntities")
public void canStartAndStop(final SoftwareProcess entity) {
    this.entity = entity;
    log.info("test=canStartAndStop; entity="+entity+"; app="+entity.getApplication());
    
    Entities.start(entity.getApplication(), ImmutableList.of(loc));
    EntityAsserts.assertAttributeEqualsEventually(
            MutableMap.of("timeout", 120*1000), entity, Startable.SERVICE_UP, Boolean.TRUE);
    entity.stop();
    assertFalse(entity.getAttribute(Startable.SERVICE_UP));
}
 
Example #12
Source File: SoftLayerSameVlanLocationCustomizer.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new {@link CountDownLatch} and optionally the {@link #COUNTDOWN_LATCH_MAP map}
 * for a scope.
 *
 * @return The latch for the scope that is stored in the map.
 */
protected CountDownLatch createCountDownLatch(JcloudsLocation location, String scopeUid) {
    synchronized (lock) {
        Map<String, CountDownLatch> map = MutableMap.copyOf(location.config().get(COUNTDOWN_LATCH_MAP));
        if (!map.containsKey(scopeUid)) {
            map.put(scopeUid, new CountDownLatch(1));
            saveAndPersist(location, COUNTDOWN_LATCH_MAP, map);
        }
        return map.get(scopeUid);
    }
}
 
Example #13
Source File: EnrichersYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void checkReferences(final Enricher enricher, Map<ConfigKey<Entity>, Entity> keyToEntity) throws Exception {
    for (final ConfigKey<Entity> key : keyToEntity.keySet()) {
        final Entity entity = keyToEntity.get(key); // Grab an entity whose execution context we can use
        Entity fromConfig = ((EntityInternal)entity).getExecutionContext().submit(MutableMap.of(), new Callable<Entity>() {
            @Override
            public Entity call() throws Exception {
                return enricher.getConfig(key);
            }
        }).get();
        Assert.assertEquals(fromConfig, keyToEntity.get(key));
    }
}
 
Example #14
Source File: SshMachineLocationReuseIntegrationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public Map<String, Object> customSshConfigKeys() throws UnknownHostException {
    return MutableMap.<String, Object>of(
            "address", Networking.getReachableLocalHost(),
            SshTool.PROP_SESSION_TIMEOUT.getName(), 20000,
            SshTool.PROP_CONNECT_TIMEOUT.getName(), 50000,
            SshTool.PROP_SCRIPT_HEADER.getName(), "#!/bin/bash");
}
 
Example #15
Source File: ActiveMQSshDriver.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String, String> getShellEnvironment() {
    return MutableMap.<String,String>builder()
            .putAll(super.getShellEnvironment())
            .put("ACTIVEMQ_HOME", getRunDir())
            .put("ACTIVEMQ_PIDFILE", getPidFile())
            .renameKey("JAVA_OPTS", "ACTIVEMQ_OPTS")
            .build();
}
 
Example #16
Source File: MapConfigKeyAndFriendsMoreTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public void testMapManyWays() throws Exception {
    entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_MAP_OBJ_THING.getName()), ImmutableMap.<String,Object>of("map", 1, "subkey", 0, "dotext", 0));
    entity.config().set(ConfigKeys.newConfigKey(Object.class, TestEntity.CONF_MAP_OBJ_THING.getName()+".dotext"), 1);
    entity.config().set(TestEntity.CONF_MAP_OBJ_THING.subKey("subkey"), 1);
    
    log.info("Map-ManyWays: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig()));
    Assert.assertEquals(entity.getConfig(TestEntity.CONF_MAP_OBJ_THING), ImmutableMap.<String,Object>of("map", 1, "subkey", 1, "dotext", 1));
}
 
Example #17
Source File: JavaWebAppsMatchingTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
public void testExampleFunctionsYamlMatch() throws IOException {
    Reader input = Streams.reader(new ResourceUtils(this).getResourceFromUrl("example-with-function.yaml"));
    
    DeploymentPlan plan = platform.pdp().parseDeploymentPlan(input);
    log.info("DP is:\n"+plan.toString());
    Map<?,?> cfg1 = (Map<?, ?>) plan.getServices().get(0).getCustomAttributes().get(BrooklynCampReservedKeys.BROOKLYN_CONFIG);
    Map<?,?> cfg = MutableMap.copyOf(cfg1);
    
    Assert.assertEquals(cfg.remove("literalValue1"), "$brooklyn: is a fun place");
    Assert.assertEquals(cfg.remove("literalValue2"), "$brooklyn: is a fun place");
    Assert.assertEquals(cfg.remove("literalValue3"), "$brooklyn: is a fun place");
    Assert.assertEquals(cfg.remove("literalValue4"), "$brooklyn: is a fun place");
    Assert.assertEquals(cfg.remove("$brooklyn:1"), "key to the city");
    Assert.assertTrue(cfg.isEmpty(), ""+cfg);

    Assert.assertEquals(plan.getName(), "example-with-function");
    Assert.assertEquals(plan.getCustomAttributes().get("location"), "localhost");
    
    AssemblyTemplate at = platform.pdp().registerDeploymentPlan(plan);
    
    Assert.assertEquals(at.getName(), "example-with-function");
    Assert.assertEquals(at.getCustomAttributes().get("location"), "localhost");
    
    PlatformComponentTemplate pct = at.getPlatformComponentTemplates().links().iterator().next().resolve();
    Object cfg2 = pct.getCustomAttributes().get(BrooklynCampReservedKeys.BROOKLYN_CONFIG);
    Assert.assertEquals(cfg2, cfg1);
}
 
Example #18
Source File: EntitiesYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testEntityWithConfigurableInitializerEmpty() throws Exception {
    String yaml =
            "services:\n"+
            "- type: "+TestEntity.class.getName()+"\n"+
            "  brooklyn.initializers: [ { type: "+TestSensorAndEffectorInitializer.TestConfigurableInitializer.class.getName()+" } ]";
    
    Application app = (Application) createStartWaitAndLogApplication(yaml);
    TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
    
    Task<String> saying = entity.invoke(Effectors.effector(String.class, TestSensorAndEffectorInitializer.EFFECTOR_SAY_HELLO).buildAbstract(), 
        MutableMap.of("name", "Bob"));
    Assert.assertEquals(saying.get(Duration.TEN_SECONDS), "Hello Bob");
}
 
Example #19
Source File: ServiceCharacteristic.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static ServiceCharacteristic of(Map<String, Object> req) {
    Map<String,Object> attrs = MutableMap.copyOf(req);
    
    ServiceCharacteristic result = new ServiceCharacteristic();
    result.name = (String) attrs.remove("name");
    result.description = (String) attrs.remove("description");
    result.characteristicType = (String) Yamls.removeMultinameAttribute(attrs, "characteristicType", "type");
    
    // TODO fulfillment
    
    result.customAttributes = attrs;
    
    return result;
}
 
Example #20
Source File: BasicTaskExecutionTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void runSimpleBasicTask() throws Exception {
    BasicTask<Object> t = new BasicTask<Object>(newPutCallable(1, "b"));
    data.put(1, "a");
    Task<Object> t2 = em.submit(MutableMap.of("tag", "A"), t);
    assertEquals("a", t.get());
    assertEquals("a", t2.get());
    assertEquals("b", data.get(1));
}
 
Example #21
Source File: JcloudsImageChoiceStubbedLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups={"Live", "Live-sanity"})
@SuppressWarnings("deprecation")
public void testJcloudsCreateWithNulls() throws Exception {
    obtainMachine(MutableMap.builder()
            .put(JcloudsLocationConfig.IMAGE_ID, "DEBIAN_8_64")
            .put(JcloudsLocationConfig.MIN_RAM, null)
            .put(JcloudsLocationConfig.MIN_CORES, null)
            .put(JcloudsLocationConfig.MIN_DISK, null)
            .put(JcloudsLocationConfig.HARDWARE_ID, null)
            .put(JcloudsLocationConfig.OS_64_BIT, null)
            .put(JcloudsLocationConfig.OS_FAMILY, null)
            .put(JcloudsLocationConfig.IMAGE_DESCRIPTION_REGEX, null)
            .put(JcloudsLocationConfig.IMAGE_NAME_REGEX, null)
            .put(JcloudsLocationConfig.OS_VERSION_REGEX, null)
            .put(JcloudsLocationConfig.SECURITY_GROUPS, null)
            .put(JcloudsLocationConfig.INBOUND_PORTS, null)
            .put(JcloudsLocationConfig.USER_METADATA_STRING, null)
            .put(JcloudsLocationConfig.STRING_TAGS, null)
            .put(JcloudsLocationConfig.USER_METADATA_MAP, null)
            .put(JcloudsLocationConfig.EXTRA_PUBLIC_KEY_DATA_TO_AUTH, null)
            .put(JcloudsLocationConfig.RUN_AS_ROOT, null)
            .put(JcloudsLocationConfig.LOGIN_USER, null)
            .put(JcloudsLocationConfig.LOGIN_USER_PASSWORD, null)
            .put(JcloudsLocationConfig.LOGIN_USER_PRIVATE_KEY_FILE, null)
            .put(JcloudsLocationConfig.KEY_PAIR, null)
            .put(JcloudsLocationConfig.AUTO_GENERATE_KEYPAIRS, null)
            .put(JcloudsLocationConfig.AUTO_ASSIGN_FLOATING_IP, null)
            .put(JcloudsLocationConfig.NETWORK_NAME, null)
            .put(JcloudsLocationConfig.DOMAIN_NAME, null)
            .put(JcloudsLocationConfig.TEMPLATE_OPTIONS, null)
            .build());
    assertEquals(template.getImage().getId(), "DEBIAN_8_64", "template="+template);
}
 
Example #22
Source File: AbstractHostNodeTemplate.java    From SeaCloudsPlatform with Apache License 2.0 5 votes vote down vote up
public Map<String, Object> getLocationPolicyGroupValues() {
    Map<String, Object> policyGroupValues = MutableMap.of();
    policyGroupValues.put(MEMBERS, Arrays.asList(nodeTemplateId));

    ArrayList<Map<String, Object>> policyList = new ArrayList<>();
    policyList.add(getLocationPolicyProperties());
    policyGroupValues.put(POLICIES, policyList);
    return policyGroupValues;
}
 
Example #23
Source File: RebindContextImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public Map<String,BrooklynObject> getAllBrooklynObjects() {
    MutableMap<String,BrooklynObject> result = MutableMap.of();
    result.putAll(locations);
    result.putAll(entities);
    result.putAll(policies);
    result.putAll(enrichers);
    result.putAll(feeds);
    result.putAll(catalogItems);
    result.putAll(bundles);
    return result.asUnmodifiable();
}
 
Example #24
Source File: SoftwareProcessSshDriverIntegrationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testRuntimeResourcesCopy() throws IOException {
    localhost.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath());
    File template = new File(tempDataDir, "template.yaml");
    VanillaSoftwareProcess entity = app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
            .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "")
            .configure(SoftwareProcess.RUNTIME_FILES, MutableMap.of("classpath://org/apache/brooklyn/entity/software/base/frogs.txt", "frogs.txt"))
            .configure(SoftwareProcess.RUNTIME_TEMPLATES, MutableMap.of("classpath://org/apache/brooklyn/entity/software/base/template.yaml", template.getAbsolutePath()))
            .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "date"));
    app.start(ImmutableList.of(localhost));

    File frogs = new File(entity.getAttribute(SoftwareProcess.RUN_DIR), "frogs.txt");
    assertExcerptFromTheFrogs(frogs);
    assertTemplateValues(template);
}
 
Example #25
Source File: DslParseComponentsTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public Object parseDslExpression(String input) {
    String s1 = Yamls.getAs( Yamls.parseAll( Streams.reader(Streams.newInputStreamWithContents(input)) ), String.class );
    BasicCampPlatform p = new BasicCampPlatform();
    p.pdp().addInterpreter(new BrooklynDslInterpreter());
    Object out = p.pdp().applyInterpreters(MutableMap.of("key", s1)).get("key");
    log.debug("parsed "+input+" as "+out+" ("+(out==null ? "null" : out.getClass())+")");
    return out;
}
 
Example #26
Source File: ProcessTool.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public ProcessTool(Map<String,?> flags) {
    super(getOptionalVal(flags, PROP_LOCAL_TEMP_DIR));
    if (flags!=null) {
        MutableMap<String, Object> flags2 = MutableMap.copyOf(flags);
        // TODO should remember other flags here?  (e.g. NO_EXTRA_OUTPUT, RUN_AS_ROOT, etc)
        flags2.remove(PROP_LOCAL_TEMP_DIR.getName());
        if (!flags2.isEmpty())
            LOG.warn(""+this+" ignoring unsupported constructor flags: "+flags);
    }
}
 
Example #27
Source File: SshCommandEffectorIntegrationTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testSshEffector() throws Exception {
    new SshCommandEffector(ConfigBag.newInstance()
            .configure(SshCommandEffector.EFFECTOR_NAME, "sayHi")
            .configure(SshCommandEffector.EFFECTOR_COMMAND, "echo hi"))
        .apply(entity);
    
    String val = entity.invoke(EFFECTOR_SAY_HI, MutableMap.<String,String>of()).get();
    Assert.assertEquals(val.trim(), "hi", "val="+val);
}
 
Example #28
Source File: DynamicWebAppClusterImpl.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
static boolean removeFromWarsByContext(Entity entity, String targetName) {
    targetName = FILENAME_TO_WEB_CONTEXT_MAPPER.convertDeploymentTargetNameToContext(targetName);
    // TODO a better way to do atomic updates, see comment above
    synchronized (entity) {
        Map<String,String> newWarsMap = MutableMap.copyOf(entity.getConfig(WARS_BY_CONTEXT));
        String url = newWarsMap.remove(targetName);
        if (url==null) {
            return false;
        }
        entity.config().set(WARS_BY_CONTEXT, newWarsMap);
        return true;
    }
}
 
Example #29
Source File: LinkDtoTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomAttrs() throws IOException {
    LinkDto l = LinkDto.newInstance("http://foo", "Foo", MutableMap.of("bar", "bee"));
    
    JsonNode t = BasicDtoTest.tree(l);
    Assert.assertEquals(t.size(), 3);
    Assert.assertEquals(t.get("href").asText(), l.getHref());
    Assert.assertEquals(t.get("targetName").asText(), l.getTargetName());
    Assert.assertEquals(t.get("bar").asText(), l.getCustomAttributes().get("bar"));
    
    Assert.assertEquals(l, new ObjectMapper().readValue(t.toString(), LinkDto.class));
}
 
Example #30
Source File: MapConfigKeyAndFriendsMoreTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testSetEmpty() throws Exception {
    // ensure it is null before we pass something in, and passing an empty collection makes it be empty
    log.info("Set-Empty-1: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig()));
    Assert.assertEquals(entity.getConfig(TestEntity.CONF_SET_THING), null);
    entity.config().set((SetConfigKey)TestEntity.CONF_SET_THING, MutableSet.of());
    log.info("Set-Empty-2: "+MutableMap.copyOf(entity.config().getLocalBag().getAllConfig()));
    Assert.assertEquals(entity.getConfig(TestEntity.CONF_SET_THING), ImmutableSet.of());
}