Search in sources :

Example 31 with AsyncTask

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

the class ComputeImageService method doImportImage.

/*
     * Schedules the import task.
     */
private TaskResourceRep doImportImage(ComputeImage ci) {
    log.info("doImportImage");
    ImageServerController controller = getController(ImageServerController.class, null);
    AsyncTask task = new AsyncTask(ComputeImage.class, ci.getId(), UUID.randomUUID().toString());
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.IMPORT_IMAGE);
    _dbClient.createTaskOpStatus(ComputeImage.class, ci.getId(), task._opId, op);
    controller.importImageToServers(task);
    return TaskMapper.toTask(ci, task._opId, op);
}
Also used : ImageServerController(com.emc.storageos.imageservercontroller.ImageServerController) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) Operation(com.emc.storageos.db.client.model.Operation)

Example 32 with AsyncTask

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

the class ComputeSystemService method doDiscoverComputeSystem.

private TaskResourceRep doDiscoverComputeSystem(ComputeSystem cs) {
    ComputeController controller = getController(ComputeController.class, cs.getSystemType());
    DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new ComputeSystemJobExec(controller));
    String taskId = UUID.randomUUID().toString();
    ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
    tasks.add(new AsyncTask(ComputeSystem.class, cs.getId(), taskId));
    TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
    return taskList.getTaskList().iterator().next();
}
Also used : ComputeController(com.emc.storageos.computecontroller.ComputeController) TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

Example 33 with AsyncTask

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

the class BlockDeviceController method addStorageSystem.

/**
 * {@inheritDoc}
 *
 * @throws WorkflowException
 */
@Override
public void addStorageSystem(URI storage, URI[] providers, boolean activeProvider, String opId) throws ControllerException {
    if (providers == null) {
        return;
    }
    String allProviders = Joiner.on("\t").join(providers);
    DiscoverTaskCompleter completer = new DiscoverTaskCompleter(StorageSystem.class, storage, opId, ControllerServiceImpl.DISCOVERY);
    StringBuilder failedProviders = new StringBuilder();
    boolean exceptionIntercepted = false;
    boolean needDiscovery = false;
    boolean acquiredLock = false;
    try {
        acquiredLock = ControllerServiceImpl.Lock.SCAN_COLLECTION_LOCK.acquire(SCAN_LOCK_TIMEOUT);
    } catch (Exception ex) {
        _log.error("Exception while acquiring a lock ", ex);
        acquiredLock = false;
    }
    if (acquiredLock) {
        try {
            StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storage);
            for (int ii = 0; ii < providers.length; ii++) {
                try {
                    StorageProvider providerSMIS = _dbClient.queryObject(StorageProvider.class, providers[ii]);
                    if (providerSMIS == null) {
                        throw DeviceControllerException.exceptions.entityNullOrEmpty(null);
                    }
                    if (providerSMIS.getInactive()) {
                        throw DeviceControllerException.exceptions.entityInactive(providerSMIS.getId());
                    }
                    boolean found = scanProvider(providerSMIS, storageSystem, activeProvider && ii == 0, opId);
                    if (!found) {
                        if (storageSystem.getSystemType().equals(Type.vnxblock.toString()) && StringUtils.isNotBlank(storageSystem.getIpAddress())) {
                            String system = addStorageToSMIS(storageSystem, providerSMIS);
                            if (!system.equalsIgnoreCase(storageSystem.getNativeGuid())) {
                                throw DeviceControllerException.exceptions.addStorageSystemFailed(storageSystem.getNativeGuid(), providerSMIS.getId().toString());
                            }
                            providerSMIS.addStorageSystem(_dbClient, storageSystem, activeProvider && ii == 0);
                            if (activeProvider && ii == 0) {
                                providerSMIS.removeDecommissionedSystem(_dbClient, storageSystem.getNativeGuid());
                            }
                            storageSystem.setReachableStatus(true);
                            _dbClient.updateObject(storageSystem);
                        } else {
                            throw DeviceControllerException.exceptions.scanFailedToFindSystem(providerSMIS.getId().toString(), storageSystem.getNativeGuid());
                        }
                    } else {
                        storageSystem.setReachableStatus(true);
                        _dbClient.updateObject(storageSystem);
                    }
                    if (providers.length > 1) {
                        completer.statusPending(_dbClient, "Adding storage to SMIS Providers : completed " + (ii + 1) + " providers out of " + providers.length);
                    }
                } catch (Exception ex) {
                    // any type of exceptions for a particular provider
                    _log.error("Failed to add storage from the following provider: " + providers[ii], ex);
                    failedProviders.append(providers[ii]).append(' ');
                    exceptionIntercepted = true;
                }
            }
            if (activeProvider) {
                updateActiveProvider(storageSystem);
                _dbClient.updateObject(storageSystem);
            }
            DecommissionedResource.removeDecommissionedFlag(_dbClient, storageSystem.getNativeGuid(), StorageSystem.class);
            if (exceptionIntercepted) {
                String opName = ResourceOperationTypeEnum.ADD_STORAGE_SYSTEM.getName();
                ServiceError serviceError = DeviceControllerException.errors.jobFailedOp(opName);
                completer.error(_dbClient, serviceError);
            } else {
                recordBourneStorageEvent(RecordableEventManager.EventType.StorageDeviceAdded, storageSystem, "Added SMI-S Storage");
                _log.info("Storage is added to the SMI-S providers: ");
                if (activeProvider) {
                    needDiscovery = true;
                    storageSystem.setLastDiscoveryRunTime(new Long(0));
                    completer.statusPending(_dbClient, "Storage is added to the specified SMI-S providers : " + allProviders);
                    // We need to set timer back to 0 to indicate that it is a new system ready for discovery.
                    _dbClient.updateObject(storageSystem);
                } else {
                    completer.ready(_dbClient);
                }
            }
        } catch (Exception outEx) {
            exceptionIntercepted = true;
            _log.error("Failed to add SMIS providers", outEx);
            ServiceError serviceError = DeviceControllerException.errors.jobFailed(outEx);
            completer.error(_dbClient, serviceError);
        } finally {
            try {
                ControllerServiceImpl.Lock.SCAN_COLLECTION_LOCK.release();
            } catch (Exception ex) {
                _log.error("Failed to release SCAN lock; scanning might become disabled", ex);
            }
            if (needDiscovery && !exceptionIntercepted) {
                try {
                    ControllerServiceImpl.scheduleDiscoverJobs(new AsyncTask[] { new AsyncTask(StorageSystem.class, storage, opId) }, Lock.DISCOVER_COLLECTION_LOCK, ControllerServiceImpl.DISCOVERY);
                } catch (Exception ex) {
                    _log.error("Failed to start discovery : " + storage, ex);
                }
            }
        }
    } else {
        String opName = ResourceOperationTypeEnum.ADD_STORAGE_SYSTEM.getName();
        ServiceError serviceError = DeviceControllerException.errors.jobFailedOp(opName);
        completer.error(_dbClient, serviceError);
        _log.debug("Not able to Acquire Scanning lock-->{}", Thread.currentThread().getId());
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) DiscoverTaskCompleter(com.emc.storageos.volumecontroller.impl.plugins.discovery.smis.DiscoverTaskCompleter) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) BaseCollectionException(com.emc.storageos.plugins.BaseCollectionException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) DataBindingException(javax.xml.bind.DataBindingException) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 34 with AsyncTask

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

the class ControllerWorkflowCleanupHandler method rediscoverDevices.

private void rediscoverDevices() {
    List<URI> storageSystemIds = dbClient.queryByType(StorageSystem.class, true);
    Iterator<StorageSystem> storageSystems = dbClient.queryIterativeObjects(StorageSystem.class, storageSystemIds);
    String taskId = UUID.randomUUID().toString();
    while (storageSystems.hasNext()) {
        StorageSystem storageSystem = storageSystems.next();
        URI storageSystemId = storageSystem.getId();
        try {
            log.info("Start discovery {}", storageSystemId);
            ControllerServiceImpl.scheduleDiscoverJobs(new AsyncTask[] { new AsyncTask(StorageSystem.class, storageSystemId, taskId) }, Lock.DISCOVER_COLLECTION_LOCK, ControllerServiceImpl.DISCOVERY);
        } catch (Exception ex) {
            log.error("Failed to start discovery : " + storageSystem.getId(), ex);
        }
    }
}
Also used : AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) URI(java.net.URI) WorkflowException(com.emc.storageos.workflow.WorkflowException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

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