Search in sources :

Example 56 with Cluster

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

the class InitiatorService method getInitiatorCluster.

private Cluster getInitiatorCluster(Initiator initiator) {
    URI hostId = initiator.getHost();
    Cluster cluster = null;
    URI clusterId = null;
    if (!NullColumnValueGetter.isNullURI(hostId)) {
        Host host = _dbClient.queryObject(Host.class, hostId);
        clusterId = host.getCluster();
    }
    if (!NullColumnValueGetter.isNullURI(clusterId)) {
        cluster = _dbClient.queryObject(Cluster.class, clusterId);
    }
    return cluster;
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 57 with Cluster

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

the class ExportGroupService method validateClientsAndPopulate.

/**
 * Validate the input data for clusters, hosts and initiators for {@link #createExportGroup(ExportCreateParam)}
 *
 * @param exportGroup the export group to populate
 * @param project the export group project
 * @param varray the export group varray
 * @param storageSystems the storage systems the export group has block object in
 * @param clusters the list of clusters to validate
 * @param hosts the list of hosts to validate
 * @param initiators the list of initiators to validate
 * @param volumes The list of volumes being exported (used to calculate numPaths)
 * @param pathParam Optional ExportPathParameters block (ignored if null)
 * @return the aggregate list of initiators needed to export all the hosts and clusters and initiators
 */
List<URI> validateClientsAndPopulate(ExportGroup exportGroup, Project project, VirtualArray varray, Collection<URI> storageSystems, List<URI> clusters, List<URI> hosts, List<URI> initiators, Collection<URI> volumes, ExportPathParameters pathParam) {
    List<URI> allInitiators = new ArrayList<>();
    List<URI> allHosts = new ArrayList<URI>();
    if (initiators != null && !initiators.isEmpty()) {
        List<Initiator> temp = new ArrayList<Initiator>();
        Set<URI> initiatorsHost = new HashSet<URI>(1);
        for (URI initiatorUri : initiators) {
            Initiator initiator = queryObject(Initiator.class, initiatorUri, true);
            if (initiator.getHost() == null || NullColumnValueGetter.isNullURI(initiator.getHost())) {
                throw APIException.badRequests.cannotExportInitiatorWithNoCompute(exportGroup.getLabel(), initiator.getInitiatorPort());
            }
            validateInitiatorRegistered(initiator);
            validateInitiatorNetworkRegistered(initiator, varray.getId());
            allInitiators.add(initiator.getId());
            initiatorsHost.add(initiator.getHost());
            temp.add(initiator);
        }
        validateInitiatorsData(temp, initiatorsHost, exportGroup);
    }
    if (hosts != null && !hosts.isEmpty()) {
        for (URI hostUri : hosts) {
            // validate the host
            Host host = queryObject(Host.class, hostUri, true);
            validateHostData(host, exportGroup, storageSystems, project, allInitiators);
            allHosts.add(host.getId());
        }
    }
    if (clusters != null && !clusters.isEmpty()) {
        for (URI clusterUri : clusters) {
            // validate the cluster
            Cluster cluster = queryObject(Cluster.class, clusterUri, true);
            validateClusterData(cluster, exportGroup, storageSystems, project, allHosts, allInitiators);
            exportGroup.addCluster(cluster);
        }
    }
    // validate tagged storage ports in varray
    validateVarrayStoragePorts(storageSystems, varray, volumes, allHosts);
    if (!allInitiators.isEmpty()) {
        // Validate StoragePorts can be assigned
        validatePortAssignmentOnStorageSystems(storageSystems, exportGroup, allInitiators, volumes, pathParam);
    }
    filterOutInitiatorsNotAssociatedWithVArray(exportGroup, storageSystems, null, allInitiators);
    // Validate the Host Operating Systems
    validateInitiatorHostOS(new HashSet(allInitiators));
    _log.info("All clients were found to be valid.");
    // now set the initiators to the export group before saving it
    exportGroup.setInitiators(StringSetUtil.uriListToStringSet(allInitiators));
    exportGroup.setHosts(StringSetUtil.uriListToStringSet(allHosts));
    return allInitiators;
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) HashSet(java.util.HashSet)

Example 58 with Cluster

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

the class ExportGroupService method validateClientsAndUpdate.

/**
 * This helper function is used by {@link #updateExportGroup(URI, ExportUpdateParam)} to
 * validate the user input and compute the updated lists of initiators, hosts and clusters.
 *
 * @param exportGroup the export group being updated.
 * @param project the export group project
 * @param storageSystems the storage systems where the export group volumes exist
 * @param param the input parameter
 * @param newClusters a list to be populated with the updated list of clusters
 * @param newHosts a list to be populated with the updated list of hosts
 * @param newInitiators a list to be populated with the updated list of initiators
 * @param addedClusters new clusters to be added to the given Export Group
 * @param removedClusters Clusters to be removed from the given Export Group
 * @param addedHosts New hosts to be added to the give Export Group
 * @param removedHosts Hosts to be removed from the give Export Group
 * @param addedInitiators New initiators to be added to the given Export Group
 * @param removedInitiators Initiators to be removed from the given Export Group
 */
void validateClientsAndUpdate(ExportGroup exportGroup, Project project, Collection<URI> storageSystems, ExportUpdateParam param, List<URI> newClusters, List<URI> newHosts, List<URI> newInitiators, Set<URI> addedClusters, Set<URI> removedClusters, Set<URI> addedHosts, Set<URI> removedHosts, Set<URI> addedInitiators, Set<URI> removedInitiators) {
    if (param.getClusters() != null) {
        if (!CollectionUtils.isEmpty(param.getClusters().getRemove())) {
            for (URI uri : param.getClusters().getRemove()) {
                if (!removedClusters.contains(uri)) {
                    removedClusters.add(uri);
                // removeClusterData(uri, newHosts, newInitiators);
                }
            }
        }
        if (!CollectionUtils.isEmpty(param.getClusters().getAdd())) {
            for (URI uri : param.getClusters().getAdd()) {
                Cluster cluster = queryObject(Cluster.class, uri, true);
                validateClusterData(cluster, exportGroup, storageSystems, project, newHosts, newInitiators);
                if (!addedClusters.contains(uri)) {
                    addedClusters.add(uri);
                }
            }
        }
    }
    _log.info("Updated list of Added clusters: {}", addedClusters.toArray());
    _log.info("Updated list of Removed clusters: {}", removedClusters.toArray());
    if (param.getHosts() != null) {
        if (!CollectionUtils.isEmpty(param.getHosts().getRemove())) {
            for (URI uri : param.getHosts().getRemove()) {
                removedHosts.add(uri);
            // removeHostData(uri, newInitiators);
            }
        }
        if (!CollectionUtils.isEmpty(param.getHosts().getAdd())) {
            for (URI uri : param.getHosts().getAdd()) {
                Host host = queryObject(Host.class, uri, true);
                // If the export type is cluster
                if (exportGroup.forCluster()) {
                    // make sure the host belongs to one of the group's clusters
                    if (!hasItems(newClusters) || !newClusters.contains(host.getCluster())) {
                        throw APIException.badRequests.invalidParameterHostNotInCluster(host.getHostName());
                    }
                }
                validateHostData(host, exportGroup, storageSystems, project, newInitiators);
                if (!addedHosts.contains(uri)) {
                    addedHosts.add(uri);
                }
            }
        }
    }
    _log.info("Updated list of Added Hosts: {}", addedHosts.toArray());
    _log.info("Updated list of Removed Hosts: {}", removedHosts.toArray());
    if (param.getInitiators() != null) {
        if (!CollectionUtils.isEmpty(param.getInitiators().getRemove())) {
            for (URI uri : param.getInitiators().getRemove()) {
                removedInitiators.add(uri);
            }
        }
        if (!CollectionUtils.isEmpty(param.getInitiators().getAdd())) {
            // TODO - Temporarily commented out for backward compatibility
            URI initiatorHostUri = getInitiatorExportGroupHost(exportGroup);
            for (URI uri : param.getInitiators().getAdd()) {
                Initiator initiator = queryObject(Initiator.class, uri, true);
                if (exportGroup.forInitiator()) {
                    if (initiatorHostUri == null) {
                        initiatorHostUri = initiator.getHost();
                    } else {
                        if (!initiatorHostUri.equals(initiator.getHost())) {
                            throw APIException.badRequests.initiatorExportGroupInitiatorsBelongToSameHost();
                        }
                    }
                }
                validateInitiatorRegistered(initiator);
                validateInitiatorNetworkRegistered(initiator, exportGroup.getVirtualArray());
                validateInitiatorData(initiator, exportGroup);
                if (exportGroup.forCluster() || exportGroup.forHost()) {
                    if (!newHosts.isEmpty() && !newHosts.contains(initiator.getHost())) {
                        throw APIException.badRequests.invalidParameterExportGroupInitiatorNotInHost(initiator.getId());
                    }
                }
                if (!addedInitiators.contains(uri)) {
                    addedInitiators.add(uri);
                }
            }
        }
    }
    validateInitiatorHostOS(addedInitiators);
    List<URI> connectStorageSystems = new ArrayList<>();
    newInitiators.addAll(addedInitiators);
    newInitiators.removeAll(removedInitiators);
    filterOutInitiatorsNotAssociatedWithVArray(exportGroup, storageSystems, connectStorageSystems, newInitiators);
    // Validate if we're adding new Volumes to the export. If so, we want to make sure that there
    // connections from the volumes to the StorageSystems. If the newInitiators list is empty, then
    // it would mean that not all StorageSystems are connected to the initiators. In which case,
    // the add volumes should fail. The user would need to make sure that the StorageSystem has
    // the necessary connections before proceeding.
    List<VolumeParam> addVolumeParams = param.getVolumes().getAdd();
    if (exportGroup.hasInitiators() && !CollectionUtils.isEmpty(addVolumeParams) && CollectionUtils.isEmpty(newInitiators)) {
        Set<URI> uniqueStorageSystemSet = new HashSet<>();
        for (VolumeParam addVolumeParam : addVolumeParams) {
            BlockObject blockObject = BlockObject.fetch(_dbClient, addVolumeParam.getId());
            if (blockObject != null) {
                uniqueStorageSystemSet.add(blockObject.getStorageController());
            }
        }
        List<String> storageSystemNames = new ArrayList<>();
        for (URI storageSystemURI : uniqueStorageSystemSet) {
            // Check if it's in the list of connected StorageSystems. If so, then skip it.
            if (connectStorageSystems.contains(storageSystemURI)) {
                continue;
            }
            StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
            if (storageSystem != null) {
                storageSystemNames.add(storageSystem.getNativeGuid());
            }
        }
        throw APIException.badRequests.storageSystemsNotConnectedForAddVolumes(Joiner.on(',').join(storageSystemNames));
    }
    _log.info("Updated list of initiators: {}", Joiner.on(',').join(newInitiators));
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Initiator(com.emc.storageos.db.client.model.Initiator) VolumeParam(com.emc.storageos.model.block.export.VolumeParam) BlockObject(com.emc.storageos.db.client.model.BlockObject) HashSet(java.util.HashSet) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 59 with Cluster

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

the class VolumeGroupService method getClusters.

/**
 * Get application clusters
 *
 * @param id Application Id
 * @brief List clusters for an application
 * @return ClusterList
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/clusters")
public ClusterList getClusters(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, VolumeGroup.class, "id");
    VolumeGroup volumeGroup = _dbClient.queryObject(VolumeGroup.class, id);
    ClusterList result = new ClusterList();
    List<Cluster> clusters = getVolumeGroupClusters(_dbClient, volumeGroup);
    for (Cluster cluster : clusters) {
        result.getClusters().add(toNamedRelatedResource(cluster));
    }
    return result;
}
Also used : ClusterList(com.emc.storageos.model.host.cluster.ClusterList) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) Cluster(com.emc.storageos.db.client.model.Cluster) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 60 with Cluster

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

the class TenantsService method createCluster.

/**
 * Creates a new host cluster for the tenant organization.
 *
 * @param tid
 *            the tenant organization id
 * @param createParam
 *            the parameter that has the type and attribute of the host to be created.
 * @prereq none
 * @brief Create host cluster for tenant
 * @return the host discovery async task representation.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/clusters")
public ClusterRestRep createCluster(@PathParam("id") URI tid, ClusterCreateParam createParam) {
    // This is mostly to validate the tenant
    TenantOrg tenant = getTenantById(tid, true);
    ClusterService clusterService = _clusterService;
    clusterService.validateClusterData(createParam, tid, null, _dbClient);
    Cluster cluster = clusterService.createNewCluster(tenant, createParam);
    _dbClient.createObject(cluster);
    recordTenantResourceOperation(OperationTypeEnum.CREATE_CLUSTER, tid, cluster);
    return map(cluster);
}
Also used : TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Cluster(com.emc.storageos.db.client.model.Cluster) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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