@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; }
@Override public void onEvent(SensorEvent<String> sensorEvent) { Boolean installed = entity.getAttribute(AmbariCluster.CLUSTER_SERVICES_INSTALLED); if (StringUtils.isNotBlank(sensorEvent.getValue()) && sensorEvent.getValue().equals("COMPLETED") && !Boolean.TRUE.equals(installed)) { try { entity.postDeployCluster(); } catch (ExtraServiceException ex) { ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator((EntityLocal) entity, "ambari.extra.service", ex.getMessage()); throw ex; } } }
public static void updateNotUpIndicatorRequiringNonEmptyList(Entity entity, AttributeSensor<? extends Collection<?>> collectionSensor) { Collection<?> nodes = entity.getAttribute(collectionSensor); if (nodes==null || nodes.isEmpty()) ServiceNotUpLogic.updateNotUpIndicator(entity, collectionSensor, "Should have at least one entry"); else ServiceNotUpLogic.clearNotUpIndicator(entity, collectionSensor); } public static void updateNotUpIndicatorRequiringNonEmptyMap(Entity entity, AttributeSensor<? extends Map<?,?>> mapSensor) {
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); }
@Override public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), "starting"); try { for (int i = 0; i < config().get(INITIAL_SIZE); i++) { addChild(EntitySpec.create(AsyncEntity.class)); } StartableMethods.start(this, locations); } catch (Throwable t) { ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), Exceptions.collapseText(t)); ServiceStateLogic.setExpectedState(this, Lifecycle.ON_FIRE); throw Exceptions.propagate(t); } }
@Override public void addNotUpIndicator(String label, String val) { ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, label, val); }
@Override public void setServiceState(Lifecycle state) { sensors().set(HOSTNAME, getHostname()); ServiceStateLogic.setExpectedState(this, state); if (state==Lifecycle.RUNNING) ServiceNotUpLogic.clearNotUpIndicator(this, SERVICE_STATE_ACTUAL); else ServiceNotUpLogic.updateNotUpIndicator(this, SERVICE_STATE_ACTUAL, "Not in RUNNING state"); }
@Override protected void initEnrichers() { super.initEnrichers(); ServiceNotUpLogic.updateNotUpIndicator(this, SERVICE_PROCESS_IS_RUNNING, "No information yet on whether this service is running"); // add an indicator above so that if is_running comes through, the map is cleared and an update is guaranteed enrichers().add(EnricherSpec.create(UpdatingNotUpFromServiceProcessIsRunning.class).uniqueTag("service-process-is-running-updating-not-up")); enrichers().add(EnricherSpec.create(ServiceNotUpDiagnosticsCollector.class).uniqueTag("service-not-up-diagnostics-collector")); }
public static void updateNotUpIndicatorRequiringNonEmptyMap(Entity entity, AttributeSensor<? extends Map<?,?>> mapSensor) { Map<?, ?> nodes = entity.getAttribute(mapSensor); if (nodes==null || nodes.isEmpty()) ServiceNotUpLogic.updateNotUpIndicator(entity, mapSensor, "Should have at least one entry"); else ServiceNotUpLogic.clearNotUpIndicator(entity, mapSensor); }
/** as {@link AbstractEntity#initEnrichers()} but also adding default service not-up and problem indicators from children */ @Override protected void initEnrichers() { super.initEnrichers(); // default app logic; easily overridable by adding a different enricher with the same tag ServiceStateLogic.newEnricherFromChildren().checkChildrenAndMembers() .configure(ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers.UP_QUORUM_CHECK, config().get(UP_QUORUM_CHECK)) .configure(ServiceStateLogic.ComputeServiceIndicatorsFromChildrenAndMembers.RUNNING_QUORUM_CHECK, config().get(RUNNING_QUORUM_CHECK)) .addTo(this); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, Attributes.SERVICE_STATE_ACTUAL, "Application created but not yet started, at "+Time.makeDateString()); }
@Test(groups="Broken") public void testStartsThenChildFailsButWithQuorumCausesAppToStayHealthy() 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); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(child, "myIndicator", "Simulate not-up of child"); assertUpAndRunningEventually(app); }
@Override public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), "starting"); }
@Override public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), "starting"); }
@Override public void onCallback(boolean success) { if (success) { ServiceStateLogic.ServiceNotUpLogic.clearNotUpIndicator(this, START.getName()); } else { ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), "callback reported failure"); } Transition expectedState = sensors().get(Attributes.SERVICE_STATE_EXPECTED); if (expectedState != null && expectedState.getState() == Lifecycle.STARTING) { ServiceStateLogic.setExpectedState(this, Lifecycle.RUNNING); } }
@Override public void start(Collection<? extends Location> locations) { ServiceStateLogic.setExpectedState(this, Lifecycle.STARTING); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(this, START.getName(), "starting"); }
public void testStartsThenOnlyChildFailsCausesAppToFail() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .child(EntitySpec.create(TestEntity.class))); TestEntity child = (TestEntity) Iterables.get(app.getChildren(), 0); app.start(ImmutableList.<Location>of()); assertUpAndRunningEventually(app); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(child, "myIndicator", "Simulate not-up of child"); assertHealthEventually(app, Lifecycle.ON_FIRE, false); }
public void testTwoIndicatorsAreBetterThanOne() { // if we set a not up indicator, entity service up should become false ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_1, "We're pretending to block service up"); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, false); ServiceNotUpLogic.updateNotUpIndicator(entity, INDICATOR_KEY_2, "We're also pretending to block service up"); ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_1); // clearing one indicator is not sufficient assertAttributeEquals(entity, Attributes.SERVICE_UP, false); // but it does not become true when both are cleared ServiceNotUpLogic.clearNotUpIndicator(entity, INDICATOR_KEY_2); assertAttributeEqualsEventually(entity, Attributes.SERVICE_UP, true); }
public void testStartsThenSomeChildFailsCausesAppToFail() throws Exception { TestApplication app = mgmt.getEntityManager().createEntity(EntitySpec.create(TestApplication.class) .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); ServiceStateLogic.ServiceNotUpLogic.updateNotUpIndicator(child, "myIndicator", "Simulate not-up of child"); assertHealthEventually(app, Lifecycle.ON_FIRE, false); }