Search in sources :

Example 41 with Operation

use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.

the class HostService method updateBootVolume.

/**
 * Updates the hosts boot volume Id
 *
 * @param id the URN of host
 * @param hostUpdateParam
 * @brief Update the host boot volume
 * @return the task.
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/update-boot-volume")
public TaskResourceRep updateBootVolume(@PathParam("id") URI id, HostUpdateParam param) {
    Host host = queryObject(Host.class, id, true);
    boolean hasPendingTasks = hostHasPendingTasks(id);
    boolean updateSanBootTargets = param.getUpdateSanBootTargets();
    if (hasPendingTasks) {
        throw APIException.badRequests.cannotUpdateHost("another operation is in progress for this host");
    }
    auditOp(OperationTypeEnum.UPDATE_HOST_BOOT_VOLUME, true, null, host.auditParameters());
    String taskId = UUID.randomUUID().toString();
    ComputeSystemController controller = getController(ComputeSystemController.class, null);
    Operation op = _dbClient.createTaskOpStatus(Host.class, id, taskId, ResourceOperationTypeEnum.UPDATE_HOST_BOOT_VOLUME);
    // The volume being set as the boot volume should be exported to the host and should not be exported to any other initiators.
    // The controller call invoked below validates that before setting the volume as the boot volume.
    controller.setHostBootVolume(host.getId(), param.getBootVolume(), updateSanBootTargets, taskId);
    return toTask(host, taskId, op);
}
Also used : ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 42 with Operation

use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.

the class HostService method createInitiator.

/**
 * Creates a new initiator for a host.
 *
 * @param id
 *            the URN of a ViPR Host
 * @param createParam
 *            the details of the initiator
 * @brief Create host initiator
 * @return the details of the host initiator when creation
 *         is successfully.
 * @throws DatabaseException
 *             when a database error occurs.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
@Path("/{id}/initiators")
public TaskResourceRep createInitiator(@PathParam("id") URI id, InitiatorCreateParam createParam) throws DatabaseException {
    Host host = queryObject(Host.class, id, true);
    Cluster cluster = null;
    validateInitiatorData(createParam, null);
    // create and populate the initiator
    Initiator initiator = new Initiator();
    initiator.setHost(id);
    initiator.setHostName(host.getHostName());
    if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
        cluster = queryObject(Cluster.class, host.getCluster(), false);
        initiator.setClusterName(cluster.getLabel());
    }
    initiator.setId(URIUtil.createId(Initiator.class));
    populateInitiator(initiator, createParam);
    _dbClient.createObject(initiator);
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(Initiator.class, initiator.getId(), taskId, ResourceOperationTypeEnum.ADD_HOST_INITIATOR);
    // if host in use. update export with new initiator
    if (ComputeSystemHelper.isHostInUse(_dbClient, host.getId())) {
        ComputeSystemController controller = getController(ComputeSystemController.class, null);
        controller.addInitiatorsToExport(initiator.getHost(), Arrays.asList(initiator.getId()), taskId);
    } else {
        // No updates were necessary, so we can close out the task.
        _dbClient.ready(Initiator.class, initiator.getId(), taskId);
    }
    auditOp(OperationTypeEnum.CREATE_HOST_INITIATOR, true, null, initiator.auditParameters());
    return toTask(initiator, taskId, op);
}
Also used : Initiator(com.emc.storageos.db.client.model.Initiator) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 43 with Operation

use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.

the class AbstractBlockServiceApiImpl method prepareSnapshots.

/**
 * Prepares the snapshots for a snapshot request.
 *
 * @param volumes
 *            The volumes for which snapshots are to be created.
 * @param snapshotType
 *            The snapshot technology type.
 * @param snapshotName
 *            The snapshot name.
 * @param snapshotURIs
 *            [OUT] The URIs for the prepared snapshots.
 * @param taskId
 *            The unique task identifier
 *
 * @return The list of snapshots
 */
@Override
public List<BlockSnapshot> prepareSnapshots(List<Volume> volumes, String snapshotType, String snapshotName, List<URI> snapshotURIs, String taskId) {
    List<BlockSnapshot> snapshots = new ArrayList<BlockSnapshot>();
    int count = 1;
    for (Volume volume : volumes) {
        // Attempt to create distinct labels here when creating >1 volumes (ScaleIO requirement)
        String rgName = volume.getReplicationGroupInstance();
        VolumeGroup application = volume.getApplication(_dbClient);
        if (volume.isVPlexVolume(_dbClient)) {
            Volume backendVol = VPlexUtil.getVPLEXBackendVolume(volumes.get(0), true, _dbClient);
            if (backendVol != null && !backendVol.getInactive()) {
                rgName = backendVol.getReplicationGroupInstance();
            }
        }
        String label = snapshotName;
        if (NullColumnValueGetter.isNotNullValue(rgName) && application != null) {
            // There can be multiple RGs in a CG, in such cases generate unique name
            if (volumes.size() > 1) {
                label = String.format("%s-%s-%s", snapshotName, rgName, count++);
            } else {
                label = String.format("%s-%s", snapshotName, rgName);
            }
        } else if (volumes.size() > 1) {
            label = String.format("%s-%s", snapshotName, count++);
        }
        BlockSnapshot snapshot = prepareSnapshotFromVolume(volume, snapshotName, label);
        snapshot.setTechnologyType(snapshotType);
        snapshot.setOpStatus(new OpStatusMap());
        Operation op = new Operation();
        op.setResourceType(ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT);
        snapshot.getOpStatus().createTaskStatus(taskId, op);
        snapshotURIs.add(snapshot.getId());
        snapshots.add(snapshot);
    }
    _dbClient.createObject(snapshots);
    return snapshots;
}
Also used : Volume(com.emc.storageos.db.client.model.Volume) VolumeGroup(com.emc.storageos.db.client.model.VolumeGroup) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) ArrayList(java.util.ArrayList) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Operation(com.emc.storageos.db.client.model.Operation) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint)

Example 44 with Operation

use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.

the class AbstractBlockServiceApiImpl method deleteVolumes.

/**
 * {@inheritDoc}
 *
 * @throws InternalException
 */
@Override
public void deleteVolumes(URI systemURI, List<URI> volumeURIs, String deletionType, String task) throws InternalException {
    // Get volume descriptor for all volumes to be deleted.
    List<VolumeDescriptor> volumeDescriptors = getDescriptorsForVolumesToBeDeleted(systemURI, volumeURIs, deletionType);
    // the controller and delete the volumes.
    if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deletionType)) {
        // Do any cleanup necessary for the ViPR only delete.
        cleanupForViPROnlyDelete(volumeDescriptors);
        // Mark them inactive. Note that some of the volumes may be mirrors,
        // which have a different database type.
        List<VolumeDescriptor> descriptorsForMirrors = VolumeDescriptor.getDescriptors(volumeDescriptors, VolumeDescriptor.Type.BLOCK_MIRROR);
        _dbClient.markForDeletion(_dbClient.queryObject(BlockMirror.class, VolumeDescriptor.getVolumeURIs(descriptorsForMirrors)));
        List<VolumeDescriptor> descriptorsForVolumes = VolumeDescriptor.filterByType(volumeDescriptors, null, new VolumeDescriptor.Type[] { VolumeDescriptor.Type.BLOCK_MIRROR });
        _dbClient.markForDeletion(_dbClient.queryObject(Volume.class, VolumeDescriptor.getVolumeURIs(descriptorsForVolumes)));
        // Delete the corresponding FCZoneReferences
        for (URI volumeURI : volumeURIs) {
            List<FCZoneReference> zoneReferences = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, FCZoneReference.class, "volumeUri", volumeURI.toString());
            for (FCZoneReference zoneReference : zoneReferences) {
                if (zoneReference != null) {
                    _dbClient.markForDeletion(zoneReference);
                }
            }
        }
        // Update the task status for each volume
        for (URI volumeURI : volumeURIs) {
            Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
            Operation op = volume.getOpStatus().get(task);
            op.ready("Volume succesfully deleted from ViPR");
            volume.getOpStatus().updateTaskStatus(task, op);
            _dbClient.updateObject(volume);
        }
    } else {
        BlockOrchestrationController controller = getController(BlockOrchestrationController.class, BlockOrchestrationController.BLOCK_ORCHESTRATION_DEVICE);
        controller.deleteVolumes(volumeDescriptors, task);
    }
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) BlockOrchestrationController(com.emc.storageos.blockorchestrationcontroller.BlockOrchestrationController) BlockMirror(com.emc.storageos.db.client.model.BlockMirror) Volume(com.emc.storageos.db.client.model.Volume) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 45 with Operation

use of com.emc.storageos.db.client.model.Operation in project coprhd-controller by CoprHD.

the class AbstractBlockServiceApiImpl method deleteSnapshot.

/**
 * {@inheritDoc}
 */
@Override
public void deleteSnapshot(BlockSnapshot requestedSnapshot, List<BlockSnapshot> allSnapshots, String taskId, String deleteType) {
    if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deleteType)) {
        s_logger.info("Executing ViPR-only snapshot deletion");
        // Do any cleanup necessary for the ViPR only delete.
        cleanupForViPROnlySnapshotDelete(allSnapshots);
        // Mark them inactive.
        _dbClient.markForDeletion(allSnapshots);
        // Note that we must go back to the database to get the latest snapshot status map.
        for (BlockSnapshot snapshot : allSnapshots) {
            BlockSnapshot updatedSnapshot = _dbClient.queryObject(BlockSnapshot.class, snapshot.getId());
            Operation op = updatedSnapshot.getOpStatus().get(taskId);
            op.ready("Snapshot succesfully deleted from ViPR");
            updatedSnapshot.getOpStatus().updateTaskStatus(taskId, op);
            _dbClient.updateObject(updatedSnapshot);
        }
    } else {
        StorageSystem device = _dbClient.queryObject(StorageSystem.class, requestedSnapshot.getStorageController());
        BlockController controller = getController(BlockController.class, device.getSystemType());
        controller.deleteSnapshot(device.getId(), requestedSnapshot.getId(), taskId);
    }
}
Also used : BlockController(com.emc.storageos.volumecontroller.BlockController) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Operation(com.emc.storageos.db.client.model.Operation) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

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