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:
committed by
Michael Hirsch
parent
c221f82ba4
commit
710627ce46
@@ -189,6 +189,16 @@ public class ConfigurableScenario {
|
|||||||
.successThreshold(String.valueOf(scenario.getRolloutSuccessThreshold())).errorThreshold("5").build())
|
.successThreshold(String.valueOf(scenario.getRolloutSuccessThreshold())).errorThreshold("5").build())
|
||||||
.getBody();
|
.getBody();
|
||||||
|
|
||||||
|
do {
|
||||||
|
try {
|
||||||
|
TimeUnit.SECONDS.sleep(5);
|
||||||
|
} catch (final InterruptedException e) {
|
||||||
|
LOGGER.warn("Interrupted!");
|
||||||
|
Thread.currentThread().interrupt();
|
||||||
|
}
|
||||||
|
} while (!"READY".equalsIgnoreCase(
|
||||||
|
rolloutResource.getRollout(rolloutResponseBody.getRolloutId()).getBody().getStatus()));
|
||||||
|
|
||||||
// start the created Rollout
|
// start the created Rollout
|
||||||
rolloutResource.start(rolloutResponseBody.getRolloutId());
|
rolloutResource.start(rolloutResponseBody.getRolloutId());
|
||||||
|
|
||||||
@@ -295,12 +305,10 @@ public class ConfigurableScenario {
|
|||||||
targetTagResource
|
targetTagResource
|
||||||
.createTargetTags(new TagBuilder().name("Page " + page)
|
.createTargetTags(new TagBuilder().name("Page " + page)
|
||||||
.description("Target tag for target page " + page).buildAsList(scenario.getTargetTags()))
|
.description("Target tag for target page " + page).buildAsList(scenario.getTargetTags()))
|
||||||
.getBody().forEach(
|
.getBody()
|
||||||
tag -> targetTagResource.assignTargets(tag.getTagId(),
|
.forEach(tag -> targetTagResource.assignTargets(tag.getTagId(), targets.stream().map(
|
||||||
targets.stream()
|
target -> new MgmtAssignedTargetRequestBody().setControllerId(target.getControllerId()))
|
||||||
.map(target -> new MgmtAssignedTargetRequestBody()
|
.collect(Collectors.toList())));
|
||||||
.setControllerId(target.getControllerId()))
|
|
||||||
.collect(Collectors.toList())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,18 +18,31 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component
|
@Component
|
||||||
@ConfigurationProperties("hawkbit.rollout")
|
@ConfigurationProperties("hawkbit.rollout")
|
||||||
public class RolloutProperties {
|
public class RolloutProperties {
|
||||||
|
// used by @Scheduled annotation which needs constant
|
||||||
|
public static final String PROP_SCHEDULER_DELAY_PLACEHOLDER = "${hawkbit.rollout.scheduler.fixedDelay:30000}";
|
||||||
|
|
||||||
|
// used by @Scheduled annotation which needs constant
|
||||||
|
public static final String PROP_CREATING_SCHEDULER_DELAY_PLACEHOLDER = "${hawkbit.rollout.creatingScheduler.fixedDelay:2000}";
|
||||||
|
|
||||||
|
// used by @Scheduled annotation which needs constant
|
||||||
|
public static final String PROP_STARTING_SCHEDULER_DELAY_PLACEHOLDER = "${hawkbit.rollout.startingScheduler.fixedDelay:2000}";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Rollout scheduler configuration.
|
* Rollout scheduler configuration.
|
||||||
*/
|
*/
|
||||||
public static class Scheduler {
|
public static class Scheduler {
|
||||||
// used by @Scheduled annotation which needs constant
|
|
||||||
public static final String PROP_SCHEDULER_DELAY_PLACEHOLDER = "${hawkbit.rollout.scheduler.fixedDelay:30000}";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule where the rollout scheduler looks necessary state changes in
|
* Schedule where the rollout scheduler looks necessary state changes in
|
||||||
* milliseconds.
|
* milliseconds.
|
||||||
*/
|
*/
|
||||||
private long fixedDelay = 30000L;
|
private long fixedDelay;
|
||||||
|
|
||||||
|
private boolean enabled = true;
|
||||||
|
|
||||||
|
public Scheduler(final long fixedDelay) {
|
||||||
|
this.fixedDelay = fixedDelay;
|
||||||
|
}
|
||||||
|
|
||||||
public long getFixedDelay() {
|
public long getFixedDelay() {
|
||||||
return fixedDelay;
|
return fixedDelay;
|
||||||
@@ -39,12 +52,30 @@ public class RolloutProperties {
|
|||||||
this.fixedDelay = fixedDelay;
|
this.fixedDelay = fixedDelay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(final boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final Scheduler scheduler = new Scheduler();
|
private final Scheduler scheduler = new Scheduler(30000L);
|
||||||
|
|
||||||
|
private final Scheduler creatingScheduler = new Scheduler(2000L);
|
||||||
|
|
||||||
|
private final Scheduler startingScheduler = new Scheduler(2000L);
|
||||||
|
|
||||||
public Scheduler getScheduler() {
|
public Scheduler getScheduler() {
|
||||||
return scheduler;
|
return scheduler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Scheduler getCreatingScheduler() {
|
||||||
|
return creatingScheduler;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Scheduler getStartingScheduler() {
|
||||||
|
return startingScheduler;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
* Maximum amount of targets that are assigned to a Rollout Group in one
|
* Maximum amount of targets that are assigned to a Rollout Group in one
|
||||||
* transaction.
|
* transaction.
|
||||||
*/
|
*/
|
||||||
private static final long TRANSACTION_TARGETS = 1000;
|
private static final int TRANSACTION_TARGETS = 1000;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EntityManager entityManager;
|
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();
|
final DefaultTransactionDefinition def = new DefaultTransactionDefinition();
|
||||||
def.setName(transactionName);
|
def.setName(transactionName);
|
||||||
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
|
||||||
return new TransactionTemplate(txManager, def).execute(action);
|
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) {
|
final String targetFilter, final long limit) {
|
||||||
|
|
||||||
return runInNewCountingTransaction("assignTargetsToRolloutGroup", status -> {
|
return runInNewCountingTransaction("assignTargetsToRolloutGroup", status -> {
|
||||||
@@ -395,7 +395,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
|
|
||||||
createAssignmentOfTargetsToGroup(targets, group);
|
createAssignmentOfTargetsToGroup(targets, group);
|
||||||
|
|
||||||
return targets.getTotalElements();
|
return targets.getNumberOfElements();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,9 +552,9 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
return totalActionsCreated;
|
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 -> {
|
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 Rollout rollout = rolloutRepository.findOne(rolloutId);
|
||||||
final RolloutGroup group = rolloutGroupRepository.findOne(groupId);
|
final RolloutGroup group = rolloutGroupRepository.findOne(groupId);
|
||||||
|
|
||||||
@@ -568,7 +568,7 @@ public class JpaRolloutManagement implements RolloutManagement {
|
|||||||
rollout, group);
|
rollout, group);
|
||||||
}
|
}
|
||||||
|
|
||||||
return targets.getTotalElements();
|
return targets.getNumberOfElements();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -57,8 +57,12 @@ public class RolloutScheduler {
|
|||||||
* tenant the {@link RolloutManagement#checkRunningRollouts(long)} in the
|
* tenant the {@link RolloutManagement#checkRunningRollouts(long)} in the
|
||||||
* {@link SystemSecurityContext}.
|
* {@link SystemSecurityContext}.
|
||||||
*/
|
*/
|
||||||
@Scheduled(initialDelayString = RolloutProperties.Scheduler.PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = RolloutProperties.Scheduler.PROP_SCHEDULER_DELAY_PLACEHOLDER)
|
@Scheduled(initialDelayString = RolloutProperties.PROP_SCHEDULER_DELAY_PLACEHOLDER, fixedDelayString = RolloutProperties.PROP_SCHEDULER_DELAY_PLACEHOLDER)
|
||||||
public void rolloutScheduler() {
|
public void runningRolloutScheduler() {
|
||||||
|
if (!rolloutProperties.getScheduler().isEnabled()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
LOGGER.debug("rollout schedule checker has been triggered.");
|
LOGGER.debug("rollout schedule checker has been triggered.");
|
||||||
// run this code in system code privileged to have the necessary
|
// run this code in system code privileged to have the necessary
|
||||||
// permission to query and create entities.
|
// permission to query and create entities.
|
||||||
@@ -74,8 +78,6 @@ public class RolloutScheduler {
|
|||||||
for (final String tenant : tenants) {
|
for (final String tenant : tenants) {
|
||||||
tenantAware.runAsTenant(tenant, () -> {
|
tenantAware.runAsTenant(tenant, () -> {
|
||||||
final long fixedDelay = rolloutProperties.getScheduler().getFixedDelay();
|
final long fixedDelay = rolloutProperties.getScheduler().getFixedDelay();
|
||||||
rolloutManagement.checkCreatingRollouts(fixedDelay);
|
|
||||||
rolloutManagement.checkStartingRollouts(fixedDelay);
|
|
||||||
rolloutManagement.checkRunningRollouts(fixedDelay);
|
rolloutManagement.checkRunningRollouts(fixedDelay);
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
@@ -83,4 +85,74 @@ public class RolloutScheduler {
|
|||||||
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#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;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user