Search in sources :

Example 1 with VirtualPool

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

the class FileService method export.

/**
 * Export file system.
 *
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param param
 *            File system export parameters
 * @param id
 *            the URN of a ViPR File system
 * @brief Create file export
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/exports")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep export(@PathParam("id") URI id, FileSystemExportParam param) throws InternalException {
    _log.info("Export request recieved {}", id);
    // check file System
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    ArgValidator.checkFieldValueFromEnum(param.getPermissions(), "permissions", EnumSet.allOf(FileShareExport.Permissions.class));
    _log.info("Export security type {}", param.getSecurityType());
    for (String sectype : param.getSecurityType().split(",")) {
        ArgValidator.checkFieldValueFromEnum(sectype.trim(), "type", EnumSet.allOf(FileShareExport.SecurityTypes.class));
    }
    ArgValidator.checkFieldValueFromEnum(param.getProtocol(), "protocol", EnumSet.allOf(StorageProtocol.File.class));
    validateIpInterfacesRegistered(param.getEndpoints(), _dbClient);
    FileShare fs = queryResource(id);
    String task = UUID.randomUUID().toString();
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    // Check for VirtualPool whether it has NFS enabled
    VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
    if (!vpool.getProtocols().contains(StorageProtocol.File.NFS.name()) && !vpool.getProtocols().contains(StorageProtocol.File.NFSv4.name())) {
        // Throw an error
        throw APIException.methodNotAllowed.vPoolDoesntSupportProtocol("Vpool doesn't support " + StorageProtocol.File.NFS.name() + " or " + StorageProtocol.File.NFSv4 + " protocol");
    }
    // locate storage port for exporting file System
    StoragePort sport = _fileScheduler.placeFileShareExport(fs, param.getProtocol(), param.getEndpoints());
    String path = fs.getPath();
    String mountPath = fs.getMountPath();
    String subDirectory = param.getSubDirectory();
    if (ArgValidator.checkSubDirName("sub_directory", param.getSubDirectory())) {
        // Add subdirectory to the path as this is a subdirectory export
        path += "/" + param.getSubDirectory();
        mountPath += "/" + param.getSubDirectory();
    }
    FSExportMap exportMap = fs.getFsExports();
    if (exportMap != null) {
        Iterator it = fs.getFsExports().keySet().iterator();
        boolean exportExists = false;
        while (it.hasNext()) {
            String fsExpKey = (String) it.next();
            FileExport fileExport = fs.getFsExports().get(fsExpKey);
            if (fileExport.getPath().equalsIgnoreCase(path)) {
                exportExists = true;
                break;
            }
        }
        if (exportExists) {
            throw APIException.badRequests.fileSystemHasExistingExport();
        }
    }
    String rootUserMapping = param.getRootUserMapping();
    if (rootUserMapping != null) {
        rootUserMapping = rootUserMapping.toLowerCase();
    }
    // check for bypassDnsCheck flag. If null then set to false
    Boolean dnsCheck = param.getBypassDnsCheck();
    if (dnsCheck == null) {
        dnsCheck = false;
    }
    FileShareExport export = new FileShareExport(param.getEndpoints(), param.getSecurityType(), param.getPermissions(), rootUserMapping, param.getProtocol(), sport.getPortGroup(), sport.getPortNetworkId(), path, mountPath, subDirectory, param.getComments(), dnsCheck);
    _log.info(String.format("FileShareExport --- FileShare id: %1$s, Clients: %2$s, StoragePort: %3$s, SecurityType: %4$s, " + "Permissions: %5$s, Root user mapping: %6$s, Protocol: %7$s, path: %8$s, mountPath: %9$s, SubDirectory: %10$s ,byPassDnsCheck: %11$s", id, export.getClients(), sport.getPortName(), export.getSecurityType(), export.getPermissions(), export.getRootUserMapping(), export.getProtocol(), export.getPath(), export.getMountPath(), export.getSubDirectory(), export.getBypassDnsCheck()));
    Operation op = _dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.EXPORT_FILE_SYSTEM);
    op.setDescription("Filesystem export");
    FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.export(device.getId(), fs.getId(), Arrays.asList(export), task);
    auditOp(OperationTypeEnum.EXPORT_FILE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, fs.getId().toString(), device.getId().toString(), export.getClients(), param.getSecurityType(), param.getPermissions(), param.getRootUserMapping(), param.getProtocol());
    return toTask(fs, task, op);
}
Also used : StoragePort(com.emc.storageos.db.client.model.StoragePort) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) FileShareExport(com.emc.storageos.volumecontroller.FileShareExport) SecurityTypes(com.emc.storageos.volumecontroller.FileShareExport.SecurityTypes) DefaultPermissions(com.emc.storageos.security.authorization.DefaultPermissions) Permissions(com.emc.storageos.volumecontroller.FileShareExport.Permissions) Iterator(java.util.Iterator) FileExport(com.emc.storageos.db.client.model.FileExport) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) 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 2 with VirtualPool

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

the class InternalFileResource method releaseFileSystemInternal.

/**
 * Release a file system from its current tenant & project for internal object usage
 *
 * @param id the URN of a ViPR file system to be released
 * @return the updated file system
 * @throws InternalException
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/release")
public FileShareRestRep releaseFileSystemInternal(@PathParam("id") URI id) throws InternalException {
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    FileShare fs = _fileService.queryResource(id);
    // and just return success down at the bottom
    if (!fs.checkInternalFlags(Flag.INTERNAL_OBJECT)) {
        URI tenantURI = fs.getTenant().getURI();
        if (!_permissionsHelper.userHasGivenRole(getUserFromContext(), tenantURI, Role.TENANT_ADMIN)) {
            throw APIException.forbidden.onlyAdminsCanReleaseFileSystems(Role.TENANT_ADMIN.toString());
        }
        // we can't release a fs that has exports
        FSExportMap exports = fs.getFsExports();
        if ((exports != null) && (!exports.isEmpty())) {
            throw APIException.badRequests.cannotReleaseFileSystemExportExists(exports.keySet().toString());
        }
        // we can't release a fs that has shares
        SMBShareMap shares = fs.getSMBFileShares();
        if ((shares != null) && (!shares.isEmpty())) {
            throw APIException.badRequests.cannotReleaseFileSystemSharesExists(shares.keySet().toString());
        }
        // files systems with pending operations can't be released
        if (fs.getOpStatus() != null) {
            for (String opId : fs.getOpStatus().keySet()) {
                Operation op = fs.getOpStatus().get(opId);
                if (Operation.Status.pending.name().equals(op.getStatus())) {
                    throw APIException.badRequests.cannotReleaseFileSystemWithTasksPending();
                }
            }
        }
        // file systems with snapshots can't be released
        Integer snapCount = _fileService.getNumSnapshots(fs);
        if (snapCount > 0) {
            throw APIException.badRequests.cannotReleaseFileSystemSnapshotExists(snapCount);
        }
        TenantOrg rootTenant = _permissionsHelper.getRootTenant();
        // we can't release the file system to the root tenant if the root tenant has no access
        // to the filesystem's virtual pool
        ArgValidator.checkFieldNotNull(fs.getVirtualPool(), "virtualPool");
        VirtualPool virtualPool = _permissionsHelper.getObjectById(fs.getVirtualPool(), VirtualPool.class);
        ArgValidator.checkEntity(virtualPool, fs.getVirtualPool(), false);
        if (!_permissionsHelper.tenantHasUsageACL(rootTenant.getId(), virtualPool)) {
            throw APIException.badRequests.cannotReleaseFileSystemRootTenantLacksVPoolACL(virtualPool.getId().toString());
        }
        fs.setOriginalProject(fs.getProject().getURI());
        fs.setTenant(new NamedURI(rootTenant.getId(), fs.getLabel()));
        fs.setProject(new NamedURI(_internalProject.getId(), fs.getLabel()));
        fs.addInternalFlags(INTERNAL_FILESHARE_FLAGS);
        _dbClient.updateAndReindexObject(fs);
        // audit against the source project, not the new dummy internal project
        auditOp(OperationTypeEnum.RELEASE_FILE_SYSTEM, true, null, fs.getId().toString(), fs.getOriginalProject().toString());
    }
    return map(fs);
}
Also used : SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) Operation(com.emc.storageos.db.client.model.Operation) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) FileShare(com.emc.storageos.db.client.model.FileShare) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Example 3 with VirtualPool

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

the class MigrationService method getVirtualPoolForMigrationTarget.

/**
 * Gets the VirtualPool for the migration target.
 *
 * @param requestedCosURI The VirtualPool specified in the migration request.
 * @param vplexVolume A reference to the VPlex virtual volume.
 * @param migrationSrc A reference to the migration source.
 *
 * @return A reference to the VirtualPool for the migration target volume.
 */
private VirtualPool getVirtualPoolForMigrationTarget(URI requestedCosURI, Volume vplexVolume, Volume migrationSrc) {
    // Get the VirtualPool for the migration source.
    VirtualPool cosForMigrationSrc = _permissionsHelper.getObjectById(migrationSrc.getVirtualPool(), VirtualPool.class);
    // Determine the VirtualPool for the migration target based on
    // the VirtualPool specified in the request, if any. Note that the
    // VirtualPool specified in the request should be the new VirtualPool for
    // the passed VPlex volume after the migration is complete.
    VirtualPool cosForMigrationTgt = null;
    if (requestedCosURI != null) {
        // Get the new VirtualPool for the virtual volume verifying
        // that the VirtualPool is valid for the project's tenant and
        // set it initially as the VirtualPool for the migration
        // target.
        Project vplexVolumeProject = _permissionsHelper.getObjectById(vplexVolume.getProject(), Project.class);
        cosForMigrationTgt = BlockService.getVirtualPoolForRequest(vplexVolumeProject, requestedCosURI, _dbClient, _permissionsHelper);
        // Now get the VirtualArray of the migration source volume.
        // We need to know if this is the primary volume or the HA
        // volume.
        URI migrationNhURI = migrationSrc.getVirtualArray();
        if (!migrationNhURI.toString().equals(vplexVolume.getVirtualArray().toString())) {
            // The HA backend volume is being migrated.
            // The VirtualPool for the HA volume is potentially
            // specified by the HA VirtualPool map in the requested
            // VirtualPool. If not, then the VirtualPool for the HA volume
            // is the same as that of the VPlex volume.
            StringMap haNhCosMap = cosForMigrationTgt.getHaVarrayVpoolMap();
            if ((haNhCosMap != null) && (haNhCosMap.containsKey(migrationNhURI.toString()))) {
                cosForMigrationTgt = BlockService.getVirtualPoolForRequest(vplexVolumeProject, URI.create(haNhCosMap.get(migrationNhURI.toString())), _dbClient, _permissionsHelper);
            }
            // Now verify the VirtualPool change is legitimate.
            VirtualPoolChangeAnalyzer.verifyVirtualPoolChangeForTechRefresh(cosForMigrationSrc, cosForMigrationTgt);
        } else {
            // The primary or source volume is being migrated.
            // The VirtualPool for the primary volume is the same as
            // that for the VPlex volume. We still need to verify
            // this is a legitimate VirtualPool change.
            VirtualPoolChangeAnalyzer.verifyVirtualPoolChangeForTechRefresh(cosForMigrationSrc, cosForMigrationTgt);
        }
    } else {
        // A new VirtualPool was not specified for the virtual volume, so
        // the VirtualPool for the migration target will be the same as that
        // for the migration source.
        cosForMigrationTgt = cosForMigrationSrc;
    }
    return cosForMigrationTgt;
}
Also used : Project(com.emc.storageos.db.client.model.Project) StringMap(com.emc.storageos.db.client.model.StringMap) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI)

Example 4 with VirtualPool

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

the class ObjectVirtualPoolService method getMatchingPoolsForVirtualPoolAttributes.

/**
 * Return the matching pools for a given set of VirtualPool attributes.
 * This API is useful for user to find the matching pools before creating a VirtualPool.
 *
 * @param param : VirtualPoolAttributeParam
 * @brief List pools matching specified properties in Object store VirtualPool
 * @return : matching pools.
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/matching-pools")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public StoragePoolList getMatchingPoolsForVirtualPoolAttributes(ObjectVirtualPoolParam param) {
    StoragePoolList poolList = new StoragePoolList();
    VirtualPool vpool = prepareVirtualPool(param);
    List<URI> poolURIs = _dbClient.queryByType(StoragePool.class, true);
    List<StoragePool> allPools = _dbClient.queryObject(StoragePool.class, poolURIs);
    StringBuffer errorMessage = new StringBuffer();
    List<StoragePool> matchedPools = ImplicitPoolMatcher.getMatchedPoolWithStoragePools(vpool, allPools, null, null, null, _dbClient, _coordinator, AttributeMatcher.VPOOL_MATCHERS, errorMessage);
    for (StoragePool pool : matchedPools) {
        poolList.getPools().add(toNamedRelatedResource(pool, pool.getNativeGuid()));
    }
    return poolList;
}
Also used : StoragePoolList(com.emc.storageos.model.pools.StoragePoolList) StoragePool(com.emc.storageos.db.client.model.StoragePool) VirtualPoolMapper.toObjectVirtualPool(com.emc.storageos.api.mapper.VirtualPoolMapper.toObjectVirtualPool) MapObjectVirtualPool(com.emc.storageos.api.mapper.functions.MapObjectVirtualPool) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) 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 5 with VirtualPool

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

the class ObjectVirtualPoolService method prepareVirtualPool.

// this method must not persist anything to the DB.
private VirtualPool prepareVirtualPool(ObjectVirtualPoolParam param) {
    VirtualPool vPool = new VirtualPool();
    vPool.setType(VirtualPool.Type.object.name());
    // set common VirtualPool parameters.
    populateCommonVirtualPoolCreateParams(vPool, param);
    StringSetMap arrayInfo = new StringSetMap();
    if (null != param.getSystemType()) {
        if (!VirtualPool.SystemType.NONE.toString().equals(param.getSystemType()) && !VirtualPool.SystemType.isObjectTypeSystem(param.getSystemType())) {
            throw APIException.badRequests.invalidParameter("system_type", param.getSystemType());
        }
        arrayInfo.put(VirtualPoolCapabilityValuesWrapper.SYSTEM_TYPE, param.getSystemType());
        vPool.addArrayInfoDetails(arrayInfo);
    }
    if (null != param.getMaxRetention()) {
        vPool.setMaxRetention(param.getMaxRetention());
    }
    if (null != param.getMinDataCenters()) {
        vPool.setMinDataCenters(param.getMinDataCenters());
    }
    return vPool;
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) VirtualPoolMapper.toObjectVirtualPool(com.emc.storageos.api.mapper.VirtualPoolMapper.toObjectVirtualPool) MapObjectVirtualPool(com.emc.storageos.api.mapper.functions.MapObjectVirtualPool) VirtualPool(com.emc.storageos.db.client.model.VirtualPool)

Aggregations

VirtualPool (com.emc.storageos.db.client.model.VirtualPool)341 URI (java.net.URI)190 ArrayList (java.util.ArrayList)122 Volume (com.emc.storageos.db.client.model.Volume)104 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)66 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)51 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)46 VirtualPoolCapabilityValuesWrapper (com.emc.storageos.volumecontroller.impl.utils.VirtualPoolCapabilityValuesWrapper)44 List (java.util.List)44 Path (javax.ws.rs.Path)43 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)42 TenantOrg (com.emc.storageos.db.client.model.TenantOrg)38 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)37