Search in sources :

Example 61 with StringMap

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

Example 62 with StringMap

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;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) MapCustomConfig(com.emc.storageos.api.mapper.functions.MapCustomConfig) StringMap(com.emc.storageos.db.client.model.StringMap) SearchResultResourceRep(com.emc.storageos.model.search.SearchResultResourceRep) ArrayList(java.util.ArrayList) RestLinkRep(com.emc.storageos.model.RestLinkRep) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) SearchResults(com.emc.storageos.model.search.SearchResults) URI(java.net.URI) CustomConfigVariableList(com.emc.storageos.model.customconfig.CustomConfigVariableList) List(java.util.List) ArrayList(java.util.ArrayList) ScopeParamList(com.emc.storageos.model.customconfig.ScopeParamList) CustomConfigList(com.emc.storageos.model.customconfig.CustomConfigList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) CustomConfigRuleList(com.emc.storageos.model.customconfig.CustomConfigRuleList) CustomConfigTypeList(com.emc.storageos.model.customconfig.CustomConfigTypeList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 63 with StringMap

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;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) CustomConfigPreviewRep(com.emc.storageos.model.customconfig.CustomConfigPreviewRep) ConfigTypeScopeParam(com.emc.storageos.model.customconfig.ConfigTypeScopeParam) ScopeParam(com.emc.storageos.model.customconfig.ScopeParam) PreviewVariableParam(com.emc.storageos.model.customconfig.PreviewVariableParam) 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 64 with StringMap

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());
                    }
                }
            }
        }
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) VpoolRemoteCopyProtectionSettings(com.emc.storageos.db.client.model.VpoolRemoteCopyProtectionSettings) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) NullColumnValueGetter.isNullURI(com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap)

Example 65 with StringMap

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());
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) VirtualPoolMapper.toBlockVirtualPool(com.emc.storageos.api.mapper.VirtualPoolMapper.toBlockVirtualPool) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Aggregations

StringMap (com.emc.storageos.db.client.model.StringMap)257 URI (java.net.URI)108 ArrayList (java.util.ArrayList)90 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)59 StringSet (com.emc.storageos.db.client.model.StringSet)57 HashMap (java.util.HashMap)57 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)48 ExportMask (com.emc.storageos.db.client.model.ExportMask)43 Volume (com.emc.storageos.db.client.model.Volume)42 NamedURI (com.emc.storageos.db.client.model.NamedURI)41 StoragePool (com.emc.storageos.db.client.model.StoragePool)39 Initiator (com.emc.storageos.db.client.model.Initiator)38 List (java.util.List)34 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)33 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)31 HashSet (java.util.HashSet)30 Project (com.emc.storageos.db.client.model.Project)24 StoragePort (com.emc.storageos.db.client.model.StoragePort)23 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)22 Network (com.emc.storageos.db.client.model.Network)21