Search in sources :

Example 6 with CustomConfig

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

the class CustomConfigService method createCustomConfig.

/**
 * Creates config.
 *
 * @param createParam create parameters
 * @brief Create config
 * @return CustomConfigRestRep
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public CustomConfigRestRep createCustomConfig(CustomConfigCreateParam createParam) {
    String configType = createParam.getConfigType();
    String theVal = createParam.getValue();
    ArgValidator.checkFieldNotEmpty(configType, CONFIG_TYPE);
    ArgValidator.checkFieldNotEmpty(theVal, VALUE);
    ScopeParam scopeParam = createParam.getScope();
    ArgValidator.checkFieldNotNull(scopeParam, SCOPE);
    StringMap scopeMap = new StringMap();
    scopeMap.put(scopeParam.getType(), scopeParam.getValue());
    customConfigHandler.validate(configType, scopeMap, theVal, true);
    String label = CustomConfigHandler.constructConfigName(configType, scopeMap);
    CustomConfig config = new CustomConfig();
    config.setId(URIUtil.createId(CustomConfig.class));
    config.setConfigType(configType);
    config.setScope(scopeMap);
    config.setLabel(label);
    config.setValue(theVal);
    config.setRegistered(createParam.getRegistered());
    config.setSystemDefault(false);
    _dbClient.createObject(config);
    auditOp(OperationTypeEnum.CREATE_CONFIG, true, null, config.getId().toString(), config.getLabel(), config.getScope());
    return DbObjectMapper.map(config);
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) StringMap(com.emc.storageos.db.client.model.StringMap) ConfigTypeScopeParam(com.emc.storageos.model.customconfig.ConfigTypeScopeParam) ScopeParam(com.emc.storageos.model.customconfig.ScopeParam) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with CustomConfig

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

the class CustomConfigService method getCustomConfig.

/**
 * Get config details
 *
 * @param id the URN of a ViPRconfig.
 *
 * @brief Show config
 * @return A reference to a CustomConfigRestRep
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public CustomConfigRestRep getCustomConfig(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, CustomConfig.class, "id");
    CustomConfig config = queryResource(id);
    return DbObjectMapper.map(config);
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 8 with CustomConfig

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

the class CustomConfigService method search.

/**
 * Search configs
 * <p>
 * Users could search configs by name, or config_name, or scope or system_default flag. e.g. /search?name=;
 * /search?config_name=SanZoneName; /search?config_name=SanZoneName&&scope=systemType.mds
 *
 * @brief Search configs
 * @return search result
 */
@GET
@Path("/search")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public SearchResults search() {
    Map<String, List<String>> parameters = uriInfo.getQueryParameters();
    // remove non-search related common parameters
    parameters.remove(RequestProcessingUtils.REQUESTING_COOKIES);
    SearchedResRepList resRepList = null;
    SearchResults result = new SearchResults();
    String name = null;
    if (parameters.containsKey(NAME)) {
        name = parameters.get(NAME).get(0);
        ArgValidator.checkFieldNotEmpty(name, NAME);
        resRepList = new SearchedResRepList(getResourceType());
        _dbClient.queryByConstraint(PrefixConstraint.Factory.getLabelPrefixConstraint(CustomConfig.class, name), resRepList);
        String systemDefault = null;
        if (parameters.containsKey(SYSTEM_DEFAULT)) {
            systemDefault = parameters.get(SYSTEM_DEFAULT).get(0);
            List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
            Iterator<SearchResultResourceRep> it = resRepList.iterator();
            while (it.hasNext()) {
                SearchResultResourceRep rp = it.next();
                URI id = rp.getId();
                CustomConfig config = queryResource(id);
                if (systemDefault.equals(config.getSystemDefault().toString())) {
                    RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), id));
                    SearchResultResourceRep searchResult = new SearchResultResourceRep(id, selfLink, config.getLabel());
                    searchResultList.add(searchResult);
                }
            }
            result.setResource(searchResultList);
        } else {
            result.setResource(resRepList);
        }
    } else if (parameters.containsKey(CONFIG_TYPE)) {
        String configName = parameters.get(CONFIG_TYPE).get(0);
        // Validate the user passed a value for the config type.
        ArgValidator.checkFieldNotEmpty(configName, CONFIG_TYPE);
        StringMap scopeMap = null;
        if (parameters.containsKey(SCOPE)) {
            String scope = parameters.get(SCOPE).get(0);
            scopeMap = new StringMap();
            if (scope.contains(".")) {
                String[] scopeSplits = scope.split("\\.");
                scopeMap.put(scopeSplits[0], scopeSplits[1]);
            } else {
                throw APIException.badRequests.invalidScopeFomart(scope);
            }
        }
        String systemDefault = null;
        if (parameters.containsKey(SYSTEM_DEFAULT)) {
            systemDefault = parameters.get(SYSTEM_DEFAULT).get(0);
        }
        List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
        List<CustomConfig> configList = getCustomConfig(configName, scopeMap);
        for (CustomConfig config : configList) {
            if (config.getInactive()) {
                continue;
            }
            if (systemDefault != null && !systemDefault.equals(config.getSystemDefault().toString())) {
                continue;
            }
            RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), config.getId()));
            SearchResultResourceRep searchResult = new SearchResultResourceRep(config.getId(), selfLink, config.getLabel());
            searchResultList.add(searchResult);
        }
        result.setResource(searchResultList);
    } else if (parameters.containsKey(SYSTEM_DEFAULT)) {
        // search parameters only contains system_default
        List<SearchResultResourceRep> searchResultList = new ArrayList<SearchResultResourceRep>();
        String systemDefault = parameters.get(SYSTEM_DEFAULT).get(0);
        List<URI> ids = _dbClient.queryByType(CustomConfig.class, true);
        Iterator<CustomConfig> iter = _dbClient.queryIterativeObjects(CustomConfig.class, ids);
        while (iter.hasNext()) {
            CustomConfig config = iter.next();
            if (systemDefault.equals(config.getSystemDefault().toString())) {
                RestLinkRep selfLink = new RestLinkRep("self", RestLinkFactory.newLink(getResourceType(), config.getId()));
                SearchResultResourceRep searchResult = new SearchResultResourceRep(config.getId(), selfLink, config.getLabel());
                searchResultList.add(searchResult);
            }
        }
        result.setResource(searchResultList);
    }
    return result;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) StringMap(com.emc.storageos.db.client.model.StringMap) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) SearchResults(com.emc.storageos.model.search.SearchResults) URI(java.net.URI) CustomConfigVariableList(com.emc.storageos.model.customconfig.CustomConfigVariableList) List(java.util.List) ArrayList(java.util.ArrayList) ScopeParamList(com.emc.storageos.model.customconfig.ScopeParamList) CustomConfigList(com.emc.storageos.model.customconfig.CustomConfigList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) CustomConfigRuleList(com.emc.storageos.model.customconfig.CustomConfigRuleList) CustomConfigTypeList(com.emc.storageos.model.customconfig.CustomConfigTypeList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 9 with CustomConfig

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

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

the class CustomConfigHandler method getSystemConfigsFromDb.

/**
 * Retrieves the list of system-defined custom configurations from the
 * data base and create a map keyed by the custom configuration unique
 * and fully qualified label.
 *
 * @return a map of db system-defined custom configurations keyed by the custom
 *         configuration unique and fully qualified label
 */
private Map<String, CustomConfig> getSystemConfigsFromDb() {
    // get all existing configs in the database
    logger.debug("getSystemConfigsFromDb started");
    Map<String, CustomConfig> systemConfigsByName = new HashMap<String, CustomConfig>();
    Iterator<CustomConfig> curConfigsItr = dbClient.queryIterativeObjects(CustomConfig.class, dbClient.queryByType(CustomConfig.class, true), true);
    CustomConfig curConfig = null;
    while (curConfigsItr.hasNext()) {
        curConfig = curConfigsItr.next();
        if (curConfig != null && curConfig.getSystemDefault()) {
            systemConfigsByName.put(curConfig.getLabel(), curConfig);
        }
    }
    logger.debug("getSystemConfigsFromDb ended and found a total of {}" + " system-defined configs in the database", systemConfigsByName.size());
    return systemConfigsByName;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) HashMap(java.util.HashMap)

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