Search in sources :

Example 1 with ExportVerificationUtility

use of com.emc.storageos.api.service.impl.resource.utils.ExportVerificationUtility in project coprhd-controller by CoprHD.

the class FileService method updateFSExportRules.

/**
 * Existing file system exports may have their list of export rules updated.
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param subDir
 *            sub-directory within a filesystem
 * @param unmountExport
 *            Whether to unmount an export when deleting or modifying a rule
 * @brief Update file system export
 * @return Task resource representation
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/export")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateFSExportRules(@PathParam("id") URI id, @QueryParam("subDir") String subDir, @QueryParam("unmountExport") boolean unmountExport, FileShareExportUpdateParams param) throws InternalException {
    // log input received.
    _log.info("Update FS Export Rules : request received for {}  with {}", id, param);
    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));
    if (ArgValidator.checkSubDirName("subDir", subDir)) {
        // Set Sub Directory
        _log.info("Sub Dir Provided {}", subDir);
        param.setSubDir(subDir);
    }
    // check for bypassDnsCheck flag. If null then set to false
    if (param.getBypassDnsCheck() == null) {
        param.setBypassDnsCheck(false);
    }
    // Check for VirtualPool whether it has NFS enabled
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    if (!vpool.getProtocols().contains(StorageProtocol.File.NFS.name()) && !vpool.getProtocols().contains(StorageProtocol.File.NFSv4.name())) {
        // Throw an error
        throw APIException.methodNotAllowed.vPoolDoesntSupportProtocol("Vpool Doesnt support " + StorageProtocol.File.NFS.name() + " or " + StorageProtocol.File.NFSv4 + " protocol");
    }
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    String path = fs.getPath();
    _log.info("Export path found {} ", path);
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SYSTEM);
    op.setDescription("Filesystem export rules update");
    try {
        // Validate the input
        ExportVerificationUtility exportVerificationUtility = new ExportVerificationUtility(_dbClient, getUserFromContext());
        exportVerificationUtility.verifyExports(fs, null, param);
        _log.info("No Errors found proceeding further {}, {}, {}", new Object[] { _dbClient, fs, param });
        FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
        fileServiceApi.updateExportRules(device.getId(), fs.getId(), param, unmountExport, task);
        auditOp(OperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), param);
    } catch (URISyntaxException e) {
        _log.error("Error Processing Export Updates {}, {}", e.getMessage(), e);
    } catch (BadRequestException e) {
        op = _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Error Processing Export Updates {}, {}", e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        // _log.error("Error Processing Export Updates {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    return toTask(fs, task, op);
}
Also used : BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) URISyntaxException(java.net.URISyntaxException) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) ExportVerificationUtility(com.emc.storageos.api.service.impl.resource.utils.ExportVerificationUtility) 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) 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 2 with ExportVerificationUtility

use of com.emc.storageos.api.service.impl.resource.utils.ExportVerificationUtility in project coprhd-controller by CoprHD.

the class FileSnapshotService method updateSnapshotExportRules.

/**
 * Existing file system exports may have their list of export rules updated.
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param subDir
 *            sub-directory within a filesystem
 * @brief Update file system export
 * @return Task resource representation
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/export")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateSnapshotExportRules(@PathParam("id") URI id, SnapshotExportUpdateParams param) throws InternalException {
    // log input received.
    _log.info("Update Snapshot Export Rules : request received for {}  with {}", id, param);
    String task = UUID.randomUUID().toString();
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snap = queryResource(id);
    ArgValidator.checkEntity(snap, id, true);
    FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    String path = snap.getPath();
    _log.info("Snapshot Export path found {} ", path);
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SNAPSHOT);
    try {
        // Validate the input
        ExportVerificationUtility exportVerificationUtility = new ExportVerificationUtility(_dbClient, getUserFromContext());
        exportVerificationUtility.verifyExports(fs, snap, param);
        _log.info("No Errors found proceeding further {}, {}, {}", new Object[] { _dbClient, fs, param });
        FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
        fileServiceApi.updateExportRules(device.getId(), snap.getId(), param, false, task);
        auditOp(OperationTypeEnum.UPDATE_EXPORT_RULES_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), param);
    } catch (URISyntaxException e) {
        op.setStatus(Operation.Status.error.name());
        _log.error("Error Processing Export Updates {}, {}", e.getMessage(), e);
        return toTask(snap, task, op);
    } catch (BadRequestException e) {
        op = _dbClient.error(Snapshot.class, snap.getId(), task, e);
        _log.error("Error Processing Export Updates {}, {}", e.getMessage(), e);
    // throw e;
    } catch (Exception e) {
        op.setStatus(Operation.Status.error.name());
        toTask(snap, task, op);
        // _log.error("Error Processing Export Updates {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    return toTask(snap, task, op);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Operation(com.emc.storageos.db.client.model.Operation) URISyntaxException(java.net.URISyntaxException) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) ExportVerificationUtility(com.emc.storageos.api.service.impl.resource.utils.ExportVerificationUtility) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) 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)

Aggregations

ExportVerificationUtility (com.emc.storageos.api.service.impl.resource.utils.ExportVerificationUtility)2 FileShare (com.emc.storageos.db.client.model.FileShare)2 Operation (com.emc.storageos.db.client.model.Operation)2 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)2 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)2 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)2 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 BadRequestException (com.emc.storageos.svcs.errorhandling.resources.BadRequestException)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 URISyntaxException (java.net.URISyntaxException)2 Consumes (javax.ws.rs.Consumes)2 PUT (javax.ws.rs.PUT)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)1 MapFileSnapshot (com.emc.storageos.api.mapper.functions.MapFileSnapshot)1 Snapshot (com.emc.storageos.db.client.model.Snapshot)1 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)1 ControllerException (com.emc.storageos.volumecontroller.ControllerException)1