Search in sources :

Example 31 with VirtualPool

use of com.emc.storageos.db.client.model.VirtualPool 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)

Example 32 with VirtualPool

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

the class FileService method updateFileSystemAcls.

/**
 * Update existing file system ACL
 *
 * @param id
 *            the URN of a ViPR fileSystem
 * @param param
 *            FileNfsACLUpdateParams
 * @brief Update file system ACL
 * @return Task resource representation
 * @throws InternalException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/acl")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep updateFileSystemAcls(@PathParam("id") URI id, FileNfsACLUpdateParams param) throws InternalException {
    // log input received.
    _log.info("Update FS ACL : request received for {}  with {}", id, param);
    // Validate the FS id.
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = queryResource(id);
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    // Check for VirtualPool whether it has NFS v4 enabled
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    if (!vpool.getProtocols().contains(StorageProtocol.File.NFSv4.name())) {
        // Throw an error
        throw APIException.methodNotAllowed.vPoolDoesntSupportProtocol("Vpool does not support " + StorageProtocol.File.NFSv4.name() + " protocol");
    }
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    String task = UUID.randomUUID().toString();
    String path = fs.getPath();
    _log.info("fileSystem  path {} ", path);
    Operation op = new Operation();
    try {
        _log.info("Sub Dir Provided {}", param.getSubDir());
        // Validate the input
        NfsACLUtility util = new NfsACLUtility(_dbClient, fs, null, param.getSubDir());
        util.verifyNfsACLs(param);
        _log.info("No Errors found proceeding further {}, {}, {}", new Object[] { _dbClient, fs, param });
        op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.UPDATE_FILE_SYSTEM_NFS_ACL);
        op.setDescription("Filesystem NFS ACL update");
        controller.updateNFSAcl(device.getId(), fs.getId(), param, task);
        auditOp(OperationTypeEnum.UPDATE_FILE_SYSTEM_NFS_ACL, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), param);
    } catch (BadRequestException e) {
        op = _dbClient.error(FileShare.class, fs.getId(), task, e);
        _log.error("Error Processing File System ACL Updates {}, {}", e.getMessage(), e);
        throw e;
    } catch (Exception e) {
        _log.error("Error Processing File System ACL Updates  {}, {}", e.getMessage(), e);
        throw APIException.badRequests.unableToProcessRequest(e.getMessage());
    }
    return toTask(fs, task, op);
}
Also used : FileController(com.emc.storageos.volumecontroller.FileController) BadRequestException(com.emc.storageos.svcs.errorhandling.resources.BadRequestException) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) NfsACLUtility(com.emc.storageos.api.service.impl.resource.utils.NfsACLUtility) 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) 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) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) 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)

Example 33 with VirtualPool

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

the class FileVirtualPoolService method queryFilteredBulkResourceReps.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected FileVirtualPoolBulkRep queryFilteredBulkResourceReps(List<URI> ids) {
    if (isSystemOrRestrictedSystemAdmin()) {
        return queryBulkResourceReps(ids);
    }
    if (!ids.iterator().hasNext()) {
        return new FileVirtualPoolBulkRep();
    }
    // get vdc id from the first id; assume all id's are from the same vdc
    String shortVdcId = VdcUtil.getVdcId(VirtualArray.class, ids.iterator().next()).toString();
    Iterator<VirtualPool> dbIterator;
    if (shortVdcId.equals(VdcUtil.getLocalShortVdcId())) {
        dbIterator = _dbClient.queryIterativeObjects(getResourceClass(), ids);
    } else {
        GeoServiceClient geoClient = _geoHelper.getClient(shortVdcId);
        try {
            dbIterator = geoClient.queryObjects(getResourceClass(), ids);
        } catch (Exception ex) {
            // TODO: revisit this exception
            _log.error("error retrieving bulk virtual pools from vdc " + shortVdcId, ex);
            throw APIException.internalServerErrors.genericApisvcError("error retrieving remote virtual pool", ex);
        }
    }
    BulkList.ResourceFilter filter = new BulkList.VirtualPoolFilter(Type.file, getUserFromContext(), _permissionsHelper);
    return new FileVirtualPoolBulkRep(BulkList.wrapping(dbIterator, MapFileVirtualPool.getInstance(), filter));
}
Also used : FileVirtualPoolBulkRep(com.emc.storageos.model.vpool.FileVirtualPoolBulkRep) VirtualArray(com.emc.storageos.db.client.model.VirtualArray) GeoServiceClient(com.emc.storageos.security.geo.GeoServiceClient) BulkList(com.emc.storageos.api.service.impl.response.BulkList) VirtualPoolMapper.toFileVirtualPool(com.emc.storageos.api.mapper.VirtualPoolMapper.toFileVirtualPool) MapFileVirtualPool(com.emc.storageos.api.mapper.functions.MapFileVirtualPool) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException)

Example 34 with VirtualPool

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

the class FileVirtualPoolService method createFileVirtualPool.

/**
 * Create File Store VirtualPool
 *
 * @param param VirtualPool parameters
 * @brief Create VirtualPool for a file store
 * @return VirtualPool details
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public FileVirtualPoolRestRep createFileVirtualPool(FileVirtualPoolParam param) {
    ArgValidator.checkFieldNotEmpty(param.getName(), VPOOL_NAME);
    checkForDuplicateName(param.getName(), VirtualPool.class);
    ArgValidator.checkFieldNotEmpty(param.getDescription(), VPOOL_DESCRIPTION);
    VirtualPoolUtil.validateFileVirtualPoolCreateParams(param, _dbClient);
    VirtualPool cos = prepareVirtualPool(param, true);
    if (null != param.getLongTermRetention()) {
        cos.setLongTermRetention(param.getLongTermRetention());
    }
    StringBuffer errorMessage = new StringBuffer();
    // update the implicit pools matching with this VirtualPool.
    ImplicitPoolMatcher.matchVirtualPoolWithAllStoragePools(cos, _dbClient, _coordinator, errorMessage);
    if (null != cos.getMatchedStoragePools() || null != cos.getInvalidMatchedPools()) {
        ImplicitUnManagedObjectsMatcher.matchVirtualPoolsWithUnManagedFileSystems(cos, _dbClient);
    }
    _dbClient.createObject(cos);
    recordOperation(OperationTypeEnum.CREATE_VPOOL, VPOOL_CREATED_DESCRIPTION, cos);
    return toFileVirtualPool(cos);
}
Also used : VirtualPoolMapper.toFileVirtualPool(com.emc.storageos.api.mapper.VirtualPoolMapper.toFileVirtualPool) MapFileVirtualPool(com.emc.storageos.api.mapper.functions.MapFileVirtualPool) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 35 with VirtualPool

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

the class VPlexScheduler method getRecommendationsForResources.

public List<Recommendation> getRecommendationsForResources(VirtualArray vArray, Project project, VirtualPool vPool, VirtualPoolCapabilityValuesWrapper capabilities, Map<VpoolUse, List<Recommendation>> currentRecommendations) {
    _log.info("Getting recommendations for VPlex volume placement");
    // availability volumes.
    if (!VirtualPool.HighAvailabilityType.vplex_distributed.name().equals(vPool.getHighAvailability()) && !VirtualPool.HighAvailabilityType.vplex_local.name().equals(vPool.getHighAvailability())) {
        throw APIException.badRequests.invalidHighAvailability(vPool.getHighAvailability());
    }
    _log.info("VirtualPool has high availability {}", vPool.getHighAvailability());
    Set<URI> vplexSystemsForPlacement = getVPlexSystemsForPlacement(vArray, vPool, capabilities);
    // Determine if the volume creation request is for HA volumes.
    boolean isHAVolumeRequest = VirtualPool.HighAvailabilityType.vplex_distributed.name().equals(vPool.getHighAvailability());
    // Get and validate the high availability VirtualArray and VirtualPool.
    // Note that the HA VirtualPool is optional. When not specified, the
    // high availability VirtualPool is the passed VirtualPool is use.
    VirtualPool haVPool = vPool;
    VirtualArray haVArray = null;
    StringMap haVaVpMap = vPool.getHaVarrayVpoolMap();
    if ((isHAVolumeRequest) && (haVaVpMap != null)) {
        _log.info("Is HA request and with an HA VirtualArray VirtualPool map");
        Iterator<String> vaIter = haVaVpMap.keySet().iterator();
        while (vaIter.hasNext()) {
            String haVaId = vaIter.next();
            _log.info("HA VirtualArray is {}", haVaId);
            if (!haVaId.equals(NullColumnValueGetter.getNullURI().toString())) {
                _log.info("HA VirtualArray is not a null URI");
                haVArray = getVirtualArrayForVolumeCreateRequest(project, URI.create(haVaId));
                if (vArray.getId().toString().equals(haVArray.getId().toString())) {
                    throw APIException.badRequests.sameVirtualArrayAndHighAvailabilityArray();
                }
            }
            // Now get the VirtualPool.
            String haVpId = haVaVpMap.get(haVaId);
            _log.info("HA VirtualPool is {}", haVpId);
            if (!haVpId.equals(NullColumnValueGetter.getNullURI().toString())) {
                _log.info("HA VirtualPool is not a null URI");
                haVPool = BlockService.getVirtualPoolForRequest(project, URI.create(haVpId), _dbClient, _permissionsHelper);
            }
        }
    }
    // Get the volume placement based on passed parameters.
    _log.info("VirtualPool: {}, HA VirtualPool: {}", vPool.getId().toString(), haVPool.getId().toString());
    List<Recommendation> recommendations = scheduleStorage(vArray, vplexSystemsForPlacement, null, vPool, isHAVolumeRequest, haVArray, haVPool, capabilities, project, VpoolUse.ROOT, currentRecommendations);
    return recommendations;
}
Also used : VirtualArray(com.emc.storageos.db.client.model.VirtualArray) StringMap(com.emc.storageos.db.client.model.StringMap) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) Recommendation(com.emc.storageos.volumecontroller.Recommendation) VPlexRecommendation(com.emc.storageos.volumecontroller.VPlexRecommendation)

Aggregations

VirtualPool (com.emc.storageos.db.client.model.VirtualPool)339 URI (java.net.URI)189 ArrayList (java.util.ArrayList)122 Volume (com.emc.storageos.db.client.model.Volume)103 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)92 NamedURI (com.emc.storageos.db.client.model.NamedURI)88 VirtualArray (com.emc.storageos.db.client.model.VirtualArray)88 StringSet (com.emc.storageos.db.client.model.StringSet)76 Project (com.emc.storageos.db.client.model.Project)65 StoragePool (com.emc.storageos.db.client.model.StoragePool)57 StringMap (com.emc.storageos.db.client.model.StringMap)53 HashMap (java.util.HashMap)52 Produces (javax.ws.rs.Produces)50 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)45 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)44 List (java.util.List)44 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)42 Path (javax.ws.rs.Path)42 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)37 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)37