summaryrefslogtreecommitdiffstats
path: root/runtime/src
diff options
context:
space:
mode:
authorsaul.gill <saul.gill@est.tech>2021-07-23 10:48:25 +0100
committersaul.gill <saul.gill@est.tech>2021-07-29 14:19:29 +0100
commit4045d5fd60013534f4ecf85f553ae7da3e32220d (patch)
tree4c6a134b4a529b87d8564399be4abeea40635a9a /runtime/src
parent096c230515b1dc2f773e8742725c9e78444ee4f3 (diff)
Added endpoint for common or instance properties
Runtime-controlloop and Camel endpoionts added Flag common can be used - true common props - false - instance props Changed getServiceTemplate endpoint to return less Added creation of controlloop db to clamp scripts Issue-ID: POLICY-3439 Change-Id: I9d189ca030868b47b46a2e0bc5e731c23fba2a61 Signed-off-by: saul.gill <saul.gill@est.tech>
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml35
-rw-r--r--runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml28
-rw-r--r--runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java47
-rw-r--r--runtime/src/test/resources/http-cache/example/node_template.json44
-rw-r--r--runtime/src/test/resources/http-cache/third_party_proxy.py25
5 files changed, 170 insertions, 9 deletions
diff --git a/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml b/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
index 01ee071ee..677ec64c9 100644
--- a/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
+++ b/runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
@@ -1724,6 +1724,41 @@
</route>
</get>
+ <get uri="/v2/toscaControlLoop/getCommonOrInstanceProperties" outType="java.lang.String" bindingMode="off" produces="application/json">
+ <route>
+ <removeHeaders pattern="*"
+ excludePattern="name|version|requestId|common"/>
+ <doTry>
+ <to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'GET Common Properties ')"/>
+ <to uri="bean:org.onap.policy.clamp.authorization.AuthorizationController?method=authorize(*,'cl','','read')"/>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <setProperty name="raiseHttpExceptionFlag">
+ <simple resultType="java.lang.Boolean">false</simple>
+ </setProperty>
+ <to uri="direct:get-common-or-instance-properties"/>
+ <to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=endLog()"/>
+ <doCatch>
+ <exception>java.lang.Exception</exception>
+ <handled>
+ <constant>true</constant>
+ </handled>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=errorLog()"/>
+ <log loggingLevel="ERROR"
+ message="GET Common Or Instance Properties request failed: ${exception.stacktrace}"/>
+ <setHeader name="CamelHttpResponseCode">
+ <constant>500</constant>
+ </setHeader>
+ <setBody>
+ <simple>GET Common Properties FAILED</simple>
+ </setBody>
+ </doCatch>
+ </doTry>
+ </route>
+ </get>
+
<post uri="/v2/toscaControlLoop/postToscaInstantiation"
type="java.lang.String"
consumes="plain/text"
diff --git a/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml b/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
index 2c063f105..ff39200b7 100644
--- a/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
+++ b/runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml
@@ -238,4 +238,32 @@
</doFinally>
</doTry>
</route>
+ <route id="get-common-or-instance-properties">
+ <from uri="direct:get-common-or-instance-properties"/>
+ <doTry>
+ <log loggingLevel="INFO"
+ message="Getting Common Or Instance Properties"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('ControlLoop', 'Getting Common Or Instance Properties')"/>
+ <setHeader name="CamelHttpMethod">
+ <constant>GET</constant>
+ </setHeader>
+ <setHeader name="Content-Type">
+ <constant>application/json</constant>
+ </setHeader>
+ <setProperty name="common">
+ <simple>${header.common}</simple>
+ </setProperty>
+ <log loggingLevel="INFO"
+ message="Endpoint to get Common Or Instance Properties: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/commission/getCommonOrInstanceProperties"></log>
+ <toD
+ uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/commission/getCommonOrInstanceProperties?common=${exchangeProperty[common]}&amp;bridgeEndpoint=true&amp;useSystemProperties=true&amp;throwExceptionOnFailure=${exchangeProperty[raiseHttpExceptionFlag]}&amp;authMethod=Basic&amp;authUsername={{clamp.config.controlloop.runtime.userName}}&amp;authPassword={{clamp.config.controlloop.runtime.password}}&amp;authenticationPreemptive=true&amp;connectionClose=true"/>
+ <convertBodyTo type="java.lang.String"/>
+ <doFinally>
+ <to uri="direct:reset-raise-http-exception-flag"/>
+ <to
+ uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeReturnLog()"/>
+ </doFinally>
+ </doTry>
+ </route>
</routes>
diff --git a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java
index a1eaf27d0..f4e171174 100644
--- a/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java
+++ b/runtime/src/test/java/org/onap/policy/clamp/runtime/RuntimeCommissioningResponseTestItCase.java
@@ -147,4 +147,51 @@ public class RuntimeCommissioningResponseTestItCase {
assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
.is2xxSuccessful()).isTrue();
}
+
+ @Test
+ public void testGetCommonOrInstancePropertiesCommonTrue() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:get-common-or-instance-properties", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("common", true)
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+
+ @Test
+ public void testGetCommonOrInstancePropertiesCommonFalse() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:get-common-or-instance-properties", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("common", false)
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
+
+ @Test
+ public void testGetCommonOrInstancePropertiesCommonMissing() {
+ ProducerTemplate prodTemplate = camelContext.createProducerTemplate();
+
+ Exchange exchangeResponse =
+ prodTemplate.send("direct:get-common-or-instance-properties", ExchangeBuilder.anExchange(camelContext)
+ .withProperty("name", "ToscaServiceTemplate")
+ .withProperty("version", "1.0.0")
+ .withProperty("raiseHttpExceptionFlag", "true")
+ .build());
+
+ assertThat(HttpStatus.valueOf((Integer) exchangeResponse.getIn().getHeader(Exchange.HTTP_RESPONSE_CODE))
+ .is2xxSuccessful()).isTrue();
+ }
}
diff --git a/runtime/src/test/resources/http-cache/example/node_template.json b/runtime/src/test/resources/http-cache/example/node_template.json
new file mode 100644
index 000000000..fdbfe8563
--- /dev/null
+++ b/runtime/src/test/resources/http-cache/example/node_template.json
@@ -0,0 +1,44 @@
+{
+ "org.onap.domain.pmsh.PMSHControlLoopDefinition": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.2.3",
+ "derived_from": null,
+ "metadata": {},
+ "description": "Control loop for Performance Management Subscription Handling",
+ "type": "org.onap.policy.clamp.controlloop.ControlLoop",
+ "type_version": "1.0.0",
+ "properties": {
+ "elements": [
+ {
+ "name": "org.onap.domain.pmsh.PMSH_DCAEMicroservice",
+ "version": "1.2.3"
+ },
+ {
+ "name": "org.onap.domain.pmsh.PMSH_MonitoringPolicyControlLoopElement",
+ "version": "1.2.3"
+ },
+ {
+ "name": "org.onap.domain.pmsh.PMSH_OperationalPolicyControlLoopElement",
+ "version": "1.2.3"
+ }
+ ],
+ "provider": "Ericsson"
+ },
+ "requirements": null,
+ "capabilities": null,
+ "identifier": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.2.3"
+ },
+ "type_identifier": {
+ "name": "org.onap.policy.clamp.controlloop.ControlLoop",
+ "version": "1.0.0"
+ },
+ "key": {
+ "name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "version": "1.2.3"
+ },
+ "defined_name": "org.onap.domain.pmsh.PMSHControlLoopDefinition",
+ "defined_version": "1.2.3"
+ }
+}
diff --git a/runtime/src/test/resources/http-cache/third_party_proxy.py b/runtime/src/test/resources/http-cache/third_party_proxy.py
index 2a28c65d3..013388197 100644
--- a/runtime/src/test/resources/http-cache/third_party_proxy.py
+++ b/runtime/src/test/resources/http-cache/third_party_proxy.py
@@ -294,16 +294,24 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
return True
elif (self.path.startswith("/onap/controlloop/v2/commission/elements")) and http_type == "GET":
- print "self.path start with /commission/elements Control Loop Elements, generating response json..."
- #jsondata = json.loads(self.data_string)
- jsonGenerated = "[{\"name\": ,\"org.onap.domain.pmsh.PMSH_DCAEMicroservice\": [{ \"version\": \"1.2.3\", \"derived_from\": null }]}]"
- self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
+ if not _file_available:
+ print "self.path start with /commission/elements Control Loop Elements, generating response json..."
+ jsonGenerated = "[{\"name\": ,\"org.onap.domain.pmsh.PMSH_DCAEMicroservice\": [{ \"version\": \"1.2.3\", \"derived_from\": null }]}]"
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
return True
elif (self.path.startswith("/onap/controlloop/v2/commission")) and http_type == "GET":
- print "self.path start with /commission control loop definition, generating response json..."
- #jsondata = json.loads(self.data_string)
- jsonGenerated = "[{\"name\": ,\"org.onap.domain.pmsh.PMSHControlLoopDefinition\": [{ \"version\": \"1.2.3\", \"derived_from\": null }]}]"
- self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
+ if not _file_available:
+ print "self.path start with /commission control loop definition, generating response json..."
+ #jsondata = json.loads(self.data_string)
+ jsonGenerated = "[{\"name\": ,\"org.onap.domain.pmsh.PMSHControlLoopDefinition\": [{ \"version\": \"1.2.3\", \"derived_from\": null }]}]"
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
+ return True
+ elif (self.path.startswith("/onap/controlloop/v2/commission/getCommonOrInstanceProperties")) and http_type == "GET":
+ if not _file_available:
+ print "self.path start with /commission getting common properties, generating response json..."
+ with open("example/node_template.json", "r") as f:
+ jsonGenerated = f.read()
+ self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
return True
elif (self.path.startswith("/onap/controlloop/v2/commission")) and http_type == "POST":
print "self.path start with POST /onap/controlloop/v2/commission, copying body to response ..."
@@ -318,7 +326,6 @@ class Proxy(SimpleHTTPServer.SimpleHTTPRequestHandler):
print "self.path start with /commission Decommissioning, generating response json..."
jsonGenerated = "{\"errorDetails\": null,\"affectedControlLoopDefinitions\": [{ \"name\": \"ToscaServiceTemplateSimple\", \"version\": \"1.0.0\" }]}"
self._create_cache(jsonGenerated, cached_file_folder, cached_file_header, cached_file_content)
-
return True
else:
return False