private void setEntityStatus(Entity entity, MachinePoolMemberStatus status) { ((EntityInternal) entity).sensors().set(SERVER_STATUS, status); }
@Override public Boolean call() throws Exception { ProvisioningTaskState state = entity().sensors().get(AttributesInternal.INTERNAL_PROVISIONING_TASK_STATE); return (state != ProvisioningTaskState.RUNNING); }}) .backoffTo(Duration.FIVE_SECONDS)
public static <K, V> V put(Entity entity, AttributeSensor<Map<K,V>> attribute, K key, V value) { Map<K, V> oldMap = entity.getAttribute(attribute); Map<K, V> newMap = MutableMap.copyOf(oldMap); V oldVal = newMap.put(key, value); ((EntityInternal)entity).sensors().set(attribute, newMap); return oldVal; }
/** * Nulls the attached entity's hostname, address, subnet hostname and subnet address sensors * and removes the given machine from its locations. */ protected void clearEntityLocationAttributes(Location machine) { entity().removeLocations(ImmutableList.of(machine)); entity().sensors().set(Attributes.HOSTNAME, null); entity().sensors().set(Attributes.ADDRESS, null); entity().sensors().set(Attributes.SUBNET_HOSTNAME, null); entity().sensors().set(Attributes.SUBNET_ADDRESS, null); }
public static <K, V> V remove(Entity entity, AttributeSensor<Map<K,V>> attribute, K key) { Map<K, V> oldMap = entity.getAttribute(attribute); Map<K, V> newMap = MutableMap.copyOf(oldMap); V oldVal = newMap.remove(key); ((EntityInternal)entity).sensors().set(attribute, newMap); return oldVal; } }
@Override protected void postStartCustom() { boolean result = false; result |= tryCheckStartPid(); result |= tryCheckStartService(); result |= tryCheckStartWindowsService(); if (!result) { log.warn("No way to check whether "+entity()+" is running; assuming yes"); } entity().sensors().set(SoftwareProcess.SERVICE_UP, true); super.postStartCustom(); }
private static void setExpectedState(Entity entity, Lifecycle state, boolean waitBrieflyForServiceUpIfRunning) { if (waitBrieflyForServiceUpIfRunning) { waitBrieflyForServiceUpIfStateIsRunning(entity, state); } ((EntityInternal)entity).sensors().set(Attributes.SERVICE_STATE_EXPECTED, new Lifecycle.Transition(state, new Date())); Maybe<Enricher> enricher = EntityAdjuncts.tryFindWithUniqueTag(entity.enrichers(), ComputeServiceState.DEFAULT_ENRICHER_UNIQUE_TAG); if (enricher.isPresent() && enricher.get() instanceof ComputeServiceState) { ((ComputeServiceState)enricher.get()).onEvent(null); } }
@Test public void testAddSensorValueThroughEntity() throws Exception{ entity.sensors().set(TEST_SENSOR, "abc"); assertEquals(entity.getEntityType().getSensors(), ImmutableSet.builder().addAll(DEFAULT_SENSORS).add(TEST_SENSOR).build()); assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(SENSOR_ADDED, entity, TEST_SENSOR))); }
@Override protected void postStartCustom() { boolean result = false; result |= tryCheckStartPid(); result |= tryCheckStartService(); result |= tryCheckStartWindowsService(); if (!result) { log.warn("No way to check whether "+entity()+" is running; assuming yes"); } entity().sensors().set(SoftwareProcess.SERVICE_UP, true); super.postStartCustom(); }
@Override public Void call(ConfigBag parameters) { synchronized (PublishingEffector.class) { Collection<Object> values = entity().sensors().get(REMOVED_EFFECTOR_VALUES); if (values == null) { values = Sets.newHashSet(); } final Object v = parameters.getStringKey("value"); values.add(v); entity().sensors().set(REMOVED_EFFECTOR_VALUES, values); return null; } } }
@Override public String call() { if (entity().getAttribute(SoftwareProcess.SERVICE_STATE_ACTUAL) == Lifecycle.STOPPED) { log.debug("Skipping stop of entity " + entity() + " when already stopped"); return "Already stopped"; } ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING); entity().sensors().set(SoftwareProcess.SERVICE_UP, false); preStopCustom(); return null; } }
@Override public void run() { DynamicTasks.waitForLast(); entity().sensors().set(SoftwareProcess.INSTALL_DIR, (String)null); entity().config().set(SoftwareProcess.INSTALL_UNIQUE_LABEL, (String)null); entity().config().putAll(parameters.getAllConfig()); entity().sensors().set(BrooklynNode.DOWNLOAD_URL, entity().getConfig(DOWNLOAD_URL)); // Setting SUGGESTED_VERSION will result in an new empty INSTALL_FOLDER, but clear it // just in case the user specified already installed version. ((BrooklynNodeDriver)((DriverDependentEntity<?>)entity()).getDriver()).clearInstallDir(); } }).build());
public String getJmxAgentJarDestinationFilePath() { // cache the local path so we continue to work post-rebind to a different version String result = getEntity().getAttribute(JMX_AGENT_LOCAL_PATH); if (Strings.isNonBlank(result)) return result; result = getJmxAgentJarDestinationFilePathDefault(); ((EntityInternal)getEntity()).sensors().set(JMX_AGENT_LOCAL_PATH, result); return result; }
@Override public void delete(String application, String entityToken, String sensorName) { final Entity entity = brooklyn().getEntity(application, entityToken); if (!Entitlements.isEntitled(mgmt().getEntitlementManager(), Entitlements.MODIFY_ENTITY, entity)) { throw WebResourceUtils.forbidden("User '%s' is not authorized to modify entity '%s'", Entitlements.getEntitlementContext().user(), entity); } AttributeSensor<?> sensor = findSensor(entity, sensorName); if (log.isDebugEnabled()) log.debug("REST user "+Entitlements.getEntitlementContext()+" deleting sensor "+sensorName); ((EntityInternal)entity).sensors().remove(sensor); }
@Test public void testDslAttributeWhenReady() throws Exception { Entity testEntity = entityWithAttributeWhenReady(); ((EntityInternal) testEntity).sensors().set(Sensors.newStringSensor("foo"), "bar"); Assert.assertEquals(getConfigInTask(testEntity, TestEntity.CONF_NAME), "bar"); }
@Test public void testDslAttributeWhenReadyRebindWhenResolved() throws Exception { Entity testEntity = entityWithAttributeWhenReady(); ((EntityInternal) testEntity).sensors().set(Sensors.newStringSensor("foo"), "bar"); Entity e2 = rebind(testEntity); Assert.assertEquals(getConfigInTask(e2, TestEntity.CONF_NAME), "bar"); }
protected boolean tryCheckStartPid() { if (getPidFile()==null) return false; // if it's still up after 5s assume we are good (default behaviour) Time.sleep(Duration.FIVE_SECONDS); if (!DynamicTasks.queue(SshEffectorTasks.isPidFromFileRunning(getPidFile()).runAsRoot()).get()) { throw new IllegalStateException("The process for "+entity()+" appears not to be running (pid file "+getPidFile()+")"); } // and set the PID entity().sensors().set(Attributes.PID, Integer.parseInt(DynamicTasks.queue(SshEffectorTasks.ssh("cat "+getPidFile()).runAsRoot()).block().getStdout().trim())); return true; }
protected boolean tryCheckStartPid() { if (getPidFile()==null) return false; // if it's still up after 5s assume we are good (default behaviour) Time.sleep(Duration.FIVE_SECONDS); if (!DynamicTasks.queue(SshEffectorTasks.isPidFromFileRunning(getPidFile()).runAsRoot()).get()) { throw new IllegalStateException("The process for "+entity()+" appears not to be running (pid file "+getPidFile()+")"); } // and set the PID entity().sensors().set(Attributes.PID, Integer.parseInt(DynamicTasks.queue(SshEffectorTasks.ssh("cat "+getPidFile()).runAsRoot()).block().getStdout().trim())); return true; }
@Test public void testRemoveSensorThroughEntity() throws Exception{ entity.sensors().set(TEST_SENSOR, "abc"); entity.removeAttribute(TEST_SENSOR); assertFalse(entity.getEntityType().getSensors().contains(TEST_SENSOR), "sensors="+entity.getEntityType().getSensors()); assertEquals(entity.getAttribute(TEST_SENSOR), null); assertEventuallyListenerEventsEqual(ImmutableList.of(BasicSensorEvent.ofUnchecked(SENSOR_ADDED, entity, TEST_SENSOR), BasicSensorEvent.ofUnchecked(SENSOR_REMOVED, entity, TEST_SENSOR))); }
@Override public String call(ConfigBag parameters) { Object name = parameters.getStringKey("name"); entity().sensors().set(Sensors.newStringSensor(SENSOR_LAST_HELLO), Strings.toString(name)); return helloWord()+" "+name; } }).build();