Search in sources :

Example 16 with FileController

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

the class FileService method update.

/**
 * Expand file system.
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param param
 *            File system expansion parameters
 * @param id
 *            the URN of a ViPR File system
 * @brief Update file system properties
 * @return Task resource representation
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep update(@PathParam("id") URI id, FileSystemUpdateParam param) throws InternalException {
    _log.info(String.format("FileShareUpdate --- FileShare id: %1$s", id));
    // check file System
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    Boolean deviceSupportsSoftLimit = device.getSupportSoftLimit() != null ? device.getSupportSoftLimit() : false;
    Boolean deviceSupportsNotificationLimit = device.getSupportNotificationLimit() != null ? device.getSupportNotificationLimit() : false;
    if (param.getSoftLimit() != 0 && !deviceSupportsSoftLimit) {
        throw APIException.badRequests.unsupportedParameterForStorageSystem("soft_limit");
    }
    if (param.getNotificationLimit() != 0 && !deviceSupportsNotificationLimit) {
        throw APIException.badRequests.unsupportedParameterForStorageSystem("notification_limit");
    }
    ArgValidator.checkFieldMaximum(param.getSoftLimit(), 100, "soft_limit");
    ArgValidator.checkFieldMaximum(param.getNotificationLimit(), 100, "notification_limit");
    if (param.getSoftLimit() > 0L) {
        ArgValidator.checkFieldMinimum(param.getSoftGrace(), 1L, "soft_grace");
        fs.setSoftGracePeriod(param.getSoftGrace());
        fs.setSoftLimit(Long.valueOf(param.getSoftLimit()));
    }
    if (param.getNotificationLimit() > 0) {
        fs.setNotificationLimit(Long.valueOf(param.getNotificationLimit()));
    }
    _dbClient.updateObject(fs);
    FileController controller = getController(FileController.class, device.getSystemType());
    String task = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.UPDATE_FILE_SYSTEM);
    controller.modifyFS(fs.getStorageDevice(), fs.getPool(), id, task);
    op.setDescription("Filesystem update");
    auditOp(OperationTypeEnum.UPDATE_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), fs.getCapacity(), param.getNotificationLimit(), param.getSoftLimit(), param.getSoftGrace());
    return toTask(fs, task, op);
}
Also used : 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) 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 17 with FileController

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

the class FileSnapshotService method unexport.

/**
 * Remove file share snapshot export.
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @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 snapshot export
 * @return Task resource representation
 * @throws InternalException
 */
@DELETE
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports/{protocol},{secType},{perm},{rootMapping}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep unexport(@PathParam("id") URI id, @PathParam("protocol") String protocol, @PathParam("secType") String securityType, @PathParam("perm") String permissions, @PathParam("rootMapping") String rootUserMapping) throws InternalException {
    String task = UUID.randomUUID().toString();
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snap = queryResource(id);
    FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
    ArgValidator.checkFieldNotNull(protocol, "protocol");
    ArgValidator.checkFieldNotNull(securityType, "secType");
    ArgValidator.checkFieldNotNull(permissions, "perm");
    ArgValidator.checkFieldNotNull(rootUserMapping, "rootMapping");
    if (snap.getFsExports() == null || snap.getFsExports().isEmpty()) {
        // No export to unexport, return success.
        String message = "Export does not exist";
        return getSuccessResponse(snap, task, ResourceOperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, message);
    }
    ArgValidator.checkEntity(snap, id, isIdEmbeddedInURL(id));
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    String path = snap.getPath();
    _log.info(String.format("securityType %1$s, permissions %2$s, rootMapping %3$s %4$s", securityType, permissions, rootUserMapping, path));
    FileExport fileSnapExport = snap.getFsExports().get(FileExport.exportLookupKey(protocol, securityType, permissions, rootUserMapping, path));
    if (fileSnapExport == null) {
        // No export to unexport, return success.
        String message = "Export does not exist";
        return getSuccessResponse(snap, task, ResourceOperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, message);
    }
    // empty list for unexport
    List<String> endpoints = new ArrayList<String>();
    FileShareExport export = new FileShareExport(endpoints, securityType, permissions, rootUserMapping, protocol, fileSnapExport.getStoragePortName(), fileSnapExport.getStoragePort(), fileSnapExport.getPath());
    export.setIsilonId(fileSnapExport.getIsilonId());
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.UNEXPORT_FILE_SNAPSHOT);
    controller.unexport(device.getId(), snap.getId(), Arrays.asList(export), task);
    auditOp(OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snap.getId().toString(), device.getId().toString(), securityType, permissions, rootUserMapping, protocol);
    return toTask(snap, task, op);
}
Also used : FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) 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) 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 18 with FileController

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

the class FileQuotaDirectoryService method updateQuotaDirectory.

/**
 * Update Quota Directory for a file share
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR Quota directory
 * @param param
 *            File system Quota directory update parameters
 * @brief Update file system quota directory
 * @return Task resource representation
 * @throws com.emc.storageos.svcs.errorhandling.resources.InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateQuotaDirectory(@PathParam("id") URI id, QuotaDirectoryUpdateParam param) throws InternalException {
    _log.info("FileService::Update Quota directory Request recieved {}", id);
    QuotaDirectory quotaDirNew = new QuotaDirectory();
    if (param.getSecurityStyle() != null) {
        ArgValidator.checkFieldValueFromEnum(param.getSecurityStyle(), "security_style", EnumSet.allOf(QuotaDirectory.SecurityStyles.class));
    }
    // Get the FileSystem object
    QuotaDirectory quotaDir = queryResource(id);
    FileShare fs = queryFileShareResource(quotaDir.getParent().getURI());
    ArgValidator.checkFieldNotNull(fs, "filesystem");
    // Set all other optional parameters too.
    quotaDirNew.setName(quotaDir.getName());
    quotaDirNew.setId(id);
    quotaDirNew.setNativeGuid(quotaDir.getNativeGuid());
    if (param.getOpLock() != null) {
        quotaDirNew.setOpLock(param.getOpLock());
    }
    if (param.getSecurityStyle() != null) {
        quotaDirNew.setSecurityStyle(param.getSecurityStyle());
    }
    if (param.getSize() != null) {
        // converts the input string in format "<value>GB" to Bytes
        Long quotaSize = SizeUtil.translateSize(param.getSize());
        if (quotaSize > 0) {
            ArgValidator.checkFieldMaximum(quotaSize, fs.getCapacity(), SizeUtil.SIZE_B, "size", true);
            quotaDirNew.setSize(quotaSize);
        }
    }
    ArgValidator.checkFieldMaximum(param.getSoftLimit(), 100, "softLimit");
    ArgValidator.checkFieldMaximum(param.getNotificationLimit(), 100, "notificationLimit");
    if (param.getSoftLimit() != 0L) {
        ArgValidator.checkFieldMinimum(param.getSoftGrace(), 1L, "softGrace");
    }
    int fsSoftLimit = -1;
    if (null != fs.getSoftLimit()) {
        fsSoftLimit = fs.getSoftLimit().intValue();
    }
    int fsNotifiLimit = -1;
    if (null != fs.getNotificationLimit()) {
        fsNotifiLimit = fs.getNotificationLimit().intValue();
    }
    int fsGraceLimit = -1;
    if (null != fs.getSoftGracePeriod()) {
        fsGraceLimit = fs.getSoftGracePeriod().intValue();
    }
    String task = UUID.randomUUID().toString();
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.UPDATE_FILE_SYSTEM_QUOTA_DIR);
    // Update the quota directory object to store in ViPR database
    quotaDir.setOpStatus(new OpStatusMap());
    quotaDir.getOpStatus().createTaskStatus(task, op);
    fs.setOpStatus(new OpStatusMap());
    fs.getOpStatus().createTaskStatus(task, op);
    _dbClient.updateObject(fs);
    _dbClient.updateObject(quotaDir);
    quotaDirNew.setSoftLimit(param.getSoftLimit() > 0 ? param.getSoftLimit() : quotaDir.getSoftLimit() > 0 ? quotaDir.getSoftLimit() : fsSoftLimit > 0 ? fsSoftLimit : 0);
    quotaDirNew.setSoftGrace(param.getSoftGrace() > 0 ? param.getSoftGrace() : quotaDir.getSoftGrace() > 0 ? quotaDir.getSoftGrace() : fsGraceLimit > 0 ? fsGraceLimit : 0);
    quotaDirNew.setNotificationLimit(param.getNotificationLimit() > 0 ? param.getNotificationLimit() : quotaDir.getNotificationLimit() > 0 ? quotaDir.getNotificationLimit() : fsNotifiLimit > 0 ? fsNotifiLimit : 0);
    // Create an object of type "FileShareQtree" to be passed into the
    // south-bound layers.
    FileShareQuotaDirectory qt = new FileShareQuotaDirectory(quotaDirNew);
    // Now get ready to make calls into the controller
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    try {
        controller.updateQuotaDirectory(device.getId(), qt, fs.getId(), task);
    } catch (InternalException e) {
        _log.error("Error during update of Quota Directory {}", e);
        // errors
        throw e;
    }
    auditOp(OperationTypeEnum.UPDATE_FILE_SYSTEM_QUOTA_DIR, true, AuditLogManager.AUDITOP_BEGIN, quotaDirNew.getLabel(), quotaDirNew.getId().toString(), fs.getId().toString());
    fs = _dbClient.queryObject(FileShare.class, fs.getId());
    _log.debug("FileService::Quota directory Before sending response, FS ID : {}, Taks : {} ; Status {}", fs.getOpStatus().get(task), fs.getOpStatus().get(task).getStatus());
    return toTask(quotaDir, task, op);
}
Also used : FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) FileController(com.emc.storageos.volumecontroller.FileController) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) MapQuotaDirectory(com.emc.storageos.api.mapper.functions.MapQuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) 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 19 with FileController

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

the class FileControllerImplTest method setupController.

@BeforeClass
public static void setupController() throws Exception {
    final Dispatcher dispatcher = new StubDispatcher();
    final Set<FileController> fileControllers = new HashSet<FileController>();
    final FileDeviceController fileDeviceController = new FileDeviceController();
    fileControllers.add(fileDeviceController);
    controller = new FileControllerImpl();
    controller.setDbClient(new StubDbClientImpl());
    controller.setDeviceImpl(fileControllers);
    controller.setDispatcher(dispatcher);
    storageSystem = new StorageSystem();
    storageSystem.setId(StorageSystemId);
}
Also used : FileController(com.emc.storageos.volumecontroller.FileController) HashSet(java.util.HashSet) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) BeforeClass(org.junit.BeforeClass)

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