Search in sources :

Example 16 with AsyncTask

use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.

the class ComputeControllerImpl method deactivateHost.

@Override
public void deactivateHost(AsyncTask[] tasks) throws InternalException {
    AsyncTask task = tasks[0];
    Host host = _dbClient.queryObject(Host.class, task._id);
    if (host != null) {
        if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
            ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
            execCompute("deactivateHost", computeElement.getComputeSystem(), task._id, task._opId);
        } else {
            _dbClient.error(Host.class, task._id, task._opId, ComputeSystemControllerException.exceptions.noComputeElementAssociatedWithHost(host.getNativeGuid().toString(), host.getId().toString(), null));
        }
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) Host(com.emc.storageos.db.client.model.Host)

Example 17 with AsyncTask

use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.

the class ComputeDeviceControllerImpl method removeHostFromVcenterCluster.

/**
 * This will attempt to remove host from vCenter cluster.
 *
 * @param hostId
 * @param stepId
 */
public void removeHostFromVcenterCluster(URI hostId, String stepId) {
    log.info("removeHostFromVcenterCluster {}", hostId);
    Host host = null;
    try {
        WorkflowStepCompleter.stepExecuting(stepId);
        host = _dbClient.queryObject(Host.class, hostId);
        if (NullColumnValueGetter.isNullURI(host.getVcenterDataCenter())) {
            log.info("datacenter is null, nothing to do");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        if (NullColumnValueGetter.isNullURI(host.getCluster())) {
            log.warn("cluster is null, nothing to do");
            WorkflowStepCompleter.stepSucceded(stepId);
            return;
        }
        // Test mechanism to invoke a failure. No-op on production systems.
        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_068);
        String taskId = stepId;
        Operation op = new Operation();
        op.setResourceType(ResourceOperationTypeEnum.UPDATE_VCENTER_CLUSTER);
        _dbClient.createTaskOpStatus(VcenterDataCenter.class, host.getVcenterDataCenter(), taskId, op);
        AsyncTask task = new AsyncTask(VcenterDataCenter.class, host.getVcenterDataCenter(), taskId);
        final String workflowKey = "updateVcenterCluster";
        if (!WorkflowService.getInstance().hasWorkflowBeenCreated(taskId, workflowKey)) {
            vcenterController.updateVcenterCluster(task, host.getCluster(), null, new URI[] { host.getId() }, null);
            // Mark this workflow as created/executed so we don't do it
            // again on retry/resume
            WorkflowService.getInstance().markWorkflowBeenCreated(taskId, workflowKey);
        }
    } catch (VcenterControllerException e) {
        log.warn("VcenterControllerException when trying to removeHostFromVcenterCluster: " + e.getMessage(), e);
        if (e.getCause() instanceof VcenterObjectNotFoundException) {
            log.info("did not find the host, considering success");
            WorkflowStepCompleter.stepSucceded(stepId);
        } else if (e.getCause() instanceof VcenterObjectConnectionException) {
            log.info("host is not connected, considering success");
            WorkflowStepCompleter.stepSucceded(stepId);
        } else {
            log.error("failure " + e);
            WorkflowStepCompleter.stepFailed(stepId, e);
        }
    } catch (InternalException e) {
        log.error("InternalException when trying to removeHostFromVcenterCluster: " + e.getMessage(), e);
        WorkflowStepCompleter.stepFailed(stepId, e);
    } catch (Exception e) {
        log.error("unexpected exception: " + e.getMessage(), e);
        ServiceCoded serviceCoded = ComputeSystemControllerException.exceptions.unableToRemoveHostVcenterCluster(host != null ? host.getHostName() : hostId.toString(), e);
        WorkflowStepCompleter.stepFailed(stepId, serviceCoded);
    }
}
Also used : VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) VcenterObjectConnectionException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectConnectionException) VcenterObjectNotFoundException(com.emc.storageos.vcentercontroller.exceptions.VcenterObjectNotFoundException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) VcenterControllerException(com.emc.storageos.vcentercontroller.exceptions.VcenterControllerException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 18 with AsyncTask

use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.

the class VcenterDataCenterService method createOrUpdateVcenterCluster.

/*
     * @param create - Whether to create a new cluster vs update an existing
     */
private TaskResourceRep createOrUpdateVcenterCluster(boolean createCluster, URI id, URI clusterId, List<URI> addHosts, List<URI> removeHosts) {
    _log.info("createOrUpdateVcenterCluster " + createCluster + " " + id + " " + clusterId);
    ArgValidator.checkFieldUriType(id, VcenterDataCenter.class, "id");
    VcenterDataCenter vcenterDataCenter = queryObject(VcenterDataCenter.class, id, false);
    ArgValidator.checkEntity(vcenterDataCenter, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldUriType(clusterId, Cluster.class, "clusterId");
    Cluster cluster = queryObject(Cluster.class, clusterId, false);
    ArgValidator.checkEntity(cluster, clusterId, isIdEmbeddedInURL(clusterId));
    verifyAuthorizedInTenantOrg(cluster.getTenant(), getUserFromContext());
    /*
         * Check if explicit add host or remove hosts are specified
         * If one or both are, only execute whats specified
         * If nothing is specified, do automatic host selection and import all hosts in cluster
         */
    Collection<URI> addHostUris = new ArrayList<URI>();
    Collection<URI> removeHostUris = new ArrayList<URI>();
    boolean manualHostSpecification = false;
    if (addHosts != null && !addHosts.isEmpty()) {
        _log.info("Request to explicitly add hosts " + addHosts);
        manualHostSpecification = true;
    }
    if (removeHosts != null && !removeHosts.isEmpty()) {
        _log.info("Request to explicitly remove hosts " + removeHosts);
        manualHostSpecification = true;
    }
    if (manualHostSpecification) {
        for (URI uri : addHosts) {
            Host host = queryObject(Host.class, uri, false);
            if (isHostCompatibleForVcenterCluster(host)) {
                addHostUris.add(uri);
            }
        }
        for (URI uri : removeHosts) {
            Host host = queryObject(Host.class, uri, false);
            if (isHostCompatibleForVcenterCluster(host)) {
                removeHostUris.add(uri);
            }
        }
    } else {
        // If no hosts specified by default add all hosts within cluster
        Collection<URI> hostUris = new ArrayList<URI>();
        List<NamedElementQueryResultList.NamedElement> hostNamedElements = listChildren(clusterId, Host.class, "label", "cluster");
        for (NamedElementQueryResultList.NamedElement hostNamedElement : hostNamedElements) {
            Host host = queryObject(Host.class, hostNamedElement.getId(), false);
            if (isHostCompatibleForVcenterCluster(host)) {
                addHostUris.add(host.getId());
            }
        }
        if (addHostUris.isEmpty()) {
            // Require at least a single compatible host for automatic mode, do not create empty cluster
            _log.error("Cluster " + cluster.getLabel() + " does not contain any ESX/ESXi hosts and is thus incompatible for vCenter operations");
            throw APIException.badRequests.clusterContainsNoCompatibleHostsForVcenter();
        }
    }
    // Find all shared volumes in the cluster
    List<URI> volumeUris = new ArrayList<URI>();
    try {
        List<ExportGroup> exportGroups = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, ExportGroup.class, AlternateIdConstraint.Factory.getConstraint(ExportGroup.class, "clusters", cluster.getId().toString()));
        _log.info("Found " + exportGroups.size() + " export groups for cluster " + cluster.getLabel());
        for (ExportGroup exportGroup : exportGroups) {
            _log.info("Cluster " + cluster.getLabel() + " has export group " + exportGroup.getLabel() + " of type " + exportGroup.getType());
            if (exportGroup.forCluster()) {
                _log.info("Export group " + exportGroup.getLabel() + " is cluster/shared type");
                StringMap volumes = exportGroup.getVolumes();
                _log.info("Export group " + exportGroup.getLabel() + " has " + volumes.size() + " volumes");
                for (String volumeUriString : volumes.keySet()) {
                    _log.info("Volume URI " + volumeUriString + " found in export group " + exportGroup.getLabel());
                    URI uri = URI.create(volumeUriString);
                    volumeUris.add(uri);
                }
            }
        }
    } catch (Exception e) {
        _log.error("Exception navigating cluster export groups for shared volumes " + e);
    // for time being just ignore
    }
    Collection<Volume> volumes = _dbClient.queryObject(Volume.class, volumeUris);
    for (Volume volume : volumes) {
        _log.info("Volume " + volume.getLabel() + " " + volume.getWWN() + " is shared and compatible for VMFS datastore");
    }
    String taskId = UUID.randomUUID().toString();
    Operation op = new Operation();
    op.setResourceType(createCluster ? ResourceOperationTypeEnum.CREATE_VCENTER_CLUSTER : ResourceOperationTypeEnum.UPDATE_VCENTER_CLUSTER);
    _dbClient.createTaskOpStatus(VcenterDataCenter.class, vcenterDataCenter.getId(), taskId, op);
    AsyncTask task = new AsyncTask(VcenterDataCenter.class, vcenterDataCenter.getId(), taskId);
    VcenterController vcenterController = getController(VcenterController.class, null);
    if (createCluster) {
        vcenterController.createVcenterCluster(task, clusterId, addHostUris.toArray(new URI[0]), volumeUris.toArray(new URI[0]));
    } else {
        vcenterController.updateVcenterCluster(task, clusterId, addHostUris.toArray(new URI[0]), removeHostUris.toArray(new URI[0]), volumeUris.toArray(new URI[0]));
    }
    auditOp(OperationTypeEnum.CREATE_UPDATE_VCENTER_CLUSTER, true, null, vcenterDataCenter.auditParameters());
    return toTask(vcenterDataCenter, taskId, op);
}
Also used : ArrayList(java.util.ArrayList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) URI(java.net.URI) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) VcenterController(com.emc.storageos.vcentercontroller.VcenterController) MapVcenterDataCenter(com.emc.storageos.api.mapper.functions.MapVcenterDataCenter) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList)

Example 19 with AsyncTask

use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.

the class ProtectionSystemService method discoverProtectionSystemsAll.

/**
 * Allows the user to manually discover all protection systems.
 *
 * @brief Discover all protection systems
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Path("/discover")
public TaskList discoverProtectionSystemsAll() {
    Iterator<URI> protectionIter = _dbClient.queryByType(ProtectionSystem.class, true).iterator();
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>();
    while (protectionIter.hasNext()) {
        URI protection = protectionIter.next();
        String taskId = UUID.randomUUID().toString();
        tasks.add(new AsyncTask(ProtectionSystem.class, protection, taskId));
    }
    ProtectionController controller = getController(RPController.class, ProtectionSystem._RP);
    return discoverProtectionSystems(tasks, controller);
}
Also used : AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) URI(java.net.URI) MapProtectionSystem(com.emc.storageos.api.mapper.functions.MapProtectionSystem) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) ProtectionController(com.emc.storageos.protectioncontroller.ProtectionController) 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 20 with AsyncTask

use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.

the class ProtectionSystemService method createProtectionSystem.

/**
 * Allow the user to manually create a protection system.
 *
 * @param param The protection system details.
 *
 * @brief Create protection system
 * @return An asynchronous task corresponding to the discovery job scheduled for the new Protection System.
 *
 * @throws BadRequestException When the system type is not valid or a
 *             protection system with the same native guid already exists.
 * @throws DatabaseException When an error occurs querying the database.
 * @throws ControllerException When an error occurs discovering the protection
 *             system.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep createProtectionSystem(ProtectionSystemRequestParam param) throws Exception {
    ProtectionSystem system = null;
    ProtectionSystem.Type systemType = ProtectionSystem.Type.valueOf(param.getSystemType());
    if (!systemType.equals(ProtectionSystem.Type.rp)) {
        throw APIException.badRequests.cannotRegisterSystemWithType(systemType.name());
    }
    system = new ProtectionSystem();
    system.setId(URIUtil.createId(ProtectionSystem.class));
    system.setSystemType(systemType.name());
    system.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
    system.setIpAddress(param.getIpAddress());
    system.setPortNumber(param.getPortNumber());
    system.setUsername(param.getUserName());
    system.setPassword(param.getPassword());
    system.setLabel(param.getLabel());
    system.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.CREATED.toString());
    _dbClient.createObject(system);
    auditOp(OperationTypeEnum.CREATE_PROTECTION_SYSTEM, true, null, param.getLabel(), systemType.name(), param.getIpAddress(), param.getPortNumber(), param.getUserName(), system.getId().toString());
    startProtectionSystem(system);
    ProtectionController controller = getController(RPController.class, ProtectionSystem._RP);
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
    String taskId = UUID.randomUUID().toString();
    tasks.add(new AsyncTask(ProtectionSystem.class, system.getId(), taskId));
    TaskList taskList = discoverProtectionSystems(tasks, controller);
    return taskList.getTaskList().listIterator().next();
}
Also used : TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) MapProtectionSystem(com.emc.storageos.api.mapper.functions.MapProtectionSystem) ProtectionSystem(com.emc.storageos.db.client.model.ProtectionSystem) ProtectionController(com.emc.storageos.protectioncontroller.ProtectionController) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

AsyncTask (com.emc.storageos.volumecontroller.AsyncTask)34 ArrayList (java.util.ArrayList)22 TaskList (com.emc.storageos.model.TaskList)17 Consumes (javax.ws.rs.Consumes)16 Produces (javax.ws.rs.Produces)16 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)15 DiscoveredObjectTaskScheduler (com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler)12 Operation (com.emc.storageos.db.client.model.Operation)11 ArrayAffinityAsyncTask (com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask)11 POST (javax.ws.rs.POST)11 Path (javax.ws.rs.Path)11 URI (java.net.URI)10 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)9 StorageProvider (com.emc.storageos.db.client.model.StorageProvider)8 BlockController (com.emc.storageos.volumecontroller.BlockController)8 Host (com.emc.storageos.db.client.model.Host)6 ImageServerController (com.emc.storageos.imageservercontroller.ImageServerController)5 MapProtectionSystem (com.emc.storageos.api.mapper.functions.MapProtectionSystem)4 ProtectionSystem (com.emc.storageos.db.client.model.ProtectionSystem)4 ProtectionController (com.emc.storageos.protectioncontroller.ProtectionController)4