Search in sources :

Example 1 with CustomConfigResolver

use of com.emc.storageos.customconfigcontroller.CustomConfigResolver in project coprhd-controller by CoprHD.

the class CustomConfigHandler method getCustomConfigPreviewValue.

/**
 * Uses the samples provided in the configuration item to generate a resolved
 * name for a given mask, configuration and scope. This can be used to preview
 * and validate a name mask prior to setting it.
 *
 * @param name the configuration type name
 * @param value the name mask to be resolved.
 * @param scope the scope to be used to for deciding which constraints to apply.
 * @param variables a map of variable-name-to-variable-value. This map can contain
 *            a value for all or only some of the name mask variables, or it can be
 *            empty. Any missing variable will be replaced with the variable default.
 * @return the resolved name.
 * @throws CustomConfigControllerException for invalid input.
 */
public String getCustomConfigPreviewValue(String name, String value, StringMap scope, Map<String, String> variables) {
    CustomConfigType item = getCustomConfigType(name);
    Map<DataSourceVariable, Boolean> dsVariables = item.getDataSourceVariables();
    DataSource sampleDatasource = null;
    if (dsVariables != null && !dsVariables.isEmpty()) {
        sampleDatasource = datasourceFactory.getSampleDataSource(name);
    }
    CustomConfigResolver resolver = configResolvers.get(item.getConfigType());
    if (variables != null && !variables.isEmpty()) {
        for (Map.Entry<String, String> entry : variables.entrySet()) {
            sampleDatasource.addProperty(entry.getKey(), entry.getValue());
        }
    }
    // validate the computed value
    resolver.validate(item, scope, value);
    // Resolve the config value
    String computedName = resolver.resolve(item, scope, value, sampleDatasource);
    // validate against the constraints
    List<CustomConfigConstraint> constraints = item.getConstraints();
    String systemType = CustomConfigConstants.DEFAULT_KEY;
    if (scope != null) {
        systemType = scope.get(CustomConfigConstants.SYSTEM_TYPE_SCOPE);
        // host type scope is only available for Hitachi Host Mode Option
        if (systemType == null) {
            systemType = scope.get(CustomConfigConstants.HOST_TYPE_SCOPE);
        }
    }
    for (CustomConfigConstraint constraint : constraints) {
        constraint.validate(computedName, systemType);
    }
    return computedName;
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) CustomConfigResolver(com.emc.storageos.customconfigcontroller.CustomConfigResolver) HashMap(java.util.HashMap) Map(java.util.Map) StringMap(com.emc.storageos.db.client.model.StringMap) DataSourceVariable(com.emc.storageos.customconfigcontroller.DataSourceVariable) DataSource(com.emc.storageos.customconfigcontroller.DataSource) CustomConfigConstraint(com.emc.storageos.customconfigcontroller.CustomConfigConstraint)

Example 2 with CustomConfigResolver

use of com.emc.storageos.customconfigcontroller.CustomConfigResolver in project coprhd-controller by CoprHD.

the class CustomConfigHandler method getComputedCustomConfigValue.

/**
 * Gets the resolved custom name for a given CustomName configuration type
 * name, a scope and the list of values specified in the data source.
 *
 * @param name the configuration type name
 * @param scope the scope to be used to find the configuration value. See {@link #getCustomConfigValue(String, StringMap)} for details.
 * @param dataSource the object containing the variable values
 *            to be used replaced in the CustomName mask.
 * @return resolved custom name for a given CustomName configuration
 */
public String getComputedCustomConfigValue(String name, StringMap scope, DataSource dataSource) throws CustomConfigControllerException {
    CustomConfigType item = getCustomConfigType(name);
    String value = getCustomConfigValue(name, scope);
    CustomConfigResolver resolver = configResolvers.get(item.getConfigType());
    String result = resolver.resolve(item, scope, value, dataSource);
    // Apply the constraints
    List<CustomConfigConstraint> constraints = item.getConstraints();
    String systemType = CustomConfigConstants.DEFAULT_KEY;
    if (scope != null) {
        systemType = scope.get(CustomConfigConstants.SYSTEM_TYPE_SCOPE);
        // host type scope is only available for Hitachi Host Mode Option
        if (systemType == null) {
            systemType = scope.get(CustomConfigConstants.HOST_TYPE_SCOPE);
        }
    }
    for (CustomConfigConstraint constraint : constraints) {
        result = constraint.applyConstraint(result, systemType);
    }
    return result;
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) CustomConfigResolver(com.emc.storageos.customconfigcontroller.CustomConfigResolver) CustomConfigConstraint(com.emc.storageos.customconfigcontroller.CustomConfigConstraint)

Example 3 with CustomConfigResolver

use of com.emc.storageos.customconfigcontroller.CustomConfigResolver in project coprhd-controller by CoprHD.

the class CustomConfigHandler method resolve.

/**
 * Resolves custom name for a given CustomName configuration type
 * name, a scope and the list of values specified in the data source
 *
 * @param name the configuration type name
 * @param scope the scope to be used to find the configuration value.
 * @param dataSource the object containing the variable values
 *            to be used replaced in the CustomName mask.
 * @return resolved custom name for a given CustomName configuration
 */
public String resolve(String name, String scope, DataSource dataSource) throws CustomConfigControllerException {
    StringMap scopeMap = new StringMap();
    CustomConfigType item = getCustomConfigType(name);
    if (item != null) {
        for (String key : item.getScope().keySet()) {
            List<String> scopeVals = java.util.Arrays.asList(item.getScope().get(key).split(","));
            if (scopeVals.contains(scope)) {
                scopeMap.put(key, scope);
            }
        }
    }
    String value = getCustomConfigValue(name, scopeMap);
    CustomConfigResolver resolver = configResolvers.get(item.getConfigType());
    String result = resolver.resolve(item, scopeMap, value, dataSource);
    return result;
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) StringMap(com.emc.storageos.db.client.model.StringMap) CustomConfigResolver(com.emc.storageos.customconfigcontroller.CustomConfigResolver)

Aggregations

CustomConfigResolver (com.emc.storageos.customconfigcontroller.CustomConfigResolver)3 CustomConfigType (com.emc.storageos.customconfigcontroller.CustomConfigType)3 CustomConfigConstraint (com.emc.storageos.customconfigcontroller.CustomConfigConstraint)2 StringMap (com.emc.storageos.db.client.model.StringMap)2 DataSource (com.emc.storageos.customconfigcontroller.DataSource)1 DataSourceVariable (com.emc.storageos.customconfigcontroller.DataSourceVariable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1