org.apache.brooklyn.core.entity.lifecycle.Lifecycle Java Examples
The following examples show how to use
org.apache.brooklyn.core.entity.lifecycle.Lifecycle.
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: StopAfterDurationPolicyTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testAppStoppedWhenDurationExpires() { // Using a second app for the subscriber. Otherwise when app is stopped+unmanaged, we might not // receive the last event because all its subscriptions will be closed! final RecordingSensorEventListener<Lifecycle> listener = new RecordingSensorEventListener<>(); Application app2 = mgmt.getEntityManager().createEntity(EntitySpec.create(BasicApplication.class)); app2.subscriptions().subscribe(app, Attributes.SERVICE_STATE_ACTUAL, listener); PolicySpec<StopAfterDurationPolicy> policy = PolicySpec.create(StopAfterDurationPolicy.class) .configure(StopAfterDurationPolicy.LIFETIME, Duration.ONE_MILLISECOND) .configure(StopAfterDurationPolicy.POLL_PERIOD, Duration.ONE_MILLISECOND); app.policies().add(policy); app.start(ImmutableList.of(app.newSimulatedLocation())); Asserts.succeedsEventually(new Runnable() { @Override public void run() { // TODO In tests, have seen duplicate "starting"; and always begins with "stopped"; and have // seen "on-fire" between stopping and stopped! Therefore not using // assertEqualsOrderIgnoringDuplicates. List<Lifecycle> states = ImmutableList.copyOf(listener.getEventValues()); assertContainsOrdered(states, ImmutableList.of(Lifecycle.RUNNING, Lifecycle.STOPPING, Lifecycle.STOPPED)); }}); }
Example #2
Source File: TestEndpointReachableTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test(groups="Integration") public void testHardcodedEndpointNotReachable() throws Exception { HostAndPort unusedPort = findUnusedPort(); TestEndpointReachable test = app.createAndManageChild(EntitySpec.create(TestEndpointReachable.class) .configure(TestEndpointReachable.TARGET_ENTITY, app) .configure(TestEndpointReachable.ENDPOINT, unusedPort.toString()) .configure(TestEndpointReachable.TIMEOUT, Duration.millis(100))); try { app.start(ImmutableList.of(loc)); } catch (Exception e) { // It should fail to start Exceptions.propagateIfFatal(e); LOG.debug("As desired, failed to start app with TestEndpointReachable: "+e.toString()); } EntityAsserts.assertAttributeEqualsEventually(test, TestEndpointReachable.SERVICE_UP, false); EntityAsserts.assertAttributeEqualsEventually(test, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); }
Example #3
Source File: RiakNodeEc2LiveTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Test(groups = {"Live"}) public void testWithOnlyPort22() throws Exception { // CentOS-6.3-x86_64-GA-EBS-02-85586466-5b6c-4495-b580-14f72b4bcf51-ami-bb9af1d2.1 jcloudsLocation = mgmt.getLocationRegistry().getLocationManaged(LOCATION_SPEC, ImmutableMap.of( "tags", ImmutableList.of(getClass().getName()), "imageId", "us-east-1/ami-a96b01c0", "hardwareId", SMALL_HARDWARE_ID)); RiakNode server = app.createAndManageChild(EntitySpec.create(RiakNode.class) .configure(RiakNode.PROVISIONING_PROPERTIES.subKey(CloudLocationConfig.INBOUND_PORTS.getName()), ImmutableList.of(22)) .configure(RiakNode.USE_HTTP_MONITORING, false)); app.start(ImmutableList.of(jcloudsLocation)); EntityAsserts.assertAttributeEqualsEventually(server, Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsEventually(server, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); Integer port = server.getAttribute(RiakNode.RIAK_PB_PORT); assertNotNull(port); assertViaSshLocalPortListeningEventually(server, port); }
Example #4
Source File: DynamicFabricTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testDifferentFirstMemberSpec() throws Exception { DynamicFabric fabric = app.createAndManageChild(EntitySpec.create(DynamicFabric.class) .configure(DynamicFabric.FIRST_MEMBER_SPEC, EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME, "first")) .configure(DynamicFabric.MEMBER_SPEC, EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME, "non-first")) .configure(DynamicFabric.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.alwaysTrue())); List<Location> locs = ImmutableList.of(loc1, loc2, loc3); fabric.start(locs); EntityAsserts.assertAttributeEqualsEventually(fabric, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); assertTrue(fabric.getAttribute(Attributes.SERVICE_UP)); assertEquals(fabric.getMembers().size(), 3); assertFirstAndNonFirstCounts(fabric.getMembers(), 1, 2); }
Example #5
Source File: SoftwareProcessEntityRebindTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testCreatesDriverAfterRebind() 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); ServiceProblemsLogic.updateProblemsIndicator(origE, "test", "fire"); EntityAsserts.assertAttributeEqualsEventually(origE, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); newApp = rebind(); MyService newE = (MyService) Iterables.getOnlyElement(newApp.getChildren()); assertTrue(newE.getDriver() != null, "driver should be initialized"); }
Example #6
Source File: ApplicationResourceIntegrationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test(groups="Integration", dependsOnMethods = { "testListSensors", "testListEntities" }) public void testTriggerStopEffector() throws Exception { Response response = client().path("/applications/simple-app/entities/simple-ent/effectors/stop") .type(MediaType.APPLICATION_JSON_TYPE) .post(toJsonEntity(ImmutableMap.of())); assertEquals(response.getStatus(), Response.Status.ACCEPTED.getStatusCode()); final URI stateSensor = URI.create("/applications/simple-app/entities/simple-ent/sensors/service.state"); final String expectedStatus = Lifecycle.STOPPED.toString(); Asserts.succeedsEventually(MutableMap.of("timeout", 60 * 1000), new Runnable() { @Override public void run() { // Accept with and without quotes; if don't specify "Accepts" header, then // might get back json or plain text (depending on compiler / java runtime // used for SensorApi!) String val = client().path(stateSensor).get(String.class); assertTrue(expectedStatus.equalsIgnoreCase(val) || ("\""+expectedStatus+"\"").equalsIgnoreCase(val), "state="+val); } }); }
Example #7
Source File: BrooklynNodeImpl.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override public Void call(ConfigBag parameters) { MutableMap<String, String> formParams = MutableMap.of(); Lifecycle initialState = entity().getAttribute(Attributes.SERVICE_STATE_ACTUAL); ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING); for (ConfigKey<?> k: new ConfigKey<?>[] { STOP_APPS_FIRST, FORCE_SHUTDOWN_ON_ERROR, SHUTDOWN_TIMEOUT, REQUEST_TIMEOUT, DELAY_FOR_HTTP_RETURN }) formParams.addIfNotNull(k.getName(), toNullableString(parameters.get(k))); try { log.debug("Shutting down "+entity()+" with "+formParams); HttpToolResponse resp = ((BrooklynNode)entity()).http() .post("/v1/server/shutdown", ImmutableMap.of("Brooklyn-Allow-Non-Master-Access", "true"), formParams); if (resp.getResponseCode() != HttpStatus.SC_NO_CONTENT) { throw new IllegalStateException("Response code "+resp.getResponseCode()); } } catch (Exception e) { Exceptions.propagateIfFatal(e); throw new PropagatedRuntimeException("Error shutting down remote node "+entity()+" (in state "+initialState+"): "+Exceptions.collapseText(e), e); } ServiceNotUpLogic.updateNotUpIndicator(entity(), SHUTDOWN.getName(), "Shutdown of remote node has completed successfuly"); return null; }
Example #8
Source File: AsyncApplicationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testStartAndStopWithVanillaChild() throws Exception { app = mgmt.getEntityManager().createEntity(EntitySpec.create(AsyncApplication.class) .configure(AsyncApplication.DESTROY_ON_STOP, false)); TestEntity child = app.addChild(EntitySpec.create(TestEntity.class)); app.start(ImmutableList.of()); assertStateEventually(child, Lifecycle.RUNNING, Lifecycle.RUNNING, true); assertStateEventually(app, Lifecycle.RUNNING, Lifecycle.RUNNING, true); app.stop(); assertTrue(Entities.isManaged(app)); assertTrue(Entities.isManaged(child)); assertStateEventually(child, Lifecycle.STOPPED, Lifecycle.STOPPED, false); assertStateEventually(app, Lifecycle.STOPPED, Lifecycle.STOPPED); }
Example #9
Source File: ParallelTestCaseImpl.java From brooklyn-server with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void stop() { // Let everyone know we're stopping (so that the GUI shows the correct icon). sensors().set(Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPING); // Get an unsubmitted task for stopping all the children of this entity in parallel. final TaskAdaptable<?> taskAdaptable = StartableMethods.stoppingChildren(this); logger.trace("{}, TaskAdaptable: {}", this, taskAdaptable); try { // Submit the task to the ExecutionManager so that they actually get stopped // and then wait until all the parallel entities have completed. submitTaskAndWait(taskAdaptable); // Let everyone know we've stopped successfully (changes the icon in the GUI). logger.debug("Tasks successfully run. Update state of {} to STOPPED.", this); setServiceState(false, Lifecycle.STOPPED); } catch (Throwable t) { logger.debug("Tasks NOT successfully run. Update state of {} to ON_FIRE.", this); setServiceState(false, Lifecycle.ON_FIRE); throw Exceptions.propagate(t); } }
Example #10
Source File: TestEndpointReachableTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test(groups="Integration") public void testSensorEndpointNotReachable() throws Exception { AttributeSensor<String> sensor = Sensors.newStringSensor("test.reachable.endpoint"); HostAndPort unusedPort = findUnusedPort(); TestEndpointReachable test = app.createAndManageChild(EntitySpec.create(TestEndpointReachable.class) .configure(TestEndpointReachable.TARGET_ENTITY, app) .configure(TestEndpointReachable.ENDPOINT, unusedPort.toString()) .configure(TestEndpointReachable.TIMEOUT, Duration.millis(100))); app.sensors().set(sensor, unusedPort.toString()); try { app.start(ImmutableList.of(loc)); } catch (Exception e) { // It should fail to start Exceptions.propagateIfFatal(e); LOG.debug("As desired, failed to start app with TestEndpointReachable: "+e.toString()); } EntityAsserts.assertAttributeEqualsEventually(test, TestEndpointReachable.SERVICE_UP, false); EntityAsserts.assertAttributeEqualsEventually(test, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); }
Example #11
Source File: MongoDBEc2LiveTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Test(groups = {"Live"}) public void testWithOnlyPort22() throws Exception { // CentOS-6.3-x86_64-GA-EBS-02-85586466-5b6c-4495-b580-14f72b4bcf51-ami-bb9af1d2.1 jcloudsLocation = mgmt.getLocationRegistry().getLocationManaged(LOCATION_SPEC, ImmutableMap.of( "tags", ImmutableList.of(getClass().getName()), "imageId", "us-east-1/ami-a96b01c0", "hardwareId", SMALL_HARDWARE_ID)); MongoDBServer server = app.createAndManageChild(EntitySpec.create(MongoDBServer.class) .configure(MongoDBServer.PROVISIONING_PROPERTIES.subKey(CloudLocationConfig.INBOUND_PORTS.getName()), ImmutableList.of(22)) .configure(MongoDBServer.USE_CLIENT_MONITORING, false)); app.start(ImmutableList.of(jcloudsLocation)); EntityAsserts.assertAttributeEqualsEventually(server, Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsEventually(server, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); Integer port = server.getAttribute(MongoDBServer.PORT); assertNotNull(port); assertViaSshLocalPortListeningEventually(server, port); }
Example #12
Source File: AsyncApplicationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testStartWithAsyncChildrenFirstChildFails() throws Exception { AsyncEntity child1 = app.addChild(EntitySpec.create(AsyncEntity.class)); AsyncEntity child2 = app.addChild(EntitySpec.create(AsyncEntity.class)); app.start(ImmutableList.of()); assertStateEventually(app, Lifecycle.STARTING, Lifecycle.STARTING, false); // First child fails child1.addNotUpIndicator("simulatedFailure", "my failure"); child1.setExpected(Lifecycle.RUNNING); assertStateEventually(child1, Lifecycle.RUNNING, Lifecycle.ON_FIRE, false); assertStateEventually(child2, Lifecycle.STARTING, Lifecycle.STARTING, false); assertStateEventually(app, Lifecycle.STARTING, Lifecycle.ON_FIRE, false); // Second child starts child2.clearNotUpIndicators(); child2.setExpected(Lifecycle.RUNNING); assertStateEventually(child1, Lifecycle.RUNNING, Lifecycle.ON_FIRE, false); assertStateEventually(child2, Lifecycle.RUNNING, Lifecycle.RUNNING, true); assertStateEventually(app, Lifecycle.RUNNING, Lifecycle.ON_FIRE, false); }
Example #13
Source File: AbstractBlueprintTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
protected void assertNoFires(final Entity app) { EntityAsserts.assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); Asserts.succeedsEventually(new Runnable() { @Override public void run() { for (Entity entity : Entities.descendantsAndSelf(app)) { assertNotEquals(entity.getAttribute(Attributes.SERVICE_STATE_ACTUAL), Lifecycle.ON_FIRE); assertNotEquals(entity.getAttribute(Attributes.SERVICE_UP), false); if (entity instanceof SoftwareProcess) { EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_UP, Boolean.TRUE); } } }}); }
Example #14
Source File: AsyncApplicationImpl.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override public void setEntity(EntityLocal entity) { if (!(entity instanceof AsyncApplicationImpl)) { throw new IllegalArgumentException("enricher designed to work only with async-apps"); } if (!isRebinding() && Boolean.FALSE.equals(config().get(SUPPRESS_DUPLICATES))) { throw new IllegalArgumentException("Must not set "+SUPPRESS_DUPLICATES+" to false when using "+this); } super.setEntity(entity); if (suppressDuplicates==null) { // only publish on changes, unless it is configured otherwise suppressDuplicates = true; } // Need to update again, e.g. if stop() effector marks this as expected=stopped. // There'd be a risk of infinite loop if we didn't suppressDuplicates! subscriptions().subscribe(entity, Attributes.SERVICE_STATE_EXPECTED, new SensorEventListener<Lifecycle.Transition>() { @Override public void onEvent(SensorEvent<Lifecycle.Transition> event) { onUpdated(); }}); }
Example #15
Source File: ServiceFailureDetectorTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test(groups="Integration") // Has a 1 second wait public void testOnFireAfterDelay() throws Exception { e1.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class) .configure(ServiceFailureDetector.SERVICE_ON_FIRE_STABILIZATION_DELAY, Duration.ONE_SECOND)); // Make the entity fail e1.sensors().set(TestEntity.SERVICE_UP, true); ServiceStateLogic.setExpectedState(e1, Lifecycle.RUNNING); EntityAsserts.assertAttributeEqualsEventually(e1, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); e1.sensors().set(TestEntity.SERVICE_UP, false); assertEquals(e1.getAttribute(TestEntity.SERVICE_STATE_ACTUAL), Lifecycle.RUNNING); Time.sleep(Duration.millis(100)); assertEquals(e1.getAttribute(TestEntity.SERVICE_STATE_ACTUAL), Lifecycle.RUNNING); EntityAsserts.assertAttributeEqualsEventually(e1, TestEntity.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); }
Example #16
Source File: DependentConfigurationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testAttributeWhenReadyAbortsWhenAlreadyOnFireByDefault() throws Exception { ServiceStateLogic.setExpectedState(entity, Lifecycle.ON_FIRE); EntityAsserts.assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); final Task<String> t = submit(DependentConfiguration.builder() .attributeWhenReady(entity, TestEntity.NAME) .build()); try { assertDoneEventually(t); fail(); } catch (Exception e) { if (!e.toString().contains("Aborted waiting for ready")) throw e; } }
Example #17
Source File: PrimaryRunningEnricher.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override public void onEvent(SensorEvent<Object> event) { Entity primary = entity.getAttribute( Sensors.newSensor(Entity.class, config().get(PRIMARY_SENSOR_NAME)) ); if (primary==null) { ServiceNotUpLogic.updateNotUpIndicator(entity, "primary.enricher", "no primary found"); ServiceProblemsLogic.updateProblemsIndicator(entity, "primary.enricher", "no primary found"); } else if (Lifecycle.RUNNING.equals(primary.getAttribute(Attributes.SERVICE_STATE_ACTUAL)) && Boolean.TRUE.equals(primary.getAttribute(Attributes.SERVICE_UP))) { if (ServiceStateLogic.getMapSensorEntry(entity, Attributes.SERVICE_PROBLEMS, "primary.enricher")!=null) { log.info("Primary "+primary+" at "+entity+" detected as healthy"); ServiceProblemsLogic.clearProblemsIndicator(entity, "primary.enricher"); ServiceNotUpLogic.clearNotUpIndicator(entity, "primary.enricher"); } } else { log.warn("Primary "+primary+" at "+entity+" detected as down or otherwise unhealthy"); ServiceProblemsLogic.updateProblemsIndicator(entity, "primary.enricher", "Primary "+primary+" not in healthy state"); } }
Example #18
Source File: SoftwareProcessEntityRebindTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@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 #19
Source File: AsyncApplicationImpl.java From brooklyn-server with Apache License 2.0 | 6 votes |
protected Lifecycle computeExpectedState(Lifecycle oldExpectedState, Lifecycle newActualState) { if (oldExpectedState != Lifecycle.STARTING) { return oldExpectedState; } // Are any of our children still starting? Map<Entity, Lifecycle> values = getValues(SERVICE_STATE_ACTUAL); boolean childIsStarting = values.containsValue(Lifecycle.STARTING) || values.containsValue(Lifecycle.CREATED) || values.containsValue(null); if (!childIsStarting) { // We only transition to expected=RUNNING if all our children are no longer starting. // When actual=running, this matters if quorum != all; // When actual=on_fire, this matters for recovering. return Lifecycle.RUNNING; } return oldExpectedState; }
Example #20
Source File: TestSshCommandIntegrationTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test(groups = "Integration") public void shouldCaptureStdoutAndStderrOfScript() throws Exception { String text = "echo 'a' 'b' && CMDSUFFIX=Suffix && doesNotExist${CMDSUFFIX}"; Path testScript = createTempScript("script", "echo " + text); try { TestSshCommand uptime = app.createAndManageChild(EntitySpec.create(TestSshCommand.class) .configure(TARGET_ENTITY, testEntity) .configure(DOWNLOAD_URL, "file:" + testScript) .configure(ASSERT_OUT, makeAssertions(ImmutableMap.of(CONTAINS, "a b"))) .configure(ASSERT_ERR, makeAssertions(ImmutableMap.of(CONTAINS, "doesNotExistSuffix")))); app.start(ImmutableList.<Location>of()); assertThat(uptime.sensors().get(SERVICE_UP)).isTrue() .withFailMessage("Service should be up"); assertThat(ServiceStateLogic.getExpectedState(uptime)).isEqualTo(Lifecycle.RUNNING) .withFailMessage("Service should be marked running"); } finally { Files.delete(testScript); } }
Example #21
Source File: TomcatServerEc2LiveTest.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Test(groups = {"Live"}) public void testWithOnlyPort22() throws Exception { // CentOS-6.3-x86_64-GA-EBS-02-85586466-5b6c-4495-b580-14f72b4bcf51-ami-bb9af1d2.1 jcloudsLocation = mgmt.getLocationRegistry().getLocationManaged(LOCATION_SPEC, ImmutableMap.of( "tags", ImmutableList.of(getClass().getName()), "imageId", "us-east-1/ami-a96b01c0", "hardwareId", SMALL_HARDWARE_ID)); final TomcatServer server = app.createAndManageChild(EntitySpec.create(TomcatServer.class) .configure(TomcatServer.PROVISIONING_PROPERTIES.subKey(CloudLocationConfig.INBOUND_PORTS.getName()), ImmutableList.of(22)) .configure(TomcatServer.USE_JMX, false) .configure(TomcatServer.OPEN_IPTABLES, true) // .configure(TomcatServer.PRE_INSTALL_COMMAND, BashCommands.sudo("yum upgrade -y ca-certificates --disablerepo=epel")) .configure("war", getTestWar())); app.start(ImmutableList.of(jcloudsLocation)); EntityAsserts.assertAttributeEqualsEventually(server, Attributes.SERVICE_UP, true); EntityAsserts.assertAttributeEqualsEventually(server, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); String url = server.getAttribute(TomcatServer.ROOT_URL); assertNotNull(url); assertViaSshLocalUrlListeningEventually(server, url); }
Example #22
Source File: PhpWebCloudFoundryLiveTest.java From SeaCloudsPlatform with Apache License 2.0 | 6 votes |
@Test(groups = {"Live"}) protected void stopApplicationTest() throws Exception { final PhpCloudFoundryPaasWebApp server = app. createAndManageChild(EntitySpec.create(PhpCloudFoundryPaasWebApp.class) .configure("application-name", "stopped" + APPLICATION_NAME) .configure("application-url", APPLICATION_URL) .location(cloudFoundryPaasLocation)); app.start(ImmutableList.of(cloudFoundryPaasLocation)); Asserts.succeedsEventually(new Runnable() { public void run() { assertTrue(server.getAttribute(Startable.SERVICE_UP)); app.stop(); assertEquals(server.getAttribute(PhpCloudFoundryPaasWebApp .SERVICE_STATE_ACTUAL), Lifecycle.STOPPED); assertFalse(server.getAttribute(Startable.SERVICE_UP)); assertNull(server.getAttribute(PhpCloudFoundryPaasWebApp .SERVICE_PROCESS_IS_RUNNING)); } }); }
Example #23
Source File: GeoscalingDnsServiceImpl.java From brooklyn-library with Apache License 2.0 | 6 votes |
@Override public void destroy() { setServiceState(Lifecycle.STOPPING); if (!isConfigured) return; // Don't leave randomized subdomains configured on our GeoScaling account. if (randomizeSmartSubdomainName) { webClient.login(username, password); Domain primaryDomain = webClient.getPrimaryDomain(primaryDomainName); SmartSubdomain smartSubdomain = (primaryDomain != null) ? primaryDomain.getSmartSubdomain(smartSubdomainName) : null; if (smartSubdomain != null) { log.info("Deleting randomized GeoScaling smart subdomain '"+smartSubdomainName+"."+primaryDomainName+"'"); smartSubdomain.delete(); } webClient.logout(); } super.destroy(); isConfigured = false; }
Example #24
Source File: LiveTestEntity.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Override public void start(final Collection<? extends Location> locs) { LOG.trace("Starting {}", this); callHistory.add("start"); sensors().set(SERVICE_STATE, Lifecycle.STARTING); counter.incrementAndGet(); addLocations(locs); provisioningLocation = (JcloudsLocation) Iterables.find(locs, Predicates.instanceOf(JcloudsLocation.class)); try { obtainedLocation = (JcloudsSshMachineLocation)provisioningLocation.obtain(((LocationInternal)provisioningLocation).config().getBag().getAllConfig()); } catch (NoMachinesAvailableException e) { throw Throwables.propagate(e); } addLocations(ImmutableList.of(obtainedLocation)); sensors().set(SERVICE_STATE, Lifecycle.RUNNING); }
Example #25
Source File: HaPolicyRebindTest.java From brooklyn-server with Apache License 2.0 | 6 votes |
@Test public void testServiceFailureDetectorWorksAfterRebind() throws Exception { origEntity.enrichers().add(EnricherSpec.create(ServiceFailureDetector.class)); // rebind TestApplication newApp = rebind(); final TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), Predicates.instanceOf(TestEntity.class)); newApp.getManagementContext().getSubscriptionManager().subscribe(newEntity, HASensors.ENTITY_FAILED, eventListener); newEntity.sensors().set(TestEntity.SERVICE_UP, true); ServiceStateLogic.setExpectedState(newEntity, Lifecycle.RUNNING); // trigger the failure newEntity.sensors().set(TestEntity.SERVICE_UP, false); assertHasEventEventually(HASensors.ENTITY_FAILED, Predicates.<Object>equalTo(newEntity), null); assertEquals(events.size(), 1, "events="+events); }
Example #26
Source File: AbstractApplication.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** * Default stop will stop all Startable children */ @Override public void stop() { logApplicationLifecycle("Stopping"); setExpectedStateAndRecordLifecycleEvent(Lifecycle.STOPPING); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application stopping"); sensors().set(SERVICE_UP, false); try { doStop(); } catch (Exception e) { setExpectedStateAndRecordLifecycleEvent(Lifecycle.ON_FIRE); log.warn("Error stopping application " + this + " (rethrowing): "+e); throw Exceptions.propagate(e); } ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application stopped"); setExpectedStateAndRecordLifecycleEvent(Lifecycle.STOPPED); logApplicationLifecycle("Stopped"); if (getParent()==null && Boolean.TRUE.equals(getConfig(DESTROY_ON_STOP))) { synchronized (this) { //TODO review mgmt destroy lifecycle // we don't necessarily want to forget all about the app on stop, //since operator may be interested in things recently stopped; //but that could be handled by the impl at management //(keeping recently unmanaged things) // however unmanaging must be done last, _after_ we stop children and set attributes getEntityManager().unmanage(this); } } }
Example #27
Source File: MachineLifecycleEffectorTasks.java From brooklyn-server with Apache License 2.0 | 5 votes |
/** runs the tasks needed to start, wrapped by setting {@link Attributes#SERVICE_STATE_EXPECTED} appropriately */ public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(entity(), Lifecycle.STARTING); try { startInLocations(locations); DynamicTasks.waitForLast(); ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING); } catch (Throwable t) { ServiceStateLogic.setExpectedState(entity(), Lifecycle.ON_FIRE); throw Exceptions.propagate(t); } }
Example #28
Source File: DynamicClusterTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test public void testDifferentFirstMemberSpec() throws Exception { DynamicCluster cluster = app.createAndManageChild(EntitySpec.create(DynamicCluster.class) .configure(DynamicCluster.FIRST_MEMBER_SPEC, EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME, "first")) .configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(BasicEntity.class).configure(TestEntity.CONF_NAME, "non-first")) .configure(DynamicCluster.UP_QUORUM_CHECK, QuorumChecks.alwaysTrue()) .configure(DynamicCluster.INITIAL_SIZE, 3)); cluster.start(ImmutableList.of(loc)); EntityAsserts.assertAttributeEqualsEventually(cluster, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); assertTrue(cluster.getAttribute(Attributes.SERVICE_UP)); assertEquals(cluster.getMembers().size(), 3); assertFirstAndNonFirstCounts(cluster.getMembers(), 1, 2); // and after re-size cluster.resize(4); // Dumper.dumpInfo(cluster); assertFirstAndNonFirstCounts(cluster.getMembers(), 1, 3); // and re-size to 1 cluster.resize(1); assertFirstAndNonFirstCounts(cluster.getMembers(), 1, 0); // and re-size to 0 cluster.resize(0); assertFirstAndNonFirstCounts(cluster.getMembers(), 0, 0); // and back to 3 cluster.resize(3); assertFirstAndNonFirstCounts(cluster.getMembers(), 1, 2); }
Example #29
Source File: SoftwareProcessRebindNotRunningEntityTest.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Test(dataProvider="terminateOrigManagementContextProvider") public void testRebindWhileProvisioning(boolean terminateOrigManagementContext) throws Exception { final CountDownLatch obtainCalledLatch = newLatch(1); final CountDownLatch obtainBlockedLatch = newLatch(1); MyProvisioningLocation blockingProvisioner = mgmt().getLocationManager().createLocation(LocationSpec.create(MyProvisioningLocation.class) .configure(MyProvisioningLocation.OBTAIN_CALLED_LATCH, obtainCalledLatch) .configure(MyProvisioningLocation.OBTAIN_BLOCKED_LATCH, obtainBlockedLatch) .configure(MyProvisioningLocation.MACHINE_SPEC, machineSpec)); VanillaSoftwareProcess entity = app().createAndManageChild(EntitySpec.create(VanillaSoftwareProcess.class) .configure(VanillaSoftwareProcess.LAUNCH_COMMAND, "myLaunch") .configure(VanillaSoftwareProcess.CHECK_RUNNING_COMMAND, "myCheckRunning")); startAsync(app(), ImmutableList.of(blockingProvisioner)); awaitOrFail(obtainCalledLatch, Asserts.DEFAULT_LONG_TIMEOUT); EntityAsserts.assertAttributeEquals(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STARTING); EntityAsserts.assertAttributeEquals(entity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, AttributesInternal.ProvisioningTaskState.RUNNING); TestApplication newApp = rebind(RebindOptions.create().terminateOrigManagementContext(terminateOrigManagementContext)); final VanillaSoftwareProcess newEntity = (VanillaSoftwareProcess) Iterables.find(newApp.getChildren(), Predicates.instanceOf(VanillaSoftwareProcess.class)); assertMarkedAsOnfire(newEntity, Lifecycle.STARTING); assertMarkedAsOnfire(newApp, Lifecycle.STARTING); assertMarkedAsVmLost(newEntity, Lifecycle.STARTING); // Expect the marker to have been cleared on rebind (sensible because task is not running). EntityAsserts.assertAttributeEquals(newEntity, AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE, null); EntityAsserts.assertAttributeEquals(newEntity, AttributesInternal.INTERNAL_TERMINATION_TASK_STATE, null); }
Example #30
Source File: EntityLaunchListener.java From brooklyn-server with Apache License 2.0 | 5 votes |
@Override public void onEvent(SensorEvent<Lifecycle> event) { if (event.getValue() == Lifecycle.RUNNING) { Task<?>launchTask = getLatestLaunchTask(enricher.getEntity()); if (launchTask != null) { launchTaskRef.set(launchTask); if (!launchTask.isDone()) { launchTask.addListener(this, enricher.getEntityExecutionContext()); } if (launchTask.isDone()) { run(); } } } }