Search in sources :

Example 71 with Operation

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);
}
Also used : ImageServerController(com.emc.storageos.imageservercontroller.ImageServerController) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 72 with Operation

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);
}
Also used : ImageServerController(com.emc.storageos.imageservercontroller.ImageServerController) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) StringSet(com.emc.storageos.db.client.model.StringSet) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 73 with Operation

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);
}
Also used : AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) Operation(com.emc.storageos.db.client.model.Operation)

Example 74 with Operation

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);
}
Also used : ComputeController(com.emc.storageos.computecontroller.ComputeController) Operation(com.emc.storageos.db.client.model.Operation) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) Path(javax.ws.rs.Path) ComputeSanBootImagePath(com.emc.storageos.db.client.model.ComputeSanBootImagePath) ComputeLanBootImagePath(com.emc.storageos.db.client.model.ComputeLanBootImagePath) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 75 with Operation

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);
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) BlockExportController(com.emc.storageos.volumecontroller.BlockExportController) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Map(java.util.Map) StringSetMap(com.emc.storageos.db.client.model.StringSetMap) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) StringMap(com.emc.storageos.db.client.model.StringMap) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

Operation (com.emc.storageos.db.client.model.Operation)272 URI (java.net.URI)114 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)105 Path (javax.ws.rs.Path)105 Produces (javax.ws.rs.Produces)103 Volume (com.emc.storageos.db.client.model.Volume)93 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)92 ArrayList (java.util.ArrayList)83 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)70 Consumes (javax.ws.rs.Consumes)70 NamedURI (com.emc.storageos.db.client.model.NamedURI)68 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)68 POST (javax.ws.rs.POST)67 TaskList (com.emc.storageos.model.TaskList)59 FileShare (com.emc.storageos.db.client.model.FileShare)56 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)49 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)40 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)36 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)35 ControllerException (com.emc.storageos.volumecontroller.ControllerException)35