Search in sources :

Example 11 with XIVRestClient

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

the class XIVRestOperationsHelper method isClusteredHost.

/**
 * Validates if the Host is part of a Cluster on XIV system. Uses initiators to find out the Hosts
 *
 * @param storage XIV Storage System instance
 * @param exportMaskURI ExportMask instance
 * @param initiatorList Host Initiators
 * @param exportType Host/Cluster export type of the operation
 * @return True if the host is part of Cluster else false.
 */
public boolean isClusteredHost(StorageSystem storage, List<Initiator> initiators, String exportType) {
    boolean isClusteredHost = false;
    if (null != initiators && !initiators.isEmpty()) {
        Set<String> hostNames = new HashSet<String>();
        XIVRestClient restExportOpr = getRestClient(storage);
        if (null == restExportOpr) {
            return isClusteredHost;
        }
        // From Initiators find all the Hosts on Array
        for (Initiator initiator : initiators) {
            try {
                final String hostName = restExportOpr.getHostNameFromPort(storage.getSmisProviderIP(), Initiator.normalizePort(initiator.getInitiatorPort()));
                if (null != hostName) {
                    hostNames.add(hostName);
                }
            } catch (Exception e) {
                _log.error("Invalid host : {} or Port : {} for HSM from Storage System : {} ", storage.getSmisProviderIP(), initiator.getInitiatorPort(), storage.getLabel());
                final String errorMessage = "Unable to contact Hyper Scale Manager to execute operation. Either Host or Port could be invalid.";
                throw XIVRestException.exceptions.errorInHSMHostConfiguration(errorMessage);
            }
        }
        // Check if Host is part of Cluster
        if (hostNames.isEmpty()) {
            if (ExportGroup.ExportGroupType.Cluster.name().equals(exportType)) {
                isClusteredHost = true;
            }
        } else {
            Set<Boolean> result = new HashSet<Boolean>();
            for (String hostName : hostNames) {
                result.add(isClusteredHostOnArray(storage, hostName));
            }
            isClusteredHost = (result.size() == 1 ? result.iterator().next() : false);
        }
    }
    return isClusteredHost;
}
Also used : 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)

Aggregations

XIVRestClient (com.emc.storageos.xiv.api.XIVRestClient)11 XIVRestException (com.emc.storageos.xiv.api.XIVRestException)10 Initiator (com.emc.storageos.db.client.model.Initiator)9 Host (com.emc.storageos.db.client.model.Host)8 ExportMask (com.emc.storageos.db.client.model.ExportMask)7 URI (java.net.URI)7 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)5 Cluster (com.emc.storageos.db.client.model.Cluster)3 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)2 BlockObject (com.emc.storageos.db.client.model.BlockObject)2 StringMap (com.emc.storageos.db.client.model.StringMap)2 StringSet (com.emc.storageos.db.client.model.StringSet)2 Volume (com.emc.storageos.db.client.model.Volume)2 VolumeURIHLU (com.emc.storageos.volumecontroller.impl.VolumeURIHLU)2 HashMap (java.util.HashMap)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 ScopedLabelSet (com.emc.storageos.db.client.model.ScopedLabelSet)1 StorageProvider (com.emc.storageos.db.client.model.StorageProvider)1 HOST_STATUS (com.emc.storageos.xiv.api.XIVRestClient.HOST_STATUS)1