use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.
the class ProtectionSystemService method updateProtectionSystem.
/**
* Allows the user to update credentials for a manually created protection systems.
*
* @param id the URN of a ViPR protection system
* @param param The protection system details to update.
*
* @brief Update protection system credentials
* @return A ProtectionSystemRestRep reference specifying the protection system
* data.
*
* @throws InternalException When an error occurs discovering the protection
* system.
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep updateProtectionSystem(@PathParam("id") URI id, ProtectionSystemUpdateRequestParam param) throws InternalException {
ProtectionSystem system = _dbClient.queryObject(ProtectionSystem.class, id);
ArgValidator.checkEntityNotNull(system, id, isIdEmbeddedInURL(id));
// and Compatibility Status.
if (!system.getIpAddress().equals(param.getIpAddress())) {
system.setMajorVersion("");
system.setCompatibilityStatus(DiscoveredDataObject.CompatibilityStatus.UNKNOWN.toString());
}
// Update the IP, port, username, and password with the new incoming values
system.setIpAddress(param.getIpAddress());
system.setPortNumber(param.getPortNumber());
system.setUsername(param.getUserName());
system.setPassword(param.getPassword());
// Must force a discover during an update.
system.setLastDiscoveryRunTime(new Long(0));
// Make necessary changes to the protection system's cluster->varray assignments
modifyClusterVarrayAssignments(system, param.getVarrayChanges());
// Persist the object changes
_dbClient.persistObject(system);
auditOp(OperationTypeEnum.UPDATE_PROTECTION_SYSTEM, true, null, system.getId().toString(), param.getIpAddress(), param.getPortNumber(), param.getUserName());
startProtectionSystem(system);
// execute discovery
ProtectionController controller = getController(RPController.class, system.getSystemType());
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().iterator().next();
}
use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.
the class SMISProviderService method registerSMISProvider.
/**
* Register an SMI-S provider to create storage systems of type
* vnxblock and vmax. This call is not used to create SMI-S
* providers for vnxfile.
* <p>
* The method is deprecated. Use /vdc/storage-providers instead.
*
* @param param SMIS-Provider parameters
* @brief Register SMI-S provider
* @return Newly registered SMIS-Provider details
* @throws ControllerException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
public TaskResourceRep registerSMISProvider(SMISProviderCreateParam param) throws ControllerException {
String providerKey = param.getIpAddress() + "-" + param.getPortNumber();
List<StorageProvider> providers = CustomQueryUtility.getActiveStorageProvidersByProviderId(_dbClient, providerKey);
if (providers != null && !providers.isEmpty()) {
throw APIException.badRequests.invalidParameterSMISProviderAlreadyRegistered(providerKey);
}
ArgValidator.checkFieldNotEmpty(param.getName(), "name");
checkForDuplicateName(param.getName(), StorageProvider.class);
ArgValidator.checkFieldNotEmpty(param.getIpAddress(), "ip_address");
ArgValidator.checkFieldNotNull(param.getPortNumber(), "port_number");
ArgValidator.checkFieldNotEmpty(param.getUserName(), "user_name");
ArgValidator.checkFieldNotEmpty(param.getPassword(), "password");
ArgValidator.checkFieldNotNull(param.getUseSSL(), "use_ssl");
ArgValidator.checkFieldRange(param.getPortNumber(), 1, 65535, "port_number");
StorageProvider smisProvider = new StorageProvider();
smisProvider.setInterfaceType(StorageProvider.InterfaceType.smis.name());
smisProvider.setId(URIUtil.createId(StorageProvider.class));
smisProvider.setLabel(param.getName());
smisProvider.setIPAddress(param.getIpAddress());
smisProvider.setPortNumber(param.getPortNumber());
smisProvider.setUserName(param.getUserName());
smisProvider.setPassword(param.getPassword());
smisProvider.setUseSSL(param.getUseSSL());
smisProvider.setRegistrationStatus(RegistrationStatus.REGISTERED.toString());
_dbClient.createObject(smisProvider);
auditOp(OperationTypeEnum.REGISTER_SMISPROVIDER, true, null, smisProvider.getLabel(), smisProvider.getId().toString(), smisProvider.getIPAddress(), smisProvider.getPortNumber(), smisProvider.getUserName());
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
String taskId = UUID.randomUUID().toString();
tasks.add(new AsyncTask(StorageProvider.class, smisProvider.getId(), taskId));
// @TODO revisit this to avoid hard coding.
BlockController controller = getController(BlockController.class, "vnxblock");
/**
* Creates MonitoringJob token for vnxblock/vmax device on zooKeeper queue
*/
controller.startMonitoring(new AsyncTask(StorageProvider.class, smisProvider.getId(), taskId), StorageSystem.Type.vnxblock);
DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new ScanJobExec(controller));
TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
return taskList.getTaskList().listIterator().next();
}
use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.
the class SMISProviderService method scanSMISProviders.
/**
* Scan all SMI-S providers.
* <p>
* The method is deprecated. Use /vdc/storage-providers/scan instead.
*
* @brief Scan SMI-S providers
* @return TasList of all created asynchronous tasks
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN })
@Path("/scan")
public TaskList scanSMISProviders() {
TaskList taskList = new TaskList();
List<StorageProvider> providerList = CustomQueryUtility.getActiveStorageProvidersByInterfaceType(_dbClient, StorageProvider.InterfaceType.smis.name());
if (providerList == null || providerList.isEmpty()) {
return taskList;
}
BlockController controller = getController(BlockController.class, "vnxblock");
DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new ScanJobExec(controller));
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>();
for (StorageProvider smisProvider : providerList) {
String taskId = UUID.randomUUID().toString();
tasks.add(new AsyncTask(StorageProvider.class, smisProvider.getId(), taskId));
}
taskList = scheduler.scheduleAsyncTasks(tasks);
return taskList;
}
use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.
the class ComputeImageServerService method createComputeImageServer.
/**
* Create the Compute image server
*
* @param createParams
* {@link ComputeImageServerCreate} containing the details
*
* @brief Define a new image server, including TFTP info
* @return {@link TaskResourceRep} instance
*/
@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 createComputeImageServer(ComputeImageServerCreate createParams) {
log.info("Create computeImageServer");
String imageServerName = createParams.getName();
String imageServerAddress = createParams.getImageServerIp();
ArgValidator.checkFieldNotEmpty(imageServerName, "imageServerName");
ArgValidator.checkIpIsNotNumeric(imageServerAddress, IMAGESERVER_IP);
checkDuplicateImageServer(null, imageServerAddress, imageServerName);
String bootDir = createParams.getTftpBootDir();
String osInstallAddress = createParams.getImageServerSecondIp();
String username = createParams.getImageServerUser();
String password = createParams.getImageServerPassword();
Integer installTimeout = createParams.getOsInstallTimeout();
Integer sshTimeout = createParams.getSshTimeout();
Integer imageImportTimeout = createParams.getImageImportTimeout();
ArgValidator.checkFieldNotEmpty(bootDir, TFTPBOOTDIR);
ArgValidator.checkIpIsNotNumeric(osInstallAddress, IMAGESERVER_SECONDARY_IP);
ArgValidator.checkFieldNotEmpty(username, IMAGESERVER_USER);
ArgValidator.checkFieldNotEmpty(password, IMAGESERVER_PASSWORD);
ArgValidator.checkFieldNotNull(installTimeout, OS_INSTALL_TIMEOUT_MS);
ArgValidator.checkFieldRange(installTimeout, 0, 2147483, "seconds", "osInstallTimeout");
ArgValidator.checkFieldNotNull(sshTimeout, OS_INSTALL_TIMEOUT_MS);
ArgValidator.checkFieldRange(sshTimeout, 0, 2147483, "seconds", "sshTimeout");
ArgValidator.checkFieldNotNull(imageImportTimeout, OS_INSTALL_TIMEOUT_MS);
ArgValidator.checkFieldRange(installTimeout, 0, 2147483, "seconds", "imageImportTimeout");
ComputeImageServer imageServer = new ComputeImageServer();
imageServer.setId(URIUtil.createId(ComputeImageServer.class));
imageServer.setLabel(imageServerName);
imageServer.setImageServerIp(imageServerAddress);
imageServer.setTftpBootDir(bootDir);
imageServer.setImageServerUser(username);
imageServer.setImageServerPassword(password);
imageServer.setOsInstallTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(installTimeout)).intValue());
imageServer.setImageServerSecondIp(osInstallAddress);
imageServer.setImageDir(_coordinator.getPropertyInfo().getProperty(IMAGE_SERVER_IMAGEDIR));
imageServer.setSshTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(sshTimeout)).intValue());
imageServer.setImageImportTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(imageImportTimeout)).intValue());
auditOp(OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES, true, null, imageServer.getId().toString(), imageServer.getImageServerIp());
_dbClient.createObject(imageServer);
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
String taskId = UUID.randomUUID().toString();
AsyncTask task = new AsyncTask(ComputeImageServer.class, imageServer.getId(), taskId);
tasks.add(task);
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_VERIFY_COMPUTE_IMAGE_SERVER);
_dbClient.createTaskOpStatus(ComputeImageServer.class, imageServer.getId(), taskId, op);
ImageServerController controller = getController(ImageServerController.class, null);
controller.verifyImageServerAndImportExistingImages(task, op.getName());
return toTask(imageServer, taskId, op);
}
use of com.emc.storageos.volumecontroller.AsyncTask in project coprhd-controller by CoprHD.
the class ComputeImageServerService method updateComputeImageServer.
/**
* Update the Compute image server details
*
* @param id
* the URN of a ViPR compute image server
*
* @brief Change an image server, including TFTP info
* @return Updated compute image server information.
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public ComputeImageServerRestRep updateComputeImageServer(@PathParam("id") URI id, ComputeImageServerUpdate param) {
log.info("Update computeImageServer id {} ", id);
ComputeImageServer imageServer = _dbClient.queryObject(ComputeImageServer.class, id);
if (null == imageServer || imageServer.getInactive()) {
throw APIException.notFound.unableToFindEntityInURL(id);
} else {
StringSet availImages = imageServer.getComputeImages();
// make sure there are no active jobs associated with this imageserver
checkActiveJobsForImageServer(id);
String imageServerName = param.getName();
String imageServerAddress = param.getImageServerIp();
String bootDir = param.getTftpBootDir();
String osInstallAddress = param.getImageServerSecondIp();
String username = param.getImageServerUser();
String password = param.getImageServerPassword();
Integer installTimeout = param.getOsInstallTimeout();
Integer sshTimeout = param.getSshTimeout();
Integer imageImportTimeout = param.getImageImportTimeout();
if (StringUtils.isNotBlank(imageServerName) && !imageServerName.equalsIgnoreCase(imageServer.getLabel())) {
checkDuplicateLabel(ComputeImageServer.class, imageServerName);
imageServer.setLabel(param.getName());
}
if (StringUtils.isNotBlank(imageServerAddress) && !imageServerAddress.equalsIgnoreCase(imageServer.getImageServerIp())) {
checkDuplicateImageServer(id, imageServerAddress, null);
disassociateComputeImages(imageServer);
imageServer.setImageServerIp(imageServerAddress);
}
if (StringUtils.isNotBlank(osInstallAddress)) {
imageServer.setImageServerSecondIp(osInstallAddress);
}
if (StringUtils.isNotBlank(username)) {
imageServer.setImageServerUser(username);
}
if (null != installTimeout) {
ArgValidator.checkFieldRange(installTimeout, 0, 2147483, "seconds", "osInstallTimeout");
imageServer.setOsInstallTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(installTimeout)).intValue());
}
if (null != sshTimeout) {
ArgValidator.checkFieldRange(sshTimeout, 0, 2147483, "seconds", "sshTimeout");
imageServer.setSshTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(sshTimeout)).intValue());
}
if (null != imageImportTimeout) {
ArgValidator.checkFieldRange(imageImportTimeout, 0, 2147483, "seconds", "imageImportTimeout");
imageServer.setImageImportTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(imageImportTimeout)).intValue());
}
if (StringUtils.isNotBlank(bootDir)) {
if (!CollectionUtils.isEmpty(availImages) && !imageServer.getTftpBootDir().equals(bootDir)) {
log.info("Cannot update TFTPBOOT directory, while " + "an image server has associated successful import images.");
throw APIException.badRequests.cannotUpdateTFTPBOOTDirectory();
} else {
imageServer.setTftpBootDir(bootDir);
}
}
if (StringUtils.isNotBlank(password)) {
imageServer.setImageServerPassword(password);
}
auditOp(OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES, true, null, imageServer.getId().toString(), imageServer.getImageServerIp());
_dbClient.updateObject(imageServer);
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
String taskId = UUID.randomUUID().toString();
AsyncTask task = new AsyncTask(ComputeImageServer.class, imageServer.getId(), taskId);
tasks.add(task);
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UPDATE_VERIFY_COMPUTE_IMAGE_SERVER);
_dbClient.createTaskOpStatus(ComputeImageServer.class, imageServer.getId(), taskId, op);
ImageServerController controller = getController(ImageServerController.class, null);
controller.verifyImageServerAndImportExistingImages(task, op.getName());
}
return map(_dbClient, imageServer);
}
Aggregations