use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class ResourceService method isAuthorized.
// Helper function to check if the user has authorization to access the project
// This is used by all search functions
protected boolean isAuthorized(URI projectUri) {
final StorageOSUser user = getUserFromContext();
if (_permissionsHelper == null) {
return false;
}
Project project = _permissionsHelper.getObjectById(projectUri, Project.class);
if (project == null) {
return false;
}
if ((_permissionsHelper.userHasGivenRole(user, project.getTenantOrg().getURI(), Role.SYSTEM_MONITOR, Role.TENANT_ADMIN) || _permissionsHelper.userHasGivenACL(user, projectUri, ACL.ANY))) {
return true;
} else {
return false;
}
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class FileService method getFileShareServiceImpl.
/**
* Returns the bean responsible for servicing the request
*
* @param fileShare
* fileshare
* @param dbClient
* db client
* @return file service implementation object
*/
public static FileServiceApi getFileShareServiceImpl(FileShare fileShare, DbClient dbClient) {
VirtualPool vPool = dbClient.queryObject(VirtualPool.class, fileShare.getVirtualPool());
Project project = dbClient.queryObject(Project.class, fileShare.getProject().getURI());
VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_REPLICATION_TYPE, VirtualPool.FileReplicationType.NONE.name());
StringBuilder errorMsg = new StringBuilder();
if (vPool.getFileReplicationSupported()) {
FilePolicyServiceUtils.updateReplicationTypeCapabilities(dbClient, vPool, project, fileShare, capabilities, errorMsg);
}
return getFileServiceImpl(capabilities, dbClient);
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class FileService method expand.
/**
* 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 Expand file system
* @return Task resource representation
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/expand")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep expand(@PathParam("id") URI id, FileSystemExpandParam param) throws InternalException {
_log.info(String.format("FileShareExpand --- FileShare id: %1$s, New Size: %2$s", id, param.getNewSize()));
// check file System
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
Long newFSsize = SizeUtil.translateSize(param.getNewSize());
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
if (newFSsize <= 0) {
throw APIException.badRequests.parameterMustBeGreaterThan("new_size", 0);
}
// checkQuota
long expand = newFSsize - fs.getCapacity();
final long MIN_EXPAND_SIZE = SizeUtil.translateSize("1MB") + 1;
if (expand < MIN_EXPAND_SIZE) {
throw APIException.badRequests.invalidParameterBelowMinimum("new_size", newFSsize, fs.getCapacity() + MIN_EXPAND_SIZE, "bytes");
}
Project project = _dbClient.queryObject(Project.class, fs.getProject().getURI());
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, fs.getTenant().getURI());
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
CapacityUtils.validateQuotasForProvisioning(_dbClient, vpool, project, tenant, expand, "filesystem");
String task = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.EXPAND_FILE_SYSTEM);
op.setDescription("Filesystem expand");
FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
try {
fileServiceApi.expandFileShare(fs, newFSsize, task);
} catch (InternalException e) {
if (_log.isErrorEnabled()) {
_log.error("Expand File Size error", e);
}
FileShare fileShare = _dbClient.queryObject(FileShare.class, fs.getId());
op = fs.getOpStatus().get(task);
op.error(e);
fileShare.getOpStatus().updateTaskStatus(task, op);
_dbClient.updateObject(fs);
throw e;
}
return toTask(fs, task, op);
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class FileService method createFileSystem.
/**
* Creates file system.
*
* The VNX File array does not allow 'root' as the beginning of a file system name. If the generated file system
* name begins with 'root', then the VNX File array will return an error.
* <p>
* NOTE: This is an asynchronous operation.
*
* @param param
* File system parameters
* @param id
* the URN of a ViPR Project
* @brief Create file system
* @return Task resource representation
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep createFileSystem(FileSystemParam param, @QueryParam("project") URI id) throws InternalException {
// check project
ArgValidator.checkFieldUriType(id, Project.class, "project");
// Make label as mandatory field
ArgValidator.checkFieldNotNull(param.getLabel(), "label");
Project project = _permissionsHelper.getObjectById(id, Project.class);
ArgValidator.checkEntity(project, id, isIdEmbeddedInURL(id));
ArgValidator.checkFieldNotNull(project.getTenantOrg(), "project");
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg().getURI());
// Check for duplicate file system in this project
if (param.getLabel() != null && !param.getLabel().isEmpty()) {
checkForDuplicateName(param.getLabel(), FileShare.class, id, "project", _dbClient);
}
return createFSInternal(param, project, tenant, null);
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class FileService method changeFileSystemVirtualPool.
/**
* Change File System Virtual Pool
*
* @param id
* the URN of a ViPR fileSystem
* @param param
* File System Virtual Pool Change parameter
* @brief Change a file systems virtual pool
* @desc Add the file system to a different virtual pool.
* @return TaskResponse
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/vpool-change")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep changeFileSystemVirtualPool(@PathParam("id") URI id, FileSystemVirtualPoolChangeParam param) {
_log.info("Request to change VirtualPool for filesystem {}", id);
StringBuilder errorMsg = new StringBuilder();
// Validate the FS id.
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
String task = UUID.randomUUID().toString();
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
// Make sure that we don't have some pending
// operation against the file system!!!
checkForPendingTasks(Arrays.asList(fs.getTenant().getURI()), Arrays.asList(fs));
// Get the project.
URI projectURI = fs.getProject().getURI();
Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
ArgValidator.checkEntity(project, projectURI, false);
_log.info("Found filesystem project {}", projectURI);
// Get the VirtualPool for the request and verify that the
// project's tenant has access to the VirtualPool.
VirtualPool newVpool = getVirtualPoolForRequest(project, param.getVirtualPool(), _dbClient, _permissionsHelper);
_log.info("Found new VirtualPool {}", newVpool.getId());
VirtualPool currentVpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
StringBuffer notSuppReasonBuff = new StringBuffer();
// Verify the vPool change is supported!!!
if (!VirtualPoolChangeAnalyzer.isSupportedFileReplicationChange(currentVpool, newVpool, notSuppReasonBuff)) {
_log.error("Virtual Pool change is not supported due to {}", notSuppReasonBuff.toString());
throw APIException.badRequests.invalidVirtualPoolForVirtualPoolChange(newVpool.getLabel(), notSuppReasonBuff.toString());
}
ArgValidator.checkFieldUriType(param.getFilePolicy(), FilePolicy.class, "file_policy");
FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, param.getFilePolicy());
ArgValidator.checkEntity(filePolicy, param.getFilePolicy(), true);
StringSet existingFSPolicies = fs.getFilePolicies();
if (existingFSPolicies != null && existingFSPolicies.contains(param.getFilePolicy().toString())) {
errorMsg.append("Provided file policy:" + filePolicy.getId() + " is already is applied to the file system:" + fs.getId());
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidVirtualPoolForVirtualPoolChange(newVpool.getLabel(), errorMsg.toString());
}
// check if same TYPE of policy already applied to file system
if (filePolicy.getFilePolicyType().equals(FilePolicy.FilePolicyType.file_replication.name()) && existingFSPolicies != null && !existingFSPolicies.isEmpty()) {
checkForDuplicatePolicyApplied(filePolicy, existingFSPolicies);
}
// Check if the target vpool supports provided policy type..
FilePolicyServiceUtils.validateVpoolSupportPolicyType(filePolicy, newVpool);
// Check if the vpool supports policy at file system level..
if (!newVpool.getAllowFilePolicyAtFSLevel()) {
errorMsg.append("Provided vpool :" + newVpool.getLabel() + " doesn't support policy at file system level");
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidVirtualPoolForVirtualPoolChange(newVpool.getLabel(), errorMsg.toString());
}
// only single replication policy per vpool/project/fs.
if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name()) && FilePolicyServiceUtils.fsHasReplicationPolicy(_dbClient, newVpool.getId(), fs.getProject().getURI(), fs.getId())) {
errorMsg.append("Provided vpool/project/fs has already assigned with replication policy.");
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidVirtualPoolForVirtualPoolChange(newVpool.getLabel(), errorMsg.toString());
}
if (FilePolicyServiceUtils.fsHasSnapshotPolicyWithSameSchedule(_dbClient, fs.getId(), filePolicy)) {
errorMsg.append("Snapshot policy with similar schedule is already present on fs " + fs.getLabel());
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidVirtualPoolForVirtualPoolChange(newVpool.getLabel(), errorMsg.toString());
}
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CHANGE_FILE_SYSTEM_VPOOL);
op.setDescription("Change vpool operation");
op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, op);
TaskResourceRep fileSystemTask = toTask(fs, task, op);
try {
// Change the virtual pool of source file system!!
fs.setVirtualPool(newVpool.getId());
_dbClient.updateObject(fs);
FilePolicyFileSystemAssignParam policyAssignParam = new FilePolicyFileSystemAssignParam();
policyAssignParam.setTargetVArrays(param.getTargetVArrays());
if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_replication.name())) {
return assignFileReplicationPolicyToFS(fs, filePolicy, policyAssignParam, task);
} else if (filePolicy.getFilePolicyType().equals(FilePolicyType.file_snapshot.name())) {
return assignFilePolicyToFS(fs, filePolicy, task);
}
} catch (BadRequestException e) {
op = _dbClient.error(FileShare.class, fs.getId(), task, e);
_log.error("Change vpool operation failed {}, {}", e.getMessage(), e);
throw e;
} catch (Exception e) {
_log.error("Change vpool operation failed {}, {}", e.getMessage(), e);
// revert the virtual pool of source file system!!
fs.setVirtualPool(currentVpool.getId());
_dbClient.updateObject(fs);
throw APIException.badRequests.unableToProcessRequest(e.getMessage());
}
return fileSystemTask;
}
Aggregations