Search in sources :

Example 46 with StringMap

use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.

the class PlacementTestUtils method createStorageSystem.

public static StorageSystem createStorageSystem(DbClient dbClient, String type, String label) {
    StorageSystem storageSystem = new StorageSystem();
    storageSystem.setId(URI.create(label));
    storageSystem.setLabel(label);
    storageSystem.setNativeGuid(label);
    storageSystem.setInactive(false);
    storageSystem.setSystemType(type);
    storageSystem.setRegistrationStatus(RegistrationStatus.REGISTERED.name());
    storageSystem.setReachableStatus(true);
    if (type.equals("vplex")) {
        storageSystem.setSerialNumber(label + "cluster1:" + label + "cluster2");
        StringMap vplexAssemblyIdtoClusterId = new StringMap();
        vplexAssemblyIdtoClusterId.put(label + "cluster1", "1");
        vplexAssemblyIdtoClusterId.put(label + "cluster2", "2");
        storageSystem.setVplexAssemblyIdtoClusterId(vplexAssemblyIdtoClusterId);
    } else {
        storageSystem.setSerialNumber(label);
    }
    dbClient.createObject(storageSystem);
    return storageSystem;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 47 with StringMap

use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.

the class ComputeSystemHelper method getStorageToVolumeMap.

private static Map<URI, Map<URI, Integer>> getStorageToVolumeMap(DbClient dbClient, ExportGroup exportGroup, boolean protection) {
    Map<URI, Map<URI, Integer>> map = new HashMap<URI, Map<URI, Integer>>();
    StringMap volumes = exportGroup.getVolumes();
    if (volumes == null) {
        return map;
    }
    for (String uriString : volumes.keySet()) {
        URI blockURI = URI.create(uriString);
        BlockObject block = BlockObject.fetch(dbClient, blockURI);
        // If this is an RP-based Block Snapshot, use the protection controller instead of the underlying block controller
        URI storage = (block.getProtectionController() != null && protection && block.getId().toString().contains("BlockSnapshot")) ? block.getProtectionController() : block.getStorageController();
        if (map.get(storage) == null) {
            map.put(storage, new HashMap<URI, Integer>());
        }
        map.get(storage).put(blockURI, Integer.valueOf(volumes.get(uriString)));
    }
    return map;
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) HashMap(java.util.HashMap) URI(java.net.URI) Map(java.util.Map) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap) BlockObject(com.emc.storageos.db.client.model.BlockObject)

Example 48 with StringMap

use of com.emc.storageos.db.client.model.StringMap 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;
}
Also used : CustomConfig(com.emc.storageos.db.client.model.CustomConfig) StringMap(com.emc.storageos.db.client.model.StringMap) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 49 with StringMap

use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.

the class CustomConfigHandler method getCustomConfigPreviewValue.

/**
 * Uses the samples provided in the configuration item to generate a resolved
 * name for a given mask, configuration and scope. This can be used to preview
 * and validate a name mask prior to setting it.
 *
 * @param name the configuration type name
 * @param value the name mask to be resolved.
 * @param scope the scope to be used to for deciding which constraints to apply.
 * @param variables a map of variable-name-to-variable-value. This map can contain
 *            a value for all or only some of the name mask variables, or it can be
 *            empty. Any missing variable will be replaced with the variable default.
 * @return the resolved name.
 * @throws CustomConfigControllerException for invalid input.
 */
public String getCustomConfigPreviewValue(String name, String value, StringMap scope, Map<String, String> variables) {
    CustomConfigType item = getCustomConfigType(name);
    Map<DataSourceVariable, Boolean> dsVariables = item.getDataSourceVariables();
    DataSource sampleDatasource = null;
    if (dsVariables != null && !dsVariables.isEmpty()) {
        sampleDatasource = datasourceFactory.getSampleDataSource(name);
    }
    CustomConfigResolver resolver = configResolvers.get(item.getConfigType());
    if (variables != null && !variables.isEmpty()) {
        for (Map.Entry<String, String> entry : variables.entrySet()) {
            sampleDatasource.addProperty(entry.getKey(), entry.getValue());
        }
    }
    // validate the computed value
    resolver.validate(item, scope, value);
    // Resolve the config value
    String computedName = resolver.resolve(item, scope, value, sampleDatasource);
    // validate against the constraints
    List<CustomConfigConstraint> constraints = item.getConstraints();
    String systemType = CustomConfigConstants.DEFAULT_KEY;
    if (scope != null) {
        systemType = scope.get(CustomConfigConstants.SYSTEM_TYPE_SCOPE);
        // host type scope is only available for Hitachi Host Mode Option
        if (systemType == null) {
            systemType = scope.get(CustomConfigConstants.HOST_TYPE_SCOPE);
        }
    }
    for (CustomConfigConstraint constraint : constraints) {
        constraint.validate(computedName, systemType);
    }
    return computedName;
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) CustomConfigResolver(com.emc.storageos.customconfigcontroller.CustomConfigResolver) HashMap(java.util.HashMap) Map(java.util.Map) StringMap(com.emc.storageos.db.client.model.StringMap) DataSourceVariable(com.emc.storageos.customconfigcontroller.DataSourceVariable) DataSource(com.emc.storageos.customconfigcontroller.DataSource) CustomConfigConstraint(com.emc.storageos.customconfigcontroller.CustomConfigConstraint)

Example 50 with StringMap

use of com.emc.storageos.db.client.model.StringMap in project coprhd-controller by CoprHD.

the class CustomConfigHandler method getComputedCustomConfigValue.

/**
 * This is a short cut for the controller code to avoid having to create
 * a scope. In the future a scope factory can be added.
 */
public String getComputedCustomConfigValue(String name, String scope, DataSource sources) throws CustomConfigControllerException {
    StringMap map = new StringMap();
    CustomConfigType item = getCustomConfigType(name);
    if (item != null) {
        for (String key : item.getScope().keySet()) {
            List<String> scopeVals = java.util.Arrays.asList(item.getScope().get(key).split(","));
            if (scopeVals.contains(scope)) {
                map.put(key, scope);
            }
        }
    }
    return getComputedCustomConfigValue(name, map, sources);
}
Also used : CustomConfigType(com.emc.storageos.customconfigcontroller.CustomConfigType) StringMap(com.emc.storageos.db.client.model.StringMap)

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