use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class ControllerUtils method getProjectTenantOrgURI.
/**
* Gets the URI of the tenant organization for the project with the passed
* URI.
*
* @param dbClient A reference to the database client.
* @param projectURI The URI for the project.
*
* @return The URI of the tenant organization.
*/
public static URI getProjectTenantOrgURI(DbClient dbClient, URI projectURI) {
URI tenantOrgURI = null;
try {
s_logger.debug("Getting the URI of the tenant for project {}.", projectURI);
// Get the Project with the passed URI from the database and extract
// the tenant organization for the project.
Project project = dbClient.queryObject(Project.class, projectURI);
if (project != null) {
tenantOrgURI = project.getTenantOrg().getURI();
if (tenantOrgURI == null) {
s_logger.warn("The tenant URI is null for project {}.", projectURI);
}
} else {
s_logger.warn("The database returned a null project for URI {}.", projectURI);
}
} catch (Exception e) {
s_logger.warn("Exception fetching project {} from the database.", projectURI, e);
}
// Use the default provider tenant if the tenant cannot be determined.
if (tenantOrgURI == null) {
tenantOrgURI = URI.create(TenantOrg.PROVIDER_TENANT_ORG);
}
s_logger.debug("Returning tenant {} for project {}.", new Object[] { tenantOrgURI, projectURI });
return tenantOrgURI;
}
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 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 FilePolicyService method assignFilePolicyToProjects.
/**
* Assign policy at project level
*
* @param param
* @param filepolicy
*/
private TaskResourceRep assignFilePolicyToProjects(FilePolicyAssignParam param, FilePolicy filePolicy) {
StringBuilder errorMsg = new StringBuilder();
StringBuilder recommendationErrorMsg = new StringBuilder();
ArgValidator.checkFieldNotNull(param.getProjectAssignParams(), "project_assign_param");
ArgValidator.checkFieldUriType(param.getProjectAssignParams().getVpool(), VirtualPool.class, "vpool");
URI vpoolURI = param.getProjectAssignParams().getVpool();
VirtualPool vpool = null;
if (NullColumnValueGetter.isNullURI(filePolicy.getFilePolicyVpool())) {
ArgValidator.checkFieldUriType(vpoolURI, VirtualPool.class, "vpool");
vpool = _permissionsHelper.getObjectById(vpoolURI, VirtualPool.class);
ArgValidator.checkEntity(vpool, vpoolURI, false);
// Check if the vpool supports provided policy type..
FilePolicyServiceUtils.validateVpoolSupportPolicyType(filePolicy, vpool);
// Check if the vpool supports policy at project level..
if (!vpool.getAllowFilePolicyAtProjectLevel()) {
errorMsg.append("Provided vpool :" + vpool.getLabel() + " doesn't support policy at project level");
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
}
} else if (vpoolURI != null) {
vpool = _dbClient.queryObject(VirtualPool.class, filePolicy.getFilePolicyVpool());
if (!vpoolURI.equals(filePolicy.getFilePolicyVpool())) {
errorMsg.append("File policy: " + filePolicy.getFilePolicyName() + " is already assigned at project level under the vpool: " + vpool.getLabel());
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
}
}
ArgValidator.checkFieldNotEmpty(param.getProjectAssignParams().getAssigntoProjects(), "assign_to_projects");
Set<URI> projectURIs = param.getProjectAssignParams().getAssigntoProjects();
List<URI> filteredProjectURIs = new ArrayList<URI>();
for (URI projectURI : projectURIs) {
ArgValidator.checkFieldUriType(projectURI, Project.class, "project");
Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
ArgValidator.checkEntity(project, projectURI, false);
if (filePolicy.getAssignedResources() != null && filePolicy.getAssignedResources().contains(project.getId().toString())) {
_log.info("Policy {} is already assigned to project {} ", filePolicy.getFilePolicyName(), project.getLabel());
continue;
}
// only single replication policy per vpool-project combination.
if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_replication.name()) && FilePolicyServiceUtils.projectHasReplicationPolicy(_dbClient, projectURI, vpool.getId())) {
errorMsg.append("Virtual pool " + vpool.getLabel() + " project " + project.getLabel() + "pair is already assigned with replication policy.");
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
}
if (filePolicy.getFilePolicyType().equalsIgnoreCase(FilePolicyType.file_snapshot.name()) && FilePolicyServiceUtils.projectHasSnapshotPolicyWithSameSchedule(_dbClient, projectURI, vpool.getId(), filePolicy)) {
errorMsg.append("Snapshot policy with similar schedule is already present on project " + project.getLabel());
_log.error(errorMsg.toString());
throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), errorMsg.toString());
}
filteredProjectURIs.add(projectURI);
}
if (param.getApplyOnTargetSite() != null) {
filePolicy.setApplyOnTargetSite(param.getApplyOnTargetSite());
}
// Verify the virtual pool has storage pools!!!
List<URI> storageSystems = getAssociatedStorageSystemsByVPool(vpool);
if (storageSystems == null || storageSystems.isEmpty()) {
String errorMessage = "No matching storage pools exists for given vpools ";
_log.error(errorMessage);
throw APIException.badRequests.noStoragePoolsExists(vpool.getLabel());
}
String task = UUID.randomUUID().toString();
TaskResourceRep taskResponse = createAssignFilePolicyTask(filePolicy, task);
FileServiceApi fileServiceApi = getDefaultFileServiceApi();
FilePolicyType policyType = FilePolicyType.valueOf(filePolicy.getFilePolicyType());
switch(policyType) {
case file_snapshot:
Map<URI, List<URI>> vpoolToStorageSystemMap = new HashMap<URI, List<URI>>();
vpoolToStorageSystemMap.put(vpoolURI, getAssociatedStorageSystemsByVPool(vpool));
AssignFileSnapshotPolicyToProjectSchedulingThread.executeApiTask(this, _asyncTaskService.getExecutorService(), _dbClient, filePolicy.getId(), vpoolToStorageSystemMap, filteredProjectURIs, fileServiceApi, taskResponse, task);
break;
case file_replication:
if (filteredProjectURIs.isEmpty()) {
throw APIException.badRequests.invalidFilePolicyAssignParam(filePolicy.getFilePolicyName(), "No projects to assign to policy.");
}
// update replication topology info
updateFileReplicationTopologyInfo(param, filePolicy);
List<URI> validRecommendationProjects = new ArrayList<URI>();
List<FileStorageSystemAssociation> associations = new ArrayList<FileStorageSystemAssociation>();
VirtualPoolCapabilityValuesWrapper capabilities = new VirtualPoolCapabilityValuesWrapper();
StringSet sourceVArraysSet = getSourceVArraySet(vpool, filePolicy);
updatePolicyCapabilities(_dbClient, sourceVArraysSet, vpool, filePolicy, capabilities, errorMsg);
// Replication policy has to be created on each applicable source storage system!!
if (storageSystems != null && !storageSystems.isEmpty()) {
for (Iterator<String> iterator = sourceVArraysSet.iterator(); iterator.hasNext(); ) {
String vArrayURI = iterator.next();
for (URI projectURI : filteredProjectURIs) {
List<FileStorageSystemAssociation> projectAssociations = new ArrayList<FileStorageSystemAssociation>();
Project project = _dbClient.queryObject(Project.class, projectURI);
VirtualArray srcVarray = _dbClient.queryObject(VirtualArray.class, URI.create(vArrayURI));
for (URI storageSystem : storageSystems) {
capabilities.put(VirtualPoolCapabilityValuesWrapper.FILE_PROTECTION_SOURCE_STORAGE_SYSTEM, storageSystem);
try {
List<FileRecommendation> newRecs = _filePlacementManager.getRecommendationsForFileCreateRequest(srcVarray, project, vpool, capabilities);
if (newRecs != null && !newRecs.isEmpty()) {
projectAssociations.addAll(convertRecommendationsToStorageSystemAssociations(newRecs, filePolicy.getApplyAt(), vpool.getId(), projectURI));
}
} catch (Exception ex) {
_log.error("No recommendations found for storage system {} and virtualArray {} with error {} ", storageSystem, srcVarray.getLabel(), ex.getMessage());
if (ex.getMessage() != null) {
recommendationErrorMsg.append(ex.getMessage());
}
// Continue to get the recommedations for next storage system!!
continue;
}
}
if (!projectAssociations.isEmpty()) {
associations.addAll(projectAssociations);
validRecommendationProjects.add(projectURI);
}
}
}
} else {
String errorMessage = "No matching storage pools exists for vpool " + vpool.getLabel();
_log.error(errorMessage);
recommendationErrorMsg.append(errorMessage);
}
// Throw an exception!!
if (associations == null || associations.isEmpty()) {
// If no other resources are assigned to replication policy
// Remove the replication topology from the policy
FileOrchestrationUtils.removeTopologyInfo(filePolicy, _dbClient);
_log.error("No matching storage pools recommendations found for policy {} with due to {}", filePolicy.getFilePolicyName(), recommendationErrorMsg.toString());
throw APIException.badRequests.noFileStorageRecommendationsFound(filePolicy.getFilePolicyName());
}
fileServiceApi.assignFileReplicationPolicyToProjects(associations, vpoolURI, validRecommendationProjects, filePolicy.getId(), task);
break;
default:
break;
}
auditOp(OperationTypeEnum.ASSIGN_FILE_POLICY, true, AuditLogManager.AUDITOP_BEGIN, filePolicy.getLabel());
if (taskResponse != null) {
// As the action done by system admin
// Set system uri as task's tenant!!!
Task taskObj = _dbClient.queryObject(Task.class, taskResponse.getId());
StorageOSUser user = getUserFromContext();
URI userTenantUri = URI.create(user.getTenantId());
FilePolicyServiceUtils.updateTaskTenant(_dbClient, filePolicy, "assign", taskObj, userTenantUri);
}
return taskResponse;
}
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