Search in sources :

Example 21 with AsyncTask

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

the class HostService method createHostTasks.

private TaskList createHostTasks(Set<Host> hosts, URI cvpUri, URI varray) {
    TaskList tl = new TaskList();
    Set<AsyncTask> tasks = new HashSet<AsyncTask>();
    for (Host host : hosts) {
        String taskId = UUID.randomUUID().toString();
        AsyncTask task = new AsyncTask(Host.class, host.getId(), taskId);
        Operation op = new Operation();
        op.setResourceType(ResourceOperationTypeEnum.CREATE_HOST);
        _dbClient.createTaskOpStatus(Host.class, host.getId(), task._opId, op);
        tasks.add(task);
        tl.getTaskList().add(TaskMapper.toTask(host, task._opId, op));
        host.setProvisioningStatus(Host.ProvisioningJobStatus.IN_PROGRESS.toString());
        auditOp(OperationTypeEnum.CREATE_HOST, true, AuditLogManager.AUDITOP_BEGIN, host.auditParameters());
    }
    /*
         * Persist the IN_PROGRESS ProvisioningJobStatus
         */
    _dbClient.persistObject(hosts);
    /*
         * Dispatch the request to the controller
         */
    ComputeController computeController = getController(ComputeController.class, null);
    computeController.createHosts(varray, cvpUri, tasks.toArray(new AsyncTask[0]));
    return tl;
}
Also used : TaskList(com.emc.storageos.model.TaskList) ComputeController(com.emc.storageos.computecontroller.ComputeController) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) HashSet(java.util.HashSet)

Example 22 with AsyncTask

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

the class HostService method osInstall.

/**
 * Install operating system on the host.
 *
 * @param hostId
 *            host URI
 * @param param
 *            OS install data
 * @brief Install operating system on the host
 * @return TaskResourceRep (asynchronous call)
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/os-install")
public TaskResourceRep osInstall(@PathParam("id") URI hostId, OsInstallParam param) {
    // validate params
    ArgValidator.checkFieldUriType(hostId, Host.class, "id");
    ArgValidator.checkFieldNotNull(param.getComputeImage(), "compute_image");
    // get data
    ComputeImage img = queryObject(ComputeImage.class, param.getComputeImage(), true);
    ArgValidator.checkEntity(img, param.getComputeImage(), isIdEmbeddedInURL(param.getComputeImage()));
    if (!ComputeImageStatus.AVAILABLE.name().equals(img.getComputeImageStatus())) {
        throw APIException.badRequests.invalidParameterComputeImageIsNotAvailable(img.getId());
    }
    ArgValidator.checkFieldNotEmpty(param.getHostIp(), "host_ip");
    Host host = queryObject(Host.class, hostId, true);
    ArgValidator.checkEntity(host, hostId, isIdEmbeddedInURL(hostId));
    // COP-28718 Fixed by making sure that the host we are installing OS does not cause an IP conflict
    // by throwing appropriate exception.
    verifyHostForDuplicateIP(host, param);
    // only support os install on hosts with compute elements
    if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        throw APIException.badRequests.invalidParameterHostHasNoComputeElement();
    }
    if (!host.getType().equals(Host.HostType.No_OS.name()) && !param.getForceInstallation()) {
        throw APIException.badRequests.invalidParameterHostAlreadyHasOs(host.getType());
    }
    if (!StringUtils.isNotBlank(param.getRootPassword())) {
        throw APIException.badRequests.hostPasswordNotSet();
    } else {
        host.setPassword(param.getRootPassword());
        host.setUsername("root");
    }
    // check that CS has os install network
    ComputeElement ce = queryObject(ComputeElement.class, host.getComputeElement(), true);
    ArgValidator.checkEntity(ce, host.getComputeElement(), isIdEmbeddedInURL(host.getComputeElement()));
    if (ce.getUuid() == null) {
        throw APIException.badRequests.computeElementHasNoUuid();
    }
    ComputeSystem cs = queryObject(ComputeSystem.class, ce.getComputeSystem(), true);
    ArgValidator.checkEntity(cs, ce.getComputeSystem(), isIdEmbeddedInURL(ce.getComputeSystem()));
    verifyImagePresentOnImageServer(cs, img);
    if (!StringUtils.isNotBlank(cs.getOsInstallNetwork())) {
        throw APIException.badRequests.osInstallNetworkNotSet();
    }
    if (!cs.getVlans().contains(cs.getOsInstallNetwork())) {
        throw APIException.badRequests.osInstallNetworkNotValid(cs.getOsInstallNetwork());
    }
    // check that there is no os install in progress for this host
    URIQueryResultList jobUriList = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeImageJobsByHostConstraint(host.getId()), jobUriList);
    Iterator<URI> iterator = jobUriList.iterator();
    while (iterator.hasNext()) {
        ComputeImageJob existingJob = _dbClient.queryObject(ComputeImageJob.class, iterator.next());
        if (!existingJob.getInactive() && existingJob.getJobStatus().equals(ComputeImageJob.JobStatus.CREATED.name())) {
            throw APIException.badRequests.osInstallAlreadyInProgress();
        }
    }
    // openssl passwd -1 (MD5 encryption of password)
    String passwordHash = Md5Crypt.md5Crypt(host.getPassword().getBytes());
    // create session
    ComputeImageJob job = new ComputeImageJob();
    job.setId(URIUtil.createId(ComputeImageJob.class));
    job.setComputeImageId(img.getId());
    job.setHostId(host.getId());
    job.setPasswordHash(passwordHash);
    job.setHostName(param.getHostName());
    job.setHostIp(param.getHostIp());
    job.setNetmask(param.getNetmask());
    job.setGateway(param.getGateway());
    job.setNtpServer(param.getNtpServer());
    job.setDnsServers(param.getDnsServers());
    job.setManagementNetwork(param.getManagementNetwork());
    job.setPxeBootIdentifier(ImageServerUtils.uuidFromString(host.getUuid()).toString());
    job.setComputeImageServerId(cs.getComputeImageServer());
    // volume id is optional
    if (!NullColumnValueGetter.isNullURI(param.getVolume()) || !NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
        Volume vol = null;
        if (!NullColumnValueGetter.isNullURI(param.getVolume())) {
            vol = queryObject(Volume.class, param.getVolume(), true);
            host.setBootVolumeId(vol.getId());
        } else {
            vol = queryObject(Volume.class, host.getBootVolumeId(), true);
        }
        job.setVolumeId(vol.getId());
        StorageSystem st = queryObject(StorageSystem.class, vol.getStorageController(), true);
        // XtremIO uses some other ID type (e.g. 514f0c5dc9600016)
        if (st != null && DiscoveredDataObject.Type.xtremio.name().equals(st.getSystemType())) {
            _log.info("xtremio volume id {}", vol.getNativeId());
            job.setBootDevice(vol.getNativeId());
        } else {
            _log.info("volume id {}", vol.getWWN());
            job.setBootDevice(ImageServerUtils.uuidFromString(vol.getWWN()).toString());
        }
    }
    host.setProvisioningStatus(ProvisioningJobStatus.IN_PROGRESS.toString());
    _dbClient.persistObject(host);
    _dbClient.createObject(job);
    // create task
    String taskId = UUID.randomUUID().toString();
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM);
    _dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, op);
    ImageServerController controller = getController(ImageServerController.class, null);
    AsyncTask task = new AsyncTask(Host.class, host.getId(), taskId);
    try {
        controller.installOperatingSystem(task, job.getId());
    } catch (InternalException e) {
        _log.error("Did not install OS due to controller error", e);
        job.setJobStatus(ComputeImageJob.JobStatus.FAILED.name());
        _dbClient.persistObject(job);
        _dbClient.error(Host.class, host.getId(), taskId, e);
    }
    return toTask(host, taskId, op);
}
Also used : AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) ComputeImage(com.emc.storageos.db.client.model.ComputeImage) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ImageServerController(com.emc.storageos.imageservercontroller.ImageServerController) UnManagedVolume(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume) Volume(com.emc.storageos.db.client.model.Volume) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 23 with AsyncTask

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

the class HostService method doDiscoverHost.

/**
 * Host Discovery
 *
 * @param host {@link Host} The Host to be discovered.
 * @param taskId {@link String} taskId for the host discovery. as new taskId is generated if null passed.
 * @param updateTaskStatus if true, mark the task status as completed for non-discovered host
 * @return the task used to track the discovery job
 */
protected TaskResourceRep doDiscoverHost(URI hostId, String taskId, boolean updateTaskStatus) {
    Host host = queryObject(Host.class, hostId, true);
    if (taskId == null) {
        taskId = UUID.randomUUID().toString();
    }
    if (host.getDiscoverable() != null && !host.getDiscoverable()) {
        host.setDiscoveryStatus(DataCollectionJobStatus.COMPLETE.name());
        _dbClient.updateObject(host);
    }
    if ((host.getDiscoverable() == null || host.getDiscoverable())) {
        ComputeSystemController controller = getController(ComputeSystemController.class, "host");
        DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new DiscoverJobExec(controller));
        ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
        tasks.add(new AsyncTask(Host.class, host.getId(), taskId));
        TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
        return taskList.getTaskList().iterator().next();
    } else {
        // if not discoverable, manually create a ready task
        Operation op = new Operation();
        op.setResourceType(ResourceOperationTypeEnum.DISCOVER_HOST);
        if (updateTaskStatus) {
            op.ready("Host is not discoverable");
        } else {
            op.pending();
        }
        _dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, op);
        return toTask(host, taskId, op);
    }
}
Also used : TaskList(com.emc.storageos.model.TaskList) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) Operation(com.emc.storageos.db.client.model.Operation)

Example 24 with AsyncTask

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

the class HostService method createHostArrayAffinityTasks.

/**
 * Create array affinity tasks for hosts.
 *
 * @param hostIds
 *            the hosts whose preferred systems need to be discovered
 */
public TaskList createHostArrayAffinityTasks(List<URI> hostIds) {
    TaskList taskList = new TaskList();
    String taskId = UUID.randomUUID().toString();
    String jobType = "";
    Map<URI, List<URI>> providerToSystemsMap = new HashMap<URI, List<URI>>();
    Map<URI, String> providerToSystemTypeMap = new HashMap<URI, String>();
    List<URI> sysURIs = _dbClient.queryByType(StorageSystem.class, true);
    Iterator<StorageSystem> storageSystems = _dbClient.queryIterativeObjects(StorageSystem.class, sysURIs);
    while (storageSystems.hasNext()) {
        StorageSystem systemObj = storageSystems.next();
        if (systemObj == null) {
            _log.warn("StorageSystem is no longer in the DB. It could have been deleted or decommissioned");
            continue;
        }
        if (systemObj.deviceIsType(Type.vmax) || systemObj.deviceIsType(Type.vnxblock) || systemObj.deviceIsType(Type.xtremio)) {
            if (systemObj.getActiveProviderURI() == null || NullColumnValueGetter.getNullURI().equals(systemObj.getActiveProviderURI())) {
                _log.info("Skipping {} Job : StorageSystem {} does not have an active provider", jobType, systemObj.getLabel());
                continue;
            }
            StorageProvider provider = _dbClient.queryObject(StorageProvider.class, systemObj.getActiveProviderURI());
            if (provider == null || provider.getInactive()) {
                _log.info("Skipping {} Job : StorageSystem {} does not have a valid active provider", jobType, systemObj.getLabel());
                continue;
            }
            List<URI> systemIds = providerToSystemsMap.get(provider.getId());
            if (systemIds == null) {
                systemIds = new ArrayList<URI>();
                providerToSystemsMap.put(provider.getId(), systemIds);
                providerToSystemTypeMap.put(provider.getId(), systemObj.getSystemType());
            }
            systemIds.add(systemObj.getId());
        } else if (systemObj.deviceIsType(Type.unity)) {
            List<URI> systemIds = new ArrayList<URI>();
            systemIds.add(systemObj.getId());
            providerToSystemsMap.put(systemObj.getId(), systemIds);
            providerToSystemTypeMap.put(systemObj.getId(), systemObj.getSystemType());
        } else {
            _log.info("Skip unsupported system {}, system type {}", systemObj.getLabel(), systemObj.getSystemType());
            continue;
        }
    }
    for (Map.Entry<URI, List<URI>> entry : providerToSystemsMap.entrySet()) {
        List<URI> systemIds = entry.getValue();
        BlockController controller = getController(BlockController.class, providerToSystemTypeMap.get(entry.getKey()));
        DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new StorageSystemService.ArrayAffinityJobExec(controller));
        ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>();
        tasks.add(new ArrayAffinityAsyncTask(StorageSystem.class, systemIds, hostIds, taskId));
        taskList.getTaskList().addAll(scheduler.scheduleAsyncTasks(tasks).getTaskList());
    }
    return taskList;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) BlockController(com.emc.storageos.volumecontroller.BlockController) TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) ArrayList(java.util.ArrayList) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) UnManagedExportMaskList(com.emc.storageos.model.block.UnManagedExportMaskList) UnManagedVolumeList(com.emc.storageos.model.block.UnManagedVolumeList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) InitiatorList(com.emc.storageos.model.host.InitiatorList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) HostList(com.emc.storageos.model.host.HostList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) LinkedList(java.util.LinkedList) IpInterfaceList(com.emc.storageos.model.host.IpInterfaceList) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 25 with AsyncTask

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

the class NetworkSystemService method doDiscoverNetworkSystem.

/**
 * Common code for submitting a request for discovery. The request may not be performed
 * by the discovery framework if a discovery was recently performed or is ongoing for
 * the network system.
 *
 * @param device the network system to be discovered to re-discovered.
 *            provided, a new taskId is generated.
 * @return the task used to track the discovery job
 */
private TaskResourceRep doDiscoverNetworkSystem(NetworkSystem device) {
    NetworkController controller = getNetworkController(device.getSystemType());
    DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new NetworkJobExec(controller));
    String taskId = UUID.randomUUID().toString();
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
    tasks.add(new AsyncTask(NetworkSystem.class, device.getId(), taskId));
    TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
    return taskList.getTaskList().iterator().next();
}
Also used : TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) NetworkController(com.emc.storageos.networkcontroller.NetworkController)

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