Search in sources :

Example 66 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class VmaxExportOperations method deleteMaskingView.

private boolean deleteMaskingView(StorageSystem storage, URI exportMaskURI, Map<StorageGroupPolicyLimitsParam, List<String>> childrenStorageGroupMap, TaskCompleter taskCompleter) throws Exception {
    boolean maskingWasDeleted = false;
    _log.debug("{} deleteMaskingView START...", storage.getSerialNumber());
    String groupName = _helper.getExportMaskName(exportMaskURI);
    CIMInstance maskingViewInstance = maskingViewExists(storage, groupName);
    if (maskingViewInstance == null) {
        _log.info("{} deleteMaskingView END...Masking view already deleted: {}", storage.getSerialNumber(), groupName);
        return true;
    }
    try {
        // get parent ig from masking view
        CIMObjectPath igPath = _helper.getInitiatorGroupForGivenMaskingView(maskingViewInstance.getObjectPath(), storage);
        // Flag to indicate whether or not we need to use the EMCForce flag on this operation.
        // We currently use this flag when dealing with RP Volumes as they are tagged for RP and the
        // operation on these volumes would fail otherwise.
        boolean forceFlag = false;
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        for (String volURI : exportMask.getUserAddedVolumes().values()) {
            forceFlag = ExportUtils.useEMCForceFlag(_dbClient, URI.create(volURI));
            if (forceFlag) {
                break;
            }
        }
        CIMArgument[] inArgs = _helper.getDeleteMaskingViewInputArguments(storage, exportMaskURI, forceFlag);
        CIMArgument[] outArgs = new CIMArgument[5];
        // Collect the current list of associated IGs for the MaskingView. This
        // will include cascaded and child IGs.
        List<CIMObjectPath> igPaths = new ArrayList<CIMObjectPath>();
        getInitiatorGroupsFromMvOrIg(storage, maskingViewInstance.getObjectPath(), igPaths);
        // remove parent IG
        igPaths.remove(igPath);
        WBEMClient client = _helper.getConnection(storage).getCimClient();
        // if SG is associated with other MVs/parent groups, set IO Limits back on it at the end
        for (Entry<StorageGroupPolicyLimitsParam, List<String>> storageGroupEntry : childrenStorageGroupMap.entrySet()) {
            for (String storageGroupName : storageGroupEntry.getValue()) {
                CIMObjectPath storageGroupPath = _cimPath.getMaskingGroupPath(storage, storageGroupName, SmisCommandHelper.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup);
                _helper.resetHostIOLimits(client, storage, storageGroupPath);
            }
        }
        // Invoke operation to delete the MaskingView. This should clean up
        // IG that are directly related to the MV. We will have to check if any
        // others that may be child IGs are left dangling. If they are and not
        // associated with other IGs or MVs, we shall have to delete them.
        SmisSynchSubTaskJob deleteJob = new SmisSynchSubTaskJob(null, storage.getId(), "DeleteMaskingView");
        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "DeleteMaskingView", inArgs, outArgs, deleteJob);
        if (deleteJob.isSuccess()) {
            if (_helper.checkExists(storage, igPath, true, false) != null) {
                List<CIMObjectPath> associatedMaskingViews = getAssociatedMaskingViews(storage, igPath);
                List<CIMObjectPath> associatedIGs = getAssociatedParentIGs(storage, igPath);
                if (associatedMaskingViews.isEmpty() && (associatedIGs.isEmpty() || _helper.isCascadedIG(storage, igPath))) {
                    // parentIGs has associated IGs, not the parent
                    // delete CIG if it is not associated with any MV (CTRL-9662)
                    // CTRL-9323 : deleting Parent IG associated with masking view.
                    deleteInitiatorGroup(storage, igPath);
                } else {
                    _log.info(String.format("Did not delete %s as it is still associated to MaskingViews [%s] and/or AssociatedIGs [%s]", igPath.toString(), Joiner.on(',').join(associatedMaskingViews), Joiner.on(',').join(associatedIGs)));
                }
            } else {
                _log.info("IG already deleted {}", igPath);
            }
            // CTRL-9323 : only child IGs will be processed, as parent is deleted already we will not hit the cyclic
            // issue
            maskingWasDeleted = checkIGsAndDeleteIfUnassociated(storage, igPaths);
            if (!maskingWasDeleted) {
                taskCompleter.error(_dbClient, DeviceControllerException.errors.unableToDeleteIGs(groupName));
                return false;
            }
        } else {
            String opName = ResourceOperationTypeEnum.DELETE_EXPORT_GROUP.getName();
            ServiceError serviceError = DeviceControllerException.errors.jobFailedOp(opName);
            taskCompleter.error(_dbClient, serviceError);
            return maskingWasDeleted;
        }
        _log.debug("{} deleteMaskingView END...", storage.getSerialNumber());
    } catch (WBEMException we) {
        _log.error(String.format("Problem when trying to delete masking view - array: %s, view: %s", storage.getSerialNumber(), groupName), we);
        String opName = ResourceOperationTypeEnum.DELETE_EXPORT_GROUP.getName();
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(we);
        taskCompleter.error(_dbClient, serviceError);
        throw we;
    }
    _log.debug("{} deleteMaskingView END...", storage.getSerialNumber());
    return maskingWasDeleted;
}
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) WBEMException(javax.wbem.WBEMException) CIMInstance(javax.cim.CIMInstance) SmisSynchSubTaskJob(com.emc.storageos.volumecontroller.impl.smis.job.SmisSynchSubTaskJob) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) StorageGroupPolicyLimitsParam(com.emc.storageos.volumecontroller.impl.StorageGroupPolicyLimitsParam) WBEMClient(javax.wbem.client.WBEMClient) CIMArgument(javax.cim.CIMArgument)

Example 67 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class VmaxExportOperations 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 mustHaveAllInitiators
 *            [in] - Indicates if true, *all* the passed in initiators
 *            have to be in the existing matching mask. If false,
 *            a mask with *any* of the specified initiators will be
 *            considered a hit.
 * @return Map of port name to Set of ExportMask URIs
 */
@Override
public Map<String, Set<URI>> findExportMasks(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllInitiators) throws DeviceControllerException {
    long startTime = System.currentTimeMillis();
    Map<String, Set<URI>> matchingMasks = new HashMap<String, Set<URI>>();
    Map<URI, ExportMask> maskMap = new HashMap<>();
    CloseableIterator<CIMInstance> maskInstanceItr = 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);
        // 'maskNames' will be used to do one-time operations against the ExportMask
        List<String> maskNames = new ArrayList<String>();
        Set<String> maskNamesFromArray = new HashSet<>();
        // Iterate through each port name ...
        for (String initiatorName : initiatorPathsMap.keySet()) {
            CIMObjectPath initiatorPath = initiatorPathsMap.get(initiatorName);
            // Find out if there is a MaskingView associated with the initiator ...
            maskInstanceItr = _helper.getAssociatorInstances(storage, initiatorPath, null, SmisConstants.SYMM_LUN_MASKING_VIEW, null, null, SmisConstants.PS_LUN_MASKING_CNTRL_NAME_AND_ROLE);
            while (maskInstanceItr.hasNext()) {
                // Found a MaskingView ...
                CIMInstance instance = maskInstanceItr.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);
                // Look up ExportMask by deviceId/name and storage URI
                ExportMask exportMask = ExportMaskUtils.getExportMaskByName(_dbClient, storage.getId(), name);
                boolean foundMaskInDb = (exportMask != null);
                maskNamesFromArray.add(name);
                // 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);
                }
                // Do some one-time updates for the ExportMask
                if (!maskNames.contains(name)) {
                    // https://coprhd.atlassian.net/browse/COP-20149
                    // Find all the initiators associated with the MaskingView and add them
                    List<String> initiatorPorts = _helper.getInitiatorsFromLunMaskingInstance(client, instance);
                    if (!CollectionUtils.isEmpty(exportMask.getExistingInitiators())) {
                        exportMask.getExistingInitiators().clear();
                    }
                    exportMask.addToExistingInitiatorsIfAbsent(initiatorPorts);
                    // Update the initiator list to include existing initiators if we know about them (and remove from existing)
                    for (String portName : initiatorPorts) {
                        Initiator existingInitiator = ExportUtils.getInitiator(Initiator.toPortNetworkId(portName), _dbClient);
                        if (existingInitiator != null && !ExportMaskUtils.checkIfDifferentResource(exportMask, existingInitiator)) {
                            exportMask.addInitiator(existingInitiator);
                            exportMask.addToUserCreatedInitiators(existingInitiator);
                            exportMask.removeFromExistingInitiators(existingInitiator);
                        }
                    }
                    // Update the tracking containers
                    Map<String, Integer> volumeWWNs = _helper.getVolumesFromLunMaskingInstance(client, instance);
                    if (!CollectionUtils.isEmpty(exportMask.getExistingVolumes())) {
                        exportMask.getExistingVolumes().clear();
                    }
                    exportMask.addToExistingVolumesIfAbsent(volumeWWNs);
                    // Update the volumes list to include existing volumes if we know about them (and remove from existing)
                    if (volumeWWNs != null) {
                        for (Entry<String, Integer> entry : volumeWWNs.entrySet()) {
                            String wwn = entry.getKey();
                            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);
                                    }
                                }
                            }
                        }
                    }
                    // 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);
                    // Get port group for the new exportMask
                    if (!foundMaskInDb) {
                        StoragePortGroup portGroup = null;
                        _log.info("Setting port group for the export mask");
                        String portGroupName = _helper.getPortGroupForGivenMaskingView(name, storage);
                        String guid = String.format("%s+%s", storage.getNativeGuid(), portGroupName);
                        URIQueryResultList result = new URIQueryResultList();
                        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getPortGroupNativeGuidConstraint(guid), result);
                        Iterator<URI> it = result.iterator();
                        if (it.hasNext()) {
                            URI pgURI = it.next();
                            portGroup = _dbClient.queryObject(StoragePortGroup.class, pgURI);
                        } else {
                            portGroup = new StoragePortGroup();
                            portGroup.setId(URIUtil.createId(StoragePortGroup.class));
                            portGroup.setLabel(portGroupName);
                            portGroup.setNativeGuid(guid);
                            portGroup.setStorageDevice(storage.getId());
                            portGroup.setInactive(false);
                            portGroup.setStoragePorts(new StringSet(storagePortURIs));
                            _dbClient.createObject(portGroup);
                        }
                        exportMask.setPortGroup(portGroup.getId());
                        if (isUsePortGroupEnabled()) {
                            portGroup.setRegistrationStatus(RegistrationStatus.REGISTERED.name());
                            portGroup.setMutable(false);
                        } else {
                            portGroup.setRegistrationStatus(RegistrationStatus.UNREGISTERED.name());
                            portGroup.setMutable(true);
                        }
                        _dbClient.updateObject(portGroup);
                    }
                    // Add the mask name to the list for which volumes are already updated
                    maskNames.add(name);
                }
                // Update the maskMap with the latest in-memory exportMask reference.
                maskMap.put(exportMask.getId(), exportMask);
                if (foundMaskInDb) {
                    ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, exportMask);
                    _dbClient.updateObject(exportMask);
                } else {
                    _dbClient.createObject(exportMask);
                }
                // Update our results map
                Set<URI> maskURIs = matchingMasks.get(initiatorName);
                if (maskURIs == null) {
                    maskURIs = new HashSet<>();
                    matchingMasks.put(initiatorName, maskURIs);
                }
                maskURIs.add(exportMask.getId());
            }
        }
        // COP-19514 - After we've found all ExportMasks that are related to a given set of initiators, we
        // need to eliminate any that do not have all the initiators if mustHaveAllInitiators=true. The
        // masksNotContainingAllInitiators set is used to hold references to those ExportMasks that do not
        // match the criteria of having all the initiators.
        Set<URI> masksNotContainingAllInitiators = new HashSet<>();
        if (mustHaveAllInitiators) {
            // Check if each ExportMask has all the ports. If not, add it to masksNotContainingAllInitiators
            for (URI exportMaskURI : maskMap.keySet()) {
                ExportMask mask = maskMap.get(exportMaskURI);
                if (!matchesSearchCriteria(mask, initiatorNames, true)) {
                    masksNotContainingAllInitiators.add(exportMaskURI);
                }
            }
        }
        // Skip the masking views whose IGs can be reused to create a new Masking view instead.
        Set<URI> masksWithReusableIGs = getMasksWhoseIGsCanBeReused(storage, maskMap, initiatorNames);
        // Adjust the matchingMap if there are any masksNotContainingAllInitiators / singleIGContainedMasks
        if (!masksNotContainingAllInitiators.isEmpty() || !masksWithReusableIGs.isEmpty()) {
            _log.info("ExportMasks not containing all initiators requested: {}", masksNotContainingAllInitiators);
            _log.info("ExportMasks whose IGs can be reused to create new masking view: {}", masksWithReusableIGs);
            // Remove references to the ExportMask URIs from the matchingMasks map entries
            Iterator<Entry<String, Set<URI>>> matchingMapEntryIterator = matchingMasks.entrySet().iterator();
            while (matchingMapEntryIterator.hasNext()) {
                Entry<String, Set<URI>> matchingMapEntry = matchingMapEntryIterator.next();
                Set<URI> maskURIs = matchingMapEntry.getValue();
                maskURIs.removeAll(masksNotContainingAllInitiators);
                maskURIs.removeAll(masksWithReusableIGs);
                // If all the ExportMask keys are cleared out, then we need to remove the whole entry
                if (maskURIs.isEmpty()) {
                    matchingMapEntryIterator.remove();
                }
            }
        }
        StringBuilder builder = new StringBuilder();
        for (URI exportMaskURI : maskMap.keySet()) {
            ExportMask exportMask = maskMap.get(exportMaskURI);
            String qualifier = (masksNotContainingAllInitiators.contains(exportMaskURI)) ? ", but not containing all initiators we're looking for" : (masksWithReusableIGs.contains(exportMaskURI) ? ", but it's IGs can be reused to create new masking view" : SmisConstants.EMPTY_STRING);
            builder.append(String.format("\nXM:%s is matching%s: ", exportMask.getMaskName(), qualifier)).append('\n').append(exportMask.toString());
        }
        /**
         * Needs to clean up stale EM from ViPR DB.
         */
        ExportUtils.cleanStaleExportMasks(storage, maskNamesFromArray, initiatorNames, _dbClient);
        _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 (maskInstanceItr != null) {
            maskInstanceItr.close();
        }
        long totalTime = System.currentTimeMillis() - startTime;
        _log.info(String.format("findExportMasks took %f seconds", (double) totalTime / (double) 1000));
    }
    return matchingMasks;
}
Also used : StoragePortGroup(com.emc.storageos.db.client.model.StoragePortGroup) Set(java.util.Set) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) Entry(java.util.Map.Entry) CIMProperty(javax.cim.CIMProperty) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) WBEMClient(javax.wbem.client.WBEMClient) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet) ExportMask(com.emc.storageos.db.client.model.ExportMask) CIMObjectPath(javax.cim.CIMObjectPath) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) Volume(com.emc.storageos.db.client.model.Volume)

Example 68 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class VmaxExportOperations method exportMaskRollback.

/**
 * Export mask operation rollback method.
 *
 * @param storage
 *            storage device
 * @param taskCompleter
 *            task completer
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private void exportMaskRollback(StorageSystem storage, ExportOperationContext context, TaskCompleter taskCompleter) throws Exception {
    // Go through each operation and roll it back.
    if (context != null && context.getOperations() != null) {
        WBEMClient client = _helper.getConnection(storage).getCimClient();
        ListIterator li = context.getOperations().listIterator(context.getOperations().size());
        while (li.hasPrevious()) {
            ExportOperationContextOperation operation = (ExportOperationContextOperation) li.previous();
            // Flag to indicate whether or not we need to use the EMCForce flag on this operation.
            // We currently use this flag when dealing with RP Volumes as they are tagged for RP and the
            // operation on these volumes would fail otherwise.
            // 
            // IMPORTANT NOTE: Default is FALSE, each rollback method will need to determine if it should be set to
            // true if it is needed.
            boolean forceFlag = false;
            try {
                switch(operation.getOperation()) {
                    case VmaxExportOperationContext.OPERATION_ADD_INITIATORS_TO_INITIATOR_GROUP:
                        // remove initiators from the initiator group
                        List<Initiator> initiatorList = (List<Initiator>) operation.getArgs().get(0);
                        CIMObjectPath initiatorGroupPath = (CIMObjectPath) operation.getArgs().get(1);
                        CIMArgument[] inArgs = _helper.getRemoveInitiatorsFromMaskingGroupInputArguments(storage, initiatorGroupPath, initiatorList);
                        CIMArgument[] outArgs = new CIMArgument[5];
                        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
                        break;
                    case VmaxExportOperationContext.OPERATION_ADD_INITIATOR_GROUPS_TO_INITIATOR_GROUP:
                        // remove initiator groups from cascaded initiator group
                        CIMObjectPath childInitiatorGroup = (CIMObjectPath) operation.getArgs().get(0);
                        CIMObjectPath parentInitiatorGroup = (CIMObjectPath) operation.getArgs().get(1);
                        inArgs = _helper.getRemoveIGFromCIG(childInitiatorGroup, parentInitiatorGroup);
                        outArgs = new CIMArgument[5];
                        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
                        break;
                    case VmaxExportOperationContext.OPERATION_CREATE_CASCADING_STORAGE_GROUP:
                    case VmaxExportOperationContext.OPERATION_CREATE_STORAGE_GROUP:
                        // Delete storage group
                        String groupName = (String) operation.getArgs().get(0);
                        // .get(2) arg is different depending on the operation, but for now we don't need it so we
                        // won't get it.
                        _helper.deleteMaskingGroup(storage, groupName, SmisCommandHelper.MASKING_GROUP_TYPE.SE_DeviceMaskingGroup);
                        break;
                    case VmaxExportOperationContext.OPERATION_CREATE_PORT_GROUP:
                        // Delete port group
                        groupName = (String) operation.getArgs().get(0);
                        _helper.deleteMaskingGroup(storage, groupName, SmisCommandHelper.MASKING_GROUP_TYPE.SE_TargetMaskingGroup);
                        break;
                    case VmaxExportOperationContext.OPERATION_ADD_TIER_TO_STORAGE_GROUP:
                        // Remove tier policy from storage group
                        String policyName = (String) operation.getArgs().get(0);
                        CIMObjectPath[] volumeGroupPaths = (CIMObjectPath[]) operation.getArgs().get(1);
                        for (CIMObjectPath volumeGroupPath : volumeGroupPaths) {
                            _helper.removeVolumeGroupFromPolicyAndLimitsAssociation(client, storage, volumeGroupPath);
                        }
                        break;
                    case VmaxExportOperationContext.OPERATION_ADD_STORAGE_GROUP_TO_CASCADING_STORAGE_GROUP:
                        // Remove storage group from cascading storage group
                        groupName = (String) operation.getArgs().get(0);
                        forceFlag = (boolean) operation.getArgs().get(2);
                        CIMObjectPath[] volumeGroupPathList = (CIMObjectPath[]) operation.getArgs().get(1);
                        inArgs = _helper.modifyCascadedStorageGroupInputArguments(storage, groupName, volumeGroupPathList, forceFlag);
                        outArgs = new CIMArgument[5];
                        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
                        break;
                    case VmaxExportOperationContext.OPERATION_CREATE_CASCADED_INITIATOR_GROUP:
                    case VmaxExportOperationContext.OPERATION_CREATE_INITIATOR_GROUP:
                        // Remove initiator group
                        groupName = (String) operation.getArgs().get(0);
                        _helper.deleteMaskingGroup(storage, groupName, SmisCommandHelper.MASKING_GROUP_TYPE.SE_InitiatorMaskingGroup);
                        break;
                    case VmaxExportOperationContext.OPERATION_CREATE_MASKING_VIEW:
                        // Remove masking view
                        String maskName = (String) operation.getArgs().get(0);
                        // Find the mask using the name
                        boolean foundMaskInDb = false;
                        ExportMask exportMask = null;
                        URIQueryResultList uriQueryList = new URIQueryResultList();
                        _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMaskByNameConstraint(maskName), uriQueryList);
                        while (uriQueryList.iterator().hasNext()) {
                            URI uri = uriQueryList.iterator().next();
                            exportMask = _dbClient.queryObject(ExportMask.class, uri);
                            if (exportMask != null && !exportMask.getInactive() && exportMask.getStorageDevice().equals(storage.getId())) {
                                foundMaskInDb = true;
                                // given name for any storage array.
                                break;
                            }
                        }
                        // If we have the mask, check to see if we need to use the force flag
                        if (foundMaskInDb) {
                            for (String volURI : exportMask.getUserAddedVolumes().values()) {
                                forceFlag = ExportUtils.useEMCForceFlag(_dbClient, URI.create(volURI));
                                if (forceFlag) {
                                    break;
                                }
                            }
                        }
                        inArgs = _helper.getDeleteMaskingViewInputArguments(storage, maskName, forceFlag);
                        outArgs = new CIMArgument[5];
                        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "DeleteMaskingView", inArgs, outArgs, null);
                        break;
                    case VmaxExportOperationContext.OPERATION_ADD_PORTS_TO_PORT_GROUP:
                        // Remove ports from port group
                        groupName = (String) operation.getArgs().get(0);
                        List<URI> targetURIList = (List<URI>) operation.getArgs().get(1);
                        inArgs = _helper.getRemoveTargetPortsFromMaskingGroupInputArguments(storage, groupName, targetURIList);
                        outArgs = new CIMArgument[5];
                        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
                        break;
                    case VmaxExportOperationContext.OPERATION_ADD_VOLUMES_TO_STORAGE_GROUP:
                        // Remove volumes from storage group
                        groupName = (String) operation.getArgs().get(0);
                        forceFlag = (boolean) operation.getArgs().get(2);
                        VolumeURIHLU[] volumeList = (VolumeURIHLU[]) operation.getArgs().get(1);
                        List<URI> volumesInSG = new ArrayList<>();
                        for (VolumeURIHLU volumeUriHlu : volumeList) {
                            volumesInSG.add(volumeUriHlu.getVolumeURI());
                        }
                        inArgs = _helper.getRemoveVolumesFromMaskingGroupInputArguments(storage, groupName, volumesInSG, forceFlag);
                        outArgs = new CIMArgument[5];
                        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "RemoveMembers", inArgs, outArgs, null);
                        break;
                    case VmaxExportOperationContext.OPERATION_ADD_EXISTING_INITIATOR_TO_EXPORT_GROUP:
                        URI initiator = (URI) operation.getArgs().get(0);
                        _log.info("Not removing initiator: {} because it already existed in the masking view", initiator);
                        // Ensure the task completer does not remove it from ViPR ExportMask/Group.
                        ((ExportMaskRemoveInitiatorCompleter) taskCompleter).removeInitiator(initiator);
                        break;
                    default:
                }
            } catch (Exception e) {
                _log.error("Exception caught while running rollback", e);
                throw e;
            }
        }
    }
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) ListIterator(java.util.ListIterator) URI(java.net.URI) ExportMaskRemoveInitiatorCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportMaskRemoveInitiatorCompleter) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) Initiator(com.emc.storageos.db.client.model.Initiator) ExportOperationContextOperation(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext.ExportOperationContextOperation) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) WBEMClient(javax.wbem.client.WBEMClient) CIMArgument(javax.cim.CIMArgument) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 69 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class VmaxExportOperations method addInitiators.

@Override
public void addInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIs, List<Initiator> initiatorList, List<URI> targetURIList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("{} addInitiators START...", storage.getSerialNumber());
    try {
        _log.info("addInitiators: Export mask id: {}", exportMaskURI);
        if (volumeURIs != null) {
            _log.info("addInitiators: volumes : {}", Joiner.on(',').join(volumeURIs));
        }
        _log.info("addInitiators: initiators : {}", Joiner.on(',').join(initiatorList));
        _log.info("addInitiators: targets : {}", Joiner.on(",").join(targetURIList));
        ExportOperationContext context = new VmaxExportOperationContext();
        // Prime the context object
        taskCompleter.updateWorkflowStepContext(context);
        ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        String cascadedIGCustomTemplateName = CustomConfigConstants.VMAX_HOST_CASCADED_IG_MASK_NAME;
        String initiatorGroupCustomTemplateName = CustomConfigConstants.VMAX_HOST_INITIATOR_GROUP_MASK_NAME;
        String exportType = ExportMaskUtils.getExportType(_dbClient, mask);
        if (ExportGroupType.Cluster.name().equals(exportType)) {
            cascadedIGCustomTemplateName = CustomConfigConstants.VMAX_CLUSTER_CASCADED_IG_MASK_NAME;
            initiatorGroupCustomTemplateName = CustomConfigConstants.VMAX_CLUSTER_INITIATOR_GROUP_MASK_NAME;
        }
        // Get the export mask complete initiator list. This is required to compute the storage group name
        Set<Initiator> initiators = ExportMaskUtils.getInitiatorsForExportMask(_dbClient, mask, null);
        DataSource cascadedIGDataSource = ExportMaskUtils.getExportDatasource(storage, new ArrayList<Initiator>(initiators), dataSourceFactory, cascadedIGCustomTemplateName);
        String cigName = customConfigHandler.getComputedCustomConfigValue(cascadedIGCustomTemplateName, storage.getSystemType(), cascadedIGDataSource);
        createOrUpdateInitiatorGroups(storage, exportMaskURI, cigName, initiatorGroupCustomTemplateName, initiatorList, taskCompleter);
        if (taskCompleter.isCompleted()) {
            // COP-27456- task already set to error in the above method if any fails.
            _log.info("{} addInitiators END...", storage == null ? null : storage.getSerialNumber());
            return;
        }
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        if (targetURIList != null && !targetURIList.isEmpty() && !exportMask.hasTargets(targetURIList)) {
            _log.info("Adding targets...");
            // always get the port group from the masking view
            CIMInstance portGroupInstance = _helper.getPortGroupInstance(storage, mask.getMaskName());
            if (null == portGroupInstance) {
                String errMsg = String.format("addInitiator failed - maskName %s : Port group not found ", mask.getMaskName());
                ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(errMsg, null);
                taskCompleter.error(_dbClient, serviceError);
                return;
            }
            String pgGroupName = (String) portGroupInstance.getPropertyValue(SmisConstants.CP_ELEMENT_NAME);
            // Get the current ports off of the storage group; only add the ones that aren't there already.
            WBEMClient client = _helper.getConnection(storage).getCimClient();
            List<String> storagePorts = _helper.getStoragePortsFromLunMaskingInstance(client, portGroupInstance);
            Set<URI> storagePortURIs = new HashSet<>();
            storagePortURIs.addAll(transform(ExportUtils.storagePortNamesToURIs(_dbClient, storagePorts), CommonTransformerFunctions.FCTN_STRING_TO_URI));
            // Google Sets.difference returns a non-serializable set, so drop it into a standard HashSet upon
            // return.
            List<URI> diffPorts = new ArrayList<URI>(Sets.difference(newHashSet(targetURIList), storagePortURIs));
            if (!diffPorts.isEmpty()) {
                CIMArgument[] inArgs = _helper.getAddTargetsToMaskingGroupInputArguments(storage, portGroupInstance.getObjectPath(), mask.getMaskName(), Lists.newArrayList(diffPorts));
                CIMArgument[] outArgs = new CIMArgument[5];
                _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "AddMembers", inArgs, outArgs, null);
                ExportOperationContext.insertContextOperation(taskCompleter, VmaxExportOperationContext.OPERATION_ADD_PORTS_TO_PORT_GROUP, pgGroupName, diffPorts);
            } else {
                _log.info(String.format("Target ports already added to port group %s, likely by a previous operation.", pgGroupName));
            }
            _dbClient.updateObject(exportMask);
        }
        _log.info(String.format("addInitiators succeeded - maskName: %s", exportMaskURI.toString()));
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_003);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error(String.format("addInitiators failed - maskName: %s", exportMaskURI.toString()), e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        taskCompleter.error(_dbClient, serviceError);
    }
    _log.info("{} addInitiators END...", storage == null ? null : storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) DataSource(com.emc.storageos.customconfigcontroller.DataSource) Initiator(com.emc.storageos.db.client.model.Initiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) WBEMClient(javax.wbem.client.WBEMClient) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet) CIMArgument(javax.cim.CIMArgument)

Example 70 with WBEMClient

use of javax.wbem.client.WBEMClient in project coprhd-controller by CoprHD.

the class VmaxExportOperations method addStoragePorts.

/**
 * Add storage ports to the port group
 *
 * @param storage - Storage system
 * @param ports - Storage ports to be added
 * @param exportMask - Export mask
 * @return - Storage ports added to the port group
 * @throws Exception
 */
private List<URI> addStoragePorts(StorageSystem storage, Set<URI> ports, ExportMask exportMask) throws Exception {
    if (ports == null || ports.isEmpty()) {
        _log.info("No storage ports, return.");
        return null;
    } else if (exportMask.hasTargets(ports)) {
        _log.info("The exportmask has the targets, do nothing");
        return null;
    }
    _log.info("Adding targets...");
    // always get the port group from the masking view
    CIMInstance portGroupInstance = _helper.getPortGroupInstance(storage, exportMask.getMaskName());
    if (null == portGroupInstance) {
        String errMsg = String.format("add storage ports failed - maskName %s : Port group not found ", exportMask.getMaskName());
        throw DeviceControllerException.exceptions.exportGroupPathAdjustmentError(errMsg);
    }
    String pgGroupName = (String) portGroupInstance.getPropertyValue(SmisConstants.CP_ELEMENT_NAME);
    // Get the current ports off of the storage group; only add the ones that aren't there already.
    WBEMClient client = _helper.getConnection(storage).getCimClient();
    List<String> storagePorts = _helper.getStoragePortsFromLunMaskingInstance(client, portGroupInstance);
    Set<URI> storagePortURIs = new HashSet<>();
    storagePortURIs.addAll(transform(ExportUtils.storagePortNamesToURIs(_dbClient, storagePorts), CommonTransformerFunctions.FCTN_STRING_TO_URI));
    // Google Sets.difference returns a non-serializable set, so drop it into a standard HashSet upon
    // return.
    List<URI> diffPorts = new ArrayList<URI>(Sets.difference(ports, storagePortURIs));
    if (!diffPorts.isEmpty()) {
        CIMArgument[] inArgs = _helper.getAddTargetsToMaskingGroupInputArguments(storage, portGroupInstance.getObjectPath(), exportMask.getMaskName(), Lists.newArrayList(diffPorts));
        CIMArgument[] outArgs = new CIMArgument[5];
        _helper.invokeMethodSynchronously(storage, _cimPath.getControllerConfigSvcPath(storage), "AddMembers", inArgs, outArgs, null);
    } else {
        _log.info(String.format("Target ports already added to port group %s, likely by a previous operation.", pgGroupName));
    }
    return diffPorts;
}
Also used : ArrayList(java.util.ArrayList) WBEMClient(javax.wbem.client.WBEMClient) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) HashSet(java.util.HashSet) CIMArgument(javax.cim.CIMArgument)

Aggregations

WBEMClient (javax.wbem.client.WBEMClient)110 CIMObjectPath (javax.cim.CIMObjectPath)75 CIMInstance (javax.cim.CIMInstance)69 WBEMException (javax.wbem.WBEMException)42 ArrayList (java.util.ArrayList)39 URI (java.net.URI)35 DbClient (com.emc.storageos.db.client.DbClient)29 Volume (com.emc.storageos.db.client.model.Volume)29 CIMConnectionFactory (com.emc.storageos.volumecontroller.impl.smis.CIMConnectionFactory)27 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)25 HashSet (java.util.HashSet)25 CimConnection (com.emc.storageos.cimadapter.connections.cim.CimConnection)24 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)18 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)18 HashMap (java.util.HashMap)17 ExportMask (com.emc.storageos.db.client.model.ExportMask)16 SmisException (com.emc.storageos.volumecontroller.impl.smis.SmisException)16 CIMProperty (javax.cim.CIMProperty)14 UnsignedInteger32 (javax.cim.UnsignedInteger32)14 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)13