Search in sources :

Example 81 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class VnxExportOperations method findHLUsForInitiators.

@Override
public Set<Integer> findHLUsForInitiators(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) {
    long startTime = System.currentTimeMillis();
    Set<Integer> usedHLUs = new HashSet<Integer>();
    CloseableIterator<CIMInstance> lunMaskingIter = null;
    try {
        // Get a mapping of the initiator port names to their CIMObjectPaths on the provider
        WBEMClient client = _helper.getConnection(storage).getCimClient();
        HashMap<String, CIMObjectPath> initiatorPathsMap = _cimPath.getInitiatorToInitiatorPath(storage, initiatorNames);
        List<String> maskNames = new ArrayList<String>();
        // Iterate through each initiator port name ...
        for (String initiatorName : initiatorPathsMap.keySet()) {
            CIMObjectPath initiatorPath = initiatorPathsMap.get(initiatorName);
            // Find out if there is a Lun Masking Instance associated with the initiator...
            lunMaskingIter = _helper.getAssociatorInstances(storage, initiatorPath, null, SmisConstants.CLAR_LUN_MASKING_SCSI_PROTOCOL_CONTROLLER, null, null, SmisConstants.PS_LUN_MASKING_CNTRL_NAME_AND_ROLE);
            while (lunMaskingIter.hasNext()) {
                // Found a Lun Masking Instance...
                CIMInstance instance = lunMaskingIter.next();
                String systemName = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_SYSTEM_NAME);
                if (!systemName.contains(storage.getSerialNumber())) {
                    // SMISProvider pointed to by 'storage' system.
                    continue;
                }
                String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_ELEMENT_NAME);
                if (!maskNames.contains(name)) {
                    _log.info("Found matching mask {}", name);
                    maskNames.add(name);
                    // Find all the initiators associated with the Masking instance
                    List<String> initiatorPorts = _helper.getInitiatorsFromLunMaskingInstance(client, instance);
                    // Get volumes for the Masking instance
                    Map<String, Integer> volumeWWNs = _helper.getVolumesFromLunMaskingInstance(client, instance);
                    // add HLUs to set
                    usedHLUs.addAll(volumeWWNs.values());
                    _log.info(String.format("%nXM:%s I:{%s} V:{%s} HLU:{%s}%n", name, Joiner.on(',').join(initiatorPorts), Joiner.on(',').join(volumeWWNs.keySet()), volumeWWNs.values()));
                }
            }
        }
        _log.info(String.format("HLUs found for Initiators { %s }: %s", Joiner.on(',').join(initiatorNames), usedHLUs));
    } catch (Exception e) {
        String errMsg = "Encountered an SMIS error when attempting to query used HLUs for initiators: " + e.getMessage();
        _log.error(errMsg, e);
        throw SmisException.exceptions.hluRetrievalFailed(errMsg, e);
    } finally {
        if (lunMaskingIter != null) {
            lunMaskingIter.close();
        }
        long totalTime = System.currentTimeMillis() - startTime;
        _log.info(String.format("find used HLUs for Initiators took %f seconds", (double) totalTime / (double) 1000));
    }
    return usedHLUs;
}
Also used : CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) WBEMClient(javax.wbem.client.WBEMClient) HashSet(java.util.HashSet)

Example 82 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class VnxExportOperations method refreshExportMask.

@Override
public ExportMask refreshExportMask(StorageSystem storage, ExportMask mask) throws DeviceControllerException {
    try {
        CIMInstance instance = _helper.getLunMaskingProtocolController(storage, mask);
        if (instance != null) {
            StringBuilder builder = new StringBuilder();
            WBEMClient client = _helper.getConnection(storage).getCimClient();
            String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_ELEMENT_NAME);
            // Get volumes and initiators for the masking instance
            Map<String, Integer> discoveredVolumes = _helper.getVolumesFromLunMaskingInstance(client, instance);
            // Update user added volume's HLU information in ExportMask and ExportGroup
            ExportMaskUtils.updateHLUsInExportMask(mask, discoveredVolumes, _dbClient);
            List<String> discoveredPorts = _helper.getInitiatorsFromLunMaskingInstance(client, instance);
            Set existingInitiators = (mask.getExistingInitiators() != null) ? mask.getExistingInitiators() : Collections.emptySet();
            Set existingVolumes = (mask.getExistingVolumes() != null) ? mask.getExistingVolumes().keySet() : Collections.emptySet();
            builder.append(String.format("%nXM existing objects: %s I{%s} V:{%s}%n", name, Joiner.on(',').join(existingInitiators), Joiner.on(',').join(existingVolumes)));
            builder.append(String.format("XM discovered: %s I:{%s} V:{%s}%n", name, Joiner.on(',').join(discoveredPorts), Joiner.on(',').join(discoveredVolumes.keySet())));
            List<String> initiatorsToAddToExisting = new ArrayList<String>();
            List<Initiator> initiatorsToAddToUserAddedAndInitiatorList = new ArrayList<Initiator>();
            /**
             * For the newly discovered initiators, if they are ViPR discovered ports and belong to same resource
             * add them to user added and initiators list, otherwise add to existing list.
             */
            for (String port : discoveredPorts) {
                String normalizedPort = Initiator.normalizePort(port);
                if (!mask.hasExistingInitiator(normalizedPort) && !mask.hasUserInitiator(normalizedPort)) {
                    Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
                    // Don't add additional initiator to initiators list if it belongs to different host/cluster
                    if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
                        _log.info("Initiator {}->{} belonging to same compute, adding to userAdded and initiator list.", normalizedPort, existingInitiator.getId());
                        initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
                    } else {
                        initiatorsToAddToExisting.add(normalizedPort);
                    }
                }
            }
            /**
             * Get the existing initiators from the mask and remove the non-discovered ports because
             * they are not discovered and are stale.
             *
             * If the mask has existing initiators but if they are discovered and belongs to same compute resource, then the
             * initiators has to get added to user Added and initiators list, and removed from existing list.
             */
            List<String> initiatorsToRemoveFromExistingList = new ArrayList<String>();
            if (mask.getExistingInitiators() != null && !mask.getExistingInitiators().isEmpty()) {
                for (String existingInitiatorStr : mask.getExistingInitiators()) {
                    if (!discoveredPorts.contains(existingInitiatorStr)) {
                        initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
                    } else {
                        Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(existingInitiatorStr), _dbClient);
                        if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(mask, existingInitiator)) {
                            _log.info("Initiator {}->{} belonging to same compute, removing from existing," + " and adding to userAdded and initiator list", existingInitiatorStr, existingInitiator.getId());
                            initiatorsToAddToUserAddedAndInitiatorList.add(existingInitiator);
                            initiatorsToRemoveFromExistingList.add(existingInitiatorStr);
                        }
                    }
                }
            }
            /**
             * Get all the initiators from the mask and remove all the ViPR discovered ports.
             * The remaining list has to be removed from user Added and initiator list, because they are not available in ViPR
             * but has to be moved to existing list.
             */
            List<URI> initiatorsToRemoveFromUserAddedAndInitiatorList = new ArrayList<URI>();
            if (mask.getInitiators() != null && !mask.getInitiators().isEmpty()) {
                initiatorsToRemoveFromUserAddedAndInitiatorList.addAll(transform(mask.getInitiators(), CommonTransformerFunctions.FCTN_STRING_TO_URI));
                for (String port : discoveredPorts) {
                    String normalizedPort = Initiator.normalizePort(port);
                    Initiator initiatorDiscoveredInViPR = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
                    if (initiatorDiscoveredInViPR != null) {
                        initiatorsToRemoveFromUserAddedAndInitiatorList.remove(initiatorDiscoveredInViPR.getId());
                    } else if (!mask.hasExistingInitiator(normalizedPort)) {
                        _log.info("Initiator {} not found in database, removing from user Added and initiator list," + " and adding to existing list.", port);
                        initiatorsToAddToExisting.add(normalizedPort);
                    }
                }
            }
            boolean removeInitiators = !initiatorsToRemoveFromExistingList.isEmpty() || !initiatorsToRemoveFromUserAddedAndInitiatorList.isEmpty();
            boolean addInitiators = !initiatorsToAddToUserAddedAndInitiatorList.isEmpty() || !initiatorsToAddToExisting.isEmpty();
            // Check the volumes and update the lists as necessary
            Map<String, Integer> volumesToAdd = ExportMaskUtils.diffAndFindNewVolumes(mask, discoveredVolumes);
            boolean addVolumes = !volumesToAdd.isEmpty();
            boolean removeVolumes = false;
            List<String> volumesToRemove = new ArrayList<String>();
            if (mask.getExistingVolumes() != null && !mask.getExistingVolumes().isEmpty()) {
                volumesToRemove.addAll(mask.getExistingVolumes().keySet());
                volumesToRemove.removeAll(discoveredVolumes.keySet());
            }
            // if the volume is in export mask's user added volumes and also in the existing volumes, remove from existing volumes
            for (String wwn : discoveredVolumes.keySet()) {
                if (mask.hasExistingVolume(wwn)) {
                    URIQueryResultList volumeList = new URIQueryResultList();
                    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn), volumeList);
                    if (volumeList.iterator().hasNext()) {
                        URI volumeURI = volumeList.iterator().next();
                        if (mask.hasUserCreatedVolume(volumeURI)) {
                            builder.append(String.format("\texisting volumes contain wwn %s, but it is also in the " + "export mask's user added volumes, so removing from existing volumes", wwn));
                            volumesToRemove.add(wwn);
                        }
                    }
                }
            }
            removeVolumes = !volumesToRemove.isEmpty();
            // NOTE/TODO: We are not modifying the storage ports upon refresh like we do for VMAX.
            // Refer to CTRL-6982.
            builder.append(String.format("XM refresh: %s existing initiators; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAddToExisting), Joiner.on(',').join(initiatorsToRemoveFromExistingList)));
            builder.append(String.format("XM refresh: %s user added and initiator list; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(initiatorsToAddToUserAddedAndInitiatorList), Joiner.on(',').join(initiatorsToRemoveFromUserAddedAndInitiatorList)));
            builder.append(String.format("XM refresh: %s volumes; add:{%s} remove:{%s}%n", name, Joiner.on(',').join(volumesToAdd.keySet()), Joiner.on(',').join(volumesToRemove)));
            // Any changes indicated, then update the mask and persist it
            if (addInitiators || removeInitiators || addVolumes || removeVolumes) {
                builder.append("XM refresh: There are changes to mask, " + "updating it...\n");
                mask.removeFromExistingInitiators(initiatorsToRemoveFromExistingList);
                mask.removeInitiatorURIs(initiatorsToRemoveFromUserAddedAndInitiatorList);
                mask.removeFromUserAddedInitiatorsByURI(initiatorsToRemoveFromUserAddedAndInitiatorList);
                mask.addInitiators(initiatorsToAddToUserAddedAndInitiatorList);
                mask.addToUserCreatedInitiators(initiatorsToAddToUserAddedAndInitiatorList);
                mask.addToExistingInitiatorsIfAbsent(initiatorsToAddToExisting);
                mask.removeFromExistingVolumes(volumesToRemove);
                mask.addToExistingVolumesIfAbsent(volumesToAdd);
                // Update the volume list to include existing volumes if know about them.
                if (addVolumes) {
                    for (String wwn : volumesToAdd.keySet()) {
                        URIQueryResultList results = new URIQueryResultList();
                        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn.toUpperCase()), results);
                        if (results != null) {
                            Iterator<URI> resultsIter = results.iterator();
                            if (resultsIter.hasNext()) {
                                Volume volume = _dbClient.queryObject(Volume.class, resultsIter.next());
                                if (null != volume) {
                                    mask.addVolume(volume.getId(), volumesToAdd.get(wwn));
                                }
                            }
                        }
                    }
                }
                ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
                _dbClient.updateObject(mask);
            } else {
                builder.append("XM refresh: There are no changes to the mask\n");
            }
            _networkDeviceController.refreshZoningMap(mask, transform(initiatorsToRemoveFromUserAddedAndInitiatorList, CommonTransformerFunctions.FCTN_URI_TO_STRING), Collections.<String>emptyList(), (addInitiators || removeInitiators), true);
            _log.info(builder.toString());
        }
    } catch (Exception e) {
        boolean throwException = true;
        if (e instanceof WBEMException) {
            WBEMException we = (WBEMException) e;
            // Only throw exception if code is not CIM_ERROR_NOT_FOUND
            throwException = (we.getID() != WBEMException.CIM_ERR_NOT_FOUND);
        }
        if (throwException) {
            String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
            _log.error(MessageFormat.format("Encountered an SMIS error when attempting to refresh existing exports: {0}", msg), e);
            throw SmisException.exceptions.refreshExistingMaskFailure(msg, e);
        }
    }
    return mask;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) WBEMException(javax.wbem.WBEMException) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) Initiator(com.emc.storageos.db.client.model.Initiator) Volume(com.emc.storageos.db.client.model.Volume) WBEMClient(javax.wbem.client.WBEMClient)

Example 83 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class VnxExportOperations method deleteExportMask.

/*
     * (non-Javadoc)
     *
     * @see
     * com.emc.storageos.volumecontroller.impl.smis.ExportMaskOperations#deleteExportMask(com.emc.storageos.db.client.
     * model.StorageSystem, java.net.URI, java.util.List, java.util.List, java.util.List,
     * com.emc.storageos.volumecontroller.TaskCompleter)
     *
     * IDs
     * Note: No need to verify storage ports.
     */
@Override
public void deleteExportMask(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("{} deleteExportMask START...", storage.getSerialNumber());
    try {
        _log.info("Export mask id: {}", exportMaskURI);
        if (volumeURIList != null) {
            _log.info("deleteExportMask: volumes:  {}", Joiner.on(',').join(volumeURIList));
        }
        if (targetURIList != null) {
            _log.info("deleteExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
        }
        if (initiatorList != null) {
            _log.info("deleteExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
        }
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        String nativeId = exportMask.getNativeId();
        if (Strings.isNullOrEmpty(nativeId)) {
            _log.warn(String.format("ExportMask %s does not have a nativeID, " + "indicating that this export may not have been created " + "successfully. Marking the delete operation ready.", exportMaskURI.toString()));
            // Perform post-mask-delete cleanup steps
            ExportUtils.cleanupAssociatedMaskResources(_dbClient, exportMask);
            taskCompleter.ready(_dbClient);
            return;
        }
        boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
        if (isRollback) {
            boolean maskCreated = false;
            // Get the context from the task completer as this is a rollback.
            ExportOperationContext context = (ExportOperationContext) WorkflowService.getInstance().loadStepData(taskCompleter.getOpId());
            if (context != null && context.getOperations() != null) {
                ListIterator li = context.getOperations().listIterator(context.getOperations().size());
                while (li.hasPrevious()) {
                    ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
                    _log.info("Handling deleteExportMask as a result of rollback");
                    if (operation != null && VnxExportOperationContext.OPERATION_CREATE_STORAGE_GROUP.equals(operation.getOperation())) {
                        URI createdExportMaskURI = (URI) operation.getArgs().get(0);
                        if (exportMask.getId().equals(createdExportMaskURI)) {
                            maskCreated = true;
                            break;
                        }
                    }
                }
            }
            if (!maskCreated) {
                _log.warn(String.format("This is a case of rollback but the ExportMask %s was not found in the export context, " + "indicating that this export may not have been created successfully. Marking the delete operation ready.", exportMaskURI.toString()));
                // Perform post-mask-delete cleanup steps
                ExportUtils.cleanupAssociatedMaskResources(_dbClient, exportMask);
                taskCompleter.ready(_dbClient);
                return;
            }
        }
        ExportMaskValidationContext ctx = new ExportMaskValidationContext();
        ctx.setStorage(storage);
        ctx.setExportMask(exportMask);
        ctx.setBlockObjects(volumeURIList, _dbClient);
        ctx.setInitiators(initiatorList);
        ctx.setAllowExceptions(!isRollback);
        validator.exportMaskDelete(ctx).validate();
        CIMObjectPath protocolController = _cimPath.getClarProtocolControllers(storage, nativeId)[0];
        CIMInstance instance = _helper.checkExists(storage, protocolController, true, true);
        if (instance != null) {
            _helper.setProtocolControllerNativeId(exportMaskURI, null);
            ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
            if (mask != null) {
                List<URI> initiatorURIs = new ArrayList<URI>();
                if (mask.getInitiators() != null) {
                    for (String initUriStr : mask.getInitiators()) {
                        initiatorURIs.add(URI.create(initUriStr));
                    }
                }
                List<Initiator> initiators = _dbClient.queryObject(Initiator.class, initiatorURIs);
                deleteStorageHWIDs(storage, initiators);
                deleteOrShrinkStorageGroup(storage, exportMaskURI, null, null);
            }
        }
        // Perform post-mask-delete cleanup steps
        ExportUtils.cleanupAssociatedMaskResources(_dbClient, exportMask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: deleteExportMask failed.", e);
        ServiceError error = DeviceControllerErrors.smis.methodFailed("deleteExportMask", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
    _log.info("{} deleteExportMask END...", storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) ExportMaskValidationContext(com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext) Initiator(com.emc.storageos.db.client.model.Initiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) ExportOperationContextOperation(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation)

Example 84 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class VnxExportOperations method findExportMasks.

/**
 * This call can be used to look up the passed in initiator/port names and find (if
 * any) to which export masks they belong on the 'storage' array.
 *
 * @param storage
 *            [in] - StorageSystem object representing the array
 * @param initiatorNames
 *            [in] - Port identifiers (WWPN or iSCSI name)
 * @param mustHaveAllPorts
 *            [in] NOT APPLICABLE FOR VNX
 * @return Map of port name to Set of ExportMask URIs
 */
@Override
public Map<String, Set<URI>> findExportMasks(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) throws DeviceControllerException {
    long startTime = System.currentTimeMillis();
    Map<String, Set<URI>> matchingMasks = new HashMap<String, Set<URI>>();
    CloseableIterator<CIMInstance> lunMaskingIter = null;
    try {
        StringBuilder builder = new StringBuilder();
        WBEMClient client = _helper.getConnection(storage).getCimClient();
        lunMaskingIter = _helper.getClarLunMaskingProtocolControllers(storage);
        while (lunMaskingIter.hasNext()) {
            CIMInstance instance = lunMaskingIter.next();
            String systemName = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_SYSTEM_NAME);
            if (!systemName.contains(storage.getSerialNumber())) {
                // SMISProvider pointed to by 'storage' system.
                continue;
            }
            String name = CIMPropertyFactory.getPropertyValue(instance, SmisConstants.CP_ELEMENT_NAME);
            CIMProperty<String> deviceIdProperty = (CIMProperty<String>) instance.getObjectPath().getKey(SmisConstants.CP_DEVICE_ID);
            // Get volumes and initiators for the masking instance
            Map<String, Integer> volumeWWNs = _helper.getVolumesFromLunMaskingInstance(client, instance);
            List<String> initiatorPorts = _helper.getInitiatorsFromLunMaskingInstance(client, instance);
            // Find out if the port is in this masking container
            List<String> matchingInitiators = new ArrayList<String>();
            for (String port : initiatorNames) {
                String normalizedName = Initiator.normalizePort(port);
                if (initiatorPorts.contains(normalizedName)) {
                    matchingInitiators.add(normalizedName);
                }
            }
            builder.append(String.format("%nXM:%s I:{%s} V:{%s}%n", name, Joiner.on(',').join(initiatorPorts), Joiner.on(',').join(volumeWWNs.keySet())));
            if (!matchingInitiators.isEmpty()) {
                // Look up ExportMask by deviceId/name and storage URI
                ExportMask exportMask = ExportMaskUtils.getExportMaskByName(_dbClient, storage.getId(), name);
                boolean foundMaskInDb = (exportMask != null);
                // then create a new one
                if (!foundMaskInDb) {
                    exportMask = new ExportMask();
                    exportMask.setMaskName(name);
                    exportMask.setNativeId(deviceIdProperty.getValue());
                    exportMask.setStorageDevice(storage.getId());
                    exportMask.setId(URIUtil.createId(ExportMask.class));
                    exportMask.setCreatedBySystem(false);
                    // Grab the storage ports that have been allocated for this
                    // existing mask and add them.
                    List<String> storagePorts = _helper.getStoragePortsFromLunMaskingInstance(client, instance);
                    List<String> storagePortURIs = ExportUtils.storagePortNamesToURIs(_dbClient, storagePorts);
                    exportMask.setStoragePorts(storagePortURIs);
                    builder.append(String.format("   ----> SP { %s }\n" + "         URI{ %s }\n", Joiner.on(',').join(storagePorts), Joiner.on(',').join(storagePortURIs)));
                } else {
                    // refresh the export mask
                    refreshExportMask(storage, exportMask);
                    builder.append('\n');
                }
                // Update the tracking containers
                exportMask.addToExistingVolumesIfAbsent(volumeWWNs);
                exportMask.addToExistingInitiatorsIfAbsent(matchingInitiators);
                // Update the initiator list to include existing initiators if we know about them.
                for (String port : matchingInitiators) {
                    Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
                    if (existingInitiator != null) {
                        exportMask.addInitiator(existingInitiator);
                        exportMask.addToUserCreatedInitiators(existingInitiator);
                        exportMask.removeFromExistingInitiators(existingInitiator);
                    }
                }
                // so, add them to the initiator list and remove them from existing as well.
                for (String port : initiatorPorts) {
                    Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(port), _dbClient);
                    if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(exportMask, existingInitiator)) {
                        exportMask.addInitiator(existingInitiator);
                        exportMask.addToUserCreatedInitiators(existingInitiator);
                        exportMask.removeFromExistingInitiators(existingInitiator);
                    }
                }
                // Update the volume list to include existing volumes if know about them.
                if (volumeWWNs != null) {
                    for (String wwn : volumeWWNs.keySet()) {
                        URIQueryResultList results = new URIQueryResultList();
                        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getVolumeWwnConstraint(wwn.toUpperCase()), results);
                        if (results != null) {
                            Iterator<URI> resultsIter = results.iterator();
                            if (resultsIter.hasNext()) {
                                Volume volume = _dbClient.queryObject(Volume.class, resultsIter.next());
                                if (volume != null) {
                                    Integer hlu = volumeWWNs.get(wwn);
                                    if (hlu == null) {
                                        _log.warn(String.format("The HLU for %s could not be found from the provider. Setting this to -1 (Unknown).", wwn));
                                        hlu = -1;
                                    }
                                    exportMask.addVolume(volume.getId(), hlu);
                                    exportMask.removeFromExistingVolumes(volume);
                                }
                            }
                        }
                    }
                }
                Set existingInitiators = (exportMask.getExistingInitiators() != null) ? exportMask.getExistingInitiators() : Collections.emptySet();
                Set existingVolumes = (exportMask.getExistingVolumes() != null) ? exportMask.getExistingVolumes().keySet() : Collections.emptySet();
                builder.append(String.format("XM:%s is matching. " + "EI: { %s }, EV: { %s }", name, Joiner.on(',').join(existingInitiators), Joiner.on(',').join(existingVolumes)));
                if (foundMaskInDb) {
                    ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, exportMask);
                    _dbClient.updateObject(exportMask);
                } else {
                    _dbClient.createObject(exportMask);
                }
                for (String it : matchingInitiators) {
                    Set<URI> maskURIs = matchingMasks.get(it);
                    if (maskURIs == null) {
                        maskURIs = new HashSet<URI>();
                        matchingMasks.put(it, maskURIs);
                    }
                    maskURIs.add(exportMask.getId());
                }
            }
        }
        _log.info(builder.toString());
    } catch (Exception e) {
        String msg = "Error when attempting to query LUN masking information: " + e.getMessage();
        _log.error(MessageFormat.format("Encountered an SMIS error when attempting to query existing exports: {0}", msg), e);
        throw SmisException.exceptions.queryExistingMasksFailure(msg, e);
    } finally {
        if (lunMaskingIter != null) {
            lunMaskingIter.close();
        }
        long totalTime = System.currentTimeMillis() - startTime;
        _log.info(String.format("findExportMasks took %f seconds", (double) totalTime / (double) 1000));
    }
    return matchingMasks;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) CIMProperty(javax.cim.CIMProperty) Initiator(com.emc.storageos.db.client.model.Initiator) WBEMClient(javax.wbem.client.WBEMClient) ExportMask(com.emc.storageos.db.client.model.ExportMask) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) Volume(com.emc.storageos.db.client.model.Volume)

Example 85 with CIMInstance

use of javax.cim.CIMInstance in project coprhd-controller by CoprHD.

the class SmisStorageDevice method checkSyncProgress.

@Override
public Integer checkSyncProgress(final URI storage, final URI source, final URI target) throws DeviceControllerException {
    _log.info("START checkSyncProgress for source: {} target: {}", source, target);
    try {
        StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
        BlockObject sourceObj = BlockObject.fetch(_dbClient, source);
        Volume targetObject = _dbClient.queryObject(Volume.class, target);
        String percentSyncValue = null;
        if (ReplicationState.getEnumValue(targetObject.getReplicaState()) == ReplicationState.DETACHED) {
            return -1;
        }
        CIMObjectPath syncObject = null;
        if (storageSystem.deviceIsType(Type.vmax) && ConsistencyGroupUtils.isCloneInConsistencyGroup(targetObject.getId(), _dbClient)) {
            String consistencyGroupName = ConsistencyGroupUtils.getSourceConsistencyGroupName(sourceObj, _dbClient);
            String replicationGroupName = targetObject.getReplicationGroupInstance();
            syncObject = _cimPath.getGroupSynchronizedPath(storageSystem, consistencyGroupName, replicationGroupName);
        } else {
            syncObject = _cimPath.getStorageSynchronized(storageSystem, sourceObj, storageSystem, targetObject);
        }
        CIMInstance syncInstance = _helper.getInstance(storageSystem, syncObject, false, false, null);
        percentSyncValue = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_PERCENT_SYNCED);
        String copyState = CIMPropertyFactory.getPropertyValue(syncInstance, SmisConstants.CP_COPY_STATE);
        if (copyState.equals(Integer.toString(SmisConstants.FRACTURED)) || copyState.equals(Integer.toString(SmisConstants.SPLIT))) {
            // when fractured or split, the synchronization should have been done.
            percentSyncValue = "100";
        }
        _log.info("DBG Got progress {}", percentSyncValue);
        return Integer.parseInt(percentSyncValue);
    } catch (Exception e) {
        String msg = String.format("Failed to check synchronization progress for %s", target);
        _log.error(msg, e);
    }
    return null;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) CIMObjectPath(javax.cim.CIMObjectPath) BlockObject(com.emc.storageos.db.client.model.BlockObject) CIMInstance(javax.cim.CIMInstance) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

CIMInstance (javax.cim.CIMInstance)370 CIMObjectPath (javax.cim.CIMObjectPath)254 WBEMException (javax.wbem.WBEMException)139 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)104 ArrayList (java.util.ArrayList)98 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)79 URI (java.net.URI)79 CIMArgument (javax.cim.CIMArgument)71 WBEMClient (javax.wbem.client.WBEMClient)69 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)62 Volume (com.emc.storageos.db.client.model.Volume)62 HashSet (java.util.HashSet)60 IOException (java.io.IOException)53 HashMap (java.util.HashMap)52 Iterator (java.util.Iterator)50 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)48 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)48 CIMProperty (javax.cim.CIMProperty)37 StringSet (com.emc.storageos.db.client.model.StringSet)31 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)29