Search in sources :

Example 1 with TenantOrg

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);
    }
}
Also used : ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) StoragePool(com.emc.storageos.db.client.model.StoragePool) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) Project(com.emc.storageos.db.client.model.Project) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FileObject(com.emc.storageos.db.client.model.FileObject) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 2 with TenantOrg

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);
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) FileDeviceInputOutput(com.emc.storageos.volumecontroller.FileDeviceInputOutput) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) URISyntaxException(java.net.URISyntaxException) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) WorkflowException(com.emc.storageos.workflow.WorkflowException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 3 with TenantOrg

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;
}
Also used : StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) URI(java.net.URI)

Example 4 with TenantOrg

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) AbstractChangeTrackingSet(com.emc.storageos.db.client.model.AbstractChangeTrackingSet) StringSet(com.emc.storageos.db.client.model.StringSet) ArrayList(java.util.ArrayList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) TenantOrgList(com.emc.storageos.model.tenant.TenantOrgList) NamedElementQueryResultList(com.emc.storageos.db.client.constraint.NamedElementQueryResultList) HashSet(java.util.HashSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with TenantOrg

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());
}
Also used : Project(com.emc.storageos.db.client.model.Project) NamedURI(com.emc.storageos.db.client.model.NamedURI) ProjectElement(com.emc.storageos.model.project.ProjectElement) PermissionsKey(com.emc.storageos.security.authorization.PermissionsKey) TenantOrg(com.emc.storageos.db.client.model.TenantOrg)

Aggregations

TenantOrg (com.emc.storageos.db.client.model.TenantOrg)138 URI (java.net.URI)64 NamedURI (com.emc.storageos.db.client.model.NamedURI)57 Project (com.emc.storageos.db.client.model.Project)54 Volume (com.emc.storageos.db.client.model.Volume)41 ArrayList (java.util.ArrayList)40 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)37 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)34 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)33 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)29 StringSet (com.emc.storageos.db.client.model.StringSet)29 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)28 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)26 Produces (javax.ws.rs.Produces)26 StoragePool (com.emc.storageos.db.client.model.StoragePool)25 List (java.util.List)23 Test (org.junit.Test)23 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)22 StringMap (com.emc.storageos.db.client.model.StringMap)21 Consumes (javax.ws.rs.Consumes)21