@Override public PortForwarder get() { PortForwarder result = (PortForwarder) entity.getAttribute(attributeOnEntity); if (result==null) throw new IllegalStateException("No PortForwarder available via "+attributeOnEntity+" on "+entity+" (returned null)"); return result; } });
public static <TKey,TVal> TVal getMapSensorEntry(Entity entity, AttributeSensor<Map<TKey,TVal>> sensor, TKey key) { Map<TKey, TVal> map = entity.getAttribute(sensor); if (map==null) return null; return map.get(key); }
@Override public boolean apply(@Nullable Entity input) { return (input != null) && Objects.equal(input.getAttribute(attribute), val); } };
@Override public String apply(String input) { if (input==null) return null; String subnetHostname = target.getAttribute(SUBNET_HOSTNAME_SENSOR); log.debug("sensor mapper replacing address in "+this+"->"+sensor+", with "+subnetHostname+", where old address in "+target); String output = input; output = replaceIfNotNull(output, target.getAttribute(SoftwareProcess.HOSTNAME), subnetHostname); output = replaceIfNotNull(output, target.getAttribute(SoftwareProcess.ADDRESS), subnetHostname); return output; } });
public JmxHelper(Entity entity) { this(toJmxUrl(entity), entity, entity.getAttribute(UsesJmx.JMX_USER), entity.getAttribute(UsesJmx.JMX_PASSWORD)); if (entity.getAttribute(UsesJmx.JMX_URL) == null) { entity.sensors().set(UsesJmx.JMX_URL, url); } }
@Override public void run() { T val = entity.getAttribute(attribute); Asserts.assertFalse(reject.contains(val), "Attribute " + attribute + " on " + entity + " has disallowed value " + val); } });
/** constructs a JMX URL suitable for connecting to the given entity, being smart about JMX/RMI vs JMXMP */ public static String toJmxUrl(Entity entity) { String url = entity.getAttribute(UsesJmx.JMX_URL); if (url != null) { return url; } else { new JmxSupport(entity, null).setJmxUrl(); url = entity.getAttribute(UsesJmx.JMX_URL); return Preconditions.checkNotNull(url, "Could not find URL for "+entity); } }
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) {
@Override public Integer getFabricSize() { int result = 0; for (Entity child : getChildren()) { result += elvis(child.getAttribute(Changeable.GROUP_SIZE), 0); } return result; }
@Override public boolean apply(Entity input) { if (!("yes".equals(input.getAttribute(MY_ATTRIBUTE)))) { return false; } else if (input.equals(e1)) { LOG.info("testGroupDetectsChangedEntitiesMatchingFilter scanned e1 when MY_ATTRIBUTE is yes; not a bug, but indicates things may be running slowly"); return false; } return true; }}); group.addSubscription(null, MY_ATTRIBUTE, new Predicate<SensorEvent<?>>() {
@Override protected boolean checkMembership(Entity e) { if (!super.checkMembership(e)) return false; if (!"Bob".equalsIgnoreCase(e.getAttribute(TestEntity.NAME))) return false; return true; } }
/** * Convenience for ensuring an individual sensor is set from its config key * (e.g. sub-classes of DynamicWebAppCluster that don't want to set HTTP_PORT etc!) */ public static <T> T apply(Entity entity, AttributeSensorAndConfigKey<?,T> key) { T v = entity.getAttribute(key); if (v!=null) return v; v = key.getAsSensorValue(entity); if (v!=null) entity.sensors().set(key, v); return v; }
public static Maybe<String> findSubnetIp(Entity entity) { String sh = entity.getAttribute(Attributes.SUBNET_ADDRESS); if (sh!=null) return Maybe.of(sh); return findSubnetIp(entity.getLocations()); }
private void assertPasswordOnlyContains(Entity entity, AttributeSensor<String> password, String acceptableChars) { String attribute_2 = entity.getAttribute(password); for (char c : attribute_2.toCharArray()) { Asserts.assertTrue(acceptableChars.indexOf(c) != -1); } }
protected boolean isTransitioningOrStopped() { if (entity==null) return false; Transition expected = entity.getAttribute(Attributes.SERVICE_STATE_EXPECTED); if (expected==null) return false; return (expected.getState()==Lifecycle.STARTING || expected.getState()==Lifecycle.STOPPING || expected.getState()==Lifecycle.STOPPED); }
private void onItemAdded(Entity item) { if (items.add(item)) { subscriptions().subscribe(item, Movable.CONTAINER, eventHandler); sensors().emit(ITEM_ADDED, new ContainerItemPair(item.getAttribute(Movable.CONTAINER), item)); } }
@Override public void onEvent(SensorEvent<Object> event) { if (sourceSensor != null) { // Simulate an event, as though our sourceSensor changed Object value = producer.getAttribute((AttributeSensor<?>)sourceSensor); AbstractTransformer.this.onEvent(new BasicSensorEvent(sourceSensor, producer, value, event.getTimestamp())); } else { // Assume the transform doesn't care about the value - otherwise it would // have declared a sourceSensor! AbstractTransformer.this.onEvent(null); } } };
private ProcessTaskFactory<Integer> execSshTask(Entity entity, String cmd, String summary) { SshMachineLocation machine = EffectorTasks.getSshMachine(entity); return SshTasks.newSshExecTaskFactory(machine, "cd $RUN_DIR\n" + cmd) .allowingNonZeroExitCode() .environmentVariable("RUN_DIR", entity.getAttribute(SoftwareProcess.RUN_DIR)) .summary(summary); }
@Override public void run() { for (Entity member : serverPool.getMembers()) { String jbossUrl = member.getAttribute(WebAppService.ROOT_URL); assertHttpStatusCodeEquals(jbossUrl, 200); } assertHttpStatusCodeEquals(nginxUrl, 200); }});
private void purgeLogs(MySqlCluster cluster, MySqlNode master) { String preFlushBinaryLogFile = getBinaryLogFile(master); ReplicationSnapshot replicationSnapshot = master.getParent().getAttribute(MySqlCluster.REPLICATION_LAST_SLAVE_SNAPSHOT); assertEquals(preFlushBinaryLogFile, replicationSnapshot.getBinLogName()); MySqlClusterTestHelper.execSql(master, "FLUSH LOGS"); String postFlushBinaryLogFile = getBinaryLogFile(master); waitSlavesCatchUp(cluster, postFlushBinaryLogFile); assertNotEquals(postFlushBinaryLogFile, preFlushBinaryLogFile); MySqlClusterTestHelper.execSql(master, "PURGE BINARY LOGS TO '" + postFlushBinaryLogFile + "';"); assertFalse(fileExists(master, preFlushBinaryLogFile)); }