use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class FileDeviceController method createFS.
@Override
public void createFS(URI storage, URI pool, URI fs, String nativeId, String opId) throws ControllerException {
FileObject fileObject = null;
FileShare fsObj = null;
StorageSystem storageObj = null;
try {
ControllerUtils.setThreadLocalLogData(fs, opId);
storageObj = _dbClient.queryObject(StorageSystem.class, storage);
String[] params = { storage.toString(), pool.toString(), fs.toString() };
_log.info("Create FS: {}, {}, {}", params);
StoragePool poolObj = _dbClient.queryObject(StoragePool.class, pool);
fsObj = _dbClient.queryObject(FileShare.class, fs);
VirtualPool vPool = _dbClient.queryObject(VirtualPool.class, fsObj.getVirtualPool());
fileObject = fsObj;
FileDeviceInputOutput args = new FileDeviceInputOutput();
args.addFileShare(fsObj);
args.addStoragePool(poolObj);
args.setVPool(vPool);
args.setNativeDeviceFsId(nativeId);
args.setOpId(opId);
Project proj = _dbClient.queryObject(Project.class, fsObj.getProject());
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, fsObj.getTenant());
setVirtualNASinArgs(fsObj.getVirtualNAS(), args);
args.setTenantOrg(tenant);
args.setProject(proj);
// work flow and we need to add TaskCompleter(TBD for vnxfile)
WorkflowStepCompleter.stepExecuting(opId);
acquireStepLock(storageObj, opId);
BiosCommandResult result = getDevice(storageObj.getSystemType()).doCreateFS(storageObj, args);
if (!result.getCommandPending()) {
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
} else {
// we need to add task completer
fsObj.getOpStatus().updateTaskStatus(opId, result.toOperation());
}
if (result.isCommandSuccess()) {
fsObj.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(_dbClient, fsObj));
fsObj.setInactive(false);
WorkflowStepCompleter.stepSucceded(opId);
} else if (!result.getCommandPending()) {
fsObj.setInactive(true);
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
_dbClient.updateObject(fsObj);
if (!result.getCommandPending()) {
recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM, result.isCommandSuccess(), "", "", fsObj);
}
} catch (Exception e) {
String[] params = { storage.toString(), pool.toString(), fs.toString(), e.getMessage() };
_log.error("Unable to create file system: storage {}, pool {}, FS {}: {}", params);
// work flow fail
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
if ((fsObj != null) && (storageObj != null)) {
fsObj.setInactive(true);
_dbClient.updateObject(fsObj);
recordFileDeviceOperation(_dbClient, OperationTypeEnum.CREATE_FILE_SYSTEM, false, e.getMessage(), "", fsObj, storageObj);
}
updateTaskStatus(opId, fileObject, e);
}
}
use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class FileDeviceController method assignFileSnapshotPolicyToProjects.
@Override
public void assignFileSnapshotPolicyToProjects(URI storageSystemURI, URI vNASURI, URI filePolicyToAssign, URI vpoolURI, URI projectURI, String opId) throws InternalException {
try {
WorkflowStepCompleter.stepExecuting(opId);
FileDeviceInputOutput args = new FileDeviceInputOutput();
StorageSystem storageObj = _dbClient.queryObject(StorageSystem.class, storageSystemURI);
FilePolicy filePolicy = _dbClient.queryObject(FilePolicy.class, filePolicyToAssign);
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, vpoolURI);
Project project = _dbClient.queryObject(Project.class, projectURI);
TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, project.getTenantOrg());
if (vNASURI != null) {
VirtualNAS vNAS = _dbClient.queryObject(VirtualNAS.class, vNASURI);
args.setvNAS(vNAS);
}
args.setFileProtectionPolicy(filePolicy);
args.setVPool(vpool);
args.setProject(project);
args.setTenantOrg(tenant);
_log.info("Assigning file snapshot policy: {} to vpool {} and project: {}", filePolicyToAssign, vpoolURI, projectURI);
BiosCommandResult result = getDevice(storageObj.getSystemType()).checkFilePolicyExistsOrCreate(storageObj, args);
if (result.getCommandPending()) {
return;
}
if (!result.isCommandSuccess() && !result.getCommandPending()) {
WorkflowStepCompleter.stepFailed(opId, result.getServiceCoded());
}
if (result.isCommandSuccess()) {
WorkflowStepCompleter.stepSucceded(opId);
}
} catch (Exception e) {
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
WorkflowStepCompleter.stepFailed(opId, serviceError);
}
}
use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class TaggedResource method getTenantIfHaveAccess.
/**
* Get tenant object from id
*
* it will also check if user have access to the tenant, return the tenant if:
* 1. it is user's home tenant
* 2. it is a subtenant which user has tenant role.
*
* or else throw insufficient permission exception.
*
* @param tenantId the URN of a ViPR tenant
* @return
*/
protected TenantOrg getTenantIfHaveAccess(String tenantId) {
if (!StringUtils.isEmpty(tenantId)) {
URI tenantUri = URI.create(tenantId);
TenantOrg org = _permissionsHelper.getObjectById(tenantUri, TenantOrg.class);
ArgValidator.checkEntity(org, tenantUri, isIdEmbeddedInURL(tenantUri), true);
// check user has access to the input tenant
StorageOSUser user = getUserFromContext();
if (org.getId().toString().equals(user.getTenantId())) {
return org;
} else {
for (String subTenantId : _permissionsHelper.getSubtenantsForUser(user)) {
if (org.getId().toString().equals(subTenantId)) {
return org;
}
}
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
}
return null;
}
use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class TenantsService method listSubTenants.
/**
* List subtenants
*
* @param id the URN of a ViPR Tenant
* @prereq none
* @brief List subtenants
* @return List of subtenants
*/
@GET
@Path("/{id}/subtenants")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public TenantOrgList listSubTenants(@PathParam("id") URI id) {
StorageOSUser user = getUserFromContext();
TenantOrg tenant = getTenantById(id, false);
TenantOrgList list = new TenantOrgList();
if (!TenantOrg.isRootTenant(tenant)) {
// no subtenants if not root tenant
throw APIException.methodNotAllowed.notSupportedForSubtenants();
}
NamedElementQueryResultList subtenants = new NamedElementQueryResultList();
if (_permissionsHelper.userHasGivenRole(user, tenant.getId(), Role.SYSTEM_MONITOR, Role.TENANT_ADMIN, Role.SECURITY_ADMIN, Role.SYSTEM_ADMIN)) {
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getTenantOrgSubTenantConstraint(tenant.getId()), subtenants);
} else {
// we will most likely not need indexing for tenants
// given the number of tenants is not going to be that many
Set<String> roles = new HashSet<String>();
roles.add(Role.TENANT_ADMIN.toString());
Map<URI, Set<String>> allTenantPermissions = _permissionsHelper.getAllPermissionsForUser(user, tenant.getId(), roles, true);
if (!allTenantPermissions.keySet().isEmpty()) {
List<TenantOrg> tenants = _dbClient.queryObjectField(TenantOrg.class, "label", new ArrayList<URI>(allTenantPermissions.keySet()));
List<NamedElementQueryResultList.NamedElement> elements = new ArrayList<NamedElementQueryResultList.NamedElement>(tenants.size());
for (TenantOrg t : tenants) {
elements.add(NamedElementQueryResultList.NamedElement.createElement(t.getId(), t.getLabel()));
}
subtenants.setResult(elements.iterator());
} else {
throw APIException.forbidden.insufficientPermissionsForUser(user.getName());
}
}
for (NamedElementQueryResultList.NamedElement el : subtenants) {
list.getSubtenants().add(toNamedRelatedResource(ResourceTypeEnum.TENANT, el.getId(), el.getName()));
}
return list;
}
use of com.emc.storageos.db.client.model.TenantOrg in project coprhd-controller by CoprHD.
the class TenantsService method createProject.
/**
* Worker method for create project. Allows external requests (REST) as well as
* internal requests that may not have a security context.
*
* @param id tenant id
* @param param project params
* @param owner name of owner of the request
* @param ownerTenantId tenant id of the owner
* @return project details
*/
public ProjectElement createProject(URI id, ProjectParam param, String owner, String ownerTenantId) {
TenantOrg tenant = getTenantById(id, true);
if (param.getName() != null && !param.getName().isEmpty()) {
checkForDuplicateName(param.getName(), Project.class, id, "tenantOrg", _dbClient);
}
Project project = new Project();
project.setId(URIUtil.createId(Project.class));
project.setLabel(param.getName());
project.setTenantOrg(new NamedURI(tenant.getId(), project.getLabel()));
project.setOwner(owner);
// set owner acl
project.addAcl(new PermissionsKey(PermissionsKey.Type.SID, owner, ownerTenantId).toString(), ACL.OWN.toString());
_dbClient.createObject(project);
recordTenantEvent(OperationTypeEnum.CREATE_PROJECT, tenant.getId(), project.getId());
return new ProjectElement(project.getId(), toLink(ResourceTypeEnum.PROJECT, project.getId()), project.getLabel());
}
Aggregations