Search in sources :

Example 11 with ComputeSystemController

use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.

the class AbstractDiscoveryAdapter method addNewInitiatorsToExport.

protected void addNewInitiatorsToExport(Host host, List<Initiator> newInitiators) {
    // update export if host is in use
    if (ComputeSystemHelper.isHostInUse(dbClient, host.getId())) {
        String taskId = UUID.randomUUID().toString();
        ComputeSystemController controller = getController(ComputeSystemController.class, null);
        List<URI> uris = Lists.newArrayList();
        for (Initiator initiator : newInitiators) {
            uris.add(initiator.getId());
        }
        controller.addInitiatorsToExport(host.getId(), uris, taskId);
    }
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) URI(java.net.URI)

Example 12 with ComputeSystemController

use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.

the class HostService method detachStorage.

/**
 * Updates export groups and fileshare exports that are referenced by the given host by removing
 * the host reference, initiators and IP interfaces belonging to this host. Volumes are left intact.
 *
 * @param id
 *            the URN of a ViPR Host
 * @brief Detach storage from host
 * @return OK if detaching completed successfully
 * @throws DatabaseException
 *             when a DB error occurs
 */
@POST
@Path("/{id}/detach-storage")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public TaskResourceRep detachStorage(@PathParam("id") URI id) throws DatabaseException {
    Host host = queryHost(_dbClient, id);
    ArgValidator.checkEntity(host, id, true);
    boolean hasPendingTasks = hostHasPendingTasks(id);
    if (hasPendingTasks) {
        throw APIException.badRequests.cannotDetachStorageForHost("another operation is in progress for this host");
    }
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, ResourceOperationTypeEnum.DETACH_HOST_STORAGE);
    ComputeSystemController controller = getController(ComputeSystemController.class, null);
    controller.detachHostStorage(host.getId(), false, false, null, taskId);
    return toTask(host, taskId, op);
}
Also used : ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 13 with ComputeSystemController

use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.

the class HostService method deactivateHost.

/**
 * Deactivates the host and all its interfaces.
 *
 * @param id
 *            the URN of a ViPR Host to be deactivated
 * @param detachStorage
 *            if true, will first detach storage.
 * @param detachStorageDeprecated
 *            Deprecated. Use detachStorage instead.
 * @param deactivateBootVolume
 *            if true, and if the host was provisioned by ViPR the associated boot volume (if exists) will be
 *            deactivated
 * @brief Deactivate host
 * @return OK if deactivation completed successfully
 * @throws DatabaseException
 *             when a DB error occurs
 */
@POST
@Path("/{id}/deactivate")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public TaskResourceRep deactivateHost(@PathParam("id") URI id, @DefaultValue("false") @QueryParam("detach_storage") boolean detachStorage, @DefaultValue("false") @QueryParam("detach-storage") boolean detachStorageDeprecated, @DefaultValue("true") @QueryParam("deactivate_boot_volume") boolean deactivateBootVolume) throws DatabaseException {
    Host host = queryHost(_dbClient, id);
    ArgValidator.checkEntity(host, id, true);
    boolean hasPendingTasks = hostHasPendingTasks(id);
    if (hasPendingTasks) {
        throw APIException.badRequests.resourceCannotBeDeleted("Host with another operation in progress");
    }
    boolean isHostInUse = ComputeSystemHelper.isHostInUse(_dbClient, host.getId());
    if (isHostInUse && !(detachStorage || detachStorageDeprecated)) {
        throw APIException.badRequests.resourceHasActiveReferences(Host.class.getSimpleName(), id);
    }
    UCSServiceProfile serviceProfile = null;
    if (!NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
        serviceProfile = _dbClient.queryObject(UCSServiceProfile.class, host.getServiceProfile());
        if (serviceProfile != null && !NullColumnValueGetter.isNullURI(serviceProfile.getComputeSystem())) {
            ComputeSystem ucs = _dbClient.queryObject(ComputeSystem.class, serviceProfile.getComputeSystem());
            if (ucs != null && ucs.getDiscoveryStatus().equals(DataCollectionJobStatus.ERROR.name())) {
                throw APIException.badRequests.resourceCannotBeDeleted("Host has service profile on a Compute System that failed to discover; ");
            }
        }
    }
    Collection<URI> hostIds = _dbClient.queryByType(Host.class, true);
    Collection<Host> hosts = _dbClient.queryObjectFields(Host.class, Arrays.asList("label", "uuid", "serviceProfile", "computeElement", "registrationStatus", "inactive"), ControllerUtils.getFullyImplementedCollection(hostIds));
    for (Host tempHost : hosts) {
        if (!tempHost.getId().equals(host.getId()) && !tempHost.getInactive()) {
            if (tempHost.getUuid() != null && tempHost.getUuid().equals(host.getUuid())) {
                throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same uuid " + host.getUuid() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
            }
            if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && host.getComputeElement() == tempHost.getComputeElement()) {
                throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same computeElement " + host.getComputeElement() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
            }
            if (!NullColumnValueGetter.isNullURI(host.getServiceProfile()) && host.getServiceProfile() == tempHost.getServiceProfile()) {
                throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same serviceProfile " + host.getServiceProfile() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
            }
        }
    }
    if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
        throw APIException.badRequests.resourceCannotBeDeletedVblock(host.getLabel(), "Host " + host.getLabel() + " has a compute element, but no service profile." + " Please re-discover the Vblock Compute System and retry.");
    }
    // VBDU [DONE]: COP-28452, Running host deactivate even if initiators == null or list empty seems risky
    // If initiators are empty, we will not perform any export updates
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, ResourceOperationTypeEnum.DELETE_HOST);
    ComputeSystemController controller = getController(ComputeSystemController.class, null);
    List<VolumeDescriptor> bootVolDescriptors = new ArrayList<>();
    if (deactivateBootVolume & !NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
        Volume vol = _dbClient.queryObject(Volume.class, host.getBootVolumeId());
        if (vol.isVPlexVolume(_dbClient)) {
            bootVolDescriptors.addAll(vplexBlockServiceApiImpl.getDescriptorsForVolumesToBeDeleted(vol.getStorageController(), Arrays.asList(host.getBootVolumeId()), null));
        } else {
            if (vol.getPool() != null) {
                StoragePool storagePool = _dbClient.queryObject(StoragePool.class, vol.getPool());
                if (storagePool != null && storagePool.getStorageDevice() != null) {
                    bootVolDescriptors.add(new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, storagePool.getStorageDevice(), host.getBootVolumeId(), null, null));
                }
            }
        }
    }
    controller.detachHostStorage(host.getId(), true, deactivateBootVolume, bootVolDescriptors, taskId);
    if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        host.setProvisioningStatus(Host.ProvisioningJobStatus.IN_PROGRESS.toString());
    }
    _dbClient.persistObject(host);
    auditOp(OperationTypeEnum.DELETE_HOST, true, op.getStatus(), host.auditParameters());
    return toTask(host, taskId, op);
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) StoragePool(com.emc.storageos.db.client.model.StoragePool) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 14 with ComputeSystemController

use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.

the class HostService method createNewHost.

/**
 * Creates a new instance of host.
 *
 * @param tenant
 *            the host parent tenant organization
 * @param param
 *            the input parameter containing the host attributes
 * @return an instance of {@link Host}
 */
protected TaskResourceRep createNewHost(TenantOrg tenant, HostParam param) {
    Host host = new Host();
    host.setId(URIUtil.createId(Host.class));
    host.setTenant(tenant.getId());
    host.setCluster(param.getCluster());
    populateHostData(host, param);
    if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
        if (ComputeSystemHelper.isClusterInExport(_dbClient, host.getCluster())) {
            String taskId = UUID.randomUUID().toString();
            ComputeSystemController controller = getController(ComputeSystemController.class, null);
            controller.addHostsToExport(Arrays.asList(host.getId()), host.getCluster(), taskId, null, false);
        } else {
            ComputeSystemHelper.updateInitiatorClusterName(_dbClient, host.getCluster(), host.getId());
        }
    }
    host.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
    _dbClient.createObject(host);
    auditOp(OperationTypeEnum.CREATE_HOST, true, null, host.auditParameters());
    return doDiscoverHost(host.getId(), null, true);
}
Also used : ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Host(com.emc.storageos.db.client.model.Host)

Example 15 with ComputeSystemController

use of com.emc.storageos.computesystemcontroller.ComputeSystemController in project coprhd-controller by CoprHD.

the class HostService method updateHost.

/**
 * Updates one or more of the host attributes. Discovery is initiated
 * after the host is updated.
 *
 * <p>
 * Updating the host's cluster:
 * <ul>
 *     <li> Adding a host to a cluster: The host will gain access to all volumes in the cluster.
 *     <li> Removing a host from a cluster: The host will lose access to all volumes in the cluster.
 *     <li> Updating a host's cluster: The host will lose access to all volumes in the old cluster. The
 *          host will gain access to all volumes in the new cluster.
 * </ul>
 *
 * @param id
 *            the URN of a ViPR Host
 * @param updateParam
 *            the parameter that has the attributes to be
 *            updated.
 * @brief Update host attributes
 * @return the host discovery async task representation.
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}")
public TaskResourceRep updateHost(@PathParam("id") URI id, HostUpdateParam updateParam, @QueryParam("validate_connection") @DefaultValue("false") final Boolean validateConnection, @QueryParam("update_exports") @DefaultValue("true") boolean updateExports) {
    // update the host
    Host host = queryObject(Host.class, id, true);
    validateHostData(updateParam, host.getTenant(), host, validateConnection);
    boolean hasPendingTasks = hostHasPendingTasks(id);
    if (hasPendingTasks) {
        throw APIException.badRequests.cannotUpdateHost("another operation is in progress for this host");
    }
    URI oldClusterURI = host.getCluster();
    URI newClusterURI = updateParam.getCluster();
    populateHostData(host, updateParam);
    if (updateParam.getHostName() != null) {
        ComputeSystemHelper.updateInitiatorHostName(_dbClient, host);
    }
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Host.class, id, taskId, ResourceOperationTypeEnum.UPDATE_HOST);
    ComputeSystemController controller = getController(ComputeSystemController.class, null);
    boolean updateTaskStatus = true;
    // We only want to update the export group if we're changing the cluster during a host update
    if (newClusterURI != null) {
        updateTaskStatus = false;
        // This is run when a clustered host is moved out of a cluster
        if (updateExports && !NullColumnValueGetter.isNullURI(oldClusterURI) && NullColumnValueGetter.isNullURI(newClusterURI) && ComputeSystemHelper.isClusterInExport(_dbClient, oldClusterURI)) {
            // Remove host from shared export
            controller.removeHostsFromExport(Arrays.asList(host.getId()), oldClusterURI, false, updateParam.getVcenterDataCenter(), taskId);
        } else if (updateExports && NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(newClusterURI) && ComputeSystemHelper.isClusterInExport(_dbClient, newClusterURI)) {
            // Non-clustered host being added to a cluster
            controller.addHostsToExport(Arrays.asList(host.getId()), newClusterURI, taskId, oldClusterURI, false);
        } else if (updateExports && !NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(newClusterURI) && !oldClusterURI.equals(newClusterURI) && (ComputeSystemHelper.isClusterInExport(_dbClient, oldClusterURI) || ComputeSystemHelper.isClusterInExport(_dbClient, newClusterURI))) {
            // Clustered host being moved to another cluster
            controller.addHostsToExport(Arrays.asList(host.getId()), newClusterURI, taskId, oldClusterURI, false);
        } else if (updateExports && !NullColumnValueGetter.isNullURI(oldClusterURI) && !NullColumnValueGetter.isNullURI(newClusterURI) && oldClusterURI.equals(newClusterURI) && ComputeSystemHelper.isClusterInExport(_dbClient, newClusterURI)) {
            // Cluster hasn't changed but we should add host to the shared exports for this cluster
            controller.addHostsToExport(Arrays.asList(host.getId()), newClusterURI, taskId, oldClusterURI, false);
        } else {
            updateTaskStatus = true;
            ComputeSystemHelper.updateHostAndInitiatorClusterReferences(_dbClient, newClusterURI, host.getId());
        }
    }
    _dbClient.updateObject(host);
    auditOp(OperationTypeEnum.UPDATE_HOST, true, null, host.auditParameters());
    return doDiscoverHost(host.getId(), taskId, updateTaskStatus);
}
Also used : ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

ComputeSystemController (com.emc.storageos.computesystemcontroller.ComputeSystemController)21 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)10 POST (javax.ws.rs.POST)10 Host (com.emc.storageos.db.client.model.Host)9 Operation (com.emc.storageos.db.client.model.Operation)9 URI (java.net.URI)6 Initiator (com.emc.storageos.db.client.model.Initiator)4 MapVcenter (com.emc.storageos.api.mapper.functions.MapVcenter)3 TaskList (com.emc.storageos.model.TaskList)3 ArrayList (java.util.ArrayList)3 Consumes (javax.ws.rs.Consumes)3 MapVcenterDataCenter (com.emc.storageos.api.mapper.functions.MapVcenterDataCenter)2 DiscoveredObjectTaskScheduler (com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler)2 ActionableEvent (com.emc.storageos.db.client.model.ActionableEvent)2 Cluster (com.emc.storageos.db.client.model.Cluster)2 AsyncTask (com.emc.storageos.volumecontroller.AsyncTask)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2