Java Code Examples for org.apache.brooklyn.config.ConfigKey#getDescription()

The following examples show how to use org.apache.brooklyn.config.ConfigKey#getDescription() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PolicyTransformer.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
public static PolicyConfigSummary policyConfigSummary(BrooklynRestResourceUtils utils, Entity entity, Policy policy, ConfigKey<?> config, UriBuilder ub) {
    URI applicationUri = serviceUriBuilder(ub, ApplicationApi.class, "get").build(entity.getApplicationId());
    URI entityUri = serviceUriBuilder(ub, EntityApi.class, "get").build(entity.getApplicationId(), entity.getId());
    URI policyUri = serviceUriBuilder(ub, PolicyApi.class, "getStatus").build(entity.getApplicationId(), entity.getId(), policy.getId());
    URI configUri = serviceUriBuilder(ub, PolicyConfigApi.class, "get").build(entity.getApplicationId(), entity.getId(), policy.getId(), config.getName());

    Map<String, URI> links = ImmutableMap.<String, URI>builder()
            .put("self", configUri)
            .put("application", applicationUri)
            .put("entity", entityUri)
            .put("policy", policyUri)
            .build();

    return new PolicyConfigSummary(config.getName(), config.getTypeName(), config.getDescription(), 
            PolicyConfigResource.getStringValueForDisplay(utils, policy, config.getDefaultValue()), 
            config.isReconfigurable(),
            null, null, null, null, null, 
            links);
}
 
Example 2
Source File: ConfigSummary.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public ConfigSummary(ConfigKey<?> config, String label, Double priority, Boolean pinned, Map<String, URI> links) {
    this.name = config.getName();
    this.description = config.getDescription();
    this.reconfigurable = config.isReconfigurable();

    /* Use String, to guarantee it is serializable; otherwise get:
     *   No serializer found for class org.apache.brooklyn.policy.autoscaling.AutoScalerPolicy$3 and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) ) (through reference chain: java.util.ArrayList[9]->org.apache.brooklyn.rest.domain.PolicyConfigSummary["defaultValue"])
     *   at org.codehaus.jackson.map.ser.impl.UnknownSerializer.failForEmpty(UnknownSerializer.java:52)
     */
    this.label = label;
    this.priority = priority;
    this.pinned = pinned;
    this.constraints = ConstraintSerialization.INSTANCE.toJsonList(config);
    if (config.getType().isEnum()) {
        this.type = Enum.class.getName();
        this.defaultValue = config.getDefaultValue() instanceof Enum? ((Enum<?>) config.getDefaultValue()).name() : 
            Jsonya.convertToJsonPrimitive(config.getDefaultValue());
        this.possibleValues = FluentIterable
                .from(Arrays.asList((Enum<?>[])(config.getType().getEnumConstants())))
                .transform(new Function<Enum<?>, Map<String, String>>() {
                    @Nullable
                    @Override
                    public Map<String, String> apply(@Nullable Enum<?> input) {
                        return ImmutableMap.of(
                                "value", input != null ? input.name() : null,
                               "description", input != null ? input.toString() : null);
                    }})
                .toList();
    } else {
        this.type = config.getTypeName();
        this.defaultValue = Jsonya.convertToJsonPrimitive(config.getDefaultValue());
        this.possibleValues = null;
    }
    this.links = (links == null) ? ImmutableMap.<String, URI>of() : ImmutableMap.copyOf(links);
}
 
Example 3
Source File: TestFrameworkAssertions.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected static List<Map<String, Object>> getAsListOfMaps(Entity entity, ConfigKey<Object> key) {
    Object config = entity.getConfig(key);
    Maybe<Map<String, Object>> maybeMap = TypeCoercions.tryCoerce(config, new TypeToken<Map<String, Object>>() {});
    if (maybeMap.isPresent()) {
        return Collections.singletonList(maybeMap.get());
    }

    Maybe<List<Map<String, Object>>> maybeList = TypeCoercions.tryCoerce(config,
        new TypeToken<List<Map<String, Object>>>() {});
    if (maybeList.isPresent()) {
        return maybeList.get();
    }

    throw new FatalConfigurationRuntimeException(key.getDescription() + " is not a map or list of maps");
}
 
Example 4
Source File: ConfigUtils.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** removes the given prefix from the key for configuration purposes; logs warning and does nothing if there is no such prefix.
 * prefix will typically end with a ".".
 * this is useful for configuration purposes when a subsystem uses a short-name config (e.g. "user")
 * but in entity config or at the root (brooklyn.properties) there are longer names (e.g. "brooklyn.ssh.config.user"),
 * and we wish to convert from the longer names to the short-name. */
public static <T> ConfigKey<T> unprefixedKey(String prefix, ConfigKey<T> key) {
    String newName = key.getName();
    if (newName.startsWith(prefix)) newName = newName.substring(prefix.length());
    else log.warn("Cannot remove prefix "+prefix+" from key "+key+" (ignoring)");
    return new BasicConfigKey<T>(key.getTypeToken(), newName, key.getDescription(), key.getDefaultValue());
}
 
Example 5
Source File: Effectors.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public static <V> ParameterType<V> asParameterType(ConfigKey<V> key) {
    return key.hasDefaultValue()
        ? new BasicParameterType<V>(key.getName(), key.getTypeToken(), key.getDescription(), key.getDefaultValue())
        : new BasicParameterType<V>(key.getName(), key.getTypeToken(), key.getDescription());
}