ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator((EntityLocal) getMasterAmbariServer(), "ambari.api", ex.getMessage()); throw ex;
ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(children.get(0), "myKey", "simulate failure"); ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(children.get(0), "myKey");
ServiceNotUpLogic.clearNotUpIndicator(app, Attributes.SERVICE_STATE_ACTUAL); assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true); assertAttributeEqualsEventually(app, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "We're also pretending to block service up"); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, false); assertAttributeEqualsContinually(app, Attributes.SERVICE_UP, true); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "Set then clear a problem to trigger SERVICE_UP enricher"); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); ServiceStateLogic.setExpectedState(entity, Lifecycle.RUNNING); assertAttributeEqualsEventually(app, Attributes.SERVICE_UP, true);
ServiceNotUpLogic.updateNotUpIndicator(this, WEB_CONSOLE_ACCESSIBLE, "No response from the web console yet");
ServiceNotUpLogic.updateNotUpIndicator(this, NGINX_URL_ANSWERS_NICELY, "No response from nginx yet");
ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application starting"); ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); setExpectedStateAndRecordLifecycleEvent(Lifecycle.STARTING); try { ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), Exceptions.collapseText(e)); throw Exceptions.propagate(e); ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL);
protected void markTransitioningEntityOnFireOnRebind(EntityInternal entity, Lifecycle expectedState) { LOG.warn("Entity {} being marked as on-fire because it was in state {} on rebind; indicators={}", new Object[] {entity, expectedState, entity.getAttribute(Attributes.SERVICE_NOT_UP_INDICATORS)}); ServiceStateLogic.setExpectedState(entity, Lifecycle.ON_FIRE); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator( entity, "Task aborted on rebind", if (machine.isAbsent() && provisioningState == ProvisioningTaskState.RUNNING) { LOG.warn("Entity {} was provisioning; VM may have been left running", entity); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator( entity, "VM may be lost on rebind", if (machine.isAbsent() && terminationState == ProvisioningTaskState.RUNNING) { LOG.warn("Entity {} was terminating; VM may have been left running", entity); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator( entity, "VM may be lost on rebind",
ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application starting"); ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); setExpectedStateAndRecordLifecycleEvent(Lifecycle.STARTING); try { ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), Exceptions.collapseText(e)); throw Exceptions.propagate(e); ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL);
ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application stopping"); sensors().set(SERVICE_UP, false); try { throw Exceptions.propagate(e); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application stopped"); setExpectedStateAndRecordLifecycleEvent(Lifecycle.STOPPED);
public void testManuallySettingIndicatorsOnEntities() { ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "We're pretending to block service up"); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, false); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.ON_FIRE); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "We're again pretending to block service up"); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, false); assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.STOPPED); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); assertAttributeEqualsEventually(entity, Attributes.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING);
@Override protected Entity createNode(Location loc, Map<?, ?> flags) { MySqlNode node = (MySqlNode) super.createNode(loc, flags); if (!MySqlClusterUtils.IS_MASTER.apply(node)) { ServiceNotUpLogic.updateNotUpIndicator(node, MySqlSlave.SLAVE_HEALTHY, "Replication not started"); addFeed(FunctionFeed.builder() .entity(node) .period(Duration.FIVE_SECONDS) .poll(FunctionPollConfig.forSensor(MySqlSlave.SLAVE_HEALTHY) .callable(new SlaveStateCallable(node)) .checkSuccess(StringPredicates.isNonBlank()) .onSuccess(new SlaveStateParser(node)) .setOnFailure(false) .description("Polls SHOW SLAVE STATUS")) .build()); node.enrichers().add(Enrichers.builder().updatingMap(Attributes.SERVICE_NOT_UP_INDICATORS) .from(MySqlSlave.SLAVE_HEALTHY) .computing(Functionals.ifNotEquals(true).value("Slave replication status is not healthy") ) .build()); } return node; }
@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; }
@Override public void onEvent(SensorEvent<List<String>> event) { List<String> hosts = event.getValue(); Integer initialClusterSize = entity.getAttribute(AmbariCluster.EXPECTED_AGENTS); Boolean initialised = entity.getAttribute(AmbariCluster.CLUSTER_SERVICES_INITIALISE_CALLED); if (hosts != null && hosts.size() == initialClusterSize && !Boolean.TRUE.equals(initialised)) { try { if (pauseOnDeployment) { entity.getMutableEntityType().addEffector(createDeployClusterEffector()); } else { entity.deployCluster(); } } catch (AmbariApiException ex) { ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator((EntityLocal) entity, "ambari.api", ex.getMessage()); throw ex; } catch (ExtraServiceException ex) { ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator((EntityLocal) entity, "ambari.extra.service", ex.getMessage()); throw ex; } } }
protected void runRebindWhenNotUp(String catalogYaml, String appId) throws Exception { addCatalogItems(catalogYaml); String appYaml = Joiner.on("\n").join( "services:", "- type: " + appId); Entity app = createStartWaitAndLogApplication(appYaml); // Make entity go on-fire TestEntity entity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); RecordingSensorEventListener<Object> listener = subscribeToHaSensors(entity); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "Simulating a problem"); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_FAILED)); // Rebind StartableApplication newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); assertHasEnricher(newEntity, ServiceFailureDetector.class); // Confirm ServiceFailureDetector still functions RecordingSensorEventListener<Object> newListener = subscribeToHaSensors(newEntity); ServiceNotUpLogic.clearNotUpIndicator(newEntity, INDICATOR_KEY_1); newListener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_RECOVERED)); newListener.assertEventCount(1); }
protected void onUpdated() { Boolean isRunning = entity.getAttribute(SERVICE_PROCESS_IS_RUNNING); if (Boolean.FALSE.equals(isRunning)) { ServiceNotUpLogic.updateNotUpIndicator(entity, SERVICE_PROCESS_IS_RUNNING, "The software process for this entity does not appear to be running"); return; } if (Boolean.TRUE.equals(isRunning)) { ServiceNotUpLogic.clearNotUpIndicator(entity, SERVICE_PROCESS_IS_RUNNING); return; } // no info on "isRunning" Boolean isUp = entity.getAttribute(Attributes.SERVICE_UP); if (Boolean.TRUE.equals(isUp)) { // if service explicitly set up, then don't apply our rule ServiceNotUpLogic.clearNotUpIndicator(entity, SERVICE_PROCESS_IS_RUNNING); return; } // service not up, or no info ServiceNotUpLogic.updateNotUpIndicator(entity, SERVICE_PROCESS_IS_RUNNING, "No information on whether this service is running"); } }
@Override public void onCallback(String childId, boolean success) { Optional<Entity> child = Iterables.tryFind(getChildren(), EntityPredicates.idEqualTo(childId)); if (child.isPresent()) { ((AsyncEntity)child.get()).onCallback(success); } else { LOG.warn("Child not found with resourceId '"+childId+"'; not injecting state from callback"); } Optional<Entity> unstartedVm = Iterables.tryFind(getChildren(), EntityPredicates.attributeSatisfies(Attributes.SERVICE_STATE_EXPECTED, new Predicate<Lifecycle.Transition>() { @Override public boolean apply(Transition input) { return input == null || input.getState() == Lifecycle.STARTING; }})); if (!unstartedVm.isPresent()) { // No VMs are still starting; we are finished starting ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); } }
protected Entity runTest(String catalogYaml, String appId) throws Exception { addCatalogItems(catalogYaml); String appYaml = Joiner.on("\n").join( "services:", "- type: " + appId); Entity app = createStartWaitAndLogApplication(appYaml); TestEntity entity = (TestEntity) Iterables.find(app.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); assertHasEnricher(entity, ServiceFailureDetector.class); // Confirm ServiceFailureDetector triggers event RecordingSensorEventListener<Object> listener = subscribeToHaSensors(entity); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "Simulate a problem"); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_FAILED)); listener.assertEventCount(1); listener.clearEvents(); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_RECOVERED)); listener.assertEventCount(1); return app; }
@Test(groups="Broken") public void testStartsThenChildFailsButWithQuorumCausesAppToSucceed() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .configure(StartableApplication.UP_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne()) .configure(StartableApplication.RUNNING_QUORUM_CHECK, QuorumCheck.QuorumChecks.atLeastOne()) .child(EntitySpec.create(TestEntity.class)) .child(EntitySpec.create(TestEntity.class))); TestEntity child = (TestEntity) Iterables.get(app.getChildren(), 0); app.start(ImmutableList.<Location>of()); assertUpAndRunningEventually(app); for (Entity childr : app.getChildren()) { EntityAsserts.assertAttributeEquals(childr, TestEntity.SERVICE_STATE_ACTUAL, Lifecycle.RUNNING); } ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(child, "myIndicator", "Simulate not-up of child"); assertHealthContinually(app, Lifecycle.RUNNING, true); mgmt.getEntityManager().unmanage(app); }
protected void runRebindWhenHealthy(String catalogYaml, String appId) throws Exception { addCatalogItems(catalogYaml); String appYaml = Joiner.on("\n").join( "services:", "- type: " + appId); createStartWaitAndLogApplication(appYaml); // Rebind StartableApplication newApp = rebind(); TestEntity newEntity = (TestEntity) Iterables.find(newApp.getChildren(), EntityPredicates.displayNameEqualTo("targetEntity")); assertHasEnricher(newEntity, ServiceFailureDetector.class); // Confirm ServiceFailureDetector still functions RecordingSensorEventListener<Object> listener = subscribeToHaSensors(newEntity); ServiceNotUpLogic.updateNotUpIndicator(newEntity, INDICATOR_KEY_1, "Simulate a problem"); listener.assertHasEventEventually(SensorEventPredicates.sensorEqualTo(HASensors.ENTITY_FAILED)); listener.assertEventCount(1); }
@Nullable @Override public Void apply(T node) { Task<Integer> task = sshTaskApply(node); Entities.submit(node, task); task.blockUntilEnded(); Integer result = task.getUnchecked(); if (result != 0) { BrooklynTaskTags.WrappedStream stream = BrooklynTaskTags.stream(task, "stderr"); final String errorMessage = String.format("%s: %s", errorDescription, stream != null ? stream.streamContents.get() : "Unexpected error"); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator((EntityLocal) node, errorKey, errorMessage); throw new RuntimeException(String.format("[Node %s] %s", node.getDisplayName(), errorMessage)); } return null; }