Search in sources :

Example 16 with VNXeHostInitiator

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

the class VNXeExportOperations method createExportMask.

@Override
public void createExportMask(StorageSystem storage, URI exportMask, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    _logger.info("{} createExportMask START...", storage.getSerialNumber());
    VNXeApiClient apiClient = getVnxeClient(storage);
    List<URI> mappedVolumes = new ArrayList<URI>();
    ExportMask mask = null;
    try {
        _logger.info("createExportMask: Export mask id: {}", exportMask);
        _logger.info("createExportMask: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        _logger.info("createExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
        _logger.info("createExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
        ExportOperationContext context = new VNXeExportOperationContext();
        taskCompleter.updateWorkflowStepContext(context);
        mask = _dbClient.queryObject(ExportMask.class, exportMask);
        if (mask == null || mask.getInactive()) {
            throw new DeviceControllerException("Invalid ExportMask URI: " + exportMask);
        }
        Set<String> processedCGs = new HashSet<String>();
        Collection<VNXeHostInitiator> initiators = prepareInitiators(initiatorList).values();
        VNXeBase host = apiClient.prepareHostsForExport(initiators);
        validateInitiators(_dbClient, initiatorList, apiClient, host.getId());
        String opId = taskCompleter.getOpId();
        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);
            String nativeId = blockObject.getNativeId();
            VNXeExportResult result = null;
            Integer newhlu = -1;
            if (hlu != null && !hlu.isEmpty() && !hlu.equals(ExportGroup.LUN_UNASSIGNED_STR)) {
                newhlu = Integer.valueOf(hlu);
            }
            String cgName = VNXeUtils.getBlockObjectCGName(blockObject, _dbClient);
            if (cgName != null && !processedCGs.contains(cgName)) {
                processedCGs.add(cgName);
                VNXeUtils.getCGLock(workflowService, storage, cgName, opId);
            }
            if (URIUtil.isType(volUri, Volume.class)) {
                result = apiClient.exportLun(host, nativeId, newhlu);
                mask.addVolume(volUri, result.getHlu());
                if (result.isNewAccess()) {
                    mappedVolumes.add(volUri);
                }
            } else if (URIUtil.isType(volUri, BlockSnapshot.class)) {
                if (BlockObject.checkForRP(_dbClient, volUri)) {
                    _logger.info(String.format("BlockObject %s is a RecoverPoint bookmark.  Exporting associated lun %s instead of snap.", volUri, nativeId));
                    result = apiClient.exportLun(host, nativeId, newhlu);
                } else {
                    result = apiClient.exportSnap(host, nativeId, newhlu);
                    setSnapWWN(apiClient, blockObject, nativeId);
                }
                mask.addVolume(volUri, result.getHlu());
                if (result.isNewAccess()) {
                    mappedVolumes.add(volUri);
                }
            }
        }
        ExportOperationContext.insertContextOperation(taskCompleter, VNXeExportOperationContext.OPERATION_ADD_VOLUMES_TO_HOST_EXPORT, mappedVolumes);
        mask.setNativeId(host.getId());
        _dbClient.updateObject(mask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _logger.error("Unexpected error: createExportMask failed.", e);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("createExportMask", e.getMessage());
        taskCompleter.error(_dbClient, error);
    }
    _logger.info("{} createExportMask END...", storage.getSerialNumber());
}
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) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URI(java.net.URI) VNXeExportResult(com.emc.storageos.vnxe.models.VNXeExportResult) VNXeException(com.emc.storageos.vnxe.VNXeException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) 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) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 17 with VNXeHostInitiator

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

the class VNXeExportOperations method getHostIdFromInitiators.

private String getHostIdFromInitiators(Collection<Initiator> initiators, VNXeApiClient apiClient) throws Exception {
    // all initiator on ViPR host should be on single host
    String vnxeHostId = null;
    for (Initiator initiator : initiators) {
        _logger.info("Processing initiator {}", initiator.getLabel());
        String initiatorId = initiator.getInitiatorPort();
        if (Protocol.FC.name().equals(initiator.getProtocol())) {
            initiatorId = initiator.getInitiatorNode() + ":" + initiatorId;
        }
        // query initiator on array
        VNXeHostInitiator vnxeInitiator = apiClient.getInitiatorByWWN(initiatorId);
        if (vnxeInitiator != null) {
            VNXeBase parentHost = vnxeInitiator.getParentHost();
            if (parentHost != null) {
                if (vnxeHostId == null) {
                    vnxeHostId = parentHost.getId();
                } else if (!vnxeHostId.equals(parentHost.getId())) {
                    String msg = String.format("Initiator %s belongs to %s, but other initiator belongs to %s. Please move initiator to the correct host", initiator.getInitiatorPort(), parentHost.getId(), vnxeHostId);
                    _logger.error(msg);
                    throw new DeviceControllerException(msg);
                }
            }
        }
    }
    if (vnxeHostId == null) {
        _logger.warn("No host found");
    }
    return vnxeHostId;
}
Also used : VNXeBase(com.emc.storageos.vnxe.models.VNXeBase) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 18 with VNXeHostInitiator

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

the class VNXeExportOperations method validateInitiators.

/**
 * Validate all initiators of VNXeHost on single ViPR host, or unknown to ViPR
 *
 * @param dbClient DbClient
 * @param initiators list of initiators that are/will be in the mask (for export mask creation)
 * @param apiClient VNXeApiClient
 * @param vnxeHostId VNXe host Id
 * @return true if validation is passed
 */
private boolean validateInitiators(DbClient dbClient, List<Initiator> initiators, VNXeApiClient apiClient, String vnxeHostId) {
    if (ExportMaskUtils.areBackendInitiators(initiators)) {
        return true;
    }
    List<VNXeHostInitiator> initiatorList = apiClient.getInitiatorsByHostId(vnxeHostId);
    URI hostId = null;
    if (initiatorList != null) {
        for (VNXeHostInitiator initiator : initiatorList) {
            String portWWN = null;
            if (HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI.equals(initiator.getType())) {
                portWWN = initiator.getInitiatorId();
            } else {
                portWWN = initiator.getPortWWN();
            }
            Initiator viprInitiator = NetworkUtil.findInitiatorInDB(portWWN, dbClient);
            if (viprInitiator != null) {
                if (NullColumnValueGetter.isNullURI(hostId)) {
                    hostId = viprInitiator.getHost();
                } else if (!hostId.equals(viprInitiator.getHost())) {
                    String msg = String.format("Found initiators with different host Ids. Initiator %s belongs to host %s, but other initiator belongs to host %s", portWWN, viprInitiator.getHost(), hostId);
                    throw new DeviceControllerException(msg);
                }
            }
        }
    }
    return true;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URI(java.net.URI) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 19 with VNXeHostInitiator

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

the class VNXeExportOperations method validateAllMasks.

/**
 * Check if all shared masks have same set of initiators
 * Could be subset of host initiators, but all masks should have same initiators
 * Initiators have already been removed from host will be ignored in the validation
 *
 * @param dbClient
 * @param exportMask
 * @param apiClient
 * @param vnxeHostId
 * @return collection of export masks of the host
 */
private Collection<ExportMask> validateAllMasks(DbClient dbClient, ExportMask exportMask, VNXeApiClient apiClient, String vnxeHostId) throws DeviceControllerException {
    URI hostUri = null;
    for (String init : exportMask.getInitiators()) {
        Initiator initiator = dbClient.queryObject(Initiator.class, URI.create(init));
        if (initiator != null && !initiator.getInactive()) {
            hostUri = initiator.getHost();
            if (!NullColumnValueGetter.isNullURI(hostUri)) {
                break;
            }
        }
    }
    // get initiators on array
    Set<String> viprInitiators = new HashSet<>();
    List<VNXeHostInitiator> initiatorList = apiClient.getInitiatorsByHostId(vnxeHostId);
    if (initiatorList != null) {
        for (VNXeHostInitiator initiator : initiatorList) {
            String portWWN = initiator.getPortWWN();
            if (HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI.equals(initiator.getType())) {
                portWWN = initiator.getInitiatorId();
            }
            Initiator viprInitiator = NetworkUtil.findInitiatorInDB(portWWN, dbClient);
            if (viprInitiator != null) {
                if (!hostUri.equals(viprInitiator.getHost())) {
                    String msg = String.format("Initiator %s is not associated with the correct host. Please move the initiator to the correct host", portWWN);
                    _logger.error(msg);
                    throw new DeviceControllerException(msg);
                }
                viprInitiators.add(viprInitiator.getId().toString());
            }
        }
    }
    // get initiators from host
    Map<URI, ExportMask> exportMasks = new HashMap<>();
    Map<URI, Set<String>> maskToInitiator = new HashMap<>();
    if (!NullColumnValueGetter.isNullURI(hostUri)) {
        URIQueryResultList list = new URIQueryResultList();
        dbClient.queryByConstraint(ContainmentConstraint.Factory.getContainedObjectsConstraint(hostUri, Initiator.class, "host"), list);
        Iterator<URI> uriIter = list.iterator();
        while (uriIter.hasNext()) {
            URI initiatorId = uriIter.next();
            URIQueryResultList egUris = new URIQueryResultList();
            dbClient.queryByConstraint(AlternateIdConstraint.Factory.getExportGroupInitiatorConstraint(initiatorId.toString()), egUris);
            ExportGroup exportGroup = null;
            for (URI egUri : egUris) {
                exportGroup = dbClient.queryObject(ExportGroup.class, egUri);
                if (exportGroup == null || exportGroup.getInactive() || exportGroup.getExportMasks() == null) {
                    continue;
                }
                List<ExportMask> masks = ExportMaskUtils.getExportMasks(dbClient, exportGroup);
                for (ExportMask mask : masks) {
                    if (mask != null && !mask.getInactive() && !mask.getId().equals(exportMask.getId()) && mask.hasInitiator(initiatorId.toString()) && mask.getVolumes() != null) {
                        if (!exportMasks.containsKey(mask.getId())) {
                            exportMasks.put(mask.getId(), mask);
                            Set<String> initiators = new HashSet<String>(mask.getInitiators());
                            // not include initiators that have been removed from array
                            initiators.retainAll(viprInitiators);
                            maskToInitiator.put(mask.getId(), initiators);
                        }
                    }
                }
            }
        }
    }
    // validate each mask has same set of initiators (not include initiators that have been removed from array)
    Set<String> usedInitiators = new HashSet<String>(exportMask.getInitiators());
    usedInitiators.retainAll(viprInitiators);
    for (Set<String> initiators : maskToInitiator.values()) {
        if (usedInitiators.size() != initiators.size() || !usedInitiators.containsAll(initiators)) {
            throw new DeviceControllerException("Removing initiators from export group is not allowed because host has multiple export groups with different sets of initiators. Please delete individual export group.");
        }
    }
    return exportMasks.values();
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HashSet(java.util.HashSet)

Example 20 with VNXeHostInitiator

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

the class VNXeExportOperations method prepareInitiators.

private Map<Initiator, VNXeHostInitiator> prepareInitiators(List<Initiator> initiators) {
    Map<Initiator, VNXeHostInitiator> result = new HashMap<Initiator, VNXeHostInitiator>();
    for (Initiator init : initiators) {
        _logger.info("initiator: {}", init.getId().toString());
        VNXeHostInitiator hostInit = new VNXeHostInitiator();
        hostInit.setName(init.getHostName());
        String protocol = init.getProtocol();
        if (protocol.equalsIgnoreCase(Protocol.iSCSI.name())) {
            hostInit.setType(VNXeHostInitiator.HostInitiatorTypeEnum.INITIATOR_TYPE_ISCSI);
            hostInit.setChapUserName(init.getInitiatorPort());
            hostInit.setInitiatorId(init.getInitiatorPort());
        } else if (protocol.equalsIgnoreCase(Protocol.FC.name())) {
            hostInit.setType(VNXeHostInitiator.HostInitiatorTypeEnum.INITIATOR_TYPE_FC);
            String portWWN = init.getInitiatorPort();
            String nodeWWN = init.getInitiatorNode();
            StringBuilder builder = new StringBuilder(nodeWWN);
            builder.append(":");
            builder.append(portWWN);
            hostInit.setInitiatorId(builder.toString());
            hostInit.setNodeWWN(nodeWWN);
            hostInit.setPortWWN(portWWN);
        } else {
            _logger.info("The initiator {} protocol {} is not supported, skip", init.getId(), init.getProtocol());
            continue;
        }
        URI hostUri = init.getHost();
        if (!NullColumnValueGetter.isNullURI(hostUri)) {
            Host host = _dbClient.queryObject(Host.class, hostUri);
            if (host != null) {
                String hostType = host.getType();
                if (NullColumnValueGetter.isNotNullValue(hostType) && !hostType.equalsIgnoreCase(OTHER)) {
                    hostInit.setHostOsType(hostType);
                }
            }
        }
        result.put(init, hostInit);
    }
    return result;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) HashMap(java.util.HashMap) VNXeHost(com.emc.storageos.vnxe.models.VNXeHost) Host(com.emc.storageos.db.client.model.Host) VNXeHostInitiator(com.emc.storageos.vnxe.models.VNXeHostInitiator) URI(java.net.URI)

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