/** * If any endpoint is used in an active File Export, throws an exception * * @param endpoints endpoints being added * @param varrays endpoints belong to * <p>Assumes endpoint formats have been validated. */ public static void checkNotUsedByActiveFileExport(String endpoint, DbClient dbClient) { Network network = NetworkUtil.getEndpointNetwork(endpoint, dbClient); if (network != null) { Set<String> netVArrayIds = network.getConnectedVirtualArrays(); if ((netVArrayIds != null) && (!netVArrayIds.isEmpty())) { Iterator<String> netVArrayIdsIter = netVArrayIds.iterator(); while (netVArrayIdsIter.hasNext()) { String varrayId = netVArrayIdsIter.next(); List<FileShare> fileShares = CustomQueryUtility.queryActiveResourcesByConstraint( dbClient, FileShare.class, AlternateIdConstraint.Factory.getConstraint(FileShare.class, "varray", varrayId)); for (FileShare fileShare : fileShares) { FSExportMap fsExports = fileShare.getFsExports(); if (fsExports != null) { Iterator<FileExport> it = fsExports.values().iterator(); while (it.hasNext()) { FileExport fileExport = it.next(); if (fileExport.getClients().contains(endpoint) || fileExport.getStoragePort().contains(endpoint)) { throw APIException.badRequests.endpointsCannotBeUpdatedActiveExport(endpoint); } } } } } } } }
public boolean isFileShareMounted() { FSExportMap exports = getFs().getFsExports(); SMBShareMap shares = getFs().getSMBFileShares(); boolean isMounted = true; if ((exports == null || (exports != null && exports.isEmpty())) && (shares == null || (shares != null && shares.isEmpty()))) { isMounted = false; } return isMounted; }
/** * 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); // if the FS is already marked as internal, we can skip all this logic // 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); }