Search in sources :

Example 1 with Path

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

the class HDSExportOperations method checkIfVolumeAlreadyExistsOnHSD.

/**
 * Verify whether volume already exists on the HostGroup.
 *
 * @param devNum
 * @param hsd
 * @return
 */
private boolean checkIfVolumeAlreadyExistsOnHSD(String devNum, HostStorageDomain hsd) {
    boolean isVolumeFound = false;
    List<Path> pathList = hsd.getPathList();
    if (null != pathList && !pathList.isEmpty()) {
        for (Path path : pathList) {
            if (path.getDevNum().equalsIgnoreCase(devNum)) {
                isVolumeFound = true;
                break;
            }
        }
    }
    return isVolumeFound;
}
Also used : Path(com.emc.storageos.hds.model.Path)

Example 2 with Path

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

the class HDSExportOperations method removeVolumes.

@Override
public void removeVolumes(StorageSystem storage, URI exportMaskURI, List<URI> volumes, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} removeVolumes START...", storage.getSerialNumber());
    try {
        log.info("removeVolumes: Export mask id: {}", exportMaskURI);
        log.info("removeVolumes: volumes: {}", Joiner.on(',').join(volumes));
        if (initiatorList != null) {
            log.info("removeVolumes: impacted initiators: {}", Joiner.on(",").join(initiatorList));
        }
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
        String systemObjectID = HDSUtils.getSystemObjectID(storage);
        ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
        if (CollectionUtils.isEmpty(exportMask.getDeviceDataMap())) {
            log.info("HSD's are not found in the exportMask {} device DataMap.", exportMask.getId());
            taskCompleter.ready(dbClient);
        }
        // Get the context from the task completer, in case this is a rollback.
        boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
        ExportMaskValidationContext ctx = new ExportMaskValidationContext();
        ctx.setStorage(storage);
        ctx.setExportMask(exportMask);
        ctx.setBlockObjects(volumes, dbClient);
        ctx.setInitiators(initiatorList);
        // Allow exceptions to be thrown when not rolling back
        ctx.setAllowExceptions(!isRollback);
        AbstractHDSValidator removeVolumeFromMaskValidator = (AbstractHDSValidator) validator.removeVolumes(ctx);
        removeVolumeFromMaskValidator.validate();
        StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
        Set<String> hsdList = deviceDataMap.keySet();
        List<Path> pathObjectIdList = new ArrayList<Path>();
        if (null == hsdList || hsdList.isEmpty()) {
            throw HDSException.exceptions.notAbleToFindHostStorageDomain(systemObjectID);
        }
        if (null != exportMask && !exportMask.getInactive()) {
            for (String hsdObjectId : hsdList) {
                HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectId);
                if (null == hsd) {
                    log.warn("Couldn't find the HSD {} to remove volume from ExportMask", hsdObjectId);
                    continue;
                }
                if (null != hsd.getPathList() && !hsd.getPathList().isEmpty()) {
                    pathObjectIdList.addAll(getPathObjectIdsFromHsd(hsd, volumes));
                }
            }
            if (!pathObjectIdList.isEmpty()) {
                hdsApiClient.getHDSBatchApiExportManager().deleteLUNPathsFromStorageSystem(systemObjectID, pathObjectIdList, storage.getModel());
            } else {
                log.info("No volumes found on system: {}", systemObjectID);
            }
        }
        // Update the status after deleting the volume from all HSD's.
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        log.error(String.format("removeVolume failed - maskURI: %s", exportMaskURI.toString()), e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailedMsg(e.getMessage(), e);
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} removeVolumes END...", storage.getSerialNumber());
}
Also used : Path(com.emc.storageos.hds.model.Path) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) AbstractHDSValidator(com.emc.storageos.volumecontroller.impl.validators.hds.AbstractHDSValidator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) ExportMaskValidationContext(com.emc.storageos.volumecontroller.impl.validators.contexts.ExportMaskValidationContext) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain)

Example 3 with Path

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

the class HDSExportOperations method updateVolumeHLUInfo.

/**
 * Updates the HLU information in the exportmask.
 *
 * @param volumeURIHLUs
 * @param pathList
 * @param exportMask
 */
private void updateVolumeHLUInfo(VolumeURIHLU[] volumeURIHLUs, List<Path> pathList, ExportMask exportMask) {
    if (null != exportMask.getVolumes() && !exportMask.getVolumes().isEmpty()) {
        Map<String, URI> deviceIdToURI = new HashMap<String, URI>();
        Map<URI, Integer> hluMap = new HashMap<URI, Integer>();
        for (VolumeURIHLU vuh : volumeURIHLUs) {
            BlockObject volume = BlockObject.fetch(dbClient, vuh.getVolumeURI());
            exportMask.addToUserCreatedVolumes(volume);
            deviceIdToURI.put(volume.getNativeId(), volume.getId());
        }
        if (!deviceIdToURI.isEmpty()) {
            for (Path path : pathList) {
                if (deviceIdToURI.containsKey(path.getDevNum())) {
                    URI volumeURI = deviceIdToURI.get(path.getDevNum());
                    log.info("updating volume {} info in exportmask.", volumeURI);
                    hluMap.put(volumeURI, Integer.parseInt(path.getLun()));
                }
            }
            exportMask.addVolumes(hluMap);
        } else {
            log.error("No HLU's found for the volumes.");
        }
    }
}
Also used : Path(com.emc.storageos.hds.model.Path) HashMap(java.util.HashMap) URI(java.net.URI) BlockObject(com.emc.storageos.db.client.model.BlockObject) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 4 with Path

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

the class HDSExportOperations method addInitiators.

@Override
public void addInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIs, List<Initiator> initiators, List<URI> targetURIList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} addInitiator START...", storage.getSerialNumber());
    HDSApiClient hdsApiClient = null;
    String systemObjectID = null;
    List<HostStorageDomain> hsdsToCreate = null;
    List<HostStorageDomain> hsdsWithInitiators = null;
    try {
        log.info("addInitiator: Export mask id: {}", exportMaskURI);
        if (volumeURIs != null) {
            log.info("addInitiator: volumes : {}", Joiner.on(',').join(volumeURIs));
        }
        log.info("addInitiator: initiators : {}", Joiner.on(',').join(initiators));
        log.info("addInitiator: targets : {}", Joiner.on(",").join(targetURIList));
        hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
        systemObjectID = HDSUtils.getSystemObjectID(storage);
        ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
        List<StoragePort> ports = dbClient.queryObject(StoragePort.class, targetURIList, true);
        if (checkIfMixedTargetPortTypeSelected(ports)) {
            log.error("Unsupported Host as it has both FC & iSCSI Initiators");
            throw HDSException.exceptions.unsupportedConfigurationFoundInHost();
        }
        // @TODO register new initiators by adding them to host on HiCommand DM.
        // Currently, HiCommand is not supporting this. Need to see how we can handle.
        String hostName = getHostNameForInitiators(initiators);
        String hostMode = null, hostModeOption = null;
        Pair<String, String> hostModeInfo = getHostModeInfo(storage, initiators);
        if (hostModeInfo != null) {
            hostMode = hostModeInfo.first;
            hostModeOption = hostModeInfo.second;
        }
        if (targetURIList != null && !targetURIList.isEmpty()) {
            Set<URI> newTargetPorts = new HashSet<>(targetURIList);
            Set<URI> existingTargetPortsInMask = new HashSet<>();
            if (exportMask.getStoragePorts() != null) {
                existingTargetPortsInMask = new HashSet<>(targetURIList);
                Collection<URI> targetPorts = Collections2.transform(exportMask.getStoragePorts(), CommonTransformerFunctions.FCTN_STRING_TO_URI);
                existingTargetPortsInMask.retainAll(targetPorts);
            }
            newTargetPorts.removeAll(existingTargetPortsInMask);
            log.info("list of new storage target ports {}", newTargetPorts);
            log.info("list of existing storage target ports available in export masks {}", existingTargetPortsInMask);
            // Case 1 is handled here for the new initiators & new target ports.
            if (!newTargetPorts.isEmpty()) {
                // If the HLU's are already configured on this target port, then an exception is thrown.
                // User should make sure that all volumes should have same HLU across all target HSD's.
                VolumeURIHLU[] volumeURIHLUs = getVolumeURIHLUFromExportMask(exportMask);
                if (0 < volumeURIHLUs.length) {
                    List<URI> portList = new ArrayList<>(newTargetPorts);
                    hsdsToCreate = processTargetPortsToFormHSDs(hdsApiClient, storage, portList, 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 to add new initiators. Aborting operation...");
                        throw HDSException.exceptions.notAbleToAddHSD(storage.getSerialNumber());
                    }
                    // Step 2: Add initiators to all HSD's.
                    Iterator<StoragePort> storagePortIterator = dbClient.queryIterativeObjects(StoragePort.class, newTargetPorts);
                    List<StoragePort> stPortList = new ArrayList<>();
                    while (storagePortIterator.hasNext()) {
                        StoragePort stPort = storagePortIterator.next();
                        if (stPort != null && !stPort.getInactive()) {
                            stPortList.add(stPort);
                        }
                    }
                    hsdsWithInitiators = executeBatchHSDAddInitiatorsCommand(hdsApiClient, systemObjectID, hsdResponseList, stPortList, initiators, 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);
                    }
                } else {
                    log.info("There are no volumes on this exportmask: {} to add to new initiator", exportMaskURI);
                }
            }
            // existing HSD to access the volumes already exported in the exportmask.
            if (!existingTargetPortsInMask.isEmpty()) {
                // Step 1: Collect all HSDs from export mask
                StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
                if (null != deviceDataMap && !deviceDataMap.isEmpty()) {
                    List<HostStorageDomain> hsdResponseList = new ArrayList<>();
                    Set<String> hsdObjectIdSet = deviceDataMap.keySet();
                    for (String hsdObjectId : hsdObjectIdSet) {
                        HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectId);
                        if (null == hsd) {
                            throw HDSException.exceptions.notAbleToFindHostStorageDomain(hsdObjectId);
                        }
                        hsdResponseList.add(hsd);
                    }
                    // Step 2: Add initiators to all HSD's.
                    Iterator<StoragePort> storagePortIterator = dbClient.queryIterativeObjects(StoragePort.class, existingTargetPortsInMask, true);
                    List<StoragePort> stPortList = new ArrayList<>();
                    while (storagePortIterator.hasNext()) {
                        StoragePort stPort = storagePortIterator.next();
                        if (stPort != null) {
                            stPortList.add(stPort);
                        }
                    }
                    hsdsWithInitiators = executeBatchHSDAddInitiatorsCommand(hdsApiClient, systemObjectID, hsdResponseList, stPortList, initiators, storage.getModel());
                } else {
                    log.info("There are no hsd information in exportMask to add initiators");
                }
            }
        }
        taskCompleter.ready(dbClient);
    } catch (Exception ex) {
        try {
            log.info("Exception occurred while adding new initiators: {}", 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("addInitiator failed - maskURI: %s", exportMaskURI.toString()), ex);
        } catch (Exception ex1) {
            log.error("Exception occurred while deleting unsuccessful HSDs on system: {}", systemObjectID, ex1.getMessage());
        } finally {
            ServiceError serviceError = DeviceControllerException.errors.jobFailedOpMsg(ResourceOperationTypeEnum.ADD_EXPORT_INITIATOR.getName(), ex.getMessage());
            taskCompleter.error(dbClient, serviceError);
        }
    }
    log.info("{} addInitiator END...", storage.getSerialNumber());
}
Also used : ArrayList(java.util.ArrayList) URI(java.net.URI) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) HashSet(java.util.HashSet) Path(com.emc.storageos.hds.model.Path) HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) ExportMask(com.emc.storageos.db.client.model.ExportMask) StoragePort(com.emc.storageos.db.client.model.StoragePort) HDSApiExportManager(com.emc.storageos.hds.api.HDSApiExportManager) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) HDSException(com.emc.storageos.hds.HDSException) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 5 with Path

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

the class HDSApiExportManager method addLUN.

/**
 * API call to addLun to the storage array.
 * Once the client makes the call, the luns should be visible to the host.
 *
 * @param systemId
 * @param targetPortId
 * @param domainId
 * @param deviceLunList
 * @param model
 * @throws Exception
 */
public List<Path> addLUN(String systemId, String targetPortId, String domainId, Map<String, String> deviceLunList, String model) throws Exception {
    InputStream responseStream = null;
    List<Path> pathList = new ArrayList<Path>();
    try {
        String addLUNQuery = constructAddLUNQuery(systemId, targetPortId, domainId, deviceLunList, pathList, model);
        log.info("Query to addLUN Query: {}", addLUNQuery);
        URI endpointURI = hdsApiClient.getBaseURI();
        ClientResponse response = hdsApiClient.post(endpointURI, addLUNQuery);
        if (HttpStatus.SC_OK == response.getStatus()) {
            responseStream = response.getEntityInputStream();
            JavaResult javaResult = SmooksUtil.getParsedXMLJavaResult(responseStream, HDSConstants.SMOOKS_CONFIG_FILE);
            verifyErrorPayload(javaResult);
            pathList = (List<Path>) javaResult.getBean(HDSConstants.PATHLIST_RESPONSE_BEANID);
            if (pathList.isEmpty()) {
                throw HDSException.exceptions.notAbleToAddVolumeToHSD(domainId, systemId);
            }
        } else {
            throw HDSException.exceptions.invalidResponseFromHDS(String.format("Not able to add Volume to HostStorageDomain due to invalid response %1$s from server", response.getStatus()));
        }
    } finally {
        if (null != responseStream) {
            try {
                responseStream.close();
            } catch (IOException e) {
                log.warn("IOException occurred while closing the response stream");
            }
        }
    }
    return pathList;
}
Also used : Path(com.emc.storageos.hds.model.Path) ClientResponse(com.sun.jersey.api.client.ClientResponse) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URI(java.net.URI) JavaResult(org.milyn.payload.JavaResult)

Aggregations

Path (com.emc.storageos.hds.model.Path)15 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)7 HostStorageDomain (com.emc.storageos.hds.model.HostStorageDomain)6 HDSApiClient (com.emc.storageos.hds.api.HDSApiClient)5 URI (java.net.URI)5 ExportMask (com.emc.storageos.db.client.model.ExportMask)4 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)4 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)4 HDSException (com.emc.storageos.hds.HDSException)4 HDSApiExportManager (com.emc.storageos.hds.api.HDSApiExportManager)4 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)4 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 BlockObject (com.emc.storageos.db.client.model.BlockObject)2 StoragePort (com.emc.storageos.db.client.model.StoragePort)2 StorageArray (com.emc.storageos.hds.model.StorageArray)2 VolumeURIHLU (com.emc.storageos.volumecontroller.impl.VolumeURIHLU)2 ClientResponse (com.sun.jersey.api.client.ClientResponse)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2