Search in sources :

Example 1 with DataSourceVariable

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

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

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