Search in sources :

Example 11 with TaskResourceRep

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

the class FileService method refreshContinuousCopies.

/**
 * Refresh continuous copies.
 *
 * @prereq none
 * @param id the URN of a ViPR Source file share
 * @brief Refresh the replication session between source and target file system.
 * @return TaskList
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/refresh")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList refreshContinuousCopies(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
    doMirrorOperationValidation(id, ProtectionOp.REFRESH.toString());
    String task = UUID.randomUUID().toString();
    FileShare sourceFileShare = queryResource(id);
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_REFRESH);
    op.setDescription("refresh the replication link between source and target");
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, sourceFileShare.getStorageDevice());
    FileController controller = getController(FileController.class, system.getSystemType());
    controller.performFileReplicationOperation(system.getId(), id, ProtectionOp.REFRESH.toString().toLowerCase(), task);
    TaskList taskList = new TaskList();
    TaskResourceRep taskResp = toTask(sourceFileShare, task, op);
    taskList.getTaskList().add(taskResp);
    return taskList;
}
Also used : FileController(com.emc.storageos.volumecontroller.FileController) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 12 with TaskResourceRep

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

the class FileService method pauseContinuousCopies.

/**
 * Pause continuous copies.
 *
 * @prereq none
 * @param id the URN of a ViPR Source file share
 * @brief Pause the replication session between source and target file system.
 * @return TaskResourceRep
 * @throws ControllerException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/pause")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList pauseContinuousCopies(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
    doMirrorOperationValidation(id, ProtectionOp.PAUSE.toString());
    String task = UUID.randomUUID().toString();
    FileShare sourceFileShare = queryResource(id);
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_PAUSE);
    op.setDescription("pause the replication link between source and target");
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, sourceFileShare.getStorageDevice());
    FileController controller = getController(FileController.class, system.getSystemType());
    controller.performFileReplicationOperation(system.getId(), id, ProtectionOp.PAUSE.toString().toLowerCase(), task);
    TaskList taskList = new TaskList();
    TaskResourceRep taskResp = toTask(sourceFileShare, task, op);
    taskList.getTaskList().add(taskResp);
    return taskList;
}
Also used : FileController(com.emc.storageos.volumecontroller.FileController) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 13 with TaskResourceRep

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

the class FileService method assignFilePolicy.

/**
 * Assign existing file system to file policy.
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param filePolicyUri
 *            the URN of a Policy
 * @brief Update file system with Policy detail
 * @return Task resource representation
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/assign-file-policy/{filePolicyUri}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep assignFilePolicy(@PathParam("id") URI id, @PathParam("filePolicyUri") URI filePolicyUri, FilePolicyFileSystemAssignParam param) throws InternalException {
    TaskResourceRep resp = new TaskResourceRep();
    StringBuilder errorMsg = new StringBuilder();
    _log.info("Assigning file policy {} to file system {}", filePolicyUri, id);
    String task = UUID.randomUUID().toString();
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    ArgValidator.checkFieldUriType(filePolicyUri, FilePolicy.class, "filePolicyUri");
    ArgValidator.checkUri(filePolicyUri);
    FilePolicy filePolicy = _permissionsHelper.getObjectById(filePolicyUri, FilePolicy.class);
    ArgValidator.checkEntityNotNull(filePolicy, filePolicyUri, isIdEmbeddedInURL(filePolicyUri));
    StringSet existingFSPolicies = fs.getFilePolicies();
    if (existingFSPolicies != null && existingFSPolicies.contains(filePolicyUri.toString())) {
        _log.info("Provided file policy {} is already is applied to the file sytem {}", filePolicy.getId(), fs.getId());
        Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.ASSIGN_FILE_POLICY_TO_FILE_SYSTEM);
        op.setDescription("assign file policy to file system");
        _dbClient.ready(FileShare.class, fs.getId(), task);
        return toTask(fs, task, op);
    }
    // check if same TYPE of policy already applied to file system
    if (filePolicy.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_replication.name()) && existingFSPolicies != null && !existingFSPolicies.isEmpty()) {
        checkForDuplicatePolicyApplied(filePolicy, existingFSPolicies);
    }
    // Check if the vpool supports provided policy type..
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    FilePolicyServiceUtils.validateVpoolSupportPolicyType(filePolicy, vpool);
    // Check if the vpool supports policy at file system level..
    if (!vpool.getAllowFilePolicyAtFSLevel()) {
        errorMsg.append("Provided vpool :" + vpool.getLabel() + " doesn't support policy at file system level");
        _log.error(errorMsg.toString());
        throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
    }
    // only single replication policy per vpool/project/fs.
    if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name()) && FilePolicyServiceUtils.fsHasReplicationPolicy(_dbClient, vpool.getId(), fs.getProject().getURI(), fs.getId())) {
        errorMsg.append("Provided vpool/project/fs has already assigned with replication policy.");
        _log.error(errorMsg.toString());
        throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
    }
    if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_snapshot.name()) && FilePolicyServiceUtils.fsHasSnapshotPolicyWithSameSchedule(_dbClient, fs.getId(), filePolicy)) {
        errorMsg.append("Snapshot policy with similar schedule is already present on fs " + fs.getLabel());
        _log.error(errorMsg.toString());
        throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
    }
    if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
        return assignFileReplicationPolicyToFS(fs, filePolicy, param, task);
    } else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
        return assignFilePolicyToFS(fs, filePolicy, task);
    }
    return resp;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) StringSet(com.emc.storageos.db.client.model.StringSet) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) 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 14 with TaskResourceRep

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

the class FileService method failoverProtection.

/**
 * Request to failover the protection link associated with the param.copyID.
 *
 * NOTE: This is an asynchronous operation.
 *
 * @prereq none
 *
 * @param id
 *            the URN of a ViPR Source fileshare
 * @param param
 *            FileReplicationParam to failover to
 *
 * @brief Failover the fileShare protection link
 * @return TaskList
 *
 * @throws ControllerException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/failover")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList failoverProtection(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
    doMirrorOperationValidation(id, ProtectionOp.FAILOVER.toString());
    TaskResourceRep taskResp = null;
    StoragePort storageportNFS = null;
    StoragePort storageportCIFS = null;
    TaskList taskList = new TaskList();
    String task = UUID.randomUUID().toString();
    FileShare fs = queryResource(id);
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILOVER);
    op.setDescription("failover source file system to target system");
    boolean replicateConfiguration = param.isReplicateConfiguration();
    if (replicateConfiguration) {
        List<String> targetfileUris = new ArrayList<String>();
        targetfileUris.addAll(fs.getMirrorfsTargets());
        FileShare targetFileShare = _dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
        SMBShareMap smbShareMap = fs.getSMBFileShares();
        if (smbShareMap != null) {
            storageportCIFS = _fileScheduler.placeFileShareExport(targetFileShare, StorageProtocol.File.CIFS.name(), null);
        }
        FSExportMap nfsExportMap = fs.getFsExports();
        if (nfsExportMap != null) {
            storageportNFS = _fileScheduler.placeFileShareExport(targetFileShare, StorageProtocol.File.NFS.name(), null);
        }
    }
    FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
    try {
        fileServiceApi.failoverFileShare(id, storageportNFS, storageportCIFS, replicateConfiguration, task);
    } catch (InternalException e) {
        if (_log.isErrorEnabled()) {
            _log.error("", e);
        }
        FileShare fileShare = _dbClient.queryObject(FileShare.class, fs.getId());
        op = fs.getOpStatus().get(task);
        op.error(e);
        fileShare.getOpStatus().updateTaskStatus(task, op);
        _dbClient.updateObject(fs);
        throw e;
    }
    taskResp = toTask(fs, task, op);
    taskList.getTaskList().add(taskResp);
    return taskList;
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) TaskList(com.emc.storageos.model.TaskList) StoragePort(com.emc.storageos.db.client.model.StoragePort) ArrayList(java.util.ArrayList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) Operation(com.emc.storageos.db.client.model.Operation) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) 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 15 with TaskResourceRep

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

the class FileService method startContinuousCopies.

/**
 * @Deprecated use @Path("/{id}/assign-file-policy/{filePolicyUri}") instead
 *             Assign file policy API will enable the policy and policy will run
 *             based on the schedule.
 *
 *             Start continuous copies.
 *
 * @prereq none
 * @param id the URN of a ViPR Source file share
 * @brief Start the replication session between source and target file system.
 * @return TaskList
 * @throws ControllerException
 */
@Deprecated
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/start")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList startContinuousCopies(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
    doMirrorOperationValidation(id, ProtectionOp.START.toString());
    String task = UUID.randomUUID().toString();
    FileShare sourceFileShare = queryResource(id);
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_START);
    op.setDescription("start the replication link between source and target");
    StorageSystem system = _dbClient.queryObject(StorageSystem.class, sourceFileShare.getStorageDevice());
    FileController controller = getController(FileController.class, system.getSystemType());
    controller.performFileReplicationOperation(system.getId(), id, ProtectionOp.START.toString().toLowerCase(), task);
    TaskList taskList = new TaskList();
    TaskResourceRep taskResp = toTask(sourceFileShare, task, op);
    taskList.getTaskList().add(taskResp);
    return taskList;
}
Also used : FileController(com.emc.storageos.volumecontroller.FileController) TaskList(com.emc.storageos.model.TaskList) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

TaskResourceRep (com.emc.storageos.model.TaskResourceRep)160 URI (java.net.URI)85 TaskList (com.emc.storageos.model.TaskList)82 Operation (com.emc.storageos.db.client.model.Operation)68 Produces (javax.ws.rs.Produces)59 ArrayList (java.util.ArrayList)56 Volume (com.emc.storageos.db.client.model.Volume)55 Path (javax.ws.rs.Path)54 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)53 POST (javax.ws.rs.POST)50 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)49 Consumes (javax.ws.rs.Consumes)36 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)35 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 NamedURI (com.emc.storageos.db.client.model.NamedURI)30 NullColumnValueGetter.isNullURI (com.emc.storageos.db.client.util.NullColumnValueGetter.isNullURI)23 Project (com.emc.storageos.db.client.model.Project)20 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)18 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)17 Copy (com.emc.storageos.model.block.Copy)17