aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorsebdet <sebastien.determe@intl.att.com>2020-02-13 05:49:21 -0800
committersebdet <sebastien.determe@intl.att.com>2020-02-14 05:11:42 -0800
commit29e3cd1afbd3202a0c16ef6a4057662942ddefa2 (patch)
treeb7811512dc4f7c08f7f2695868e3be66e57572a3 /src/main
parent728ad5ce6d3b5e3d973b6349469f96d6c3600fef (diff)
Add tests
Add tests for https and aaf Issue-ID: CLAMP-624 Signed-off-by: sebdet <sebastien.determe@intl.att.com> Change-Id: Ia78ed8da7e54eaeaaed4fb87f483e0aff3a4a8c5
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java67
-rw-r--r--src/main/java/org/onap/clamp/policy/downloader/PolicyEngineController.java29
2 files changed, 73 insertions, 23 deletions
diff --git a/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java
index e916afc1f..2302cc891 100644
--- a/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java
+++ b/src/main/java/org/onap/clamp/clds/client/PolicyEngineServices.java
@@ -26,6 +26,11 @@ package org.onap.clamp.clds.client;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.builder.ExchangeBuilder;
@@ -38,6 +43,10 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
+import org.yaml.snakeyaml.Yaml;
+
+
+
/**
* The class implements the communication with the Policy Engine to retrieve
@@ -60,27 +69,52 @@ public class PolicyEngineServices {
public static final String POLICY_RETRY_INTERVAL = "policy.retry.interval";
public static final String POLICY_RETRY_LIMIT = "policy.retry.limit";
+ /**
+ * Default constructor.
+ *
+ * @param camelContext Camel context bean
+ * @param clampProperties ClampProperties bean
+ * @param policyModelsRepository policyModel repository bean
+ */
@Autowired
- public PolicyEngineServices(CamelContext camelContext, ClampProperties refProp,
+ public PolicyEngineServices(CamelContext camelContext, ClampProperties clampProperties,
PolicyModelsRepository policyModelsRepository) {
this.camelContext = camelContext;
this.policyModelsRepository = policyModelsRepository;
- if (refProp.getStringValue(POLICY_RETRY_LIMIT) != null) {
- retryLimit = Integer.valueOf(refProp.getStringValue(POLICY_RETRY_LIMIT));
+ if (clampProperties.getStringValue(POLICY_RETRY_LIMIT) != null) {
+ retryLimit = Integer.valueOf(clampProperties.getStringValue(POLICY_RETRY_LIMIT));
}
- if (refProp.getStringValue(POLICY_RETRY_INTERVAL) != null) {
- retryInterval = Integer.valueOf(refProp.getStringValue(POLICY_RETRY_INTERVAL));
+ if (clampProperties.getStringValue(POLICY_RETRY_INTERVAL) != null) {
+ retryInterval = Integer.valueOf(clampProperties.getStringValue(POLICY_RETRY_INTERVAL));
}
}
+ /**
+ * This method query Policy engine and create a PolicyModel object with type and version.
+ *
+ * @param policyType The policyType id
+ * @param policyVersion The policy version of that type
+ * @return A PolicyModel created from policyEngine data
+ */
public PolicyModel createPolicyModelFromPolicyEngine(String policyType, String policyVersion) {
return new PolicyModel(policyType, this.downloadOnePolicy(policyType, policyVersion), policyVersion);
}
+ /**
+ * This method query Policy engine and create a PolicyModel object with type and version.
+ *
+ * @param microService microservice object instance
+ * @return A PolicyModel created from policyEngine data
+ */
public PolicyModel createPolicyModelFromPolicyEngine(BlueprintMicroService microService) {
return createPolicyModelFromPolicyEngine(microService.getModelType(), microService.getModelVersion());
}
+ /**
+ * Thie method creates an PolicyModel in Db if it does not exist.
+ *
+ * @param policyModel The policyModel to save
+ */
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void createPolicyInDbIfNeeded(PolicyModel policyModel) {
if (!policyModelsRepository
@@ -90,6 +124,29 @@ public class PolicyEngineServices {
}
/**
+ * This method synchronize the clamp database and the policy engine.
+ * So it creates the required PolicyModel.
+ */
+ public void synchronizeAllPolicies() {
+ LinkedHashMap<String, Object> loadedYaml;
+ loadedYaml = new Yaml().load(downloadAllPolicies());
+ if (loadedYaml == null || loadedYaml.isEmpty()) {
+ logger.warn("getAllPolicyType yaml returned by policy engine could not be decoded, as it's null or empty");
+ return;
+ }
+
+ List<LinkedHashMap<String, Object>> policyTypesList = (List<LinkedHashMap<String, Object>>) loadedYaml
+ .get("policy_types");
+ policyTypesList.parallelStream().forEach(policyType -> {
+ Map.Entry<String, Object> policyTypeEntry = (Map.Entry<String, Object>) new ArrayList(policyType.entrySet()).get(0);
+
+ createPolicyInDbIfNeeded(
+ createPolicyModelFromPolicyEngine(policyTypeEntry.getKey(),
+ ((String) ((LinkedHashMap<String, Object>) policyTypeEntry.getValue()).get("version"))));
+ });
+ }
+
+ /**
* This method can be used to download all policy types + data types defined in
* policy engine.
*
diff --git a/src/main/java/org/onap/clamp/policy/downloader/PolicyEngineController.java b/src/main/java/org/onap/clamp/policy/downloader/PolicyEngineController.java
index f3eaf0c83..50be035b2 100644
--- a/src/main/java/org/onap/clamp/policy/downloader/PolicyEngineController.java
+++ b/src/main/java/org/onap/clamp/policy/downloader/PolicyEngineController.java
@@ -26,6 +26,7 @@ package org.onap.clamp.policy.downloader;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
+import java.time.Instant;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
@@ -56,31 +57,23 @@ public class PolicyEngineController {
private final PolicyEngineServices policyEngineServices;
+ private Instant lastInstantExecuted;
+
@Autowired
public PolicyEngineController(PolicyEngineServices policyEngineService,
- PolicyModelsRepository policyModelsRepository) {
+ PolicyModelsRepository policyModelsRepository) {
this.policyEngineServices = policyEngineService;
}
@Scheduled(fixedRate = 120000)
- public void synchronizeAllPolicies() {
- LinkedHashMap<String, Object> loadedYaml;
- loadedYaml = new Yaml().load(policyEngineServices.downloadAllPolicies());
- if (loadedYaml == null || loadedYaml.isEmpty()) {
- logger.warn("getAllPolicyType yaml returned by policy engine could not be decoded, as it's null or empty");
- return;
- }
-
- List<LinkedHashMap<String, Object>> policyTypesList = (List<LinkedHashMap<String, Object>>) loadedYaml
- .get("policy_types");
- policyTypesList.parallelStream().forEach(policyType -> {
- Entry<String, Object> policyTypeEntry = (Entry<String, Object>) new ArrayList(policyType.entrySet()).get(0);
-
- policyEngineServices.createPolicyInDbIfNeeded(
- policyEngineServices.createPolicyModelFromPolicyEngine(policyTypeEntry.getKey(),
- ((String) ((LinkedHashMap<String, Object>) policyTypeEntry.getValue()).get("version"))));
+ public synchronized void synchronizeAllPolicies() {
+ policyEngineServices.synchronizeAllPolicies();
+ lastInstantExecuted = Instant.now();
+ }
- });
+ public Instant getLastInstantExecuted() {
+ return lastInstantExecuted;
}
+
}