Search in sources :

Example 1 with VNXeHostInitiator

use of com.emc.storageos.vnxe.models.VNXeHostInitiator in project coprhd-controller by CoprHD.

the class VNXeExportOperations method addVolumes.

@Override
public void addVolumes(StorageSystem storage, URI exportMaskUri, VolumeURIHLU[] volumeURIHLUs, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _logger.info("{} addVolume START...", storage.getSerialNumber());
    List<URI> mappedVolumes = new ArrayList<URI>();
    ExportMask exportMask = null;
    try {
        _logger.info("addVolumes: Export mask id: {}", exportMaskUri);
        _logger.info("addVolumes: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        if (initiatorList != null) {
            _logger.info("addVolumes: initiators impacted: {}", Joiner.on(',').join(initiatorList));
        }
        ExportOperationContext context = new VNXeExportOperationContext();
        taskCompleter.updateWorkflowStepContext(context);
        VNXeApiClient apiClient = getVnxeClient(storage);
        exportMask = _dbClient.queryObject(ExportMask.class, exportMaskUri);
        if (exportMask == null || exportMask.getInactive()) {
            throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskUri);
        }
        List<Initiator> initiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
        Collection<VNXeHostInitiator> vnxeInitiators = prepareInitiators(initiators).values();
        VNXeBase host = apiClient.prepareHostsForExport(vnxeInitiators);
        String opId = taskCompleter.getOpId();
        Set<String> processedCGs = new HashSet<String>();
        for (VolumeURIHLU volURIHLU : volumeURIHLUs) {
            URI volUri = volURIHLU.getVolumeURI();
            String hlu = volURIHLU.getHLU();
            _logger.info(String.format("hlu %s", hlu));
            BlockObject blockObject = BlockObject.fetch(_dbClient, volUri);
            VNXeExportResult result = null;
            Integer newhlu = -1;
            if (hlu != null && !hlu.isEmpty() && !hlu.equals(ExportGroup.LUN_UNASSIGNED_STR)) {
                newhlu = Integer.valueOf(hlu);
            }
            // COP-25254 this method could be called when create vplex volumes from snapshot. in this case
            // the volume passed in is an internal volume, representing the snapshot. we need to find the snapshot
            // with the same nativeGUID, then export the snapshot.
            BlockObject snapshot = findSnapshotByInternalVolume(blockObject);
            boolean isVplexVolumeFromSnap = false;
            URI vplexBackendVol = null;
            if (snapshot != null) {
                blockObject = snapshot;
                exportMask.addVolume(volUri, newhlu);
                isVplexVolumeFromSnap = true;
                vplexBackendVol = volUri;
                volUri = blockObject.getId();
            }
            String cgName = VNXeUtils.getBlockObjectCGName(blockObject, _dbClient);
            if (cgName != null && !processedCGs.contains(cgName)) {
                processedCGs.add(cgName);
                VNXeUtils.getCGLock(workflowService, storage, cgName, opId);
            }
            String nativeId = blockObject.getNativeId();
            if (URIUtil.isType(volUri, Volume.class)) {
                result = apiClient.exportLun(host, nativeId, newhlu);
                exportMask.addVolume(volUri, result.getHlu());
                if (result.isNewAccess()) {
                    mappedVolumes.add(volUri);
                }
            } else if (URIUtil.isType(volUri, BlockSnapshot.class)) {
                result = apiClient.exportSnap(host, nativeId, newhlu);
                exportMask.addVolume(volUri, result.getHlu());
                if (result.isNewAccess()) {
                    mappedVolumes.add(volUri);
                }
                String snapWWN = setSnapWWN(apiClient, blockObject, nativeId);
                if (isVplexVolumeFromSnap) {
                    Volume backendVol = _dbClient.queryObject(Volume.class, vplexBackendVol);
                    backendVol.setWWN(snapWWN);
                    _dbClient.updateObject(backendVol);
                }
            }
        }
        ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_VOLUMES_TO_HOST_EXPORT, mappedVolumes);
        _dbClient.updateObject(exportMask);
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_002);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _logger.error("Add volumes error: ", e);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addVolume", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
    _logger.info("{} addVolumes END...", storage.getSerialNumber());
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ArrayList(java.util.ArrayList) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URI(java.net.URI) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeExportResult(com.emc.storageos.vnxe.models.VNXeExportResult) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) Volume(com.emc.storageos.db.client.model.Volume) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 2 with VNXeHostInitiator

use of com.emc.storageos.vnxe.models.VNXeHostInitiator in project coprhd-controller by CoprHD.

the class VNXeExportOperations method addInitiators.

@Override
public void addInitiators(StorageSystem storage, URI exportMaskUri, List<URI> volumeURIs, List<Initiator> initiatorList, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
    _logger.info("{} addInitiator START...", storage.getSerialNumber());
    List<Initiator> createdInitiators = new ArrayList<Initiator>();
    ExportMask exportMask = null;
    try {
        ExportOperationContext context = new VNXeExportOperationContext();
        taskCompleter.updateWorkflowStepContext(context);
        exportMask = _dbClient.queryObject(ExportMask.class, exportMaskUri);
        if (exportMask == null || exportMask.getInactive()) {
            throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskUri);
        }
        VNXeApiClient apiClient = getVnxeClient(storage);
        List<Initiator> initiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
        // Finding existing host from the array
        Collection<VNXeHostInitiator> vnxeInitiators = prepareInitiators(initiators).values();
        String hostId = null;
        for (VNXeHostInitiator init : vnxeInitiators) {
            VNXeHostInitiator foundInit = apiClient.getInitiatorByWWN(init.getInitiatorId());
            if (foundInit != null) {
                VNXeBase host = foundInit.getParentHost();
                if (host != null) {
                    hostId = host.getId();
                    break;
                }
            }
        }
        if (hostId == null) {
            String msg = String.format("No existing host found in the array for the existing exportMask %s", exportMask.getMaskName());
            _logger.error(msg);
            ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addiniator", msg);
            taskCompleter.error(_dbClient, error);
            return;
        }
        validateInitiators(_dbClient, initiatorList, apiClient, hostId);
        Map<Initiator, VNXeHostInitiator> initiatorMap = prepareInitiators(initiatorList);
        for (Entry<Initiator, VNXeHostInitiator> entry : initiatorMap.entrySet()) {
            VNXeHostInitiator newInit = entry.getValue();
            VNXeHostInitiator init = apiClient.getInitiatorByWWN(newInit.getInitiatorId());
            // COP-27752 - fresh deleted initiator may not be deleted completely
            int retry = 0;
            while (retry <= MAX_REMOVE_INITIATOR_RETRIES && init != null && init.getParentHost() == null) {
                try {
                    Thread.sleep(WAIT_FOR_RETRY);
                } catch (InterruptedException e1) {
                    Thread.currentThread().interrupt();
                }
                init = apiClient.getInitiatorByWWN(newInit.getInitiatorId());
            }
            if (init != null) {
                // found it
                VNXeBase host = init.getParentHost();
                if (host != null && host.getId().equals(hostId)) {
                    // do nothing. it is already in the array
                    _logger.info("The initiator exist in the host in the array");
                } else if (host == null) {
                    // initiator without parent host, add parent host
                    apiClient.setInitiatorHost(init.getId(), hostId);
                } else {
                    String msg = String.format("Initiator %s belongs to %s, but other initiator belongs to %s. Please move initiator to the correct host", init.getInitiatorId(), host.getId(), hostId);
                    _logger.error(msg);
                    if (!createdInitiators.isEmpty()) {
                        for (Initiator initiator : createdInitiators) {
                            exportMask.getInitiators().add(initiator.getId().toString());
                        }
                        _dbClient.updateObject(exportMask);
                        ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_INITIATORS_TO_HOST, createdInitiators);
                    }
                    ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addiniator", msg);
                    taskCompleter.error(_dbClient, error);
                    return;
                }
            } else {
                apiClient.createInitiator(newInit, hostId);
                createdInitiators.add(entry.getKey());
            }
        }
        for (Initiator initiator : initiatorList) {
            exportMask.getInitiators().add(initiator.getId().toString());
        }
        _dbClient.updateObject(exportMask);
        ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_INITIATORS_TO_HOST, createdInitiators);
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_003);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _logger.error("Add initiators error: ", e);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("addInitiator", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 3 with VNXeHostInitiator

use of com.emc.storageos.vnxe.models.VNXeHostInitiator in project coprhd-controller by CoprHD.

the class VNXUnityArrayAffinityDiscoverer method getPreferredPoolMap.

/**
 * Construct pool to pool type map for a host
 *
 * @param system
 * @param hostId
 * @param apiClient
 * @param dbClient
 * @return pool to pool type map
 * @throws IOException
 */
private Map<String, String> getPreferredPoolMap(StorageSystem system, URI hostId, VNXeApiClient apiClient, DbClient dbClient) throws IOException {
    Map<String, String> preferredPoolMap = new HashMap<String, String>();
    Map<String, StoragePool> pools = getStoragePoolMap(system, dbClient);
    List<Initiator> allInitiators = CustomQueryUtility.queryActiveResourcesByConstraint(dbClient, Initiator.class, ContainmentConstraint.Factory.getContainedObjectsConstraint(hostId, Initiator.class, Constants.HOST));
    String vnxeHostId = null;
    for (Initiator initiator : allInitiators) {
        logger.info("Processing initiator {}", initiator.getLabel());
        String initiatorId = initiator.getInitiatorPort();
        if (Protocol.FC.name().equals(initiator.getProtocol())) {
            initiatorId = initiator.getInitiatorNode() + ":" + initiatorId;
        }
        // query VNX Unity initiator
        VNXeHostInitiator vnxeInitiator = apiClient.getInitiatorByWWN(initiatorId);
        if (vnxeInitiator != null) {
            VNXeBase parentHost = vnxeInitiator.getParentHost();
            if (parentHost != null) {
                vnxeHostId = parentHost.getId();
                break;
            }
        }
    }
    if (vnxeHostId == null) {
        logger.info("Host {} cannot be found on array", hostId);
        return preferredPoolMap;
    }
    // Get vnxeHost from vnxeHostId
    VNXeHost vnxeHost = apiClient.getHostById(vnxeHostId);
    List<VNXeBase> hostLunIds = vnxeHost.getHostLUNs();
    if (hostLunIds != null && !hostLunIds.isEmpty()) {
        for (VNXeBase hostLunId : hostLunIds) {
            HostLun hostLun = apiClient.getHostLun(hostLunId.getId());
            // get lun from from hostLun
            VNXeBase lunId = hostLun.getLun();
            if (lunId != null) {
                VNXeLun lun = apiClient.getLun(lunId.getId());
                if (lun != null) {
                    String nativeGuid = NativeGUIDGenerator.generateNativeGuidForVolumeOrBlockSnapShot(system.getNativeGuid(), lun.getId());
                    if (DiscoveryUtils.checkStorageVolumeExistsInDB(dbClient, nativeGuid) != null) {
                        logger.info("Skipping volume {} as it is already managed by ViPR", nativeGuid);
                        continue;
                    }
                    StoragePool pool = getStoragePoolOfUnManagedObject(lun.getPool().getId(), system, pools);
                    if (pool != null) {
                        String exportType = isSharedLun(lun) ? ExportGroup.ExportGroupType.Cluster.name() : ExportGroup.ExportGroupType.Host.name();
                        ArrayAffinityDiscoveryUtils.addPoolToPreferredPoolMap(preferredPoolMap, pool.getId().toString(), exportType);
                    } else {
                        logger.error("Skipping volume {} as its storage pool doesn't exist in ViPR", lun.getId());
                    }
                }
            }
        }
    }
    return preferredPoolMap;
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) HashMap(java.util.HashMap) HostLun(com.emc.storageos.vnxe.models.HostLun) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) VNXeLun(com.emc.storageos.vnxe.models.VNXeLun)

Example 4 with VNXeHostInitiator

use of com.emc.storageos.vnxe.models.VNXeHostInitiator in project coprhd-controller by CoprHD.

the class VNXUnityExportOperations method findHLUsForInitiators.

@Override
public Set<Integer> findHLUsForInitiators(StorageSystem storage, List<String> initiatorNames, boolean mustHaveAllPorts) {
    Set<Integer> usedHLUs = new HashSet<Integer>();
    try {
        Set<String> vnxeHostIds = new HashSet<String>();
        VNXeApiClient apiClient = getVnxeClient(storage);
        for (String initiatorName : initiatorNames) {
            initiatorName = Initiator.toPortNetworkId(initiatorName);
            URIQueryResultList initiatorResult = new URIQueryResultList();
            _dbClient.queryByConstraint(AlternateIdConstraint.Factory.getInitiatorPortInitiatorConstraint(initiatorName), initiatorResult);
            if (initiatorResult.iterator().hasNext()) {
                Initiator initiator = _dbClient.queryObject(Initiator.class, initiatorResult.iterator().next());
                String initiatorId = initiator.getInitiatorPort();
                if (Protocol.FC.name().equals(initiator.getProtocol())) {
                    initiatorId = initiator.getInitiatorNode() + ":" + initiatorId;
                }
                // query VNX Unity initiator
                VNXeHostInitiator vnxeInitiator = apiClient.getInitiatorByWWN(initiatorId);
                if (vnxeInitiator != null) {
                    VNXeBase parentHost = vnxeInitiator.getParentHost();
                    if (parentHost != null) {
                        vnxeHostIds.add(parentHost.getId());
                    }
                }
            }
        }
        if (vnxeHostIds.isEmpty()) {
            log.info("No Host found on array for initiators {}", Joiner.on(',').join(initiatorNames));
        } else {
            log.info("Found matching hosts {} on array", vnxeHostIds);
            for (String vnxeHostId : vnxeHostIds) {
                // Get vnxeHost from vnxeHostId
                VNXeHost vnxeHost = apiClient.getHostById(vnxeHostId);
                List<VNXeBase> hostLunIds = vnxeHost.getHostLUNs();
                if (hostLunIds != null && !hostLunIds.isEmpty()) {
                    for (VNXeBase hostLunId : hostLunIds) {
                        HostLun hostLun = apiClient.getHostLun(hostLunId.getId());
                        log.info("Looking at Host Lun {}; Lun: {}, HLU: {}", hostLunId.getId(), hostLun.getLun(), hostLun.getHlu());
                        usedHLUs.add(hostLun.getHlu());
                    }
                }
            }
        }
        log.info(String.format("HLUs found for Initiators { %s }: %s", Joiner.on(',').join(initiatorNames), usedHLUs));
    } catch (Exception e) {
        String errMsg = "Encountered an error when attempting to query used HLUs for initiators: " + e.getMessage();
        log.error(errMsg, e);
        throw VNXeException.exceptions.hluRetrievalFailed(errMsg, e);
    }
    return usedHLUs;
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) HostLun(com.emc.storageos.vnxe.models.HostLun) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) VNXeException(com.emc.storageos.vnxe.VNXeException) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) HashSet(java.util.HashSet)

Example 5 with VNXeHostInitiator

use of com.emc.storageos.vnxe.models.VNXeHostInitiator in project coprhd-controller by CoprHD.

the class HostInitiatorTest method getHostInitiator.

@Test
public void getHostInitiator() {
    String wwn = "20:00:00:25:b5:5d:00:04:20:00:00:25:b5:5d:00:e5";
    HostInitiatorRequest req = new HostInitiatorRequest(_client);
    VNXeHostInitiator init = req.getByIQNorWWN(wwn);
    System.out.println(init.getPortWWN());
}
Also used : VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) Test(org.junit.Test)

Aggregations

VNXeHostInitiator (com.emc.storageos.vnxe.models.VNXeHostInitiator)22 Initiator (com.emc.storageos.db.client.model.Initiator)13 VNXeBase (com.emc.storageos.vnxe.models.VNXeBase)11 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)9 URI (java.net.URI)9 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)8 ExportMask (com.emc.storageos.db.client.model.ExportMask)7 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)7 VNXeException (com.emc.storageos.vnxe.VNXeException)6 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)5 ExportOperationContext (com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext)5 VNXeHost (com.emc.storageos.vnxe.models.VNXeHost)4 HashMap (java.util.HashMap)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)3 BlockObject (com.emc.storageos.db.client.model.BlockObject)3 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 StringSet (com.emc.storageos.db.client.model.StringSet)3 HostLun (com.emc.storageos.vnxe.models.HostLun)3 VNXeExportResult (com.emc.storageos.vnxe.models.VNXeExportResult)3