Fixed scheduler and mgmt simulator after rollout management changes (#352)

* Fixed scheduler and mgmt simulator

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>

* Fix typo

Signed-off-by: kaizimmerm <kai.zimmermann@bosch-si.com>
This commit is contained in:
Kai Zimmermann
2016-11-18 08:47:41 +01:00
committed by Michael Hirsch
parent c221f82ba4
commit 710627ce46
4 changed files with 132 additions and 21 deletions

View File

@@ -90,7 +90,7 @@ public class JpaRolloutManagement implements RolloutManagement {
* Maximum amount of targets that are assigned to a Rollout Group in one
* transaction.
*/
private static final long TRANSACTION_TARGETS = 1000;
private static final int TRANSACTION_TARGETS = 1000;
@Autowired
private EntityManager entityManager;
@@ -376,14 +376,14 @@ public class JpaRolloutManagement implements RolloutManagement {
}
}
private Long runInNewCountingTransaction(final String transactionName, final TransactionCallback<Long> action) {
private int runInNewCountingTransaction(final String transactionName, final TransactionCallback<Integer> action) {
final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
def.setName(transactionName);
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
return new TransactionTemplate(txManager, def).execute(action);
}
private long assignTargetsToGroupInNewTransaction(final Rollout rollout, final RolloutGroup group,
private Integer assignTargetsToGroupInNewTransaction(final Rollout rollout, final RolloutGroup group,
final String targetFilter, final long limit) {
return runInNewCountingTransaction("assignTargetsToRolloutGroup", status -> {
@@ -395,7 +395,7 @@ public class JpaRolloutManagement implements RolloutManagement {
createAssignmentOfTargetsToGroup(targets, group);
return targets.getTotalElements();
return targets.getNumberOfElements();
});
}
@@ -552,9 +552,9 @@ public class JpaRolloutManagement implements RolloutManagement {
return totalActionsCreated;
}
private long createActionsForTargetsInNewTransaction(final long rolloutId, final long groupId, final long limit) {
private Integer createActionsForTargetsInNewTransaction(final long rolloutId, final long groupId, final int limit) {
return runInNewCountingTransaction("createActionsForTargets", status -> {
final PageRequest pageRequest = new PageRequest(0, Math.toIntExact(limit));
final PageRequest pageRequest = new PageRequest(0, limit);
final Rollout rollout = rolloutRepository.findOne(rolloutId);
final RolloutGroup group = rolloutGroupRepository.findOne(groupId);
@@ -568,7 +568,7 @@ public class JpaRolloutManagement implements RolloutManagement {
rollout, group);
}
return targets.getTotalElements();
return targets.getNumberOfElements();
});
}

View File

@@ -57,8 +57,12 @@ public class RolloutScheduler {
* tenant the {@link RolloutManagement#checkRunningRollouts(long)} in the
* {@link SystemSecurityContext}.
*/
@Scheduled(initialDelayString = RolloutProperties.Scheduler.PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = RolloutProperties.Scheduler.PROP_SCHEDULER_DELAY_PLACEHOLDER)
public void rolloutScheduler() {
@Scheduled(initialDelayString = RolloutProperties.PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = RolloutProperties.PROP_SCHEDULER_DELAY_PLACEHOLDER)
public void runningRolloutScheduler() {
if (!rolloutProperties.getScheduler().isEnabled()) {
return;
}
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.
@@ -74,8 +78,6 @@ public class RolloutScheduler {
for (final String tenant : tenants) {
tenantAware.runAsTenant(tenant, () -> {
final long fixedDelay = rolloutProperties.getScheduler().getFixedDelay();
rolloutManagement.checkCreatingRollouts(fixedDelay);
rolloutManagement.checkStartingRollouts(fixedDelay);
rolloutManagement.checkRunningRollouts(fixedDelay);
return null;
});
@@ -83,4 +85,74 @@ public class RolloutScheduler {
return null;
});
}
/**
* Scheduler method called by the spring-async mechanism. Retrieves all
* tenants from the {@link SystemManagement#findTenants()} and runs for each
* tenant the {@link RolloutManagement#checkStartingRollouts(long)} in the
* {@link SystemSecurityContext}.
*/
@Scheduled(initialDelayString = RolloutProperties.PROP_STARTING_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = RolloutProperties.PROP_STARTING_SCHEDULER_DELAY_PLACEHOLDER)
public void startingRolloutScheduler() {
if (!rolloutProperties.getStartingScheduler().isEnabled()) {
return;
}
LOGGER.debug("rollout starting 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.
final List<String> tenants = systemManagement.findTenants();
LOGGER.info("Checking starting rollouts for {} tenants", tenants.size());
for (final String tenant : tenants) {
tenantAware.runAsTenant(tenant, () -> {
final long fixedDelay = rolloutProperties.getStartingScheduler().getFixedDelay();
rolloutManagement.checkStartingRollouts(fixedDelay);
return null;
});
}
return null;
});
}
/**
* Scheduler method called by the spring-async mechanism. Retrieves all
* tenants from the {@link SystemManagement#findTenants()} and runs for each
* tenant the {@link RolloutManagement#checkCreatingRollouts(long)} in the
* {@link SystemSecurityContext}.
*/
@Scheduled(initialDelayString = RolloutProperties.PROP_CREATING_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = RolloutProperties.PROP_CREATING_SCHEDULER_DELAY_PLACEHOLDER)
public void creatingRolloutScheduler() {
if (!rolloutProperties.getCreatingScheduler().isEnabled()) {
return;
}
LOGGER.debug("rollout creating 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.
final List<String> tenants = systemManagement.findTenants();
LOGGER.info("Checking creating rollouts for {} tenants", tenants.size());
for (final String tenant : tenants) {
tenantAware.runAsTenant(tenant, () -> {
final long fixedDelay = rolloutProperties.getCreatingScheduler().getFixedDelay();
rolloutManagement.checkCreatingRollouts(fixedDelay);
return null;
});
}
return null;
});
}
}