-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow each policy to define its own execution schedule (#434)
* Refactor PolicyExecutorTask infra * so that each policy can define its own execution schedule * a default cron schedule will be applied if none defined * policy id is consistent whether git-backed or not * includes updates to DDL * includes config property for task scheduling pool size * removes cron.execution config property * More updates in support of scheduling individual policies for execution * includes additions and refactoring * polymorphism is our friend * Upgrade Spring Boot version to 3.2.5 * Increase width for git_commit column
- Loading branch information
Showing
57 changed files
with
571 additions
and
241 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 18 additions & 11 deletions
29
src/main/java/org/cftoolsuite/cfapp/controller/OnDemandPolicyTriggerController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,42 @@ | ||
package org.cftoolsuite.cfapp.controller; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import org.cftoolsuite.cfapp.service.PoliciesService; | ||
import org.cftoolsuite.cfapp.task.PolicyExecutorTask; | ||
import org.springframework.beans.factory.ListableBeanFactory; | ||
import org.springframework.beans.factory.BeanFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
@Profile("on-demand") | ||
@RestController | ||
public class OnDemandPolicyTriggerController { | ||
|
||
private ListableBeanFactory factory; | ||
private BeanFactory factory; | ||
private PoliciesService service; | ||
|
||
@Autowired | ||
public OnDemandPolicyTriggerController(ListableBeanFactory factory) { | ||
public OnDemandPolicyTriggerController(BeanFactory factory, PoliciesService service) { | ||
this.factory = factory; | ||
this.service = service; | ||
} | ||
|
||
@PostMapping("/policies/execute") | ||
public Mono<ResponseEntity<Void>> triggerPolicyExection() { | ||
Map<String, PolicyExecutorTask> taskMap = factory.getBeansOfType(PolicyExecutorTask.class); | ||
Collection<PolicyExecutorTask> tasks = taskMap.values(); | ||
tasks.forEach(PolicyExecutorTask::execute); | ||
return Mono.just(ResponseEntity.accepted().build()); | ||
public Mono<ResponseEntity<Void>> triggerPolicyExecution() { | ||
return service.getTaskMap() | ||
.flatMapMany(taskTypeMap -> | ||
Flux.fromIterable(taskTypeMap.entrySet()) | ||
.flatMap(entry -> { | ||
String policyId = entry.getKey(); | ||
Class<? extends PolicyExecutorTask> taskClass = entry.getValue(); | ||
PolicyExecutorTask task = factory.getBean(taskClass); | ||
return Mono.fromRunnable(() -> task.execute(policyId)); | ||
})) | ||
.then(Mono.just(ResponseEntity.accepted().build())); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.