use of com.emc.storageos.db.client.model.Operation 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.db.client.model.Operation 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);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class ComputeImageService method getReadyOp.
/*
* Returns task in ready state.
*/
private TaskResourceRep getReadyOp(ComputeImage ci, ResourceOperationTypeEnum opType) {
log.info("doImportImageDone");
String taskId = UUID.randomUUID().toString();
AsyncTask task = new AsyncTask(ComputeImage.class, ci.getId(), taskId);
Operation readyOp = new Operation();
readyOp.ready();
readyOp.setResourceType(opType);
_dbClient.createTaskOpStatus(ComputeImage.class, ci.getId(), task._opId, readyOp);
return TaskMapper.toTask(ci, task._opId, readyOp);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class ComputeSystemService method deleteComputeSystem.
/**
* Deletes a Compute System and the discovered information about it from
* ViPR
*
* @param id
* the URN of a ViPR Compute System to be deleted
* @brief Delete compute system
* @return TaskResourceRep (asynchronous call)
* @throws DatabaseException
*/
@POST
@Path("/{id}/deactivate")
@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 deleteComputeSystem(@PathParam("id") URI id) throws DatabaseException {
ComputeSystem cs = queryObject(ComputeSystem.class, id, true);
ArgValidator.checkEntity(cs, id, isIdEmbeddedInURL(id));
if (!RegistrationStatus.UNREGISTERED.toString().equals(cs.getRegistrationStatus())) {
throw APIException.badRequests.invalidParameterCannotDeactivateRegisteredComputeSystem(cs.getId());
}
List<String> provHosts = getProvisionedBlades(cs);
if (!provHosts.isEmpty()) {
throw APIException.badRequests.unableToDeactivateProvisionedComputeSystem(cs.getLabel(), org.springframework.util.StringUtils.collectionToCommaDelimitedString(provHosts));
}
ComputeController controller = getController(ComputeController.class, cs.getSystemType());
controller.clearDeviceSession(cs.getId());
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(ComputeSystem.class, cs.getId(), taskId, ResourceOperationTypeEnum.DELETE_COMPUTE_SYSTEM);
PurgeRunnable.executePurging(_dbClient, _dbPurger, _asynchJobService.getExecutorService(), cs, 0, /* _retry_attempts */
taskId, 60);
recordAndAudit(cs, OperationTypeEnum.DELETE_COMPUTE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN);
return toTask(cs, taskId, op);
}
use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.
the class ExportGroupService method deactivateExportGroup.
/**
* Deactivate block export. It will be deleted by the garbage collector on a
* subsequent iteration
* <p>
* This removes visibility of shared storage in the block export to servers through initiators in the block export.
* <p>
* If SAN Zones were created as a result of this Export Group (see Export Group Create), they will be removed if they are not in use by
* other Export Groups.
* <p>
*
* NOTE: This is an asynchronous operation.
*
* @param groupId Block export identifier
* @brief Delete block export
* @return Task resource representation
* @throws ControllerException
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep deactivateExportGroup(@PathParam("id") URI groupId) throws ControllerException {
String task = UUID.randomUUID().toString();
Operation op = null;
ExportGroup exportGroup = lookupExportGroup(groupId);
Map<URI, Map<URI, Integer>> storageMap = ExportUtils.getStorageToVolumeMap(exportGroup, true, _dbClient);
validateExportGroupNoPendingEvents(exportGroup);
// Validate that none of the volumes are mounted (datastores, etc)
if (exportGroup.getVolumes() != null) {
validateVolumesNotMounted(exportGroup, URIUtil.toURIList(exportGroup.getVolumes().keySet()));
}
// Don't allow deactivation if there is an operation in progress.
Set<URI> tenants = new HashSet<URI>();
tenants.add(exportGroup.getTenant().getURI());
Set<ExportGroup> dataObjects = new HashSet<ExportGroup>();
dataObjects.add(exportGroup);
checkForPendingTasks(tenants, dataObjects);
// Mark deletion in progress. This will cause future updates to fail.
exportGroup.addInternalFlags(DataObject.Flag.DELETION_IN_PROGRESS);
// Remove any associated ExportPathParam
if (exportGroup.getVolumes() != null && !exportGroup.getVolumes().isEmpty() && !exportGroup.getPathParameters().isEmpty()) {
removeBlockObjectsFromPathParamMap(URIUtil.uris(exportGroup.getVolumes().keySet()), exportGroup);
}
if (storageMap.isEmpty()) {
op = initTaskStatus(exportGroup, task, Operation.Status.ready, ResourceOperationTypeEnum.DELETE_EXPORT_GROUP);
_dbClient.markForDeletion(exportGroup);
} else {
op = initTaskStatus(exportGroup, task, Operation.Status.pending, ResourceOperationTypeEnum.DELETE_EXPORT_GROUP);
_dbClient.persistObject(exportGroup);
BlockExportController exportController = getExportController();
exportController.exportGroupDelete(exportGroup.getId(), task);
}
auditOp(OperationTypeEnum.DELETE_EXPORT_GROUP, true, AuditLogManager.AUDITOP_BEGIN, exportGroup.getLabel(), exportGroup.getId().toString(), exportGroup.getVirtualArray().toString(), exportGroup.getProject().toString());
return toTask(exportGroup, task, op);
}
Aggregations