diff --git a/pom.xml b/pom.xml
index b1d01889..8a33bc3a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -53,7 +53,7 @@
org.springframework.boot
spring-boot-starter-parent
- 3.2.4
+ 3.2.5
@@ -609,7 +609,7 @@
org.springframework.boot
spring-boot-maven-plugin
- 3.2.4
+ 3.2.5
paketobuildpacks/builder-jammy-tiny
diff --git a/samples/application-pcfone.yml b/samples/application-pcfone.yml
index 76b83db5..d1e4ddbf 100644
--- a/samples/application-pcfone.yml
+++ b/samples/application-pcfone.yml
@@ -14,7 +14,6 @@ logging:
# @see https://crontab.guru for help, first parameter is seconds
cron:
collection: "0 0 0 * * *"
- execution: "0 0 2 * * *"
management:
endpoints:
diff --git a/samples/application-pws.yml b/samples/application-pws.yml
index ff415fb2..874198da 100644
--- a/samples/application-pws.yml
+++ b/samples/application-pws.yml
@@ -14,7 +14,6 @@ logging:
# @see https://crontab.guru for help, first parameter is seconds
cron:
collection: "0 0 0 * * *"
- execution: "0 0 2 * * *"
management:
endpoints:
diff --git a/samples/secrets.pcfone.json b/samples/secrets.pcfone.json
index e7f4a3ba..8329089e 100644
--- a/samples/secrets.pcfone.json
+++ b/samples/secrets.pcfone.json
@@ -5,6 +5,5 @@
"CF_REFRESH-TOKEN": "xxxxxx",
"CF_ORGANIZATION-BLACK-LIST": [ "system" ],
"CF_ACCOUNT-REGEX": "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$",
- "CRON_COLLECTION": "0 0 0 * * *",
- "CRON_EXECUTION": "0 0 2 * * *"
+ "CRON_COLLECTION": "0 0 0 * * *"
}
\ No newline at end of file
diff --git a/samples/secrets.pws.json b/samples/secrets.pws.json
index 6e78a41e..ab8e4431 100644
--- a/samples/secrets.pws.json
+++ b/samples/secrets.pws.json
@@ -7,7 +7,6 @@
"CF_ORGANIZATION-BLACK-LIST": [ "system" ],
"CF_ACCOUNT-REGEX": "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$",
"CRON_COLLECTION": "0 0 0 * * *",
- "CRON_EXECUTION": "0 0 2 * * *",
"CF_POLICIES_GIT_URI": "https://github.com/cf-toolsuite/cf-butler-sample-config.git",
"CF_POLICIES_GIT_COMMIT": "e745cfe5d93e6517038675fd6b0fe3b85524f130",
"CF_POLICIES_GIT_FILE-PATHS": [
diff --git a/samples/secrets.pws.with-mysql.json b/samples/secrets.pws.with-mysql.json
index 9d45d5c1..dc98e018 100644
--- a/samples/secrets.pws.with-mysql.json
+++ b/samples/secrets.pws.with-mysql.json
@@ -7,7 +7,6 @@
"CF_ORGANIZATION-BLACK-LIST": [ "system" ],
"CF_ACCOUNT-REGEX": "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$",
"CRON_COLLECTION": "0 0 0 * * *",
- "CRON_EXECUTION": "0 0 2 * * *",
"CF_POLICIES_GIT_URI": "https://github.com/cf-toolsuite/cf-butler-sample-config.git",
"CF_POLICIES_GIT_COMMIT": "e745cfe5d93e6517038675fd6b0fe3b85524f130",
"CF_POLICIES_GIT_FILE-PATHS": [
diff --git a/samples/secrets.pws.with-postgres.json b/samples/secrets.pws.with-postgres.json
index 617f564b..410771ad 100644
--- a/samples/secrets.pws.with-postgres.json
+++ b/samples/secrets.pws.with-postgres.json
@@ -7,7 +7,6 @@
"CF_ORGANIZATION-BLACK-LIST": [ "system" ],
"CF_ACCOUNT-REGEX": "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$",
"CRON_COLLECTION": "0 0 0 * * *",
- "CRON_EXECUTION": "0 0 2 * * *",
"CF_POLICIES_GIT_URI": "https://github.com/cf-toolsuite/cf-butler-sample-config.git",
"CF_POLICIES_GIT_COMMIT": "e745cfe5d93e6517038675fd6b0fe3b85524f130",
"CF_POLICIES_GIT_FILE-PATHS": [
diff --git a/src/main/java/org/cftoolsuite/cfapp/AppInit.java b/src/main/java/org/cftoolsuite/cfapp/AppInit.java
index 1af4c43a..73be77b0 100644
--- a/src/main/java/org/cftoolsuite/cfapp/AppInit.java
+++ b/src/main/java/org/cftoolsuite/cfapp/AppInit.java
@@ -3,14 +3,12 @@
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesScan;
-import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import io.netty.util.ResourceLeakDetector;
import reactor.core.publisher.Hooks;
-@EnableScheduling
@EnableTransactionManagement
@ConfigurationPropertiesScan
@SpringBootApplication
diff --git a/src/main/java/org/cftoolsuite/cfapp/config/ButlerCfEnvProcessor.java b/src/main/java/org/cftoolsuite/cfapp/config/ButlerCfEnvProcessor.java
index 06ce4361..e2e3fa74 100644
--- a/src/main/java/org/cftoolsuite/cfapp/config/ButlerCfEnvProcessor.java
+++ b/src/main/java/org/cftoolsuite/cfapp/config/ButlerCfEnvProcessor.java
@@ -79,7 +79,6 @@ public void process(CfCredentials cfCredentials, Map properties)
addOrUpdatePropertyValue("pivnet.apiToken", "PIVNET_API-TOKEN", cfCredentials, properties);
addOrUpdatePropertyValue("pivnet.enabled", "PIVNET_ENABLED", cfCredentials, properties);
addOrUpdatePropertyValue("cron.collection", "CRON_COLLECTION", cfCredentials, properties);
- addOrUpdatePropertyValue("cron.execution", "CRON_EXECUTION", cfCredentials, properties);
addOrUpdatePropertyValue("management.endpoints.web.exposure.include", "EXPOSED_ACTUATOR_ENDPOINTS", cfCredentials, properties);
addOrUpdatePropertyValue("java.artifacts.fetch.mode", "JAVA_ARTIFACTS_FETCH_MODE", cfCredentials, properties);
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/controller/OnDemandPolicyTriggerController.java b/src/main/java/org/cftoolsuite/cfapp/controller/OnDemandPolicyTriggerController.java
index 6a5f0bf8..51eb5966 100644
--- a/src/main/java/org/cftoolsuite/cfapp/controller/OnDemandPolicyTriggerController.java
+++ b/src/main/java/org/cftoolsuite/cfapp/controller/OnDemandPolicyTriggerController.java
@@ -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> triggerPolicyExection() {
- Map taskMap = factory.getBeansOfType(PolicyExecutorTask.class);
- Collection tasks = taskMap.values();
- tasks.forEach(PolicyExecutorTask::execute);
- return Mono.just(ResponseEntity.accepted().build());
+ public Mono> 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()));
}
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationOperation.java b/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationOperation.java
index 45baa988..7509e676 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationOperation.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationOperation.java
@@ -1,8 +1,15 @@
package org.cftoolsuite.cfapp.domain;
import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.Map;
import java.util.stream.Collectors;
+import org.cftoolsuite.cfapp.task.DeleteAppPolicyExecutorTask;
+import org.cftoolsuite.cfapp.task.PolicyExecutorTask;
+import org.cftoolsuite.cfapp.task.ScaleAppInstancesPolicyExecutorTask;
+import org.cftoolsuite.cfapp.task.StackChangeAppInstancesPolicyExecutorTask;
+import org.cftoolsuite.cfapp.task.StopAppPolicyExecutorTask;
import org.springframework.util.Assert;
import com.fasterxml.jackson.annotation.JsonValue;
@@ -14,6 +21,20 @@ public enum ApplicationOperation {
STOP("stop"),
CHANGE_STACK("change-stack");
+ private final String name;
+
+ ApplicationOperation(String name) {
+ this.name = name;
+ }
+
+ static final Map> operationTaskMap = new EnumMap<>(ApplicationOperation.class);
+ static {
+ operationTaskMap.put(ApplicationOperation.DELETE, DeleteAppPolicyExecutorTask.class);
+ operationTaskMap.put(ApplicationOperation.SCALE_INSTANCES, ScaleAppInstancesPolicyExecutorTask.class);
+ operationTaskMap.put(ApplicationOperation.STOP, StopAppPolicyExecutorTask.class);
+ operationTaskMap.put(ApplicationOperation.CHANGE_STACK, StackChangeAppInstancesPolicyExecutorTask.class);
+ }
+
public static ApplicationOperation from(String name) {
Assert.hasText(name, "ApplicationOperation must not be null or empty");
ApplicationOperation result = Arrays.asList(ApplicationOperation.values()).stream().filter(s -> s.getName().equalsIgnoreCase(name)).collect(Collectors.toList()).get(0);
@@ -21,14 +42,13 @@ public static ApplicationOperation from(String name) {
return result;
}
- private final String name;
-
- ApplicationOperation(String name) {
- this.name = name;
+ public static Class extends PolicyExecutorTask> getTaskType(String op) {
+ return operationTaskMap.get(from(op));
}
@JsonValue
public String getName() {
return name;
}
+
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicy.java b/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicy.java
index a7b19507..144d6da4 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicy.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicy.java
@@ -27,15 +27,16 @@
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonPropertyOrder({ "id", "operation", "description", "state", "options", "organization-whitelist" })
+@JsonPropertyOrder({ "id", "git-commit", "operation", "description", "state", "options", "organization-whitelist", "cron-expression" })
@Getter
@ToString
@Table("application_policy")
-public class ApplicationPolicy implements HasOrganizationWhiteList {
+public class ApplicationPolicy implements HasOrganizationWhiteList, Policy {
public static ApplicationPolicy seed(ApplicationPolicy policy) {
return ApplicationPolicy
.builder()
+ .cronExpression(policy.getCronExpression())
.description(policy.getDescription())
.operation(policy.getOperation())
.options(policy.getOptions())
@@ -44,10 +45,11 @@ public static ApplicationPolicy seed(ApplicationPolicy policy) {
.build();
}
- public static ApplicationPolicy seedWith(ApplicationPolicy policy, String id) {
+ public static ApplicationPolicy seedWith(ApplicationPolicy policy, String gitCommit) {
return ApplicationPolicy
.builder()
- .id(id)
+ .gitCommit(gitCommit)
+ .cronExpression(policy.getCronExpression())
.description(policy.getDescription())
.operation(policy.getOperation())
.options(policy.getOptions())
@@ -64,6 +66,10 @@ public static ApplicationPolicy seedWith(ApplicationPolicy policy, String id) {
@JsonProperty("id")
private String id = Generators.timeBasedGenerator().generate().toString();
+ @JsonProperty("git-commit")
+ @Column("git_commit")
+ private String gitCommit;
+
@JsonProperty("operation")
private String operation;
@@ -82,22 +88,30 @@ public static ApplicationPolicy seedWith(ApplicationPolicy policy, String id) {
@Column("organization_whitelist")
private Set organizationWhiteList = new HashSet<>();
+ @JsonProperty("cron-expression")
+ @Column("cron_expression")
+ private String cronExpression;
+
@JsonCreator
ApplicationPolicy(
@JsonProperty("pk") Long pk,
@JsonProperty("id") String id,
+ @JsonProperty("git-commit") String gitCommit,
@JsonProperty("operation") String operation,
@JsonProperty("description") String description,
@JsonProperty("state") String state,
@JsonProperty("options") Map options,
- @JsonProperty("organization-whitelist") Set organizationWhiteList) {
+ @JsonProperty("organization-whitelist") Set organizationWhiteList,
+ @JsonProperty("cron-expression") String cronExpression) {
this.pk = pk;
this.id = id;
+ this.gitCommit = gitCommit;
this.operation = operation;
this.description = description;
this.state = state;
this.options = options;
this.organizationWhiteList = organizationWhiteList;
+ this.cronExpression = cronExpression;
}
@JsonIgnore
@@ -110,6 +124,10 @@ public T getOption(String key, Class type) {
return type.cast(value);
}
+ public String getCronExpression() {
+ return StringUtils.isBlank(cronExpression) ? defaultCronExpression(): cronExpression;
+ }
+
public Map getOptions() {
return CollectionUtils.isEmpty(options) ? new HashMap<>(): Collections.unmodifiableMap(options);
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicyReadConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicyReadConverter.java
index 38e2c73e..5231589f 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicyReadConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicyReadConverter.java
@@ -26,10 +26,12 @@ public ApplicationPolicy convert(Row source) {
.builder()
.pk(source.get("pk", Long.class))
.id(source.get("id", String.class))
+ .gitCommit(source.get("git_commit", String.class))
.operation(source.get("operation", String.class))
.description(source.get("description", String.class))
.options(readOptions(source.get("options", String.class) == null ? "{}" : source.get("options", String.class)))
.organizationWhiteList(CsvUtil.parse(source.get("organization_whitelist", String.class)))
+ .cronExpression(source.get("cron_expression", String.class))
.state(source.get("state", String.class))
.build();
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicyWriteConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicyWriteConverter.java
index 8a5c07f5..825079ed 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicyWriteConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/ApplicationPolicyWriteConverter.java
@@ -23,10 +23,12 @@ public class ApplicationPolicyWriteConverter implements Converter endpoints,
- @JsonProperty("email-notification-template") EmailNotificationTemplate emailNotificationTemplate) {
+ @JsonProperty("email-notification-template") EmailNotificationTemplate emailNotificationTemplate,
+ @JsonProperty("cron-expression") String cronExpression) {
this.pk = pk;
this.id = id;
+ this.gitCommit = gitCommit;
this.description = description;
this.endpoints = endpoints;
this.emailNotificationTemplate = emailNotificationTemplate;
+ this.cronExpression = cronExpression;
+ }
+
+ public String getCronExpression() {
+ return StringUtils.isBlank(cronExpression) ? defaultCronExpression(): cronExpression;
}
public Set getEndpoints() {
@@ -87,5 +107,4 @@ public Set getEndpoints() {
public Long getPk() {
return pk;
}
-
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/EndpointPolicyReadConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/EndpointPolicyReadConverter.java
index 1abedbc1..f301a740 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/EndpointPolicyReadConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/EndpointPolicyReadConverter.java
@@ -32,6 +32,7 @@ public EndpointPolicy convert(Row source) {
source.get("email_notification_template", String.class) == null
? "{}"
: source.get("email_notification_template", String.class)))
+ .cronExpression(source.get("cron_expression", String.class))
.build();
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/EndpointPolicyWriteConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/EndpointPolicyWriteConverter.java
index cb9d5929..3e91fa13 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/EndpointPolicyWriteConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/EndpointPolicyWriteConverter.java
@@ -22,9 +22,11 @@ public class EndpointPolicyWriteConverter implements Converter organizationWhiteList = new HashSet<>();
+ @JsonProperty("cron-expression")
+ @Column("cron_expression")
+ private String cronExpression;
+
@Default
@JsonProperty("include-applications")
@Column("include_applications")
@@ -93,23 +104,31 @@ public static HygienePolicy seedWith(HygienePolicy policy, String id) {
public HygienePolicy(
@JsonProperty("pk") Long pk,
@JsonProperty("id") String id,
+ @JsonProperty("git-commit") String gitCommit,
@JsonProperty("days-since-last-update") Integer daysSinceLastUpdate,
@JsonProperty("operator-email-template") EmailNotificationTemplate operatorTemplate,
@JsonProperty("notifyee-email-template") EmailNotificationTemplate notifyeeTemplate,
@JsonProperty("organization-whitelist") Set organizationWhiteList,
+ @JsonProperty("cron-expression") String cronExpression,
@JsonProperty("include-applications") boolean includeApplications,
@JsonProperty("include-service-instances") boolean includeServiceInstances
) {
this.pk = pk;
this.id = id;
+ this.gitCommit = gitCommit;
this.daysSinceLastUpdate = daysSinceLastUpdate;
this.operatorTemplate = operatorTemplate;
this.notifyeeTemplate = notifyeeTemplate;
this.organizationWhiteList = organizationWhiteList;
+ this.cronExpression = cronExpression;
this.includeApplications = includeApplications;
this.includeServiceInstances = includeServiceInstances;
}
+ public String getCronExpression() {
+ return StringUtils.isBlank(cronExpression) ? defaultCronExpression(): cronExpression;
+ }
+
public Set getOrganizationWhiteList() {
return CollectionUtils.isEmpty(organizationWhiteList) ? new HashSet<>() : Collections.unmodifiableSet(organizationWhiteList);
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/HygienePolicyReadConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/HygienePolicyReadConverter.java
index f10d890c..60aba022 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/HygienePolicyReadConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/HygienePolicyReadConverter.java
@@ -24,10 +24,12 @@ public HygienePolicy convert(Row source) {
.builder()
.pk(source.get("pk", Long.class))
.id(source.get("id", String.class))
+ .gitCommit(source.get("git_commit", String.class))
.daysSinceLastUpdate(source.get("days_since_last_update", Integer.class))
.operatorTemplate(readEmailNotificationTemplate(source.get("operator_email_template", String.class) == null ? "{}": source.get("operator_email_template", String.class)))
.notifyeeTemplate(readEmailNotificationTemplate(source.get("notifyee_email_template", String.class) == null ? "{}": source.get("notifyee_email_template", String.class)))
.organizationWhiteList(CsvUtil.parse(source.get("organization_whitelist", String.class)))
+ .cronExpression(source.get("cron_expression", String.class))
.build();
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/HygienePolicyWriteConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/HygienePolicyWriteConverter.java
index 328b616f..8451e409 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/HygienePolicyWriteConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/HygienePolicyWriteConverter.java
@@ -22,10 +22,12 @@ public class HygienePolicyWriteConverter implements Converter stacks = new HashSet<>();
@@ -79,23 +86,35 @@ public static LegacyPolicy seedWith(LegacyPolicy policy, String id) {
@Column("organization_whitelist")
private Set organizationWhiteList = new HashSet<>();
+ @JsonProperty("cron-expression")
+ @Column("cron_expression")
+ private String cronExpression;
+
@JsonCreator
public LegacyPolicy(
@JsonProperty("pk") Long pk,
@JsonProperty("id") String id,
+ @JsonProperty("git-commit") String gitCommit,
@JsonProperty("stacks") Set stacks,
@JsonProperty("service-offerings") Set serviceOfferings,
@JsonProperty("operator-email-template") EmailNotificationTemplate operatorTemplate,
@JsonProperty("notifyee-email-template") EmailNotificationTemplate notifyeeTemplate,
- @JsonProperty("organization-whitelist") Set organizationWhiteList
+ @JsonProperty("organization-whitelist") Set organizationWhiteList,
+ @JsonProperty("cron-expression") String cronExpression
) {
this.pk = pk;
this.id = id;
+ this.gitCommit = gitCommit;
this.stacks = stacks;
this.serviceOfferings = serviceOfferings;
this.operatorTemplate = operatorTemplate;
this.notifyeeTemplate = notifyeeTemplate;
this.organizationWhiteList = organizationWhiteList;
+ this.cronExpression = cronExpression;
+ }
+
+ public String getCronExpression() {
+ return StringUtils.isBlank(cronExpression) ? defaultCronExpression(): cronExpression;
}
public Set getOrganizationWhiteList() {
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/LegacyPolicyReadConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/LegacyPolicyReadConverter.java
index 01bc6ce0..fabc47b9 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/LegacyPolicyReadConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/LegacyPolicyReadConverter.java
@@ -24,11 +24,13 @@ public LegacyPolicy convert(Row source) {
.builder()
.pk(source.get("pk", Long.class))
.id(source.get("id", String.class))
+ .gitCommit(source.get("git_commit", String.class))
.stacks(CsvUtil.parse(source.get("stacks", String.class)))
.serviceOfferings(CsvUtil.parse(source.get("service_offerings", String.class)))
.operatorTemplate(readEmailNotificationTemplate(source.get("operator_email_template", String.class) == null ? "{}": source.get("operator_email_template", String.class)))
.notifyeeTemplate(readEmailNotificationTemplate(source.get("notifyee_email_template", String.class) == null ? "{}": source.get("notifyee_email_template", String.class)))
.organizationWhiteList(CsvUtil.parse(source.get("organization_whitelist", String.class)))
+ .cronExpression(source.get("cron_expression", String.class))
.build();
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/LegacyPolicyWriteConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/LegacyPolicyWriteConverter.java
index 9b5f670c..8a0c0654 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/LegacyPolicyWriteConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/LegacyPolicyWriteConverter.java
@@ -22,11 +22,13 @@ public class LegacyPolicyWriteConverter implements Converter getResourceNotificationPolicies() {
return resourceNotificationPolicies != null ? resourceNotificationPolicies: Collections.emptyList();
}
+ public List all() {
+ List policies = new ArrayList<>();
+ policies.addAll(getApplicationPolicies());
+ policies.addAll(getEndpointPolicies());
+ policies.addAll(getHygienePolicies());
+ policies.addAll(getLegacyPolicies());
+ policies.addAll(getQueryPolicies());
+ policies.addAll(getResourceNotificationPolicies());
+ policies.addAll(getServiceInstancePolicies());
+ return policies;
+ }
+
+ public Policy getById(String policyId) {
+ return all()
+ .stream()
+ .filter(policy -> policy.getId().equals(policyId))
+ .findFirst()
+ .orElse(null);
+ }
+
@JsonIgnore
public boolean isEmpty() {
return getApplicationPolicies().isEmpty()
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/Policy.java b/src/main/java/org/cftoolsuite/cfapp/domain/Policy.java
new file mode 100644
index 00000000..04964712
--- /dev/null
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/Policy.java
@@ -0,0 +1,3 @@
+package org.cftoolsuite.cfapp.domain;
+
+public interface Policy extends HasIdentifier, HasCronExpression {}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicy.java b/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicy.java
index dc333afb..58949b1d 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicy.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicy.java
@@ -4,7 +4,9 @@
import java.util.HashSet;
import java.util.Set;
+import org.apache.commons.lang3.StringUtils;
import org.springframework.data.annotation.Id;
+import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;
import org.springframework.util.CollectionUtils;
@@ -22,11 +24,11 @@
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonPropertyOrder({ "id", "description", "queries", "email-notification-template" })
+@JsonPropertyOrder({ "id", "git-commit", "description", "queries", "email-notification-template", "cron-expression" })
@Getter
@ToString
@Table("query_policy")
-public class QueryPolicy {
+public class QueryPolicy implements Policy {
public static QueryPolicy seed(QueryPolicy policy) {
return QueryPolicy
@@ -34,16 +36,18 @@ public static QueryPolicy seed(QueryPolicy policy) {
.description(policy.getDescription())
.queries(policy.getQueries())
.emailNotificationTemplate(policy.getEmailNotificationTemplate())
+ .cronExpression(policy.getCronExpression())
.build();
}
- public static QueryPolicy seedWith(QueryPolicy policy, String id) {
+ public static QueryPolicy seedWith(QueryPolicy policy, String gitCommit) {
return QueryPolicy
.builder()
- .id(id)
+ .gitCommit(gitCommit)
.description(policy.getDescription())
.queries(policy.getQueries())
.emailNotificationTemplate(policy.getEmailNotificationTemplate())
+ .cronExpression(policy.getCronExpression())
.build();
}
@@ -55,6 +59,10 @@ public static QueryPolicy seedWith(QueryPolicy policy, String id) {
@JsonProperty("id")
private String id = Generators.timeBasedGenerator().generate().toString();
+ @JsonProperty("git-commit")
+ @Column("git_commit")
+ private String gitCommit;
+
@JsonProperty("description")
private String description;
@@ -65,18 +73,30 @@ public static QueryPolicy seedWith(QueryPolicy policy, String id) {
@JsonProperty("email-notification-template")
private EmailNotificationTemplate emailNotificationTemplate;
+ @JsonProperty("cron-expression")
+ @Column("cron_expression")
+ private String cronExpression;
+
@JsonCreator
QueryPolicy(
@JsonProperty("pk") Long pk,
@JsonProperty("id") String id,
+ @JsonProperty("git-commit") String gitCommit,
@JsonProperty("description") String description,
@JsonProperty("queries") Set queries,
- @JsonProperty("email-notification-template") EmailNotificationTemplate emailNotificationTemplate) {
+ @JsonProperty("email-notification-template") EmailNotificationTemplate emailNotificationTemplate,
+ @JsonProperty("cron-expression") String cronExpression) {
this.pk = pk;
this.id = id;
+ this.gitCommit = gitCommit;
this.description = description;
this.queries = queries;
this.emailNotificationTemplate = emailNotificationTemplate;
+ this.cronExpression = cronExpression;
+ }
+
+ public String getCronExpression() {
+ return StringUtils.isBlank(cronExpression) ? defaultCronExpression(): cronExpression;
}
@JsonIgnore
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicyReadConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicyReadConverter.java
index 45d5f24b..a8a659fd 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicyReadConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicyReadConverter.java
@@ -25,6 +25,7 @@ public QueryPolicy convert(Row source) {
.builder()
.pk(source.get("pk", Long.class))
.id(source.get("id", String.class))
+ .gitCommit(source.get("git_commit", String.class))
.description(source.get("description", String.class))
.queries(readQueries(source.get("queries", String.class) == null ? "[]" : source.get("queries", String.class)))
.emailNotificationTemplate(
@@ -32,6 +33,7 @@ public QueryPolicy convert(Row source) {
source.get("email_notification_template", String.class) == null
? "{}"
: source.get("email_notification_template", String.class)))
+ .cronExpression(source.get("cron_expression", String.class))
.build();
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicyWriteConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicyWriteConverter.java
index 0df66a8e..625d6562 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicyWriteConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/QueryPolicyWriteConverter.java
@@ -22,9 +22,11 @@ public class QueryPolicyWriteConverter implements Converter resourceBlackList = new HashSet<>();
+ @JsonProperty("cron-expression")
+ @Column("cron_expression")
+ private String cronExpression;
+
@JsonCreator
public ResourceNotificationPolicy(
@JsonProperty("pk") Long pk,
@JsonProperty("id") String id,
+ @JsonProperty("git-commit") String gitCommit,
@JsonProperty("resource-email-template") EmailNotificationTemplate resourceEmailTemplate,
@JsonProperty("resource-email-metadata") ResourceEmailMetadata resourceEmailMetadata,
@JsonProperty("resource-whitelist") Set resourceWhiteList,
- @JsonProperty("resource-blacklist") Set resourceBlackList
+ @JsonProperty("resource-blacklist") Set resourceBlackList,
+ @JsonProperty("cron-expression") String cronExpression
) {
this.pk = pk;
this.id = id;
+ this.gitCommit = gitCommit;
this.resourceEmailTemplate = resourceEmailTemplate;
this.resourceEmailMetadata = resourceEmailMetadata;
this.resourceWhiteList = resourceWhiteList;
this.resourceBlackList = resourceBlackList;
+ this.cronExpression = cronExpression;
+ }
+
+ public String getCronExpression() {
+ return StringUtils.isBlank(cronExpression) ? defaultCronExpression(): cronExpression;
+ }
+
+ @JsonIgnore
+ public Long getPk() {
+ return pk;
}
public Set getResourceWhiteList() {
@@ -100,8 +124,4 @@ public Set getResourceBlackList() {
return CollectionUtils.isEmpty(resourceBlackList) ? new HashSet<>() : Collections.unmodifiableSet(resourceBlackList);
}
- @JsonIgnore
- public Long getPk() {
- return pk;
- }
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/ResourceNotificationPolicyReadConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/ResourceNotificationPolicyReadConverter.java
index f39a8dac..eb5907df 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/ResourceNotificationPolicyReadConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/ResourceNotificationPolicyReadConverter.java
@@ -24,10 +24,12 @@ public ResourceNotificationPolicy convert(Row source) {
.builder()
.pk(source.get("pk", Long.class))
.id(source.get("id", String.class))
+ .gitCommit(source.get("git_commit", String.class))
.resourceEmailTemplate(readEmailNotificationTemplate(source.get("resource_email_template", String.class) == null ? "{}": source.get("resource_email_template", String.class)))
.resourceEmailMetadata(readResourceEmailMetadata(source.get("resource_email_metadata", String.class) == null ? "{}": source.get("resource_email_metadata", String.class)))
.resourceWhiteList(CsvUtil.parse(source.get("resource_whitelist", String.class)))
.resourceBlackList(CsvUtil.parse(source.get("resource_blacklist", String.class)))
+ .cronExpression(source.get("cron_expression", String.class))
.build();
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/ResourceNotificationPolicyWriteConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/ResourceNotificationPolicyWriteConverter.java
index c1421117..49ae45f6 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/ResourceNotificationPolicyWriteConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/ResourceNotificationPolicyWriteConverter.java
@@ -22,10 +22,12 @@ public class ResourceNotificationPolicyWriteConverter implements Converter> operationTaskMap = new EnumMap<>(ServiceInstanceOperation.class);
+ static {
+ operationTaskMap.put(ServiceInstanceOperation.DELETE, DeleteServiceInstancePolicyExecutorTask.class);
+ }
+
public static ServiceInstanceOperation from(String name) {
Assert.hasText(name, "ServiceInstanceOperation must not be null or empty");
ServiceInstanceOperation result = Arrays.asList(ServiceInstanceOperation.values()).stream().filter(s -> s.getName().equalsIgnoreCase(name)).collect(Collectors.toList()).get(0);
@@ -18,10 +33,8 @@ public static ServiceInstanceOperation from(String name) {
return result;
}
- private final String name;
-
- ServiceInstanceOperation(String name) {
- this.name = name;
+ public static Class extends PolicyExecutorTask> getTaskType(String op) {
+ return operationTaskMap.get(from(op));
}
@JsonValue
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicy.java b/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicy.java
index 8df86d15..6d0ac21a 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicy.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicy.java
@@ -8,6 +8,7 @@
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.annotation.Id;
+import org.springframework.data.relational.core.mapping.Column;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
@@ -25,17 +26,10 @@
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
-@JsonPropertyOrder({ "id", "operation", "description", "options", "organization-whitelist" })
+@JsonPropertyOrder({ "id", "git-commit", "operation", "description", "options", "organization-whitelist", "cron-expression" })
@Getter
@ToString
-public class ServiceInstancePolicy implements HasOrganizationWhiteList {
-
- public static String[] columnNames() {
- return
- new String[] {
- "pk", "id", "operation", "description", "options", "organization_whitelist"
- };
- }
+public class ServiceInstancePolicy implements HasOrganizationWhiteList, Policy {
public static ServiceInstancePolicy seed(ServiceInstancePolicy policy) {
return ServiceInstancePolicy
@@ -44,17 +38,19 @@ public static ServiceInstancePolicy seed(ServiceInstancePolicy policy) {
.operation(policy.getOperation())
.options(policy.getOptions())
.organizationWhiteList(policy.getOrganizationWhiteList())
+ .cronExpression(policy.getCronExpression())
.build();
}
- public static ServiceInstancePolicy seedWith(ServiceInstancePolicy policy, String id) {
+ public static ServiceInstancePolicy seedWith(ServiceInstancePolicy policy, String gitCommit) {
return ServiceInstancePolicy
.builder()
- .id(id)
+ .gitCommit(gitCommit)
.description(policy.getDescription())
.operation(policy.getOperation())
.options(policy.getOptions())
.organizationWhiteList(policy.getOrganizationWhiteList())
+ .cronExpression(policy.getCronExpression())
.build();
}
@@ -70,6 +66,10 @@ public static String tableName() {
@JsonProperty("id")
private String id = Generators.timeBasedGenerator().generate().toString();
+ @JsonProperty("git-commit")
+ @Column("git_commit")
+ private String gitCommit;
+
@JsonProperty("operation")
private String operation;
@@ -84,20 +84,32 @@ public static String tableName() {
@JsonProperty("organization-whitelist")
private Set organizationWhiteList = new HashSet<>();
+ @JsonProperty("cron-expression")
+ @Column("cron_expression")
+ private String cronExpression;
+
@JsonCreator
ServiceInstancePolicy(
@JsonProperty("pk") Long pk,
@JsonProperty("id") String id,
+ @JsonProperty("git-commit") String gitCommit,
@JsonProperty("operation") String operation,
@JsonProperty("description") String description,
@JsonProperty("options") Map options,
- @JsonProperty("organization-whitelist") Set organizationWhiteList) {
+ @JsonProperty("organization-whitelist") Set organizationWhiteList,
+ @JsonProperty("cron-expression") String cronExpression) {
this.pk = pk;
this.id = id;
+ this.gitCommit = gitCommit;
this.operation = operation;
this.description = description;
this.options = options;
this.organizationWhiteList = organizationWhiteList;
+ this.cronExpression = cronExpression;
+ }
+
+ public String getCronExpression() {
+ return StringUtils.isBlank(cronExpression) ? defaultCronExpression(): cronExpression;
}
@JsonIgnore
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicyReadConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicyReadConverter.java
index ee8157a5..2bda66d6 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicyReadConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicyReadConverter.java
@@ -26,10 +26,12 @@ public ServiceInstancePolicy convert(Row source) {
.builder()
.pk(source.get("pk", Long.class))
.id(source.get("id", String.class))
+ .gitCommit(source.get("git_commit", String.class))
.operation(source.get("operation", String.class))
.description(source.get("description", String.class))
.options(readOptions(source.get("options", String.class) == null ? "{}" : source.get("options", String.class)))
.organizationWhiteList(CsvUtil.parse(source.get("organization_whitelist", String.class)))
+ .cronExpression(source.get("cron_expression", String.class))
.build();
}
diff --git a/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicyWriteConverter.java b/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicyWriteConverter.java
index dfe3816b..bb8712cc 100644
--- a/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicyWriteConverter.java
+++ b/src/main/java/org/cftoolsuite/cfapp/domain/ServiceInstancePolicyWriteConverter.java
@@ -23,10 +23,12 @@ public class ServiceInstancePolicyWriteConverter implements Converter findQueryPolicyById(String id);
Mono findServiceInstancePolicyById(String id);
Mono save(Policies entity);
+ Mono