use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class FileService method deleteFSExportRules.
/**
* Delete FS Export Rules
*
* Existing file system exports may have their list of export rules deleted.
*
* @param id
* the URN of a ViPR fileSystem
* @param subDir
* sub-directory within a filesystem
* @param allDirs
* All Dirs within a filesystem
* @param unmountExport
* Whether to unmount an export when deleting the rule
* @brief Delete the export rules for a file system
* @return Task resource representation
* @throws InternalException
*/
@DELETE
@Path("/{id}/export")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep deleteFSExportRules(@PathParam("id") URI id, @QueryParam("allDirs") boolean allDirs, @QueryParam("subDir") String subDir, @QueryParam("unmountExport") boolean unmountExport) {
// log input received.
_log.info("Delete Export Rules : request received for {}, with allDirs : {}, subDir : {}", new Object[] { id, allDirs, subDir });
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));
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
String path = fs.getPath();
_log.info("Export path found {} ", path);
// Before running operation check if subdirectory exists
List<FileExportRule> exportFileRulesTemp = queryDBFSExports(fs);
boolean subDirFound = false;
if (ArgValidator.checkSubDirName("subDir", subDir)) {
for (FileExportRule rule : exportFileRulesTemp) {
if (rule.getExportPath().endsWith("/" + subDir)) {
subDirFound = true;
}
}
if (!subDirFound) {
_log.info("Sub-Directory {} doesnot exists, so deletion of Sub-Directory export rule from DB failed ", subDir);
throw APIException.badRequests.subDirNotFound(subDir);
}
}
Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.UNEXPORT_FILE_SYSTEM);
op.setDescription("Filesystem unexport");
try {
FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
fileServiceApi.deleteExportRules(device.getId(), fs.getId(), allDirs, subDir, unmountExport, task);
auditOp(OperationTypeEnum.UNEXPORT_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), allDirs, subDir);
} catch (BadRequestException e) {
op = _dbClient.error(FileShare.class, fs.getId(), task, e);
_log.error("Error Processing Export Updates {}", e.getMessage(), e);
} catch (Exception e) {
_log.error("Error Processing Export Updates {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return toTask(fs, task, op);
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException 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);
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException 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);
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException 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());
}
}
use of com.emc.storageos.svcs.errorhandling.resources.BadRequestException in project coprhd-controller by CoprHD.
the class FilePolicyService method unassignFilePolicy.
/**
* Unassign File Policy
*
* @param id
* of the file policy.
* @param FilePolicyUnAssignParam
* @brief Unassign file policy from vpool, project, file system
* @return TaskResourceRep
*/
@POST
@Path("/{id}/unassign-policy")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.TENANT_ADMIN })
public TaskResourceRep unassignFilePolicy(@PathParam("id") URI id, FilePolicyUnAssignParam param) {
_log.info("Unassign File Policy :{} request received.", id);
String task = UUID.randomUUID().toString();
ArgValidator.checkFieldUriType(id, FilePolicy.class, "id");
FilePolicy filepolicy = this._dbClient.queryObject(FilePolicy.class, id);
ArgValidator.checkEntity(filepolicy, id, true);
StringBuilder errorMsg = new StringBuilder();
Operation op = _dbClient.createTaskOpStatus(FilePolicy.class, filepolicy.getId(), task, ResourceOperationTypeEnum.UNASSIGN_FILE_POLICY);
op.setDescription("unassign File Policy from resources ");
// As the action done by tenant/system admin
// Set corresponding tenant uri as task's tenant!!!
Task taskObj = op.getTask(filepolicy.getId());
StorageOSUser user = getUserFromContext();
URI userTenantUri = URI.create(user.getTenantId());
FilePolicyServiceUtils.updateTaskTenant(_dbClient, filepolicy, "unassign", taskObj, userTenantUri);
if (filepolicy.getAssignedResources() == null || filepolicy.getAssignedResources().isEmpty()) {
_log.info("File Policy: " + id + " doesn't have any assigned resources.");
_dbClient.ready(FilePolicy.class, filepolicy.getId(), task);
return toTask(filepolicy, task, op);
}
ArgValidator.checkFieldNotNull(param.getUnassignfrom(), "unassign_from");
Set<URI> unassignFrom = param.getUnassignfrom();
if (unassignFrom != null) {
for (URI uri : unassignFrom) {
canUserUnAssignPolicyAtGivenLevel(filepolicy, uri);
if (!filepolicy.getAssignedResources().contains(uri.toString())) {
errorMsg.append("Provided resource URI is either being not assigned to the file policy:" + filepolicy.getId() + " or it is a invalid URI");
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyUnAssignParam(filepolicy.getFilePolicyName(), errorMsg.toString());
}
}
}
FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
try {
controller.unassignFilePolicy(filepolicy.getId(), unassignFrom, task);
auditOp(OperationTypeEnum.UNASSIGN_FILE_POLICY, true, "BEGIN", filepolicy.getId().toString(), filepolicy.getLabel());
} catch (BadRequestException e) {
op = _dbClient.error(FilePolicy.class, filepolicy.getId(), task, e);
_log.error("Error Unassigning File policy {}, {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
_log.error("Error Unassigning Files Policy {}, {}", e.getMessage(), e);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return toTask(filepolicy, task, op);
}
Aggregations