ADD Change State Control Loop Definition 26/123326/4
authorbrunomilitzer <bruno.militzer@est.tech>
Mon, 16 Aug 2021 09:34:06 +0000 (10:34 +0100)
committerAjith Sreekumar <ajith.sreekumar@bell.ca>
Fri, 20 Aug 2021 08:56:39 +0000 (08:56 +0000)
Issue-ID: POLICY-3425
Change-Id: I0898feefd0d63802e90c1c191d1ac1f14f7df389
Signed-off-by: brunomilitzer <bruno.militzer@est.tech>
models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/GenericNameVersion.java [new file with mode: 0644]
models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopOrderStateResponse.java [new file with mode: 0644]
models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationOrderStateResponse.java [new file with mode: 0644]
runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/instantiation/ControlLoopInstantiationProvider.java
runtime-controlloop/src/main/java/org/onap/policy/clamp/controlloop/runtime/main/rest/InstantiationController.java
runtime/src/main/resources/clds/camel/rest/clamp-api-v2.xml
runtime/src/main/resources/clds/camel/routes/controlloop-flows.xml

diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/GenericNameVersion.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/GenericNameVersion.java
new file mode 100644 (file)
index 0000000..a48af92
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 Nordix Foundation.
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.messages.rest;
+
+import lombok.Data;
+
+@Data
+public class GenericNameVersion {
+
+    private String name;
+
+    private String version;
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopOrderStateResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/ControlLoopOrderStateResponse.java
new file mode 100644 (file)
index 0000000..dcc63a5
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 Nordix Foundation.
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.messages.rest.instantiation;
+
+import java.util.ArrayList;
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.messages.rest.GenericNameVersion;
+import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse;
+
+
+/**
+ * Response to Commissioning requests that affect a change.
+ */
+@Getter
+@Setter
+@ToString(callSuper = true)
+public class ControlLoopOrderStateResponse extends SimpleResponse {
+
+    private ControlLoopOrderedState orderedState = ControlLoopOrderedState.UNINITIALISED;
+
+    private List<GenericNameVersion> controlLoopIdentifierList = new ArrayList<>();
+}
diff --git a/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationOrderStateResponse.java b/models/src/main/java/org/onap/policy/clamp/controlloop/models/messages/rest/instantiation/InstantiationOrderStateResponse.java
new file mode 100644 (file)
index 0000000..5943dc5
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * ============LICENSE_START=======================================================
+ *  Copyright (C) 2021 Nordix Foundation.
+ *  ================================================================================
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *        http://www.apache.org/licenses/LICENSE-2.0
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *
+ *  SPDX-License-Identifier: Apache-2.0
+ *  ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.clamp.controlloop.models.messages.rest.instantiation;
+
+import java.util.List;
+import lombok.Getter;
+import lombok.Setter;
+import lombok.ToString;
+import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopOrderedState;
+import org.onap.policy.clamp.controlloop.models.messages.rest.SimpleResponse;
+
+/**
+ * Response to instantiation OrderState.
+ */
+@Getter
+@Setter
+@ToString(callSuper = true)
+public class InstantiationOrderStateResponse extends SimpleResponse {
+
+    private ControlLoopOrderedState orderedState;
+}
index 1011f62..cb22132 100644 (file)
@@ -35,6 +35,8 @@ import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoop
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoopState;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
 import org.onap.policy.clamp.controlloop.models.controlloop.persistence.provider.ControlLoopProvider;
+import org.onap.policy.clamp.controlloop.models.messages.rest.GenericNameVersion;
+import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.ControlLoopOrderStateResponse;
 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;
@@ -251,4 +253,29 @@ public class ControlLoopInstantiationProvider {
 
         return response;
     }
+
+    /**
+     * Gets a list of control loops with it's ordered state.
+     *
+     * @param name the name of the control loop to get, null for all control loops
+     * @param version the version of the control loop to get, null for all control loops
+     * @return a list of Instantiation Command
+     * @throws PfModelException on errors getting control loops
+     */
+    public ControlLoopOrderStateResponse getInstantiationOrderState(String name, String version)
+        throws PfModelException {
+
+        List<ControlLoop> controlLoops = controlLoopProvider.getControlLoops(name, version);
+
+        ControlLoopOrderStateResponse response = new ControlLoopOrderStateResponse();
+
+        controlLoops.forEach(controlLoop -> {
+            GenericNameVersion genericNameVersion = new GenericNameVersion();
+            genericNameVersion.setName(controlLoop.getName());
+            genericNameVersion.setVersion(controlLoop.getVersion());
+            response.getControlLoopIdentifierList().add(genericNameVersion);
+        });
+
+        return response;
+    }
 }
index 29919f5..6f0c859 100644 (file)
@@ -32,6 +32,7 @@ import java.util.UUID;
 import lombok.RequiredArgsConstructor;
 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopException;
 import org.onap.policy.clamp.controlloop.models.controlloop.concepts.ControlLoops;
+import org.onap.policy.clamp.controlloop.models.messages.rest.instantiation.ControlLoopOrderStateResponse;
 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.instantiation.ControlLoopInstantiationProvider;
@@ -376,4 +377,65 @@ public class InstantiationController extends AbstractRestController {
 
         return ResponseEntity.accepted().body(provider.issueControlLoopCommand(command));
     }
+
+    /**
+     * Queries details of all control loops.
+     *
+     * @param requestId request ID used in ONAP logging
+     * @param name the name of the control loop to get, null for all control loops
+     * @param version the version of the control loop to get, null for all control loops
+     * @return the control loops
+     * @throws PfModelException on errors getting commissioning of control loop
+     */
+    // @formatter:off
+    @GetMapping(value = "/instantiationState",
+        produces = {MediaType.APPLICATION_JSON_VALUE, APPLICATION_YAML})
+    @ApiOperation(value = "Query details of the requested control loops",
+        notes = "Queries details of the requested control loops, returning all control loop details",
+        response = ControlLoops.class,
+        tags = {TAGS},
+        authorizations = @Authorization(value = AUTHORIZATION_TYPE),
+        responseHeaders = {
+            @ResponseHeader(
+                name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
+                response = String.class),
+            @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
+                response = String.class),
+            @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
+                response = String.class),
+            @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
+                response = UUID.class)},
+        extensions = {
+            @Extension
+                (
+                    name = EXTENSION_NAME,
+                    properties = {
+                        @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
+                        @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
+                    }
+                )
+        }
+    )
+    @ApiResponses(
+        value = {
+            @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
+            @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
+            @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
+        }
+    )
+    // @formatter:on
+    public ResponseEntity<ControlLoopOrderStateResponse> getInstantiationOrderState(
+        @RequestHeader(
+            name = REQUEST_ID_NAME,
+            required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
+        @ApiParam(value = "Control Loop definition name", required = false) @RequestParam(
+            value = "name",
+            required = false) String name,
+        @ApiParam(value = "Control Loop definition version", required = false) @RequestParam(
+            value = "version",
+            required = false) String version)
+        throws PfModelException {
+
+        return ResponseEntity.ok().body(provider.getInstantiationOrderState(name, version));
+    }
 }
index 677ec64..2e71c58 100644 (file)
 
         <get uri="/v2/toscaControlLoop/getToscaInstantiation" outType="java.lang.String" bindingMode="off" produces="application/json">
             <route>
+                <removeHeaders pattern="*"
+                               excludePattern="name|version|requestId"/>
                 <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')"/>
                 </doTry>
             </route>
         </get>
+        <get uri="/v2/toscaControlLoop/getInstantiationOrderState" outType="java.lang.String" bindingMode="off" produces="application/json">
+            <route>
+                <removeHeaders pattern="*"
+                               excludePattern="name|version|requestId"/>
+                <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-order-state"/>
+                    <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/toscaControlLoop/getJsonSchema" outType="java.lang.String" bindingMode="off" produces="application/json">
             <route>
                 <removeHeaders pattern="*"
index ff39200..230aea1 100644 (file)
             </doFinally>
         </doTry>
     </route>
+    <route id="get-tosca-instantiation-order-state">
+        <from uri="direct:get-tosca-instantiation-order-state"/>
+        <doTry>
+            <log loggingLevel="INFO"
+                 message="Getting the Tosca Instantiation Order State"/>
+            <to
+                    uri="bean:org.onap.policy.clamp.flow.log.FlowLogOperation?method=invokeLog('ControlLoop', 'Getting the Tosca Instantiation Order State')"/>
+            <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 Order State: {{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiationState"></log>
+            <toD
+                    uri="{{clamp.config.controlloop.runtime.url}}/onap/controlloop/v2/instantiationState?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>
     <route id="get-json-schema">
         <from uri="direct:get-json-schema"/>
         <doTry>