@Override boolean matches(EntityDriver driver, String addon) { String actualType = driver.getEntity().getEntityType().getName(); String actualSimpleType = actualType.substring(actualType.lastIndexOf(".")+1); return addonName.equals(addon) && entityType.equalsIgnoreCase(actualSimpleType); } }
@Override boolean matches(EntityDriver driver, String addon) { String actualType = driver.getEntity().getEntityType().getName(); String actualSimpleType = actualType.substring(actualType.lastIndexOf(".")+1); return addon == null && entityType.equalsIgnoreCase(actualSimpleType); } }
private boolean isEntityUp() { if (entity == null) { return false; } else if (entity.getEntityType().getSensors().contains(Startable.SERVICE_UP)) { return Boolean.TRUE.equals(entity.getAttribute(Startable.SERVICE_UP)); } else { return true; } }
private AttributeSensor<?> findSensor(EntityLocal entity, String name) { Sensor<?> s = entity.getEntityType().getSensor(name); if (s instanceof AttributeSensor) return (AttributeSensor<?>) s; return new BasicAttributeSensor<Object>(Object.class, name); }
@Override public List<EntityConfigSummary> list(final String application, final String entityToken) { final EntityLocal entity = brooklyn().getEntity(application, entityToken); return Lists.newArrayList(transform( entity.getEntityType().getConfigKeys(), new Function<ConfigKey<?>, EntityConfigSummary>() { @Override public EntityConfigSummary apply(ConfigKey<?> config) { return EntityTransformer.entityConfigSummary(entity, config); } })); }
public static void apply(EntityLocal entity) { for (Sensor<?> it : entity.getEntityType().getSensors()) { if (it instanceof AttributeSensorAndConfigKey) { apply(entity, (AttributeSensorAndConfigKey<?,?>)it); } } }
private AttributeSensor<?> findSensor(EntityLocal entity, String name) { Sensor<?> s = entity.getEntityType().getSensor(name); if (s instanceof AttributeSensor) return (AttributeSensor<?>) s; return new BasicAttributeSensor<Object>(Object.class, name); }
@Override public List<EffectorSummary> list(final String application, final String entityToken ) { final EntityLocal entity = brooklyn().getEntity(application, entityToken); return Lists.newArrayList(transform( entity.getEntityType().getEffectors(), new Function<Effector<?>, EffectorSummary>() { @Override public EffectorSummary apply(Effector<?> effector) { return EffectorTransformer.effectorSummary(entity, effector); } })); }
/** * @deprecated since 0.5.0; instead rely on {@link DownloadResolverManager} to include local-repo */ protected String getEntityVersionLabel(String separator) { return elvis(entity.getEntityType().getSimpleName(), entity.getClass().getName())+(!NO_VERSION_INFO.equals(getVersion()) ? separator+getVersion() : ""); }
/** * Name to be used in the local repo, when looking for the download file. * If null, will */ public String getDownloadFilename() { return getEntity().getEntityType().getSimpleName().toLowerCase() + "-"+getVersion() + ".tar.gz"; }
@Override public List<SensorSummary> list(final String application, final String entityToken) { final EntityLocal entity = brooklyn().getEntity(application, entityToken); return Lists.newArrayList(transform(filter( entity.getEntityType().getSensors(), new Predicate<Sensor<?>>() { @Override public boolean apply(@Nullable Sensor<?> input) { return input instanceof AttributeSensor; } }), new Function<Sensor<?>, SensorSummary>() { @Override public SensorSummary apply(Sensor<?> sensor) { return SensorTransformer.sensorSummary(entity, sensor); } })); }
@GET @ApiOperation(value = "Fetch the list of effectors", responseClass = "brooklyn.rest.domain.EffectorSummary", multiValueResponse = true) @ApiErrors(value = { @ApiError(code = 404, reason = "Could not find application or entity") }) public List<EffectorSummary> list( @ApiParam(name = "application", value = "Application name", required = true) @PathParam("application") final String application, @ApiParam(name = "entity", value = "Entity name", required = true) @PathParam("entity") final String entityToken ) { final EntityLocal entity = brooklyn().getEntity(application, entityToken); return Lists.newArrayList(transform( entity.getEntityType().getEffectors(), new Function<Effector<?>, EffectorSummary>() { @Override public EffectorSummary apply(Effector<?> effector) { return EffectorSummary.fromEntity(entity, effector); } })); }
final EntityLocal entity = brooklyn().getEntity(application, entityToken); final Effector<?> effector = EffectorUtils.findEffectorMatching(entity.getEntityType().getEffectors(), effectorName, parameters); if (effector == null) { throw WebResourceUtils.notFound("Entity '%s' has no effector with name '%s'", entityToken, effectorName);
@Override public Map<String, Object> batchSensorRead(final String application, final String entityToken ) { final EntityLocal entity = brooklyn().getEntity(application, entityToken); Map<String, Object> sensorMap = Maps.newHashMap(); List<Sensor<?>> sensors = Lists.newArrayList(filter(entity.getEntityType().getSensors(), new Predicate<Sensor<?>>() { @Override public boolean apply(@Nullable Sensor<?> input) { return input instanceof AttributeSensor; } })); for (Sensor<?> sensor : sensors) { Object value = entity.getAttribute(findSensor(entity, sensor.getName())); // TODO type sensorMap.put(sensor.getName(), JsonUtils.toJsonable(value)); } return sensorMap; }
@GET @ApiOperation(value = "Fetch the config keys for a specific application entity", responseClass = "brooklyn.rest.domain.ConfigSummary", multiValueResponse = true) @ApiErrors(value = { @ApiError(code = 404, reason = "Could not find application or entity") }) public List<EntityConfigSummary> list( @ApiParam(value = "Application ID or name", required = true) @PathParam("application") final String application, @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") final String entityToken ) { final EntityLocal entity = brooklyn().getEntity(application, entityToken); return Lists.newArrayList(transform( entity.getEntityType().getConfigKeys(), new Function<ConfigKey<?>, EntityConfigSummary>() { @Override public EntityConfigSummary apply(ConfigKey<?> config) { return EntityConfigSummary.fromEntity(entity, config); } })); }
@GET @ApiOperation(value = "Fetch the sensor list for a specific application entity", responseClass = "brooklyn.rest.domain.SensorSummary", multiValueResponse = true) @ApiErrors(value = { @ApiError(code = 404, reason = "Could not find application or entity") }) public List<SensorSummary> list( @ApiParam(value = "Application ID or name", required = true) @PathParam("application") final String application, @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") final String entityToken ) { final EntityLocal entity = brooklyn().getEntity(application, entityToken); return Lists.newArrayList(transform(filter( entity.getEntityType().getSensors(), new Predicate<Sensor<?>>() { @Override public boolean apply(@Nullable Sensor<?> input) { return input instanceof AttributeSensor; } }), new Function<Sensor<?>, SensorSummary>() { @Override public SensorSummary apply(Sensor<?> sensor) { return SensorSummary.fromEntity(entity, sensor); } })); }
@GET @Path("/current-state") @ApiOperation(value = "Fetch sensor values in batch", notes="Returns a map of sensor name to value") public Map<String, Object> batchSensorRead( @ApiParam(value = "Application ID or name", required = true) @PathParam("application") final String application, @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") final String entityToken ) { final EntityLocal entity = brooklyn().getEntity(application, entityToken); Map<String, Object> sensorMap = Maps.newHashMap(); List<Sensor<?>> sensors = Lists.newArrayList(filter(entity.getEntityType().getSensors(), new Predicate<Sensor<?>>() { @Override public boolean apply(@Nullable Sensor<?> input) { return input instanceof AttributeSensor; } })); for (Sensor<?> sensor : sensors) { Object value = entity.getAttribute(findSensor(entity, sensor.getName())); // TODO type sensorMap.put(sensor.getName(), JsonUtils.toJsonable(value)); } return sensorMap; }
/** @deprecated since 0.6.0 use {@link #toJmxUrl(EntityLocal)} */ public static String toConnectorUrl(EntityLocal entity) { LOG.warn("Using legacy method toConnectorUrl("+entity+") which will only return JMX URLs"); String url = entity.getAttribute(Attributes.JMX_SERVICE_URL); if (url != null) { return url; } else { String host = checkNotNull(entity.getAttribute(Attributes.HOSTNAME)); Integer jmxEntryPort = entity.getAttribute(Attributes.JMX_PORT); if (GroovyJavaMethods.truth(entity.getConfig(UsesJmx.JMX_SSL_ENABLED))) { url = String.format(JMXMP_URL_FORMAT, host, jmxEntryPort); } else { Integer rmiServerPort = entity.getAttribute(Attributes.RMI_REGISTRY_PORT); String context = entity.getAttribute(Attributes.JMX_CONTEXT); url = toConnectorUrl(host, jmxEntryPort, rmiServerPort, context); } if (entity.getEntityType().getSensors().contains(Attributes.JMX_SERVICE_URL)) entity.setAttribute(Attributes.JMX_SERVICE_URL, url); return url; } }
@GET @Path("/{config}") @ApiOperation(value = "Fetch config value", responseClass = "Object") @ApiErrors(value = { @ApiError(code = 404, reason = "Could not find application, entity or config key") }) public String get( @ApiParam(value = "Application ID or name", required = true) @PathParam("application") String application, @ApiParam(value = "Entity ID or name", required = true) @PathParam("entity") String entityToken, @ApiParam(value = "Config key ID", required = true) @PathParam("config") String configKeyName ) { EntityLocal entity = brooklyn().getEntity(application, entityToken); ConfigKey<?> ck = entity.getEntityType().getConfigKey(configKeyName); if (ck==null) ck = new BasicConfigKey<Object>(Object.class, configKeyName); return getValueForDisplay(entity, ((AbstractEntity)entity).getConfigMap().getRawConfig(ck)); }
@Override public String get(String application, String entityToken, String configKeyName) { EntityLocal entity = brooklyn().getEntity(application, entityToken); ConfigKey<?> ck = entity.getEntityType().getConfigKey(configKeyName); if (ck==null) ck = new BasicConfigKey<Object>(Object.class, configKeyName); return getValueForDisplay(entity, ((AbstractEntity)entity).getConfigMap().getRawConfig(ck)); }