Search in sources :

Example 71 with StringSetMap

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

the class HDSExportOperations method deleteExportMask.

@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());
    List<HostStorageDomain> hsdToDeleteList = new ArrayList<HostStorageDomain>();
    try {
        log.info("deleteExportMask: 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));
        }
        // Get the context from the task completer, in case this is a rollback.
        boolean isRollback = WorkflowService.getInstance().isStepInRollbackState(taskCompleter.getOpId());
        ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
        ExportMaskValidationContext ctx = new ExportMaskValidationContext();
        ctx.setStorage(storage);
        ctx.setExportMask(exportMask);
        ctx.setBlockObjects(volumeURIList, dbClient);
        ctx.setInitiators(initiatorList);
        // Allow exceptions to be thrown when not rolling back
        ctx.setAllowExceptions(!isRollback);
        AbstractHDSValidator deleteMaskValidator = (AbstractHDSValidator) validator.exportMaskDelete(ctx);
        deleteMaskValidator.validate();
        HDSApiClient hdsApiClient = hdsApiFactory.getClient(HDSUtils.getHDSServerManagementServerInfo(storage), storage.getSmisUserName(), storage.getSmisPassword());
        HDSApiExportManager exportMgr = hdsApiClient.getHDSApiExportManager();
        String systemObjectId = HDSUtils.getSystemObjectID(storage);
        StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
        if (null != deviceDataMap && !deviceDataMap.isEmpty()) {
            Set<String> hsdObjectIdList = deviceDataMap.keySet();
            for (String hsdObjectIdFromDb : hsdObjectIdList) {
                HostStorageDomain hsdObj = exportMgr.getHostStorageDomain(systemObjectId, hsdObjectIdFromDb);
                if (null != hsdObj) {
                    hsdToDeleteList.add(hsdObj);
                }
            }
            if (!hsdToDeleteList.isEmpty()) {
                hdsApiClient.getHDSBatchApiExportManager().deleteBatchHostStorageDomains(systemObjectId, hsdToDeleteList, storage.getModel());
            }
            // By this time, we have removed all HSD's created in this mask.
            taskCompleter.ready(dbClient);
        } else {
            String message = String.format("ExportMask %s does not have a configured HSD's, " + "indicating that this export may not have been created " + "successfully. Marking the delete operation ready.", exportMaskURI.toString());
            log.info(message);
            taskCompleter.ready(dbClient);
            return;
        }
    } catch (Exception e) {
        log.error("Unexpected error: deleteExportMask failed.", e);
        ServiceError error = DeviceControllerErrors.hds.methodFailed("deleteExportMask", e.getMessage());
        taskCompleter.error(dbClient, error);
    }
    log.info("{} deleteExportMask END...", storage.getSerialNumber());
}
Also used : 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 72 with StringSetMap

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

the class HDSExportOperations method addVolumes.

@Override
public void addVolumes(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<Initiator> initiatorList, TaskCompleter taskCompleter) throws DeviceControllerException {
    log.info("{} addVolumes START...", storage.getSerialNumber());
    HDSApiClient hdsApiClient = null;
    String systemObjectID = null;
    try {
        log.info("addVolumes: Export mask id: {}", exportMaskURI);
        log.info("addVolumes: volume-HLU pairs: {}", Joiner.on(',').join(volumeURIHLUs));
        if (initiatorList != null) {
            log.info("addVolumes: initiators impacted: {}", Joiner.on(',').join(initiatorList));
        }
        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);
        StringSetMap deviceDataMap = exportMask.getDeviceDataMap();
        Set<String> hsdList = deviceDataMap.keySet();
        if (null == hsdList || hsdList.isEmpty()) {
            throw HDSException.exceptions.notAbleToFindHostStorageDomain(systemObjectID);
        }
        if (null != exportMask && !exportMask.getInactive() && !hsdList.isEmpty()) {
            List<Path> pathList = new ArrayList<Path>();
            for (String hsdObjectID : hsdList) {
                // Query the provider to see whether the HSD exists or not.
                HostStorageDomain hsd = exportMgr.getHostStorageDomain(systemObjectID, hsdObjectID);
                if (null != hsd) {
                    Map<String, String> volumeLunMap = getVolumeLunMap(systemObjectID, hsd.getObjectID(), volumeURIHLUs, exportMgr);
                    for (Map.Entry<String, String> entry : volumeLunMap.entrySet()) {
                        if (!checkIfVolumeAlreadyExistsOnHSD(entry.getKey(), hsd)) {
                            Path path = new Path(hsd.getPortID(), hsd.getDomainID(), null, entry.getValue(), entry.getKey());
                            pathList.add(path);
                        }
                    }
                }
            }
            if (!pathList.isEmpty()) {
                List<Path> pathResponseList = hdsApiClient.getHDSBatchApiExportManager().addLUNPathsToHSDs(systemObjectID, pathList, storage.getModel());
                if (null != pathResponseList && !pathResponseList.isEmpty()) {
                    // update volume-lun relationship to exportmask.
                    updateVolumeHLUInfo(volumeURIHLUs, pathResponseList, exportMask);
                    dbClient.updateObject(exportMask);
                } else {
                    log.error(String.format("addVolumes failed - maskURI: %s", exportMaskURI.toString()), new Exception("Not able to parse the response of addLUN from server"));
                    ServiceError serviceError = DeviceControllerException.errors.jobFailedOpMsg(ResourceOperationTypeEnum.ADD_EXPORT_VOLUME.getName(), "Not able to parse the response of addLUN from server");
                    taskCompleter.error(dbClient, serviceError);
                    return;
                }
            } else {
                log.info("All the volumes are already part of the HSDs.");
            }
            taskCompleter.ready(dbClient);
        }
    } catch (Exception e) {
        log.error(String.format("addVolumes failed - maskURI: %s", exportMaskURI.toString()), e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        taskCompleter.error(dbClient, serviceError);
    }
    log.info("{} addVolumes 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) 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) HostStorageDomain(com.emc.storageos.hds.model.HostStorageDomain) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap)

Example 73 with StringSetMap

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

the class ExportMaskUtils method getZoneMapFromAssignments.

/**
 * Returns a StringSetMap containing the Initiator to StoragePort URIs from zoning assignments.
 *
 * @param assignments Map<URI, List<URI>> of zoning assignments.
 * @return StringSetMap with same information encoded as
 */
public static StringSetMap getZoneMapFromAssignments(Map<URI, List<URI>> assignments) {
    StringSetMap zoneMap = new StringSetMap();
    for (URI initiatorURI : assignments.keySet()) {
        StringSet portIds = new StringSet();
        List<URI> portURIs = assignments.get(initiatorURI);
        for (URI portURI : portURIs) {
            portIds.add(portURI.toString());
        }
        zoneMap.put(initiatorURI.toString(), portIds);
    }
    return zoneMap;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StringSet(com.emc.storageos.db.client.model.StringSet) URI(java.net.URI)

Example 74 with StringSetMap

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

the class ExportMaskUtils method getRemovePathsForExportMask.

/**
 * Get the remove path list for the exportMask in the given removedPaths.
 * The given removedPaths could be paths from all the exportMasks belonging to one export group.
 *
 * @param exportMask
 * @param removedPaths - The list paths. some of them may not belong to the export mask.
 * @return - The list of paths are going to be removed from the export mask.
 */
public static Map<URI, List<URI>> getRemovePathsForExportMask(ExportMask exportMask, Map<URI, List<URI>> removedPaths) {
    Map<URI, List<URI>> result = new HashMap<URI, List<URI>>();
    StringSetMap zoningMap = exportMask.getZoningMap();
    StringSet maskInitiators = exportMask.getInitiators();
    if (removedPaths == null || removedPaths.isEmpty()) {
        return result;
    }
    for (Map.Entry<URI, List<URI>> entry : removedPaths.entrySet()) {
        URI initiator = entry.getKey();
        if (!maskInitiators.contains(initiator.toString())) {
            continue;
        }
        List<URI> ports = entry.getValue();
        List<URI> removePorts = new ArrayList<URI>();
        StringSet targets = zoningMap.get(initiator.toString());
        if (targets != null && !targets.isEmpty()) {
            for (URI port : ports) {
                if (targets.contains(port.toString())) {
                    removePorts.add(port);
                }
            }
            if (!removePorts.isEmpty()) {
                result.put(initiator, removePorts);
            }
        }
    }
    return result;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) HashMap(java.util.HashMap) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) URI(java.net.URI) ZoneInfoMap(com.emc.storageos.db.client.model.ZoneInfoMap) Map(java.util.Map) HashMap(java.util.HashMap) StringSetMap(com.emc.storageos.db.client.model.StringSetMap)

Example 75 with StringSetMap

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

the class ExportMaskUtils method buildZoningMapFromInitiatorsAndPorts.

/**
 * Builds a default zoneMap from the initiators and ports.
 *
 * For the targets in the mask, they are paired with the initiators they can service,
 * i.e. that are on the same or a route-able network, and are usable in the varray,
 * and the corresponding zones are put in the zoning map.
 *
 * @param mask -- The ExportMask being manipulated
 * @param varray -- The Virtual Array (normally from the ExportGroup)
 * @param dbClient -- DbClient
 * @return - The zoning map represented as a string set map that is constructed from the
 * cross product of mask initiators and mask storage ports. Initiators are only paired
 * with ports on the same network.
 *
 *       Assumption: the export mask has up to date initiators and storage ports
 */
public static StringSetMap buildZoningMapFromInitiatorsAndPorts(ExportMask mask, URI varray, DbClient dbClient) {
    _log.info(String.format("Creating zoning map for ExportMask %s (%s) from the initiator and port sets", mask.getMaskName(), mask.getId()));
    StringSetMap zoningMap = new StringSetMap();
    // corresponding to the Initiator.
    for (String initiatorURIStr : mask.getInitiators()) {
        Initiator initiator = dbClient.queryObject(Initiator.class, URI.create(initiatorURIStr));
        if (initiator == null || initiator.getInactive()) {
            continue;
        }
        List<URI> storagePortList = ExportUtils.getPortsInInitiatorNetwork(mask, initiator, dbClient);
        if (storagePortList.isEmpty()) {
            continue;
        }
        StringSet storagePorts = new StringSet();
        for (URI portURI : storagePortList) {
            StoragePort port = dbClient.queryObject(StoragePort.class, portURI);
            if (!port.isUsable()) {
                _log.debug("Storage port {} is not selected because it is inactive, is not compatible, is not visible, not on a network, " + "is not registered, or is not a frontend port", port.getLabel());
                continue;
            }
            // Network connectivity was checked in getInitiatorPortsInMask()
            if (port.getTaggedVirtualArrays().contains(varray.toString())) {
                storagePorts.add(portURI.toString());
            } else {
                _log.debug("Storage port {} is not selected because it is not in the specified varray {}", port.getLabel(), varray.toString());
            }
        }
        if (!storagePorts.isEmpty()) {
            zoningMap.put(initiatorURIStr, storagePorts);
        }
    }
    _log.info("Constructed zoningMap -" + zoningMap.toString());
    return zoningMap;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI)

Aggregations

StringSetMap (com.emc.storageos.db.client.model.StringSetMap)158 StringSet (com.emc.storageos.db.client.model.StringSet)95 URI (java.net.URI)72 ArrayList (java.util.ArrayList)68 List (java.util.List)49 HashMap (java.util.HashMap)43 StoragePort (com.emc.storageos.db.client.model.StoragePort)37 Map (java.util.Map)32 Initiator (com.emc.storageos.db.client.model.Initiator)31 NamedURI (com.emc.storageos.db.client.model.NamedURI)31 StringMap (com.emc.storageos.db.client.model.StringMap)31 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)26 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)26 ExportMask (com.emc.storageos.db.client.model.ExportMask)25 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)25 HashSet (java.util.HashSet)22 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)21 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)18 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)17 Test (org.junit.Test)16