Search in sources :

Example 26 with HostStorageDomain

use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.

the class HDSExportMaskValidator method validate.

@Override
public boolean validate() throws Exception {
    log.info("Initiating validation of HDS ExportMask: {}", id);
    try {
        ExportMask exportMask = getExportMask();
        StorageSystem system = getStorage();
        if (exportMask != null && !CollectionUtils.isEmpty(exportMask.getDeviceDataMap())) {
            Set<String> hsdList = exportMask.getDeviceDataMap().keySet();
            HDSApiClient client = getClientFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(system), system.getSmisUserName(), system.getSmisPassword());
            HDSApiExportManager exportManager = client.getHDSApiExportManager();
            String maskName = null;
            String systemObjectID = HDSUtils.getSystemObjectID(system);
            Set<String> volumesInExportMask = new HashSet<>();
            Set<String> initiatorsInExportMask = new HashSet<>();
            if (!CollectionUtils.isEmpty(exportMask.getUserAddedVolumes())) {
                volumesInExportMask.addAll(exportMask.getUserAddedVolumes().keySet());
            }
            if (!CollectionUtils.isEmpty(exportMask.getUserAddedInitiators())) {
                initiatorsInExportMask.addAll(exportMask.getUserAddedInitiators().keySet());
            }
            log.info("Volumes {} in Export Mask {}", volumesInExportMask, exportMask.forDisplay());
            log.info("Initiators {} in Export Mask {}", initiatorsInExportMask, exportMask.forDisplay());
            for (String hsdObjectIdFromDb : hsdList) {
                Set<String> discoveredInitiators = new HashSet<>();
                Set<String> discoveredVolumes = new HashSet<>();
                HostStorageDomain hsd = exportManager.getHostStorageDomain(systemObjectID, hsdObjectIdFromDb);
                if (null == hsd) {
                    continue;
                }
                maskName = (null == hsd.getName()) ? hsd.getNickname() : hsd.getName();
                // Get volumes and initiators from storage system
                discoveredVolumes.addAll(HDSUtils.getVolumesFromHSD(hsd, system).keySet());
                discoveredInitiators.addAll(HDSUtils.getInitiatorsFromHSD(hsd));
                log.info("Volumes {} discovered from array for the HSD {}", discoveredVolumes, maskName);
                log.info("Initiators {} discovered from array for the HSD {}", discoveredInitiators, maskName);
                Set<String> additionalVolumesOnArray = Sets.difference(discoveredVolumes, volumesInExportMask);
                Set<String> additionalInitiatorsOnArray = Sets.difference(discoveredInitiators, initiatorsInExportMask);
                if (!CollectionUtils.isEmpty(additionalVolumesOnArray)) {
                    getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "volumes", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalVolumesOnArray));
                }
                if (!CollectionUtils.isEmpty(additionalInitiatorsOnArray)) {
                    getValidatorLogger().logDiff(String.format("%s - %s", id, maskName), "initiators", ValidatorLogger.NO_MATCHING_ENTRY, Joiner.on("\t").join(additionalInitiatorsOnArray));
                }
            }
            checkForErrors();
        }
    } catch (Exception ex) {
        log.error("Unexpected exception validating ExportMask initiators: " + ex.getMessage(), ex);
        if (getValidatorConfig().isValidationEnabled()) {
            throw DeviceControllerException.exceptions.unexpectedCondition("Unexpected exception validating ExportMask initiators: " + ex.getMessage());
        }
    }
    return true;
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) ExportMask(com.emc.storageos.db.client.model.ExportMask) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) HashSet(java.util.HashSet)

Example 27 with HostStorageDomain

use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.

the class HDSProtectionOperations method addDummyLunPath.

/**
 * Adds Dummy Lun Path to Secondary Volume for pair creation
 *
 * @param client
 * @param volume
 * @throws Exception
 */
public void addDummyLunPath(HDSApiClient client, BlockObject volume) throws Exception {
    StorageSystem system = dbClient.queryObject(StorageSystem.class, volume.getStorageController());
    String systemObjectId = HDSUtils.getSystemObjectID(system);
    ReentrantLock lock = null;
    try {
        /**
         * This will take care synchronization between all cluster node.
         * So that same time two different node can not add same lun to different volumes.
         * This will not take care within the same node.
         */
        locker.acquireLock(systemObjectId, HDSConstants.LOCK_WAIT_SECONDS);
        /**
         * We create and maintain lock instance per storage system.
         * So that multiple thread can not add same lun number to different volumes on same storage system.
         */
        lock = getLock(systemObjectId);
        lock.lock();
        log.info("Acquired Lock to add lun path");
        HostStorageDomain hsd = getDummyHSDFromStorageSystem(client, systemObjectId);
        if (null == hsd) {
            log.info("Creating dummy HSD for ShadowImage");
            // Get any port which belongs to the storage system.
            URIQueryResultList storagePortURIs = new URIQueryResultList();
            dbClient.queryByConstraint(ContainmentConstraint.Factory.getStorageDeviceStoragePortConstraint(system.getId()), storagePortURIs);
            StoragePort storagePort = null;
            Iterator<URI> storagePortsIter = storagePortURIs.iterator();
            while (storagePortsIter.hasNext()) {
                URI storagePortURI = storagePortsIter.next();
                storagePort = dbClient.queryObject(StoragePort.class, storagePortURI);
                if (storagePort != null && !storagePort.getInactive()) {
                    break;
                }
            }
            if (storagePort != null) {
                String portId = HDSUtils.getPortID(storagePort);
                hsd = client.getHDSApiExportManager().addHostStorageDomain(systemObjectId, portId, HDSConstants.HOST_GROUP_DOMAIN_TYPE, null, HDSConstants.DUMMY_HSD, null, null, system.getModel());
                log.info("Created dummy HSD on {} portid", portId);
            }
        }
        List<FreeLun> freeLunList = client.getHDSApiExportManager().getFreeLUNInfo(systemObjectId, hsd.getObjectID());
        log.debug("freeLunList.size :{}", freeLunList.size());
        log.debug("Free lun:{}", freeLunList.get(0).getLun());
        Map<String, String> deviceLunList = new HashMap<String, String>();
        deviceLunList.put(volume.getNativeId(), freeLunList.get(0).getLun());
        client.getHDSApiExportManager().addLUN(systemObjectId, hsd.getPortID(), hsd.getDomainID(), deviceLunList, system.getModel());
        log.info("Completed addDummyLunPath method");
    } finally {
        if (lock != null) {
            lock.unlock();
            log.info("Released Lock to add lun path");
        }
        locker.releaseLock(systemObjectId);
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) FreeLun(com.emc.storageos.hds.model.FreeLun) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 28 with HostStorageDomain

use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.

the class HDSProtectionOperations method getDummyHSDPathId.

/**
 * Get Dummy Lun Path's path objectID
 *
 * @param storageSystem
 * @param volume
 * @return
 * @throws Exception
 */
private String getDummyHSDPathId(StorageSystem storageSystem, BlockObject blockObj) throws Exception {
    String dummyLunPathId = null;
    HDSApiClient apiClient = HDSUtils.getHDSApiClient(hdsApiFactory, storageSystem);
    HDSApiExportManager apiExportManager = apiClient.getHDSApiExportManager();
    String systemObjectId = HDSUtils.getSystemObjectID(storageSystem);
    List<HostStorageDomain> hsdList = apiExportManager.getHostStorageDomains(systemObjectId);
    if (hsdList != null) {
        for (HostStorageDomain hsd : hsdList) {
            if (hsd != null && HDSConstants.DUMMY_HSD.equalsIgnoreCase(hsd.getNickname())) {
                if (hsd.getPathList() != null) {
                    for (Path path : hsd.getPathList()) {
                        if (path.getDevNum().equalsIgnoreCase(blockObj.getNativeId())) {
                            dummyLunPathId = path.getObjectID();
                            log.info("Found secondary volume's dummy lun path id :{}", dummyLunPathId);
                            return dummyLunPathId;
                        }
                    }
                }
            }
        }
    }
    log.info("Dummy lun path has been removed already for this secondary volume");
    return dummyLunPathId;
}
Also used : Path(com.emc.storageos.hds.model.Path) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager)

Example 29 with HostStorageDomain

use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.

the class HDSExportOperations method getHostGroupNetworkIdMap.

/**
 * Constructs a map of [Host Group => Network Id] for the given storage ports.
 *
 * @param sports
 * @param hsds
 * @param dbClient
 * @return
 */
private static Map<HostStorageDomain, URI> getHostGroupNetworkIdMap(List<StoragePort> sports, List<HostStorageDomain> hsds, DbClient dbClient) {
    Map<HostStorageDomain, URI> networkToHSDMap = new HashMap<HostStorageDomain, URI>();
    for (StoragePort sport : sports) {
        NetworkLite network = NetworkUtil.getEndpointNetworkLite(sport.getPortNetworkId(), dbClient);
        if (null != network) {
            if (network != null && network.getInactive() == false && network.getTransportType().equals(sport.getTransportType())) {
                HostStorageDomain hsd = findStoragePortOfHSD(hsds, sport);
                if (null != hsd) {
                    log.info("Found a matching network {} for HSD {}", network.getLabel(), sport.getNativeGuid());
                    networkToHSDMap.put(hsd, network.getId());
                } else {
                    log.error("Couldn't find the HSD configured for port: {}", sport.getNativeGuid());
                }
            }
        }
    }
    return networkToHSDMap;
}
Also used : HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) HashMap(java.util.HashMap) NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI)

Example 30 with HostStorageDomain

use of com.emc.storageos.hds.model.HostStorageDomain in project coprhd-controller by CoprHD.

the class HDSExportOperations method createExportMask.

/**
 * Creates a ExportMask with the given initiators & volumes.
 *
 * Below are the steps to follow to create an Export Mask on Hitachi array.
 * Step 1: Register host with initiators.
 * Step 2: Based on the targetport type, create a Host Storage Domain.
 * Step 3: Add WWN/ISCSI names to the Host Storage Domain.
 * Step 4: Add Luns to the HostStorageDomain created in step 2.
 */
@Override
public void createExportMask(StorageSystem storage, URI exportMaskId, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} createExportMask START...", storage.getSerialNumber());
    HDSApiClient hdsApiClient = null;
    String systemObjectID = null;
    ExportMask exportMask = null;
    List<HostStorageDomain> hsdsWithInitiators = null;
    List<HostStorageDomain> hsdsToCreate = null;
    try {
        log.info("createExportMask: Export mask id :{}", exportMaskId);
        log.info("createExportMask: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        log.info("createExportMask: initiators: {}", Joiner.on(',').join(initiatorList));
        log.info("createExportMask: assignments: {}", Joiner.on(',').join(targetURIList));
        hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        systemObjectID = HDSUtils.getSystemObjectID(storage);
        exportMask = dbClient.queryObject(ExportMask.class, exportMaskId);
        // Check whether host is already registered or not. If host is not
        // registered, add the host.
        registerHostsWithInitiators(initiatorList, hdsApiClient);
        List<StoragePort> storagePorts = dbClient.queryObject(StoragePort.class, targetURIList, true);
        if (checkIfMixedTargetPortTypeSelected(storagePorts)) {
            log.error("Unsupported Host as it has both FC & iSCSI Initiators");
            throw HDSException.exceptions.unsupportedConfigurationFoundInHost();
        }
        if (null != targetURIList && !targetURIList.isEmpty()) {
            String hostName = getHostNameForInitiators(initiatorList);
            String hostMode = null, hostModeOption = null;
            Pair<String, String> hostModeInfo = getHostModeInfo(storage, initiatorList);
            if (hostModeInfo != null) {
                hostMode = hostModeInfo.first;
                hostModeOption = hostModeInfo.second;
            }
            hsdsToCreate = processTargetPortsToFormHSDs(hdsApiClient, storage, targetURIList, hostName, exportMask, hostModeInfo, systemObjectID);
            // Step 1: Create all HSD's using batch operation.
            List<HostStorageDomain> hsdResponseList = hdsApiClient.getHDSBatchApiExportManager().addHostStorageDomains(systemObjectID, hsdsToCreate, storage.getModel());
            if (null == hsdResponseList || hsdResponseList.isEmpty()) {
                log.error("Batch HSD creation failed. Aborting operation...");
                throw HDSException.exceptions.notAbleToAddHSD(storage.getSerialNumber());
            }
            // Step 2: Add initiators to all HSD's.
            hsdsWithInitiators = executeBatchHSDAddInitiatorsCommand(hdsApiClient, systemObjectID, hsdResponseList, storagePorts, initiatorList, storage.getModel());
            // Step 3: Add volumes to all HSD's.
            List<Path> allHSDPaths = executeBatchHSDAddVolumesCommand(hdsApiClient, systemObjectID, hsdsWithInitiators, volumeURIHLUs, storage.getModel());
            if (null != allHSDPaths && !allHSDPaths.isEmpty()) {
                updateExportMaskDetailInDB(hsdsWithInitiators, allHSDPaths, exportMask, storage, volumeURIHLUs);
            }
        }
        taskCompleter.ready(dbClient);
    } catch (Exception ex) {
        // initiators/volumes.
        try {
            log.info("Exception occurred while processing exportmask due to: {}", ex.getMessage());
            if (null != hsdsWithInitiators && !hsdsWithInitiators.isEmpty()) {
                hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectID, hsdsWithInitiators, storage.getModel());
            } else {
                if (null != hsdsToCreate && !hsdsToCreate.isEmpty()) {
                    List<HostStorageDomain> allHSDs = hdsApiClient.getHDSApiExportManager().getHostStorageDomains(systemObjectID);
                    List<HostStorageDomain> partialHSDListToRemove = getPartialHSDListToDelete(allHSDs, hsdsToCreate);
                    hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectID, partialHSDListToRemove, storage.getModel());
                }
            }
            log.error(String.format("createExportMask failed - maskName: %s", exportMaskId.toString()), ex);
        } catch (Exception ex1) {
            log.error("Exception occurred while deleting unsuccessful HSDs on system: {}", systemObjectID, ex1.getMessage());
        } finally {
            ServiceError serviceError = DeviceControllerException.errors.jobFailed(ex);
            taskCompleter.error(dbClient, serviceError);
        }
    }
    log.info("{} createExportMask END...", storage.getSerialNumber());
}
Also used : Path(com.emc.storageos.hds.model.Path) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) StoragePort(com.emc.storageos.db.client.model.StoragePort) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)35 URI (java.net.URI)18 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)16 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)12 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)11 HDSApiExportManager (com.emc.storageos.hds.api.HDSApiExportManager)11 StorageArray (com.emc.storageos.hds.model.StorageArray)11 ClientResponse (com.sun.jersey.api.client.ClientResponse)11 IOException (java.io.IOException)11 InputStream (java.io.InputStream)11 JavaResult (org.milyn.payload.JavaResult)11 ExportMask (com.emc.storageos.db.client.model.ExportMask)10 HDSException (com.emc.storageos.hds.HDSException)9 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)8 Path (com.emc.storageos.hds.model.Path)7 HashSet (java.util.HashSet)7 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)6 StoragePort (com.emc.storageos.db.client.model.StoragePort)5 Add (com.emc.storageos.hds.model.Add)5