Search in sources :

Example 11 with CustomConfig

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));
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) ArrayList(java.util.ArrayList)

Example 12 with CustomConfig

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;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 13 with CustomConfig

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);
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 14 with CustomConfig

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);
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 15 with CustomConfig

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;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig)

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