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