Search in sources :

Example 76 with DataObject

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

the class InMemoryDbClient method findByPrefix.

@Override
public <T extends DataObject> List<NamedElement> findByPrefix(Class<T> clazz, String columnField, String prefix) throws DataAccessException {
    List<NamedElement> results = Lists.newArrayList();
    for (URI modelId : findAllIds(clazz)) {
        T model = findById(clazz, modelId);
        Object o = getColumnField(model, columnField);
        if (o != null && o.toString().startsWith(prefix)) {
            results.add(createNamedElement(model));
        }
    }
    return results;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) URI(java.net.URI)

Example 77 with DataObject

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

the class InMemoryDbClient method findByContainmentAndPrefix.

@Override
public <T extends DataObject> List<NamedElement> findByContainmentAndPrefix(Class<T> clazz, String columnField, URI id, String labelPrefix) throws DataAccessException {
    List<NamedElement> results = Lists.newArrayList();
    for (URI modelId : findAllIds(clazz)) {
        T model = findById(clazz, modelId);
        Object o = getColumnField(model, columnField);
        if (ObjectUtils.equals(o, id) && StringUtils.startsWith(model.getLabel(), labelPrefix)) {
            results.add(createNamedElement(model));
        }
    }
    return results;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) URI(java.net.URI)

Example 78 with DataObject

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

the class InMemoryDbClient method findByAlternateId.

@Override
public <T extends DataObject> List<NamedElement> findByAlternateId(Class<T> clazz, String columnField, String value) throws DataAccessException {
    List<NamedElement> results = Lists.newArrayList();
    for (URI modelId : findAllIds(clazz)) {
        T model = findById(clazz, modelId);
        Object o = getColumnField(model, columnField);
        if (ObjectUtils.equals(o, value)) {
            results.add(createNamedElement(model));
        }
    }
    return results;
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement) URI(java.net.URI)

Example 79 with DataObject

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

the class VPlexDeviceController method createVirtualVolumes.

/**
 * Do the creation of a VPlex Virtual Volume. This is called as a Workflow Step.
 * NOTE: The parameters here must match createVirtualVolumesMethod above (except stepId).
 *
 * @param vplexURI
 *            -- URI of the VPlex StorageSystem
 * @param vplexVolumeURIs
 *            -- URI of the VPlex volumes to be created. They must contain
 *            associatedVolumes (URI of the underlying Storage Volumes).
 * @param computeResourceMap
 *            A Map of the compute resource for each volume.
 * @param stepId
 *            - The stepId used for completion.
 * @throws WorkflowException
 */
public void createVirtualVolumes(URI vplexURI, List<URI> vplexVolumeURIs, Map<URI, URI> computeResourceMap, String stepId) throws WorkflowException {
    List<List<VolumeInfo>> rollbackData = new ArrayList<List<VolumeInfo>>();
    List<URI> createdVplexVolumeURIs = new ArrayList<URI>();
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        // Get the API client.
        StorageSystem vplex = getDataObject(StorageSystem.class, vplexURI, _dbClient);
        VPlexApiClient client = getVPlexAPIClient(_vplexApiFactory, vplex, _dbClient);
        // Make a map of StorageSystem ids to Storage System
        Map<URI, StorageSystem> storageMap = new HashMap<URI, StorageSystem>();
        // Make a map of Virtual Volumes to Storage Volumes.
        Map<Volume, List<Volume>> volumeMap = new HashMap<Volume, List<Volume>>();
        // Make a string buffer for volume labels
        StringBuffer volumeLabels = new StringBuffer();
        // List of storage system Guids
        List<String> storageSystemGuids = new ArrayList<String>();
        Boolean isDistributedVolume = false;
        Map<String, Set<URI>> clusterVarrayMap = new HashMap<>();
        for (URI vplexVolumeURI : vplexVolumeURIs) {
            Volume vplexVolume = getDataObject(Volume.class, vplexVolumeURI, _dbClient);
            URI vplexVolumeVarrayURI = vplexVolume.getVirtualArray();
            String clusterId = ConnectivityUtil.getVplexClusterForVarray(vplexVolumeVarrayURI, vplexVolume.getStorageController(), _dbClient);
            if (clusterVarrayMap.containsKey(clusterId)) {
                clusterVarrayMap.get(clusterId).add(vplexVolumeVarrayURI);
            } else {
                Set<URI> varraysForCluster = new HashSet<>();
                varraysForCluster.add(vplexVolumeVarrayURI);
                clusterVarrayMap.put(clusterId, varraysForCluster);
            }
            volumeLabels.append(vplexVolume.getLabel()).append(" ");
            volumeMap.put(vplexVolume, new ArrayList<Volume>());
            // Find the underlying Storage Volumes
            StringSet associatedVolumes = vplexVolume.getAssociatedVolumes();
            if (associatedVolumes.size() > 1) {
                isDistributedVolume = true;
            }
            for (String associatedVolume : associatedVolumes) {
                Volume storageVolume = getDataObject(Volume.class, new URI(associatedVolume), _dbClient);
                URI storageSystemId = storageVolume.getStorageController();
                if (storageMap.containsKey(storageSystemId) == false) {
                    StorageSystem storage = _dbClient.queryObject(StorageSystem.class, storageSystemId);
                    storageMap.put(storageSystemId, storage);
                    if (!storageSystemGuids.contains(storage.getNativeGuid())) {
                        storageSystemGuids.add(storage.getNativeGuid());
                    }
                }
                volumeMap.get(vplexVolume).add(storageVolume);
            }
        }
        _log.info(String.format("Request to create: %s virtual volume(s) %s", volumeMap.size(), volumeLabels));
        long startTime = System.currentTimeMillis();
        // If a new backend system is connected to a VPLEX and the VPLEX does not
        // yet know about the system i.e., the system does not show up in the path
        // /clusters/cluster-x/storage-elements/storage-arrays, and a user attempts
        // to create a virtual volume, the request may fail because we cannot find
        // the storage system. When the backend volume on the new system is created
        // and exported to the VPLEX, the VPLEX will recognize new system. However,
        // this may not occur immediately. So, when we go to create the vplex volume
        // using that backend volume, we may not find that system and volume on the
        // first try. We saw this in development. As such there was a retry loop
        // added when finding the backend volumes in the discovery that is performed
        // in the method to create the virtual volume.
        // 
        // However changes for CTRL-12826 were merged on 7/31/2015 that circumvented
        // that retry code. Changes were made to do the array re-discover here prior
        // to virtual volume creation, rather than during virtual volume creation and
        // false was passed to the create virtual volume routine for the discovery
        // required flag. The newly added call does not do any kind of retry if the
        // system is not found and so a failure will occur in the scenario described
        // above. If a system is not found an exception is thrown. Now we will catch
        // that exception and re-enable discovery in the volume creation routine.
        // Essentially we revert to what was happening before the 12826 changes if there
        // is an issue discovering the systems on the initial try here.
        boolean discoveryRequired = false;
        try {
            client.rediscoverStorageSystems(storageSystemGuids);
        } catch (Exception e) {
            String warnMsg = String.format("Initial discovery of one or more of these backend systems %s failed: %s." + "Discovery is required during virtual volume creation", storageSystemGuids, e.getMessage());
            _log.warn(warnMsg);
            discoveryRequired = true;
        }
        // Now make a call to the VPlexAPIClient.createVirtualVolume for each vplex volume.
        StringBuilder buf = new StringBuilder();
        buf.append("Vplex: " + vplexURI + " created virtual volume(s): ");
        boolean thinEnabled = false;
        boolean searchAllClustersForStorageVolumes = ((clusterVarrayMap.keySet().size() > 1 || isDistributedVolume) ? true : false);
        List<VPlexVirtualVolumeInfo> virtualVolumeInfos = new ArrayList<VPlexVirtualVolumeInfo>();
        Map<String, Volume> vplexVolumeNameMap = new HashMap<String, Volume>();
        List<VPlexClusterInfo> clusterInfoList = null;
        for (Volume vplexVolume : volumeMap.keySet()) {
            URI vplexVolumeId = vplexVolume.getId();
            _log.info(String.format("Creating virtual volume: %s (%s)", vplexVolume.getLabel(), vplexVolumeId));
            URI vplexVolumeVarrayURI = vplexVolume.getVirtualArray();
            String clusterId = null;
            for (Entry<String, Set<URI>> clusterEntry : clusterVarrayMap.entrySet()) {
                if (clusterEntry.getValue().contains(vplexVolumeVarrayURI)) {
                    clusterId = clusterEntry.getKey();
                }
            }
            List<VolumeInfo> vinfos = new ArrayList<VolumeInfo>();
            for (Volume storageVolume : volumeMap.get(vplexVolume)) {
                StorageSystem storage = storageMap.get(storageVolume.getStorageController());
                List<String> itls = VPlexControllerUtils.getVolumeITLs(storageVolume);
                VolumeInfo info = new VolumeInfo(storage.getNativeGuid(), storage.getSystemType(), storageVolume.getWWN().toUpperCase().replaceAll(":", ""), storageVolume.getNativeId(), storageVolume.getThinlyProvisioned().booleanValue(), itls);
                if (storageVolume.getVirtualArray().equals(vplexVolumeVarrayURI)) {
                    // We always want the source backend volume identified first. It
                    // may not be first in the map as the map is derived from the
                    // VPLEX volume's associated volumes list which is an unordered
                    // StringSet.
                    vinfos.add(0, info);
                } else {
                    vinfos.add(info);
                }
                if (info.getIsThinProvisioned()) {
                    // if either or both legs of distributed is thin, try for thin-enabled
                    // (or if local and the single backend volume is thin, try as well)
                    thinEnabled = true;
                }
            }
            // Update rollback information.
            rollbackData.add(vinfos);
            _workflowService.storeStepData(stepId, rollbackData);
            InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_045);
            // Make a call to get cluster info
            if (null == clusterInfoList) {
                if (searchAllClustersForStorageVolumes) {
                    clusterInfoList = client.getClusterInfoDetails();
                } else {
                    clusterInfoList = new ArrayList<VPlexClusterInfo>();
                }
            }
            // Make the call to create a virtual volume. It is distributed if there are two (or more?)
            // physical volumes.
            boolean isDistributed = (vinfos.size() >= 2);
            thinEnabled = thinEnabled && verifyVplexSupportsThinProvisioning(vplex);
            VPlexVirtualVolumeInfo vvInfo = client.createVirtualVolume(vinfos, isDistributed, discoveryRequired, false, clusterId, clusterInfoList, false, thinEnabled, searchAllClustersForStorageVolumes);
            // Note: according to client.createVirtualVolume, this will never be the case.
            if (vvInfo == null) {
                VPlexApiException ex = VPlexApiException.exceptions.cantFindRequestedVolume(vplexVolume.getLabel());
                throw ex;
            }
            vplexVolumeNameMap.put(vvInfo.getName(), vplexVolume);
            virtualVolumeInfos.add(vvInfo);
        }
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_046);
        Map<String, VPlexVirtualVolumeInfo> foundVirtualVolumes = client.findVirtualVolumes(clusterInfoList, virtualVolumeInfos);
        if (!foundVirtualVolumes.isEmpty()) {
            for (Entry<String, Volume> entry : vplexVolumeNameMap.entrySet()) {
                Volume vplexVolume = entry.getValue();
                VPlexVirtualVolumeInfo vvInfo = foundVirtualVolumes.get(entry.getKey());
                try {
                    // Now we try and rename the volume to the customized name. Note that if custom naming
                    // is disabled the custom name will not be generated and will be null.
                    // Create the VPLEX volume name custom configuration datasource and generate the
                    // custom volume name based on whether the volume is a local or distributed volume.
                    String hostOrClusterName = null;
                    URI computeResourceURI = computeResourceMap.get(vplexVolume.getId());
                    if (computeResourceURI != null) {
                        DataObject hostOrCluster = null;
                        if (URIUtil.isType(computeResourceURI, Cluster.class)) {
                            hostOrCluster = getDataObject(Cluster.class, computeResourceURI, _dbClient);
                        } else if (URIUtil.isType(computeResourceURI, Host.class)) {
                            hostOrCluster = getDataObject(Host.class, computeResourceURI, _dbClient);
                        }
                        if ((hostOrCluster != null) && ((vplexVolume.getPersonality() == null) || (vplexVolume.checkPersonality(Volume.PersonalityTypes.SOURCE)))) {
                            hostOrClusterName = hostOrCluster.getLabel();
                        }
                    }
                    if (CustomVolumeNamingUtils.isCustomVolumeNamingEnabled(customConfigHandler, vplex.getSystemType())) {
                        String customConfigName = CustomVolumeNamingUtils.getCustomConfigName(hostOrClusterName != null);
                        Project project = getDataObject(Project.class, vplexVolume.getProject().getURI(), _dbClient);
                        TenantOrg tenant = getDataObject(TenantOrg.class, vplexVolume.getTenant().getURI(), _dbClient);
                        DataSource customNameDataSource = CustomVolumeNamingUtils.getCustomConfigDataSource(project, tenant, vplexVolume.getLabel(), vvInfo.getWwn(), hostOrClusterName, dataSourceFactory, customConfigName, _dbClient);
                        if (customNameDataSource != null) {
                            String customVolumeName = CustomVolumeNamingUtils.getCustomName(customConfigHandler, customConfigName, customNameDataSource, vplex.getSystemType());
                            vvInfo = CustomVolumeNamingUtils.renameVolumeOnVPlex(vvInfo, customVolumeName, client);
                            // Update the label to match the custom name.
                            vplexVolume.setLabel(vvInfo.getName());
                            // Also, we update the name portion of the project and tenant URIs
                            // to reflect the custom name. This is necessary because the API
                            // to search for volumes by project, extracts the name portion of the
                            // project URI to get the volume name.
                            NamedURI namedURI = vplexVolume.getProject();
                            namedURI.setName(vvInfo.getName());
                            vplexVolume.setProject(namedURI);
                            namedURI = vplexVolume.getTenant();
                            namedURI.setName(vvInfo.getName());
                            vplexVolume.setTenant(namedURI);
                        }
                    }
                } catch (Exception e) {
                    _log.warn(String.format("Error renaming newly created VPLEX volume %s:%s", vplexVolume.getId(), vplexVolume.getLabel()), e);
                }
                buf.append(vvInfo.getName() + " ");
                _log.info(String.format("Created virtual volume: %s path: %s size: %s", vvInfo.getName(), vvInfo.getPath(), vvInfo.getCapacityBytes()));
                vplexVolume.setNativeId(vvInfo.getPath());
                vplexVolume.setNativeGuid(vvInfo.getPath());
                vplexVolume.setDeviceLabel(vvInfo.getName());
                vplexVolume.setThinlyProvisioned(vvInfo.isThinEnabled());
                checkThinEnabledResult(vvInfo, thinEnabled, _workflowService.getWorkflowFromStepId(stepId).getOrchTaskId());
                vplexVolume.setWWN(vvInfo.getWwn());
                // For Vplex virtual volumes set allocated capacity to 0 (cop-18608)
                vplexVolume.setAllocatedCapacity(0L);
                vplexVolume.setProvisionedCapacity(vvInfo.getCapacityBytes());
                _dbClient.updateObject(vplexVolume);
                // Record VPLEX volume created event.
                createdVplexVolumeURIs.add(vplexVolume.getId());
                recordBourneVolumeEvent(vplexVolume.getId(), OperationTypeEnum.CREATE_BLOCK_VOLUME.getEvType(true), Operation.Status.ready, OperationTypeEnum.CREATE_BLOCK_VOLUME.getDescription());
            }
        }
        if (foundVirtualVolumes.size() != vplexVolumeNameMap.size()) {
            VPlexApiException ex = VPlexApiException.exceptions.cantFindAllRequestedVolume();
            throw ex;
        }
        long elapsed = System.currentTimeMillis() - startTime;
        _log.info(String.format("TIMER: %s virtual volume(s) %s create took %f seconds", volumeMap.size(), volumeLabels.toString(), (double) elapsed / (double) 1000));
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (VPlexApiException vae) {
        _log.error("Exception creating Vplex Virtual Volume: " + vae.getMessage(), vae);
        // not created.
        for (URI vplexVolumeURI : vplexVolumeURIs) {
            if (!createdVplexVolumeURIs.contains(vplexVolumeURI)) {
                recordBourneVolumeEvent(vplexVolumeURI, OperationTypeEnum.CREATE_BLOCK_VOLUME.getEvType(false), Operation.Status.error, OperationTypeEnum.CREATE_BLOCK_VOLUME.getDescription());
            }
        }
        WorkflowStepCompleter.stepFailed(stepId, vae);
    } catch (Exception ex) {
        _log.error("Exception creating Vplex Virtual Volume: " + ex.getMessage(), ex);
        // not created.
        for (URI vplexVolumeURI : vplexVolumeURIs) {
            if (!createdVplexVolumeURIs.contains(vplexVolumeURI)) {
                recordBourneVolumeEvent(vplexVolumeURI, OperationTypeEnum.CREATE_BLOCK_VOLUME.getEvType(false), Operation.Status.error, OperationTypeEnum.CREATE_BLOCK_VOLUME.getDescription());
            }
        }
        String opName = ResourceOperationTypeEnum.CREATE_VIRTUAL_VOLUME.getName();
        ServiceError serviceError = VPlexApiException.errors.createVirtualVolumesFailed(opName, ex);
        WorkflowStepCompleter.stepFailed(stepId, serviceError);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) ArrayList(java.util.ArrayList) VolumeInfo(com.emc.storageos.vplex.api.clientdata.VolumeInfo) VPlexVirtualVolumeInfo(com.emc.storageos.vplex.api.VPlexVirtualVolumeInfo) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) VPlexVirtualVolumeInfo(com.emc.storageos.vplex.api.VPlexVirtualVolumeInfo) VPlexClusterInfo(com.emc.storageos.vplex.api.VPlexClusterInfo) StringSet(com.emc.storageos.db.client.model.StringSet) ApplicationAddVolumeList(com.emc.storageos.volumecontroller.ApplicationAddVolumeList) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) InternalServerErrorException(com.emc.storageos.svcs.errorhandling.resources.InternalServerErrorException) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataSource(com.emc.storageos.customconfigcontroller.DataSource) Project(com.emc.storageos.db.client.model.Project) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) DataObject(com.emc.storageos.db.client.model.DataObject) VPlexControllerUtils.getDataObject(com.emc.storageos.vplexcontroller.VPlexControllerUtils.getDataObject) Volume(com.emc.storageos.db.client.model.Volume) VPlexApiException(com.emc.storageos.vplex.api.VPlexApiException) VPlexApiClient(com.emc.storageos.vplex.api.VPlexApiClient) TenantOrg(com.emc.storageos.db.client.model.TenantOrg)

Example 80 with DataObject

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

the class GeoDependencyChecker method checkDependencies.

/**
 * checks to see if any references exist for this uri
 * uses dependency list created from relational indices
 *
 * @param uri id of the DataObject
 * @param type DataObject class name
 * @param onlyActive if true, checks for active references only (expensive)
 * @param excludeTypes optional list of classes that can be excluded as dependency
 * @return null if no references exist on this uri, return the type of the dependency if exist
 */
public String checkDependencies(URI uri, Class<? extends DataObject> type, boolean onlyActive, List<Class<? extends DataObject>> excludeTypes) {
    String depMsg = localDependencyChecker.checkDependencies(uri, type, true, excludeTypes);
    if (depMsg != null || KeyspaceUtil.isLocal(type)) {
        return depMsg;
    }
    // If there is any vdc under disconnect status, do not check dependency, return ""
    if (hasDisconnectedVdc()) {
        return "";
    }
    List<URI> vDCIds = dbClient.queryByType(VirtualDataCenter.class, true);
    VirtualDataCenter vDC = null;
    for (URI vDCId : vDCIds) {
        if (vDCId.equals(VdcUtil.getLocalVdc().getId())) {
            // skip local vDC
            continue;
        }
        vDC = dbClient.queryObject(VirtualDataCenter.class, vDCId);
        GeoServiceClient client = geoClientManager.getGeoClient(vDC.getShortId());
        log.debug("Query Geo server={}", client.getServiceURI());
        try {
            String dependency = client.checkDependencies(type, uri, true);
            if (!dependency.isEmpty()) {
                log.info("Can't GC {} because depends on {} on {}", new Object[] { uri, dependency, vDCId });
                return dependency;
            }
        } catch (Exception e) {
            log.error("Failed to query depenedency for {} on {} e=", new Object[] { uri, vDC.getShortId(), e });
            log.error("so assume it has dependency");
            return "";
        }
    }
    log.debug("Geo object {} can be GC", uri);
    return null;
}
Also used : VirtualDataCenter(com.emc.storageos.db.client.model.VirtualDataCenter) DataObject(com.emc.storageos.db.client.model.DataObject) URI(java.net.URI)

Aggregations

DataObject (com.emc.storageos.db.client.model.DataObject)154 URI (java.net.URI)62 ArrayList (java.util.ArrayList)53 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)44 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)30 Volume (com.emc.storageos.db.client.model.Volume)26 NamedURI (com.emc.storageos.db.client.model.NamedURI)24 StringSet (com.emc.storageos.db.client.model.StringSet)23 HashMap (java.util.HashMap)22 BlockObject (com.emc.storageos.db.client.model.BlockObject)17 HashSet (java.util.HashSet)17 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)16 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)14 Operation (com.emc.storageos.db.client.model.Operation)13 List (java.util.List)10 Set (java.util.Set)10 BlockSnapshotSession (com.emc.storageos.db.client.model.BlockSnapshotSession)9 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)8