Search in sources :

Example 6 with FileController

use of com.emc.storageos.volumecontroller.FileController in project coprhd-controller by CoprHD.

the class FileService method unexport.

/**
 * @Deprecated use @Path("/{id}/export") instead
 *
 *             <p>
 *             NOTE: This is an asynchronous operation.
 * @param id
 *            the URN of a ViPR Project
 * @param protocol
 *            Protocol valid values - NFS,NFSv4,CIFS
 * @param securityType
 *            Security type valid values - sys,krb5,krb5i,krb5p
 * @param permissions
 *            Permissions valid values - ro,rw,root
 * @param rootUserMapping
 *            Root user mapping
 * @brief Delete file system export.
 *        <p>
 *        Use /file/filesystems/{id}/export instead
 * @return Task resource representation
 * @throws InternalException
 */
@Deprecated
@DELETE
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports/{protocol},{secType},{perm},{root_mapping}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep unexport(@PathParam("id") URI id, @PathParam("protocol") String protocol, @PathParam("secType") String securityType, @PathParam("perm") String permissions, @PathParam("root_mapping") String rootUserMapping, @QueryParam("subDirectory") String subDirectory) throws InternalException {
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkFieldNotNull(protocol, "protocol");
    ArgValidator.checkFieldNotNull(securityType, "secType");
    ArgValidator.checkFieldNotNull(permissions, "perm");
    ArgValidator.checkFieldNotNull(rootUserMapping, "root_mapping");
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    String task = UUID.randomUUID().toString();
    if (fs.getFsExports() == null) {
        // No exports present. Return success.
        return getSuccessResponse(fs, task, ResourceOperationTypeEnum.UNEXPORT_FILE_SYSTEM, "Export does not exist");
    }
    if (fs.getStoragePort() == null) {
        // port associated with export, fail the operation
        return getFailureResponse(fs, task, ResourceOperationTypeEnum.UNEXPORT_FILE_SYSTEM, "No storage port associated with " + fs.getLabel());
    }
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    String path = fs.getPath();
    String mountPath = fs.getMountPath();
    if (subDirectory != null && subDirectory.length() > 0) {
        // Add subdirectory to the path as this is a subdirectory export
        path += "/" + subDirectory;
        mountPath += "/" + subDirectory;
    }
    FileExport fExport = null;
    _log.info("unexport subdirectory passed value is {}", subDirectory);
    if (subDirectory != null) {
        _log.info("unexport subdirectory {} with path {} ", subDirectory, path);
        _log.info(String.format("securityType %1$s, permissions %2$s, rootMapping %3$s, protocol %4$s subDirectory %5$s", securityType, permissions, rootUserMapping, protocol, path));
        fExport = fs.getFsExports().get(FileExport.exportLookupKey(protocol, securityType, permissions, rootUserMapping, path));
    } else {
        _log.info("unexport FS  {} with path {} ", fs.getName(), path);
        _log.info(String.format("securityType %1$s, permissions %2$s, rootMapping %3$s, protocol %4$s FileSystem %5$s", securityType, permissions, rootUserMapping, protocol, path));
        fExport = fs.getFsExports().get(FileExport.exportLookupKey(protocol, securityType, permissions, rootUserMapping, path));
    }
    if (fExport == null) {
        // No export to unexport, return success.
        return getSuccessResponse(fs, task, ResourceOperationTypeEnum.UNEXPORT_FILE_SYSTEM, "Export does not exist");
    }
    fExport.setStoragePort(fs.getStoragePort().toString());
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.UNEXPORT_FILE_SYSTEM);
    op.setDescription("Filesystem unexport");
    // empty list for unexport
    List<String> endpoints = new ArrayList<String>();
    FileShareExport export = new FileShareExport(endpoints, securityType, permissions, rootUserMapping, protocol, fExport.getStoragePortName(), fExport.getStoragePort(), fExport.getPath());
    export.setIsilonId(fExport.getIsilonId());
    controller.unexport(device.getId(), fs.getId(), Arrays.asList(export), task);
    auditOp(OperationTypeEnum.UNEXPORT_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), securityType, permissions, rootUserMapping, protocol);
    return toTask(fs, task, op);
}
Also used : FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) FileController(com.emc.storageos.volumecontroller.FileController) FileExport(com.emc.storageos.db.client.model.FileExport) ArrayList(java.util.ArrayList) 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) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 7 with FileController

use of com.emc.storageos.volumecontroller.FileController 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 8 with FileController

use of com.emc.storageos.volumecontroller.FileController 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 9 with FileController

use of com.emc.storageos.volumecontroller.FileController in project coprhd-controller by CoprHD.

the class FileService method getFileSystemSchedulePolicySnapshots.

/**
 * Get file system Snapshot created by policy
 *
 * @param id
 *            The URN of a ViPR file system
 * @param filePolicyUri
 *            The URN of a file policy schedule
 * @param timeout
 *            Time limit in seconds to get the output .Default is 30 seconds
 * @brief Get snapshots related to the specified policy
 * @return List of snapshots created by a file policy
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/file-policies/{filePolicyUri}/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public ScheduleSnapshotList getFileSystemSchedulePolicySnapshots(@PathParam("id") URI id, @PathParam("filePolicyUri") URI filePolicyUri, @QueryParam("timeout") int timeout) {
    // valid value of timeout is 10 sec to 10 min
    if (timeout < 10 || timeout > 600) {
        // default timeout value.
        timeout = 30;
    }
    ScheduleSnapshotList list = new ScheduleSnapshotList();
    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 sp = _permissionsHelper.getObjectById(filePolicyUri, FilePolicy.class);
    ArgValidator.checkEntityNotNull(sp, filePolicyUri, isIdEmbeddedInURL(filePolicyUri));
    // verify the schedule policy is associated with file system or not.
    if (!fs.getFilePolicies().contains(filePolicyUri.toString())) {
        throw APIException.badRequests.cannotFindAssociatedPolicy(filePolicyUri);
    }
    String task = UUID.randomUUID().toString();
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.GET_FILE_SYSTEM_SNAPSHOT_BY_SCHEDULE);
    op.setDescription("list snapshots created by a policy");
    try {
        _log.info("No Errors found. Proceeding further {}, {}, {}", new Object[] { _dbClient, fs, sp });
        controller.listSanpshotByPolicy(device.getId(), fs.getId(), sp.getId(), task);
        Task taskObject = null;
        auditOp(OperationTypeEnum.GET_FILE_SYSTEM_SNAPSHOT_BY_SCHEDULE, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), sp.getId());
        int timeoutCounter = 0;
        // wait till timeout or result from controller service ,whichever is earlier
        do {
            TimeUnit.SECONDS.sleep(1);
            taskObject = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), task);
            timeoutCounter++;
        // exit the loop if task is completed with error/success or timeout
        } while ((taskObject != null && !(taskObject.isReady() || taskObject.isError())) && timeoutCounter < timeout);
        if (taskObject == null) {
            throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots task information");
        } else if (taskObject.isReady()) {
            URIQueryResultList snapshotsURIs = new URIQueryResultList();
            _dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(id), snapshotsURIs);
            List<Snapshot> snapList = _dbClient.queryObject(Snapshot.class, snapshotsURIs);
            for (Snapshot snap : snapList) {
                if (!snap.getInactive() && snap.getExtensions().containsKey("schedule")) {
                    ScheduleSnapshotRestRep snapRest = new ScheduleSnapshotRestRep();
                    getScheduleSnapshotRestRep(snapRest, snap);
                    list.getScheduleSnapList().add(snapRest);
                    snap.setInactive(true);
                    _dbClient.updateObject(snap);
                }
            }
        } else if (taskObject.isError()) {
            throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots due to" + taskObject.getMessage());
        } else {
            throw APIException.badRequests.unableToProcessRequest("Error occured while getting Filesystem policy Snapshots due to timeout");
        }
    } catch (BadRequestException e) {
        op = _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Error while getting  Filesystem policy  Snapshots {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    } catch (Exception e) {
        _log.error("Error while getting  Filesystem policy  Snapshots {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    return list;
}
Also used : TaskMapper.toTask(com.emc.storageos.api.mapper.TaskMapper.toTask) Task(com.emc.storageos.db.client.model.Task) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) FileController(com.emc.storageos.volumecontroller.FileController) 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) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) 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) Snapshot(com.emc.storageos.db.client.model.Snapshot) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) 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) ScheduleSnapshotRestRep(com.emc.storageos.model.file.ScheduleSnapshotRestRep) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 10 with FileController

use of com.emc.storageos.volumecontroller.FileController 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

FileController (com.emc.storageos.volumecontroller.FileController)19 FileShare (com.emc.storageos.db.client.model.FileShare)17 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)17 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)16 Operation (com.emc.storageos.db.client.model.Operation)15 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)15 Path (javax.ws.rs.Path)15 Produces (javax.ws.rs.Produces)15 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)11 Consumes (javax.ws.rs.Consumes)10 POST (javax.ws.rs.POST)9 TaskList (com.emc.storageos.model.TaskList)6 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)6 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)4 ArrayList (java.util.ArrayList)4 ContainmentConstraint (com.emc.storageos.db.client.constraint.ContainmentConstraint)3 ContainmentPrefixConstraint (com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint)3 PrefixConstraint (com.emc.storageos.db.client.constraint.PrefixConstraint)3 FileExport (com.emc.storageos.db.client.model.FileExport)3 OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)3