use of com.emc.storageos.db.client.model.CustomConfig in project coprhd-controller by CoprHD.
the class CustomConfigHandler method loadSystemCustomConfigs.
/**
* This function is called when the controller service is started. It reads
* the custom configuration types, computes the list of system-defined
* configurations that should be persisted in the database and updates the DB accordingly.
*/
public void loadSystemCustomConfigs() {
logger.debug("loadSystemCustomConfigs started");
long start = System.currentTimeMillis();
// get all existing system-define configs in the database
Map<String, CustomConfig> dbSystemConfigsByLabel = getSystemConfigsFromDb();
// compute the list of required system-define configs from the types
Map<String, CustomConfig> templateConfigsByLabel = getTemplateConfigs();
// Diff the two maps and update
List<CustomConfig> created = new ArrayList<CustomConfig>();
List<CustomConfig> updated = new ArrayList<CustomConfig>();
List<CustomConfig> deleted = new ArrayList<CustomConfig>();
CustomConfig curConfig = null;
CustomConfig newConfig = null;
for (String label : templateConfigsByLabel.keySet()) {
if (dbSystemConfigsByLabel.containsKey(label)) {
curConfig = dbSystemConfigsByLabel.get(label);
newConfig = templateConfigsByLabel.get(label);
// check if we need to update
if (!newConfig.getValue().equals(curConfig.getValue())) {
curConfig.setValue(newConfig.getValue());
logger.info("System-defined CustomConfig {} will be updated", label);
updated.add(curConfig);
}
dbSystemConfigsByLabel.remove(label);
} else {
newConfig = templateConfigsByLabel.get(label);
newConfig.setId(URIUtil.createId(CustomConfig.class));
logger.info("System-defined CustomConfig {} will be created", label);
created.add(newConfig);
}
}
// any user-defined instances should also be deleted
for (String label : dbSystemConfigsByLabel.keySet()) {
logger.info("System-defined CustomConfig {} will be deleted.", label);
deleted.add(dbSystemConfigsByLabel.get(label));
curConfig = getUserDefinedCustomConfig(label);
if (curConfig != null) {
logger.info("User-defined CustomConfig {} will be delete with user-defined instance", label);
deleted.add(curConfig);
}
}
dbClient.markForDeletion(deleted);
dbClient.createObject(created);
dbClient.persistObject(updated);
logger.info("loadSystemCustomConfigs results: Created: {}, Updated: {}, Deleted: {}", new Object[] { created.size(), updated.size(), deleted.size() });
logger.debug("loadSystemCustomConfigs ended and took {}", (System.currentTimeMillis() - start));
}
use of com.emc.storageos.db.client.model.CustomConfig in project coprhd-controller by CoprHD.
the class CustomConfigService method getCustomConfig.
/**
* Get config instance matching config type and scope
*
* @param configType config type e.g. SanZoneName
* @param scope
* @return CustomConfig instance
*/
private List<CustomConfig> getCustomConfig(String configType, StringMap scope) {
List<CustomConfig> configList = new ArrayList<CustomConfig>();
URIQueryResultList results = new URIQueryResultList();
_dbClient.queryByConstraint(AlternateIdConstraint.Factory.getCustomConfigByConfigType(configType), results);
while (results.iterator().hasNext()) {
CustomConfig tmpConfig = _dbClient.queryObject(CustomConfig.class, results.iterator().next());
if (scope == null || scope.isEmpty()) {
configList.add(tmpConfig);
continue;
} else {
Map<String, String> tmpscope = tmpConfig.getScope();
if (tmpscope != null && scope != null && tmpscope.equals(scope)) {
configList.add(tmpConfig);
log.debug("Found the custom config {} for {}", configType, scope);
break;
}
}
}
return configList;
}
use of com.emc.storageos.db.client.model.CustomConfig in project coprhd-controller by CoprHD.
the class CustomConfigService method registerCustomConfig.
/**
* Register a config.
*
* @param id URN of the config
* @brief Register config
* @return NamedRelatedResourceRep
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/register")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public CustomConfigRestRep registerCustomConfig(@PathParam("id") URI id) {
CustomConfig config = getCustomConfigById(id, true);
if (config.getRegistered()) {
return DbObjectMapper.map(config);
}
config.setRegistered(true);
_dbClient.updateAndReindexObject(config);
auditOp(OperationTypeEnum.REGISTER_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 deregisterCustomConfig.
/**
* Deregister a config.
*
* @param id URN of the config
* @brief Deregister config
* @return NamedRelatedResourceRep
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deregister")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public CustomConfigRestRep deregisterCustomConfig(@PathParam("id") URI id) {
CustomConfig config = getCustomConfigById(id, true);
if (config.getSystemDefault()) {
throw APIException.badRequests.systemDefaultConfigCouldNotBeModifiedOrDeactivated(config.getId());
}
config.setRegistered(false);
_dbClient.updateAndReindexObject(config);
auditOp(OperationTypeEnum.DEREGISTER_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 getCustomConfigById.
/**
* Get CustomConfig object from id
*
* @param id the URN of a ViPR CustomConfig
* @return
*/
private CustomConfig getCustomConfigById(URI id, boolean checkInactive) {
if (id == null) {
return null;
}
CustomConfig ret = _permissionsHelper.getObjectById(id, CustomConfig.class);
ArgValidator.checkEntity(ret, id, isIdEmbeddedInURL(id), checkInactive);
return ret;
}
Aggregations