Search in sources :

Example 26 with XtremIOClient

use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.

the class XtremIOSnapshotOperations method restoreGroupSnapshots.

@Override
public void restoreGroupSnapshots(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        BlockSnapshot snapshotObj = dbClient.queryObject(BlockSnapshot.class, snapshot);
        BlockConsistencyGroup group = dbClient.queryObject(BlockConsistencyGroup.class, snapshotObj.getConsistencyGroup());
        // Check if the CG exists on the array
        String clusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        String cgName = ConsistencyGroupUtils.getSourceConsistencyGroupName(snapshotObj, dbClient);
        XtremIOConsistencyGroup cg = XtremIOProvUtils.isCGAvailableInArray(client, cgName, clusterName);
        if (cg == null) {
            _log.error("The consistency group does not exist in the array: {}", storage.getSerialNumber());
            taskCompleter.error(dbClient, DeviceControllerException.exceptions.consistencyGroupNotFound(cgName, group.getCgNameOnStorageSystem(storage.getId())));
            return;
        }
        client.restoreCGFromSnapshot(clusterName, cgName, snapshotObj.getReplicationGroupInstance());
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        _log.error("Snapshot restore failed", e);
        ServiceError serviceError = null;
        if (e instanceof XtremIOApiException) {
            XtremIOApiException xioException = (XtremIOApiException) e;
            // check for specific error key for snapshot size mismatch with source volume.
            if (null != xioException.getMessage() && xioException.getMessage().contains(XtremIOConstants.SNAP_SIZE_MISMATCH_ERROR_KEY)) {
                String restoreFailureMsg = "One or more CG snapshots size mismatch with its source volume size. " + "Use expand snapshot feature to increase the snapshot size.";
                serviceError = DeviceControllerErrors.xtremio.restoreSnapshotFailureSourceSizeMismatch(restoreFailureMsg);
            }
        } else {
            serviceError = DeviceControllerException.errors.jobFailed(e);
        }
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) XtremIOConsistencyGroup(com.emc.storageos.xtremio.restapi.model.response.XtremIOConsistencyGroup) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup)

Example 27 with XtremIOClient

use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.

the class XtremIOSnapshotOperations method createGroupSnapshots.

@Override
public void createGroupSnapshots(StorageSystem storage, List<URI> snapshotList, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        List<BlockSnapshot> snapObjs = dbClient.queryObject(BlockSnapshot.class, snapshotList);
        BlockSnapshot snapshotObj = snapObjs.get(0);
        BlockConsistencyGroup blockCG = dbClient.queryObject(BlockConsistencyGroup.class, snapshotObj.getConsistencyGroup());
        // Check if the CG for which we are creating snapshot exists on the array
        String clusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        String snapsetLabel = snapshotObj.getSnapsetLabel();
        String cgName = ConsistencyGroupUtils.getSourceConsistencyGroupName(snapshotObj, dbClient);
        XtremIOConsistencyGroup cg = XtremIOProvUtils.isCGAvailableInArray(client, cgName, clusterName);
        if (cg == null) {
            _log.error("The consistency group does not exist in the array: {}", storage.getSerialNumber());
            taskCompleter.error(dbClient, DeviceControllerException.exceptions.consistencyGroupNotFound(cgName, blockCG.getCgNameOnStorageSystem(storage.getId())));
            return;
        }
        String snapType = readOnly ? XtremIOConstants.XTREMIO_READ_ONLY_TYPE : XtremIOConstants.XTREMIO_REGULAR_TYPE;
        String snapshotSetTagName = XtremIOProvUtils.createTagsForVolumeAndSnaps(client, getVolumeFolderName(snapshotObj.getProject().getURI(), storage), clusterName).get(XtremIOConstants.SNAPSHOT_KEY);
        snapsetLabel = snapsetLabel + "_" + new SimpleDateFormat("yyyyMMddhhmmssSSS").format(new Date());
        client.createConsistencyGroupSnapshot(cgName, snapsetLabel, "", snapType, clusterName);
        // tag the created the snapshotSet
        client.tagObject(snapshotSetTagName, XTREMIO_ENTITY_TYPE.SnapshotSet.name(), snapsetLabel, clusterName);
        _log.info("Snapset label :{}", snapsetLabel);
        // Create mapping of volume.deviceLabel to BlockSnapshot object
        Map<String, BlockSnapshot> volumeToSnapMap = new HashMap<String, BlockSnapshot>();
        for (BlockSnapshot snapshot : snapObjs) {
            Volume volume = dbClient.queryObject(Volume.class, snapshot.getParent());
            volumeToSnapMap.put(volume.getDeviceLabel(), snapshot);
        }
        // Get the snapset details
        XtremIOConsistencyGroup snapset = client.getSnapshotSetDetails(snapsetLabel, clusterName);
        for (List<Object> snapDetails : snapset.getVolList()) {
            XtremIOVolume xioSnap = client.getSnapShotDetails(snapDetails.get(1).toString(), clusterName);
            _log.info("XIO Snap : {}", xioSnap);
            BlockSnapshot snapshot = volumeToSnapMap.get(xioSnap.getAncestoVolInfo().get(1));
            if (snapshot != null) {
                processSnapshot(xioSnap, snapshot, storage);
                snapshot.setReplicationGroupInstance(snapsetLabel);
                dbClient.updateObject(snapshot);
            }
        }
        taskCompleter.ready(dbClient);
    } catch (Exception e) {
        _log.error("Snapshot creation failed", e);
        ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
        taskCompleter.error(dbClient, serviceError);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) XtremIOConsistencyGroup(com.emc.storageos.xtremio.restapi.model.response.XtremIOConsistencyGroup) HashMap(java.util.HashMap) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Date(java.util.Date) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) XtremIOVolume(com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume) Volume(com.emc.storageos.db.client.model.Volume) XtremIOVolume(com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) BlockObject(com.emc.storageos.db.client.model.BlockObject) SimpleDateFormat(java.text.SimpleDateFormat)

Example 28 with XtremIOClient

use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.

the class XtremIOArrayAffinityDiscoverer method findAndUpdatePreferredPools.

/**
 * Find and update preferred pools information for all Hosts.
 *
 * @param system the system
 * @param dbClient the db client
 * @param partitionManager
 * @throws Exception the exception
 */
public void findAndUpdatePreferredPools(StorageSystem system, DbClient dbClient, PartitionManager partitionManager) throws Exception {
    /**
     * Get all initiators on array,
     * Group initiators by IG, also maintain a map of Host to IGs, and a map of IG to Hosts.
     * For each Host in the DB:
     * - Find if any of its IG has volumes,
     * - Find the mask type for the host.
     */
    XtremIOClient xtremIOClient = XtremIOProvUtils.getXtremIOClient(dbClient, system, xtremioRestClientFactory);
    String xioClusterName = xtremIOClient.getClusterDetails(system.getSerialNumber()).getName();
    // Group all the initiators and their initiator groups based on ViPR host.
    ArrayListMultimap<String, Initiator> igNameToInitiatorsMap = ArrayListMultimap.create();
    Map<URI, Set<String>> hostToIGNamesMap = new HashMap<URI, Set<String>>();
    Map<String, Set<String>> igNameToHostsMap = new HashMap<String, Set<String>>();
    List<XtremIOInitiator> initiators = xtremIOClient.getXtremIOInitiatorsInfo(xioClusterName);
    for (XtremIOInitiator initiator : initiators) {
        String initiatorNetworkId = initiator.getPortAddress();
        // check if a host initiator exists for this id
        Initiator knownInitiator = NetworkUtil.getInitiator(initiatorNetworkId, dbClient);
        if (knownInitiator == null) {
            log.debug("Skipping XtremIO initiator {} as it is not found in database", initiatorNetworkId);
            continue;
        }
        URI hostId = knownInitiator.getHost();
        String hostName = knownInitiator.getHostName();
        if (!NullColumnValueGetter.isNullURI(hostId)) {
            log.info("Found a host {}({}) in ViPR for initiator {}", hostId.toString(), knownInitiator.getHostName(), initiatorNetworkId);
            String igName = initiator.getInitiatorGroup().get(1);
            igNameToInitiatorsMap.put(igName, knownInitiator);
            Set<String> hostIGNames = hostToIGNamesMap.get(hostId);
            if (hostIGNames == null) {
                hostIGNames = new HashSet<String>();
                hostToIGNamesMap.put(hostId, hostIGNames);
            }
            hostIGNames.add(igName);
            Set<String> igHostNames = igNameToHostsMap.get(igName);
            if (igHostNames == null) {
                igHostNames = new HashSet<String>();
                igNameToHostsMap.put(igName, igHostNames);
            }
            igHostNames.add(hostName);
        } else {
            log.info("No host in ViPR found configured for initiator {}", initiatorNetworkId);
        }
    }
    log.info("IG name to Initiators Map: {}", Joiner.on(",").join(igNameToInitiatorsMap.asMap().entrySet()));
    log.info("IG name to Hosts Map: {}", Joiner.on(",").join(igNameToHostsMap.entrySet()));
    log.info("Host to IG names Map: {}", Joiner.on(",").join(hostToIGNamesMap.entrySet()));
    // map of IG name to Volume names mapped
    Map<String, Set<String>> igToVolumesMap = getIgToVolumesMap(xtremIOClient, xioClusterName);
    // As XtremIO array has only one storage pool, add the pool directly.
    // get the storage pool associated with the XtremIO system
    StoragePool storagePool = XtremIOProvUtils.getXtremIOStoragePool(system.getId(), dbClient);
    List<Host> hostsToUpdate = new ArrayList<Host>();
    List<URI> hostURIs = dbClient.queryByType(Host.class, true);
    Iterator<Host> hosts = dbClient.queryIterativeObjectFields(Host.class, ArrayAffinityDiscoveryUtils.HOST_PROPERTIES, hostURIs);
    while (hosts.hasNext()) {
        Host host = hosts.next();
        if (host != null && !host.getInactive()) {
            log.info("Processing Host {}", host.getLabel());
            Map<String, String> preferredPoolMap = new HashMap<String, String>();
            Set<String> volumeNames = getVolumesForHost(hostToIGNamesMap.get(host.getId()), igToVolumesMap);
            // consider only unmanaged volumes
            filterKnownVolumes(system, dbClient, xtremIOClient, xioClusterName, volumeNames);
            if (!volumeNames.isEmpty()) {
                log.info("UnManaged Volumes found for this Host: {}", volumeNames);
                if (storagePool != null) {
                    String maskType = getMaskTypeForHost(xtremIOClient, xioClusterName, igNameToInitiatorsMap, igNameToHostsMap, hostToIGNamesMap.get(host.getId()), volumeNames);
                    ArrayAffinityDiscoveryUtils.addPoolToPreferredPoolMap(preferredPoolMap, storagePool.getId().toString(), maskType);
                }
            } else {
                log.info("No UnManaged Volumes found for this Host");
            }
            if (ArrayAffinityDiscoveryUtils.updatePreferredPools(host, Sets.newHashSet(system.getId().toString()), dbClient, preferredPoolMap)) {
                hostsToUpdate.add(host);
            }
        }
    }
    if (!hostsToUpdate.isEmpty()) {
        partitionManager.updateAndReIndexInBatches(hostsToUpdate, Constants.DEFAULT_PARTITION_SIZE, dbClient, HOST);
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) StoragePool(com.emc.storageos.db.client.model.StoragePool) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) XtremIOInitiator(com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) XtremIOInitiator(com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient)

Example 29 with XtremIOClient

use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.

the class XtremIOExportOperations method addInitiators.

@Override
public void addInitiators(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIs, List<Initiator> initiators, List<URI> targets, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("{} addInitiators START...", storage.getSerialNumber());
    try {
        _log.info("addInitiators: Export mask id: {}", exportMaskURI);
        if (volumeURIs != null) {
            _log.info("addInitiators: volumes : {}", Joiner.on(',').join(volumeURIs));
        }
        _log.info("addInitiators: initiators : {}", Joiner.on(',').join(initiators));
        _log.info("addInitiators: targets : {}", Joiner.on(",").join(targets));
        ExportOperationContext context = new XtremIOExportOperationContext();
        // Prime the context object
        taskCompleter.updateWorkflowStepContext(context);
        ExportMask exportMask = dbClient.queryObject(ExportMask.class, exportMaskURI);
        if (exportMask == null || exportMask.getInactive()) {
            throw new DeviceControllerException("Invalid ExportMask URI: " + exportMaskURI);
        }
        XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
        String xioClusterName = client.getClusterDetails(storage.getSerialNumber()).getName();
        List<Initiator> initiatorsToBeCreated = new ArrayList<Initiator>();
        ArrayListMultimap<String, Initiator> initiatorToIGMap = XtremIOProvUtils.mapInitiatorToInitiatorGroup(storage.getSerialNumber(), initiators, initiatorsToBeCreated, xioClusterName, client);
        XtremIOExportMaskVolumesValidator volumeValidator = (XtremIOExportMaskVolumesValidator) validator.addInitiators(storage, exportMask, volumeURIs);
        volumeValidator.setIgNames(initiatorToIGMap.keySet());
        volumeValidator.validate();
        Map<URI, Integer> map = new HashMap<URI, Integer>();
        for (URI volumeURI : volumeURIs) {
            String hlu = exportMask.getVolumes().get(volumeURI.toString());
            if (NullColumnValueGetter.isNotNullValue(hlu)) {
                map.put(volumeURI, Integer.parseInt(hlu));
            }
        }
        // to make it uniform , using these structures
        VolumeURIHLU[] volumeLunArray = ControllerUtils.getVolumeURIHLUArray(storage.getSystemType(), map, dbClient);
        runLunMapCreationAlgorithm(storage, exportMask, volumeLunArray, initiators, targets, client, xioClusterName, initiatorToIGMap, initiatorsToBeCreated, taskCompleter);
    } catch (final Exception ex) {
        _log.error("Problem in addInitiators: ", ex);
        ServiceError serviceError = DeviceControllerErrors.xtremio.operationFailed("addInitiators", ex.getMessage());
        taskCompleter.error(dbClient, serviceError);
    }
    _log.info("{} addInitiators END...", storage.getSerialNumber());
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) XtremIOExportMaskVolumesValidator(com.emc.storageos.volumecontroller.impl.validators.xtremio.XtremIOExportMaskVolumesValidator) HashMap(java.util.HashMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) URI(java.net.URI) XtremIOApiException(com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) XtremIOInitiator(com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator) Initiator(com.emc.storageos.db.client.model.Initiator) ExportOperationContext(com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 30 with XtremIOClient

use of com.emc.storageos.xtremio.restapi.XtremIOClient in project coprhd-controller by CoprHD.

the class XtremIOStorageDevice method doResyncSnapshot.

@Override
public void doResyncSnapshot(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    _log.info("SnapShot resync..... Started");
    List<BlockSnapshot> snapshots = dbClient.queryObject(BlockSnapshot.class, Arrays.asList(snapshot));
    XtremIOClient client = XtremIOProvUtils.getXtremIOClient(dbClient, storage, xtremioRestClientFactory);
    if (client.isVersion2() && ControllerUtils.checkSnapshotsInConsistencyGroup(snapshots, dbClient, taskCompleter)) {
        snapshotOperations.resyncGroupSnapshots(storage, volume, snapshot, taskCompleter);
    } else {
        snapshotOperations.resyncSingleVolumeSnapshot(storage, volume, snapshot, taskCompleter);
    }
    _log.info("SnapShot resync..... End");
}
Also used : BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) XtremIOClient(com.emc.storageos.xtremio.restapi.XtremIOClient)

Aggregations

XtremIOClient (com.emc.storageos.xtremio.restapi.XtremIOClient)38 XtremIOApiException (com.emc.storageos.xtremio.restapi.errorhandling.XtremIOApiException)27 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)26 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)20 XtremIOVolume (com.emc.storageos.xtremio.restapi.model.response.XtremIOVolume)15 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)13 URI (java.net.URI)13 ArrayList (java.util.ArrayList)12 Initiator (com.emc.storageos.db.client.model.Initiator)11 XtremIOInitiator (com.emc.storageos.xtremio.restapi.model.response.XtremIOInitiator)11 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)9 BlockObject (com.emc.storageos.db.client.model.BlockObject)9 HashMap (java.util.HashMap)9 HashSet (java.util.HashSet)8 Volume (com.emc.storageos.db.client.model.Volume)7 XtremIOConsistencyGroup (com.emc.storageos.xtremio.restapi.model.response.XtremIOConsistencyGroup)6 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)5 ExportMask (com.emc.storageos.db.client.model.ExportMask)5 ExportOperationContext (com.emc.storageos.volumecontroller.impl.utils.ExportOperationContext)5 List (java.util.List)5