Search in sources :

Example 1 with XIVRestException

use of com.emc.storageos.xiv.api.XIVRestException in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method removeInitiatorsUsingREST.

/**
 * Removes initiators from an existing export mask
 *
 * @param storage
 *            StorageSystem instance
 * @param exportMaskURI
 *            ExportMask URI where Initiator needs to be removed
 * @param volumeURIList
 *            Volume to be validated against this operation
 * @param initiatorList
 *            List of Initiators to be removed
 * @param taskCompleter
 *            Task Completer instance
 */
public void removeInitiatorsUsingREST(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIs, List<Initiator> initiatorList, TaskCompleter taskCompleter) {
    try {
        ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        XIVRestClient restExportOpr = getRestClient(storage);
        final String storageIP = storage.getSmisProviderIP();
        List<URI> userRemovedInitiators = new ArrayList<URI>();
        Set<URI> hostURIs = new HashSet<URI>();
        if (null != initiatorList) {
            for (Initiator initiator : initiatorList) {
                final Host host = _dbClient.queryObject(Host.class, initiator.getHost());
                final String normalizedPort = Initiator.normalizePort(initiator.getInitiatorPort());
                if (restExportOpr.deleteHostPort(storageIP, host.getLabel(), normalizedPort, initiator.getProtocol().toLowerCase(), true)) {
                    userRemovedInitiators.add(initiator.getId());
                    hostURIs.add(initiator.getHost());
                }
            }
        }
        mask.removeFromUserAddedInitiatorsByURI(userRemovedInitiators);
        // Delete Host if there are no associated Initiators to it.
        for (URI hostURI : hostURIs) {
            Host host = _dbClient.queryObject(Host.class, hostURI);
            boolean hostDeleted = restExportOpr.deleteHost(storageIP, host.getLabel(), true);
            // Perform post-mask-delete cleanup steps
            if (hostDeleted) {
                unsetTag(host, storage.getSerialNumber());
            }
        }
        ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
        _dbClient.updateObject(mask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: addInitiator failed.", e);
        XIVRestException error = XIVRestException.exceptions.methodFailed("addInitiator", e);
        taskCompleter.error(_dbClient, error);
    }
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) Initiator(com.emc.storageos.db.client.model.Initiator) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) HashSet(java.util.HashSet)

Example 2 with XIVRestException

use of com.emc.storageos.xiv.api.XIVRestException in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method addInitiatorsUsingREST.

/**
 * Add Initiators to an existing Export Mask.
 *
 * @param storage
 *            StorageSystem instance
 * @param exportMaskURI
 *            Export mask URI where the initiator needs to be added
 * @param volumeURIList
 *            Volume to be validated against this operation
 * @param initiatorList
 *            List of initiators need to be added
 * @param taskCompleter
 *            Task Completer instance
 */
public void addInitiatorsUsingREST(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIs, List<Initiator> initiatorList, TaskCompleter taskCompleter) {
    try {
        ExportMask mask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        XIVRestClient restExportOpr = getRestClient(storage);
        final String storageIP = storage.getSmisProviderIP();
        List<Initiator> userAddedInitiators = new ArrayList<Initiator>();
        for (Initiator initiator : initiatorList) {
            final Host host = _dbClient.queryObject(Host.class, initiator.getHost());
            // Add Initiators to Host.
            if (!restExportOpr.createHostPort(storageIP, host.getLabel(), Initiator.normalizePort(initiator.getInitiatorPort()), initiator.getProtocol().toLowerCase())) {
                userAddedInitiators.add(initiator);
            }
        }
        mask.addToUserCreatedInitiators(userAddedInitiators);
        ExportMaskUtils.sanitizeExportMaskContainers(_dbClient, mask);
        _dbClient.updateObject(mask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: addInitiator failed.", e);
        XIVRestException error = XIVRestException.exceptions.methodFailed("addInitiator", e);
        taskCompleter.error(_dbClient, error);
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) Host(com.emc.storageos.db.client.model.Host) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) XIVRestException(com.emc.storageos.xiv.api.XIVRestException)

Example 3 with XIVRestException

use of com.emc.storageos.xiv.api.XIVRestException in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method deleteRESTExportMask.

/**
 * Deletes the Export Mask and its attributes
 *
 * @param storage
 *            XIV storage system
 * @param exportMaskURI
 *            Export mask URI
 * @param volumeURIList
 *            Volume URI as list
 * @param targetURIList
 *            target port URI as list [ not used for xiv]
 * @param initiatorList
 *            Initiator port URI as list
 * @param taskCompleter
 *            task completer instance
 */
public void deleteRESTExportMask(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) {
    try {
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        final String storageIP = storage.getSmisProviderIP();
        final String exportType = ExportMaskUtils.getExportType(_dbClient, exportMask);
        final String name = exportMask.getNativeId();
        final StringSet emInitiatorURIs = exportMask.getInitiators();
        final StringMap emVolumeURIs = exportMask.getVolumes();
        XIVRestClient restExportOpr = getRestClient(storage);
        Set<URI> hostURIs = new HashSet<URI>();
        // Un export Volumes
        if (null != emVolumeURIs) {
            Iterator<Entry<String, String>> emVolumeURIItr = emVolumeURIs.entrySet().iterator();
            while (emVolumeURIItr.hasNext()) {
                URI volUri = URI.create(emVolumeURIItr.next().getKey());
                if (URIUtil.isType(volUri, Volume.class)) {
                    Volume volume = _dbClient.queryObject(Volume.class, volUri);
                    restExportOpr.unExportVolume(storageIP, exportType, name, volume.getLabel());
                }
            }
        }
        // Delete initiators
        if (null != emInitiatorURIs) {
            for (String initiatorURI : emInitiatorURIs) {
                Initiator initiator = _dbClient.queryObject(Initiator.class, URI.create(initiatorURI));
                Host host = _dbClient.queryObject(Host.class, initiator.getHost());
                hostURIs.add(host.getId());
                String normalizedPort = Initiator.normalizePort(initiator.getInitiatorPort());
                restExportOpr.deleteHostPort(storageIP, host.getLabel(), normalizedPort, initiator.getProtocol().toLowerCase(), false);
            }
        }
        // Delete Host if there are no associated Initiators/Volume to it.
        for (URI hostURI : hostURIs) {
            Host host = _dbClient.queryObject(Host.class, hostURI);
            boolean hostDeleted = restExportOpr.deleteHost(storageIP, host.getLabel(), false);
            // Perform post-mask-delete cleanup steps
            if (hostDeleted && emVolumeURIs.size() > 0) {
                unsetTag(host, storage.getSerialNumber());
            }
        }
        // Delete Cluster if there is no associated hosts to it.
        if (ExportGroup.ExportGroupType.Cluster.name().equals(exportType)) {
            restExportOpr.deleteCluster(storageIP, name);
        }
        ExportUtils.cleanupAssociatedMaskResources(_dbClient, exportMask);
        exportMask.setMaskName(NullColumnValueGetter.getNullURI().toString());
        exportMask.setLabel(NullColumnValueGetter.getNullURI().toString());
        exportMask.setNativeId(NullColumnValueGetter.getNullURI().toString());
        exportMask.setResource(NullColumnValueGetter.getNullURI().toString());
        _dbClient.updateObject(exportMask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: deleteExportMask failed.", e);
        XIVRestException error = XIVRestException.exceptions.methodFailed("createExportMask", e);
        taskCompleter.error(_dbClient, error);
    }
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) ExportMask(com.emc.storageos.db.client.model.ExportMask) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) Entry(java.util.Map.Entry) Volume(com.emc.storageos.db.client.model.Volume) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) HashSet(java.util.HashSet)

Example 4 with XIVRestException

use of com.emc.storageos.xiv.api.XIVRestException in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method addVolumesUsingREST.

/**
 * Adds volumes to an export mask
 *
 * @param storage
 *            Storage system instance
 * @param exportMaskURI
 *            Export mask URI
 * @param volumeURIHLUs
 *            Volume to be added URI
 * @param initiatorList
 *            initiators to be valiated against for this operation
 * @param taskCompleter
 *            task completer instance
 */
public void addVolumesUsingREST(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<Initiator> initiatorList, TaskCompleter taskCompleter) {
    _log.info("{} addVolume START...", storage.getLabel());
    try {
        // Export volume to Cluster
        if (volumeURIHLUs != null && volumeURIHLUs.length > 0) {
            ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
            final String storageIP = storage.getSmisProviderIP();
            XIVRestClient restExportOpr = getRestClient(storage);
            // Find HOST from Export Mask
            URI hostName = null;
            Set<Initiator> exportMaskInits = ExportMaskUtils.getInitiatorsForExportMask(_dbClient, exportMask, null);
            Iterator<Initiator> exportMaskInitsItr = exportMaskInits.iterator();
            if (exportMaskInitsItr.hasNext()) {
                hostName = exportMaskInitsItr.next().getHost();
            }
            final Host host = _dbClient.queryObject(Host.class, hostName);
            // Validate if it is a cluster
            String exportName = host.getLabel();
            String clusterName = null;
            final String exportType = ExportMaskUtils.getExportType(_dbClient, exportMask);
            if (ExportGroup.ExportGroupType.Cluster.name().equals(exportType)) {
                Cluster cluster = _dbClient.queryObject(Cluster.class, host.getCluster());
                clusterName = cluster.getLabel();
                exportName = clusterName;
            }
            // Export volume
            List<BlockObject> userAddedVolumes = new ArrayList<BlockObject>();
            for (VolumeURIHLU volumeURIHLU : volumeURIHLUs) {
                final BlockObject blockObject = getBlockObject(volumeURIHLU.getVolumeURI());
                final String volumeHLU = volumeURIHLU.getHLU();
                if (volumeHLU != null && !volumeHLU.equalsIgnoreCase(ExportGroup.LUN_UNASSIGNED_STR)) {
                    int hluDec = Integer.parseInt(volumeHLU, 16);
                    if (hluDec > MAXIMUM_LUN) {
                        String errMsg = String.format(INVALID_LUN_ERROR_MSG, hluDec, MAXIMUM_LUN);
                        _log.error(errMsg);
                        throw new Exception(errMsg);
                    } else {
                        restExportOpr.exportVolume(storageIP, exportType, exportName, blockObject.getLabel(), String.valueOf(hluDec), isSnapshot(volumeURIHLU.getVolumeURI()));
                        userAddedVolumes.add(blockObject);
                    }
                }
            }
            exportMask.addToUserCreatedVolumes(userAddedVolumes);
            _dbClient.updateObject(exportMask);
            taskCompleter.ready(_dbClient);
        }
    } catch (Exception e) {
        _log.error("Unexpected error: addVolume failed.", e);
        XIVRestException error = XIVRestException.exceptions.methodFailed("addVolume", e);
        taskCompleter.error(_dbClient, error);
    }
    _log.info("{} addVolume END...", storage.getLabel());
}
Also used : ExportMask(com.emc.storageos.db.client.model.ExportMask) ArrayList(java.util.ArrayList) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) Initiator(com.emc.storageos.db.client.model.Initiator) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) BlockObject(com.emc.storageos.db.client.model.BlockObject) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

Example 5 with XIVRestException

use of com.emc.storageos.xiv.api.XIVRestException in project coprhd-controller by CoprHD.

the class XIVRestOperationsHelper method removeVolumesUsingREST.

/**
 * Removes volumes from an Export mask
 *
 * @param storage
 *            Storage system instance
 * @param exportMaskURI
 *            Export mask URI
 * @param volumeURIList
 *            Volume to be removed URI
 * @param initiatorList
 *            initiators to be valiated against for this operation
 * @param taskCompleter
 *            task completer instance
 */
public void removeVolumesUsingREST(StorageSystem storage, URI exportMaskURI, List<URI> volumeURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) {
    try {
        // Export volume to Cluster
        if (volumeURIList != null && volumeURIList.size() > 0) {
            ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
            final String storageIP = storage.getSmisProviderIP();
            XIVRestClient restExportOpr = getRestClient(storage);
            // Find HOST from Export Mask
            URI hostName = null;
            Set<Initiator> exportMaskInits = ExportMaskUtils.getInitiatorsForExportMask(_dbClient, exportMask, null);
            Iterator<Initiator> exportMaskInitsItr = exportMaskInits.iterator();
            if (exportMaskInitsItr.hasNext()) {
                hostName = exportMaskInitsItr.next().getHost();
            }
            final Host host = _dbClient.queryObject(Host.class, hostName);
            // Validate if it is a cluster
            String exportName = host.getLabel();
            final String exportType = ExportMaskUtils.getExportType(_dbClient, exportMask);
            if (ExportGroup.ExportGroupType.Cluster.name().equals(exportType)) {
                Cluster cluster = _dbClient.queryObject(Cluster.class, host.getCluster());
                exportName = cluster.getLabel();
            }
            // Export volume
            for (URI volumeURI : volumeURIList) {
                final Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
                if (volume != null) {
                    restExportOpr.unExportVolume(storageIP, exportType, exportName, volume.getLabel());
                }
            }
        }
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: removeVolume failed.", e);
        XIVRestException error = XIVRestException.exceptions.methodFailed("removeVolume", e);
        taskCompleter.error(_dbClient, error);
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) Volume(com.emc.storageos.db.client.model.Volume) ExportMask(com.emc.storageos.db.client.model.ExportMask) Cluster(com.emc.storageos.db.client.model.Cluster) XIVRestClient(com.emc.storageos.xiv.api.XIVRestClient) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI) XIVRestException(com.emc.storageos.xiv.api.XIVRestException) XIVRestException(com.emc.storageos.xiv.api.XIVRestException)

Aggregations

ExportMask (com.emc.storageos.db.client.model.ExportMask)6 Host (com.emc.storageos.db.client.model.Host)6 Initiator (com.emc.storageos.db.client.model.Initiator)6 XIVRestClient (com.emc.storageos.xiv.api.XIVRestClient)6 XIVRestException (com.emc.storageos.xiv.api.XIVRestException)6 URI (java.net.URI)5 ArrayList (java.util.ArrayList)4 Cluster (com.emc.storageos.db.client.model.Cluster)3 HashSet (java.util.HashSet)3 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2 BlockObject (com.emc.storageos.db.client.model.BlockObject)2 Volume (com.emc.storageos.db.client.model.Volume)2 VolumeURIHLU (com.emc.storageos.volumecontroller.impl.VolumeURIHLU)2 StringMap (com.emc.storageos.db.client.model.StringMap)1 StringSet (com.emc.storageos.db.client.model.StringSet)1 Entry (java.util.Map.Entry)1