Search in sources :

Example 1 with CustomConfigType

use of com.emc.storageos.customconfigcontroller.CustomConfigType 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 CustomConfigType

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

the class CustomConfigHandler method getTemplateConfigs.

/**
 * Computes the list of system-defined custom configurations that should
 * be exist in the database from the custom configuration templates. Each
 * scope must have a system-defined default custom configuration . If none
 * is specified in the template, than the template 'default' will be used.
 *
 * @return a map of the system-defined custom configurations that need to be
 *         in the database keyed by the custom configuration unique and fully qualified label
 */
private Map<String, CustomConfig> getTemplateConfigs() {
    logger.debug("getTemplateConfigs started");
    CustomConfig customConfig;
    // the default value for the scope.
    String defaultValue;
    // the 'default' default value as defined in the template
    String masterDefaultValue;
    Map<String, String> defaultValuesMap;
    List<CustomConfigType> templates = configTypeProvider.getCustomConfigTypes();
    Map<String, CustomConfig> customConfigsMap = new HashMap<String, CustomConfig>();
    for (CustomConfigType template : templates) {
        defaultValuesMap = template.getDefaultValues();
        // if the template defines a 'default' default value, get it
        masterDefaultValue = defaultValuesMap.get(CustomConfigConstants.DEFAULT_KEY);
        for (String key : template.getScope().keySet()) {
            String[] vals = template.getScope().get(key).split(",");
            for (String val : vals) {
                if (defaultValuesMap.containsKey(val)) {
                    // if a default value is specified in the template for this scope, use it
                    defaultValue = defaultValuesMap.get(val);
                } else if (masterDefaultValue != null) {
                    // if a default value is NOT specified in the template for this scope,
                    // use the template 'default' default value
                    defaultValue = masterDefaultValue;
                } else {
                    // A mistake made in the config file, either a scope or a 'default' default must be specified
                    throw CustomConfigControllerException.exceptions.customConfigScopeWithNoDefault(template.getName(), key, val);
                }
                logger.debug("System-define CutomConfig item for {} " + " and scope {}:{} is computed", new Object[] { template.getName(), key, val });
                customConfig = createSystemConfig(template, key, val, defaultValue);
                customConfigsMap.put(customConfig.getLabel(), customConfig);
            }
        }
    }
    logger.debug("getTemplateConfigs ended and found a total of {} " + " system-defined configs in the templates", customConfigsMap.size());
    return customConfigsMap;
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) CustomConfig(com.emc.storageos.db.client.model.CustomConfig) HashMap(java.util.HashMap)

Example 3 with CustomConfigType

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

the class CustomConfigHandler method getComputedCustomConfigValue.

/**
 * This is a short cut for the controller code to avoid having to create
 * a scope. In the future a scope factory can be added.
 */
public String getComputedCustomConfigValue(String name, String scope, DataSource sources) throws CustomConfigControllerException {
    StringMap map = 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)) {
                map.put(key, scope);
            }
        }
    }
    return getComputedCustomConfigValue(name, map, sources);
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) StringMap(com.emc.storageos.db.client.model.StringMap)

Example 4 with CustomConfigType

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

the class CustomConfigService method getCustomConfigTypes.

/**
 * List config types.
 *
 * @brief List of config types
 * @return The list of config types.
 */
@GET
@Path("/types")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public CustomConfigTypeList getCustomConfigTypes() {
    List<CustomConfigType> items = customConfigHandler.getCustomConfigTypes();
    List<RelatedConfigTypeRep> types = new ArrayList<RelatedConfigTypeRep>();
    for (CustomConfigType item : items) {
        RelatedConfigTypeRep type = new RelatedConfigTypeRep();
        // build config type Link
        String service = ResourceTypeEnum.CONFIG_TYPE.getService();
        StringBuilder build = (new StringBuilder(service)).append('/').append(item.getName());
        type.setConfigName(item.getName());
        try {
            type.setSelfLink(new RestLinkRep("self", new URI(build.toString())));
        } catch (URISyntaxException e) {
        // it should not happen
        }
        types.add(type);
    }
    return new CustomConfigTypeList(types);
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) RelatedConfigTypeRep(com.emc.storageos.model.customconfig.RelatedConfigTypeRep) ArrayList(java.util.ArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) CustomConfigTypeList(com.emc.storageos.model.customconfig.CustomConfigTypeList) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 5 with CustomConfigType

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

the class CustomConfigService method getCustomConfigTypeValue.

/**
 * Get the custom config value set in ViPR. This is valid for simple value config type only
 *
 * @brief Show config type details
 * @return The config type data.
 */
@GET
@Path("/types/{config_name}/value")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public SimpleValueRep getCustomConfigTypeValue(@PathParam("config_name") String configName, @QueryParam("scope") String scope) {
    ArgValidator.checkFieldNotEmpty(configName, "configName");
    CustomConfigType item = customConfigHandler.getCustomConfigType(configName);
    if (item != null && !SIMPLE_VALUE_TYPE.equals(item.getConfigType())) {
        throw APIException.badRequests.invalidConfigValueType(configName);
    }
    SimpleValueRep result = new SimpleValueRep();
    if (item != null) {
        String value = customConfigHandler.getComputedCustomConfigValue(configName, scope, null);
        result.setValue(value);
    } else {
        log.info(String.format("Invalid config type for %s", configName));
        throw APIException.badRequests.invalidConfigType(configName);
    }
    return result;
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) SimpleValueRep(com.emc.storageos.model.customconfig.SimpleValueRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

CustomConfigType (com.emc.storageos.customconfigcontroller.CustomConfigType)9 CustomConfigConstraint (com.emc.storageos.customconfigcontroller.CustomConfigConstraint)4 StringMap (com.emc.storageos.db.client.model.StringMap)4 CustomConfigResolver (com.emc.storageos.customconfigcontroller.CustomConfigResolver)3 HashMap (java.util.HashMap)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 DataSourceVariable (com.emc.storageos.customconfigcontroller.DataSourceVariable)2 CustomConfig (com.emc.storageos.db.client.model.CustomConfig)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 DataSource (com.emc.storageos.customconfigcontroller.DataSource)1 RestLinkRep (com.emc.storageos.model.RestLinkRep)1 ConfigTypeScopeParam (com.emc.storageos.model.customconfig.ConfigTypeScopeParam)1 CustomConfigRuleList (com.emc.storageos.model.customconfig.CustomConfigRuleList)1 CustomConfigTypeList (com.emc.storageos.model.customconfig.CustomConfigTypeList)1 CustomConfigTypeRep (com.emc.storageos.model.customconfig.CustomConfigTypeRep)1 CustomConfigVariableList (com.emc.storageos.model.customconfig.CustomConfigVariableList)1