Search in sources :

Example 51 with Cluster

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

the class ComputeSystemHelper method updateInitiatorClusterName.

public static void updateInitiatorClusterName(DbClient dbClient, URI clusterURI, URI hostURI) {
    Cluster cluster = null;
    if (!NullColumnValueGetter.isNullURI(clusterURI)) {
        cluster = dbClient.queryObject(Cluster.class, clusterURI);
    }
    List<Initiator> initiators = ComputeSystemHelper.queryInitiators(dbClient, hostURI);
    for (Initiator initiator : initiators) {
        initiator.setClusterName(cluster != null ? cluster.getLabel() : "");
    }
    dbClient.updateObject(initiators);
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) Cluster(com.emc.storageos.db.client.model.Cluster)

Example 52 with Cluster

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

the class ProcessHostChangesCompleter method complete.

@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    if (isNotifyWorkflow()) {
        // If there is a workflow, update the step to complete.
        updateWorkflowStatus(status, coded);
    }
    // if export updates were successful, remove all old initiators and deleted hosts
    if (status.equals(Status.ready)) {
        for (HostStateChange hostChange : changes) {
            for (URI initiatorId : hostChange.getOldInitiators()) {
                Initiator initiator = dbClient.queryObject(Initiator.class, initiatorId);
                dbClient.markForDeletion(initiator);
                _logger.info("Initiator marked for deletion: " + this.getId());
            }
        }
        for (URI hostId : deletedHosts) {
            Host host = dbClient.queryObject(Host.class, hostId);
            // don't delete host if it was provisioned by Vipr
            if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
                _logger.info("do not delete provisioned host {} - disassociate it from vcenter", host.getLabel());
                host.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
                dbClient.persistObject(host);
            } else if (!NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
                _logger.info("do not delete host with boot volume {} - disassociate it from vcenter", host.getLabel());
                host.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
                dbClient.persistObject(host);
            } else {
                ComputeSystemHelper.doDeactivateHost(dbClient, host);
                _logger.info("Deactivating Host: " + host.getId());
            }
        }
        for (URI clusterId : deletedClusters) {
            Cluster cluster = dbClient.queryObject(Cluster.class, clusterId);
            List<URI> clusterHosts = ComputeSystemHelper.getChildrenUris(dbClient, clusterId, Host.class, "cluster");
            // don't delete cluster if auto-exports are disabled or all hosts weren't deleted (ex: hosts provisioned by ViPR)
            if (!clusterHosts.isEmpty()) {
                _logger.info("do not delete cluster {} - it still has hosts - disassociate it from vcenter", cluster.getLabel());
                cluster.setVcenterDataCenter(NullColumnValueGetter.getNullURI());
                cluster.setExternalId(NullColumnValueGetter.getNullStr());
                dbClient.persistObject(cluster);
            } else {
                ComputeSystemHelper.doDeactivateCluster(dbClient, cluster);
                _logger.info("Deactivating Cluster: " + cluster.getId());
            }
        }
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) HostStateChange(com.emc.storageos.computesystemcontroller.impl.adapter.HostStateChange) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) URI(java.net.URI)

Example 53 with Cluster

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

the class AbstractHostDiscoveryAdapter method setInitiator.

/**
 * Sets the host/cluster values for the initiator.
 *
 * @param initiator
 *            the initiator.
 * @param host
 *            the host.
 */
protected void setInitiator(Initiator initiator, Host host) {
    initiator.setHost(host.getId());
    initiator.setHostName(host.getHostName());
    Cluster cluster = getCluster(host);
    initiator.setClusterName(cluster != null ? cluster.getLabel() : "");
}
Also used : Cluster(com.emc.storageos.db.client.model.Cluster)

Example 54 with Cluster

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

the class UnManagedVolumeService method ingestExportedVolumes.

/**
 * Ingest Exported Volumes
 *
 * For each UnManaged Volume Find the list of masking views this volume
 * is exposed to.
 *
 * If only 1 masking view verify if all the initiators are available on
 * the existing MV. Verify the storage Ports are available in given
 * VArray Verify if this export mask is available already If not, then
 * create a new Export Mask with the storage Ports, initiators from
 * ViPr. Else, add volume to export mask.
 *
 * If more than 1 masking view verify if all the initiators are
 * available on all existing MVs. Verify the storage Ports within each
 * Masking view are available in given VArray. Verify if this export
 * mask is available already If not, then create a new Export Mask with
 * the storage Ports, initiators from ViPr. Else, add volume to export
 * mask.
 *
 * @param exportIngestParam
 * @brief Add volumes to new or existing export masks; create masks when needed
 * @return TaskList
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/ingest-exported")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskList ingestExportedVolumes(VolumeExportIngestParam exportIngestParam) throws InternalException {
    TaskList taskList = new TaskList();
    Map<String, TaskResourceRep> taskMap = new HashMap<String, TaskResourceRep>();
    BaseIngestionRequestContext requestContext = null;
    try {
        if (exportIngestParam.getUnManagedVolumes().size() > getMaxBulkSize()) {
            throw APIException.badRequests.exceedingLimit("unmanaged volumes", getMaxBulkSize());
        }
        Project project = _permissionsHelper.getObjectById(exportIngestParam.getProject(), Project.class);
        ArgValidator.checkEntity(project, exportIngestParam.getProject(), false);
        VirtualArray varray = VolumeIngestionUtil.getVirtualArrayForVolumeCreateRequest(project, exportIngestParam.getVarray(), _permissionsHelper, _dbClient);
        VirtualPool vpool = VolumeIngestionUtil.getVirtualPoolForVolumeCreateRequest(project, exportIngestParam.getVpool(), _permissionsHelper, _dbClient);
        // allow ingestion for VPool without Virtual Arrays
        if (null != vpool.getVirtualArrays() && !vpool.getVirtualArrays().isEmpty() && !vpool.getVirtualArrays().contains(exportIngestParam.getVarray().toString())) {
            throw APIException.internalServerErrors.virtualPoolNotMatchingVArray(exportIngestParam.getVarray());
        }
        // check for Quotas
        long unManagedVolumesCapacity = VolumeIngestionUtil.getTotalUnManagedVolumeCapacity(_dbClient, exportIngestParam.getUnManagedVolumes());
        _logger.info("UnManagedVolume provisioning quota validation successful");
        TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
        CapacityUtils.validateQuotasForProvisioning(_dbClient, vpool, project, tenant, unManagedVolumesCapacity, "volume");
        VolumeIngestionUtil.checkIngestionRequestValidForUnManagedVolumes(exportIngestParam.getUnManagedVolumes(), vpool, _dbClient);
        requestContext = new BaseIngestionRequestContext(_dbClient, exportIngestParam.getUnManagedVolumes(), vpool, varray, project, tenant, exportIngestParam.getVplexIngestionMethod());
        while (requestContext.hasNext()) {
            UnManagedVolume unManagedVolume = requestContext.next();
            if (null == unManagedVolume) {
                _logger.warn("No Unmanaged Volume with URI {} found in database. Continuing...", requestContext.getCurrentUnManagedVolumeUri());
                continue;
            }
            String taskId = UUID.randomUUID().toString();
            Operation operation = _dbClient.createTaskOpStatus(UnManagedVolume.class, requestContext.getCurrentUnManagedVolumeUri(), taskId, ResourceOperationTypeEnum.INGEST_EXPORTED_BLOCK_OBJECTS);
            TaskResourceRep task = toTask(unManagedVolume, taskId, operation);
            taskMap.put(unManagedVolume.getId().toString(), task);
        }
        taskList.getTaskList().addAll(taskMap.values());
        // find or create ExportGroup for this set of volumes being ingested
        URI exportGroupResourceUri = null;
        String resourceType = ExportGroupType.Host.name();
        String computeResourcelabel = null;
        if (null != exportIngestParam.getCluster()) {
            resourceType = ExportGroupType.Cluster.name();
            Cluster cluster = _dbClient.queryObject(Cluster.class, exportIngestParam.getCluster());
            exportGroupResourceUri = cluster.getId();
            computeResourcelabel = cluster.getLabel();
            requestContext.setCluster(exportIngestParam.getCluster());
        } else {
            Host host = _dbClient.queryObject(Host.class, exportIngestParam.getHost());
            exportGroupResourceUri = host.getId();
            computeResourcelabel = host.getHostName();
            requestContext.setHost(exportIngestParam.getHost());
        }
        ExportGroup exportGroup = VolumeIngestionUtil.verifyExportGroupExists(requestContext, requestContext.getProject().getId(), exportGroupResourceUri, exportIngestParam.getVarray(), resourceType, _dbClient);
        if (null == exportGroup) {
            _logger.info("Creating Export Group with label {}", computeResourcelabel);
            ResourceAndUUIDNameGenerator nameGenerator = new ResourceAndUUIDNameGenerator();
            exportGroup = VolumeIngestionUtil.initializeExportGroup(requestContext.getProject(), resourceType, exportIngestParam.getVarray(), computeResourcelabel, _dbClient, nameGenerator, requestContext.getTenant());
            requestContext.setExportGroupCreated(true);
        }
        requestContext.setExportGroup(exportGroup);
        _logger.info("ExportGroup {} created ", exportGroup.forDisplay());
        IngestVolumesExportedSchedulingThread.executeApiTask(_asyncTaskService.getExecutorService(), requestContext, ingestStrategyFactory, this, _dbClient, taskMap, taskList);
    } catch (InternalException e) {
        _logger.error("InternalException occurred due to: {}", e);
        throw e;
    } catch (Exception e) {
        _logger.error("Unexpected exception occurred due to: {}", e);
        throw APIException.internalServerErrors.genericApisvcError(ExceptionUtils.getExceptionMessage(e), e);
    }
    return taskList;
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) HashMap(java.util.HashMap) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) ExportGroup(com.emc.storageos.db.client.model.ExportGroup) BaseIngestionRequestContext(com.emc.storageos.api.service.impl.resource.blockingestorchestration.context.impl.BaseIngestionRequestContext) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) ResourceAndUUIDNameGenerator(com.emc.storageos.db.client.util.ResourceAndUUIDNameGenerator) 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)

Example 55 with Cluster

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

the class HostService method validateHostData.

/**
 * Validates the create/update host input data
 *
 * @param hostParam
 *            the input parameter
 * @param host
 *            the host being updated in case of update operation.
 *            This parameter must be null for create operations.n
 */
protected void validateHostData(HostParam hostParam, URI tenanUri, Host host, Boolean validateConnection) {
    Cluster cluster = null;
    VcenterDataCenter dataCenter = null;
    Project project = null;
    Volume volume = null;
    // validate the host type
    if (hostParam.getType() != null) {
        ArgValidator.checkFieldValueFromEnum(hostParam.getType(), "Type", Host.HostType.class);
    }
    // validate the project is present, active, and in the same tenant org
    if (!NullColumnValueGetter.isNullURI(hostParam.getProject())) {
        project = queryObject(Project.class, hostParam.getProject(), true);
        if (!project.getTenantOrg().getURI().equals(tenanUri)) {
            throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("project");
        }
    }
    if (!NullColumnValueGetter.isNullURI(hostParam.getBootVolume())) {
        volume = queryObject(Volume.class, hostParam.getBootVolume(), true);
        if (!volume.getTenant().getURI().equals(tenanUri)) {
            throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("boot volume");
        }
    }
    // validate the cluster is present, active, and in the same tenant org
    if (!NullColumnValueGetter.isNullURI(hostParam.getCluster())) {
        cluster = queryObject(Cluster.class, hostParam.getCluster(), true);
        if (!cluster.getTenant().equals(tenanUri)) {
            throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("cluster");
        }
    }
    // validate the data center is present, active, and in the same tenant org
    if (!NullColumnValueGetter.isNullURI(hostParam.getVcenterDataCenter())) {
        dataCenter = queryObject(VcenterDataCenter.class, hostParam.getVcenterDataCenter(), true);
        if (!dataCenter.getTenant().equals(tenanUri)) {
            throw APIException.badRequests.resourcedoesNotBelongToHostTenantOrg("data center");
        }
    }
    if (cluster != null) {
        if (dataCenter != null) {
            // check the cluster and data center are consistent
            if (!dataCenter.getId().equals(cluster.getVcenterDataCenter())) {
                throw APIException.badRequests.invalidParameterClusterNotInDataCenter(cluster.getLabel(), dataCenter.getLabel());
            }
        } else if (project != null) {
            // check the cluster and data center are consistent
            if (!project.getId().equals(cluster.getProject())) {
                throw APIException.badRequests.invalidParameterClusterNotInHostProject(cluster.getLabel());
            }
        }
    }
    // check the host name is not a duplicate
    if (host == null || (hostParam.getHostName() != null && !hostParam.getHostName().equals(host.getHostName()))) {
        checkDuplicateAltId(Host.class, "hostName", EndpointUtility.changeCase(hostParam.getHostName()), "host");
    }
    // check the host label is not a duplicate
    if (host == null || (hostParam.getName() != null && !hostParam.getName().equals(host.getLabel()))) {
        checkDuplicateLabel(Host.class, hostParam.getName());
    }
    // If the host project is being changed, check for active exports
    if (host != null && !areEqual(host.getProject(), hostParam.getProject())) {
        if (ComputeSystemHelper.isHostInUse(_dbClient, host.getId())) {
            throw APIException.badRequests.hostProjectChangeNotAllowed(host.getHostName());
        }
    }
    // Find out if the host should be discoverable by checking input and current values
    Boolean discoverable = hostParam.getDiscoverable() == null ? (host == null ? Boolean.FALSE : host.getDiscoverable()) : hostParam.getDiscoverable();
    boolean vCenterManaged = host == null ? false : Host.HostType.Esx.name().equals(host.getType()) && !NullColumnValueGetter.isNullURI(host.getVcenterDataCenter());
    // If discoverable, ensure username and password are set in the current host or parameters
    if (!vCenterManaged && discoverable != null && discoverable) {
        String username = hostParam.getUserName() == null ? (host == null ? null : host.getUsername()) : hostParam.getUserName();
        String password = hostParam.getPassword() == null ? (host == null ? null : host.getPassword()) : hostParam.getPassword();
        ArgValidator.checkFieldNotNull(username, "username");
        ArgValidator.checkFieldNotNull(password, "password");
        Host.HostType hostType = Host.HostType.valueOf(hostParam.getType() == null ? (host == null ? null : host.getType()) : hostParam.getType());
        if (hostType != null && hostType == Host.HostType.Windows) {
            Integer portNumber = hostParam.getPortNumber() == null ? (host == null ? null : host.getPortNumber()) : hostParam.getPortNumber();
            ArgValidator.checkFieldNotNull(portNumber, "port_number");
        }
    }
    if (validateConnection != null && validateConnection == true) {
        if (!HostConnectionValidator.isHostConnectionValid(hostParam, host)) {
            throw APIException.badRequests.invalidHostConnection();
        }
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) Cluster(com.emc.storageos.db.client.model.Cluster) VcenterDataCenter(com.emc.storageos.db.client.model.VcenterDataCenter) Host(com.emc.storageos.db.client.model.Host)

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