Search in sources :

Example 96 with TaskList

use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.

the class BlockSnapshotSessions method deactivate.

/**
 * Begins deactivating a given block snapshot session by ID.
 * <p>
 * API Call: <tt>POST /block/snapshot-sessions/{id}/deactivate</tt>
 *
 * @param id
 *            the ID of the snapshot session to deactivate.
 * @param type
 *            {@code FULL} or {@code VIPR_ONLY}
 *
 * @return a task for monitoring the progress of the operation.
 */
public Tasks<BlockSnapshotSessionRestRep> deactivate(URI id, VolumeDeleteTypeEnum type) {
    URI uri = client.uriBuilder(getDeactivateUrl()).queryParam("type", type).build(id);
    TaskList tasks = client.postURI(TaskList.class, uri);
    return new Tasks<>(client, tasks.getTaskList(), resourceClass);
}
Also used : Tasks(com.emc.vipr.client.Tasks) TaskList(com.emc.storageos.model.TaskList) URI(java.net.URI)

Example 97 with TaskList

use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.

the class FileService method deactivateContinuousCopies.

/**
 * Deactivate Continuous Copies
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param param
 *            File System Delete parameter
 * @brief Delete continuous copies
 * @return TaskResponse
 * @throws InternalException
 * @throws APIException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/deactivate")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep deactivateContinuousCopies(@PathParam("id") URI id, FileSystemDeleteParam param) throws InternalException, APIException {
    _log.info("Request to deactivate replication copies for filesystem {}", id);
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    FileShare orgFs = queryResource(id);
    String task = UUID.randomUUID().toString();
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    TaskList taskList = new TaskList();
    // Make sure that we don't have some pending
    // operation against the file system!!!
    checkForPendingTasks(Arrays.asList(fs.getTenant().getURI()), Arrays.asList(fs));
    // Get the project.
    URI projectURI = fs.getProject().getURI();
    Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
    ArgValidator.checkEntity(project, projectURI, false);
    _log.info("Found filesystem project {}", projectURI);
    VirtualPool currentVpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    StringBuffer notSuppReasonBuff = new StringBuffer();
    // Verify the file system and its vPool are capable of doing replication!!!
    if (!FileSystemReplicationUtils.validateDeleteMirrorCopies(fs, currentVpool, notSuppReasonBuff)) {
        _log.error("delete mirror copies is not supported for file system {} due to {}", fs.getId().toString(), notSuppReasonBuff.toString());
        throw APIException.badRequests.unableToDeleteMirrorCopies(fs.getId(), notSuppReasonBuff.toString());
    }
    // Get the virtual array!!!
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, fs.getVirtualArray());
    // New operation
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.DELETE_MIRROR_FILE_SYSTEMS);
    op.setDescription("Deactivate file system mirror operation");
    op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, op);
    TaskResourceRep fileSystemTask = toTask(fs, task, op);
    taskList.getTaskList().add(fileSystemTask);
    List<URI> fileShareURIs = new ArrayList<URI>();
    fileShareURIs.add(id);
    boolean deleteMirrorCopies = true;
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
    try {
        fileServiceApi.deleteFileSystems(device.getId(), fileShareURIs, param.getDeleteType(), param.getForceDelete(), deleteMirrorCopies, task);
    } catch (InternalException e) {
        if (_log.isErrorEnabled()) {
            _log.error("deactivate continuous copies error ", e);
        }
        FileShare fileShare = _dbClient.queryObject(FileShare.class, fs.getId());
        op = fs.getOpStatus().get(task);
        op.error(e);
        fileShare.getOpStatus().updateTaskStatus(task, op);
        // Revert the file system to original state!!!
        restoreFromOriginalFs(orgFs, fs);
        _dbClient.updateObject(fs);
        throw e;
    }
    auditOp(OperationTypeEnum.DELETE_MIRROR_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getLabel(), currentVpool.getLabel(), fs.getLabel(), project == null ? null : project.getId().toString());
    return taskList.getTaskList().get(0);
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) 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 98 with TaskList

use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.

the class FileService method createContinuousCopies.

/**
 * Create Continuous Copies
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param param
 *            File Replication Create parameter
 * @brief Define continuous copies
 * @return TaskResponse
 * @throws InternalException
 * @throws APIException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/create")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep createContinuousCopies(@PathParam("id") URI id, FileReplicationCreateParam param) throws InternalException, APIException {
    _log.info("Request to create replication copies for filesystem {}", id);
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    FileShare orgFs = queryResource(id);
    String task = UUID.randomUUID().toString();
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    TaskList taskList = new TaskList();
    // Make sure that we don't have some pending
    // operation against the file system!!!
    checkForPendingTasks(Arrays.asList(fs.getTenant().getURI()), Arrays.asList(fs));
    // Get the project.
    URI projectURI = fs.getProject().getURI();
    Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
    ArgValidator.checkEntity(project, projectURI, false);
    _log.info("Found filesystem project {}", projectURI);
    VirtualPool currentVpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    StringBuffer notSuppReasonBuff = new StringBuffer();
    // Verify the file system and its vPool are capable of doing replication!!!
    if (!FileSystemReplicationUtils.isSupportedFileReplicationCreate(fs, currentVpool, notSuppReasonBuff)) {
        _log.error("create mirror copies is not supported for file system {} due to {}", fs.getId().toString(), notSuppReasonBuff.toString());
        throw APIException.badRequests.unableToCreateMirrorCopies(fs.getId(), notSuppReasonBuff.toString());
    }
    // Get the virtual array!!!
    VirtualArray varray = _dbClient.queryObject(VirtualArray.class, fs.getVirtualArray());
    // New operation
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.CREATE_FILE_SYSTEM_MIRROR_COPIES);
    op.setDescription("Create file system mirror operation");
    op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, op);
    TaskResourceRep fileSystemTask = toTask(fs, task, op);
    taskList.getTaskList().add(fileSystemTask);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    // prepare vpool capability values
    VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
    capabilities.put(VirtualPoolCapabilityValuesWrapper.SIZE, fs.getCapacity());
    capabilities.put(VirtualPoolCapabilityValuesWrapper.RESOURCE_COUNT, new Integer(1));
    if (VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(currentVpool.getSupportedProvisioningType())) {
        capabilities.put(VirtualPoolCapabilityValuesWrapper.THIN_PROVISIONING, Boolean.TRUE);
    }
    // Set the source file system details
    // source fs details used in finding recommendations for target fs!!
    capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_SYSTEM_CREATE_MIRROR_COPY, Boolean.TRUE);
    capabilities.put(VirtualPoolCapabilityValuesWrapper.EXISTING_SOURCE_FILE_SYSTEM, fs);
    capabilities.put(VirtualPoolCapabilityValuesWrapper.SOURCE_STORAGE_SYSTEM, device);
    StringBuilder errorMsg = new StringBuilder();
    if (!FilePolicyServiceUtils.updatePolicyCapabilities(_dbClient, varray, currentVpool, project, null, capabilities, errorMsg)) {
        _log.error("File system can not be created, ", errorMsg.toString());
        throw APIException.badRequests.unableToProcessRequest(errorMsg.toString());
    }
    if (param.getCopyName() != null && !param.getCopyName().isEmpty()) {
        // No need to generate any name -- Since the requirement is to use the customizing label we should use the
        // same.
        // Stripping out the special characters like ; /-+!@#$%^&())";:[]{}\ | but allow underscore character _
        String convertedName = param.getCopyName().replaceAll("[^\\dA-Za-z\\_]", "");
        _log.info("Original copy name {} and converted copy name {}", param.getCopyName(), convertedName);
        capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_TARGET_COPY_NAME, convertedName);
    }
    FileServiceApi fileServiceApi = getFileShareServiceImpl(capabilities, _dbClient);
    try {
        // Call out placementManager to get the recommendation for placement.
        List recommendations = _filePlacementManager.getRecommendationsForFileCreateRequest(varray, project, currentVpool, capabilities);
        // Verify the source virtual pool recommendations meets source fs storage!!!
        fileServiceApi.createTargetsForExistingSource(fs, project, currentVpool, varray, taskList, task, recommendations, capabilities);
    } catch (BadRequestException e) {
        // Revert the file system to original state!!!
        restoreFromOriginalFs(orgFs, fs);
        _dbClient.updateObject(fs);
        op = _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Create file system mirror copy failed {}, {}", e.getMessage(), e);
        throw e;
    } catch (InternalException e) {
        // Revert the file system to original state!!!
        restoreFromOriginalFs(orgFs, fs);
        _dbClient.updateObject(fs);
        op = _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Create file system mirror copy failed {}, {}", e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        _log.error("Create file system mirror copy failed  {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    auditOp(OperationTypeEnum.CREATE_MIRROR_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getLabel(), currentVpool.getLabel(), fs.getLabel(), project == null ? null : project.getId().toString());
    return taskList.getTaskList().get(0);
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Project(com.emc.storageos.db.client.model.Project) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) FilePolicyList(com.emc.storageos.model.file.FilePolicyList) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) QuotaDirectoryList(com.emc.storageos.model.file.QuotaDirectoryList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) FileSystemShareList(com.emc.storageos.model.file.FileSystemShareList) List(java.util.List) FileSystemExportList(com.emc.storageos.model.file.FileSystemExportList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList) MirrorList(com.emc.storageos.model.block.MirrorList) SnapshotList(com.emc.storageos.model.SnapshotList) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) 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 99 with TaskList

use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.

the class HostService method doDiscoverHost.

/**
 * Host Discovery
 *
 * @param host {@link Host} The Host to be discovered.
 * @param taskId {@link String} taskId for the host discovery. as new taskId is generated if null passed.
 * @param updateTaskStatus if true, mark the task status as completed for non-discovered host
 * @return the task used to track the discovery job
 */
protected TaskResourceRep doDiscoverHost(URI hostId, String taskId, boolean updateTaskStatus) {
    Host host = queryObject(Host.class, hostId, true);
    if (taskId == null) {
        taskId = UUID.randomUUID().toString();
    }
    if (host.getDiscoverable() != null && !host.getDiscoverable()) {
        host.setDiscoveryStatus(DataCollectionJobStatus.COMPLETE.name());
        _dbClient.updateObject(host);
    }
    if ((host.getDiscoverable() == null || host.getDiscoverable())) {
        ComputeSystemController controller = getController(ComputeSystemController.class, "host");
        DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new DiscoverJobExec(controller));
        ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
        tasks.add(new AsyncTask(Host.class, host.getId(), taskId));
        TaskList taskList = scheduler.scheduleAsyncTasks(tasks);
        return taskList.getTaskList().iterator().next();
    } else {
        // if not discoverable, manually create a ready task
        Operation op = new Operation();
        op.setResourceType(ResourceOperationTypeEnum.DISCOVER_HOST);
        if (updateTaskStatus) {
            op.ready("Host is not discoverable");
        } else {
            op.pending();
        }
        _dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, op);
        return toTask(host, taskId, op);
    }
}
Also used : TaskList(com.emc.storageos.model.TaskList) ComputeSystemController(com.emc.storageos.computesystemcontroller.ComputeSystemController) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) Operation(com.emc.storageos.db.client.model.Operation)

Example 100 with TaskList

use of com.emc.storageos.model.TaskList in project coprhd-controller by CoprHD.

the class HostService method createHostArrayAffinityTasks.

/**
 * Create array affinity tasks for hosts.
 *
 * @param hostIds
 *            the hosts whose preferred systems need to be discovered
 */
public TaskList createHostArrayAffinityTasks(List<URI> hostIds) {
    TaskList taskList = new TaskList();
    String taskId = UUID.randomUUID().toString();
    String jobType = "";
    Map<URI, List<URI>> providerToSystemsMap = new HashMap<URI, List<URI>>();
    Map<URI, String> providerToSystemTypeMap = new HashMap<URI, String>();
    List<URI> sysURIs = _dbClient.queryByType(StorageSystem.class, true);
    Iterator<StorageSystem> storageSystems = _dbClient.queryIterativeObjects(StorageSystem.class, sysURIs);
    while (storageSystems.hasNext()) {
        StorageSystem systemObj = storageSystems.next();
        if (systemObj == null) {
            _log.warn("StorageSystem is no longer in the DB. It could have been deleted or decommissioned");
            continue;
        }
        if (systemObj.deviceIsType(Type.vmax) || systemObj.deviceIsType(Type.vnxblock) || systemObj.deviceIsType(Type.xtremio)) {
            if (systemObj.getActiveProviderURI() == null || NullColumnValueGetter.getNullURI().equals(systemObj.getActiveProviderURI())) {
                _log.info("Skipping {} Job : StorageSystem {} does not have an active provider", jobType, systemObj.getLabel());
                continue;
            }
            StorageProvider provider = _dbClient.queryObject(StorageProvider.class, systemObj.getActiveProviderURI());
            if (provider == null || provider.getInactive()) {
                _log.info("Skipping {} Job : StorageSystem {} does not have a valid active provider", jobType, systemObj.getLabel());
                continue;
            }
            List<URI> systemIds = providerToSystemsMap.get(provider.getId());
            if (systemIds == null) {
                systemIds = new ArrayList<URI>();
                providerToSystemsMap.put(provider.getId(), systemIds);
                providerToSystemTypeMap.put(provider.getId(), systemObj.getSystemType());
            }
            systemIds.add(systemObj.getId());
        } else if (systemObj.deviceIsType(Type.unity)) {
            List<URI> systemIds = new ArrayList<URI>();
            systemIds.add(systemObj.getId());
            providerToSystemsMap.put(systemObj.getId(), systemIds);
            providerToSystemTypeMap.put(systemObj.getId(), systemObj.getSystemType());
        } else {
            _log.info("Skip unsupported system {}, system type {}", systemObj.getLabel(), systemObj.getSystemType());
            continue;
        }
    }
    for (Map.Entry<URI, List<URI>> entry : providerToSystemsMap.entrySet()) {
        List<URI> systemIds = entry.getValue();
        BlockController controller = getController(BlockController.class, providerToSystemTypeMap.get(entry.getKey()));
        DiscoveredObjectTaskScheduler scheduler = new DiscoveredObjectTaskScheduler(_dbClient, new StorageSystemService.ArrayAffinityJobExec(controller));
        ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>();
        tasks.add(new ArrayAffinityAsyncTask(StorageSystem.class, systemIds, hostIds, taskId));
        taskList.getTaskList().addAll(scheduler.scheduleAsyncTasks(tasks).getTaskList());
    }
    return taskList;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) BlockController(com.emc.storageos.volumecontroller.BlockController) TaskList(com.emc.storageos.model.TaskList) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) ArrayList(java.util.ArrayList) DiscoveredObjectTaskScheduler(com.emc.storageos.api.service.impl.resource.utils.DiscoveredObjectTaskScheduler) StorageProvider(com.emc.storageos.db.client.model.StorageProvider) URI(java.net.URI) ArrayAffinityAsyncTask(com.emc.storageos.volumecontroller.ArrayAffinityAsyncTask) UnManagedExportMaskList(com.emc.storageos.model.block.UnManagedExportMaskList) UnManagedVolumeList(com.emc.storageos.model.block.UnManagedVolumeList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) InitiatorList(com.emc.storageos.model.host.InitiatorList) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) MountInfoList(com.emc.storageos.model.file.MountInfoList) HostList(com.emc.storageos.model.host.HostList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) List(java.util.List) BulkList(com.emc.storageos.api.service.impl.response.BulkList) LinkedList(java.util.LinkedList) IpInterfaceList(com.emc.storageos.model.host.IpInterfaceList) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Aggregations

TaskList (com.emc.storageos.model.TaskList)161 ArrayList (java.util.ArrayList)84 URI (java.net.URI)83 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)82 Volume (com.emc.storageos.db.client.model.Volume)67 Produces (javax.ws.rs.Produces)62 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)57 Operation (com.emc.storageos.db.client.model.Operation)55 POST (javax.ws.rs.POST)55 Path (javax.ws.rs.Path)54 Consumes (javax.ws.rs.Consumes)44 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)43 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)35 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)33 NamedURI (com.emc.storageos.db.client.model.NamedURI)28 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)27 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)27 Tasks (com.emc.vipr.client.Tasks)27 List (java.util.List)26 WaitForTasks (com.emc.sa.service.vipr.tasks.WaitForTasks)23