/** @deprecated since 0.6.0; use {@link ConfigKeys#newConfigKeyWithDefault(ConfigKey, Object)} */ public BasicConfigKey(ConfigKey<T> key, T defaultValue) { log.warn("deprecated use of BasicConfigKey(exendedKey) constructor, for "+key+" ("+defaultValue+")"); this.description = key.getDescription(); this.name = checkNotNull(key.getName(), "name"); this.typeToken = checkNotNull(key.getTypeToken(), "type"); this.type = checkNotNull(key.getType(), "type"); this.defaultValue = defaultValue; this.reconfigurable = false; }
public Object setConfig(ConfigKey<?> key, Object v) { Object val; if ((v instanceof Future) || (v instanceof DeferredSupplier)) { // no coercion for these (coerce on exit) val = v; } else if (key instanceof StructuredConfigKey) { // no coercion for these structures (they decide what to do) val = v; } else { try { val = TypeCoercions.coerce(v, key.getType()); } catch (Exception e) { throw new IllegalArgumentException("Cannot coerce or set "+v+" to "+key, e); } } Object oldVal; if (key instanceof StructuredConfigKey) { oldVal = ((StructuredConfigKey)key).applyValueToMap(val, ownConfig); } else { oldVal = ownConfig.put(key, val); } return oldVal; }
if (config.getType().isEnum()) { this.type = Enum.class.getName(); this.defaultValue = (config.getDefaultValue() == null) ? null : ((Enum)config.getDefaultValue()).name(); this.possibleValues = FluentIterable .from(Arrays.asList((Enum[])(config.getType().getEnumConstants()))) .transform(new Function<Enum, Map<String, String>>() { @Nullable
protected Collection<Integer> getRequiredOpenPorts(Entity entity) { Set<Integer> ports = MutableSet.of(22); for (ConfigKey k: entity.getEntityType().getConfigKeys()) { if (PortRange.class.isAssignableFrom(k.getType())) { PortRange p = (PortRange) entity.getConfig(k); if (p != null && !p.isEmpty()) ports.add(p.iterator().next()); } } log.debug("getRequiredOpenPorts detected default {} for {}", ports, entity); return ports; }
ConfigKey key = entry.getKey(); Object value = entry.getValue(); Class<?> type = (key.getType() != null) ? key.getType() : rebindContext.loadClass(key.getTypeName()); if (memento.getEntityReferenceConfigs().contains(entry.getKey())) { value = MementoTransformer.transformIdsToEntities(rebindContext, value, type, true);
/** returns the ports that this entity wants to use; * default implementation returns 22 plus first value for each PortAttributeSensorAndConfigKey config key PortRange. */ protected Collection<Integer> getRequiredOpenPorts() { Set<Integer> ports = MutableSet.of(22); for (ConfigKey k: getEntityType().getConfigKeys()) { if (PortRange.class.isAssignableFrom(k.getType())) { PortRange p = (PortRange)getConfig(k); if (p != null && !p.isEmpty()) ports.add(p.iterator().next()); } } log.debug("getRequiredOpenPorts detected default {} for {}", ports, this); return ports; }
public Object setConfig(ConfigKey<?> key, Object v) { Object val; if ((v instanceof Future) || (v instanceof DeferredSupplier)) { // no coercion for these (coerce on exit) val = v; } else if (key instanceof StructuredConfigKey) { // no coercion for these structures (they decide what to do) val = v; } else { try { val = TypeCoercions.coerce(v, key.getType()); } catch (Exception e) { throw new IllegalArgumentException("Cannot coerce or set "+v+" to "+key, e); } } Object oldVal; if (key instanceof StructuredConfigKey) { oldVal = ((StructuredConfigKey)key).applyValueToMap(val, ownConfig); } else { oldVal = ownConfig.put(key, val); } entity.refreshInheritedConfigOfChildren(); return oldVal; }
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public Response set( String application, String entityToken, String policyToken, String configKeyName, String value ) { Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); ConfigKey<?> ck = policy.getPolicyType().getConfigKey(configKeyName); if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); policy.setConfig((ConfigKey)ck, TypeCoercions.coerce(value, ck.getType())); return Response.status(Response.Status.OK).build(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) @POST @Path("/{config}/set") @ApiOperation(value = "Sets the given config on this policy") @ApiErrors(value = { @ApiError(code = 404, reason = "Could not find application, entity, policy or config key") }) public Response set( @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 = "Policy ID or name", required = true) @PathParam("policy") String policyToken, @ApiParam(value = "Config key ID", required = true) @PathParam("config") String configKeyName, @ApiParam(name = "value", value = "New value for the configuration", required = true) @QueryParam("value") String value ) { Policy policy = brooklyn().getPolicy(application, entityToken, policyToken); ConfigKey<?> ck = policy.getPolicyType().getConfigKey(configKeyName); if (ck == null) throw WebResourceUtils.notFound("Cannot find config key '%s' in policy '%s' of entity '%s'", configKeyName, policy, entityToken); policy.setConfig((ConfigKey)ck, TypeCoercions.coerce(value, ck.getType())); return Response.status(Response.Status.OK).build(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) public <V> EffectorBuilder<T> parameter(ConfigKey<V> key) { return parameter(new BasicParameterType<V>(key.getName(), (Class)key.getType(), key.getDescription(), key.getDefaultValue())); } public EffectorBuilder<T> parameter(ParameterType<?> p) {