Search in sources :

Example 16 with Project

use of com.emc.storageos.db.client.model.Project in project coprhd-controller by CoprHD.

the class ResourceService method isAuthorized.

// Helper function to check if the user has authorization to access the project
// This is used by all search functions
protected boolean isAuthorized(URI projectUri) {
    final StorageOSUser user = getUserFromContext();
    if (_permissionsHelper == null) {
        return false;
    }
    Project project = _permissionsHelper.getObjectById(projectUri, Project.class);
    if (project == null) {
        return false;
    }
    if ((_permissionsHelper.userHasGivenRole(user, project.getTenantOrg().getURI(), Role.SYSTEM_MONITOR, Role.TENANT_ADMIN) || _permissionsHelper.userHasGivenACL(user, projectUri, ACL.ANY))) {
        return true;
    } else {
        return false;
    }
}
Also used : Project(com.emc.storageos.db.client.model.Project) StorageOSUser(com.emc.storageos.security.authentication.StorageOSUser)

Example 17 with Project

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);
}
Also used : VirtualPoolCapabilityValuesWrapper(com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper) Project(com.emc.storageos.db.client.model.Project) VirtualPool(com.emc.storageos.db.client.model.VirtualPool)

Example 18 with Project

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);
}
Also used : Project(com.emc.storageos.db.client.model.Project) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 19 with Project

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);
}
Also used : Project(com.emc.storageos.db.client.model.Project) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 20 with Project

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;
}
Also used : FilePolicy(com.emc.storageos.db.client.model.FilePolicy) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) 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) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) Project(com.emc.storageos.db.client.model.Project) StringSet(com.emc.storageos.db.client.model.StringSet) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) FilePolicyFileSystemAssignParam(com.emc.storageos.model.file.policy.FilePolicyFileSystemAssignParam) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

Project (com.emc.storageos.db.client.model.Project)190 URI (java.net.URI)98 NamedURI (com.emc.storageos.db.client.model.NamedURI)93 ArrayList (java.util.ArrayList)67 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)65 Volume (com.emc.storageos.db.client.model.Volume)57 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)54 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)50 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)47 StringSet (com.emc.storageos.db.client.model.StringSet)43 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)40 List (java.util.List)37 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)36 Produces (javax.ws.rs.Produces)34 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)33 Test (org.junit.Test)31 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)27 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)27 Operation (com.emc.storageos.db.client.model.Operation)26 Consumes (javax.ws.rs.Consumes)26