Search in sources :

Example 76 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.

the class FileSnapshotService method queryResource.

@Override
protected Snapshot queryResource(URI id) {
    ArgValidator.checkUri(id);
    Snapshot snap = _permissionsHelper.getObjectById(id, Snapshot.class);
    ArgValidator.checkEntityNotNull(snap, id, isIdEmbeddedInURL(id));
    return snap;
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot)

Example 77 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.

the class FileSnapshotService method updateSnapshotShareACL.

/**
 * API to update ACLs of an existing share
 *
 * @param id
 *            the file system URI
 * @param shareName
 *            name of the share
 * @param param
 *            request payload object of type <code>com.emc.storageos.model.file.CifsShareACLUpdateParams</code>
 * @brief Change a snapshot share ACL
 * @return TaskResponse
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares/{shareName}/acl")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateSnapshotShareACL(@PathParam("id") URI id, @PathParam("shareName") String shareName, SnapshotCifsShareACLUpdateParams param) throws InternalException {
    _log.info("Update snapshot share acl request received. Snapshot: {}, Share: {}", id.toString(), shareName);
    _log.info("Request body: {}", param.toString());
    ArgValidator.checkFieldNotNull(shareName, "shareName");
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snapshot = queryResource(id);
    ArgValidator.checkEntity(snapshot, id, isIdEmbeddedInURL(id));
    if (!CifsShareUtility.doesShareExist(snapshot, shareName)) {
        _log.error("CIFS share does not exist {}", shareName);
        throw APIException.notFound.invalidParameterObjectHasNoSuchShare(snapshot.getId(), shareName);
    }
    FileShare fs = _permissionsHelper.getObjectById(snapshot.getParent(), FileShare.class);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    CifsShareUtility.checkForUpdateShareACLOperationOnStorage(device.getSystemType(), OperationTypeEnum.UPDATE_FILE_SNAPSHOT_SHARE_ACL.name());
    String task = UUID.randomUUID().toString();
    // Check for VirtualPool whether it has CIFS enabled
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    if (!vpool.getProtocols().contains(StorageProtocol.File.CIFS.name())) {
        throw APIException.methodNotAllowed.vPoolDoesntSupportProtocol("Vpool doesn't support " + StorageProtocol.File.CIFS.name() + " protocol");
    }
    // Validate the input
    CifsShareUtility util = new CifsShareUtility(_dbClient, null, snapshot, shareName);
    util.verifyShareACLs(param);
    _log.info("Request payload verified. No errors found.");
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snapshot.getId(), task, ResourceOperationTypeEnum.UPDATE_FILE_SNAPSHOT_SHARE_ACL);
    FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.updateShareACLs(device.getId(), snapshot.getId(), shareName, param, task);
    auditOp(OperationTypeEnum.UPDATE_FILE_SNAPSHOT_SHARE_ACL, true, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), device.getId().toString(), param);
    return toTask(snapshot, task, op);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) CifsShareUtility(com.emc.storageos.api.service.impl.resource.utils.CifsShareUtility) 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) 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 78 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot 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)

Example 79 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.

the class FileSnapshotService method deleteSnapshotExportRules.

/**
 * Delete Snapshot Export Rules
 *
 * @param id
 *            the URN of a ViPR file system
 * @brief Delete an export rule
 * @return TaskResponse
 */
@DELETE
@Path("/{id}/export")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep deleteSnapshotExportRules(@PathParam("id") URI id) {
    // log input received.
    _log.info("Delete Snapshot Export Rules : request received for {}", new Object[] { id });
    String task = UUID.randomUUID().toString();
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snapshot = queryResource(id);
    FileShare fileShare = _permissionsHelper.getObjectById(snapshot.getParent(), FileShare.class);
    ArgValidator.checkEntity(snapshot, id, isIdEmbeddedInURL(id));
    /* check if the Snapshot has any export rules on it */
    List<FileExportRule> exports = queryDBSnapshotExports(snapshot);
    if (exports == null || exports.isEmpty()) {
        _log.error("Error Processing Export Updates for snapshot {} doesnot have exports", snapshot.getName());
        throw APIException.badRequests.snapshotHasNoExport(snapshot.getId());
    }
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fileShare.getStorageDevice());
    String path = snapshot.getPath();
    _log.info("Export path found {} ", path);
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snapshot.getId(), task, ResourceOperationTypeEnum.UNEXPORT_FILE_SNAPSHOT);
    try {
        FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fileShare, _dbClient);
        fileServiceApi.deleteExportRules(device.getId(), snapshot.getId(), false, null, false, task);
        auditOp(OperationTypeEnum.UNEXPORT_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snapshot.getId().toString(), device.getId().toString(), false, null);
        return toTask(snapshot, task, op);
    } catch (BadRequestException 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());
    }
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) 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) DELETE(javax.ws.rs.DELETE) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 80 with Snapshot

use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.

the class FileSnapshotService method deleteShare.

/**
 * Deletes SMB share.
 * <p>
 * Note: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @param shareName
 *            SMB share name
 * @brief Delete file snapshot SMB share
 * @return Task resource representation
 * @throws InternalException
 */
@DELETE
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares/{shareName}")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep deleteShare(@PathParam("id") URI id, @PathParam("shareName") String shareName) throws InternalException {
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snap = queryResource(id);
    FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
    ArgValidator.checkFieldNotNull(shareName, "shareName");
    ArgValidator.checkEntity(snap, id, isIdEmbeddedInURL(id));
    String task = UUID.randomUUID().toString();
    if (!CifsShareUtility.doesShareExist(snap, shareName)) {
        _log.error("CIFS share does not exist", shareName);
        throw APIException.notFound.invalidParameterObjectHasNoSuchShare(id, shareName);
    }
    SMBFileShare smbShare = snap.getSMBFileShares().get(shareName);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE);
    FileSMBShare fileSMBShare = new FileSMBShare(shareName, smbShare.getDescription(), smbShare.getPermissionType(), smbShare.getPermission(), Integer.toString(smbShare.getMaxUsers()), smbShare.getNativeId(), smbShare.getPath());
    FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.deleteShare(device.getId(), snap.getId(), fileSMBShare, task);
    auditOp(OperationTypeEnum.DELETE_FILE_SNAPSHOT_SHARE, true, AuditLogManager.AUDITOP_BEGIN, smbShare.getName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getMaxUsers(), smbShare.getDescription(), snap.getId().toString());
    return toTask(snap, task, op);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) Operation(com.emc.storageos.db.client.model.Operation) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare) 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)

Aggregations

Snapshot (com.emc.storageos.db.client.model.Snapshot)92 FileShare (com.emc.storageos.db.client.model.FileShare)59 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)52 URI (java.net.URI)36 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)34 ControllerException (com.emc.storageos.volumecontroller.ControllerException)34 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)31 ArrayList (java.util.ArrayList)24 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)23 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)22 FileObject (com.emc.storageos.db.client.model.FileObject)21 URISyntaxException (java.net.URISyntaxException)21 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)19 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)19 WorkflowException (com.emc.storageos.workflow.WorkflowException)19 MapFileSnapshot (com.emc.storageos.api.mapper.functions.MapFileSnapshot)18 Path (javax.ws.rs.Path)18 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)17 Produces (javax.ws.rs.Produces)17