org.apache.brooklyn.api.location.Location Java Examples

The following examples show how to use org.apache.brooklyn.api.location.Location. 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: CampInternalUtils.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
private static LocationSpec<?> resolveLocationSpec(
        String type,
        Map<String, Object> brooklynConfig,
        BrooklynClassLoadingContext loader) {
    if (brooklynConfig==null) {
        brooklynConfig = MutableMap.of();
    }
    Maybe<Class<? extends Location>> javaClass = loader.tryLoadClass(type, Location.class);
    LocationSpec<?> spec;
    if (javaClass.isPresent()) {
        spec = LocationSpec.create(javaClass.get());
    } else {
        Maybe<LocationSpec<? extends Location>> loc = loader.getManagementContext().getLocationRegistry().getLocationSpec(type, brooklynConfig);
        if (loc.isPresent()) {
            spec = loc.get();
        } else {
            throw new IllegalStateException("No class or resolver found for location type "+type);
        }
    }
    return spec;
}
 
Example #2
Source File: TestSshCommandTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFailOnUnmatchedStdout() {
    String cmd = "stdoutAndStderr-" + Identifiers.randomLong();
    RecordingSshTool.setCustomResponse(cmd, new RecordingSshTool.CustomResponse(0, "wrongstdout", null));
    
    TestSshCommand test = app.createAndManageChild(EntitySpec.create(TestSshCommand.class)
        .configure(MAX_ATTEMPTS, 1)
        .configure(TARGET_ENTITY, testEntity)
        .configure(COMMAND, cmd)
        .configure(ASSERT_OUT, makeAssertions(ImmutableMap.of(CONTAINS, "mystdout"))));

    try {
        app.start(ImmutableList.<Location>of());
        Asserts.shouldHaveFailedPreviously();
    } catch (Throwable t) {
        Asserts.expectedFailureContains(t, "stdout expected contains mystdout but found wrongstdout");
    }

    assertEntityFailed(test);
}
 
Example #3
Source File: SoftwareProcessStopsDuringStartTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testSequentialStartThenStop() throws Exception {
    loc.getObtainResumeLatch(0).countDown();
    
    entity.start(ImmutableList.<Location>of(loc));
    SshMachineLocation machine = Machines.findUniqueMachineLocation(entity.getLocations(), SshMachineLocation.class).get();
    EntityAsserts.assertAttributeEquals(entity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, null);
    EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE, machine);
    
    Stopwatch stopwatch = Stopwatch.createStarted();
    entity.stop();
    Duration stopDuration = Duration.of(stopwatch);
    assertTrue(Asserts.DEFAULT_LONG_TIMEOUT.isLongerThan(stopDuration), "stop took "+stopDuration);
    EntityAsserts.assertAttributeEquals(entity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, null);
    EntityAsserts.assertAttributeEquals(entity, MachineLifecycleEffectorTasks.INTERNAL_PROVISIONED_MACHINE, null);
    
    assertEquals(loc.getCalls(), ImmutableList.of("obtain", "release"));
}
 
Example #4
Source File: XmlMementoSerializerTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
LookupContextImpl(String description, ManagementContext mgmt, Map<String,? extends Entity> entities, Map<String,? extends Location> locations,
        Map<String,? extends Policy> policies, Map<String,? extends Enricher> enrichers, Map<String,? extends Feed> feeds,
        Map<String, ? extends CatalogItem<?, ?>> catalogItems, Map<String,? extends ManagedBundle> bundles,
        boolean failOnDangling) {
    this.description = new Stack<>();
    this.description.push(description);
    this.mgmt = mgmt;
    this.entities = ImmutableMap.copyOf(entities);
    this.locations = ImmutableMap.copyOf(locations);
    this.policies = ImmutableMap.copyOf(policies);
    this.enrichers = ImmutableMap.copyOf(enrichers);
    this.feeds = ImmutableMap.copyOf(feeds);
    this.catalogItems = ImmutableMap.copyOf(catalogItems);
    this.bundles = ImmutableMap.copyOf(bundles);
    this.failOnDangling = failOnDangling;
}
 
Example #5
Source File: LocationExternalConfigYamlTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test(groups="Integration")
public void testLocalhostInheritance() throws Exception {
    String yaml = Joiner.on("\n").join(
            "services:",
            "- type: "+EmptySoftwareProcess.class.getName(),
            "location:",
            "  localhost:",
            "    my.config.key: $brooklyn:external(\"myprovider\", \"mykey\")");

    origApp = (StartableApplication) createAndStartApplication(new StringReader(yaml));

    Entity entity = Iterables.getOnlyElement( origApp.getChildren() );
    Location l = Iterables.getOnlyElement( entity.getLocations() );
    assertEquals(l.config().get(MY_CONFIG_KEY), "myval");
            
    Maybe<Object> rawConfig = ((BrooklynObjectInternal.ConfigurationSupportInternal)l.config()).getRaw(MY_CONFIG_KEY);
    Assert.assertTrue(rawConfig.isPresentAndNonNull());
    Assert.assertTrue(rawConfig.get() instanceof DeferredSupplier, "Expected deferred raw value; got "+rawConfig.get());
}
 
Example #6
Source File: StubInfrastructureImpl.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
public void doStart(Collection<? extends Location> locations) {
    // TODO support multiple locations
    sensors().set(SERVICE_UP, Boolean.FALSE);

    Location provisioner = Iterables.getOnlyElement(locations);
    LOG.info("Creating new DockerLocation wrapping {}", provisioner);

    Map<String, ?> flags = MutableMap.<String, Object>builder()
            .putAll(config().get(LOCATION_FLAGS))
            .put("provisioner", provisioner)
            .build();
    createLocation(flags);

    super.doStart(locations);

    sensors().set(SERVICE_UP, Boolean.TRUE);
}
 
Example #7
Source File: Tomcat8ServerSoftlayerLiveTest.java    From brooklyn-library with Apache License 2.0 6 votes vote down vote up
@Override
    protected void doTest(Location loc) throws Exception {
        final Tomcat8Server server = app.createAndManageChild(EntitySpec.create(Tomcat8Server.class)
                .configure("war", getTestWar()));
        
        app.start(ImmutableList.of(loc));
        
        String url = server.getAttribute(Tomcat8Server.ROOT_URL);
        
        HttpTestUtils.assertHttpStatusCodeEventuallyEquals(url, 200);
        HttpTestUtils.assertContentContainsText(url, "Hello");
        
        Asserts.succeedsEventually(new Runnable() {
            @Override public void run() {
                assertNotNull(server.getAttribute(Tomcat8Server.REQUEST_COUNT));
                assertNotNull(server.getAttribute(Tomcat8Server.ERROR_COUNT));
                assertNotNull(server.getAttribute(Tomcat8Server.TOTAL_PROCESSING_TIME));
                
                // TODO These appear not to be set in TomcatServerImpl.connectSensors
                //      See TomcatServerEc2LiveTest, where these are also not included.
//                assertNotNull(server.getAttribute(TomcatServer.MAX_PROCESSING_TIME));
//                assertNotNull(server.getAttribute(TomcatServer.BYTES_RECEIVED));
//                assertNotNull(server.getAttribute(TomcatServer.BYTES_SENT));
            }});
    }
 
Example #8
Source File: CloudExplorerSupport.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Override
protected void doCall(JcloudsLocation loc, String indent) throws Exception {

    ComputeService computeService = loc.getComputeService();
    ConfigBag setup = loc.config().getBag();
    
    JcloudsLocationCustomizer customizersDelegate = LocationCustomizerDelegate.newInstance(loc.getManagementContext(), setup);
    Template template = loc.buildTemplate(computeService, setup, customizersDelegate);
    Image image = template.getImage();
    Hardware hardware = template.getHardware();
    org.jclouds.domain.Location location = template.getLocation();
    TemplateOptions options = template.getOptions();
    stdout.println(indent+"Default template {");
    stdout.println(indent+"\tImage: "+image);
    stdout.println(indent+"\tHardware: "+hardware);
    stdout.println(indent+"\tLocation: "+location);
    stdout.println(indent+"\tOptions: "+options);
    stdout.println(indent+"}");
}
 
Example #9
Source File: TestSshCommandTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFailUsingSuccessfulExitAsDefaultCondition() {
    String cmd = "commandExpectedToFail-" + Identifiers.randomLong();
    RecordingSshTool.setCustomResponse(cmd, new RecordingSshTool.CustomResponse(1, null, null));
    
    TestSshCommand test = app.createAndManageChild(EntitySpec.create(TestSshCommand.class)
        .configure(MAX_ATTEMPTS, 1)
        .configure(TARGET_ENTITY, testEntity)
        .configure(COMMAND, cmd));

    try {
        app.start(ImmutableList.<Location>of());
        Asserts.shouldHaveFailedPreviously();
    } catch (Throwable t) {
        Asserts.expectedFailureContains(t, "exit code expected equals 0 but found 1");
    }

    assertEntityFailed(test);
    assertThat(RecordingSshTool.getLastExecCmd().commands).isEqualTo(ImmutableList.of(cmd));
}
 
Example #10
Source File: Machines.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public static Maybe<String> getSubnetIp(Location where) {
    // TODO Too much duplication between the ip and hostname methods
    String result = null;
    if (where instanceof HasSubnetHostname) {
        result = ((HasSubnetHostname) where).getSubnetIp();
    }
    if (where instanceof HasNetworkAddresses) {
        Set<String> privateAddrs = ((HasNetworkAddresses) where).getPrivateAddresses();
        if (privateAddrs.size() > 0) {
            result = Iterables.get(privateAddrs, 0);
        }
    }
    if (result == null && where instanceof MachineLocation) {
        InetAddress addr = ((MachineLocation) where).getAddress();
        if (addr != null) result = addr.getHostAddress();
    }
    log.debug("computed subnet host ip {} for {}", result, where);
    return Maybe.fromNullable(result);
}
 
Example #11
Source File: TargetableTestComponentTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testTargetEntityByIdNotFound() {
    app.addChild(EntitySpec.create(TestSensor.class)
            .configure(TestSensor.TARGET_ID, "myTargetId")
            .configure(TestSensor.SENSOR_NAME, STRING_SENSOR.getName())
            .configure(TestSensor.ASSERTIONS, ImmutableList.of(ImmutableMap.of("equals", "myval"))));

    try {
        app.start(ImmutableList.<Location>of());
        Asserts.shouldHaveFailedPreviously();
    } catch (Exception e) {
        NoSuchElementException e2 = Exceptions.getFirstThrowableOfType(e, NoSuchElementException.class);
        if (e2 == null) throw e;
        Asserts.expectedFailureContains(e2, "No entity matching id myTargetId");
    }
}
 
Example #12
Source File: SeaCloudsManagementPolicy.java    From SeaCloudsPlatform with Apache License 2.0 6 votes vote down vote up
private Effector<Void> newStartEffector() {
    return Effectors.effector(Startable.START)
            .impl(new EffectorBody<Void>() {
                @Override
                public Void call(ConfigBag parameters) {
                    LOG.info("Starting SeaCloudsInitializerPolicy " + "for " + entity.getId());
                    installSLA();
                    installMonitoringRules();
                    notifyRulesReady();
                    installInfluxDbObservers();
                    installGrafanaDashboards();

                    // Rewire the original behaviour
                    Collection<? extends Location> locations = null;
                    Object locationRaw = parameters.getStringKey(EffectorStartableImpl.StartParameters.LOCATIONS.getName());
                    locations = Locations.coerceToCollectionOfLocationsManaged(getManagementContext(), locationRaw);
                    ((StartableApplication) entity).start(locations);

                    return null;
                }
            })
            .build();
}
 
Example #13
Source File: LocalhostLocationResolverTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@Test
public void testRegistryCommaResolution() throws NoMachinesAvailableException {
    List<Location> l;
    l = getLocationResolver().getListOfLocationsManaged(JavaStringEscapes.unwrapJsonishListStringIfPossible("localhost,localhost,localhost"));
    assertEquals(l.size(), 3, "l="+l);
    assertTrue(l.get(0) instanceof LocalhostMachineProvisioningLocation, "l="+l);
    assertTrue(l.get(1) instanceof LocalhostMachineProvisioningLocation, "l="+l);
    assertTrue(l.get(2) instanceof LocalhostMachineProvisioningLocation, "l="+l);

    // And check works if comma in brackets
    l = getLocationResolver().getListOfLocationsManaged(JavaStringEscapes.unwrapJsonishListStringIfPossible(
        "[ \"byon:(hosts=\\\"192.168.0.1\\\",user=bob)\", \"byon:(hosts=\\\"192.168.0.2\\\",user=bob2)\" ]"));
    assertEquals(l.size(), 2, "l="+l);
    assertTrue(l.get(0) instanceof FixedListMachineProvisioningLocation, "l="+l);
    assertTrue(l.get(1) instanceof FixedListMachineProvisioningLocation, "l="+l);
    assertEquals(((FixedListMachineProvisioningLocation<SshMachineLocation>)l.get(0)).obtain().getUser(), "bob");
    assertEquals(((FixedListMachineProvisioningLocation<SshMachineLocation>)l.get(1)).obtain().getUser(), "bob2");
}
 
Example #14
Source File: RebindEntityTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void testRestoresEntityLocationAndCleansUp() throws Exception {
    MyEntity child = origApp.createAndManageChild(EntitySpec.create(MyEntity.class).location(LocationSpec.create(MyLocation.class)));
    Location loc = Iterables.getOnlyElement(child.getLocations());
    
    newApp = rebind();
    MyEntity newE = (MyEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(MyEntity.class));
    
    Assert.assertEquals(newE.getLocations().size(), 1); 
    Location loc2 = Iterables.getOnlyElement(newE.getLocations());
    Assert.assertEquals(loc, loc2);
    Assert.assertFalse(loc==loc2);
    
    newApp.stop();
    // TODO how to trigger automatic unmanagement? see notes in RebindLocalhostLocationTest
    newManagementContext.getLocationManager().unmanage(loc2);
    switchOriginalToNewManagementContext();
    RebindTestUtils.waitForPersisted(origManagementContext);
    
    BrooklynMementoManifest mf = loadMementoManifest();
    Assert.assertTrue(mf.getLocationIdToType().isEmpty(), "Expected no locations; had "+mf.getLocationIdToType());
}
 
Example #15
Source File: TestSshCommandTest.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldFailOnUnmatchedStderr() {
    String cmd = "stdoutAndStderr-" + Identifiers.randomLong();
    RecordingSshTool.setCustomResponse(cmd, new RecordingSshTool.CustomResponse(0, null, "wrongstderr"));
    
    TestSshCommand test = app.createAndManageChild(EntitySpec.create(TestSshCommand.class)
        .configure(MAX_ATTEMPTS, 1)
        .configure(TARGET_ENTITY, testEntity)
        .configure(COMMAND, cmd)
        .configure(ASSERT_ERR, makeAssertions(ImmutableMap.of(CONTAINS, "mystderr"))));

    try {
        app.start(ImmutableList.<Location>of());
        Asserts.shouldHaveFailedPreviously();
    } catch (Throwable t) {
        Asserts.expectedFailureContains(t, "stderr expected contains mystderr but found wrongstderr");
    }

    assertEntityFailed(test);
}
 
Example #16
Source File: CreateUserPolicyLiveTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test(groups="Live")
@SuppressWarnings("unchecked")
public void testLiveCreatesUserOnCentos() throws Exception {
    String locSpec = "jclouds:softlayer:ams01";
    ImmutableMap<String, String> locArgs = ImmutableMap.of("imageId", "CENTOS_6_64");
    Location loc = mgmt.getLocationRegistry().getLocationManaged(locSpec, locArgs);
    runTestCreatesUser((MachineProvisioningLocation<SshMachineLocation>) loc);
}
 
Example #17
Source File: CatalogItem.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static CatalogItemType ofTargetClass(Class<? extends BrooklynObject> type) {
    if (type==null) return null;
    if (Policy.class.isAssignableFrom(type)) return POLICY;
    if (Enricher.class.isAssignableFrom(type)) return ENRICHER;
    if (Location.class.isAssignableFrom(type)) return LOCATION;
    if (Application.class.isAssignableFrom(type)) return APPLICATION;
    if (Entity.class.isAssignableFrom(type)) return ENTITY;
    return null;
}
 
Example #18
Source File: MySqlLiveGceTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Override
protected void doTest(Location loc) throws Exception {
    MySqlNode mysql = app.createAndManageChild(EntitySpec.create(MySqlNode.class)
            .configure(DatastoreCommon.CREATION_SCRIPT_CONTENTS, MySqlIntegrationTest.CREATION_SCRIPT)
            .configure("test.table.name", "COMMENTS"));

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

    new VogellaExampleAccess("com.mysql.jdbc.Driver", mysql.getAttribute(DatastoreCommon.DATASTORE_URL)).readModifyAndRevertDataBase();
}
 
Example #19
Source File: BrooklynTypes.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public BrooklynDynamicType<?, ?> call() throws Exception {
    if (Entity.class.isAssignableFrom(brooklynClass)) {
        return new ImmutableEntityType((Class<? extends Entity>)brooklynClass);
    } else if (Location.class.isAssignableFrom(brooklynClass)) {
        return new ImmutableEntityType((Class<? extends Entity>)brooklynClass);
    } else if (Policy.class.isAssignableFrom(brooklynClass)) {
        return new PolicyDynamicType((Class<? extends Policy>)brooklynClass); // TODO immutable?
    } else if (Enricher.class.isAssignableFrom(brooklynClass)) {
        return new EnricherDynamicType((Class<? extends Enricher>)brooklynClass); // TODO immutable?
    } else {
        throw new IllegalStateException("Invalid brooklyn type "+brooklynClass);
    }
}
 
Example #20
Source File: MultiLocationYamlTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void assertMultiLocation(MultiLocation<?> multiLoc, int expectedSize, List<? extends Predicate<? super Location>> expectedSubLocationPredicates) {
    AvailabilityZoneExtension zones = multiLoc.getExtension(AvailabilityZoneExtension.class);
    List<Location> subLocs = zones.getAllSubLocations();
    assertEquals(subLocs.size(), expectedSize, "zones="+subLocs);
    for (int i = 0; i < subLocs.size(); i++) {
        Location subLoc = subLocs.get(i);
        assertTrue(expectedSubLocationPredicates.get(i).apply(subLoc), "index="+i+"; subLocs="+subLocs);
    }
}
 
Example #21
Source File: AbstractApplication.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected void doStartChildren(Collection<? extends Location> locations) {
    try {
        StartableMethods.start(this, locations);
    } catch (Exception e) {
        Exceptions.propagateIfFatal(e);
        throw new ProblemStartingChildrenException(e);
    }
}
 
Example #22
Source File: ConfigKeyConstraintTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@DataProvider(name = "brooklynObjects")
public Object[][] createBrooklynObjects() throws Exception {
    EntitySpec<TestApplication> appSpec = EntitySpec.create(TestApplication.class)
        .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, shouldSkipOnBoxBaseDirResolution());
    setUp();
    TestApplication app = mgmt.getEntityManager().createEntity(appSpec);

    EntityRequiringConfigKeyInRange entity = app.createAndManageChild(EntitySpec.create(EntityRequiringConfigKeyInRange.class)
            .configure(EntityRequiringConfigKeyInRange.RANGE, 5));
    Policy policy = entity.policies().add(PolicySpec.create(TestPolicy.class));
    Location location = app.newSimulatedLocation();
    return new Object[][]{{entity}, {policy}, {location}};
}
 
Example #23
Source File: ProportionalZoneFailureDetector.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected boolean doHasFailed(Location loc, ZoneHistory zoneHistory) {
    synchronized (zoneHistory) {
        zoneHistory.trimOlderThan(currentTimeMillis() - timeToConsider);
        int numDatapoints = zoneHistory.successes.size() + zoneHistory.failures.size();
        double proportionFailure = ((double)zoneHistory.failures.size()) / ((double)numDatapoints);
        return numDatapoints >= minDatapoints && proportionFailure >= maxProportionFailures;
    }
}
 
Example #24
Source File: FixedListMachineProvisioningLocationRebindTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void assertLocationIdsEqual(Iterable<? extends Location> actual, Iterable<? extends Location> expected) {
    Function<Location, String> locationIdFunction = new Function<Location, String>() {
        @Override public String apply(@Nullable Location input) {
            return (input != null) ? input.getId() : null;
        }
    };
    Set<String> actualIds = MutableSet.copyOf(Iterables.transform(actual, locationIdFunction));
    Set<String> expectedIds = MutableSet.copyOf(Iterables.transform(expected, locationIdFunction));
    
    assertEquals(actualIds, expectedIds);
}
 
Example #25
Source File: LocalLocationManager.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void recursively(Location e, Predicate<AbstractLocation> action) {
    boolean success = action.apply( (AbstractLocation)e );
    if (!success) {
        return; // Don't manage children if action false/unnecessary for parent
    }
    for (Location child : e.getChildren()) {
        recursively(child, action);
    }
}
 
Example #26
Source File: DynamicFabricImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected Entity addCluster(Location location) {
    String locationName = elvis(location.getDisplayName(), location.getDisplayName(), null);
    Map creation = Maps.newLinkedHashMap();
    creation.putAll(getCustomChildFlags());
    if (groovyTruth(getDisplayNamePrefix()) || groovyTruth(getDisplayNameSuffix())) {
        String displayName = "" + elvis(getDisplayNamePrefix(), "") + elvis(locationName, "unnamed") + elvis(getDisplayNameSuffix(),"");
        creation.put("displayName", displayName);
    }
    logger.info("Creating entity in fabric {} at {}{}", new Object[] {this, location, 
            (creation!=null && !creation.isEmpty() ? ", properties "+creation : "") });

    Entity entity = createCluster(location, creation);
    
    if (locationName != null) {
        if (entity.getDisplayName()==null)
            entity.setDisplayName(entity.getEntityType().getSimpleName() +" ("+locationName+")");
        else if (!entity.getDisplayName().contains(locationName)) 
            entity.setDisplayName(entity.getDisplayName() +" ("+locationName+")");
    }
    if (entity.getParent()==null) entity.setParent(this);
    
    // Continue to call manage(), because some uses of NodeFactory (in tests) still instantiate the
    // entity via its constructor
    Entities.manage(entity);
    
    addMember(entity);
    
    return entity;
}
 
Example #27
Source File: NodeJsWebAppEc2LiveTest.java    From brooklyn-library with Apache License 2.0 5 votes vote down vote up
@Override
protected void doTest(Location loc) throws Exception {
    final NodeJsWebAppService server = app.createAndManageChild(EntitySpec.create(NodeJsWebAppService.class)
            .configure("gitRepoUrl", GIT_REPO_URL)
            .configure("appFileName", APP_FILE)
            .configure("appName", APP_NAME));

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

    String url = server.getAttribute(NodeJsWebAppService.ROOT_URL);

    HttpAsserts.assertHttpStatusCodeEventuallyEquals(url, 200);
    HttpAsserts.assertContentContainsText(url, "Hello");
}
 
Example #28
Source File: TestSensorImpl.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void restart() {
    final Collection<Location> locations = Lists.newArrayList(getLocations());
    stop();
    start(locations);
}
 
Example #29
Source File: LocalhostLocationResolverTest.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Test
public void testResolvesDefaultName() throws Exception {
    Location location = resolve("localhost");
    assertTrue(location instanceof LocalhostMachineProvisioningLocation);
    assertEquals(location.getDisplayName(), "localhost");

    Location location2 = resolve("localhost()");
    assertTrue(location2 instanceof LocalhostMachineProvisioningLocation);
    assertEquals(location2.getDisplayName(), "localhost");
}
 
Example #30
Source File: ReflectiveEntityDriverFactory.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
public <D extends EntityDriver> String inferDriverClassName(DriverDependentEntity<D> entity, Class<D> driverInterface, Location location) {
    String driverInterfaceName = driverInterface.getName();
    if (!(location instanceof SshMachineLocation)) return null;
    if (!driverInterfaceName.endsWith("Driver")) {
        throw new IllegalArgumentException(String.format("Driver name [%s] doesn't end with 'Driver'; cannot auto-detect SshDriver class name", driverInterfaceName));
    }
    return Strings.removeFromEnd(driverInterfaceName, "Driver")+"SshDriver";
}