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);
}
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);
}
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;
}
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());
}
}
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;
}
Aggregations