private DistributionSetType getDefaultDistributionSetType() { final TenantMetaData tenantMetaData = systemManagement.getTenantMetadata(); return tenantMetaData.getDefaultDsType(); }
public void deleteAllRepos() { final List<String> tenants = systemSecurityContext .runAsSystem(() -> systemManagement.findTenants(PAGE).getContent()); tenants.forEach(tenant -> { try { systemSecurityContext.runAsSystem(() -> { systemManagement.deleteTenant(tenant); return null; }); } catch (final Exception e) { LOGGER.error("Error hile delete tenant", e); } }); } }
/** * @return the {@link SystemManagement#currentTenant()}. */ public String currentTenant() { return systemManagement.currentTenant(); }
/** * Deletes the tenant data of a given tenant. USE WITH CARE! * * @param tenant * to delete * @return HttpStatus.OK */ @Override public ResponseEntity<Void> deleteTenant(@PathVariable("tenant") final String tenant) { systemManagement.deleteTenant(tenant); return ResponseEntity.ok().build(); }
/** * Method which executes each registered cleanup task for each tenant. */ @SuppressWarnings("squid:S3516") private Void executeAutoCleanup() { systemManagement.forEachTenant(tenant -> cleanupTasks.forEach(task -> { final Lock lock = obtainLock(task, tenant); if (!lock.tryLock()) { return; } try { task.run(); } catch (final RuntimeException e) { LOGGER.error("Cleanup task failed.", e); } finally { lock.unlock(); } })); return null; }
/** * Collects and returns system usage statistics. It provides a system wide * overview and tenant based stats. * * @return system usage statistics */ @Override public ResponseEntity<MgmtSystemStatisticsRest> getSystemUsageStats() { final SystemUsageReportWithTenants report = systemManagement.getSystemUsageStatisticsWithTenants(); final MgmtSystemStatisticsRest result = new MgmtSystemStatisticsRest() .setOverallActions(report.getOverallActions()).setOverallArtifacts(report.getOverallArtifacts()) .setOverallArtifactVolumeInBytes(report.getOverallArtifactVolumeInBytes()) .setOverallTargets(report.getOverallTargets()).setOverallTenants(report.getTenants().size()); result.setTenantStats(report.getTenants().stream().map(MgmtSystemManagementResource::convertTenant) .collect(Collectors.toList())); return ResponseEntity.ok(result); }
/** * Method which executes each registered cleanup task for each tenant. */ @SuppressWarnings("squid:S3516") private Void executeAutoCleanup() { systemManagement.forEachTenant(tenant -> cleanupTasks.forEach(task -> { final Lock lock = obtainLock(task, tenant); if (!lock.tryLock()) { return; } try { task.run(); } catch (final RuntimeException e) { LOGGER.error("Cleanup task failed.", e); } finally { lock.unlock(); } })); return null; }
private DistributionSetType getCurrentDistributionSetType() { return systemManagement.getTenantMetadata().getDefaultDsType(); } }
public void deleteAllRepos() { final List<String> tenants = systemSecurityContext .runAsSystem(() -> systemManagement.findTenants(PAGE).getContent()); tenants.forEach(tenant -> { try { systemSecurityContext.runAsSystem(() -> { systemManagement.deleteTenant(tenant); return null; }); } catch (final Exception e) { LOGGER.error("Error hile delete tenant", e); } }); } }
/** * Scheduler method called by the spring-async mechanism. Retrieves all * tenants from the {@link SystemManagement#findTenants()} and runs for each * tenant the {@link RolloutManagement#handleRollouts()} in the * {@link SystemSecurityContext}. */ @Scheduled(initialDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER) public void runningRolloutScheduler() { LOGGER.debug("rollout schedule checker has been triggered."); // run this code in system code privileged to have the necessary // permission to query and create entities. systemSecurityContext.runAsSystem(() -> { // workaround eclipselink that is currently not possible to // execute a query without multitenancy if MultiTenant // annotation is used. // https://bugs.eclipse.org/bugs/show_bug.cgi?id=355458. So // iterate through all tenants and execute the rollout check for // each tenant seperately. systemManagement.forEachTenant(tenant -> rolloutManagement.handleRollouts()); return null; }); }
private DistributionSetType getDefaultDistributionSetType() { final TenantMetaData tenantMetaData = systemManagement.getTenantMetadata(); return tenantMetaData.getDefaultDsType(); }
/** * Scheduler method called by the spring-async mechanism. Retrieves all * tenants from the {@link SystemManagement#findTenants()} and runs for each * tenant the {@link RolloutManagement#handleRollouts()} in the * {@link SystemSecurityContext}. */ @Scheduled(initialDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = PROP_SCHEDULER_DELAY_PLACEHOLDER) public void runningRolloutScheduler() { LOGGER.debug("rollout schedule checker has been triggered."); // run this code in system code privileged to have the necessary // permission to query and create entities. systemSecurityContext.runAsSystem(() -> { // workaround eclipselink that is currently not possible to // execute a query without multitenancy if MultiTenant // annotation is used. // https://bugs.eclipse.org/bugs/show_bug.cgi?id=355458. So // iterate through all tenants and execute the rollout check for // each tenant seperately. systemManagement.forEachTenant(tenant -> rolloutManagement.handleRollouts()); return null; }); }
private DistributionSetType getCurrentDistributionSetType() { tenantMetaData = systemManagement.getTenantMetadata(); return tenantMetaData.getDefaultDsType(); }
@SuppressWarnings("squid:S3516") private Object executeAutoAssign() { // workaround eclipselink that is currently not possible to // execute a query without multitenancy if MultiTenant // annotation is used. // https://bugs.eclipse.org/bugs/show_bug.cgi?id=355458. So // iterate through all tenants and execute the rollout check for // each tenant separately. final Lock lock = lockRegistry.obtain("autoassign"); if (!lock.tryLock()) { return null; } try { systemManagement.forEachTenant(tenant -> autoAssignChecker.check()); } finally { lock.unlock(); } return null; } }
private DistributionSetType getCurrentDistributionSetType() { return systemManagement.getTenantMetadata().getDefaultDsType(); } }
@SuppressWarnings("squid:S3516") private Object executeAutoAssign() { // workaround eclipselink that is currently not possible to // execute a query without multitenancy if MultiTenant // annotation is used. // https://bugs.eclipse.org/bugs/show_bug.cgi?id=355458. So // iterate through all tenants and execute the rollout check for // each tenant separately. final Lock lock = lockRegistry.obtain("autoassign"); if (!lock.tryLock()) { return null; } try { systemManagement.forEachTenant(tenant -> autoAssignChecker.check()); } finally { lock.unlock(); } return null; } }
private DistributionSetType getCurrentDistributionSetType() { tenantMetaData = systemManagement.getTenantMetadata(); return tenantMetaData.getDefaultDsType(); }
@Override public ResponseEntity<List<MgmtDistributionSet>> createDistributionSets( @RequestBody final List<MgmtDistributionSetRequestBodyPost> sets) { LOG.debug("creating {} distribution sets", sets.size()); // set default Ds type if ds type is null final String defaultDsKey = systemSecurityContext .runAsSystem(systemManagement.getTenantMetadata().getDefaultDsType()::getKey); sets.stream().filter(ds -> ds.getType() == null).forEach(ds -> ds.setType(defaultDsKey)); final Collection<DistributionSet> createdDSets = distributionSetManagement .create(MgmtDistributionSetMapper.dsFromRequest(sets, entityFactory)); LOG.debug("{} distribution sets created, return status {}", sets.size(), HttpStatus.CREATED); return new ResponseEntity<>(MgmtDistributionSetMapper.toResponseDistributionSets(createdDSets), HttpStatus.CREATED); }
private void createTenant(final String tenantId) { final SecurityContext oldContext = SecurityContextHolder.getContext(); setSecurityContext(privilegedUser()); try { SystemManagementHolder.getInstance().getSystemManagement().getTenantMetadata(tenantId); } finally { after(oldContext); } }
private void createTenant(final String tenantId) { final SecurityContext oldContext = SecurityContextHolder.getContext(); setSecurityContext(privilegedUser()); try { SystemManagementHolder.getInstance().getSystemManagement().getTenantMetadata(tenantId); } finally { after(oldContext); } }