org.apache.brooklyn.core.entity.BrooklynConfigKeys Java Examples

The following examples show how to use org.apache.brooklyn.core.entity.BrooklynConfigKeys. 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: KubernetesLocation.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected LocationSpec<KubernetesSshMachineLocation> prepareSshableLocationSpec(Entity entity, ConfigBag setup, Service service, Pod pod) {
    InetAddress node = Networking.getInetAddressWithFixedName(pod.getSpec().getNodeName());
    String podAddress = pod.getStatus().getPodIP();
    LocationSpec<KubernetesSshMachineLocation> locationSpec = LocationSpec.create(KubernetesSshMachineLocation.class)
            .configure(ADDRESS_KEY, node)
            .configure(SshMachineLocation.PRIVATE_ADDRESSES, ImmutableSet.of(podAddress))
            .configure(CALLER_CONTEXT, setup.get(CALLER_CONTEXT));
    if (!isDockerContainer(entity)) {
        Optional<ServicePort> sshPort = Iterables.tryFind(service.getSpec().getPorts(), input -> "TCP".equalsIgnoreCase(input.getProtocol()) && input.getPort() == 22);
        Optional<Integer> sshPortNumber;
        if (sshPort.isPresent()) {
            sshPortNumber = Optional.of(sshPort.get().getNodePort());
        } else {
            LOG.warn("No port-mapping found to ssh port 22, for container {}", service);
            sshPortNumber = Optional.absent();
        }
        locationSpec.configure(CloudLocationConfig.USER, setup.get(KubernetesLocationConfig.LOGIN_USER))
                .configure(SshMachineLocation.PASSWORD, setup.get(KubernetesLocationConfig.LOGIN_USER_PASSWORD))
                .configureIfNotNull(SshMachineLocation.SSH_PORT, sshPortNumber.orNull())
                .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
                .configure(BrooklynConfigKeys.ONBOX_BASE_DIR, "/tmp");
    }
    return locationSpec;
}
 
Example #2
Source File: SoftwareProcessEntityTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testInstallDirAndRunDirUsingTilde() throws Exception {
    String dataDirName = ".brooklyn-foo"+Strings.makeRandomId(4);
    String dataDir = "~/"+dataDirName;
    String resolvedDataDir = Os.mergePaths(Os.home(), dataDirName);
    
    MyService entity = app.createAndManageChild(EntitySpec.create(MyService.class)
        .configure(BrooklynConfigKeys.ONBOX_BASE_DIR, dataDir));

    entity.start(ImmutableList.of(loc));

    Assert.assertEquals(Os.nativePath(entity.getAttribute(SoftwareProcess.INSTALL_DIR)),
                        Os.nativePath(Os.mergePaths(resolvedDataDir, "installs/MyService")));
    Assert.assertEquals(Os.nativePath(entity.getAttribute(SoftwareProcess.RUN_DIR)),
                        Os.nativePath(Os.mergePaths(resolvedDataDir, "apps/"+entity.getApplicationId()+"/entities/MyService_"+entity.getId())));
}
 
Example #3
Source File: SoftwareProcessSshDriverIntegrationTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups = "Integration")
public void testTemplatesAndCopiesAllFilesInDirectory() throws IOException {
    localhost.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath());

    Path templatePath = Paths.get(tempDataDir.getAbsolutePath(), "runtime-templates", "template.yaml");
    Files.createParentDirs(templatePath.toFile());
    String templateContent = new ResourceUtils(null).getResourceAsString("classpath://org/apache/brooklyn/entity/software/base/template.yaml");
    Files.write(templateContent.getBytes(), templatePath.toFile());

    EmptySoftwareProcess entity = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class)
            .configure(SoftwareProcess.RUNTIME_TEMPLATES, MutableMap.of(templatePath.getParent().toString(), "custom-runtime-templates")));
    app.start(ImmutableList.of(localhost));

    File runtimeTemplate = new File(entity.getAttribute(SoftwareProcess.RUN_DIR), "custom-runtime-templates/template.yaml");
    assertTemplateValues(runtimeTemplate);
}
 
Example #4
Source File: SoftwareProcessSshDriverIntegrationTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups = "Integration")
public void testCopiesAllFilesInDirectory() throws IOException {
    localhost.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath());

    Path frogsPath = Paths.get(tempDataDir.getAbsolutePath(), "runtime-files", "frogs.txt");
    Files.createParentDirs(frogsPath.toFile());
    String frogsContent = new ResourceUtils(null).getResourceAsString("classpath://org/apache/brooklyn/entity/software/base/frogs.txt");
    Files.write(frogsContent.getBytes(), frogsPath.toFile());

    EmptySoftwareProcess entity = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class)
            .configure(SoftwareProcess.RUNTIME_FILES, MutableMap.of(frogsPath.getParent().toString(), "custom-runtime-files")));
    app.start(ImmutableList.of(localhost));

    File frogs = new File(entity.getAttribute(SoftwareProcess.RUN_DIR), "custom-runtime-files/frogs.txt");
    assertExcerptFromTheFrogs(frogs);
}
 
Example #5
Source File: VanillaWindowsProcessWinrmStreamsLiveTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups = "Live")
@Override
public void testGetsStreams() {
    VanillaWindowsProcess entity = app.createAndManageChild(EntitySpec.create(VanillaWindowsProcess.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
            .configure(VanillaSoftwareProcess.PRE_INSTALL_COMMAND, "echo " + getCommands().get("winrm: pre-install-command.*"))
            .configure(VanillaSoftwareProcess.INSTALL_COMMAND, "echo " + getCommands().get("winrm: install.*"))
            .configure(VanillaSoftwareProcess.POST_INSTALL_COMMAND, "echo " + getCommands().get("winrm: post-install-command.*"))
            .configure(VanillaSoftwareProcess.CUSTOMIZE_COMMAND, "echo " + getCommands().get("winrm: customize.*"))
            .configure(VanillaSoftwareProcess.PRE_LAUNCH_COMMAND, "echo " + getCommands().get("winrm: pre-launch-command.*"))
            .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "echo " + getCommands().get("winrm: launch.*"))
            .configure(VanillaSoftwareProcess.POST_LAUNCH_COMMAND, "echo " + getCommands().get("winrm: post-launch-command.*"))
            .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "echo true"));
    app.start(ImmutableList.of(machine));
    assertStreams(entity);
}
 
Example #6
Source File: SoftwareProcessSshDriverIntegrationTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups="Integration")
public void testPreAndPostLaunchCommands() throws IOException {
    File tempFile = new File(tempDataDir, "tempFile.txt");
    localhost.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath());
    app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
            .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "")
            .configure(SoftwareProcess.PRE_LAUNCH_COMMAND, String.format("echo inPreLaunch >> %s", tempFile.getAbsoluteFile()))
            .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, String.format("echo inLaunch >> %s", tempFile.getAbsoluteFile()))
            .configure(SoftwareProcess.POST_LAUNCH_COMMAND, String.format("echo inPostLaunch >> %s", tempFile.getAbsoluteFile())));
    app.start(ImmutableList.of(localhost));

    List<String> output = Files.readLines(tempFile, Charsets.UTF_8);
    assertEquals(output.size(), 3);
    assertEquals(output.get(0), "inPreLaunch");
    assertEquals(output.get(1), "inLaunch");
    assertEquals(output.get(2), "inPostLaunch");
    tempFile.delete();
}
 
Example #7
Source File: SoftwareProcessSshDriverIntegrationTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups="Integration")
public void testPreAndPostCustomizeCommands() throws IOException {
    File tempFile = new File(tempDataDir, "tempFile.txt");
    localhost.config().set(BrooklynConfigKeys.ONBOX_BASE_DIR, tempDataDir.getAbsolutePath());
    app.createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class)
            .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "")
            .configure(BrooklynConfigKeys.PRE_CUSTOMIZE_COMMAND, String.format("echo inPreCustomize >> %s", tempFile.getAbsoluteFile()))
            .configure(VanillaSoftwareProcess.CUSTOMIZE_COMMAND, String.format("echo inCustomize >> %s", tempFile.getAbsoluteFile()))
            .configure(BrooklynConfigKeys.POST_CUSTOMIZE_COMMAND, String.format("echo inPostCustomize >> %s", tempFile.getAbsoluteFile()))
            .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, String.format("echo inLaunch >> %s", tempFile.getAbsoluteFile())));
    app.start(ImmutableList.of(localhost));

    List<String> output = Files.readLines(tempFile, Charsets.UTF_8);
    assertEquals(output.size(), 4);
    assertEquals(output.get(0), "inPreCustomize");
    assertEquals(output.get(1), "inCustomize");
    assertEquals(output.get(2), "inPostCustomize");
    // Launch command is required
    assertEquals(output.get(3), "inLaunch");
    tempFile.delete();
}
 
Example #8
Source File: SoftwareProcessEntityRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testDoesNotCreateDriverAfterRebind() throws Exception {
    MyService origE = origApp.createAndManageChild(EntitySpec.create(MyService.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true));
            //the entity skips enricher initialization, do it explicitly
    origE.enrichers().add(ServiceStateLogic.newEnricherForServiceStateFromProblemsAndUp());
    
    MyProvisioningLocation origLoc = mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class)
            .displayName("mylocname"));
    origApp.start(ImmutableList.of(origLoc));
    assertEquals(origE.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.RUNNING);
    EntityAsserts.assertAttributeEqualsEventually(origE, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);

    ServiceStateLogic.setExpectedState(origE, Lifecycle.ON_FIRE);
    EntityAsserts.assertAttributeEqualsEventually(origE, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE);

    newApp = rebind();
    MyService newE = (MyService) Iterables.getOnlyElement(newApp.getChildren());
    assertNull(newE.getDriver(), "driver should not be initialized because entity is in a permanent failure");
}
 
Example #9
Source File: SoftwareProcessEntityRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testReleasesLocationOnStopAfterRebinding() throws Exception {
    MyService origE = origApp.createAndManageChild(EntitySpec.create(MyService.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true));
    
    MyProvisioningLocation origLoc = mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class)
            .displayName("mylocname"));
    origApp.start(ImmutableList.of(origLoc));
    assertEquals(origLoc.inUseCount.get(), 1);
    
    newApp = rebind();
    MyProvisioningLocation newLoc = (MyProvisioningLocation) Iterables.getOnlyElement(newApp.getLocations());
    assertEquals(newLoc.inUseCount.get(), 1);
    
    newApp.stop();
    assertEquals(newLoc.inUseCount.get(), 0);
}
 
Example #10
Source File: SshCommandSensor.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, String> get() {
    if (entity == null) return ImmutableMap.of(); // See BROOKLYN-568
    
    Map<String, Object> env = MutableMap.copyOf(entity.getConfig(BrooklynConfigKeys.SHELL_ENVIRONMENT));

    // Add the shell environment entries from our configuration
    if (rawSensorShellEnv != null) {
        env.putAll(TypeCoercions.coerce(rawSensorShellEnv, new TypeToken<Map<String,Object>>() {}));
    }

    // Try to resolve the configuration in the env Map
    try {
        env = (Map<String, Object>) Tasks.resolveDeepValue(env, Object.class, ((EntityInternal) entity).getExecutionContext());
    } catch (InterruptedException | ExecutionException e) {
        Exceptions.propagateIfFatal(e);
    }

    // Convert the environment into strings with the serializer
    ShellEnvironmentSerializer serializer = new ShellEnvironmentSerializer(((EntityInternal) entity).getManagementContext());
    return serializer.serialize(env);
}
 
Example #11
Source File: MachineEntityRebindTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testNoLogWarningsWhenRebindToMachineEntity() throws Exception {
    String loggerName = InternalFactory.class.getName();
    ch.qos.logback.classic.Level logLevel = ch.qos.logback.classic.Level.WARN;
    Predicate<ILoggingEvent> filter = Predicates.alwaysTrue();
    try (LogWatcher watcher = new LogWatcher(loggerName, logLevel, filter)) {
        origApp.createAndManageChild(EntitySpec.create(MachineEntity.class)
                .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true));
        origApp.start(ImmutableList.of(origMachine));
        
        rebind();
    
        List<ILoggingEvent> events = watcher.getEvents();
        assertTrue(events.isEmpty(), "events="+events);
    }
}
 
Example #12
Source File: SetHostnameCustomizerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testCustomizerPropagatesException() throws Exception {
    SshMachineLocation machine = mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocationThrowsException.class)
            .configure("address", "4.3.2.1"));
    
    FixedListMachineProvisioningLocation<?> provisioningLoc = mgmt.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class)
            .configure("machines", MutableSet.of(machine)));

    MachineEntity entity = app.createAndManageChild(EntitySpec.create(MachineEntity.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
            .configure(MachineEntity.PROVISIONING_PROPERTIES.subKey(JcloudsLocation.MACHINE_LOCATION_CUSTOMIZERS.getName()), ImmutableSet.of(customizer)));

    try {
        entity.start(ImmutableList.of(provisioningLoc));
        fail();
    } catch (RuntimeException e) {
        if (Exceptions.getFirstThrowableMatching(e, Predicates.compose(StringPredicates.containsLiteral("simulated failure"), Functions.toStringFunction())) == null) {
            throw e;
        };
        assertFalse(Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).isPresent());
    }
    
}
 
Example #13
Source File: ActivityApiEntitlementsTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@BeforeMethod(alwaysRun=true)
@Override
public void setUp() throws Exception {
    super.setUp();
    
    machineEntity = app.addChild(EntitySpec.create(MachineEntity.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
            .location(TestApplication.LOCALHOST_PROVISIONER_SPEC));
    machineEntity.start(ImmutableList.<Location>of());
    
    machineEntity.execCommand("echo myval");
    
    Set<Task<?>> tasks = BrooklynTaskTags.getTasksInEntityContext(mgmt.getExecutionManager(), machineEntity);
    String taskNameRegex = "ssh: echo myval";
    
    streams = Maps.newLinkedHashMap();
    subTask = AbstractSoftwareProcessStreamsTest.findTaskOrSubTask(tasks, TaskPredicates.displayNameSatisfies(StringPredicates.matchesRegex(taskNameRegex))).get();
    for (String streamId : ImmutableList.of("stdin", "stdout", "stderr")) {
        streams.put(streamId, AbstractSoftwareProcessStreamsTest.getStreamOrFail(subTask, streamId));
    }
}
 
Example #14
Source File: SetHostnameCustomizerLiveTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"Live"})
public void testSetAutogeneratedHostname() throws Exception {
    SetHostnameCustomizer customizer = new SetHostnameCustomizer(ConfigBag.newInstance());

    MachineEntity entity = app.createAndManageChild(EntitySpec.create(MachineEntity.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
            .configure(MachineEntity.PROVISIONING_PROPERTIES.subKey(JcloudsLocation.MACHINE_LOCATION_CUSTOMIZERS.getName()), ImmutableSet.of(customizer))
            .configure(MachineEntity.PROVISIONING_PROPERTIES.subKey(JcloudsLocation.IMAGE_ID.getName()), "CENTOS_6_64"));


    app.start(ImmutableList.of(loc));
    
    SshMachineLocation machine = Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).get();
    
    String ip;
    if (machine.getPrivateAddresses().isEmpty()) {
        ip = Iterables.get(machine.getPublicAddresses(), 0);
    } else {
        ip = Iterables.get(machine.getPrivateAddresses(), 0);
    }
    String expected = "ip-"+(ip.replace(".", "-")+"-"+machine.getId());
    assertEquals(getHostname(machine), expected);
}
 
Example #15
Source File: SetHostnameCustomizerLiveTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups = {"Live"})
public void testSetFixedHostname() throws Exception {
    SetHostnameCustomizer customizer = new SetHostnameCustomizer(ConfigBag.newInstance()
            .configure(SetHostnameCustomizer.FIXED_HOSTNAME, "myhostname"));
    
    MachineEntity entity = app.createAndManageChild(EntitySpec.create(MachineEntity.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
            .configure(MachineEntity.PROVISIONING_PROPERTIES.subKey(JcloudsLocation.MACHINE_LOCATION_CUSTOMIZERS.getName()), ImmutableSet.of(customizer))
            .configure(MachineEntity.PROVISIONING_PROPERTIES.subKey(JcloudsLocation.IMAGE_ID.getName()), PROVIDER_IMAGE_ID));


    app.start(ImmutableList.of(loc));
    
    SshMachineLocation machine = Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).get();
    
    assertEquals(getHostname(machine), "myhostname");
}
 
Example #16
Source File: VanillaWindowsProcessTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllCmds() throws Exception {
    app.createAndManageChild(EntitySpec.create(VanillaWindowsProcess.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
            .configure(VanillaWindowsProcess.PRE_INSTALL_COMMAND, "preInstallCommand")
            .configure(VanillaWindowsProcess.INSTALL_COMMAND, "installCommand")
            .configure(VanillaWindowsProcess.POST_INSTALL_COMMAND, "postInstallCommand")
            .configure(VanillaWindowsProcess.PRE_CUSTOMIZE_COMMAND, "preCustomizeCommand")
            .configure(VanillaWindowsProcess.CUSTOMIZE_COMMAND, "customizeCommand")
            .configure(VanillaWindowsProcess.POST_CUSTOMIZE_COMMAND, "postCustomizeCommand")
            .configure(VanillaWindowsProcess.PRE_LAUNCH_COMMAND, "preLaunchCommand")
            .configure(VanillaWindowsProcess.LAUNCH_COMMAND, "launchCommand")
            .configure(VanillaWindowsProcess.POST_LAUNCH_COMMAND, "postLaunchCommand")
            .configure(VanillaWindowsProcess.CHECK_RUNNING_COMMAND, "checkRunningCommand")
            .configure(VanillaWindowsProcess.STOP_COMMAND, "stopCommand"));
    app.start(ImmutableList.of(loc));

    assertExecsContain(RecordingWinRmTool.getExecs(), ImmutableList.of(
            "preInstallCommand", "installCommand", "postInstallCommand", 
            "preCustomizeCommand", "customizeCommand", "postCustomizeCommand", 
            "preLaunchCommand", "launchCommand", "postLaunchCommand", 
            "checkRunningCommand"));
    
    app.stop();

    assertExecContains(RecordingWinRmTool.getLastExec(), "stopCommand");
}
 
Example #17
Source File: BrooklynAppUnitTestSupport.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void setUpApp() {
    EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class);
    if (shouldSkipOnBoxBaseDirResolution()!=null)
        appSpec.configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, shouldSkipOnBoxBaseDirResolution());
    
    app = mgmt.getEntityManager().createEntity(appSpec);
}
 
Example #18
Source File: VanillaWindowsProcessTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testAllPowershell() throws Exception {
    app.createAndManageChild(EntitySpec.create(VanillaWindowsProcess.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
            .configure(VanillaWindowsProcess.PRE_INSTALL_POWERSHELL_COMMAND, "preInstallCommand")
            .configure(VanillaWindowsProcess.INSTALL_POWERSHELL_COMMAND, "installCommand")
            .configure(VanillaWindowsProcess.POST_INSTALL_POWERSHELL_COMMAND, "postInstallCommand")
            .configure(VanillaWindowsProcess.PRE_CUSTOMIZE_POWERSHELL_COMMAND, "preCustomizeCommand")
            .configure(VanillaWindowsProcess.CUSTOMIZE_POWERSHELL_COMMAND, "customizeCommand")
            .configure(VanillaWindowsProcess.POST_CUSTOMIZE_POWERSHELL_COMMAND, "postCustomizeCommand")
            .configure(VanillaWindowsProcess.PRE_LAUNCH_POWERSHELL_COMMAND, "preLaunchCommand")
            .configure(VanillaWindowsProcess.LAUNCH_POWERSHELL_COMMAND, "launchCommand")
            .configure(VanillaWindowsProcess.POST_LAUNCH_POWERSHELL_COMMAND, "postLaunchCommand")
            .configure(VanillaWindowsProcess.CHECK_RUNNING_POWERSHELL_COMMAND, "checkRunningCommand")
            .configure(VanillaWindowsProcess.STOP_POWERSHELL_COMMAND, "stopCommand"));
    app.start(ImmutableList.of(loc));

    assertExecsContain(RecordingWinRmTool.getExecs(), ImmutableList.of(
            "preInstallCommand", "installCommand", "postInstallCommand", 
            "preCustomizeCommand", "customizeCommand", "postCustomizeCommand", 
            "preLaunchCommand", "launchCommand", "postLaunchCommand", 
            "checkRunningCommand"));
    
    app.stop();

    assertExecContains(RecordingWinRmTool.getLastExec(), "stopCommand");
}
 
Example #19
Source File: BasicDownloadsRegistryTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testUsesDownloadUrlAttribute() throws Exception {
    entity.config().set(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion");
    entity.sensors().set(Attributes.DOWNLOAD_URL, "acme.com/version=${version},type=${type},simpletype=${simpletype}");
    String expectedFilename = String.format("version=%s,type=%s,simpletype=%s", "myversion", TestEntity.class.getName(), "TestEntity");
    
    String expectedLocalRepo = String.format("file://$HOME/.brooklyn/repository/%s/%s/%s", "TestEntity", "myversion", expectedFilename);
    String expectedDownloadUrl = String.format("acme.com/%s", expectedFilename);
    String expectedCloudsoftRepo = String.format("http://downloads.cloudsoftcorp.com/brooklyn/repository/%s/%s/%s", "TestEntity", "myversion", expectedFilename);
    assertResolves(expectedLocalRepo, expectedDownloadUrl, expectedCloudsoftRepo);
}
 
Example #20
Source File: EntitySshToolTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomSshToolClassConfiguredOnEntityWithPrefix() throws Exception {
    MachineEntity entity = app.addChild(EntitySpec.create(MachineEntity.class)
            .configure(BrooklynConfigKeys.SSH_TOOL_CLASS, RecordingSshTool.class.getName()));
    entity.start(ImmutableList.of(machine));
    runCustomSshToolClass(entity);
}
 
Example #21
Source File: StartStopSshDriverTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testSshCliPickedUpWhenSpecified() {
    entity.config().set(BrooklynConfigKeys.SSH_TOOL_CLASS, SshCliTool.class.getName());
    driver.execute(Arrays.asList("echo hi"), "test");
    assertTrue(sshMachineLocation.lastTool instanceof SshCliTool, "expect CLI tool, got "+
                    (sshMachineLocation.lastTool!=null ? ""+sshMachineLocation.lastTool.getClass()+":" : "") + sshMachineLocation.lastTool);
}
 
Example #22
Source File: StartStopSshDriverTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testSshScriptHeaderUsedWhenSpecified() {
    entity.config().set(BrooklynConfigKeys.SSH_CONFIG_SCRIPT_HEADER, "#!/bin/bash -e\necho hello world");
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    driver.execute(ImmutableMap.of("out", out), Arrays.asList("echo goodbye"), "test");
    String s = out.toString();
    assertTrue(s.contains("goodbye"), "should have said goodbye: "+s);
    assertTrue(s.contains("hello world"), "should have said hello: "+s);
    assertTrue(sshMachineLocation.lastTool instanceof SshjTool, "expect sshj tool, got "+
        (sshMachineLocation.lastTool!=null ? ""+sshMachineLocation.lastTool.getClass()+":" : "") + sshMachineLocation.lastTool);
}
 
Example #23
Source File: MachineLifecycleEffectorTasksTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Integration")
public void testProvisionLatchObeyed() throws Exception {

    AttributeSensor<Boolean> ready = Sensors.newBooleanSensor("readiness");

    BasicEntity triggerEntity = app.createAndManageChild(EntitySpec.create(BasicEntity.class));

    EmptySoftwareProcess entity = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class)
            .configure(BrooklynConfigKeys.PROVISION_LATCH, DependentConfiguration.attributeWhenReady(triggerEntity, ready)));

    final Task<Void> task = Entities.invokeEffector(app, app, Startable.START, ImmutableMap.of(
            "locations", ImmutableList.of(BailOutJcloudsLocation.newBailOutJcloudsLocation(app.getManagementContext()))));
    
    Time.sleep(ValueResolver.PRETTY_QUICK_WAIT);
    if (task.isDone()) throw new IllegalStateException("Task finished early with: "+task.get());
    assertEffectorBlockingDetailsEventually(entity, "Waiting for config " + BrooklynConfigKeys.PROVISION_LATCH.getName());

    Asserts.succeedsContinually(new Runnable() {
        @Override
        public void run() {
            if (task.isDone()) throw new IllegalStateException("Task finished early with: "+task.getUnchecked());
        }
    });
    try {
        triggerEntity.sensors().set(ready, true);
        task.get(Duration.THIRTY_SECONDS);
    } catch (Throwable t) {
        Exceptions.propagateIfFatal(t);
        if ((t.toString().contains(BailOutJcloudsLocation.ERROR_MESSAGE))) {
            // expected - BailOut location throws - just swallow
        } else {
            Exceptions.propagate(t);
        }
    }
}
 
Example #24
Source File: SoftwareProcessEntityTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected <T extends MyService> void doStartAndCheckVersion(Class<T> type, String expectedLabel, ConfigBag config) {
    MyService entity = app.createAndManageChild(EntitySpec.create(type)
        .configure(BrooklynConfigKeys.ONBOX_BASE_DIR, "/tmp/brooklyn-foo")
        .configure(config.getAllConfigAsConfigKeyMap()));
    entity.start(ImmutableList.of(loc));
    Assert.assertEquals(entity.getAttribute(SoftwareProcess.INSTALL_DIR), "/tmp/brooklyn-foo/installs/"
        + expectedLabel);
}
 
Example #25
Source File: MachineEntityRebindTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testRebindToMachineEntity() throws Exception {
    MachineEntity entity = origApp.createAndManageChild(EntitySpec.create(MachineEntity.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true));
    origApp.start(ImmutableList.of(origMachine));
    EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
    
    rebind();
    
    Entity newEntity = mgmt().getEntityManager().getEntity(entity.getId());
    EntityAsserts.assertAttributeEqualsEventually(newEntity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
}
 
Example #26
Source File: DownloadSubstitutersTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testSubstitutionIncludesDefaultSubs() throws Exception {
    entity.config().set(BrooklynConfigKeys.SUGGESTED_VERSION, "myversion");
    String pattern = "version=${version},type=${type},simpletype=${simpletype}";
    BasicDownloadRequirement req = new BasicDownloadRequirement(driver);
    String result = DownloadSubstituters.substitute(req, pattern);
    assertEquals(result, String.format("version=%s,type=%s,simpletype=%s", "myversion", TestEntity.class.getName(), TestEntity.class.getSimpleName()));
}
 
Example #27
Source File: SoftwareProcessStopsDuringStartJcloudsLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void runStartStopSequentiallyIsQuick(final ProvisioningLocation<?> loc) throws Exception {
    final EmptySoftwareProcess entity = app.createAndManageChild(EntitySpec.create(EmptySoftwareProcess.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true));
    
    executeInLimitedTime(new Callable<Void>() {
        @Override
        public Void call() {
            app.start(ImmutableList.of(loc));
            return null;
        }
    }, Asserts.DEFAULT_LONG_TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS);
    EntityAsserts.assertEntityHealthy(entity);
    assertEquals(entity.getAttribute(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE), null);
    assertEquals(entity.getAttribute(MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE), Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).get());

    executeInLimitedTime(new Callable<Void>() {
        @Override
        public Void call() {
            Entities.destroy(app);
            return null;
        }
    }, Asserts.DEFAULT_LONG_TIMEOUT.toMilliseconds(), TimeUnit.MILLISECONDS);
    assertEquals(app.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.STOPPED);
    assertEquals(app.getAttribute(Attributes.SERVICE_STATE_EXPECTED).getState(), Lifecycle.STOPPED);
    assertEquals(entity.getAttribute(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE), null);
    assertEquals(entity.getAttribute(MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE), null);
}
 
Example #28
Source File: JcloudsLocationUsageTrackingTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@BeforeMethod(alwaysRun = true)
@Override
public void setUp() throws Exception {
    super.setUp();
    RecordingSshTool.clear();

    app = managementContext.getEntityManager().createEntity(EntitySpec.create(TestApplication.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true));
    entity = app.createAndManageChild(EntitySpec.create(SoftwareProcessEntityTest.MyService.class));
    
    serverSocket = new ServerSocket();
    serverSocket.bind(new InetSocketAddress(Networking.getReachableLocalHost(), 0), 0);
}
 
Example #29
Source File: VanillaWindowsProcessWinrmStreamsLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups = "Live")
public void testGetsStreamsPowerShell() {
    VanillaWindowsProcess entity = app.createAndManageChild(EntitySpec.create(VanillaWindowsProcess.class)
            .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, true)
            .configure(VanillaWindowsProcess.PRE_INSTALL_POWERSHELL_COMMAND, "echo " + getCommands().get("winrm: pre-install-command.*"))
            .configure(VanillaWindowsProcess.INSTALL_POWERSHELL_COMMAND, "echo " + getCommands().get("winrm: install.*"))
            .configure(VanillaWindowsProcess.POST_INSTALL_POWERSHELL_COMMAND, "echo " + getCommands().get("winrm: post-install-command.*"))
            .configure(VanillaWindowsProcess.CUSTOMIZE_POWERSHELL_COMMAND, "echo " + getCommands().get("winrm: customize.*"))
            .configure(VanillaWindowsProcess.PRE_LAUNCH_POWERSHELL_COMMAND, "echo " + getCommands().get("winrm: pre-launch-command.*"))
            .configure(VanillaWindowsProcess.LAUNCH_POWERSHELL_COMMAND, "echo " + getCommands().get("winrm: launch.*"))
            .configure(VanillaWindowsProcess.POST_LAUNCH_POWERSHELL_COMMAND, "echo " + getCommands().get("winrm: post-launch-command.*"))
            .configure(VanillaWindowsProcess.CHECK_RUNNING_POWERSHELL_COMMAND, "echo true"));
    app.start(ImmutableList.of(machine));
    assertStreams(entity);
}
 
Example #30
Source File: EntitySshToolTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testCustomSshToolClassConfiguredOnBrooklynProperties() throws Exception {
    mgmt.getBrooklynProperties().put(BrooklynConfigKeys.SSH_TOOL_CLASS, RecordingSshTool.class.getName());
    MachineEntity entity = app.addChild(EntitySpec.create(MachineEntity.class));
    entity.start(ImmutableList.of(machine));
    runCustomSshToolClass(entity);
}