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

The following examples show how to use org.apache.brooklyn.config.ConfigKey#getName() . 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: KubernetesCerts.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
protected Optional<String> getData(ConfigKey<String> dataKey, ConfigKey<String> fileKey, ConfigBag config) {
    String data = Strings.isNonBlank(config.get(dataKey)) ? config.get(dataKey).trim() : null;
    String file = config.get(fileKey);
    String fileData = Strings.isNonBlank(file) ? getFileContents(file).trim() : null;

    if (Strings.isNonBlank(data) && Strings.isNonBlank(fileData)) {
        if (data.equals(fileData)) {
            LOG.warn("Duplicate (matching) configuration for {} and {} (continuing)", dataKey.getName(), fileKey.getName());
        } else {
            throw new IllegalStateException("Duplicate conflicting configuration for " + dataKey.getName() + " and " + fileKey.getName());
        }
    }

    String result = Strings.isNonBlank(data) ? data : (Strings.isNonBlank(fileData) ? fileData : null);
    return Optional.fromNullable(result);
}
 
Example 2
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 3
Source File: ConfigUtilsInternal.java    From brooklyn-server with Apache License 2.0 6 votes vote down vote up
private static ConfigValue getValue(Map<?,?> flags, ConfigKey<?> key) {
    Maybe<Object> val;
    String keyName = key.getName();
    if (flags.containsKey(keyName)) {
        val = Maybe.of(flags.get(keyName));
        flags.remove(keyName);
    } else {
        val = Maybe.absent();
    }
    Map<String, Object> deprecatedValues = new LinkedHashMap<>(key.getDeprecatedNames().size());
    for (String deprecatedName : key.getDeprecatedNames()) {
        if (flags.containsKey(deprecatedName)) {
            deprecatedValues.put(deprecatedName, flags.get(deprecatedName));
            flags.remove(deprecatedName);
        }
    }
    return new ConfigValue(val, deprecatedValues);
}
 
Example 4
Source File: AbstractSoftwareProcessSshDriver.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
private void executeSuccessfully(ConfigKey<String> configKey, String label) {
    if(Strings.isNonBlank(getEntity().getConfig(configKey))) {
        log.debug("Executing {} on entity {}", label, entity.getDisplayName());
        int result = execute(ImmutableList.of(getEntity().getConfig(configKey)), label);
        if (0 != result) {
            log.debug("Executing {} failed with return code {}", label, result);
            throw new IllegalStateException("commands for " + configKey.getName() + " failed with return code " + result);
        }
    }
}
 
Example 5
Source File: AbstractScheduledEffectorPolicy.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
@Override
protected <T> void doReconfigureConfig(ConfigKey<T> key, T val) {
    if (key.isReconfigurable()) {
        return;
    } else {
        throw new UnsupportedOperationException("Reconfiguring key " + key.getName() + " not supported on " + getClass().getSimpleName());
    }
}
 
Example 6
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 7
Source File: ShellAbstractTool.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static <T> T getOptionalVal(Map<String,?> map, ConfigKey<T> keyC) {
    if (keyC==null) return null;
    String key = keyC.getName();
    if (map!=null && map.containsKey(key) && map.get(key) != null) {
        return TypeCoercions.coerce(map.get(key), keyC.getTypeToken());
    } else {
        return keyC.getDefaultValue();
    }
}
 
Example 8
Source File: ShellAbstractTool.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
/** returns the value of the key if specified, otherwise defaultValue */
protected static <T> T getOptionalVal(Map<String,?> map, ConfigKey<T> keyC, T defaultValue) {
    String key = keyC.getName();
    if (map!=null && map.containsKey(key) && map.get(key) != null) {
        return TypeCoercions.coerce(map.get(key), keyC.getTypeToken());
    } else {
        return defaultValue;
    }
}
 
Example 9
Source File: ExecWithLoggingHelpers.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
protected static <T> T getOptionalVal(Map<String,?> map, ConfigKey<T> keyC) {
    if (keyC==null) return null;
    String key = keyC.getName();
    if (map!=null && map.containsKey(key)) {
        return TypeCoercions.coerce(map.get(key), keyC.getTypeToken());
    } else {
        return keyC.getDefaultValue();
    }
}
 
Example 10
Source File: BasicSpecParameter.java    From brooklyn-server with Apache License 2.0 5 votes vote down vote up
public static WeightedParameter getFieldConfig(ConfigKey<?> config, Field configKeyField) {
    if (configKeyField == null) return null;
    CatalogConfig catalogConfig = configKeyField.getAnnotation(CatalogConfig.class);
    String label = config.getName();
    Double priority = null;
    Boolean pinned = Boolean.FALSE;
    if (catalogConfig != null) {
        label = Maybe.fromNullable(catalogConfig.label()).or(config.getName());
        priority = catalogConfig.priority();
        pinned = catalogConfig.pinned();
    }
    @SuppressWarnings({ "unchecked", "rawtypes" })
    SpecParameter<?> param = new BasicSpecParameter(label, pinned, config);
    return new WeightedParameter(priority, param);
}
 
Example 11
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 12
Source File: ShellAbstractTool.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected static Boolean hasVal(Map<String,?> map, ConfigKey<?> keyC) {
    String key = keyC.getName();
    return map.containsKey(key);
}
 
Example 13
Source File: ShellAbstractTool.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected static <T> T getMandatoryVal(Map<String,?> map, ConfigKey<T> keyC) {
    String key = keyC.getName();
    checkArgument(map.containsKey(key), "must contain key '"+keyC+"'");
    return TypeCoercions.coerce(map.get(key), keyC.getTypeToken());
}
 
Example 14
Source File: AbstractEntityAdjunct.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
protected <K> K getRequiredConfig(ConfigKey<K> key) {
    K result = config().get(key);
    if (result==null) 
        throw new NullPointerException("Value required for '"+key.getName()+"' in "+this);
    return result;
}
 
Example 15
Source File: BasicConfigKey.java    From brooklyn-server with Apache License 2.0 4 votes vote down vote up
public Builder(ConfigKey<T> key) {
    this(key.getName(), key);
}
 
Example 16
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());
}