Set timeout to CL timeout if zero 33/90233/3
authorJim Hahn <jrh3@att.com>
Thu, 20 Jun 2019 14:09:21 +0000 (10:09 -0400)
committerJim Hahn <jrh3@att.com>
Thu, 20 Jun 2019 15:00:24 +0000 (11:00 -0400)
Modified the rules to set the operational timeout to the overall
CL timeout if the operational timeout is zero.
Added code to check for zero timeout for the overall CL, too.

Change-Id: I28d41632f59e9bc2fce953267883d567abc92a49
Issue-ID: POLICY-1859
Signed-off-by: Jim Hahn <jrh3@att.com>
controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
controlloop/common/eventmanager/src/test/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManagerTest.java
controlloop/common/eventmanager/src/test/resources/test-null-timeout.yaml [new file with mode: 0644]
controlloop/common/eventmanager/src/test/resources/test-zero-timeout.yaml [new file with mode: 0644]
controlloop/templates/archetype-cl-amsterdam/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl
controlloop/templates/archetype-cl-usecases/src/main/resources/archetype-resources/src/main/resources/__closedLoopControlName__.drl

index 7811b2d..b82a5f8 100644 (file)
@@ -666,7 +666,10 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
      */
     public int getControlLoopTimeout(Integer defaultTimeout) {
         if (this.processor != null && this.processor.getControlLoop() != null) {
-            return this.processor.getControlLoop().getTimeout();
+            Integer timeout = this.processor.getControlLoop().getTimeout();
+            if (timeout != null && timeout > 0) {
+                return timeout;
+            }
         }
         if (defaultTimeout != null) {
             return defaultTimeout;
index 1eec0a7..beea88d 100644 (file)
@@ -912,6 +912,56 @@ public class ControlLoopEventManagerTest {
         assertTrue(60 == manager.getControlLoopTimeout(null));
     }
 
+    @Test
+    public void testControlLoopTimeout_ZeroTimeout() throws IOException {
+        InputStream is = new FileInputStream(new File("src/test/resources/test-zero-timeout.yaml"));
+        final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
+
+        UUID requestId = UUID.randomUUID();
+        VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
+        onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+        onsetEvent.setRequestId(requestId);
+        onsetEvent.setTarget("generic-vnf.vnf-id");
+        onsetEvent.setClosedLoopAlarmStart(Instant.now());
+        onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
+        onsetEvent.setAai(new HashMap<>());
+        onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+
+        ControlLoopEventManager manager = makeManager(onsetEvent);
+
+        VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
+        assertNotNull(notification);
+        assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
+
+        assertTrue(0 == manager.getControlLoopTimeout(null));
+        assertTrue(120 == manager.getControlLoopTimeout(120));
+    }
+
+    @Test
+    public void testControlLoopTimeout_NullTimeout() throws IOException {
+        InputStream is = new FileInputStream(new File("src/test/resources/test-null-timeout.yaml"));
+        final String yamlString = IOUtils.toString(is, StandardCharsets.UTF_8);
+
+        UUID requestId = UUID.randomUUID();
+        VirtualControlLoopEvent onsetEvent = new VirtualControlLoopEvent();
+        onsetEvent.setClosedLoopControlName("TwoOnsetTest");
+        onsetEvent.setRequestId(requestId);
+        onsetEvent.setTarget("generic-vnf.vnf-id");
+        onsetEvent.setClosedLoopAlarmStart(Instant.now());
+        onsetEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
+        onsetEvent.setAai(new HashMap<>());
+        onsetEvent.getAai().put("generic-vnf.vnf-name", "onsetOne");
+
+        ControlLoopEventManager manager = makeManager(onsetEvent);
+
+        VirtualControlLoopNotification notification = manager.activate(yamlString, onsetEvent);
+        assertNotNull(notification);
+        assertEquals(ControlLoopNotificationType.ACTIVE, notification.getNotification());
+
+        assertTrue(0 == manager.getControlLoopTimeout(null));
+        assertTrue(120 == manager.getControlLoopTimeout(120));
+    }
+
     @Test
     public void testQueryAai_AlreadyDisabled() throws AaiException {
         ControlLoopEventManager mgr = null;
diff --git a/controlloop/common/eventmanager/src/test/resources/test-null-timeout.yaml b/controlloop/common/eventmanager/src/test/resources/test-null-timeout.yaml
new file mode 100644 (file)
index 0000000..dae7045
--- /dev/null
@@ -0,0 +1,37 @@
+# Copyright 2019 AT&T Intellectual Property. All rights reserved
+#
+# 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.
+controlLoop:
+  version: 1.0.0
+  controlLoopName: ControlLoop-vService-cbed919f-2212-4ef7-8051-fe6308da1bda
+  services:
+    - serviceName: service1
+  resources:
+    - resourceName: resource1
+      resourceType: VF
+  trigger_policy: unique-policy-id-3-migrate
+
+policies:
+  - id: unique-policy-id-3-migrate
+    name: Migrate Policy
+    description:
+    actor: APPC
+    recipe: Migrate
+    target: VM
+    retry: 0
+    timeout: 30
+    success: final_success
+    failure: final_failure
+    failure_timeout: final_failure_timeout
+    failure_retries: final_failure_retries
+    failure_exception: final_failure_exception
diff --git a/controlloop/common/eventmanager/src/test/resources/test-zero-timeout.yaml b/controlloop/common/eventmanager/src/test/resources/test-zero-timeout.yaml
new file mode 100644 (file)
index 0000000..b85dee6
--- /dev/null
@@ -0,0 +1,38 @@
+# Copyright 2019 AT&T Intellectual Property. All rights reserved
+#
+# 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.
+controlLoop:
+  version: 1.0.0
+  controlLoopName: ControlLoop-vService-cbed919f-2212-4ef7-8051-fe6308da1bda
+  services:
+    - serviceName: service1
+  resources:
+    - resourceName: resource1
+      resourceType: VF
+  trigger_policy: unique-policy-id-3-migrate
+  timeout: 0
+
+policies:
+  - id: unique-policy-id-3-migrate
+    name: Migrate Policy
+    description:
+    actor: APPC
+    recipe: Migrate
+    target: VM
+    retry: 0
+    timeout: 30
+    success: final_success
+    failure: final_failure
+    failure_timeout: final_failure_timeout
+    failure_retries: final_failure_retries
+    failure_exception: final_failure_exception
index 6a73f8e..f28ee17 100644 (file)
@@ -451,11 +451,12 @@ rule "${policyName}.EVENT.MANAGER"
                   //
                   // insert operation timeout object
                   //
-                   ControlLoopTimer opTimer = new ControlLoopTimer();
-                   opTimer.setTimerType("Operation");
-                   opTimer.setClosedLoopControlName($event.getClosedLoopControlName());
-                   opTimer.setRequestId($event.getRequestId().toString());
-                   opTimer.setDelay(operation.getOperationTimeout().toString() + "s");
+                  ControlLoopTimer opTimer = new ControlLoopTimer();
+                  opTimer.setTimerType("Operation");
+                  opTimer.setClosedLoopControlName($event.getClosedLoopControlName());
+                  opTimer.setRequestId($event.getRequestId().toString());
+                  Integer timeout = operation.getOperationTimeout();
+                  opTimer.setDelay(timeout > 0 ? timeout.toString() + "s" : $clTimer.getDelay());
                   insert(opTimer);
               
                   //
@@ -463,7 +464,7 @@ rule "${policyName}.EVENT.MANAGER"
                   //
                   insert(result.getB());
               } else {
-                   logger.debug("The target resource {} is already processing",
+                  logger.debug("The target resource {} is already processing",
                             $event.getAai().get($event.getTarget()));
                   notification = new VirtualControlLoopNotification($event);
                   notification.setNotification(ControlLoopNotificationType.REJECTED);
index 3f2bf57..a9e17c3 100644 (file)
@@ -440,7 +440,8 @@ rule "EVENT.MANAGER"
                   opTimer.setTimerType("Operation");
                   opTimer.setClosedLoopControlName($event.getClosedLoopControlName());
                   opTimer.setRequestId($event.getRequestId().toString());
-                  opTimer.setDelay(operation.getOperationTimeout().toString() + "s");
+                  Integer timeout = operation.getOperationTimeout();
+                  opTimer.setDelay(timeout > 0 ? timeout.toString() + "s" : $clTimer.getDelay());
                   insert(opTimer);
 
                   //