use of com.emc.storageos.db.client.model.StringMap 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.StringMap 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.StringMap in project coprhd-controller by CoprHD.
the class CustomConfigService method getCustomConfigPreviewValue.
/**
* Get a config preview value.
*
* @param param create parameters
* @brief Get config preview value
* @return preview value
*/
@POST
@Path("/preview")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public CustomConfigPreviewRep getCustomConfigPreviewValue(CustomConfigPreviewParam param) {
String configType = param.getConfigType();
String theVal = param.getValue();
ArgValidator.checkFieldNotEmpty(configType, CONFIG_TYPE);
ArgValidator.checkFieldNotEmpty(theVal, VALUE);
ScopeParam scopeParm = param.getScope();
StringMap scope = null;
if (scopeParm != null) {
scope = new StringMap();
scope.put(scopeParm.getType(), scopeParm.getValue());
}
List<PreviewVariableParam> variables = param.getPreviewVariables();
Map<String, String> variableValues = null;
if (variables != null && !variables.isEmpty()) {
variableValues = new HashMap<String, String>();
for (PreviewVariableParam variable : variables) {
variableValues.put(variable.getVariableName(), variable.getValue());
}
}
String result = customConfigHandler.getCustomConfigPreviewValue(configType, theVal, scope, variableValues);
CustomConfigPreviewRep preview = new CustomConfigPreviewRep(result);
return preview;
}
use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.
the class BlockService method validateVpoolCopyModeSetting.
private void validateVpoolCopyModeSetting(Volume srcVolume, String newCopyMode) {
if (srcVolume != null) {
URI virtualPoolURI = srcVolume.getVirtualPool();
VirtualPool virtualPool = _dbClient.queryObject(VirtualPool.class, virtualPoolURI);
if (virtualPool != null) {
StringMap remoteCopySettingsMap = virtualPool.getProtectionRemoteCopySettings();
if (remoteCopySettingsMap != null) {
for (Map.Entry<URI, VpoolRemoteCopyProtectionSettings> entry : VirtualPool.getRemoteProtectionSettings(virtualPool, _dbClient).entrySet()) {
VpoolRemoteCopyProtectionSettings copySetting = entry.getValue();
if (!newCopyMode.equalsIgnoreCase(copySetting.getCopyMode())) {
throw APIException.badRequests.invalidCopyModeOp(newCopyMode, copySetting.getCopyMode());
}
}
}
}
}
}
use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.
the class BlockVirtualPoolService method verifyNewHAVpoolForHAVpoolUpdate.
/**
* When updating a virtual pool, this function verifies that if there is
* and update to the HA virtual pool, that the specified pool is valid
* for the virtual pool being updated.
*
* @param vPoolBeingUpdated The vpool being updated.
* @param newHAVpoolId The non-null id of the new HA vpool.
*/
private void verifyNewHAVpoolForHAVpoolUpdate(VirtualPool vPoolBeingUpdated, String newHAVpoolId) {
URI newHAVpoolURI = URI.create(newHAVpoolId);
VirtualPool newHAVpool = _dbClient.queryObject(VirtualPool.class, newHAVpoolURI);
if (newHAVpool == null) {
throw APIException.badRequests.haVpoolForVpoolUpdateDoesNotExist(newHAVpoolId);
}
if (newHAVpool.getInactive()) {
throw APIException.badRequests.haVpoolForVpoolUpdateIsInactive(newHAVpool.getLabel());
}
StringMap newHAVpoolHAMap = newHAVpool.getHaVarrayVpoolMap();
if ((newHAVpoolHAMap == null) || (newHAVpoolHAMap.isEmpty())) {
// New HA vpool does not specify VPLEX HA.
return;
}
String newHAVpoolHAVpoolId = newHAVpoolHAMap.get(newHAVpoolHAMap.keySet().iterator().next());
if (!NullColumnValueGetter.isNotNullValue(newHAVpoolHAVpoolId)) {
// No HA Vpool specified.
return;
}
VirtualPool newHAVpoolHAVpool = _dbClient.queryObject(VirtualPool.class, URI.create(newHAVpoolHAVpoolId));
if (newHAVpoolHAVpool == null) {
// Invalid HA vpool for the new HA vpool does not exist.
throw APIException.badRequests.haVpoolForNewHAVpoolForVpoolUpdateDoesNotExist(newHAVpoolHAVpoolId, newHAVpool.getLabel());
}
// HA vpool is not this vpool being updated. See Jira 6797.
if (newHAVpoolHAVpool.getId().equals(vPoolBeingUpdated.getId())) {
throw APIException.badRequests.haVpoolForVpoolUpdateHasInvalidHAVpool(newHAVpool.getLabel());
}
}
Aggregations