Search in sources :

Example 91 with ExportMask

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

the class MaskingWorkflowEntryPoints method doExportGroupAddVolumes.

public void doExportGroupAddVolumes(URI storageURI, URI exportGroupURI, URI exportMaskURI, Map<URI, Integer> volumeMap, List<URI> initiatorURIs, TaskCompleter taskCompleter, String token) throws ControllerException {
    String call = String.format("doExportGroupAddVolumes(%s, %s, %s, [%s], [%s], %s)", storageURI.toString(), exportGroupURI.toString(), exportMaskURI.toString(), volumeMap != null ? Joiner.on(',').join(volumeMap.entrySet()) : "No Volumes", initiatorURIs != null ? Joiner.on(',').join(initiatorURIs) : "No Initiators", taskCompleter.getOpId());
    try {
        WorkflowStepCompleter.stepExecuting(token);
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        StorageSystem storage = _dbClient.queryObject(StorageSystem.class, storageURI);
        List<Initiator> initiators = new ArrayList<>();
        if (initiatorURIs != null && !initiatorURIs.isEmpty()) {
            initiators = _dbClient.queryObject(Initiator.class, initiatorURIs);
        }
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_001);
        getDevice(storage).doExportAddVolumes(storage, exportMask, initiators, volumeMap, taskCompleter);
        _log.info(String.format("%s end", call));
    } catch (final InternalException e) {
        _log.info(call + " Encountered an exception", e);
        taskCompleter.error(_dbClient, e);
    } catch (final Exception e) {
        _log.info(call + " Encountered an exception", e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        taskCompleter.error(_dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 92 with ExportMask

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

the class VmaxPortGroupProcessor method getExportMasksForPortGroup.

/**
 * Get export masks using the specified port group
 *
 * @param client
 *            - WBEMClient
 * @param groupPath
 *            - port group CIMObjectPath
 * @param portGroupName
 *            - port group name
 * @param device
 *            - Storage system
 * @return List of export mask using this port group
 */
private List<ExportMask> getExportMasksForPortGroup(WBEMClient client, CIMObjectPath groupPath, String portGroupName, StorageSystem device) {
    List<ExportMask> result = new ArrayList<ExportMask>();
    CloseableIterator<CIMInstance> iterator = null;
    try {
        iterator = client.associatorInstances(groupPath, null, Constants.SYMM_LUNMASKINGVIEW, null, null, false, Constants.PS_NAME);
        if (!iterator.hasNext()) {
            // No lun masking view associated.
            return result;
        }
        while (iterator.hasNext()) {
            CIMInstance cimInstance = iterator.next();
            String maskName = CIMPropertyFactory.getPropertyValue(cimInstance, Constants._Name);
            if (maskName != null) {
                // Try to see if we could find export mask in ViPR has the same name
                URIQueryResultList exportMaskURIs = new URIQueryResultList();
                dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMaskByNameConstraint(maskName), exportMaskURIs);
                Iterator<URI> maskIt = exportMaskURIs.iterator();
                while (maskIt.hasNext()) {
                    URI maskURI = maskIt.next();
                    ExportMask mask = dbClient.queryObject(ExportMask.class, maskURI);
                    if (device.getId().equals(mask.getStorageDevice()) && mask.getUserAddedVolumes() != null && !mask.getUserAddedVolumes().isEmpty()) {
                        result.add(mask);
                        log.info(String.format("The port group %s is used by the export mask %s %s", portGroupName, maskName, maskURI.toString()));
                    }
                }
            }
        }
    } catch (Exception e) {
        log.warn("Exception while getting port gorup association:", e);
    } finally {
        if (null != iterator) {
            iterator.close();
        }
    }
    return result;
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) URI(java.net.URI) CIMInstance(javax.cim.CIMInstance) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException)

Example 93 with ExportMask

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

the class PortMetricsProcessor method checkForMatchingExportMask.

/**
 * Checks to see if there is an ExportMask of the given maskName belonging
 * to specified device with same nativeId.
 *
 * @param maskName -- String mask name. It's an alternate index to ExportMask.
 * @param nativeId -- String native id of mask.
 * @param device -- URI of device
 * @return true if there is a matching ExportMask, false otherwise
 */
private boolean checkForMatchingExportMask(String maskName, String nativeId, URI device) {
    URIQueryResultList uriQueryList = new URIQueryResultList();
    _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportMaskByNameConstraint(maskName), uriQueryList);
    while (uriQueryList.iterator().hasNext()) {
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, uriQueryList.iterator().next());
        if (exportMask != null && !exportMask.getInactive() && (exportMask.getNativeId() != null && exportMask.getNativeId().equals(nativeId)) && exportMask.getStorageDevice().equals(device)) {
            return true;
        }
    }
    return false;
}
Also used : UnManagedExportMask(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedExportMask) ExportMask(com.emc.storageos.db.client.model.ExportMask) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 94 with ExportMask

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

the class VnxExportOperations method createOrGrowStorageGroup.

private CIMObjectPath[] createOrGrowStorageGroup(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<Initiator> initiatorList, List<URI> targetURIList, TaskCompleter completer) throws Exception {
    // TODO - Refactor createOrGrowStorageGroup by moving code for creating an empty storage group
    // to its own createStorageGroup method which calls exposePaths with null for initiators
    // and targets
    _log.info("{} createOrGrowStorageGroup START...", storage.getSerialNumber());
    try {
        List<CIMObjectPath> paths = new ArrayList<CIMObjectPath>();
        Map<String, CIMObjectPath> existingHwStorageIds = getStorageHardwareIds(storage);
        // If so, we need to register that initiator as the same name as the existing initiators. (CTRL-8407)
        if (initiatorList != null) {
            for (Initiator initiator : initiatorList) {
                updateInitiatorBasedOnPeers(storage, existingHwStorageIds, initiator);
                if (initiator != null) {
                    _log.info("After updateIntiatorBasedOnPeers : {} {}", initiator.getHostName(), initiator.toString());
                }
            }
        }
        Multimap<String, String> existingTargets = createStorageHWIDs(storage, existingHwStorageIds, initiatorList, completer);
        if (initiatorList != null && existingTargets.keySet().size() == initiatorList.size()) {
            _log.info(String.format("All the initiators are known to the array and have target endpoints: %s\n." + "These are the targets %s", Joiner.on(',').join(existingTargets.entries()), Joiner.on(',').join(targetURIList)));
        }
        Multimap<URI, Initiator> targetPortsToInitiators = HashMultimap.create();
        // Some of the Initiators are already registered partially on the array based on pre existing zoning
        // COP-16954 We need to manually register them, the Initiators will have HardwareId created but,
        // The registration is not complete.. createHardwareIDs method above will include those Initiators
        _log.info("Preregistered Target and Initiator ports processing .. Start");
        // Map to hash translations
        HashMap<String, URI> targetPortMap = new HashMap<>();
        for (String initPort : existingTargets.keySet()) {
            _log.info("InitiatorPort {} and TargetStoragePort {}", initPort, existingTargets.get(initPort));
            // CLARIION+CKM00115001014+PORT+50:06:01:61:3E:A0:45:79]
            if (!WWNUtility.isValidNoColonWWN(initPort)) {
                _log.info("InitiatorPort {} is not a valid FC WWN so ignore it", initPort);
                continue;
            }
            Collection<String> targetPorts = existingTargets.get(initPort);
            for (String targetPortGuid : targetPorts) {
                URI targetPortURI = targetPortMap.get(targetPortGuid);
                if (targetPortURI == null) {
                    targetPortURI = getStoragePortURI(targetPortGuid);
                    targetPortMap.put(targetPortGuid, targetPortURI);
                }
                Initiator translatedInitiator = getInitiatorForWWN(initPort);
                _log.info("Calculating Initiator {} and Target {}", translatedInitiator, targetPortURI);
                if (targetPortURI != null && translatedInitiator != null) {
                    targetPortsToInitiators.put(targetPortURI, translatedInitiator);
                } else {
                    _log.info("Initiator WWN {} translation was null or targetPort is null {}", initPort, targetPortURI);
                }
            }
        }
        _log.info("Preregistered Target and Initiator ports processing .. End");
        List<URI> volumeURIs = new ArrayList<URI>();
        if (volumeURIHLUs != null && volumeURIHLUs.length > 0) {
            for (VolumeURIHLU volumeURIHLU : volumeURIHLUs) {
                volumeURIs.add(volumeURIHLU.getVolumeURI());
            }
        }
        if (initiatorList == null || initiatorList.isEmpty()) {
            _log.info("InitiatorList is null or Empty so call exposePathsWithVolumesOnly");
            paths.addAll(Arrays.asList(exposePathsWithVolumesOnly(storage, exportMaskURI, volumeURIHLUs)));
        } else {
            ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
            for (Initiator initiator : initiatorList) {
                // TODO - Ask Tom is there is a reason why we should not do this instead of old code
                List<URI> tzTargets = ExportUtils.getInitiatorPortsInMask(mask, initiator, _dbClient);
                _log.info("Calculating Intiator {} and Targets {}", initiator, tzTargets);
                if (!tzTargets.isEmpty()) {
                    for (URI targetURI : tzTargets) {
                        targetPortsToInitiators.put(targetURI, initiator);
                    }
                }
            }
            _log.info("Call manuallyRegisterHostInitiators with {} ", targetPortsToInitiators.toString());
            // Register the initiator to target port mappings
            manuallyRegisterHostInitiators(storage, targetPortsToInitiators);
            // CTRL-9086
            // Modify the list of initiators list to match what is being mapped. If there are any initiators
            // that are passed to the ExposePaths call that weren't manuallyRegistered (above), then those
            // initiators will automatically get mapped all the array's StoragePorts.
            // 
            // If the targetPortsToInitiators MultiMap is empty, then we will send all the initiators.
            // Presumably, in this situation there are already some existing mappings for the initiators,
            // so would just need to call ExposePaths with those initiators, so that they get added to the
            // StorageGroup
            List<Initiator> initiatorsToExpose = initiatorList;
            if (!targetPortsToInitiators.isEmpty()) {
                Map<URI, Initiator> uniqueInitiatorMap = new HashMap<>();
                for (Collection<Initiator> initiatorCollection : targetPortsToInitiators.asMap().values()) {
                    for (Initiator initiator : initiatorCollection) {
                        uniqueInitiatorMap.put(initiator.getId(), initiator);
                    }
                }
                initiatorsToExpose = new ArrayList<>(uniqueInitiatorMap.values());
                // confused about the initiators.
                if (completer instanceof ExportMaskCreateCompleter) {
                    ExportMaskCreateCompleter createCompleter = ((ExportMaskCreateCompleter) completer);
                    List<URI> removedInitiators = new ArrayList<>();
                    List<URI> maskInitiators = StringSetUtil.stringSetToUriList(mask.getInitiators());
                    for (URI maskInitiator : maskInitiators) {
                        if (!uniqueInitiatorMap.containsKey(maskInitiator)) {
                            mask.removeInitiator(maskInitiator);
                            removedInitiators.add(maskInitiator);
                        }
                    }
                    _dbClient.updateObject(mask);
                    if (!removedInitiators.isEmpty()) {
                        _log.info(String.format("The following initiators will not be mapped, hence they will be " + "removed from the initiator list of ExportMask %s (%s): %s", mask.getMaskName(), mask.getId(), Joiner.on(',').join(removedInitiators)));
                    }
                    // Adjust the completer's initiator list
                    createCompleter.removeInitiators(removedInitiators);
                }
            }
            _log.info(String.format("ExposePaths will be called with these initiators: %s", Joiner.on(',').join(Collections2.transform(initiatorsToExpose, CommonTransformerFunctions.fctnInitiatorToPortName()))));
            // Add all the initiators to the StorageGroup
            paths.addAll(Arrays.asList(exposePathsWithVolumesAndInitiatorsOnly(storage, exportMaskURI, volumeURIHLUs, initiatorsToExpose)));
        }
        ExportOperationContext.insertContextOperation(completer, VnxExportOperationContext.OPERATION_ADD_VOLUMES_TO_STORAGE_GROUP, volumeURIs);
        _log.info("{} createOrGrowStorageGroup END...", storage.getSerialNumber());
        return paths.toArray(new CIMObjectPath[paths.size()]);
    } catch (WBEMException e) {
        _log.error("Problem making SMI-S call: ", e);
        throw e;
    } catch (Exception e) {
        _log.error("Unexpected error: createOrGrowStorageGroup failed.", e);
        throw e;
    }
}
Also used : HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) CIMObjectPath(javax.cim.CIMObjectPath) ArrayList(java.util.ArrayList) WBEMException(javax.wbem.WBEMException) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) WBEMException(javax.wbem.WBEMException) SmisException(com.emc.storageos.volumecontroller.impl.smis.SmisException) ExportMaskCreateCompleter(com.emc.storageos.volumecontroller.impl.block.taskcompleter.ExportMaskCreateCompleter) Initiator(com.emc.storageos.db.client.model.Initiator) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 95 with ExportMask

use of com.emc.storageos.db.client.model.ExportMask 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)

Aggregations

ExportMask (com.emc.storageos.db.client.model.ExportMask)368 URI (java.net.URI)274 ArrayList (java.util.ArrayList)224 Initiator (com.emc.storageos.db.client.model.Initiator)155 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)140 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)134 HashMap (java.util.HashMap)128 HashSet (java.util.HashSet)121 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)107 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)102 List (java.util.List)79 StringSet (com.emc.storageos.db.client.model.StringSet)68 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)65 Map (java.util.Map)65 StringMap (com.emc.storageos.db.client.model.StringMap)60 BlockObject (com.emc.storageos.db.client.model.BlockObject)56 NamedURI (com.emc.storageos.db.client.model.NamedURI)56 Workflow (com.emc.storageos.workflow.Workflow)54 Set (java.util.Set)51 Volume (com.emc.storageos.db.client.model.Volume)44