Search in sources :

Example 6 with XIVRestException

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

the class XIVRestOperationsHelper method createRESTExportMask.

/**
 * Creates Export mask for a Cluster. Creates Cluster, Host and Inititators on XIV. Exports the volume to the
 * Cluster.
 *
 * @param storage
 *            XIV Storage System
 * @param exportMaskURI
 *            Export Mask URI
 * @param volumeURIHLUs
 *            Volume URIs to be exported
 * @param targetURIList
 *            Target ports (not used for XIV)
 * @param initiatorList
 *            Initiator ports
 * @param taskCompleter
 *            Task Completer instance
 */
public void createRESTExportMask(StorageSystem storage, URI exportMaskURI, VolumeURIHLU[] volumeURIHLUs, List<URI> targetURIList, List<Initiator> initiatorList, TaskCompleter taskCompleter) {
    try {
        ExportMask exportMask = _dbClient.queryObject(ExportMask.class, exportMaskURI);
        XIVRestClient restExportOpr = getRestClient(storage);
        final String storageIP = storage.getSmisProviderIP();
        String exportName = null;
        String clusterName = null;
        URI clusterURI = null;
        Set<String> hosts = new HashSet<String>();
        for (Initiator initiator : initiatorList) {
            final Host host = _dbClient.queryObject(Host.class, initiator.getHost());
            exportName = host.getLabel();
            hosts.add(exportName);
            clusterURI = host.getCluster();
        }
        final String exportType = ExportMaskUtils.getExportType(_dbClient, exportMask);
        if (ExportGroup.ExportGroupType.Cluster.name().equals(exportType) && null != clusterURI) {
            Cluster cluster = _dbClient.queryObject(Cluster.class, clusterURI);
            clusterName = cluster.getLabel();
            exportName = clusterName;
            // Create Cluster if not exist
            restExportOpr.createCluster(storageIP, clusterName);
        }
        // Create Host if not exist
        for (String hostName : hosts) {
            restExportOpr.createHost(storageIP, clusterName, hostName);
        }
        List<Initiator> userAddedInitiator = new ArrayList<Initiator>();
        List<BlockObject> userAddedVolumes = new ArrayList<BlockObject>();
        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())) {
                userAddedInitiator.add(initiator);
            }
        }
        // Export volume to Cluster
        if (volumeURIHLUs != null && volumeURIHLUs.length > 0) {
            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 {
                        if (!restExportOpr.exportVolume(storageIP, exportType, exportName, blockObject.getLabel(), String.valueOf(hluDec), isSnapshot(volumeURIHLU.getVolumeURI()))) {
                            userAddedVolumes.add(blockObject);
                        }
                    }
                }
            }
        }
        // Update Masking information
        exportMask.setCreatedBySystem(true);
        exportMask.addToUserCreatedInitiators(userAddedInitiator);
        exportMask.addToUserCreatedVolumes(userAddedVolumes);
        exportMask.setMaskName(exportName);
        exportMask.setNativeId(exportName);
        exportMask.setLabel(exportName);
        _dbClient.updateObject(exportMask);
        taskCompleter.ready(_dbClient);
    } catch (Exception e) {
        _log.error("Unexpected error: createRESTExportMask failed.", e);
        XIVRestException error = XIVRestException.exceptions.methodFailed("createExportMask", e);
        taskCompleter.error(_dbClient, error);
    }
}
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) HashSet(java.util.HashSet) VolumeURIHLU(com.emc.storageos.volumecontroller.impl.VolumeURIHLU)

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