use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class BlockService method getVolumesForVirtualArrayChange.
/**
* Get Volumes For Virtual Array Change
*
* @param projectURI
* the URI of a ViPR project
*
* @param varrayURI
* the URI of a ViPR vArray
*
* @brief Show potential volumes for virtual array change
*
* @return Get Volume for Virtual Array Change
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/varray-change")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public NamedVolumesList getVolumesForVirtualArrayChange(@QueryParam("project") URI projectURI, @QueryParam("targetVarray") URI varrayURI) {
NamedVolumesList volumeList = new NamedVolumesList();
// Get the project.
ArgValidator.checkFieldUriType(projectURI, Project.class, "project");
Project project = _permissionsHelper.getObjectById(projectURI, Project.class);
ArgValidator.checkEntity(project, projectURI, false);
_log.info("Found project {}:{}", projectURI);
// Verify the user is authorized for the project.
BlockServiceUtils.verifyUserIsAuthorizedForRequest(project, getUserFromContext(), _permissionsHelper);
_log.info("User is authorized for project");
// Get the target virtual array.
ArgValidator.checkFieldUriType(varrayURI, VirtualArray.class, "targetVarray");
VirtualArray tgtVarray = _permissionsHelper.getObjectById(varrayURI, VirtualArray.class);
ArgValidator.checkEntity(tgtVarray, varrayURI, false);
_log.info("Found target virtual array {}:{}", tgtVarray.getLabel(), varrayURI);
// Determine all volumes in the project that could potentially
// be moved to the target virtual array.
URIQueryResultList volumeIds = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getProjectVolumeConstraint(projectURI), volumeIds);
Iterator<Volume> volumeItr = _dbClient.queryIterativeObjects(Volume.class, volumeIds);
while (volumeItr.hasNext()) {
Volume volume = volumeItr.next();
try {
// Don't operate on VPLEX backend, RP Journal volumes,
// or other internal volumes.
BlockServiceUtils.validateNotAnInternalBlockObject(volume, false);
// Don't operate on ingested volumes.
VolumeIngestionUtil.checkOperationSupportedOnIngestedVolume(volume, ResourceOperationTypeEnum.CHANGE_BLOCK_VOLUME_VARRAY, _dbClient);
// Can't change to the same varray.
if (volume.getVirtualArray().equals(varrayURI)) {
_log.info("Virtual array change not supported for volume {} already in the target varray", volume.getId());
continue;
}
// Get the appropriate block service implementation.
BlockServiceApi blockServiceAPI = getBlockServiceImpl(volume);
// Verify that the virtual array change is allowed for the
// volume and target virtual array.
blockServiceAPI.verifyVarrayChangeSupportedForVolumeAndVarray(volume, tgtVarray);
// If so, add it to the list.
volumeList.getVolumes().add(toNamedRelatedResource(volume));
} catch (Exception e) {
_log.info("Virtual array change not supported for volume {}:{}", volume.getId(), e.getMessage());
}
}
return volumeList;
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class BlockSnapshotService method getTenantOwner.
@Override
protected URI getTenantOwner(URI id) {
BlockSnapshot snapshot = (BlockSnapshot) queryResource(id);
URI projectUri = snapshot.getProject().getURI();
ArgValidator.checkUri(projectUri);
Project project = _permissionsHelper.getObjectById(projectUri, Project.class);
ArgValidator.checkEntityNotNull(project, projectUri, isIdEmbeddedInURL(projectUri));
return project.getTenantOrg().getURI();
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class BucketService method createBucket.
/**
* Creates bucket.
*
* <p>
* NOTE: This is an asynchronous operation.
*
* @param param Bucket parameters
* @param id the URN of a ViPR Project
* @brief Create bucket
* @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 createBucket(BucketParam param, @QueryParam("project") URI id) throws InternalException {
// check project
ArgValidator.checkFieldUriType(id, Project.class, "project");
// Check for all mandatory field
ArgValidator.checkFieldNotNull(param.getLabel(), "name");
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());
final String namespace = tenant.getNamespace();
if (null == namespace || namespace.isEmpty()) {
throw APIException.badRequests.objNoNamespaceForTenant(tenant.getId());
}
// Check if there already exist a bucket with same name in a Project.
checkForDuplicateName(param.getLabel().replaceAll(SPECIAL_CHAR_REGEX, ""), Bucket.class, id, "project", _dbClient);
return initiateBucketCreation(param, project, tenant, null);
}
use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.
the class ExportGroupService method validateInitiatorsData.
/**
* Validates that the host belongs to same tenant org and/or project as the export group.
* Also validates that the host has connectivity to all the storage systems that the
* export group has block objects in.
*
* @param host the host being validated
* @param exportGroup the export group where the host will be added
* @param storageSystems the storage systems the export group has block objects in.
* @param project the export group project
* @param initiators the list of initiators to be updated with the host initiators.
*/
private void validateInitiatorsData(List<Initiator> initiators, Set<URI> initiatorsHosts, ExportGroup exportGroup) {
if (initiatorsHosts.size() != 1) {
throw APIException.badRequests.initiatorExportGroupInitiatorsBelongToSameHost();
}
Host host = queryObject(Host.class, initiatorsHosts.iterator().next(), true);
// if the host is in a project
if (!NullColumnValueGetter.isNullURI(host.getProject())) {
// validate it is in the same project as the as the export group,
if (!host.getProject().equals(exportGroup.getProject().getURI())) {
throw APIException.badRequests.invalidParameterExportGroupHostAssignedToDifferentProject(host.getHostName(), exportGroup.getProject().getName());
}
} else {
// validate the host is in the same tenant Org as the as the export group,
Project project = queryObject(Project.class, exportGroup.getProject().getURI(), true);
if (!host.getTenant().equals(project.getTenantOrg().getURI())) {
throw APIException.badRequests.invalidParameterExportGroupHostAssignedToDifferentTenant(host.getHostName(), project.getLabel());
}
}
validatePortConnectivity(exportGroup, initiators);
_log.info("The initiators were validated successfully.");
}
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;
}
Aggregations