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);
}
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();
}
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());
}
}
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);
}
}
}
Aggregations