Search in sources :

Example 31 with Cluster

use of com.emc.storageos.db.client.model.Cluster 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 32 with Cluster

use of com.emc.storageos.db.client.model.Cluster 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)

Example 33 with Cluster

use of com.emc.storageos.db.client.model.Cluster 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)

Example 34 with Cluster

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

the class ClusterFinder method findClusterByNameAndDatacenter.

/**
 * Find the Cluster in a vCenterDataCenter by name.
 *
 * @param datacenterId vCenterDataCenterId.
 * @param name name of the Cluster.
 * @param activeOnly indicates whether active only or not.
 * @return the Cluster if the name matches, otherwise null.
 */
public Cluster findClusterByNameAndDatacenter(URI datacenterId, String name, boolean activeOnly) {
    List<NamedElement> clusters = findIdsByDatacenter(datacenterId);
    Iterator<NamedElement> clusterIt = clusters.iterator();
    while (clusterIt.hasNext()) {
        Cluster cluster = findById(clusterIt.next().getId());
        if (cluster != null && cluster.getLabel().equalsIgnoreCase(name)) {
            return cluster;
        }
    }
    return null;
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster) NamedElement(com.emc.storageos.db.client.constraint.NamedElementQueryResultList.NamedElement)

Example 35 with Cluster

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

the class VcenterControllerImpl method getVirtualMachines.

private List<String> getVirtualMachines(URI datacenterUri, URI clusterUri, boolean runningOnly) throws InternalException {
    VcenterApiClient vcenterApiClient = null;
    try {
        VcenterDataCenter vcenterDataCenter = _dbClient.queryObject(VcenterDataCenter.class, datacenterUri);
        Cluster cluster = _dbClient.queryObject(Cluster.class, clusterUri);
        Vcenter vcenter = _dbClient.queryObject(Vcenter.class, vcenterDataCenter.getVcenter());
        _log.info("Request to get virtual machines for " + vcenter.getLabel() + "/" + vcenterDataCenter.getLabel() + "/" + cluster.getLabel());
        vcenterApiClient = new VcenterApiClient(_coordinator.getPropertyInfo());
        vcenterApiClient.setup(vcenter.getIpAddress(), vcenter.getUsername(), vcenter.getPassword(), vcenter.getPortNumber());
        return runningOnly ? vcenterApiClient.getRunningVirtualMachines(vcenterDataCenter.getLabel(), cluster.getExternalId()) : vcenterApiClient.getVirtualMachines(vcenterDataCenter.getLabel(), cluster.getExternalId());
    } catch (VcenterObjectNotFoundException e) {
        throw VcenterControllerException.exceptions.objectNotFoundException(e.getLocalizedMessage(), e);
    } catch (VcenterServerConnectionException e) {
        throw VcenterControllerException.exceptions.serverConnectionException(e.getLocalizedMessage(), e);
    } catch (Exception e) {
        _log.error("getVirtualMachines exception " + e);
        throw VcenterControllerException.exceptions.unexpectedException(e.getLocalizedMessage(), e);
    } finally {
        if (vcenterApiClient != null) {
            vcenterApiClient.destroy();
        }
    }
}
Also used : Vcenter(com.emc.storageos.db.client.model.Vcenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterApiClient(com.emc.storageos.vcentercontroller.VcenterApiClient) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) VcenterServerConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)

Aggregations

Cluster (com.emc.storageos.db.client.model.Cluster)67 Host (com.emc.storageos.db.client.model.Host)38 URI (java.net.URI)26 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)20 VcenterDataCenter (com.emc.storageos.db.client.model.VcenterDataCenter)19 Initiator (com.emc.storageos.db.client.model.Initiator)15 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 Path (javax.ws.rs.Path)14 Produces (javax.ws.rs.Produces)14 VcenterControllerException (com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException)13 VcenterObjectConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException)13 VcenterObjectNotFoundException (com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException)13 ArrayList (java.util.ArrayList)13 Vcenter (com.emc.storageos.db.client.model.Vcenter)12 VcenterServerConnectionException (com.emc.storageos.vcentercontroller.exceptions.VcenterServerConnectionException)11 HashSet (java.util.HashSet)9 MapCluster (com.emc.storageos.api.mapper.functions.MapCluster)8 VcenterApiClient (com.emc.storageos.vcentercontroller.VcenterApiClient)8 GET (javax.ws.rs.GET)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)6