Search in sources :

Example 6 with CustomConfigType

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

the class CustomConfigHandler method validate.

/**
 * Performs the necessary checks to ensure the user-specified value for a
 * configuration is valid.
 * <ol>
 * <li>if isCheckDuplicate is set to true, ensure that a user-created configuration does not already exist for this configuration type
 * and scope</li>
 * <li>check that a configuration type exists for the name</li>
 * <li>check that the scope is supported based on the definition of the scope in the type of this configuration</li>
 * <li>check that the value is of the right type and that it is compliant with the constraints defined for this configuration type</li>
 * </ol>
 *
 * @param name the configuration type name
 * @param scope the scope of the configuration item
 * @param value the value of the configuration item in a string form
 * @param isCheckDuplicate true when uniqueness check is requested
 * @throws CustomConfigControllerException if any of the checks fail.
 */
public void validate(String name, StringMap scope, String value, boolean isCheckDuplicate) {
    // check this is a supported config
    CustomConfigType item = getCustomConfigType(name);
    if (item == null) {
        throw CustomConfigControllerException.exceptions.configTypeNotFound(name);
    }
    // if this is a create, check for duplicates and also validate the scope
    if (isCheckDuplicate) {
        CustomConfig config = getUserDefinedCustomConfig(constructConfigName(name, scope));
        if (config != null && config.getScope().equals(scope)) {
            throw CustomConfigControllerException.exceptions.customConfigAlreadyExists(config.getLabel());
        }
        // check this is a supported scope
        for (String key : scope.keySet()) {
            if (!item.getScope().containsKey(key)) {
                throw CustomConfigControllerException.exceptions.scopeTypeNotSupported(key, name);
            }
            List<String> scopeVals = java.util.Arrays.asList(item.getScope().get(key).split(","));
            if (!scopeVals.contains(scope.get(key))) {
                throw CustomConfigControllerException.exceptions.scopeValueNotSupported(scope.get(key), key, name);
            }
        }
    }
    // this performs additional validations
    value = getCustomConfigPreviewValue(name, value, scope, null);
    // check the value against each constraint
    for (CustomConfigConstraint constraint : item.getConstraints()) {
        constraint.validate(value, scope.values().iterator().next());
    }
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) CustomConfig(com.emc.storageos.db.client.model.CustomConfig) CustomConfigConstraint(com.emc.storageos.customconfigcontroller.CustomConfigConstraint)

Example 7 with CustomConfigType

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

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

Example 9 with CustomConfigType

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

the class CustomConfigService method getCustomConfigType.

/**
 * Show config type.
 *
 * @brief Show config type details
 * @return The config type data.
 */
@GET
@Path("/types/{config_name}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public CustomConfigTypeRep getCustomConfigType(@PathParam("config_name") String configName) {
    CustomConfigType item = customConfigHandler.getCustomConfigType(configName);
    CustomConfigTypeRep result = new CustomConfigTypeRep();
    if (item == null) {
        log.info("No config type found for :", configName);
        throw APIException.badRequests.invalidConfigType(configName);
    }
    result.setConfigName(configName);
    result.setType(item.getType());
    result.setConfigType(item.getConfigType());
    Map<DataSourceVariable, Boolean> dataSources = item.getDataSourceVariables();
    if (dataSources != null && !dataSources.isEmpty()) {
        List<VariableParam> variables = new ArrayList<VariableParam>();
        for (Map.Entry<DataSourceVariable, Boolean> entry : dataSources.entrySet()) {
            DataSourceVariable datasource = entry.getKey();
            VariableParam variable = new VariableParam();
            variable.setName(datasource.getDisplayName());
            variable.setSampleValue(datasource.getSample());
            variable.setIsRecommended(entry.getValue());
            variables.add(variable);
        }
        CustomConfigVariableList variableList = new CustomConfigVariableList(variables);
        result.setVariables(variableList);
    }
    Map<String, String> scopes = item.getScope();
    if (scopes != null && !scopes.isEmpty()) {
        List<ConfigTypeScopeParam> scopeParms = new ArrayList<ConfigTypeScopeParam>();
        for (Map.Entry<String, String> entry : scopes.entrySet()) {
            String type = entry.getKey();
            String value = entry.getValue();
            List<String> values = new ArrayList<String>();
            if (value.contains(SCOPE_DELIMETER)) {
                values = java.util.Arrays.asList(value.split(SCOPE_DELIMETER));
            } else {
                values.add(value);
            }
            ConfigTypeScopeParam scopeparm = new ConfigTypeScopeParam(type, values);
            scopeParms.add(scopeparm);
        }
        ScopeParamList scopeList = new ScopeParamList(scopeParms);
        result.setScopes(scopeList);
    }
    // get rules
    List<CustomConfigConstraint> constraints = item.getConstraints();
    if (constraints != null && !constraints.isEmpty()) {
        List<String> rules = new ArrayList<String>();
        for (CustomConfigConstraint constraint : constraints) {
            rules.add(constraint.getName());
        }
        CustomConfigRuleList ruleList = new CustomConfigRuleList(rules);
        result.setRules(ruleList);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) PreviewVariableParam(com.emc.storageos.model.customconfig.PreviewVariableParam) VariableParam(com.emc.storageos.model.customconfig.VariableParam) CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) CustomConfigTypeRep(com.emc.storageos.model.customconfig.CustomConfigTypeRep) ScopeParamList(com.emc.storageos.model.customconfig.ScopeParamList) CustomConfigVariableList(com.emc.storageos.model.customconfig.CustomConfigVariableList) ConfigTypeScopeParam(com.emc.storageos.model.customconfig.ConfigTypeScopeParam) CustomConfigRuleList(com.emc.storageos.model.customconfig.CustomConfigRuleList) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap) DataSourceVariable(com.emc.storageos.customconfigcontroller.DataSourceVariable) CustomConfigConstraint(com.emc.storageos.customconfigcontroller.CustomConfigConstraint) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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