Added Camel Endpoint for Tosca Instantiation 78/122078/3
authorbrunomilitzer <bruno.militzer@est.tech>
Fri, 18 Jun 2021 15:11:11 +0000 (16:11 +0100)
committerBruno Militzer <bruno.militzer@est.tech>
Tue, 22 Jun 2021 16:25:31 +0000 (16:25 +0000)
Endpoint redirects GET to runtime instantiation

Issue-ID: POLICY-3357
Change-Id: Idf733c2803be2f6ab5cc681d583c1c6b46b2ce96
Signed-off-by: brunomilitzer <bruno.militzer@est.tech>
runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml

index 5fd2422..b3c4edb 100644 (file)
             </route>
         </post>
 
+        <get uri="/v2/toscaControlLoop/getToscaInstantiation" outType="java.lang.String" bindingMode="off" produces="application/json">
+            <route>
+                <doTry>
+                    <to uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=startLog(*, 'GET Tosca Instantiation ')"/>
+                    <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">true</simple>
+                    </setProperty>
+                    <to uri="direct:get-tosca-instantiation"/>
+                    <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 Tosca Instantiation JSON request failed: ${exception.stacktrace}"/>
+                        <setHeader name="CamelHttpResponseCode">
+                            <constant>500</constant>
+                        </setHeader>
+                        <setBody>
+                            <simple>GET Tosca Instantiation JSON FAILED</simple>
+                        </setBody>
+                    </doCatch>
+                </doTry>
+            </route>
+        </get>
+
         <get uri="/v2/clampInformation" outType="org.onap.policy.clamp.clds.model.ClampInformation"
              produces="application/json">
             <route>
index 0641b32..009e00f 100644 (file)
             </doFinally>
         </doTry>
     </route>
+    <route id="get-tosca-instantiation">
+        <from uri="direct:get-tosca-instantiation"/>
+        <doTry>
+            <log loggingLevel="INFO"
+                 message="Getting the Tosca instantiation"/>
+            <to
+                    uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('ControlLoop', 'Getting the Tosca instantiation')"/>
+            <setHeader name="CamelHttpMethod">
+                <constant>GET</constant>
+            </setHeader>
+            <setHeader name="Content-Type">
+                <constant>application/json</constant>
+            </setHeader>
+            <log loggingLevel="INFO"
+                 message="Endpoint to get Tosca Instantiation: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiation"></log>
+            <toD
+                    uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiation?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>