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 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 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 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;
}
Aggregations