Search in sources :

Example 1 with CustomConfig

use of com.emc.storageos.db.client.model.CustomConfig in project coprhd-controller by CoprHD.

the class CustomConfigHandler method getCustomConfigValue.

/**
 * Gets the resolved value for a given configuration name,
 * and scope.
 *
 * @param configName the configuration type name
 * @param scope the scope to be used to find the configuration value.
 *            This is determined by first trying to find a configuration with
 *            exact scope, if one cannot be found then the global scope, and
 *            this cannot be found then the system default defined {@link CustomConfigType}
 * @return the resolved value for a given configuration name,
 *         and scope. This function is guaranteed to return a value for
 *         all valid inputs.
 */
public String getCustomConfigValue(String configName, StringMap scope) throws CustomConfigControllerException {
    CustomConfig customConfig = null;
    CustomConfig globalConfig = null;
    CustomConfig systemDefaultConfig = null;
    String value = null;
    URIQueryResultList results = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getCustomConfigByConfigType(configName), results);
    while (results.iterator().hasNext()) {
        CustomConfig tmpConfig = dbClient.queryObject(CustomConfig.class, results.iterator().next());
        if (tmpConfig == null || tmpConfig.getInactive() == true || !tmpConfig.getRegistered()) {
            continue;
        }
        StringMap tmpscope = tmpConfig.getScope();
        if (tmpscope != null && scope != null && tmpscope.equals(scope)) {
            if (tmpConfig.getSystemDefault()) {
                systemDefaultConfig = tmpConfig;
            } else {
                customConfig = tmpConfig;
                break;
            }
        } else if (tmpscope != null && tmpscope.containsKey(CustomConfigConstants.GLOBAL_KEY)) {
            if (tmpConfig.getSystemDefault()) {
                if (systemDefaultConfig == null) {
                    systemDefaultConfig = tmpConfig;
                }
            } else {
                globalConfig = tmpConfig;
            }
        }
    }
    String scopeKey = "none";
    String scopeValue = "none";
    if (scope != null && scope.keySet() != null && scope.keySet().iterator() != null && scope.keySet().iterator().hasNext()) {
        scopeKey = scope.keySet().iterator().next();
        scopeValue = scope.get(scopeKey) != null ? scope.get(scopeKey) : "no value";
    }
    if (customConfig != null) {
        logger.info(String.format("Found the custom config %s for %s:%s", configName, scopeKey, scopeValue));
        value = customConfig.getValue();
    } else if (globalConfig != null) {
        logger.info(String.format("Could not find custom config %s for %s:%s. The global custom config will be used.", configName, scopeKey, scopeValue));
        value = globalConfig.getValue();
    } else if (systemDefaultConfig != null) {
        logger.info(String.format("Could not find custom config %s for %s:%s. The system default config will be used.", configName, scopeKey, scopeValue));
        value = systemDefaultConfig.getValue();
    } else {
        throw CustomConfigControllerException.exceptions.customConfigScopeWithNoDefault(configName, scopeKey, scopeValue);
    }
    return value;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) StringMap(com.emc.storageos.db.client.model.StringMap) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 2 with CustomConfig

use of com.emc.storageos.db.client.model.CustomConfig in project coprhd-controller by CoprHD.

the class CustomConfigHandler method createSystemConfig.

private CustomConfig createSystemConfig(CustomConfigType template, String scopeType, String scopevalue, String value) {
    // create one
    CustomConfig curConfig = new CustomConfig();
    curConfig.setConfigType(template.getName());
    curConfig.setSystemDefault(true);
    curConfig.setValue(value);
    StringMap scope = new StringMap();
    scope.put(scopeType, scopevalue);
    curConfig.setScope(scope);
    curConfig.setLabel(CustomConfigHandler.constructConfigName(template.getName(), scope));
    curConfig.setRegistered(true);
    return curConfig;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) StringMap(com.emc.storageos.db.client.model.StringMap)

Example 3 with CustomConfig

use of com.emc.storageos.db.client.model.CustomConfig 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 4 with CustomConfig

use of com.emc.storageos.db.client.model.CustomConfig in project coprhd-controller by CoprHD.

the class CustomConfigHandler method getUserDefinedCustomConfig.

/**
 * Get the custom configuration item for the given label.
 *
 * @param label which is the unique and fully qualified name of the configuration
 *            that includes the configuration name and its full scope.
 * @return the custom configuration item if a configuration item is found. Return
 *         null otherwise.
 */
public CustomConfig getUserDefinedCustomConfig(String label) {
    CustomConfig value = null;
    URIQueryResultList results = new URIQueryResultList();
    dbClient.queryByConstraint(PrefixConstraint.Factory.getLabelPrefixConstraint(CustomConfig.class, label), results);
    while (results.iterator().hasNext()) {
        CustomConfig tmpConfig = dbClient.queryObject(CustomConfig.class, results.iterator().next());
        if (!tmpConfig.getSystemDefault()) {
            value = tmpConfig;
            break;
        }
    }
    return value;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 5 with CustomConfig

use of com.emc.storageos.db.client.model.CustomConfig in project coprhd-controller by CoprHD.

the class CustomConfigService method deactivateCustomConfig.

/**
 * Deactivates the config.
 * When a config is deleted it will move to a "marked for deletion" state.
 *
 * @prereq none
 * @param id the URN of a ViPR config
 * @brief Deactivate config
 * @return No data returned in response body
 */
@POST
@Path("/{id}/deactivate")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public Response deactivateCustomConfig(@PathParam("id") URI id) {
    CustomConfig customConfig = getCustomConfigById(id, true);
    ArgValidator.checkReference(CustomConfig.class, id, checkForDelete(customConfig));
    if (customConfig.getSystemDefault()) {
        // system default could not be deleted
        throw APIException.badRequests.systemDefaultConfigCouldNotBeModifiedOrDeactivated(customConfig.getId());
    }
    customConfig.setRegistered(false);
    _dbClient.markForDeletion(customConfig);
    auditOp(OperationTypeEnum.DELETE_CONFIG, true, null, id.toString(), customConfig.getLabel(), customConfig.getScope());
    return Response.ok().build();
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

CustomConfig (com.emc.storageos.db.client.model.CustomConfig)18 MapCustomConfig (com.emc.storageos.api.mapper.functions.MapCustomConfig)10 Produces (javax.ws.rs.Produces)8 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)7 Consumes (javax.ws.rs.Consumes)6 Path (javax.ws.rs.Path)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 StringMap (com.emc.storageos.db.client.model.StringMap)4 ArrayList (java.util.ArrayList)4 POST (javax.ws.rs.POST)4 URI (java.net.URI)3 GET (javax.ws.rs.GET)3 CustomConfigType (com.emc.storageos.customconfigcontroller.CustomConfigType)2 CustomConfigList (com.emc.storageos.model.customconfig.CustomConfigList)2 HashMap (java.util.HashMap)2 BulkList (com.emc.storageos.api.service.impl.response.BulkList)1 SearchedResRepList (com.emc.storageos.api.service.impl.response.SearchedResRepList)1 CustomConfigConstraint (com.emc.storageos.customconfigcontroller.CustomConfigConstraint)1 RestLinkRep (com.emc.storageos.model.RestLinkRep)1 ConfigTypeScopeParam (com.emc.storageos.model.customconfig.ConfigTypeScopeParam)1