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);
}
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);
}
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;
}
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;
}
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;
}
Aggregations