summaryrefslogtreecommitdiffstats
path: root/runtime-controlloop
diff options
context:
space:
mode:
authorFrancescoFioraEst <francesco.fiora@est.tech>2021-09-30 11:28:28 +0100
committerFrancescoFioraEst <francesco.fiora@est.tech>2021-10-04 14:26:37 +0100
commit1ead22e0bf08c7cd95e900267f4ba89e131b7f36 (patch)
treebfbfc5c8f498fa8ecce3fd719fdd6caae46259a4 /runtime-controlloop
parent7c4cea7c3ee9031092facf20ff8df937d56d2c2e (diff)
Fix startPhase delay
Issue-ID: POLICY-3624 Change-Id: Ie7e25ddc3796324246f267dd0c92b9bc1fe15aa2 Signed-off-by: FrancescoFioraEst <francesco.fiora@est.tech>
Diffstat (limited to 'runtime-controlloop')
-rw-r--r--runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java38
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java87
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java38
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java8
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java28
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java8
-rw-r--r--runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java49
7 files changed, 141 insertions, 115 deletions
diff --git a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
index 684711677..df7efbe9c 100644
--- a/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
+++ b/runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScanner.java
@@ -22,7 +22,9 @@
package org.onap.policy.clamp.controlloop.runtime.supervision;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
import org.apache.commons.lang3.tuple.Pair;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopElement;
@@ -53,11 +55,13 @@ import org.springframework.stereotype.Component;
public class SupervisionScanner {
private static final Logger LOGGER = LoggerFactory.getLogger(SupervisionScanner.class);
- private HandleCounter<ToscaConceptIdentifier> controlLoopCounter = new HandleCounter<>();
- private HandleCounter<ToscaConceptIdentifier> participantStatusCounter = new HandleCounter<>();
- private HandleCounter<Pair<ToscaConceptIdentifier, ToscaConceptIdentifier>> participantUpdateCounter =
+ private final HandleCounter<ToscaConceptIdentifier> controlLoopCounter = new HandleCounter<>();
+ private final HandleCounter<ToscaConceptIdentifier> participantStatusCounter = new HandleCounter<>();
+ private final HandleCounter<Pair<ToscaConceptIdentifier, ToscaConceptIdentifier>> participantUpdateCounter =
new HandleCounter<>();
+ private final Map<ToscaConceptIdentifier, Integer> phaseMap = new HashMap<>();
+
private final ControlLoopProvider controlLoopProvider;
private final PolicyModelsProvider modelsProvider;
private final ControlLoopStateChangePublisher controlLoopStateChangePublisher;
@@ -224,7 +228,6 @@ public class SupervisionScanner {
int startPhase = ParticipantUtils.findStartPhase(toscaNodeTemplate.getProperties());
minSpNotCompleted = Math.min(minSpNotCompleted, startPhase);
}
-
}
if (completed) {
@@ -239,7 +242,12 @@ public class SupervisionScanner {
} else {
LOGGER.debug("control loop scan: transition from state {} to {} not completed", controlLoop.getState(),
controlLoop.getOrderedState());
- if (counterCheck) {
+
+ if (minSpNotCompleted != phaseMap.getOrDefault(controlLoop.getKey().asIdentifier(), 0)
+ && ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) {
+ phaseMap.put(controlLoop.getKey().asIdentifier(), minSpNotCompleted);
+ sendControlLoopMsg(controlLoop, minSpNotCompleted);
+ } else if (counterCheck) {
handleCounter(controlLoop, minSpNotCompleted);
}
}
@@ -247,6 +255,7 @@ public class SupervisionScanner {
private void clearFaultAndCounter(ControlLoop controlLoop) {
controlLoopCounter.clear(controlLoop.getKey().asIdentifier());
+ phaseMap.clear();
}
private void handleCounter(ControlLoop controlLoop, int startPhase) {
@@ -258,17 +267,22 @@ public class SupervisionScanner {
if (controlLoopCounter.getDuration(id) > controlLoopCounter.getMaxWaitMs()) {
if (controlLoopCounter.count(id)) {
- if (ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) {
- LOGGER.debug("retry message ControlLoopUpdate");
- controlLoopUpdatePublisher.send(controlLoop, startPhase);
- } else {
- LOGGER.debug("retry message ControlLoopStateChange");
- controlLoopStateChangePublisher.send(controlLoop);
- }
+ phaseMap.put(id, startPhase);
+ sendControlLoopMsg(controlLoop, startPhase);
} else {
LOGGER.debug("report ControlLoop fault");
controlLoopCounter.setFault(id);
}
}
}
+
+ private void sendControlLoopMsg(ControlLoop controlLoop, int startPhase) {
+ if (ControlLoopState.UNINITIALISED2PASSIVE.equals(controlLoop.getState())) {
+ LOGGER.debug("retry message ControlLoopUpdate");
+ controlLoopUpdatePublisher.send(controlLoop, startPhase);
+ } else {
+ LOGGER.debug("retry message ControlLoopStateChange");
+ controlLoopStateChangePublisher.send(controlLoop);
+ }
+ }
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
index 3e038f3fc..b0ea00913 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/CommissioningProviderTest.java
@@ -35,12 +35,11 @@ import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.coder.YamlJsonTranslator;
-import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaCapabilityType;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -56,9 +55,8 @@ class CommissioningProviderTest {
private static final String TOSCA_SERVICE_TEMPLATE_YAML =
"src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml";
private static final String COMMON_TOSCA_SERVICE_TEMPLATE_YAML =
- "src/test/resources/rest/servicetemplates/full-tosca-with-common-properties.yaml";
+ "src/test/resources/rest/servicetemplates/full-tosca-with-common-properties.yaml";
private static final String TEMPLATE_IS_NULL = ".*serviceTemplate is marked non-null but is null";
- private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
private PolicyModelsProvider modelsProvider = null;
private ControlLoopProvider clProvider = null;
@@ -92,10 +90,9 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
- null, participantProvider);
- ToscaServiceTemplate serviceTemplate = yamlTranslator
- .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ CommissioningProvider provider =
+ new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null);
assertThat(listOfTemplates).isEmpty();
@@ -131,15 +128,14 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
- null, participantProvider);
+ CommissioningProvider provider =
+ new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
// Test Service template is null
assertThatThrownBy(() -> provider.createControlLoopDefinitions(null)).hasMessageMatching(TEMPLATE_IS_NULL);
List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null);
assertThat(listOfTemplates).isEmpty();
- ToscaServiceTemplate serviceTemplate = yamlTranslator
- .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
// Response should return the number of node templates present in the service template
List<ToscaConceptIdentifier> affectedDefinitions =
@@ -158,23 +154,22 @@ class CommissioningProviderTest {
void testGetToscaServiceTemplate() throws Exception {
ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("getCLDefinitions");
modelsProvider =
- CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
- null, participantProvider);
- ToscaServiceTemplate serviceTemplate = yamlTranslator
- .fromYaml(ResourceUtils
- .getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ CommissioningProvider provider =
+ new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ ToscaServiceTemplate serviceTemplate =
+ InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML);
provider.createControlLoopDefinitions(serviceTemplate);
ToscaServiceTemplate returnedServiceTemplate = provider.getToscaServiceTemplate(null, null);
assertThat(returnedServiceTemplate).isNotNull();
- Map<String, ToscaNodeTemplate> nodeTemplates = returnedServiceTemplate
- .getToscaTopologyTemplate().getNodeTemplates();
+ Map<String, ToscaNodeTemplate> nodeTemplates =
+ returnedServiceTemplate.getToscaTopologyTemplate().getNodeTemplates();
assertThat(nodeTemplates).hasSize(8);
}
@@ -188,15 +183,14 @@ class CommissioningProviderTest {
void testGetToscaServiceTemplateReduced() throws Exception {
ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("getCLDefinitions");
modelsProvider =
- CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
- null, participantProvider);
- ToscaServiceTemplate serviceTemplate = yamlTranslator
- .fromYaml(ResourceUtils
- .getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ CommissioningProvider provider =
+ new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ ToscaServiceTemplate serviceTemplate =
+ InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML);
provider.createControlLoopDefinitions(serviceTemplate);
@@ -218,29 +212,23 @@ class CommissioningProviderTest {
ClRuntimeParameterGroup clRuntimeParameterGroup = CommonTestData.geParameterGroup("getCLDefinitions");
modelsProvider =
- CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
+ CommonTestData.getPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
- null, participantProvider);
- ToscaServiceTemplate serviceTemplate = yamlTranslator
- .fromYaml(ResourceUtils
- .getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ CommissioningProvider provider =
+ new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ ToscaServiceTemplate serviceTemplate =
+ InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML);
provider.createControlLoopDefinitions(serviceTemplate);
mapper.setPropertyNamingStrategy(PropertyNamingStrategies.SNAKE_CASE);
- Map<String, Class<?>> sections = Map.of(
- "all", ToscaServiceTemplate.class,
- "data_types", ToscaDataType.class,
- "capability_types", ToscaCapabilityType.class,
- "node_types", ToscaNodeType.class,
- "relationship_types", ToscaRelationshipType.class,
- "policy_types", ToscaPolicyType.class,
- "topology_template", ToscaTopologyTemplate.class,
- "node_templates", List.class);
+ Map<String, Class<?>> sections = Map.of("all", ToscaServiceTemplate.class, "data_types", ToscaDataType.class,
+ "capability_types", ToscaCapabilityType.class, "node_types", ToscaNodeType.class, "relationship_types",
+ ToscaRelationshipType.class, "policy_types", ToscaPolicyType.class, "topology_template",
+ ToscaTopologyTemplate.class, "node_templates", List.class);
for (Map.Entry<String, Class<?>> entry : sections.entrySet()) {
String returnedServiceTemplateSchema = provider.getToscaServiceTemplateSchema(entry.getKey());
@@ -250,8 +238,7 @@ class CommissioningProviderTest {
if (entry.getKey().equals("node_templates")) {
mapper.acceptJsonFormatVisitor(
- mapper.getTypeFactory().constructCollectionType(List.class, ToscaNodeTemplate.class),
- visitor);
+ mapper.getTypeFactory().constructCollectionType(List.class, ToscaNodeTemplate.class), visitor);
} else {
mapper.acceptJsonFormatVisitor(mapper.constructType(entry.getValue()), visitor);
}
@@ -275,10 +262,9 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
- null, participantProvider);
- ToscaServiceTemplate serviceTemplate = yamlTranslator
- .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ CommissioningProvider provider =
+ new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
List<ToscaNodeTemplate> listOfTemplates = provider.getControlLoopDefinitions(null, null);
assertThat(listOfTemplates).isEmpty();
@@ -305,10 +291,9 @@ class CommissioningProviderTest {
clProvider = new ControlLoopProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
participantProvider = new ParticipantProvider(clRuntimeParameterGroup.getDatabaseProviderParameters());
- CommissioningProvider provider = new CommissioningProvider(modelsProvider, clProvider,
- null, participantProvider);
- ToscaServiceTemplate serviceTemplate = yamlTranslator
- .fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML), ToscaServiceTemplate.class);
+ CommissioningProvider provider =
+ new CommissioningProvider(modelsProvider, clProvider, null, participantProvider);
+ ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
provider.getControlLoopDefinitions(null, null);
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java
index 481192927..4a5a6e2a3 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/commissioning/rest/CommissioningControllerTest.java
@@ -40,10 +40,9 @@ import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.onap.policy.clamp.controlloop.models.messages.rest.commissioning.CommissioningResponse;
+import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParameterGroup;
import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController;
-import org.onap.policy.common.utils.coder.YamlJsonTranslator;
-import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.tosca.authorative.concepts.ToscaNodeTemplate;
@@ -64,8 +63,8 @@ class CommissioningControllerTest extends CommonRestController {
private static final String TOSCA_SERVICE_TEMPLATE_YAML =
"src/test/resources/rest/servicetemplates/pmsh_multiple_cl_tosca.yaml";
private static final String COMMON_TOSCA_SERVICE_TEMPLATE_YAML =
- "src/test/resources/rest/servicetemplates/full-tosca-with-common-properties.yaml";
- private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
+ "src/test/resources/rest/servicetemplates/full-tosca-with-common-properties.yaml";
+
private static final String COMMISSIONING_ENDPOINT = "commission";
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
private static ToscaServiceTemplate commonPropertiesServiceTemplate = new ToscaServiceTemplate();
@@ -84,11 +83,9 @@ class CommissioningControllerTest extends CommonRestController {
@BeforeAll
public static void setUpBeforeClass() throws Exception {
- serviceTemplate = yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(TOSCA_SERVICE_TEMPLATE_YAML),
- ToscaServiceTemplate.class);
- commonPropertiesServiceTemplate = yamlTranslator.fromYaml(ResourceUtils
- .getResourceAsString(COMMON_TOSCA_SERVICE_TEMPLATE_YAML),
- ToscaServiceTemplate.class);
+ serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ commonPropertiesServiceTemplate =
+ InstantiationUtils.getToscaServiceTemplate(COMMON_TOSCA_SERVICE_TEMPLATE_YAML);
}
@BeforeEach
@@ -146,8 +143,7 @@ class CommissioningControllerTest extends CommonRestController {
void testQueryToscaServiceTemplate() throws Exception {
createFullEntryInDbWithCommonProps();
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
- + "/toscaservicetemplate");
+ Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/toscaservicetemplate");
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
ToscaServiceTemplate template = rawresp.readEntity(ToscaServiceTemplate.class);
@@ -160,8 +156,8 @@ class CommissioningControllerTest extends CommonRestController {
void testQueryToscaServiceTemplateSchema() throws Exception {
createFullEntryInDbWithCommonProps();
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
- + "/toscaServiceTemplateSchema");
+ Invocation.Builder invocationBuilder =
+ super.sendRequest(COMMISSIONING_ENDPOINT + "/toscaServiceTemplateSchema");
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
String schema = rawresp.readEntity(String.class);
@@ -174,7 +170,7 @@ class CommissioningControllerTest extends CommonRestController {
createFullEntryInDbWithCommonProps();
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
- + "/getCommonOrInstanceProperties" + "?common=true&name=ToscaServiceTemplateSimple&version=1.0.0");
+ + "/getCommonOrInstanceProperties" + "?common=true&name=ToscaServiceTemplateSimple&version=1.0.0");
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
@@ -244,7 +240,7 @@ class CommissioningControllerTest extends CommonRestController {
void testQueryElementsBadRequest() throws Exception {
createEntryInDB();
- //Call get elements with no info
+ // Call get elements with no info
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/elements");
Response resp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.NOT_ACCEPTABLE.getStatusCode(), resp.getStatus());
@@ -255,8 +251,8 @@ class CommissioningControllerTest extends CommonRestController {
void testQueryElements() throws Exception {
createEntryInDB();
- Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/elements"
- + "?name=org.onap.domain.pmsh.PMSHControlLoopDefinition");
+ Invocation.Builder invocationBuilder = super.sendRequest(
+ COMMISSIONING_ENDPOINT + "/elements" + "?name=org.onap.domain.pmsh.PMSHControlLoopDefinition");
Response rawresp = invocationBuilder.buildGet().invoke();
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
List<?> entityList = rawresp.readEntity(List.class);
@@ -270,7 +266,7 @@ class CommissioningControllerTest extends CommonRestController {
createEntryInDB();
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
- //Call delete with no info
+ // Call delete with no info
Response resp = invocationBuilder.delete();
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), resp.getStatus());
@@ -282,7 +278,7 @@ class CommissioningControllerTest extends CommonRestController {
Invocation.Builder invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "?name="
+ serviceTemplate.getName() + "&version=" + serviceTemplate.getVersion());
- //Call delete with no info
+ // Call delete with no info
Response resp = invocationBuilder.delete();
assertEquals(Response.Status.OK.getStatusCode(), resp.getStatus());
@@ -305,7 +301,7 @@ class CommissioningControllerTest extends CommonRestController {
// Delete entries from the DB after relevant tests
private synchronized void deleteEntryInDB(String name, String version) throws Exception {
try (PolicyModelsProvider modelsProvider = new PolicyModelsProviderFactory()
- .createPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters())) {
+ .createPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters())) {
if (!modelsProvider.getServiceTemplateList(null, null).isEmpty()) {
modelsProvider.deleteServiceTemplate(name, version);
}
@@ -314,7 +310,7 @@ class CommissioningControllerTest extends CommonRestController {
private synchronized void createFullEntryInDbWithCommonProps() throws Exception {
try (PolicyModelsProvider modelsProvider = new PolicyModelsProviderFactory()
- .createPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters())) {
+ .createPolicyModelsProvider(clRuntimeParameterGroup.getDatabaseProviderParameters())) {
deleteEntryInDB(commonPropertiesServiceTemplate.getName(), commonPropertiesServiceTemplate.getVersion());
modelsProvider.createServiceTemplate(commonPropertiesServiceTemplate);
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
index 24272e308..abf0cfc3e 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProviderTest.java
@@ -26,7 +26,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.List;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
@@ -53,8 +52,6 @@ import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantDer
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantRegisterAckPublisher;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantUpdatePublisher;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
-import org.onap.policy.common.utils.coder.YamlJsonTranslator;
-import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -97,8 +94,6 @@ class ControlLoopInstantiationProviderTest {
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
- private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
-
private static SupervisionHandler supervisionHandler;
private static CommissioningProvider commissioningProvider;
private static ControlLoopProvider clProvider;
@@ -107,8 +102,7 @@ class ControlLoopInstantiationProviderTest {
@BeforeAll
public static void setUpBeforeClass() throws Exception {
- serviceTemplate = yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(TOSCA_TEMPLATE_YAML),
- ToscaServiceTemplate.class);
+ serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
}
/**
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java
index c107986a5..5aa68657c 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/InstantiationUtils.java
@@ -23,21 +23,18 @@ package org.onap.policy.clamp.controlloop.runtime.instantiation;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
import java.io.File;
-import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop;
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
-import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstancePropertiesResponse;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationCommand;
import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.InstantiationResponse;
-import org.onap.policy.clamp.controlloop.runtime.commissioning.CommissioningProvider;
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.common.utils.coder.YamlJsonTranslator;
+import org.onap.policy.common.utils.coder.StandardYamlCoder;
import org.onap.policy.common.utils.resources.ResourceUtils;
-import org.onap.policy.models.base.PfModelException;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
@@ -47,7 +44,7 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
public class InstantiationUtils {
private static final Coder CODER = new StandardCoder();
- private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
+ private static final StandardYamlCoder YAML_TRANSLATOR = new StandardYamlCoder();
/**
* Gets the ControlLoops from Resource.
@@ -128,20 +125,17 @@ public class InstantiationUtils {
}
/**
- * Store ToscaServiceTemplate from resource to DB.
+ * Get ToscaServiceTemplate from resource.
*
* @param path path of the resource
- * @param commissioningProvider The CommissioningProvider
- * @throws PfModelException if an error occurs
*/
- public static void storeToscaServiceTemplate(String path, CommissioningProvider commissioningProvider)
- throws PfModelException, ControlLoopException {
+ public static ToscaServiceTemplate getToscaServiceTemplate(String path) {
- ToscaServiceTemplate template =
- yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(path), ToscaServiceTemplate.class);
-
- commissioningProvider.deleteControlLoopDefinition(null, null);
-
- commissioningProvider.createControlLoopDefinitions(template);
+ try {
+ return YAML_TRANSLATOR.decode(ResourceUtils.getResourceAsStream(path), ToscaServiceTemplate.class);
+ } catch (CoderException e) {
+ fail("Cannot read or decode " + path);
+ return null;
+ }
}
}
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
index 5a15687c5..2e01be289 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/instantiation/rest/InstantiationControllerTest.java
@@ -46,8 +46,6 @@ import org.onap.policy.clamp.controlloop.runtime.main.parameters.ClRuntimeParame
import org.onap.policy.clamp.controlloop.runtime.main.rest.InstantiationController;
import org.onap.policy.clamp.controlloop.runtime.util.CommonTestData;
import org.onap.policy.clamp.controlloop.runtime.util.rest.CommonRestController;
-import org.onap.policy.common.utils.coder.YamlJsonTranslator;
-import org.onap.policy.common.utils.resources.ResourceUtils;
import org.onap.policy.models.provider.PolicyModelsProvider;
import org.onap.policy.models.provider.PolicyModelsProviderFactory;
import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
@@ -87,9 +85,6 @@ class InstantiationControllerTest extends CommonRestController {
private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
- private static final YamlJsonTranslator yamlTranslator = new YamlJsonTranslator();
-
-
@Autowired
private ClRuntimeParameterGroup clRuntimeParameterGroup;
@@ -104,8 +99,7 @@ class InstantiationControllerTest extends CommonRestController {
@BeforeAll
public static void setUpBeforeClass() throws Exception {
- serviceTemplate = yamlTranslator.fromYaml(ResourceUtils.getResourceAsString(TOSCA_TEMPLATE_YAML),
- ToscaServiceTemplate.class);
+ serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_TEMPLATE_YAML);
}
@BeforeEach
diff --git a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
index 1bf445734..47cc6f1dc 100644
--- a/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
+++ b/runtime-controlloop/src/test/java/org/onap/policy/clamp/controlloop/runtime/supervision/SupervisionScannerTest.java
@@ -22,6 +22,7 @@ package org.onap.policy.clamp.controlloop.runtime.supervision;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -40,6 +41,7 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.Participant
import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ParticipantState;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ParticipantProvider;
+import org.onap.policy.clamp.controlloop.runtime.instantiation.InstantiationUtils;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopStateChangePublisher;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ControlLoopUpdatePublisher;
import org.onap.policy.clamp.controlloop.runtime.supervision.comm.ParticipantStatusReqPublisher;
@@ -52,6 +54,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
class SupervisionScannerTest {
+ private static final String TOSCA_SERVICE_TEMPLATE_YAML =
+ "src/test/resources/rest/servicetemplates/tosca-for-smoke-testing.yaml";
+
@Test
void testScannerOrderedStateEqualsToState() throws PfModelException {
var controlLoopProvider = mock(ControlLoopProvider.class);
@@ -131,6 +136,50 @@ class SupervisionScannerTest {
}
@Test
+ void testSendControlLoopMsgUpdate() throws PfModelException {
+ var controlLoop = new ControlLoop();
+ controlLoop.setState(ControlLoopState.UNINITIALISED2PASSIVE);
+ controlLoop.setOrderedState(ControlLoopOrderedState.PASSIVE);
+ controlLoop.setElements(Map.of(UUID.randomUUID(),
+ createHttpElement(ControlLoopState.UNINITIALISED, ControlLoopOrderedState.PASSIVE)));
+
+ var controlLoopProvider = mock(ControlLoopProvider.class);
+ when(controlLoopProvider.getControlLoops(null, null)).thenReturn(List.of(controlLoop));
+
+ ToscaServiceTemplate serviceTemplate = InstantiationUtils.getToscaServiceTemplate(TOSCA_SERVICE_TEMPLATE_YAML);
+ var modelsProvider = mock(PolicyModelsProvider.class);
+ when(modelsProvider.getServiceTemplateList(null, null)).thenReturn(List.of(serviceTemplate));
+
+ var participantProvider = mock(ParticipantProvider.class);
+ var controlLoopUpdatePublisher = mock(ControlLoopUpdatePublisher.class);
+ var participantStatusReqPublisher = mock(ParticipantStatusReqPublisher.class);
+ var controlLoopStateChangePublisher = mock(ControlLoopStateChangePublisher.class);
+ var participantUpdatePublisher = mock(ParticipantUpdatePublisher.class);
+ var clRuntimeParameterGroup = CommonTestData.geParameterGroup("dbScanner");
+
+ var supervisionScanner = new SupervisionScanner(controlLoopProvider, modelsProvider,
+ controlLoopStateChangePublisher, controlLoopUpdatePublisher, participantProvider,
+ participantStatusReqPublisher, participantUpdatePublisher, clRuntimeParameterGroup);
+
+ supervisionScanner.run(false);
+
+ verify(controlLoopUpdatePublisher).send(any(ControlLoop.class), anyInt());
+ }
+
+ private ControlLoopElement createHttpElement(ControlLoopState state, ControlLoopOrderedState orderedState) {
+ var element = new ControlLoopElement();
+ element.setDefinition(new ToscaConceptIdentifier(
+ "org.onap.domain.database.Http_PMSHMicroserviceControlLoopElement", "1.2.3"));
+ element.setState(state);
+ element.setOrderedState(orderedState);
+ element.setParticipantId(new ToscaConceptIdentifier("HttpParticipant0", "1.0.0"));
+ element.setParticipantType(
+ new ToscaConceptIdentifier("org.onap.k8s.controlloop.HttpControlLoopParticipant", "2.3.4"));
+
+ return element;
+ }
+
+ @Test
void testScanParticipant() throws PfModelException {
var controlLoopProvider = mock(ControlLoopProvider.class);
var controlLoop = new ControlLoop();