aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-07-21 20:17:48 +0000
committerGerrit Code Review <gerrit@onap.org>2020-07-21 20:17:48 +0000
commitbb43e16b1eaa0cce5a982a9f3282c653f964e0a4 (patch)
tree352d89c6bdf8b7d32b5c8c03d87357cf6a1a5ee9
parenta956225992fa998fe4f89db07d16cb67c18cafcc (diff)
parentfd2f9e3fb31335e15a72ca3db728667874053d44 (diff)
Merge "Remove m2 model from drools-apps"
-rw-r--r--controlloop/m2/adapters/pom.xml40
-rw-r--r--controlloop/m2/adapters/src/main/java/org/onap/policy/m2/adapters/VirtualOnsetAdapter.java60
-rw-r--r--controlloop/m2/adapters/src/test/java/org/onap/policy/m2/adapters/VirtualOnsetAdapterTest.java54
-rw-r--r--controlloop/m2/appclcm/pom.xml75
-rw-r--r--controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmActor.java74
-rw-r--r--controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmHealthCheckOperation.java245
-rw-r--r--controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmOperation.java695
-rw-r--r--controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/model/AppcLcmResponseCode.java58
-rw-r--r--controlloop/m2/appclcm/src/main/resources/META-INF/services/org.onap.policy.m2.base.Actor1
-rw-r--r--controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmActorTest.java118
-rw-r--r--controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmHealthCheckOperationTest.java330
-rw-r--r--controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmOperationTest.java723
-rw-r--r--controlloop/m2/appclcm/src/test/java/model/AppcLcmResponseCodeTest.java43
-rw-r--r--controlloop/m2/base/pom.xml88
-rw-r--r--controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Actor.java52
-rw-r--r--controlloop/m2/base/src/main/java/org/onap/policy/m2/base/GuardAdjunct.java122
-rw-r--r--controlloop/m2/base/src/main/java/org/onap/policy/m2/base/OnsetAdapter.java155
-rw-r--r--controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Operation.java125
-rw-r--r--controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Transaction.java712
-rw-r--r--controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Util.java63
-rw-r--r--controlloop/m2/base/src/test/java/org/onap/policy/m2/base/ActorOperationTest.java116
-rw-r--r--controlloop/m2/base/src/test/java/org/onap/policy/m2/base/GuardAdjunctTest.java99
-rw-r--r--controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java408
-rw-r--r--controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/ActorImpl.java43
-rw-r--r--controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/OperationImpl.java75
-rw-r--r--controlloop/m2/base/src/test/resources/META-INF/services/org.onap.policy.m2.base.Actor1
-rw-r--r--controlloop/m2/feature-controlloop-m2/pom.xml126
-rw-r--r--controlloop/m2/feature-controlloop-m2/src/assembly/assemble_zip.xml80
-rw-r--r--controlloop/m2/guard/pom.xml132
-rw-r--r--controlloop/m2/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java155
-rw-r--r--controlloop/m2/guard/src/main/java/org/onap/policy/guard/GuardContext.java393
-rw-r--r--controlloop/m2/guard/src/main/java/org/onap/policy/guard/GuardResult.java25
-rw-r--r--controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardRequest.java84
-rw-r--r--controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardResponse.java71
-rw-r--r--controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java139
-rw-r--r--controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributes.java123
-rw-r--r--controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java210
-rw-r--r--controlloop/m2/guard/src/main/java/org/onap/policy/guard/Util.java146
-rw-r--r--controlloop/m2/guard/src/main/resources/META-INF/persistence.xml43
-rw-r--r--controlloop/m2/guard/src/test/java/org/onap/policy/guard/CallGuardTaskTest.java78
-rw-r--r--controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardContextTest.java194
-rw-r--r--controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardResultTest.java42
-rw-r--r--controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardUtilTest.java102
-rw-r--r--controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardRequestTest.java59
-rw-r--r--controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardResponseTest.java55
-rw-r--r--controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlHelperTest.java150
-rw-r--r--controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributesTest.java74
-rw-r--r--controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardYamlToXacmlTest.java248
-rw-r--r--controlloop/m2/guard/src/test/java/org/onap/policy/guard/SupportTextFileUtils.java65
-rw-r--r--controlloop/m2/guard/src/test/resources/META-INF/persistence.xml43
-rw-r--r--controlloop/m2/guard/src/test/resources/blacklist_template.xml117
-rw-r--r--controlloop/m2/guard/src/test/resources/frequency_limiter_template.xml127
-rw-r--r--controlloop/m2/lock/pom.xml50
-rw-r--r--controlloop/m2/lock/src/main/java/org/onap/policy/drools/m2/lock/LockAdjunct.java158
-rw-r--r--controlloop/m2/lock/src/test/java/org/onap/policy/drools/m2/lock/LockAdjunctTest.java90
-rw-r--r--controlloop/m2/pom.xml49
-rw-r--r--controlloop/m2/test/pom.xml95
-rw-r--r--controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java333
-rw-r--r--controlloop/m2/test/src/test/java/org/onap/policy/m2/test/SimDmaap.java264
-rw-r--r--controlloop/m2/test/src/test/java/org/onap/policy/m2/test/SimGuard.java62
-rw-r--r--controlloop/m2/test/src/test/java/org/onap/policy/m2/test/Util.java500
-rw-r--r--controlloop/m2/test/src/test/resources/appclcm/CLRulevUSPAPPCLCMGuardTemplate.yaml83
-rw-r--r--controlloop/m2/test/src/test/resources/appclcm/M2CLRulevUSPAPPCLCMGuardTemplate.drl649
-rw-r--r--controlloop/m2/test/src/test/resources/appclcm/controller.properties58
-rw-r--r--controlloop/m2/test/src/test/resources/appclcm/kmodule.xml26
-rw-r--r--controlloop/m2/test/src/test/resources/appclcm/pom.xml29
-rw-r--r--controlloop/m2/util/pom.xml41
-rw-r--r--controlloop/m2/util/src/main/java/org/onap/policy/util/DroolsSessionCommonSerializable.java134
-rw-r--r--controlloop/m2/util/src/test/java/org/onap/policy/util/DroolsSessionCommonSerializableTest.java89
-rw-r--r--controlloop/pom.xml1
70 files changed, 0 insertions, 10367 deletions
diff --git a/controlloop/m2/adapters/pom.xml b/controlloop/m2/adapters/pom.xml
deleted file mode 100644
index 4045ff358..000000000
--- a/controlloop/m2/adapters/pom.xml
+++ /dev/null
@@ -1,40 +0,0 @@
-<?xml version="1.0"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>m2</artifactId>
- <version>1.7.1-SNAPSHOT</version>
- </parent>
- <artifactId>adapters</artifactId>
- <name>adapters</name>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>base</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-</project>
diff --git a/controlloop/m2/adapters/src/main/java/org/onap/policy/m2/adapters/VirtualOnsetAdapter.java b/controlloop/m2/adapters/src/main/java/org/onap/policy/m2/adapters/VirtualOnsetAdapter.java
deleted file mode 100644
index 1a3a5f66c..000000000
--- a/controlloop/m2/adapters/src/main/java/org/onap/policy/m2/adapters/VirtualOnsetAdapter.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/adapters
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.adapters;
-
-import java.io.Serializable;
-import org.onap.policy.controlloop.ControlLoopEvent;
-import org.onap.policy.controlloop.ControlLoopNotification;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.VirtualControlLoopNotification;
-import org.onap.policy.m2.base.OnsetAdapter;
-
-public class VirtualOnsetAdapter extends OnsetAdapter implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private static VirtualOnsetAdapter instance = new VirtualOnsetAdapter();
-
- /**
- * This method is called to register the 'VirtualOnsetAdapter' instance
- * under the 'VirtualControlLoopEvent' class. This method called in the
- * static initialization code of the 'Actor' classes that use this
- * adapter -- namely, 'AppcLcmActor'.
- */
- public static void register() {
- OnsetAdapter.register(VirtualControlLoopEvent.class, instance);
- }
-
- /**
- * This method overrides the associated 'OnsetAdapter' method.
- */
- @Override
- public ControlLoopNotification createNotification(ControlLoopEvent event) {
- if (event instanceof VirtualControlLoopEvent) {
- return new VirtualControlLoopNotification((VirtualControlLoopEvent) event);
- }
-
- // Right now, the onset event from the transaction is used to locate
- // the adapter. It is expected that the 'event' passed here will
- // be of the same class, but that isn't always guaranteed. If this
- // is not the case, the appropriate adapter is located in this way.
- return OnsetAdapter.get(event).createNotification(event);
- }
-}
diff --git a/controlloop/m2/adapters/src/test/java/org/onap/policy/m2/adapters/VirtualOnsetAdapterTest.java b/controlloop/m2/adapters/src/test/java/org/onap/policy/m2/adapters/VirtualOnsetAdapterTest.java
deleted file mode 100644
index 4b38b1e14..000000000
--- a/controlloop/m2/adapters/src/test/java/org/onap/policy/m2/adapters/VirtualOnsetAdapterTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * adapters
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.adapters;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-import org.onap.policy.controlloop.ControlLoopEvent;
-import org.onap.policy.controlloop.ControlLoopNotification;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.VirtualControlLoopNotification;
-import org.onap.policy.m2.base.OnsetAdapter;
-
-public class VirtualOnsetAdapterTest {
-
- @Test
- public void test() {
- VirtualOnsetAdapter.register();
- VirtualControlLoopEvent virtualControlLoopEvent = new VirtualControlLoopEvent();
- VirtualOnsetAdapter virtualOnsetAdapter =
- VirtualOnsetAdapter.class.cast(OnsetAdapter.get(virtualControlLoopEvent));
- assertNotNull(virtualOnsetAdapter);
-
- ControlLoopNotification notification = virtualOnsetAdapter.createNotification(virtualControlLoopEvent);
- assertNotNull(notification);
- // we want an exact class match, so 'instanceOf' is not being used
- assertEquals(VirtualControlLoopNotification.class, notification.getClass());
-
- ControlLoopEvent controlLoopEvent = new ControlLoopEvent() {
- private static final long serialVersionUID = 1L;
- };
- notification = virtualOnsetAdapter.createNotification(controlLoopEvent);
- assertNotNull(notification);
- }
-}
diff --git a/controlloop/m2/appclcm/pom.xml b/controlloop/m2/appclcm/pom.xml
deleted file mode 100644
index cfc163737..000000000
--- a/controlloop/m2/appclcm/pom.xml
+++ /dev/null
@@ -1,75 +0,0 @@
-<?xml version="1.0"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>m2</artifactId>
- <version>1.7.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>appclcm</artifactId>
- <name>Experimental Control Loop Model - appclcm</name>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>adapters</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>base</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>lock</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
- <artifactId>appclcm</artifactId>
- <version>${policy.models.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-management</artifactId>
- <version>${version.policy.drools-pdp}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <scope>provided</scope>
- </dependency>
-
- </dependencies>
-
-</project>
diff --git a/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmActor.java b/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmActor.java
deleted file mode 100644
index ee9ebdc3d..000000000
--- a/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmActor.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/appclcm
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.appclcm;
-
-import java.io.Serializable;
-import org.onap.policy.controlloop.ControlLoopEvent;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.m2.adapters.VirtualOnsetAdapter;
-import org.onap.policy.m2.base.Actor;
-import org.onap.policy.m2.base.Operation;
-import org.onap.policy.m2.base.Transaction;
-
-/**
- * A single instance of this class is created, and resides within the
- * 'nameToActor' table within class 'Transaction', under the key 'APPC'.
- */
-public class AppcLcmActor implements Actor, Serializable {
- /* *******************/
- /* 'Actor' interface */
- /* *******************/
-
- private static final long serialVersionUID = -593438898257647144L;
-
-
- static {
- // ensures that 'VirtualOnsetAdapter' has an entry in the
- // 'OnsetAdapter' table
- VirtualOnsetAdapter.register();
- }
-
- /**
- * Return the name associated with this 'Actor'.
- *
- * {@inheritDoc}
- */
- @Override
- public String getName() {
- return "APPCLCM";
- }
-
- /**
- * Create an 'Operation' for this 'Actor'.
- *
- * {@inheritDoc}
- */
- @Override
- public Operation createOperation(
- Transaction transaction, Policy policy, ControlLoopEvent onset,
- int attempt) {
-
- if ("healthcheck".equalsIgnoreCase(policy.getRecipe())) {
- return new AppcLcmHealthCheckOperation(transaction, policy, onset, attempt);
- }
- return new AppcLcmOperation(transaction, policy, onset, attempt);
- }
-}
diff --git a/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmHealthCheckOperation.java b/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmHealthCheckOperation.java
deleted file mode 100644
index 40e0b0afb..000000000
--- a/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmHealthCheckOperation.java
+++ /dev/null
@@ -1,245 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/appclcm
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.appclcm;
-
-import java.util.HashMap;
-import java.util.Map;
-import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
-import org.onap.policy.appclcm.AppcLcmOutput;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.controlloop.ControlLoopEvent;
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.guard.PolicyGuardResponse;
-import org.onap.policy.m2.appclcm.model.AppcLcmResponseCode;
-import org.onap.policy.m2.base.Transaction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AppcLcmHealthCheckOperation extends AppcLcmOperation {
- public static final String DCAE_IPV4_ADDR =
- "vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address";
-
- private static Logger logger = LoggerFactory.getLogger(AppcLcmHealthCheckOperation.class);
-
- private static final long serialVersionUID = 4969322301462776173L;
-
- public AppcLcmHealthCheckOperation(Transaction transaction, Policy policy,
- ControlLoopEvent onset, int attempt) {
- super(transaction, policy, onset, attempt);
- }
-
- /**
- * This method will attempt to deserialize the json payload from appc and
- * then parse the response to determine if the vnf is healthy or unhealthy.
- * The "state" field in the payload will contain "healthy" or "unhealthy"
- * based on the condition of the vnf.
- *
- * @param jsonPayload
- * the appc lcm response json payload
- * @return the string that contains the state of the vnf
- */
- @SuppressWarnings("unchecked")
- private String getVnfHealthState(String jsonPayload) {
- HashMap<String, Object> healthCheckPayloadMap;
- try {
- healthCheckPayloadMap = coder.decode(jsonPayload, HashMap.class);
- } catch (CoderException e) {
- return null;
- }
-
- String stateOfHealth = null;
- if (healthCheckPayloadMap.containsKey("state")) {
- stateOfHealth = healthCheckPayloadMap.get("state").toString();
- } else {
- return null;
- }
- return stateOfHealth;
- }
-
- /**
- * An incoming message is being delivered to the operation.
- *
- * {@inheritDoc}
- */
- @Override
- public void incomingMessage(Object object) {
- if (!(object instanceof AppcLcmDmaapWrapper)) {
- if (object instanceof PolicyGuardResponse) {
- incomingGuardMessage((PolicyGuardResponse) object);
- }
- // ignore this message (not sure why we even got it)
- return;
- }
-
- // If we reach this point, we have a 'AppcLcmDmaapWrapper' instance.
- // The rest of this method is mostly copied from
- // 'ControlLoopOperationManager.onResponse'.
-
- AppcLcmOutput response = ((AppcLcmDmaapWrapper) object).getBody().getOutput();
-
- //
- // Determine which subrequestID (ie. attempt)
- //
- int operationAttempt;
- try {
- operationAttempt = Integer
- .parseInt(response.getCommonHeader().getSubRequestId());
- } catch (NumberFormatException e) {
- //
- // We cannot tell what happened if this doesn't exist
- //
- this.completeOperation(
- this.getAttempt(),
- "Policy was unable to parse APP-C SubRequestID (it was null).",
- PolicyResult.FAILURE_EXCEPTION);
- return;
- }
- //
- // Sanity check the response message
- //
- if (response.getStatus() == null) {
- //
- // We cannot tell what happened if this doesn't exist
- //
- this.completeOperation(
- operationAttempt,
- "Policy was unable to parse APP-C response status field (it was null).",
- PolicyResult.FAILURE_EXCEPTION);
- return;
- }
- //
- // Get the Response Code
- //
- AppcLcmResponseCode responseValue = AppcLcmResponseCode
- .toResponseValue(response.getStatus().getCode());
- if (responseValue == null) {
- //
- // We are unaware of this code
- //
- this.completeOperation(
- operationAttempt,
- "Policy was unable to parse APP-C response status code field.",
- PolicyResult.FAILURE_EXCEPTION);
- return;
- }
- //
- // Ok, let's figure out what APP-C's response is
- //
- switch (responseValue) {
- case ACCEPTED:
- //
- // This is good, they got our original message and
- // acknowledged it.
- //
- // Is there any need to track this?
- //
- return;
- case ERROR:
- case REJECT:
- //
- // We'll consider these two codes as exceptions
- //
- this.completeOperation(operationAttempt,
- response.getStatus().getMessage(),
- PolicyResult.FAILURE_EXCEPTION);
- return;
- case FAILURE:
- //
- // APPC could not do a healthcheck
- //
- this.completeOperation(operationAttempt,
- response.getStatus().getMessage(),
- PolicyResult.FAILURE);
- return;
- case SUCCESS:
- //
- // This means APPC was able to execute the health check.
- // The payload has to be parsed to see if the VNF is
- // healthy or unhealthy
- //
-
- //
- // sanity check the payload
- //
- if (response.getPayload() == null || response.getPayload().isEmpty()) {
- //
- // We are cannot parse the payload
- //
- this.completeOperation(
- operationAttempt,
- "Policy was unable to parse APP-C response payload because it was null.",
- PolicyResult.FAILURE_EXCEPTION);
- return;
- }
-
- //
- // parse the payload to see if the VNF is healthy/unhealthy
- //
- String vnfHealthState = getVnfHealthState(response.getPayload());
- if ("healthy".equalsIgnoreCase(vnfHealthState)) {
- this.completeOperation(operationAttempt, "VNF is healthy",
- PolicyResult.SUCCESS);
- } else if ("unhealthy".equalsIgnoreCase(vnfHealthState)) {
- this.completeOperation(operationAttempt, "VNF is unhealthy",
- PolicyResult.FAILURE);
- } else {
- this.completeOperation(
- operationAttempt,
- "Error: Could not determine the state of the VNF."
- + " The state field in the APPC response payload was unrecognized or null.",
- PolicyResult.FAILURE_EXCEPTION);
- }
- return;
- default:
- return;
- }
- }
-
- /**
- * This method will construct a payload for a health check.
- * The payload must be an escaped json string so gson is used
- * to convert the payload hashmap into json
- *
- * @return an escaped json string representation of the payload
- * @throws ControlLoopException if it occurs
- */
- @Override
- protected String setPayload(Map<String, String> aai, String recipe) throws ControlLoopException {
- Map<String, String> payload = new HashMap<>();
-
- // Extract oam ip address from the onset
- String ipAddr = aai.get(DCAE_IPV4_ADDR);
- if (ipAddr != null) {
- payload.put("host-ip-address", ipAddr);
- } else {
- logger.error("Error - IPv4 Address not found in the onset");
- setErrorStatus("Error - IPv4 Address not found in the onset");
- }
-
- try {
- return coder.encode(payload);
- } catch (CoderException e) {
- return null;
- }
- }
-}
diff --git a/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmOperation.java b/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmOperation.java
deleted file mode 100644
index cbd7413f9..000000000
--- a/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/AppcLcmOperation.java
+++ /dev/null
@@ -1,695 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/appclcm
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.appclcm;
-
-import com.google.common.collect.ImmutableList;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-import lombok.Getter;
-import org.onap.policy.appclcm.AppcLcmBody;
-import org.onap.policy.appclcm.AppcLcmCommonHeader;
-import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
-import org.onap.policy.appclcm.AppcLcmInput;
-import org.onap.policy.appclcm.AppcLcmOutput;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.controlloop.ControlLoopEvent;
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.ControlLoopOperation;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.TargetType;
-import org.onap.policy.drools.m2.lock.LockAdjunct;
-import org.onap.policy.guard.PolicyGuardResponse;
-import org.onap.policy.m2.appclcm.model.AppcLcmResponseCode;
-import org.onap.policy.m2.base.GuardAdjunct;
-import org.onap.policy.m2.base.Operation;
-import org.onap.policy.m2.base.Transaction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class is used for all APPC LCM operations. The only difference between
- * operation types (Restart, Rebuild, Migrate, Evacuate, or HealthCheck) as
- * far as DroolsPDP is concerned, is the operation name (policy.recipe).
- * It is up to APPC to interpret these operations.
- */
-public class AppcLcmOperation implements Operation, LockAdjunct.Requestor, Serializable {
- public static final String DCAE_CLOSEDLOOP_DISABLED_FIELD = "vserver.is-closed-loop-disabled";
- public static final String DCAE_VSERVER_SELF_LINK_FIELD = "vserver.selflink";
- public static final String DCAE_IDENTITY_FIELD = "cloud-region.identity-url";
- public static final String DCAE_VNF_NAME_FIELD = "generic-vnf.vnf-name";
- public static final String DCAE_VNF_ID_FIELD = "generic-vnf.vnf-id";
- public static final String DCAE_VSERVER_ID_FIELD = "vserver.vserver-id";
- public static final String DCAE_TENANT_ID_FIELD = "tenant.tenant-id";
-
- public static final String APPC_LCM_VM_ID_FIELD = "vm-id";
- public static final String APPC_LCM_IDENTITY_URL_FIELD = "identity-url";
- public static final String APPC_LCM_TENANT_ID_FIELD = "tenant-id";
-
- private static Logger logger = LoggerFactory.getLogger(AppcLcmOperation.class);
-
- private static final long serialVersionUID = 5062964240000304989L;
-
- private static final String DCAE_ONSET_MISSING = "dcae onset is missing ";
-
- // state when waiting for a lock
- public static final String LCM_WAIT_FOR_LOCK = "LCM.WAIT_FOR_LOCK";
-
- // state when waiting for a response from 'guard'
- public static final String LCM_GUARD_PENDING = "LCM.GUARD_PENDING";
-
- // state when ready to send out the LCM message
- public static final String LCM_BEGIN = "LCM.BEGIN";
-
- // state when waiting for a response from APPC
- public static final String LCM_PENDING = "LCM.PENDING";
-
- // state when processing can't continue due to errors
- public static final String LCM_ERROR = "LCM.ERROR";
-
- // state when the operation has completed (success, failure, or timeout)
- public static final String LCM_COMPLETE = "LCM.COMPLETE";
-
- // the APPC LCM recipes supported by Policy
- private static final ImmutableList<String> recipes = ImmutableList.of(
- "Restart", "Rebuild", "Migrate", "Evacuate",
- "HealthCheck", "Reboot", "Start", "Stop");
-
- // used for JSON <-> String conversion
- protected static StandardCoder coder = new StandardCoder();
-
- // current state -- one of the 6 values, above
- @Getter(onMethod = @__({@Override}))
- private String state;
-
- // transaction associated with this operation
- private Transaction transaction;
-
- // policy associated with this operation
- @Getter(onMethod = @__({@Override}))
- private Policy policy;
-
- // initial onset message
- private VirtualControlLoopEvent onset;
-
- // attempt associated with this operation
- @Getter(onMethod = @__({@Override}))
- private int attempt;
-
- // message, if any, associated with the result of this operation
- @Getter(onMethod = @__({@Override}))
- private String message = null;
-
- // operation result -- set to a non-null value when the operation completes
- @Getter(onMethod = @__({@Override}))
- private PolicyResult result = null;
-
- // the APPC LCM 'target' derived from the onset
- private String target;
-
- // reference to a Transaction adjunct supporting guard operations
- private GuardAdjunct guardAdjunct;
-
- // counter for how many partial failures were received from appc
- private int partialFailureCount = 0;
-
- // counter for how many partial success were received from appc
- private int partialSuccessCount = 0;
-
- /**
- * Constructor -- initialize an LCM operation instance,
- * try to acquire a lock, and start the guard query if we are ready.
- *
- * @param transaction the transaction the operation is running under
- * @param policy the policy associated with this operation
- * @param onset the initial onset event that triggered the transaction
- * @param attempt this value starts at 1, and is incremented for each retry
- */
- public AppcLcmOperation(Transaction transaction, Policy policy, ControlLoopEvent onset,
- int attempt) {
- // state prior to aquiring the lock
- // (will be changed when the lock is acquired)
- this.state = LCM_WAIT_FOR_LOCK;
- this.transaction = transaction;
- this.policy = policy;
- this.attempt = attempt;
-
- if (!(onset instanceof VirtualControlLoopEvent)) {
- // we need the correct 'onset' event type
- state = LCM_COMPLETE;
- result = PolicyResult.FAILURE;
- message = "Onset event has the wrong type";
- return;
- }
-
- this.onset = (VirtualControlLoopEvent) onset;
-
- // fetch or create the guard adjunct -- note that 'guard' operations are
- // only performed if a 'GuardContext' is present, and the adjunct was
- // created by the Drools rules prior to creating this operation
- this.guardAdjunct = transaction.getAdjunct(GuardAdjunct.class);
-
- // attempt to get a lock for the VM -- if we get it immediately,
- // we can go to the 'LCM_GUARD_PENDING' or 'LCM_BEGIN' state
-
- target = this.onset.getAai().get(onset.getTarget());
- String key = onset.getTargetType() + ":" + target;
- if (transaction.getAdjunct(LockAdjunct.class).getLock(this, key,
- transaction.getRequestId().toString(), false)) {
- // lock was acquired immediately -- move on to the 'guard query'
- // phase
- guardQuery();
- }
- }
-
- /**
- * A method returning true if the A&AI subtag exists
- * and the control loop exists and is not disabled and
- * the target field exists as a key in the A&AI subtag.
- *
- * @param transaction the transaction corresponding to an event
- * @param event the onset containing the A&AI subtag
- * @return true if the A&AI subtag is valid, false otherwise
- */
- public static boolean isAaiValid(Transaction transaction, VirtualControlLoopEvent event) {
- if (event.getAai() == null) {
- transaction.setNotificationMessage("No A&AI Subtag");
- return false;
- } else if (!event.getAai().containsKey(DCAE_CLOSEDLOOP_DISABLED_FIELD)) {
- transaction.setNotificationMessage(DCAE_CLOSEDLOOP_DISABLED_FIELD
- + " information missing");
- return false;
- } else if (isClosedLoopDisabled(event.getAai())) {
- transaction.setNotificationMessage(DCAE_CLOSEDLOOP_DISABLED_FIELD
- + " is set to true");
- return false;
- } else if (!event.getAai().containsKey(event.getTarget())) {
- transaction.setNotificationMessage("target field invalid - must have corresponding AAI value");
- return false;
- }
- return true;
- }
-
- private static boolean isClosedLoopDisabled(Map<String, String> map) {
- if (!map.containsKey(DCAE_CLOSEDLOOP_DISABLED_FIELD)) {
- return false;
- }
- String disabled = map.get(DCAE_CLOSEDLOOP_DISABLED_FIELD);
- return ("true".equalsIgnoreCase(disabled) || "y".equalsIgnoreCase(disabled));
- }
-
- /**
- * trigger an asynchronous guard query -- if guard is not enabled,
- * we go directly to the 'LCM_BEGIN' state.
- */
- private void guardQuery() {
- if (guardAdjunct.asyncQuery(policy, target, onset.getRequestId().toString())) {
- // 'GuardContext' is available --
- // wait for an incoming 'PolicyGuardResponse' message
- this.state = LCM_GUARD_PENDING;
- } else {
- // no 'GuardContext' is available -- go directly to the 'begin' state
- this.state = LCM_BEGIN;
- transaction.modify();
- }
- }
-
- /*=====================================*/
- /* 'LockAdjunct.Requestor' interface */
- /*=====================================*/
-
- /**
- * This method is called by 'LockAdjunct' if we initially had to wait for
- * the lock, but it has now became available.
- */
- public void lockAvailable() {
- if (LCM_WAIT_FOR_LOCK.equals(this.state)) {
- // we have the lock -- invoke 'quardQuery()',
- // go to the appropriate state, and mark the transaction as modified
- guardQuery();
-
- // the 'lockAvailable' method was presumably triggered by the
- // release
- // of the lock by an unrelated transaction -- 'transaction.modify'
- // is
- // called to let Drools know that our transaction has gone through a
- // state change
- transaction.modify();
- }
- }
-
- /**
- * This method is called by 'LockAdjunct' if the lock was unable to be
- * obtained.
- */
- public void lockUnavailable() {
- if (LCM_WAIT_FOR_LOCK.equals(this.state)) {
- try {
- setErrorStatus("Already processing event with this target");
- } catch (ControlLoopException e) {
- logger.debug("Lock could not be obtained for this operation");
- }
- }
- }
-
- /*=======================*/
- /* 'Operation' interface */
- /*=======================*/
-
- /**
- * This method maps the recipe to the correct rpc-name syntax.
- */
- private String toRpcName(String recipe) {
- String rpcName = recipe.toLowerCase();
- if ("healthcheck".equals(rpcName)) {
- rpcName = "health-check";
- }
- return rpcName;
- }
-
- /**
- * This method forwards the construction of the recipe's
- * payload to the proper handler.
- *
- * @return a json representation of the payload
- * @throws ControlLoopException if it occurs
- */
- protected String setPayload(Map<String, String> aai, String recipe) throws ControlLoopException {
- Map<String, String> payload = null;
-
- switch (recipe) {
- case "restart":
- case "rebuild":
- case "migrate":
- case "evacuate":
- case "start":
- case "stop":
- if (this.policy.getTarget().getType() == TargetType.VM) {
- payload = setCommonPayload(aai);
- }
- break;
- case "reboot":
- payload = setRebootPayload();
- break;
- default:
- break;
- }
-
- if (payload == null) {
- return null;
- }
-
- try {
- return coder.encode(payload);
- } catch (CoderException e) {
- return null;
- }
- }
-
- /**
- * This method will construct a payload for a restart, rebuild,
- * migrate, or evacuate. The payload must be an escaped json
- * string so gson is used to convert the payload hashmap into
- * json
- *
- * @return a hashmap representation of the payload
- * @throws ControlLoopException if it occurs
- */
- private Map<String, String> setCommonPayload(Map<String, String> aai) throws ControlLoopException {
- Map<String, String> payload = new HashMap<>();
- for (Map.Entry<String, String> entry : aai.entrySet()) {
- switch (entry.getKey()) {
- case DCAE_VSERVER_SELF_LINK_FIELD:
- if (entry.getValue() != null) {
- payload.put(APPC_LCM_VM_ID_FIELD, entry.getValue());
- } else {
- setErrorStatus(DCAE_ONSET_MISSING + DCAE_VSERVER_SELF_LINK_FIELD);
- }
- break;
- case DCAE_IDENTITY_FIELD:
- if (entry.getValue() != null) {
- payload.put(APPC_LCM_IDENTITY_URL_FIELD, entry.getValue());
- } else {
- setErrorStatus(DCAE_ONSET_MISSING + DCAE_IDENTITY_FIELD);
- }
- break;
- case DCAE_TENANT_ID_FIELD:
- if (entry.getValue() != null) {
- payload.put(APPC_LCM_TENANT_ID_FIELD, entry.getValue());
- } else {
- setErrorStatus(DCAE_ONSET_MISSING + DCAE_TENANT_ID_FIELD);
- }
- break;
- default:
- break;
- }
- }
-
- return payload;
- }
-
- /**
- * This method will construct a payload for a reboot.
- * The payload must be an escaped json string so gson is used
- * to convert the payload hashmap into json. The reboot payload
- * requires a type of "HARD" or "SOFT" reboot from the policy
- * defined through CLAMP.
- *
- * @return an escaped json string representation of the payload
- */
- private Map<String, String> setRebootPayload() throws ControlLoopException {
- Map<String, String> payload = new HashMap<>();
-
- if (this.policy.getTarget().getType() == TargetType.VM) {
- payload = setCommonPayload(onset.getAai());
- // The tenant-id is not used for the reboot request so we can remove
- // it after being added by the common payload
- payload.remove(APPC_LCM_TENANT_ID_FIELD);
- }
-
- // Extract "HARD" or "SOFT" from YAML policy
- String type = this.policy.getPayload().get("type").toUpperCase();
- payload.put("type", type);
-
- return payload;
- }
-
- /**
- * Return the request message associated with this operation.
- *
- * {@inheritDoc}
- *
- * @throws ControlLoopException if it occurs
- */
- @Override
- public Object getRequest() throws ControlLoopException {
- AppcLcmCommonHeader commonHeader = new AppcLcmCommonHeader();
- commonHeader.setRequestId(onset.getRequestId());
- commonHeader.setOriginatorId("POLICY");
- commonHeader.setSubRequestId(String.valueOf(attempt));
-
- // Policy will send a default ttl of 10 minutes (600 seconds)
- Map<String, String> flags = new HashMap<>();
- flags.put("ttl", "600");
- commonHeader.setFlags(flags);
-
- String action = null;
- for (String recipe: recipes) {
- if (recipe.equalsIgnoreCase(policy.getRecipe())) {
- action = recipe;
- break;
- }
- }
-
- if (action == null) {
- setErrorStatus("Error - invalid recipe");
- }
-
- Map<String, String> actionIdentifiers = new HashMap<>();
-
- // The vnf-id is needed for both VNF and VM level operations
- if (onset.getAai().containsKey(DCAE_VNF_NAME_FIELD)) {
- actionIdentifiers.put("vnf-id", onset.getAai().get(DCAE_VNF_ID_FIELD));
- } else {
- logger.error("Error - no AAI DCAE VNF NAME key in the onset");
- setErrorStatus("Error - no VNF NAME key in the onset");
- }
-
- if (this.policy.getTarget().getType() == TargetType.VM) {
- if (onset.getAai().containsKey(DCAE_VSERVER_ID_FIELD)) {
- actionIdentifiers.put("vserver-id", onset.getAai().get(DCAE_VSERVER_ID_FIELD));
- } else {
- logger.error("Error - no DCAE VSERVER ID key in the onset AAI\n");
- setErrorStatus("Error - no VSERVER ID key in the onset");
- }
- }
-
- String payload = setPayload(onset.getAai(), action.toLowerCase());
-
- // construct an APPC LCM 'Request' message
- AppcLcmInput request = new AppcLcmInput();
-
- request.setCommonHeader(commonHeader);
- request.setAction(action);
- request.setActionIdentifiers(actionIdentifiers);
- request.setPayload(payload);
-
- // Pass the LCM request to the LCM wrapper
- AppcLcmDmaapWrapper dmaapWrapper = new AppcLcmDmaapWrapper();
- dmaapWrapper.setVersion("2.0");
- AppcLcmBody appcBody = new AppcLcmBody();
- appcBody.setInput(request);
- dmaapWrapper.setBody(appcBody);
- dmaapWrapper.setCorrelationId(onset.getRequestId() + "-" + attempt);
- dmaapWrapper.setRpcName(toRpcName(action));
- dmaapWrapper.setType("request");
-
- // go to the LCM_PENDING state, under the assumption that the
- // calling Drools code will send out the message we are returning
- this.state = LCM_PENDING;
- transaction.modify();
- return dmaapWrapper;
- }
-
- /**
- * This method is called by 'incomingMessage' when the message is a
- * 'PolicyGuardResponse' message (leaving 'incomingMessage' to focus on
- * 'Response' messages).
- *
- * @param response the received guard response message
- */
- void incomingGuardMessage(PolicyGuardResponse response) {
- // this message is only meaningful if we are waiting for a
- // 'guard' response -- ignore it, if this isn't the case
- if (LCM_GUARD_PENDING.equals(this.state)) {
- if ("Deny".equals(response.getResult())) {
- // this is a guard failure
- logger.error("LCM operation denied by 'Guard'");
- this.message = "Denied by Guard";
- this.result = PolicyResult.FAILURE_GUARD;
- this.state = LCM_COMPLETE;
- } else {
- // everything else is treated as 'Permit'
- this.state = LCM_BEGIN;
- transaction.modify();
- }
- }
- }
-
- /**
- * An incoming message is being delivered to the operation.
- *
- * {@inheritDoc}
- */
- @Override
- public void incomingMessage(Object object) {
- if (! (object instanceof AppcLcmDmaapWrapper)) {
- if (object instanceof PolicyGuardResponse) {
- incomingGuardMessage((PolicyGuardResponse) object);
- } else if (object instanceof ControlLoopEvent) {
- incomingAbatedEvent((ControlLoopEvent) object);
- }
- // ignore this message (not sure why we even got it)
- return;
- }
-
- // If we reach this point, we have a 'AppcLcmDmaapWrapper' instance.
- // The rest of this method is mostly copied from
- // 'ControlLoopOperationManager.onResponse'.
-
- AppcLcmOutput response = ((AppcLcmDmaapWrapper) object).getBody().getOutput();
-
- //
- // Determine which subrequestID (ie. attempt)
- //
- int operationAttempt;
- try {
- operationAttempt = Integer.parseInt(response.getCommonHeader()
- .getSubRequestId());
- } catch (NumberFormatException e) {
- //
- // We cannot tell what happened if this doesn't exist
- // If the attempt cannot be parsed then we assume it is
- // the current attempt
- //
- this.completeOperation(this.attempt, "Policy was unable to parse APP-C SubRequestID (it was null).",
- PolicyResult.FAILURE_EXCEPTION);
- return;
- }
- //
- // Sanity check the response message
- //
- if (response.getStatus() == null) {
- //
- // We cannot tell what happened if this doesn't exist
- //
- this.completeOperation(operationAttempt,
- "Policy was unable to parse APP-C response status field (it was null).",
- PolicyResult.FAILURE_EXCEPTION);
- return;
- }
- //
- // Get the Response Code
- //
- AppcLcmResponseCode responseValue = AppcLcmResponseCode.toResponseValue(response.getStatus().getCode());
- if (responseValue == null) {
- //
- // We are unaware of this code
- //
- this.completeOperation(operationAttempt, "Policy was unable to parse APP-C response status code field.",
- PolicyResult.FAILURE_EXCEPTION);
- return;
- }
- //
- // Ok, let's figure out what APP-C's response is
- //
- switch (responseValue) {
- case ACCEPTED:
- //
- // This is good, they got our original message and
- // acknowledged it.
- //
- // Is there any need to track this?
- //
- return;
- case PARTIAL_SUCCESS:
- //
- // Keep count of partial successes to determine
- // if retries should be done at the vnf level
- //
- this.partialSuccessCount++;
- return;
- case PARTIAL_FAILURE:
- //
- // Keep count of partial failures to determine
- // if no retries should be done
- //
- this.partialFailureCount++;
- return;
- case ERROR:
- case REJECT:
- //
- // We'll consider these two codes as exceptions
- //
- this.completeOperation(operationAttempt, response.getStatus()
- .getMessage(), PolicyResult.FAILURE_EXCEPTION);
- return;
- case SUCCESS:
- //
- //
- //
- this.completeOperation(operationAttempt, response.getStatus()
- .getMessage(), PolicyResult.SUCCESS);
- return;
- case FAILURE:
- // For the VNF level operations, retries will be attempted only
- // if ALL individual VMs failed the operation
- if (this.partialSuccessCount == 0) {
- // Since there are no partial successes, that means all VMs failed
- // if all vms fail, we can retry the VNF level action
- this.completeOperation(operationAttempt, response.getStatus()
- .getMessage(), PolicyResult.FAILURE);
- } else if (this.partialFailureCount > 0) {
- // Since only a subset of VMs had partial failures,
- // the result should go to final failure and not
- // retry or move on to the next policy in the chain.
- this.completeOperation(operationAttempt, response.getStatus()
- .getMessage(), PolicyResult.FAILURE_EXCEPTION);
- }
- return;
- default:
- break;
- }
- }
-
- /**
- * This method is called by 'incomingMessage' only when an 'ABATED' event is received before an APPC
- * request is sent.
- *
- * @param event the control loop event that was received
- */
- private void incomingAbatedEvent(ControlLoopEvent event) {
- // check if ClosedLoopEventStatus is 'abated'
- if (event.isEventStatusValid() && "ABATED".equalsIgnoreCase(event.getClosedLoopEventStatus().toString())) {
- this.result = PolicyResult.SUCCESS;
- this.message = "Abatement received before APPC request was sent";
- this.state = LCM_COMPLETE;
- }
- }
-
- /**
- * This method is called by 'incomingMessage' in order to complete the
- * operation.
- *
- * @param attempt the operation attempt indicated in the response message
- * @param message the value to store in the 'message' field'
- * @param result the value to store in the 'result' field
- */
- void completeOperation(int attempt, String message, PolicyResult result) {
- logger.debug("LCM: completeOperation(this.attempt={}, attempt={}, result={}, message ={})",
- this.attempt, attempt, result, message);
- if (this.attempt == attempt) {
- // we need to verify that the attempt matches in order to reduce the
- // chances that we are reacting to a prior 'Response' message that
- // was received after we timed out (unfortunately, we can't guarantee
- // this, because we have no reliable way to verify the 'recipe')
-
- this.message = message;
- this.result = result;
- state = LCM_COMPLETE;
- }
- }
-
- /**
- * The operation has timed out.
- *
- * {@inheritDoc}
- */
- @Override
- public void timeout() {
- result = PolicyResult.FAILURE_TIMEOUT;
- state = LCM_COMPLETE;
- }
-
- void setErrorStatus(String message) throws ControlLoopException {
- result = PolicyResult.FAILURE_EXCEPTION;
- state = LCM_ERROR;
- this.message = message;
- transaction.modify();
- throw new ControlLoopException(message);
- }
-
- /**
- * This is called right after it's history entry has been completed.
- *
- * {@inheritDoc}
- */
- @Override
- public void histEntryCompleted(ControlLoopOperation histEntry) {
- // give 'guard' a chance to create a DB entry (this only happens if
- // we really have a 'GuardContext', and all of the needed parameters
- // were provided in the '*-controller.properties' file)
- guardAdjunct.asyncCreateDbEntry(histEntry, target);
- }
-}
diff --git a/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/model/AppcLcmResponseCode.java b/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/model/AppcLcmResponseCode.java
deleted file mode 100644
index ca812a4db..000000000
--- a/controlloop/m2/appclcm/src/main/java/org/onap/policy/m2/appclcm/model/AppcLcmResponseCode.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/appclcm
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.appclcm.model;
-
-import java.io.Serializable;
-
-public enum AppcLcmResponseCode implements Serializable {
- ACCEPTED, ERROR, REJECT, SUCCESS, FAILURE, PARTIAL_SUCCESS, PARTIAL_FAILURE;
-
- private static final long serialVersionUID = 1L;
-
- /**
- * Translates the code to a string value that represents the meaning of the
- * code.
- *
- * @param code
- * the numeric value that is returned by APPC based on success,
- * failure, etc. of the action requested
- * @return the enum value equivalent of the APPC response code
- */
- public static AppcLcmResponseCode toResponseValue(int code) {
- if (code == 100) {
- return ACCEPTED;
- } else if (code == 200) {
- return ERROR;
- } else if (code >= 300 && code <= 316) {
- return REJECT;
- } else if (code == 400) {
- return SUCCESS;
- } else if (code == 450 || (code >= 401 && code <= 406)) {
- return FAILURE;
- } else if (code == 500) {
- return PARTIAL_SUCCESS;
- } else if (code >= 501 && code <= 599) {
- return PARTIAL_FAILURE;
- }
- return null;
- }
-
-}
diff --git a/controlloop/m2/appclcm/src/main/resources/META-INF/services/org.onap.policy.m2.base.Actor b/controlloop/m2/appclcm/src/main/resources/META-INF/services/org.onap.policy.m2.base.Actor
deleted file mode 100644
index 2e6065608..000000000
--- a/controlloop/m2/appclcm/src/main/resources/META-INF/services/org.onap.policy.m2.base.Actor
+++ /dev/null
@@ -1 +0,0 @@
-org.onap.policy.m2.appclcm.AppcLcmActor
diff --git a/controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmActorTest.java b/controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmActorTest.java
deleted file mode 100644
index 1c6e81ec6..000000000
--- a/controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmActorTest.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/appclcm
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package appclcm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-import java.util.Properties;
-import java.util.UUID;
-import org.drools.core.WorkingMemory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.controlloop.ControlLoopEventStatus;
-import org.onap.policy.controlloop.ControlLoopTargetType;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.m2.appclcm.AppcLcmActor;
-import org.onap.policy.m2.appclcm.AppcLcmHealthCheckOperation;
-import org.onap.policy.m2.appclcm.AppcLcmOperation;
-import org.onap.policy.m2.base.Transaction;
-
-public class AppcLcmActorTest {
- public static Policy policy;
- public static VirtualControlLoopEvent event;
- public static Transaction transaction;
- public static AppcLcmHealthCheckOperation operation;
- public static AppcLcmActor actor;
-
- /**
- * Class-level setup.
- */
- @BeforeClass
- public static void setup() {
- PolicyEngineConstants.getManager().configure(new Properties());
- PolicyEngineConstants.getManager().start();
-
- policy = new Policy();
- policy.setActor("APPCLCM");
- policy.setTarget(new Target(TargetType.VM));
-
- event = new VirtualControlLoopEvent();
- event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- event.setRequestId(UUID.randomUUID());
- event.setTarget("vserver.vserver-name");
- event.setTargetType(ControlLoopTargetType.VM);
- event.getAai().put("vserver.is-closed-loop-disabled", "false");
- event.getAai().put("complex.state", "NJ");
- event.getAai().put("vserver.l-interface.interface-name", "89ee9ee6-1e96-4063-b690-aa5ca9f73b32");
- event.getAai().put("vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address",
- "135.144.3.49");
- event.getAai().put("vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address", null);
- event.getAai().put("vserver.in-maint", "N");
- event.getAai().put("complex.city", "AAIDefault");
- event.getAai().put("vserver.vserver-id", "aa7a24f9-8791-491f-b31a-c8ba5ad9e2aa");
- event.getAai().put("vserver.l-interface.network-name", "vUSP_DPA3_OAM_3750");
- event.getAai().put("vserver.vserver-name", "ctsf0002vm013");
- event.getAai().put("generic-vnf.vnf-name", "ctsf0002v");
- event.getAai().put("generic-vnf.vnf-id", "0f551f1b-e4e5-4ce2-84da-eda916e06e1c");
- event.getAai().put("generic-vnf.service-id", "e433710f-9217-458d-a79d-1c7aff376d89");
- event.getAai().put("vserver.selflink", "https://compute-aic.dpa3.cci.att.com:8774/v2/d0719b845a804b368f8ac0bba39e188b/servers/aa7a24f9-8791-491f-b31a-c8ba5ad9e2aa");
- event.getAai().put("generic-vnf.vnf-type", "vUSP - vCTS");
- event.getAai().put("tenant.tenant-id", "d0719b845a804b368f8ac0bba39e188b");
- event.getAai().put("cloud-region.identity-url", "https://compute-aic.dpa3.cci.att.com:8774/");
- event.getAai().put("vserver.prov-status", "PROV");
- event.getAai().put("complex.physical-location-id", "LSLEILAA");
-
- WorkingMemory wm = mock(WorkingMemory.class);
- transaction = new Transaction(wm, "clvusptest", event.getRequestId(), null);
-
- actor = new AppcLcmActor();
- }
-
- @AfterClass
- public static void cleanup() {
- transaction.cleanup();
- PolicyEngineConstants.getManager().stop();
- }
-
- @Test
- public void testGetName() {
- assertEquals("APPCLCM", actor.getName());
- }
-
- @Test
- public void testCreateOperation() {
- policy.setRecipe("HEALTHCHECK");
- policy.getTarget().setType(TargetType.VNF);
- operation = (AppcLcmHealthCheckOperation) actor.createOperation(transaction, policy, event, 1);
- assertTrue(operation instanceof AppcLcmHealthCheckOperation);
-
- policy.setRecipe("");
- AppcLcmOperation lcmOperation = (AppcLcmOperation) actor.createOperation(transaction, policy, event, 1);
- assertTrue(lcmOperation instanceof AppcLcmOperation);
- }
-}
diff --git a/controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmHealthCheckOperationTest.java b/controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmHealthCheckOperationTest.java
deleted file mode 100644
index 6e606b28b..000000000
--- a/controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmHealthCheckOperationTest.java
+++ /dev/null
@@ -1,330 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/appclcm
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package appclcm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-import java.util.Properties;
-import java.util.UUID;
-import org.drools.core.WorkingMemory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
-import org.onap.policy.appclcm.AppcLcmInput;
-import org.onap.policy.appclcm.util.Serialization;
-import org.onap.policy.controlloop.ControlLoopEventStatus;
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.ControlLoopTargetType;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.guard.PolicyGuardResponse;
-import org.onap.policy.m2.appclcm.AppcLcmActor;
-import org.onap.policy.m2.appclcm.AppcLcmHealthCheckOperation;
-import org.onap.policy.m2.base.Transaction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AppcLcmHealthCheckOperationTest {
- private static Logger logger = LoggerFactory.getLogger(AppcLcmHealthCheckOperationTest.class);
-
- public static Policy policy;
- public static VirtualControlLoopEvent event;
- public static Transaction transaction;
- public static AppcLcmHealthCheckOperation operation;
-
- /**
- * Class-level setup.
- */
- @BeforeClass
- public static void setup() {
- PolicyEngineConstants.getManager().configure(new Properties());
- PolicyEngineConstants.getManager().start();
-
- policy = new Policy();
- policy.setActor("APPCLCM");
- policy.setTarget(new Target(TargetType.VM));
-
- event = new VirtualControlLoopEvent();
- event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- event.setRequestId(UUID.randomUUID());
- event.setTarget("vserver.vserver-name");
- event.setTargetType(ControlLoopTargetType.VM);
- event.getAai().put("vserver.is-closed-loop-disabled", "false");
- event.getAai().put("complex.state", "NJ");
- event.getAai().put("vserver.l-interface.interface-name", "89ee9ee6-1e96-4063-b690-aa5ca9f73b32");
- event.getAai().put("vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address",
- "135.144.3.49");
- event.getAai().put("vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address", null);
- event.getAai().put("vserver.in-maint", "N");
- event.getAai().put("complex.city", "AAIDefault");
- event.getAai().put("vserver.vserver-id", "aa7a24f9-8791-491f-b31a-c8ba5ad9e2aa");
- event.getAai().put("vserver.l-interface.network-name", "vUSP_DPA3_OAM_3750");
- event.getAai().put("vserver.vserver-name", "ctsf0002vm013");
- event.getAai().put("generic-vnf.vnf-name", "ctsf0002v");
- event.getAai().put("generic-vnf.vnf-id", "0f551f1b-e4e5-4ce2-84da-eda916e06e1c");
- event.getAai().put("generic-vnf.service-id", "e433710f-9217-458d-a79d-1c7aff376d89");
- event.getAai().put("vserver.selflink", "https://compute-aic.dpa3.cci.att.com:8774/v2/d0719b845a804b368f8ac0bba39e188b/servers/aa7a24f9-8791-491f-b31a-c8ba5ad9e2aa");
- event.getAai().put("generic-vnf.vnf-type", "vUSP - vCTS");
- event.getAai().put("tenant.tenant-id", "d0719b845a804b368f8ac0bba39e188b");
- event.getAai().put("cloud-region.identity-url", "https://compute-aic.dpa3.cci.att.com:8774/");
- event.getAai().put("vserver.prov-status", "PROV");
- event.getAai().put("complex.physical-location-id", "LSLEILAA");
-
- WorkingMemory wm = mock(WorkingMemory.class);
- transaction = new Transaction(wm, "clvusptest", event.getRequestId(), null);
-
- }
-
- @AfterClass
- public static void cleanup() {
- transaction.cleanup();
- PolicyEngineConstants.getManager().stop();
- }
-
- @Test
- public void testGetVnfHealthCheckRequest() throws ControlLoopException {
-
- policy.setRecipe("HEALTHCHECK");
- policy.getTarget().setType(TargetType.VNF);
- AppcLcmActor actor = new AppcLcmActor();
- operation = (AppcLcmHealthCheckOperation) actor.createOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("health-check", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("HealthCheck", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertNotNull(appcRequest.getPayload());
- assertTrue(appcRequest.getPayload().contains("host-ip-address"));
-
- logger.info("health-check request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testIncomingHealthCheckMessageHealthyState() {
- policy.setRecipe("HEALTHCHECK");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2017-08-25T21:06:23.037Z\","
- + "\"api-ver\":\"5.00\",\"originator-id\":\"POLICY\","
- + "\"request-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200\",\"sub-request-id\":\"1\",\"flags\":{}},"
- + "\"status\":{\"code\":400,\"message\":\"HealthCheckSuccessful\"},"
- + "\"payload\":\"{\\\"identifier\\\":\\\"scoperepresented\\\",\\\"state\\\":\\\"healthy\\\","
- + "\\\"time\\\":\\\"01-01-1000:0000\\\"}\"}},\"version\":\"2.0\",\"rpc-name\":\"health-check\","
- + "\"correlation-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200-1\",\"type\":\"response\"}";
- AppcLcmDmaapWrapper healthCheckResp = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation.incomingMessage(healthCheckResp);
- assertEquals(PolicyResult.SUCCESS, operation.getResult());
- }
-
- @Test
- public void testIncomingHealthCheckMessageUnhealthyState() {
- policy.setRecipe("HEALTHCHECK");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2017-08-25T21:06:23.037Z\","
- + "\"api-ver\":\"5.00\",\"originator-id\":\"POLICY\","
- + "\"request-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200\",\"sub-request-id\":\"1\",\"flags\":{}},"
- + "\"status\":{\"code\":400,\"message\":\"VNF is unhealthy\"},"
- + "\"payload\":\"{\\\"identifier\\\":\\\"scoperepresented\\\",\\\"state\\\":\\\"unhealthy\\\","
- + "\\\"info\\\":\\\"Systemthresholdexceededdetails\\\",\\\"fault\\\":{\\\"cpuOverall\\\":0.80,"
- + "\\\"cpuThreshold\\\":0.45},\\\"time\\\":\\\"01-01-1000:0000\\\"}\"}},\"version\":\"2.0\","
- + "\"rpc-name\":\"health-check\",\"correlation-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200-1\","
- + "\"type\":\"response\"}";
- AppcLcmDmaapWrapper healthCheckResp = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation.incomingMessage(healthCheckResp);
- assertEquals(PolicyResult.FAILURE, operation.getResult());
- }
-
- @Test
- public void testIncomingHealthCheckMessageUnknownState() {
- policy.setRecipe("HEALTHCHECK");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2017-08-25T21:06:23.037Z\","
- + "\"api-ver\":\"5.00\",\"originator-id\":\"POLICY\","
- + "\"request-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200\",\"sub-request-id\":\"1\",\"flags\":{}},"
- + "\"status\":{\"code\":400,\"message\":\"VNF is unhealthy\"},"
- + "\"payload\":\"{\\\"identifier\\\":\\\"scoperepresented\\\",\\\"state\\\":\\\"unknown\\\","
- + "\\\"info\\\":\\\"Systemthresholdexceededdetails\\\",\\\"fault\\\":{\\\"cpuOverall\\\":0.80,"
- + "\\\"cpuThreshold\\\":0.45},\\\"time\\\":\\\"01-01-1000:0000\\\"}\"}},\"version\":\"2.0\","
- + "\"rpc-name\":\"health-check\",\"correlation-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200-1\","
- + "\"type\":\"response\"}";
- AppcLcmDmaapWrapper healthCheckResp = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation.incomingMessage(healthCheckResp);
- assertEquals(PolicyResult.FAILURE_EXCEPTION, operation.getResult());
- }
-
- @Test
- public void testIncomingHealthCheckMessageNoState() {
- policy.setRecipe("HEALTHCHECK");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2017-08-25T21:06:23.037Z\","
- + "\"api-ver\":\"5.00\",\"originator-id\":\"POLICY\","
- + "\"request-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200\",\"sub-request-id\":\"1\",\"flags\":{}},"
- + "\"status\":{\"code\":400,\"message\":\"VNF is unhealthy\"},"
- + "\"payload\":\"{\\\"identifier\\\":\\\"scoperepresented\\\","
- + "\\\"info\\\":\\\"Systemthresholdexceededdetails\\\",\\\"fault\\\":{\\\"cpuOverall\\\":0.80,"
- + "\\\"cpuThreshold\\\":0.45},\\\"time\\\":\\\"01-01-1000:0000\\\"}\"}},\"version\":\"2.0\","
- + "\"rpc-name\":\"health-check\",\"correlation-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200-1\","
- + "\"type\":\"response\"}";
- AppcLcmDmaapWrapper healthCheckResp = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation.incomingMessage(healthCheckResp);
- assertEquals(PolicyResult.FAILURE_EXCEPTION, operation.getResult());
- }
-
- @Test
- public void testIncomingHealthCheckMessageUnsuccessful() {
- policy.setRecipe("HEALTHCHECK");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2017-08-25T21:06:23.037Z\","
- + "\"api-ver\":\"5.00\",\"originator-id\":\"POLICY\","
- + "\"request-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200\",\"sub-request-id\":\"1\",\"flags\":{}},"
- + "\"status\":{\"code\":401,\"message\":\"Could not complete HealthCheck\"},"
- + "\"payload\":\"{\\\"identifier\\\":\\\"scoperepresented\\\","
- + "\\\"info\\\":\\\"Systemthresholdexceededdetails\\\",\\\"fault\\\":{\\\"cpuOverall\\\":0.80,"
- + "\\\"cpuThreshold\\\":0.45},\\\"time\\\":\\\"01-01-1000:0000\\\"}\"}},\"version\":\"2.0\","
- + "\"rpc-name\":\"health-check\",\"correlation-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200-1\","
- + "\"type\":\"response\"}";
- AppcLcmDmaapWrapper healthCheckResp = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation.incomingMessage(healthCheckResp);
- assertEquals(PolicyResult.FAILURE, operation.getResult());
- }
-
- @Test
- public void testIncomingHealthCheckMessageNoPayload() {
- policy.setRecipe("HEALTHCHECK");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2017-08-25T21:06:23.037Z\","
- + "\"api-ver\":\"5.00\",\"originator-id\":\"POLICY\","
- + "\"request-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200\",\"sub-request-id\":\"1\",\"flags\":{}},"
- + "\"status\":{\"code\":400,\"message\":\"VNF is unhealthy\"}}},\"version\":\"2.0\","
- + "\"rpc-name\":\"health-check\",\"correlation-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200-1\","
- + "\"type\":\"response\"}";
- AppcLcmDmaapWrapper healthCheckResp = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation.incomingMessage(healthCheckResp);
- assertEquals(PolicyResult.FAILURE_EXCEPTION, operation.getResult());
- }
-
- @Test
- public void testIncomingHealthCheckMessageEmptyPayload() {
- policy.setRecipe("HEALTHCHECK");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2017-08-25T21:06:23.037Z\","
- + "\"api-ver\":\"5.00\",\"originator-id\":\"POLICY\","
- + "\"request-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200\",\"sub-request-id\":\"1\",\"flags\":{}},"
- + "\"status\":{\"code\":400,\"message\":\"VNF is unhealthy\"},\"payload\":\"\"}},\"version\":\"2.0\","
- + "\"rpc-name\":\"health-check\",\"correlation-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200-1\","
- + "\"type\":\"response\"}";
- AppcLcmDmaapWrapper healthCheckResp = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation.incomingMessage(healthCheckResp);
- assertEquals(PolicyResult.FAILURE_EXCEPTION, operation.getResult());
- }
-
- @Test
- public void testIncomingMessage() {
- policy.setRecipe("HEALTHCHECK");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
-
- //Submitting Policy Guard Response instead of AppcLcmDmaapWrapper
- PolicyGuardResponse response = new PolicyGuardResponse("", UUID.randomUUID(), "");
- operation.incomingMessage(response);
-
- //Checking for Failure Code
- String lcmRespJson = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2017-08-25T21:06:23.037Z\","
- + "\"api-ver\":\"5.00\",\"originator-id\":\"POLICY\","
- + "\"request-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200\",\"sub-request-id\":\"1\",\"flags\":{}},"
- + "\"status\":{\"code\":404,\"message\":\"VNF is unhealthy\"},\"payload\":\"\"}},\"version\":\"2.0\","
- + "\"rpc-name\":\"health-check\",\"correlation-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200-1\","
- + "\"type\":\"response\"}";
- AppcLcmDmaapWrapper healthCheckResp = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
- operation.incomingMessage(healthCheckResp);
- assertEquals(PolicyResult.FAILURE, operation.getResult());
-
- //Checking code 300 Failure_Exception
- lcmRespJson = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2017-08-25T21:06:23.037Z\","
- + "\"api-ver\":\"5.00\",\"originator-id\":\"POLICY\","
- + "\"request-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200\",\"sub-request-id\":\"1\",\"flags\":{}},"
- + "\"status\":{\"code\":300,\"message\":\"VNF is unhealthy\"},\"payload\":\"\"}},\"version\":\"2.0\","
- + "\"rpc-name\":\"health-check\",\"correlation-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200-1\","
- + "\"type\":\"response\"}";
- healthCheckResp = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
- operation.incomingMessage(healthCheckResp);
- assertEquals(PolicyResult.FAILURE_EXCEPTION, operation.getResult());
-
- //Checking code 100 accepted does nothing to result
- //Leaving the operation result as the initialized value of null
- lcmRespJson = "{\"body\":{\"output\":{\"common-header\":{\"timestamp\":\"2017-08-25T21:06:23.037Z\","
- + "\"api-ver\":\"5.00\",\"originator-id\":\"POLICY\","
- + "\"request-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200\",\"sub-request-id\":\"1\",\"flags\":{}},"
- + "\"status\":{\"code\":100,\"message\":\"VNF is unhealthy\"},\"payload\":\"\"}},\"version\":\"2.0\","
- + "\"rpc-name\":\"health-check\",\"correlation-id\":\"664be3d2-6c12-4f4b-a3e7-c349acced200-1\","
- + "\"type\":\"response\"}";
- healthCheckResp = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation = new AppcLcmHealthCheckOperation(transaction, policy, event, 1);
- operation.incomingMessage(healthCheckResp);
- assertEquals(null, operation.getResult());
- }
-}
diff --git a/controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmOperationTest.java b/controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmOperationTest.java
deleted file mode 100644
index e270c3d71..000000000
--- a/controlloop/m2/appclcm/src/test/java/appclcm/AppcLcmOperationTest.java
+++ /dev/null
@@ -1,723 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/appclcm
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package appclcm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-import java.util.HashMap;
-import java.util.Properties;
-import java.util.UUID;
-import org.drools.core.WorkingMemory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
-import org.onap.policy.appclcm.AppcLcmInput;
-import org.onap.policy.appclcm.util.Serialization;
-import org.onap.policy.controlloop.ControlLoopEventStatus;
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.ControlLoopTargetType;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.controlloop.policy.Target;
-import org.onap.policy.controlloop.policy.TargetType;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.m2.appclcm.AppcLcmOperation;
-import org.onap.policy.m2.base.Transaction;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class AppcLcmOperationTest {
- private static Logger logger = LoggerFactory.getLogger(AppcLcmOperationTest.class);
-
- public static Policy policy;
- public static VirtualControlLoopEvent event;
- public static Transaction transaction;
- public static AppcLcmOperation operation;
-
- /**
- * Class-level setup.
- */
- @BeforeClass
- public static void start() {
- PolicyEngineConstants.getManager().configure(new Properties());
- PolicyEngineConstants.getManager().start();
-
- policy = new Policy();
- policy.setActor("APPCLCM");
- policy.setTarget(new Target(TargetType.VM));
-
- event = new VirtualControlLoopEvent();
- event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- event.setRequestId(UUID.randomUUID());
- event.setTarget("vserver.vserver-name");
- event.setTargetType(ControlLoopTargetType.VM);
- event.getAai().put("vserver.is-closed-loop-disabled", "false");
- event.getAai().put("complex.state", "NJ");
- event.getAai().put("vserver.l-interface.interface-name", "89ee9ee6-1e96-4063-b690-aa5ca9f73b32");
- event.getAai().put("vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address",
- "135.144.3.49");
- event.getAai().put("vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address", null);
- event.getAai().put("vserver.in-maint", "N");
- event.getAai().put("complex.city", "AAIDefault");
- event.getAai().put("vserver.vserver-id", "aa7a24f9-8791-491f-b31a-c8ba5ad9e2aa");
- event.getAai().put("vserver.l-interface.network-name", "vUSP_DPA3_OAM_3750");
- event.getAai().put("vserver.vserver-name", "ctsf0002vm013");
- event.getAai().put("generic-vnf.vnf-name", "ctsf0002v");
- event.getAai().put("generic-vnf.vnf-id", "0f551f1b-e4e5-4ce2-84da-eda916e06e1c");
- event.getAai().put("generic-vnf.service-id", "e433710f-9217-458d-a79d-1c7aff376d89");
- event.getAai().put("vserver.selflink", "https://compute-aic.dpa3.cci.att.com:8774/v2/d0719b845a804b368f8ac0bba39e188b/servers/aa7a24f9-8791-491f-b31a-c8ba5ad9e2aa");
- event.getAai().put("generic-vnf.vnf-type", "vUSP - vCTS");
- event.getAai().put("tenant.tenant-id", "d0719b845a804b368f8ac0bba39e188b");
- event.getAai().put("cloud-region.identity-url", "https://compute-aic.dpa3.cci.att.com:8774/");
- event.getAai().put("vserver.prov-status", "PROV");
- event.getAai().put("complex.physical-location-id", "LSLEILAA");
-
- WorkingMemory wm = mock(WorkingMemory.class);
- transaction = new Transaction(wm, "clvusptest", event.getRequestId(), null);
- }
-
- @AfterClass
- public static void cleanup() {
- transaction.cleanup();
- PolicyEngineConstants.getManager().stop();
- }
-
- @Test
- public void testGetVmRestartRequest() throws ControlLoopException {
-
- policy.setRecipe("RESTART");
- policy.getTarget().setType(TargetType.VM);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("restart", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Restart", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertEquals(event.getAai().get("vserver.vserver-id"), appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNotNull(appcRequest.getPayload());
-
- logger.info("vm restart request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVnfRestartRequest() throws ControlLoopException {
-
- policy.setRecipe("RESTART");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("restart", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Restart", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertNull(appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNull(appcRequest.getPayload());
-
- logger.info("vnf restart request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVmRebuildRequest() throws ControlLoopException {
-
- policy.setRecipe("REBUILD");
- policy.getTarget().setType(TargetType.VM);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("rebuild", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Rebuild", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertEquals(event.getAai().get("vserver.vserver-id"), appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNotNull(appcRequest.getPayload());
-
- logger.info("vm rebuild request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVnfRebuildRequest() throws ControlLoopException {
-
- policy.setRecipe("REBUILD");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("rebuild", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Rebuild", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertNull(appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNull(appcRequest.getPayload());
-
- logger.info("vnf rebuild request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVmMigrateRequest() throws ControlLoopException {
-
- policy.setRecipe("MIGRATE");
- policy.getTarget().setType(TargetType.VM);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("migrate", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Migrate", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertEquals(event.getAai().get("vserver.vserver-id"), appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNotNull(appcRequest.getPayload());
-
- logger.info("vm migrate request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVnfMigrateRequest() throws ControlLoopException {
-
- policy.setRecipe("MIGRATE");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("migrate", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Migrate", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertNull(appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNull(appcRequest.getPayload());
-
- logger.info("vnf migrate request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVmEvacuateRequest() throws ControlLoopException {
-
- policy.setRecipe("EVACUATE");
- policy.getTarget().setType(TargetType.VM);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("evacuate", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Evacuate", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertEquals(event.getAai().get("vserver.vserver-id"), appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNotNull(appcRequest.getPayload());
-
- logger.info("vm evacuate request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVnfEvacuateRequest() throws ControlLoopException {
-
- policy.setRecipe("EVACUATE");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("evacuate", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Evacuate", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertNull(appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNull(appcRequest.getPayload());
-
- logger.info("vnf evacuate request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVmRebootRequest() throws ControlLoopException {
-
- policy.setRecipe("REBOOT");
- policy.getTarget().setType(TargetType.VM);
- policy.setPayload(new HashMap<String, String>());
- policy.getPayload().put("type", "HARD");
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("reboot", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Reboot", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertEquals(event.getAai().get("vserver.vserver-id"), appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNotNull(appcRequest.getPayload());
-
- logger.info("vm reboot request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVnfRebootRequest() throws ControlLoopException {
-
- policy.setRecipe("REBOOT");
- policy.getTarget().setType(TargetType.VNF);
- policy.setPayload(new HashMap<String, String>());
- policy.getPayload().put("type", "HARD");
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("reboot", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Reboot", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertNull(appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNotNull(appcRequest.getPayload());
-
- logger.info("vnf reboot request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVnfStartRequest() throws ControlLoopException {
-
- policy.setRecipe("START");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("start", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Start", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertNull(appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNull(appcRequest.getPayload());
-
- logger.info("vnf start request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVmStartRequest() throws ControlLoopException {
-
- policy.setRecipe("START");
- policy.getTarget().setType(TargetType.VM);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("start", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Start", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertEquals(event.getAai().get("vserver.vserver-id"), appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNotNull(appcRequest.getPayload());
-
- logger.info("vm start request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVnfStopRequest() throws ControlLoopException {
-
- policy.setRecipe("STOP");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
- assertEquals("stop", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Stop", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertNull(appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNull(appcRequest.getPayload());
-
- logger.info("vnf stop request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- @Test
- public void testGetVmStopRequest() throws ControlLoopException {
-
- policy.setRecipe("STOP");
- policy.getTarget().setType(TargetType.VM);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- Object request = operation.getRequest();
- assertTrue(request instanceof AppcLcmDmaapWrapper);
-
- AppcLcmDmaapWrapper dmaapRequest = (AppcLcmDmaapWrapper) request;
- assertEquals("request", dmaapRequest.getType());
-
- assertEquals("stop", dmaapRequest.getRpcName());
- assertNotNull(dmaapRequest.getBody());
-
- AppcLcmInput appcRequest = dmaapRequest.getBody().getInput();
- assertNotNull(appcRequest.getCommonHeader());
- assertEquals("2.00", appcRequest.getCommonHeader().getApiVer());
- assertEquals("POLICY", appcRequest.getCommonHeader().getOriginatorId());
- assertNotNull(appcRequest.getAction());
- assertEquals("Stop", appcRequest.getAction());
- assertNotNull(appcRequest.getActionIdentifiers());
- assertEquals(event.getAai().get("generic-vnf.vnf-id"), appcRequest.getActionIdentifiers().get("vnf-id"));
- assertEquals(event.getAai().get("vserver.vserver-id"), appcRequest.getActionIdentifiers().get("vserver-id"));
- assertNotNull(appcRequest.getPayload());
-
- logger.info("vm stop request: {}", Serialization.gson.toJson(request, AppcLcmDmaapWrapper.class));
-
- }
-
- /* ===================================================================== */
-
- /*
- * these tests are for ensuring the incoming response messages process
- * properly and translate to the expected policy result
- */
-
- @Test
- public void testIncomingVmSuccessMessage() {
- policy.setRecipe("RESTART");
- policy.getTarget().setType(TargetType.VM);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"version\": \"2.0\",\"rpc-name\": \"Restart\",\"correlation-id\": \"baf5ba32-6b8c-430c-a91b-02d2c0ba3064-1\",\"type\": \"response\",\"body\": {\"output\": {\"status\": {\"code\": 400,\"message\": \"Restart Successful\"},\"common-header\": {\"timestamp\": \"2017-07-18T16:52:06.186Z\",\"api-ver\": \"2.01\",\"request-id\": \"baf5ba32-6b8c-430c-a91b-02d2c0ba3064\",\"sub-request-id\": \"1\",\"flags\": {\"ttl\": 600}},\"payload\": \"{\\\"vm-id\\\":\\\"http://135.25.246.131:8774/v2/81fc2bc61f974de1b5a49e8c2ec090bb/servers/75dce20c-97f9-454d-abcc-aa904a33df5a\\\",\\\"tenant-id\\\":\\\"test2\\\"}\"}}}";
- AppcLcmDmaapWrapper restartResponse = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation.incomingMessage(restartResponse);
- assertEquals(PolicyResult.SUCCESS, operation.getResult());
- }
-
- @Test
- public void testIncomingVnfSuccessMessage() {
- policy.setRecipe("RESTART");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"version\": \"2.0\",\"rpc-name\": \"Restart\",\"correlation-id\": \"baf5ba32-6b8c-430c-a91b-02d2c0ba3064-1\",\"type\": \"response\",\"body\": {\"output\": {\"status\": {\"code\": 500,\"message\": \"Restart Successful\"},\"common-header\": {\"timestamp\": \"2017-07-18T16:52:06.186Z\",\"api-ver\": \"2.01\",\"request-id\": \"baf5ba32-6b8c-430c-a91b-02d2c0ba3064\",\"sub-request-id\": \"1\",\"flags\": {\"ttl\": 600}},\"payload\": \"{\\\"vm-id\\\":\\\"http://135.25.246.131:8774/v2/81fc2bc61f974de1b5a49e8c2ec090bb/servers/75dce20c-97f9-454d-abcc-aa904a33df5a\\\",\\\"tenant-id\\\":\\\"test2\\\"}\"}}}";
- AppcLcmDmaapWrapper restartResponse = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- /* Send in several partial success messages */
- for (int i = 0; i < 5; i++) {
- operation.incomingMessage(restartResponse);
- assertNull(operation.getResult());
- }
-
- /* Send in an operation success */
- restartResponse.getBody().getOutput().getStatus().setCode(400);
- operation.incomingMessage(restartResponse);
- assertEquals(PolicyResult.SUCCESS, operation.getResult());
- }
-
- @Test
- public void testIncomingVmFailureMessage() {
- policy.setRecipe("RESTART");
- policy.getTarget().setType(TargetType.VM);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"version\": \"2.0\",\"rpc-name\": \"Restart\",\"correlation-id\": \"baf5ba32-6b8c-430c-a91b-02d2c0ba3064-1\",\"type\": \"response\",\"body\": {\"output\": {\"status\": {\"code\": 401,\"message\": \"Restart Successful\"},\"common-header\": {\"timestamp\": \"2017-07-18T16:52:06.186Z\",\"api-ver\": \"2.01\",\"request-id\": \"baf5ba32-6b8c-430c-a91b-02d2c0ba3064\",\"sub-request-id\": \"1\",\"flags\": {\"ttl\": 600}},\"payload\": \"{\\\"vm-id\\\":\\\"http://135.25.246.131:8774/v2/81fc2bc61f974de1b5a49e8c2ec090bb/servers/75dce20c-97f9-454d-abcc-aa904a33df5a\\\",\\\"tenant-id\\\":\\\"test2\\\"}\"}}}";
- AppcLcmDmaapWrapper restartResponse = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- operation.incomingMessage(restartResponse);
- assertEquals(PolicyResult.FAILURE, operation.getResult());
- }
-
- @Test
- public void testIncomingAllVnfFailureMessage() {
- policy.setRecipe("RESTART");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"version\": \"2.0\",\"rpc-name\": \"Restart\",\"correlation-id\": \"baf5ba32-6b8c-430c-a91b-02d2c0ba3064-1\",\"type\": \"response\",\"body\": {\"output\": {\"status\": {\"code\": 501,\"message\": \"Restart Successful\"},\"common-header\": {\"timestamp\": \"2017-07-18T16:52:06.186Z\",\"api-ver\": \"2.01\",\"request-id\": \"baf5ba32-6b8c-430c-a91b-02d2c0ba3064\",\"sub-request-id\": \"1\",\"flags\": {\"ttl\": 600}},\"payload\": \"{\\\"vm-id\\\":\\\"http://135.25.246.131:8774/v2/81fc2bc61f974de1b5a49e8c2ec090bb/servers/75dce20c-97f9-454d-abcc-aa904a33df5a\\\",\\\"tenant-id\\\":\\\"test2\\\"}\"}}}";
- AppcLcmDmaapWrapper restartResponse = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- /* Send in ALL failure messages */
- for (int i = 0; i < 5; i++) {
- operation.incomingMessage(restartResponse);
- assertNull(operation.getResult());
- }
-
- /* Send in an operation failure */
- restartResponse.getBody().getOutput().getStatus().setCode(401);
- operation.incomingMessage(restartResponse);
-
- /* Because every VM failed in the VNF, it should be failure result */
- assertEquals(PolicyResult.FAILURE, operation.getResult());
- }
-
- @Test
- public void testIncomingPartialVnfFailureMessage() {
- policy.setRecipe("RESTART");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
-
- String lcmRespJson = "{\"version\": \"2.0\",\"rpc-name\": \"Restart\",\"correlation-id\": \"baf5ba32-6b8c-430c-a91b-02d2c0ba3064-1\",\"type\": \"response\",\"body\": {\"output\": {\"status\": {\"code\": 500,\"message\": \"Restart Successful\"},\"common-header\": {\"timestamp\": \"2017-07-18T16:52:06.186Z\",\"api-ver\": \"2.01\",\"request-id\": \"baf5ba32-6b8c-430c-a91b-02d2c0ba3064\",\"sub-request-id\": \"1\",\"flags\": {\"ttl\": 600}},\"payload\": \"{\\\"vm-id\\\":\\\"http://135.25.246.131:8774/v2/81fc2bc61f974de1b5a49e8c2ec090bb/servers/75dce20c-97f9-454d-abcc-aa904a33df5a\\\",\\\"tenant-id\\\":\\\"test2\\\"}\"}}}";
- AppcLcmDmaapWrapper restartResponse = Serialization.gson.fromJson(lcmRespJson, AppcLcmDmaapWrapper.class);
-
- /* Send in several partial success messages */
- for (int i = 0; i < 5; i++) {
- operation.incomingMessage(restartResponse);
- assertNull(operation.getResult());
- }
-
- /* Change status to partial failure */
- restartResponse.getBody().getOutput().getStatus().setCode(501);
-
- /* Send in several partial failures messages */
- for (int i = 0; i < 5; i++) {
- operation.incomingMessage(restartResponse);
- assertNull(operation.getResult());
- }
-
- /* Send in an operation failure */
- restartResponse.getBody().getOutput().getStatus().setCode(401);
- operation.incomingMessage(restartResponse);
-
- /*
- * Only a subset of VMs failed in the VNF so the
- * result will be failure_exception
- */
- assertEquals(PolicyResult.FAILURE_EXCEPTION, operation.getResult());
- }
-
- /* ===================================================================== */
-
- /*
- * these tests are for validating the A&AI subtag and target in an onset
- */
-
- @Test
- public void testValidAaiSubtag() {
- transaction.setNotificationMessage(null);
- VirtualControlLoopEvent validEvent = new VirtualControlLoopEvent();
- validEvent.setTarget("vserver.vserver-name");
- validEvent.getAai().put(AppcLcmOperation.DCAE_CLOSEDLOOP_DISABLED_FIELD, "false");
- validEvent.getAai().put(validEvent.getTarget(), "VM001");
- assertTrue(AppcLcmOperation.isAaiValid(transaction, validEvent));
- assertNull(transaction.getNotificationMessage());
- }
-
- @Test
- public void testNoAaiSubtag() {
- transaction.setNotificationMessage(null);
- VirtualControlLoopEvent noAaiTag = new VirtualControlLoopEvent();
- noAaiTag.setAai(null);
- assertFalse(AppcLcmOperation.isAaiValid(transaction, noAaiTag));
- assertEquals("No A&AI Subtag", transaction.getNotificationMessage());
- }
-
- @Test
- public void testNoClosedLoopDisabledInAai() {
- transaction.setNotificationMessage(null);
- VirtualControlLoopEvent invalidEvent = new VirtualControlLoopEvent();
- assertFalse(AppcLcmOperation.isAaiValid(transaction, invalidEvent));
- assertEquals(AppcLcmOperation.DCAE_CLOSEDLOOP_DISABLED_FIELD
- + " information missing", transaction.getNotificationMessage());
- }
-
- @Test
- public void testClosedLoopDisabledInAai() {
- transaction.setNotificationMessage(null);
- VirtualControlLoopEvent invalidEvent = new VirtualControlLoopEvent();
- invalidEvent.getAai().put(AppcLcmOperation.DCAE_CLOSEDLOOP_DISABLED_FIELD, "true");
- assertFalse(AppcLcmOperation.isAaiValid(transaction, invalidEvent));
- assertEquals(AppcLcmOperation.DCAE_CLOSEDLOOP_DISABLED_FIELD
- + " is set to true", transaction.getNotificationMessage());
- }
-
- @Test
- public void testTargetMismatchInAai() {
- transaction.setNotificationMessage(null);
- VirtualControlLoopEvent validEvent = new VirtualControlLoopEvent();
- validEvent.setTarget("vserver.vserver-name");
- validEvent.getAai().put(AppcLcmOperation.DCAE_CLOSEDLOOP_DISABLED_FIELD, "false");
- assertFalse(AppcLcmOperation.isAaiValid(transaction, validEvent));
- assertEquals("target field invalid - must have corresponding AAI value",
- transaction.getNotificationMessage());
- }
-
- @Test
- public void testTimeout() {
- policy.setRecipe("RESTART");
- policy.getTarget().setType(TargetType.VNF);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
- operation.timeout();
- assertEquals(PolicyResult.FAILURE_TIMEOUT, operation.getResult());
- }
-
- @Test
- public void testIncomingAbatedEvent() {
- transaction.setNotificationMessage(null);
- VirtualControlLoopEvent validEvent = new VirtualControlLoopEvent();
- validEvent.setTarget("vserver.vserver-name");
- validEvent.getAai().put(AppcLcmOperation.DCAE_CLOSEDLOOP_DISABLED_FIELD, "false");
- validEvent.setClosedLoopEventStatus(ControlLoopEventStatus.ABATED);
- operation = new AppcLcmOperation(transaction, policy, event, 1);
- operation.incomingMessage(validEvent);
- assertEquals(PolicyResult.SUCCESS, operation.getResult());
- }
-}
diff --git a/controlloop/m2/appclcm/src/test/java/model/AppcLcmResponseCodeTest.java b/controlloop/m2/appclcm/src/test/java/model/AppcLcmResponseCodeTest.java
deleted file mode 100644
index 327f8c5d4..000000000
--- a/controlloop/m2/appclcm/src/test/java/model/AppcLcmResponseCodeTest.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * appclcm
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import org.junit.Test;
-import org.onap.policy.m2.appclcm.model.AppcLcmResponseCode;
-
-
-public class AppcLcmResponseCodeTest {
-
- @Test
- public void test() {
- assertEquals(AppcLcmResponseCode.ACCEPTED, AppcLcmResponseCode.toResponseValue(100));
- assertEquals(AppcLcmResponseCode.ERROR, AppcLcmResponseCode.toResponseValue(200));
- assertEquals(AppcLcmResponseCode.REJECT, AppcLcmResponseCode.toResponseValue(300));
- assertEquals(AppcLcmResponseCode.SUCCESS, AppcLcmResponseCode.toResponseValue(400));
- assertEquals(AppcLcmResponseCode.FAILURE, AppcLcmResponseCode.toResponseValue(450));
- assertEquals(AppcLcmResponseCode.PARTIAL_SUCCESS, AppcLcmResponseCode.toResponseValue(500));
- assertEquals(AppcLcmResponseCode.PARTIAL_FAILURE, AppcLcmResponseCode.toResponseValue(501));
- assertNull(AppcLcmResponseCode.toResponseValue(600));
- }
-}
diff --git a/controlloop/m2/base/pom.xml b/controlloop/m2/base/pom.xml
deleted file mode 100644
index 50c4a0131..000000000
--- a/controlloop/m2/base/pom.xml
+++ /dev/null
@@ -1,88 +0,0 @@
-<?xml version="1.0"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>m2</artifactId>
- <version>1.7.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>base</artifactId>
- <name>Experimental Control Loop Model - base</name>
-
- <dependencies>
-
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>guard</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.common</groupId>
- <artifactId>eventmanager</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions</groupId>
- <artifactId>model-yaml</artifactId>
- <version>${policy.models.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
- <artifactId>events</artifactId>
- <version>${policy.models.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
- <artifactId>aai</artifactId>
- <version>${policy.models.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
- <artifactId>sdc</artifactId>
- <version>${policy.models.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-management</artifactId>
- <version>${version.policy.drools-pdp}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <scope>provided</scope>
- </dependency>
-
- </dependencies>
-
-</project>
diff --git a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Actor.java b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Actor.java
deleted file mode 100644
index 00eb181fc..000000000
--- a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Actor.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base;
-
-import org.onap.policy.controlloop.ControlLoopEvent;
-import org.onap.policy.controlloop.policy.Policy;
-
-/**
- * This is the 'Actor' interface -- objects implementing this interface
- * are placed within the 'nameToActor' table within class 'Transaction'.
- * All of the instances are created and inserted in the table at initialization
- * time, and are located using the 'Policy.actor' field as a key.
- */
-public interface Actor {
- /**
- * Return the name associated with this Actor.
- *
- * @return the name associated with this Actor (as it appears in the 'yaml')
- */
- String getName();
-
- /**
- * Create an operation for this actor, based on the supplied policy.
- *
- * @param transaction the transaction the operation is running under
- * @param policy the policy associated with this operation
- * @param onset the initial onset event that triggered the transaction
- * @param attempt this value starts at 1, and is incremented for each retry
- * @return the Operation instance
- */
- Operation createOperation(
- Transaction transaction, Policy policy, ControlLoopEvent onset,
- int attempt);
-}
diff --git a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/GuardAdjunct.java b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/GuardAdjunct.java
deleted file mode 100644
index d3675ae12..000000000
--- a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/GuardAdjunct.java
+++ /dev/null
@@ -1,122 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base;
-
-import java.io.Serializable;
-import org.onap.policy.controlloop.ControlLoopOperation;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.guard.GuardContext;
-
-/**
- * This adjunct class provides a way of accessing 'GuardContext' for any
- * operations that use 'guard'. It needs to be created and inserted into the
- * transaction 'adjunct' list prior to creating any operations that use it.
- *
- * <p>TBD: Serialization will need to factor in the fact that 'GuardContext'
- * is a shared object.
- */
-public class GuardAdjunct implements Transaction.Adjunct, Serializable {
- private static final long serialVersionUID = 1L;
-
- // the associated transaction
- private Transaction transaction = null;
-
- // the 'GuardContext' instance
- private GuardContext context = null;
-
- /**
- * Constructor -- just in case 'getInstance()' is used to create this
- * instance (in which case 'guard' will not be used).
- */
- public GuardAdjunct() {
- // This comment is here to keep SONAR from getting upset
- }
-
- /**
- * This method is called to create the adjunct, and insert it into the
- * transaction.
- *
- * @param transaction the associated transaction
- * @param context the GuardContext derived from the controller properties
- */
- public static void create(Transaction transaction, GuardContext context) {
- GuardAdjunct ga = new GuardAdjunct();
- ga.transaction = transaction;
- ga.context = context;
- transaction.putAdjunct(ga);
- }
-
- /**
- * Return the GuardContext instance.
- *
- * @return the GuardContext instance
- */
- public GuardContext get() {
- return context;
- }
-
- /**
- * Do an asynchronous 'guard' query, and place the result in Drools memory.
- *
- * @param policy the policy associated with the operation
- * @param target the target in a form meaningful to 'guard'
- * @param requestId the transaction's request id
- * @return 'true' if we have a 'GuardContext', and a response is expected,
- * 'false' if 'guard' was not used, and should be skipped
- */
- public boolean asyncQuery(Policy policy, String target, String requestId) {
- if (context != null) {
- // note that we still return 'true' as long as we have a
- // 'GuardContext', even when 'guard.disabled' is set -- as long
- // as there is an asynchronous response coming
- context.asyncQuery(transaction.getWorkingMemory(),
- policy.getActor(),
- policy.getRecipe(),
- target,
- requestId,
- transaction.getClosedLoopControlName());
- return true;
- }
- return false;
- }
-
- /**
- * Create a DB entry describing this operation.
- *
- * @param op the history entry associated with the operation
- * @param target the same target that was passed on the 'asyncQuery' call
- */
- public void asyncCreateDbEntry(ControlLoopOperation op, String target) {
- if (context != null) {
- context.asyncCreateDbEntry(
- op.getStart(),
- op.getEnd(),
- transaction.getClosedLoopControlName(),
- op.getActor(),
- op.getOperation(),
- target,
- transaction.getRequestId().toString(),
- op.getSubRequestId(),
- op.getMessage(),
- op.getOutcome());
- }
- }
-}
diff --git a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/OnsetAdapter.java b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/OnsetAdapter.java
deleted file mode 100644
index 3c164cfd2..000000000
--- a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/OnsetAdapter.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base;
-
-import java.io.Serializable;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
-import org.onap.policy.controlloop.ControlLoopEvent;
-import org.onap.policy.controlloop.ControlLoopNotification;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/*
- * This class maps the class of an incoming ONSET message into the
- * appropriate adapter. The default adapter is included here as well.
- */
-public class OnsetAdapter implements Serializable {
- private static final long serialVersionUID = 1L;
- private static Logger logger = LoggerFactory.getLogger(OnsetAdapter.class);
-
- // table mapping onset message class to 'OnsetAdapter' instance
- private static Map<Class<?>, OnsetAdapter> map = new ConcurrentHashMap<>();
-
- /**
- * This method is called to add an entry to the table.
- *
- * @param clazz the class of the ONSET message
- * @param value an instance of 'OnsetAdapter' that should be
- * associated with 'clazz'
- */
- public static void register(Class<?> clazz, OnsetAdapter value) {
- // only create an entry if one doesn't already exist
- map.putIfAbsent(clazz, value);
- }
-
- /**
- * Map an incoming event's class into the appropriate 'OnsetAdapter'
- * to use.
- *
- * @param event this is the onset event
- * @return an adapter appropriate for the 'event'
- */
- public static OnsetAdapter get(ControlLoopEvent event) {
- Class<?> clazz = event.getClass();
- OnsetAdapter rval = map.get(clazz);
- if (rval != null) {
- return rval;
- }
-
- // This algorithm below is generic, in the sense that it can be used
- // to find a "best match" for any class out of a set of classes
- // using the class inheritance relationships. In the general case,
- // it is possible that there could be multiple best matches, but this
- // can only happen if all of the matching keys are interfaces,
- // except perhaps one. If there are multiple matches,
- // one will be chosen "at random".
-
- // we need to look for the best match of 'clazz'
- HashSet<Class<?>> matches = new HashSet<>();
- Class<?> chosenMatch = null;
- synchronized (map) {
- for (Class<?> possibleMatch : map.keySet()) {
- if (possibleMatch.isAssignableFrom(clazz)) {
- // we have a match -- see if it is the best match
- boolean add = true;
- for (Class<?> match : new ArrayList<Class<?>>(matches)) {
- if (match.isAssignableFrom(possibleMatch)) {
- // 'possibleMatch' is a better match than 'match'
- matches.remove(match);
- } else if (possibleMatch.isAssignableFrom(match)) {
- // we already have a better match
- add = false;
- break;
- }
- }
- if (add) {
- matches.add(possibleMatch);
- }
- }
- }
- if (!matches.isEmpty()) {
- // we have at least one match
- chosenMatch = matches.iterator().next();
- rval = map.get(chosenMatch);
-
- // add this entry back into the table -- this means we can
- // now use this cached entry, and don't have to run through
- // the algorithm again for this class
- map.put(clazz, rval);
- }
- }
-
- if (matches.isEmpty()) {
- logger.error("no matches for {}", clazz);
- } else if (matches.size() != 1) {
- logger.warn("multiple matches for {}: {} -- chose {}",
- clazz, matches, chosenMatch);
- }
-
- return rval;
- }
-
- /* ============================================================ */
-
- // the following code creates an initial entry in the table
- private static OnsetAdapter instance = new OnsetAdapter();
-
- static {
- register(ControlLoopEvent.class, instance);
- }
-
- // the new 'ControlLoopNotification' is abstract
- public static class BaseControlLoopNotification extends ControlLoopNotification {
- private static final long serialVersionUID = 1L;
-
- BaseControlLoopNotification(ControlLoopEvent event) {
- super(event);
- }
- }
-
- /**
- * This method is what all of the fuss is about -- we want to create
- * a 'ControlLoopNotification' instance compatible with the type of the
- * 'event' argument. This is the default implementation -- subclasses of
- * 'ControlLoopEvent' may have entries in the table that are specialized
- * generate objects that are a subclass of 'ControlLoopNotification'
- * appropriate for the transaction type.
- *
- * @param event this is the event in question
- * @return a 'ControlLoopNotification' instance based upon this event
- */
- public ControlLoopNotification createNotification(ControlLoopEvent event) {
- return new BaseControlLoopNotification(event);
- }
-}
diff --git a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Operation.java b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Operation.java
deleted file mode 100644
index c8ee901c3..000000000
--- a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Operation.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base;
-
-import java.io.Serializable;
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.ControlLoopOperation;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-
-/**
- * This is the 'Operation' interface -- each object implementing this
- * interface exists for the duration of a single operation.
- *
- * <p>An operation typically includes some of the following steps:
- * 1) Acquiring locks
- * 2) 'Guard' query to see if the operation should proceed (some operations)
- * 3) Outgoing request (usually using DMAAP or UEB, but possibly HTTP or HTTPS)
- * 4) Incoming response
- */
-public interface Operation extends Serializable {
- /**
- * This method is used as part of sending out the request. In the case of
- * DMAAP or UEB interfaces, the method returns the message to be sent,
- * but leaves it to the Drools code to do the actual sending. In the case
- * of HTTP or HTTPS (e.g. AOTS), the method itself may run the operation in
- * a different thread.
- *
- * @return an object containing the message
- * @throws ControlLoopException if it occurs
- */
- Object getRequest() throws ControlLoopException;
-
- /**
- * Return the 'Policy' instance associated with this operation.
- *
- * @return the 'Policy' instance associated with this operation
- */
- Policy getPolicy();
-
- /**
- * The 'state' of an operation is also the state of the 'Transaction'
- * instance, while that operation is active. The state is often referenced
- * in the 'when' clause of Drools rules, with the rules resembling state
- * transition routines (state + event -> operation). In order to avoid
- * confusion, the state names should be unique across all operations --
- * this is managed by having each state name begin with 'ACTOR.', where
- * 'ACTOR' is the actor associated with the operation.
- *
- * @return a string value indicating the state of the operation
- */
- String getState();
-
- /**
- * This is set to '1' for the initial attempt, and is incremented by one
- * for each retry. Note that a new 'Operation' instance is created for
- * each attempt.
- *
- * @return '1' for the initial attempt of an operation, and incremented
- * for each retry
- */
- int getAttempt();
-
- /**
- * Return the result of the operation.
- *
- * @return the result of the operation
- * ('null' if the operation is still in progress)
- */
- PolicyResult getResult();
-
- /**
- * Return the message associated with the completed operation.
- *
- * @return the message associated with the completed operation
- * ('null' if the operation is still in progress)
- */
- String getMessage();
-
- /**
- * An incoming message is being delivered to the operation. The type of
- * the message is operation-dependent, and an operation will typically
- * understand only one or two message types, and ignore the rest. The
- * calling Drools code is written to assume that the transaction has been
- * modified -- frequently, a state transition occurs as a result of
- * the message.
- *
- * @param object the incoming message
- */
- void incomingMessage(Object object);
-
- /**
- * The operation has timed out. This typically results in the operation
- * completing, but that is not enforced.
- */
- void timeout();
-
- /**
- * This method is called on every operation right after its history
- * entry has been completed. It gives the operation a chance to do some
- * processing based on this entry (e.g. create a 'guard' entry in the DB).
- *
- * @param histEntry the history entry for this particular operation
- */
- default void histEntryCompleted(ControlLoopOperation histEntry) {
- }
-}
diff --git a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Transaction.java b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Transaction.java
deleted file mode 100644
index f964e207e..000000000
--- a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Transaction.java
+++ /dev/null
@@ -1,712 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base;
-
-import java.io.Serializable;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.ServiceLoader;
-import java.util.UUID;
-import lombok.Getter;
-import org.drools.core.WorkingMemory;
-import org.kie.api.runtime.rule.FactHandle;
-import org.onap.policy.controlloop.ControlLoopEvent;
-import org.onap.policy.controlloop.ControlLoopNotification;
-import org.onap.policy.controlloop.ControlLoopNotificationType;
-import org.onap.policy.controlloop.ControlLoopOperation;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.controlloop.policy.FinalResult;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/*
- * Each instance of this class corresonds to a transaction that is in
- * progress. While active, it resides within Drools memory.
- */
-
-public class Transaction implements Serializable {
-
- private static Logger logger = LoggerFactory.getLogger(Transaction.class);
-
- // This table maps 'actor' names to objects implementing the
- // 'Actor' interface. 'ServiceLoader' is used to locate and create
- // these objects, and populate the table.
- private static Map<String, Actor> nameToActor = new HashMap<>();
-
- static {
- // use 'ServiceLoader' to locate all of the 'Actor' implementations
- for (Actor actor :
- ServiceLoader.load(Actor.class, Actor.class.getClassLoader())) {
- logger.debug("Actor: {}, {}", actor.getName(), actor.getClass());
- nameToActor.put(actor.getName(), actor);
- }
- }
-
- private static final long serialVersionUID = 4389211793631707360L;
-
- // Drools working memory containing this transaction
- @Getter
- private transient WorkingMemory workingMemory;
-
- // a service-identifier specified on the associated onset message
- @Getter
- private String closedLoopControlName;
-
- // identifies this transaction
- @Getter
- private UUID requestId;
-
- // the decoded YAML file for the policy
- private ControlLoopPolicy policy;
-
- // the initial incoming event
- private ControlLoopEvent onset = null;
-
- // operations specific to the type of 'event'
- private OnsetAdapter onsetAdapter = null;
-
- // the current (or most recent) policy in effect
- @Getter
- private Policy currentPolicy = null;
-
- // the operation currently in progress
- @Getter
- private Operation currentOperation = null;
-
- // a history entry being constructed that is associated with the
- // currently running operation
- private ControlLoopOperation histEntry = null;
-
- // a list of completed history entries
- @Getter
- private List<ControlLoopOperation> history = new LinkedList<>();
-
- // when the transaction completes, this is the final transaction result
- @Getter
- private FinalResult finalResult = null;
-
- //message, if any, associated with the result of this operation
- private String message = null;
-
- // this table maps a class name into the associated adjunct
- private Map<Class<?>, Adjunct> adjuncts = new HashMap<>();
-
- /**
- * Constructor - initialize a 'Transaction' instance
- * (typically invoked from 'Drools').
- *
- * @param workingMemory Drools working memory containing this Transaction
- * @param closedLoopControlName a string identifying the associated service
- * @param requestId uniquely identifies this transaction
- * @param policy decoded YAML file containing the policy
- */
- public Transaction(
- WorkingMemory workingMemory,
- String closedLoopControlName,
- UUID requestId,
- ControlLoopPolicy policy) {
-
- logger.info("Transaction constructor");
- this.workingMemory = workingMemory;
- this.closedLoopControlName = closedLoopControlName;
- this.requestId = requestId;
- this.policy = policy;
- }
-
- /**
- * Return a string indicating the current state of this transaction.
- * If there is an operation in progress, the state indicates the operation
- * state. Otherwise, the state is 'COMPLETE'.
- *
- * @return a string indicating the current state of this transaction
- */
- public String getState() {
- return currentOperation == null
- ? "COMPLETE" : currentOperation.getState();
- }
-
- /**
- * Return 'true' if the transaction has completed, and the final result
- * indicates failure.
- *
- * @return 'true' if the transaction has completed, and the final result
- * indicates failure
- */
- public boolean finalResultFailure() {
- return FinalResult.FINAL_SUCCESS != finalResult
- && FinalResult.FINAL_OPENLOOP != finalResult
- && finalResult != null;
- }
-
- /**
- * Return the overall policy timeout value as a String that can be used
- * in a Drools timer.
- *
- * @return the overall policy timeout value as a String that can be used
- * in a Drools timer
- */
- public String getTimeout() {
- return String.valueOf(policy.getControlLoop().getTimeout()) + "s";
- }
-
- /**
- * Return the current operation timeout value as a String that can be used
- * in a Drools timer.
- *
- * @return the current operation timeout value as a String that can be used
- * in a Drools timer
- */
- public String getOperationTimeout() {
- return String.valueOf(currentPolicy.getTimeout()) + "s";
- }
-
- /**
- * Let Drools know the transaction has been modified.
- *
- * <p>It is not necessary for Java code to call this method when an incoming
- * message is received for an operation, or an operation timeout occurs --
- * the Drools code has been written with the assumption that the transaction
- * is modified in these cases. Instead, this method should be called when
- * some type of internal occurrence results in a state change, such as when
- * an operation acquires a lock after initially being blocked.
- */
- public void modify() {
- FactHandle handle = workingMemory.getFactHandle(this);
- if (handle != null) {
- workingMemory.update(handle, this);
- }
- }
-
- /**
- * Set the initial 'onset' event that started this transaction.
- *
- * @param event the initial 'onset' event
- */
- public void setControlLoopEvent(ControlLoopEvent event) {
- if (onset != null) {
- logger.error("'Transaction' received unexpected event");
- return;
- }
-
- onset = event;
-
- // fetch associated 'OnsetAdapter'
- onsetAdapter = OnsetAdapter.get(onset);
-
- // check trigger policy type
- if (isOpenLoop(policy.getControlLoop().getTrigger_policy())) {
- // no operation is needed for open loops
- finalResult = FinalResult.FINAL_OPENLOOP;
- modify();
- } else {
- // fetch current policy
- setPolicyId(policy.getControlLoop().getTrigger_policy());
- }
- }
-
- /**
- * Validates the onset by ensuring fields that are required
- * for processing are included in the onset. The fields needed
- * include the requestId, targetType, and target.
- *
- * @param onset the initial message that triggers processing
- */
- public boolean isControlLoopEventValid(ControlLoopEvent onset) {
- if (onset.getRequestId() == null) {
- this.message = "No requestID";
- return false;
- } else if (onset.getTargetType() == null) {
- this.message = "No targetType";
- return false;
- } else if (onset.getTarget() == null || onset.getTarget().isEmpty()) {
- this.message = "No target field";
- return false;
- }
- return true;
- }
-
- /**
- * Create a 'ControlLoopNotification' from the specified event. Note thet
- * the type of the initial 'onset' event is used to determine the type
- * of the 'ControlLoopNotification', rather than the event passed to the
- * method.
- *
- * @param event the event used to generate the notification
- * (if 'null' is passed, the 'onset' event is used)
- * @return the created 'ControlLoopNotification' (or subclass) instance
- */
- public ControlLoopNotification getNotification(ControlLoopEvent event) {
- ControlLoopNotification notification =
- onsetAdapter.createNotification(event == null ? this.onset : event);
-
- // include entire history
- notification.setHistory(new ArrayList<>(history));
-
- return notification;
- }
-
- /**
- * This method is called when additional incoming messages are received
- * for the transaction. Messages are routed to the current operation,
- * any results are processed, and a notification may be returned to
- * the caller.
- *
- * @param object an incoming message, which should be meaningful to the
- * operation currently in progress
- * @return a notification message if the operation completed,
- * or 'null' if it is still in progress
- */
- public ControlLoopNotification incomingMessage(Object object) {
- ControlLoopNotification notification = null;
- if (currentOperation != null) {
- currentOperation.incomingMessage(object);
- notification = processResult(currentOperation.getResult());
- } else {
- logger.error("'Transaction' received unexpected message: {}", object);
- }
- return notification;
- }
-
- /**
- * This method is called from Drools when the current operation times out.
- *
- * @return a notification message if there is an operation in progress,
- * or 'null' if not
- */
- public ControlLoopNotification timeout() {
- ControlLoopNotification notification = null;
- if (currentOperation != null) {
- // notify the current operation
- currentOperation.timeout();
-
- // process the timeout within the transaction
- notification = processResult(currentOperation.getResult());
- } else {
- logger.error("'Transaction' received unexpected timeout");
- }
- return notification;
- }
-
- /**
- * This method is called from Drools during a control loop timeout
- * to ensure the correct final notification is sent.
- */
- public void clTimeout() {
- this.finalResult = FinalResult.FINAL_FAILURE_TIMEOUT;
- message = "Control Loop timed out";
- currentOperation = null;
- }
-
- /**
- * This method is called from Drools to generate a notification message
- * when an operation is started.
- *
- * @return an initial notification message if there is an operation in
- * progress, or 'null' if not
- */
- public ControlLoopNotification initialOperationNotification() {
- if (currentOperation == null || histEntry == null) {
- return null;
- }
-
- ControlLoopNotification notification =
- onsetAdapter.createNotification(onset);
- notification.setNotification(ControlLoopNotificationType.OPERATION);
- notification.setMessage(histEntry.toHistory());
- notification.setHistory(new LinkedList<>());
- for (ControlLoopOperation clo : history) {
- if (histEntry.getOperation().equals(clo.getOperation())
- && histEntry.getActor().equals(clo.getActor())) {
- notification.getHistory().add(clo);
- }
- }
- return notification;
- }
-
- /**
- * Return a final notification message for the entire transaction.
- *
- * @return a final notification message for the entire transaction,
- * or 'null' if we don't have a final result yet
- */
- public ControlLoopNotification finalNotification() {
- if (finalResult == null) {
- return null;
- }
-
- ControlLoopNotification notification =
- onsetAdapter.createNotification(onset);
- switch (finalResult) {
- case FINAL_SUCCESS:
- notification.setNotification(
- ControlLoopNotificationType.FINAL_SUCCESS);
- break;
- case FINAL_OPENLOOP:
- notification.setNotification(
- ControlLoopNotificationType.FINAL_OPENLOOP);
- break;
- default:
- notification.setNotification(
- ControlLoopNotificationType.FINAL_FAILURE);
- notification.setMessage(this.message);
- break;
- }
- notification.setHistory(history);
- return notification;
- }
-
- /**
- * Return a 'ControlLoopNotification' instance describing the current operation error.
- *
- * @return a 'ControlLoopNotification' instance describing the current operation error
- */
- public ControlLoopNotification processError() {
- ControlLoopNotification notification = null;
- if (currentOperation != null) {
- // process the error within the transaction
- notification = processResult(currentOperation.getResult());
- }
- return notification;
- }
-
- /**
- * Update the state of the transaction based upon the result of an operation.
- *
- * @param result if not 'null', this is the result of the current operation
- * (if 'null', the operation is still in progress,
- * and no changes are made)
- * @return if not 'null', this is a notification message that should be
- * sent to RUBY
- */
- private ControlLoopNotification processResult(PolicyResult result) {
- if (result == null) {
- modify();
- return null;
- }
- String nextPolicy = null;
-
- ControlLoopOperation saveHistEntry = histEntry;
- completeHistEntry(result);
-
- final ControlLoopNotification notification = processResultHistEntry(saveHistEntry, result);
-
- // If there is a message from the operation then we set it to be
- // used by the control loop notifications
- message = currentOperation.getMessage();
-
- // set the value 'nextPolicy' based upon the result of the operation
- switch (result) {
- case SUCCESS:
- nextPolicy = currentPolicy.getSuccess();
- break;
-
- case FAILURE:
- nextPolicy = processResultFailure();
- break;
-
- case FAILURE_TIMEOUT:
- nextPolicy = currentPolicy.getFailure_timeout();
- message = "Operation timed out";
- break;
-
- case FAILURE_RETRIES:
- nextPolicy = currentPolicy.getFailure_retries();
- message = "Control Loop reached failure retry limit";
- break;
-
- case FAILURE_EXCEPTION:
- nextPolicy = currentPolicy.getFailure_exception();
- break;
-
- case FAILURE_GUARD:
- nextPolicy = currentPolicy.getFailure_guard();
- break;
-
- default:
- break;
- }
-
- if (nextPolicy != null) {
- finalResult = FinalResult.toResult(nextPolicy);
- if (finalResult == null) {
- // it must be the next state
- logger.debug("advancing to next operation");
- setPolicyId(nextPolicy);
- } else {
- logger.debug("moving to COMPLETE state");
- currentOperation = null;
- }
- } else {
- logger.debug("doing retry with current actor");
- }
-
- modify();
- return notification;
- }
-
- // returns a notification message based on the history entry
- private ControlLoopNotification processResultHistEntry(ControlLoopOperation hist, PolicyResult result) {
- if (hist == null) {
- return null;
- }
-
- // generate notification, containing operation history
- ControlLoopNotification notification = onsetAdapter.createNotification(onset);
- notification.setNotification(
- result == PolicyResult.SUCCESS
- ? ControlLoopNotificationType.OPERATION_SUCCESS
- : ControlLoopNotificationType.OPERATION_FAILURE);
- notification.setMessage(hist.toHistory());
-
- // include the subset of history that pertains to this
- // actor and operation
- notification.setHistory(new LinkedList<>());
- for (ControlLoopOperation clo : history) {
- if (hist.getOperation().equals(clo.getOperation())
- && hist.getActor().equals(clo.getActor())) {
- notification.getHistory().add(clo);
- }
- }
-
- return notification;
- }
-
- // returns the next policy if the current operation fails
- private String processResultFailure() {
- String nextPolicy = null;
- int attempt = currentOperation.getAttempt();
- if (attempt <= currentPolicy.getRetry()) {
- // operation failed, but there are retries left
- Actor actor = nameToActor.get(currentPolicy.getActor());
- if (actor != null) {
- attempt += 1;
- logger.debug("found Actor, attempt {}", attempt);
- currentOperation =
- actor.createOperation(this, currentPolicy, onset, attempt);
- createHistEntry();
- } else {
- logger.error("'Transaction' can't find actor {}", currentPolicy.getActor());
- }
- } else {
- // operation failed, and no retries (or no retries left)
- nextPolicy = (attempt == 1
- ? currentPolicy.getFailure()
- : currentPolicy.getFailure_retries());
- logger.debug("moving to policy {}", nextPolicy);
- }
- return nextPolicy;
- }
-
- /**
- * Create a history entry at the beginning of an operation, and store it
- * in the 'histEntry' instance variable.
- */
- private void createHistEntry() {
- histEntry = new ControlLoopOperation();
- histEntry.setActor(currentPolicy.getActor());
- histEntry.setOperation(currentPolicy.getRecipe());
- histEntry.setTarget(currentPolicy.getTarget().toString());
- histEntry.setSubRequestId(String.valueOf(currentOperation.getAttempt()));
-
- // histEntry.end - we will set this one later
- // histEntry.outcome - we will set this one later
- // histEntry.message - we will set this one later
- }
-
- /**
- * Finish up the history entry at the end of an operation, and add it
- * to the history list.
- *
- * @param result this is the result of the operation, which can't be 'null'
- */
- private void completeHistEntry(PolicyResult result) {
- if (histEntry == null) {
- return;
- }
-
- // append current entry to history
- histEntry.setEnd(Instant.now());
- histEntry.setOutcome(result.toString());
- histEntry.setMessage(currentOperation.getMessage());
- history.add(histEntry);
-
- // give current operation a chance to act on it
- currentOperation.histEntryCompleted(histEntry);
- logger.debug("histEntry = {}", histEntry);
- histEntry = null;
- }
-
- /**
- * Look up the identifier for the next policy, and prepare to start that
- * operation.
- *
- * @param id this is the identifier associated with the policy
- */
- private void setPolicyId(String id) {
- currentPolicy = null;
- currentOperation = null;
-
- // search through the policies for a matching 'id'
- for (Policy tmp : policy.getPolicies()) {
- if (id.equals(tmp.getId())) {
- // found a match
- currentPolicy = tmp;
- break;
- }
- }
-
- if (currentPolicy != null) {
- // locate the 'Actor' associated with 'currentPolicy'
- Actor actor = nameToActor.get(currentPolicy.getActor());
- if (actor != null) {
- // found the associated 'Actor' instance
- currentOperation =
- actor.createOperation(this, currentPolicy, onset, 1);
- createHistEntry();
- } else {
- logger.error("'Transaction' can't find actor {}", currentPolicy.getActor());
- }
- } else {
- logger.error("Transaction' can't find policy {}", id);
- }
-
- if (currentOperation == null) {
-
- // either we couldn't find the actor or the operation --
- // the transaction fails
- finalResult = FinalResult.FINAL_FAILURE;
- }
- }
-
- private boolean isOpenLoop(String policyId) {
- return FinalResult.FINAL_OPENLOOP.name().equalsIgnoreCase(policyId);
- }
-
- /**
- * This method sets the message for a control loop notification
- * in the case where a custom message wants to be sent due to
- * error processing, etc.
- *
- * @param message the message to be set for the control loop notification
- */
- public void setNotificationMessage(String message) {
- this.message = message;
- }
-
- /**
- * Return the notification message of this transaction.
- *
- * @return the notification message of this transaction
- */
- public String getNotificationMessage() {
- return this.message;
- }
-
- /* ============================================================ */
-
- /**
- * Subclasses of 'Adjunct' provide data and methods to support one or
- * more Actors/Operations, but are stored within the 'Transaction'
- * instance.
- */
- public static interface Adjunct extends Serializable {
- /**
- * Called when an adjunct is automatically created as a result of
- * a 'getAdjunct' call.
- *
- * @param transaction the transaction containing the adjunct
- */
- public default void init(Transaction transaction) {
- }
-
- /**
- * Called for each adjunct when the transaction completes, and is
- * removed from Drools memory. Any adjunct-specific cleanup can be
- * done at this point (e.g. freeing locks).
- */
- public default void cleanup(Transaction transaction) {
- }
- }
-
- /**
- * This is a method of class 'Transaction', and returns an adjunct of
- * the specified class (it is created if it doesn't exist).
- *
- * @param clazz this is the class of the adjunct
- * @return an adjunct of the specified class ('null' may be returned if
- * the 'newInstance' method is unable to create the adjunct)
- */
- public <T extends Adjunct> T getAdjunct(final Class<T> clazz) {
- return clazz.cast(adjuncts.computeIfAbsent(clazz, cl -> {
- T adjunct = null;
- try {
- // create the adjunct (may trigger an exception)
- adjunct = clazz.getDeclaredConstructor().newInstance();
-
- // initialize the adjunct (may also trigger an exception */
- adjunct.init(Transaction.this);
- } catch (Exception e) {
- logger.error("Transaction can't create adjunct of {}", cl, e);
- }
- return adjunct;
- }));
- }
-
- /**
- * Explicitly create an adjunct -- this is useful when the adjunct
- * initialization requires that some parameters be passed.
- *
- * @param adjunct this is the adjunct to insert into the table
- * @return 'true' if successful
- * ('false' is returned if an adjunct with this class already exists)
- */
- public boolean putAdjunct(Adjunct adjunct) {
- return adjuncts.putIfAbsent(adjunct.getClass(), adjunct) == null;
- }
-
- /**
- * This method needs to be called when the transaction completes, which
- * is typically right after it is removed from Drools memory.
- */
- public void cleanup() {
- // create a list containing all of the adjuncts (in no particular order)
- List<Adjunct> values;
- synchronized (adjuncts) {
- values = new LinkedList<>(adjuncts.values());
- }
-
- // iterate over the list
- for (Adjunct a : values) {
- try {
- // call the 'cleanup' method on the adjunct
- a.cleanup(this);
- } catch (Exception e) {
- logger.error("Transaction.cleanup exception", e);
- }
- }
- }
-}
diff --git a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Util.java b/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Util.java
deleted file mode 100644
index 5347b5c4e..000000000
--- a/controlloop/m2/base/src/main/java/org/onap/policy/m2/base/Util.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base;
-
-import org.onap.policy.drools.core.PolicyContainer;
-import org.onap.policy.drools.core.PolicySession;
-import org.onap.policy.drools.system.PolicyController;
-import org.onap.policy.drools.system.PolicyControllerConstants;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-
-/**
- * This class contains static utility methods.
- */
-public class Util {
- // Add a private Util to hide the implicit public one.
- private Util() {
- //not called
- }
-
- /**
- * Find the PolicyController associated with the specified PolicySession.
- *
- * @param session the current PolicySession
- * @return the associated PolicyController (or 'null' if not found)
- */
- public static PolicyController getPolicyController(PolicySession session) {
- PolicyContainer container = session.getPolicyContainer();
- return PolicyControllerConstants.getFactory().get(
- container.getGroupId(), container.getArtifactId());
- }
-
- /**
- * Send a UEB/DMAAP message to the specified topic, using the specified
- * PolicyController.
- *
- * @param topic UEB/DMAAP topic
- * @param event the message to encode, and send
- * @return 'true' if successful, 'false' if delivery failed
- * @throws IllegalStateException if the topic can't be found,
- * or there are multiple topics with the same name
- */
- public static boolean deliver(String topic, Object event) {
- return PolicyEngineConstants.getManager().deliver(topic, event);
- }
-}
diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/ActorOperationTest.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/ActorOperationTest.java
deleted file mode 100644
index 33b4928b1..000000000
--- a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/ActorOperationTest.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import org.junit.Test;
-import org.onap.policy.controlloop.ControlLoopEvent;
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-
-public class ActorOperationTest {
-
- public static final String ACTOR_NAME = "test";
- public static final String STATE = "COMPLETE";
-
- public static class TestOperation implements Operation {
- private static final long serialVersionUID = 1L;
-
- @Override
- public Object getRequest() throws ControlLoopException {
- return "request";
- }
-
- @Override
- public Policy getPolicy() {
- return null;
- }
-
- @Override
- public String getState() {
- return STATE;
- }
-
- @Override
- public int getAttempt() {
- return 0;
- }
-
- @Override
- public PolicyResult getResult() {
- return PolicyResult.SUCCESS;
- }
-
- @Override
- public String getMessage() {
- return "success";
- }
-
- @Override
- public void incomingMessage(Object object) {
- return;
- }
-
- @Override
- public void timeout() {
- return;
- }
-
- }
-
- public static class TestActor implements Actor {
-
- @Override
- public String getName() {
- return ACTOR_NAME;
- }
-
- @Override
- public Operation createOperation(Transaction transaction, Policy policy, ControlLoopEvent onset, int attempt) {
- return new TestOperation();
- }
-
- }
-
- @Test
- public void getNameTest() {
- Actor actor = new TestActor();
- assertEquals(ACTOR_NAME, actor.getName());
- }
-
- @Test
- public void testOperation() throws ControlLoopException {
- Actor actor = new TestActor();
- Operation operation = actor.createOperation(null, null, null, 0);
- assertNotNull(operation);
- assertEquals("request", operation.getRequest());
- assertNull(operation.getPolicy());
- assertEquals(STATE, operation.getState());
- assertEquals(0, operation.getAttempt());
- assertEquals(PolicyResult.SUCCESS, operation.getResult());
- assertEquals("success", operation.getMessage());
- }
-
-}
diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/GuardAdjunctTest.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/GuardAdjunctTest.java
deleted file mode 100644
index facde545a..000000000
--- a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/GuardAdjunctTest.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.times;
-import static org.mockito.Mockito.verify;
-
-import java.time.Instant;
-import java.util.UUID;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.controlloop.ControlLoopOperation;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.guard.GuardContext;
-import org.powermock.reflect.Whitebox;
-
-public class GuardAdjunctTest {
- private static final String ADJUNCT_CONTEXT_FIELD = "context";
-
- private static GuardAdjunct adjunct;
- private static Transaction transaction;
- private static GuardContext context;
-
- /**
- * Class-level initialization.
- */
- @BeforeClass
- public static void setup() {
- transaction = new Transaction(null, "testCL", UUID.randomUUID(), null);
- context = mock(GuardContext.class);
-
- GuardAdjunct.create(transaction, context);
- adjunct = transaction.getAdjunct(GuardAdjunct.class);
- }
-
- @Test
- public void createGuardAdjunctTest() {
- assertEquals(context, adjunct.get());
- }
-
- @Test
- public void testAsyncQuery() {
- Policy policy = new Policy();
- policy.setActor("APPCLCM");
- policy.setRecipe("test");
-
- assertTrue(adjunct.asyncQuery(policy, "testTarget", UUID.randomUUID().toString()));
-
- GuardContext savedContext = Whitebox.getInternalState(adjunct, ADJUNCT_CONTEXT_FIELD);
- Whitebox.setInternalState(adjunct, ADJUNCT_CONTEXT_FIELD, (GuardContext) null);
-
- try {
- assertFalse(adjunct.asyncQuery(policy, "testTarget", UUID.randomUUID().toString()));
- } finally {
- Whitebox.setInternalState(adjunct, ADJUNCT_CONTEXT_FIELD, savedContext);
- }
- }
-
- @Test
- public void testAsyncCreateDbEntry() {
- ControlLoopOperation op = new ControlLoopOperation();
- op.setStart(Instant.now().minusSeconds(1));
- op.setEnd(Instant.now());
- op.setActor("testActor");
- op.setOperation("testOperation");
- op.setSubRequestId("0");
- op.setMessage("test");
- op.setOutcome("success");
-
- adjunct.asyncCreateDbEntry(op, "testTarget");
- verify(context, times(1)).asyncCreateDbEntry(op.getStart(), op.getEnd(),
- transaction.getClosedLoopControlName(), op.getActor(),
- op.getOperation(), "testTarget", transaction.getRequestId().toString(),
- op.getSubRequestId(), op.getMessage(), op.getOutcome());
-
- }
-}
diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java
deleted file mode 100644
index 9158a6f52..000000000
--- a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/TransactionTest.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base;
-
-import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.time.Instant;
-import java.util.LinkedList;
-import java.util.UUID;
-import org.drools.core.WorkingMemory;
-import org.drools.core.impl.StatefulKnowledgeSessionImpl;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.kie.api.runtime.rule.FactHandle;
-import org.onap.policy.controlloop.ControlLoopEventStatus;
-import org.onap.policy.controlloop.ControlLoopNotification;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.policy.ControlLoop;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.controlloop.policy.FinalResult;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.Target;
-
-public class TransactionTest {
-
- private static final String CL_NAME = "clTest";
-
- private static WorkingMemory mockWorkingMemory;
-
- /**
- * Mocks the working memory.
- */
- @BeforeClass
- public static void setUpBeforeClass() {
- mockWorkingMemory = mock(WorkingMemory.class);
- FactHandle factHandle = mock(FactHandle.class);
- when(mockWorkingMemory.getFactHandle(any())).thenReturn(factHandle);
- }
-
- @Test
- public void testValidControlLoopEvent() {
- VirtualControlLoopEvent event =
- createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
- Transaction transaction = new Transaction(null, "clvusptest", event.getRequestId(), createControlLoop());
- assertTrue(transaction.isControlLoopEventValid(event));
- }
-
- @Test
- public void testNoRequestIdControlLoopEvent() {
- VirtualControlLoopEvent event =
- createControlLoopEvent(null, CL_NAME, null, "VM", "vserver.vserver-name");
- Transaction transaction = new Transaction(null, "clvusptest", event.getRequestId(), createControlLoop());
- assertFalse(transaction.isControlLoopEventValid(event));
- assertEquals("No requestID", transaction.getNotificationMessage());
- }
-
- @Test
- public void testNoTargetTypeControlLoopEvent() {
- VirtualControlLoopEvent event =
- createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, null, "vserver.vserver-name");
- Transaction transaction = new Transaction(null, "clvusptest", event.getRequestId(), createControlLoop());
- assertFalse(transaction.isControlLoopEventValid(event));
- assertEquals("No targetType", transaction.getNotificationMessage());
- }
-
- @Test
- public void testNoTargetControlLoopEvent() {
- VirtualControlLoopEvent event =
- createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", null);
- Transaction transaction = new Transaction(null, "clvusptest", event.getRequestId(), createControlLoop());
- assertFalse(transaction.isControlLoopEventValid(event));
- assertEquals("No target field", transaction.getNotificationMessage());
- }
-
- @Test
- public void testEmptyTargetControlLoopEvent() {
- assertInvalidTarget("");
- }
-
- @Test
- public void testGetClosedLoopControlName() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- assertEquals(CL_NAME, transaction.getClosedLoopControlName());
- }
-
- @Test
- public void testGetRequestId() {
- UUID requestId = UUID.randomUUID();
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, requestId, createControlLoop());
- assertEquals(requestId, transaction.getRequestId());
- }
-
- @Test
- public void testGetWorkingMemory() {
- // Create mock working session
- StatefulKnowledgeSessionImpl mockWorkingMemory = mock(StatefulKnowledgeSessionImpl.class);
- Transaction transaction = new Transaction(mockWorkingMemory, "clvusptest",
- UUID.randomUUID(), createControlLoop());
- assertEquals(mockWorkingMemory, transaction.getWorkingMemory());
- }
-
- @Test
- public void testGetStateComplete() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- assertEquals("COMPLETE", transaction.getState());
- }
-
- @Test
- public void testGetFinalResult() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- assertEquals(null, transaction.getFinalResult());
- }
-
- @Test
- public void testFinalResultFailure() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- assertFalse(transaction.finalResultFailure());
- transaction.clTimeout();
- assertTrue(transaction.finalResultFailure());
- }
-
- @Test
- public void testGetTimeout() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- assertEquals("15s", transaction.getTimeout());
- }
-
- @Test
- public void testGetOperationTimeout() {
- Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), createControlLoop());
- VirtualControlLoopEvent onset =
- createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
- transaction.setControlLoopEvent(onset);
- assertEquals("10s", transaction.getOperationTimeout());
- }
-
- @Test
- public void testGetCurrentPolicy() {
- ControlLoopPolicy controlLoopPolicy = createControlLoop();
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), controlLoopPolicy);
- VirtualControlLoopEvent onset =
- createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
- transaction.setControlLoopEvent(onset);
- assertEquals(controlLoopPolicy.getPolicies().get(0), transaction.getCurrentPolicy());
- }
-
- @Test
- public void testGetOperation() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- assertEquals(null, transaction.getCurrentOperation());
- }
-
- @Test
- public void testGetNotification() {
- Transaction transaction = new Transaction(null, "clvusptest", UUID.randomUUID(), createControlLoop());
- VirtualControlLoopEvent onset =
- createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
- transaction.setControlLoopEvent(onset);
- ControlLoopNotification notification = transaction.getNotification(onset);
- assertEquals(onset.getClosedLoopControlName(), notification.getClosedLoopControlName());
- assertEquals(onset.getRequestId(), notification.getRequestId());
- assertEquals(onset.getTarget(), notification.getTarget());
-
- notification = transaction.getNotification(null);
- assertEquals(onset.getClosedLoopControlName(), notification.getClosedLoopControlName());
- assertEquals(onset.getRequestId(), notification.getRequestId());
- assertEquals(onset.getTarget(), notification.getTarget());
- }
-
- @Test
- public void testSetControlLoopEventOnsetNotNull() {
- UUID requestId = UUID.randomUUID();
- VirtualControlLoopEvent event = createControlLoopEvent(requestId, CL_NAME, Instant.now(), "VM", "vserver-name");
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, requestId, createControlLoop());
- assertEquals("COMPLETE", transaction.getState());
- transaction.setControlLoopEvent(event);
- assertEquals("TEST.PENDING", transaction.getState());
- transaction.setControlLoopEvent(event);
- }
-
- @Test
- public void testSetOpenLoopEvent() {
- ControlLoop controlLoop = new ControlLoop();
- controlLoop.setControlLoopName(CL_NAME);
- controlLoop.setTrigger_policy(FinalResult.FINAL_OPENLOOP.toString());
-
- ControlLoopPolicy controlLoopPolicy = new ControlLoopPolicy();
- controlLoopPolicy.setControlLoop(controlLoop);
-
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), controlLoopPolicy);
- VirtualControlLoopEvent onset = createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver-name");
- transaction.setControlLoopEvent(onset);
-
- assertEquals("COMPLETE", transaction.getState());
- }
-
- @Test
- public void testIncomingMessage() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- ControlLoopNotification notification = transaction.incomingMessage("message 1");
- assertNull(notification);
-
- VirtualControlLoopEvent onset = createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver-name");
- transaction.setControlLoopEvent(onset);
- notification = transaction.incomingMessage("message 2");
- assertNotNull(notification);
- }
-
- @Test
- public void testIncomingMessageNullOperation() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- ControlLoopNotification notification = transaction.incomingMessage("test");
- assertNull(notification);
- }
-
- @Test
- public void testTimeout() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- VirtualControlLoopEvent onset =
- createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
- transaction.setControlLoopEvent(onset);
- ControlLoopNotification notification = transaction.timeout();
- assertNotNull(notification);
-
- transaction.clTimeout();
- notification = transaction.timeout();
- assertNull(notification);
- }
-
- @Test
- public void testClTimeout() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- transaction.clTimeout();
- Operation operation = transaction.getCurrentOperation();
- assertNull(operation);
- }
-
- @Test
- public void testInitialOperationNotification() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- VirtualControlLoopEvent onset =
- createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
- transaction.setControlLoopEvent(onset);
- ControlLoopNotification notification = transaction.initialOperationNotification();
- assertNotNull(notification);
-
- transaction.clTimeout();
- notification = transaction.initialOperationNotification();
- assertNull(notification);
- }
-
- @Test
- public void testFinalNotification() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- ControlLoopNotification notification = transaction.finalNotification();
- assertNull(notification);
-
- VirtualControlLoopEvent onset =
- createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
- transaction.setControlLoopEvent(onset);
- transaction.timeout();
- notification = transaction.finalNotification();
- assertNotNull(notification);
-
- transaction.clTimeout();
- notification = transaction.finalNotification();
- assertNotNull(notification);
-
- // openloop test case
- ControlLoop controlLoop = new ControlLoop();
- controlLoop.setControlLoopName(CL_NAME);
- controlLoop.setTrigger_policy(FinalResult.FINAL_OPENLOOP.toString());
- ControlLoopPolicy controlLoopPolicy = new ControlLoopPolicy();
- controlLoopPolicy.setControlLoop(controlLoop);
- transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), controlLoopPolicy);
- transaction.setControlLoopEvent(onset);
- notification = transaction.finalNotification();
- assertNotNull(notification);
- }
-
- @Test
- public void testProcessError() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- ControlLoopNotification notification = transaction.processError();
- assertNull(notification);
-
- VirtualControlLoopEvent onset =
- createControlLoopEvent(UUID.randomUUID(), CL_NAME, null, "VM", "vserver.vserver-name");
- transaction.setControlLoopEvent(onset);
- notification = transaction.processError();
- assertNotNull(notification);
- }
-
- @Test
- public void testSetNotificationMessage() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- transaction.setNotificationMessage("test");
- assertEquals("test", transaction.getNotificationMessage());
- }
-
- @Test
- public void testGetAdjunct() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- GuardAdjunct adjunct = transaction.getAdjunct(GuardAdjunct.class);
- assertNotNull(adjunct);
- }
-
- @Test
- public void testPutAdjunct() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- GuardAdjunct adjunct = new GuardAdjunct();
- boolean status = transaction.putAdjunct(adjunct);
- assertTrue(status);
- }
-
- @Test
- public void testCleanup() {
- Transaction transaction = new Transaction(mockWorkingMemory, CL_NAME, UUID.randomUUID(), createControlLoop());
- GuardAdjunct adjunct = new GuardAdjunct();
- transaction.putAdjunct(adjunct);
- GuardAdjunct adjunct2 = new GuardAdjunct();
- transaction.putAdjunct(adjunct2);
- transaction.cleanup();
- assertThatCode(() -> transaction.cleanup()).doesNotThrowAnyException();
- }
-
- private VirtualControlLoopEvent createControlLoopEvent(UUID requestId, String closedLoopControlName,
- Instant eventStart, String targetType, String target) {
-
- VirtualControlLoopEvent event = new VirtualControlLoopEvent();
- event.setClosedLoopControlName(closedLoopControlName);
- event.setClosedLoopEventStatus(ControlLoopEventStatus.ONSET);
- event.setRequestId(requestId);
- event.setClosedLoopAlarmStart(eventStart);
- event.setTarget(target);
- event.setTargetType(targetType);
- event.getAai().put("vserver.is-closed-loop-disabled", "false");
- event.getAai().put("vserver.in-maint", "N");
- event.getAai().put("vserver.vserver-name", "vnf01vm01");
- event.getAai().put("generic-vnf.vnf-name", "vnf01");
-
- return event;
- }
-
- private ControlLoopPolicy createControlLoop() {
- ControlLoop controlLoop = new ControlLoop();
- controlLoop.setControlLoopName(CL_NAME);
- controlLoop.setTrigger_policy("testId");
- controlLoop.setTimeout(15);
-
- Policy policy = new Policy();
- policy.setActor("testActor");
- policy.setId("testId");
- policy.setName("testPolicy");
- policy.setRecipe("testOperation");
- policy.setTarget(new Target("testTarget"));
- policy.setRetry(1);
- policy.setTimeout(10);
- policy.setSuccess(FinalResult.FINAL_SUCCESS.toString());
- policy.setFailure(FinalResult.FINAL_FAILURE.toString());
- policy.setFailure_exception(FinalResult.FINAL_FAILURE_EXCEPTION.toString());
- policy.setFailure_guard(FinalResult.FINAL_FAILURE_GUARD.toString());
- policy.setFailure_retries(FinalResult.FINAL_FAILURE_RETRIES.toString());
- policy.setFailure_timeout(FinalResult.FINAL_FAILURE_TIMEOUT.toString());
-
- LinkedList<Policy> policies = new LinkedList<>();
- policies.add(policy);
-
- ControlLoopPolicy controlLoopPolicy = new ControlLoopPolicy();
- controlLoopPolicy.setControlLoop(controlLoop);
- controlLoopPolicy.setPolicies(policies);
-
- return controlLoopPolicy;
- }
-
- private void assertInvalidTarget(String target) {
- VirtualControlLoopEvent event = createControlLoopEvent(UUID.randomUUID(), CL_NAME, Instant.now(), "VM", target);
- Transaction transaction = new Transaction(null, CL_NAME, event.getRequestId(), createControlLoop());
- assertFalse(transaction.isControlLoopEventValid(event));
- assertEquals("No target field", transaction.getNotificationMessage());
- }
-}
diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/ActorImpl.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/ActorImpl.java
deleted file mode 100644
index fe8836aa4..000000000
--- a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/ActorImpl.java
+++ /dev/null
@@ -1,43 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base.impl;
-
-import org.onap.policy.controlloop.ControlLoopEvent;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.m2.base.Actor;
-import org.onap.policy.m2.base.Operation;
-import org.onap.policy.m2.base.Transaction;
-
-public class ActorImpl implements Actor {
-
- public static final String ACTOR_NAME = "testActor";
-
- @Override
- public String getName() {
- return ACTOR_NAME;
- }
-
- @Override
- public Operation createOperation(Transaction transaction, Policy policy, ControlLoopEvent onset, int attempt) {
- return new OperationImpl();
- }
-
-} \ No newline at end of file
diff --git a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/OperationImpl.java b/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/OperationImpl.java
deleted file mode 100644
index 56f79eec3..000000000
--- a/controlloop/m2/base/src/test/java/org/onap/policy/m2/base/impl/OperationImpl.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/base
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.base.impl;
-
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.controlloop.policy.PolicyResult;
-import org.onap.policy.m2.base.Operation;
-
-public class OperationImpl implements Operation {
-
- private static final long serialVersionUID = 1L;
-
- private String state = "TEST.PENDING";
-
- @Override
- public Object getRequest() throws ControlLoopException {
- return "request";
- }
-
- @Override
- public Policy getPolicy() {
- return null;
- }
-
- @Override
- public String getState() {
- return state;
- }
-
- @Override
- public int getAttempt() {
- return 0;
- }
-
- @Override
- public PolicyResult getResult() {
- return PolicyResult.SUCCESS;
- }
-
- @Override
- public String getMessage() {
- state = "TEST.PENDING";
- return "test";
- }
-
- @Override
- public void incomingMessage(Object object) {
- state = "TEST.COMPLETE";
- }
-
- @Override
- public void timeout() {
- state = "TEST.COMPLETE";
- }
-
-} \ No newline at end of file
diff --git a/controlloop/m2/base/src/test/resources/META-INF/services/org.onap.policy.m2.base.Actor b/controlloop/m2/base/src/test/resources/META-INF/services/org.onap.policy.m2.base.Actor
deleted file mode 100644
index c0d6270b2..000000000
--- a/controlloop/m2/base/src/test/resources/META-INF/services/org.onap.policy.m2.base.Actor
+++ /dev/null
@@ -1 +0,0 @@
-org.onap.policy.m2.base.impl.ActorImpl \ No newline at end of file
diff --git a/controlloop/m2/feature-controlloop-m2/pom.xml b/controlloop/m2/feature-controlloop-m2/pom.xml
deleted file mode 100644
index 857c08fd2..000000000
--- a/controlloop/m2/feature-controlloop-m2/pom.xml
+++ /dev/null
@@ -1,126 +0,0 @@
-<?xml version="1.0"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
--->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>m2</artifactId>
- <version>1.7.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>feature-controlloop-m2</artifactId>
-
- <build>
- <resources>
- <resource>
- <directory>src/main/feature</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
- <plugins>
- <plugin>
- <artifactId>maven-assembly-plugin</artifactId>
- <executions>
- <execution>
- <id>zipfile</id>
- <goals>
- <goal>single</goal>
- </goals>
- <phase>package</phase>
- <configuration>
- <attach>true</attach>
- <finalName>${project.artifactId}-${project.version}</finalName>
- <descriptors>
- <descriptor>src/assembly/assemble_zip.xml</descriptor>
- </descriptors>
- <appendAssemblyId>false</appendAssemblyId>
- </configuration>
- </execution>
- </executions>
- </plugin>
-
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <id>copy-dependencies</id>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <phase>prepare-package</phase>
- <configuration>
- <outputDirectory>${project.build.directory}/assembly/lib</outputDirectory>
- <overWriteReleases>false</overWriteReleases>
- <overWriteSnapshots>true</overWriteSnapshots>
- <overWriteIfNewer>true</overWriteIfNewer>
- <useRepositoryLayout>false</useRepositoryLayout>
- <addParentPoms>false</addParentPoms>
- <copyPom>false</copyPom>
- <includeScope>runtime</includeScope>
- <excludeTransitive>true</excludeTransitive>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>util</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>guard</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>base</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>appclcm</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>lock</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>adapters</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
-</project>
diff --git a/controlloop/m2/feature-controlloop-m2/src/assembly/assemble_zip.xml b/controlloop/m2/feature-controlloop-m2/src/assembly/assemble_zip.xml
deleted file mode 100644
index bf006dd1a..000000000
--- a/controlloop/m2/feature-controlloop-m2/src/assembly/assemble_zip.xml
+++ /dev/null
@@ -1,80 +0,0 @@
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<!-- Defines how we build the .zip file which is our distribution. -->
-
-<assembly
- xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
- <id>feature-controlloop-m2-package</id>
- <formats>
- <format>zip</format>
- </formats>
-
- <includeBaseDirectory>false</includeBaseDirectory>
-
- <fileSets>
- <fileSet>
- <directory>target</directory>
- <outputDirectory>lib/feature</outputDirectory>
- <includes>
- <include>feature-controlloop-m2-${project.version}.jar</include>
- </includes>
- </fileSet>
-
- <fileSet>
- <directory>target/assembly/lib</directory>
- <outputDirectory>lib/dependencies</outputDirectory>
- <includes>
- <include>*.jar</include>
- </includes>
- </fileSet>
-
- <fileSet>
- <directory>target/classes/config</directory>
- <outputDirectory>config</outputDirectory>
- <fileMode>0644</fileMode>
- <excludes/>
- </fileSet>
-
- <fileSet>
- <directory>src/main/feature/bin</directory>
- <outputDirectory>bin</outputDirectory>
- <fileMode>0755</fileMode>
- <excludes/>
- </fileSet>
-
- <fileSet>
- <directory>src/main/feature/db</directory>
- <outputDirectory>db</outputDirectory>
- <fileMode>0755</fileMode>
- <excludes/>
- </fileSet>
-
- <fileSet>
- <directory>src/main/feature/install</directory>
- <outputDirectory>install</outputDirectory>
- <fileMode>0755</fileMode>
- <excludes/>
- </fileSet>
- </fileSets>
-
-</assembly>
diff --git a/controlloop/m2/guard/pom.xml b/controlloop/m2/guard/pom.xml
deleted file mode 100644
index 7a4993a40..000000000
--- a/controlloop/m2/guard/pom.xml
+++ /dev/null
@@ -1,132 +0,0 @@
-<?xml version="1.0"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>m2</artifactId>
- <version>1.7.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>guard</artifactId>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>util</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions</groupId>
- <artifactId>model-yaml</artifactId>
- <version>${policy.models.version}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-core</artifactId>
- <version>${version.policy.drools-pdp}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-management</artifactId>
- <version>${version.policy.drools-pdp}</version>
- <scope>provided</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
- <artifactId>guard</artifactId>
- <version>${policy.models.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models</groupId>
- <artifactId>policy-models-decisions</artifactId>
- <version>${policy.models.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions.model-impl</groupId>
- <artifactId>rest</artifactId>
- <version>${policy.models.version}</version>
- </dependency>
-
- <dependency>
- <groupId>com.att.research.xacml</groupId>
- <artifactId>xacml-pdp</artifactId>
- <version>1.0.2</version>
- <exclusions>
- <!--
- Exclude jars with an older version or that are insecure and not needed.
- -->
- <exclusion>
- <artifactId>commons-codec</artifactId>
- <groupId>commons-codec</groupId>
- </exclusion>
- <exclusion>
- <artifactId>commons-logging</artifactId>
- <groupId>commons-logging</groupId>
- </exclusion>
- <exclusion>
- <artifactId>guava</artifactId>
- <groupId>com.google.guava</groupId>
- </exclusion>
- <exclusion>
- <artifactId>commons-lang3</artifactId>
- <groupId>org.apache.commons</groupId>
- </exclusion>
- <exclusion>
- <artifactId>jackson-databind</artifactId>
- <groupId>com.fasterxml.jackson.core</groupId>
- </exclusion>
- <exclusion>
- <artifactId>commons-collections</artifactId>
- <groupId>commons-collections</groupId>
- </exclusion>
- <exclusion>
- <artifactId>commons-lang</artifactId>
- <groupId>commons-lang</groupId>
- </exclusion>
- </exclusions>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions</groupId>
- <artifactId>simulators</artifactId>
- <version>${policy.models.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>com.h2database</groupId>
- <artifactId>h2</artifactId>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-</project>
diff --git a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java b/controlloop/m2/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java
deleted file mode 100644
index 0331b7aab..000000000
--- a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/CallGuardTask.java
+++ /dev/null
@@ -1,155 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2017-2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import java.util.HashSet;
-import java.util.Set;
-import java.util.UUID;
-import java.util.function.Supplier;
-import org.drools.core.WorkingMemory;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class CallGuardTask implements Runnable {
-
- private static final Logger logger = LoggerFactory.getLogger(CallGuardTask.class);
-
- /**
- * Actor/recipe pairs whose guard requests need a VF Module count. Each element is of
- * the form "&lt;actor&gt;:&lt;recipe&gt;".
- */
- private static final Set<String> NEEDS_VF_COUNT = new HashSet<>();
-
- /**
- * Actor/recipe pairs whose guard requests need the VF Module count to be incremented
- * (i.e., because a module is being added). Each element is of the form
- * "&lt;actor&gt;:&lt;recipe&gt;".
- */
- private static final Set<String> INCR_VF_COUNT = new HashSet<>();
-
- static {
- INCR_VF_COUNT.add("SO:VF Module Create");
- NEEDS_VF_COUNT.addAll(INCR_VF_COUNT);
- }
-
- private WorkingMemory workingMemory;
- private String clname;
- private String actor;
- private String recipe;
- private String target;
- private String requestId;
- private Integer vfCount;
-
- /**
- * Populated once the response has been determined, which may happen during the
- * constructor or later, during {@link #run()}.
- */
- private PolicyGuardResponse guardResponse;
-
- /**
- * Guard url is grabbed from PolicyEngine manager properties.
- */
- public CallGuardTask(WorkingMemory wm, String cl, String act,
- String rec, String tar, String reqId, Supplier<Integer> vfcnt) {
- workingMemory = wm;
- clname = cl;
- actor = act;
- recipe = rec;
- requestId = reqId;
- target = tar;
-
- vfCount = null;
-
- String key = act + ":" + rec;
-
- if (NEEDS_VF_COUNT.contains(key)) {
- // this actor/recipe needs the count - get it
- if ((vfCount = vfcnt.get()) == null) {
- /*
- * The count is missing - create an artificial Deny, which will be
- * inserted into working memory when "run()" is called.
- */
- guardResponse = new PolicyGuardResponse(Util.DENY, UUID.fromString(requestId), recipe);
- logger.error("CallGuardTask.run missing VF Module count; requestId={}", requestId);
- return;
- }
-
- if (INCR_VF_COUNT.contains(key)) {
- // this actor/recipe needs the count to be incremented
- ++vfCount;
- }
- }
- }
-
- @Override
- public void run() {
- if (guardResponse != null) {
- // already have a response - just insert it
- workingMemory.insert(guardResponse);
- return;
- }
-
- final long startTime = System.nanoTime();
-
- PolicyGuardXacmlRequestAttributes xacmlReq =
- new PolicyGuardXacmlRequestAttributes(clname, actor, recipe, target, requestId, vfCount);
-
- logger.debug("\n********** XACML REQUEST START ********");
- logger.debug("{}", xacmlReq);
- logger.debug("********** XACML REQUEST END ********\n");
-
- String guardDecision = null;
-
- //
- // Make guard request
- //
- guardDecision = new PolicyGuardXacmlHelper().callPdp(xacmlReq);
-
- logger.debug("\n********** XACML RESPONSE START ********");
- logger.debug("{}", guardDecision);
- logger.debug("********** XACML RESPONSE END ********\n");
-
- //
- // Check if the restful call was unsuccessful or property doesn't exist
- //
- if (guardDecision == null) {
- logger.error("********** XACML FAILED TO CONNECT ********");
- guardDecision = Util.INDETERMINATE;
- }
-
- guardResponse = new PolicyGuardResponse(guardDecision, UUID.fromString(this.requestId), this.recipe);
-
- //
- // Create an artificial Guard response in case we didn't get a clear Permit or Deny
- //
- if ("Indeterminate".equals(guardResponse.getResult())) {
- guardResponse.setOperation(recipe);
- guardResponse.setRequestId(UUID.fromString(requestId));
- }
-
- long estimatedTime = System.nanoTime() - startTime;
- logger.debug("\n\n============ Guard inserted with decision {} !!! =========== time took: {} mili sec \n\n",
- guardResponse.getResult(), (double) estimatedTime / 1000 / 1000);
- workingMemory.insert(guardResponse);
-
- }
-
-}
diff --git a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/GuardContext.java b/controlloop/m2/guard/src/main/java/org/onap/policy/guard/GuardContext.java
deleted file mode 100644
index 75163e24e..000000000
--- a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/GuardContext.java
+++ /dev/null
@@ -1,393 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import java.io.ObjectStreamException;
-import java.io.Serializable;
-import java.sql.Timestamp;
-import java.time.Instant;
-import java.util.HashMap;
-import java.util.Properties;
-import java.util.UUID;
-import javax.persistence.EntityManager;
-import javax.persistence.EntityManagerFactory;
-import javax.persistence.Persistence;
-import org.drools.core.WorkingMemory;
-import org.eclipse.persistence.config.PersistenceUnitProperties;
-import org.onap.policy.drools.core.PolicyContainer;
-import org.onap.policy.drools.core.PolicySession;
-import org.onap.policy.drools.system.PolicyControllerConstants;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.util.DroolsSessionCommonSerializable;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * Each instance of this class is initialized from a 'Properties' object,
- * which is most likely a '*-controller.properties' file. The expectation is
- * that it will be initialized within a '.drl' file, and be referenced by
- * the associated 'Context' object.
- */
-public class GuardContext implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private static Logger logger = LoggerFactory.getLogger(GuardContext.class);
-
- // object that should be serialized
- private Object namedSerializable;
-
- /*==================================*/
- /* fields extracted from properties */
- /*==================================*/
- // contains the four database properties, 'javax.persistence.jdbc.*',
- private Properties dbProperties = null;
-
- // initialized from 'guard.disabled', but may also be set to 'true' if
- // there is an initialization error
- private boolean disabled = false;
-
- // errors that forced 'disabled' to be set to 'true'
- private String errorMessage = null;
-
- /*======================================================*/
- /* fields that shouldn't be included in serialized data */
- /*======================================================*/
-
- // derived from DB properties
- private transient EntityManagerFactory emf = null;
-
- /**
- * Constructor - initialize the 'GuardContext' instance using the
- * controller's properties file. The properties file is located using a
- * 'PolicySession' instance, but the way this mapping is done isn't
- * perfect -- it may use the wrong properties file if there is another
- * 'PolicyContainer' instance using the same 'artifactId' and 'groupId'.
- *
- * @param session the 'PolicySession' instance used to locate the associated
- * 'Properties' instance
- */
- public GuardContext(PolicySession session) {
- this(session, null);
- }
-
- /**
- * Constructor - initialize the 'GuardContext' instance using the
- * controller's properties file. The properties file is located using a
- * 'PolicySession' instance, but the way this mapping is done isn't
- * perfect -- it may use the wrong properties file if there is another
- * 'PolicyContainer' instance using the same 'artifactId' and 'groupId'.
- *
- * @param session the 'PolicySession' instance used to locate the associated
- * 'Properties' instance
- * @param serializableName a String name unique within the Drools session
- * that can be used to locate the corresponding 'GuardContext' object
- * on the remote host
- */
- public GuardContext(PolicySession session, String serializableName) {
- namedSerializable =
- (serializableName == null ? this :
- new DroolsSessionCommonSerializable(serializableName, this));
-
- // At present, there is no simple way to get the properties based
- // upon a 'PolicyContainer'. Instead, we search through all of the
- // 'PolicyController' instances looking for one with a matching
- // 'artifactId' and 'groupId'. Note that this may not work correctly
- // if there is more than one controller using the same or different
- // version of the same artifact.
-
- PolicyContainer container = session.getPolicyContainer();
- String artifactId = container.getArtifactId();
- String groupId = container.getGroupId();
-
- Properties properties =
- PolicyControllerConstants.getFactory().get(groupId, artifactId).getProperties();
- init(properties);
- }
-
- /**
- * Constructor - initialize the 'GuardContext' instance using the
- * specified properties.
- *
- * @param properties configuration data used to initialize the 'GuardContext' instance
- */
- public GuardContext(Properties properties) {
- init(properties);
- }
-
- /**
- * Common initialization routine code used by both constructors.
- *
- * @param properties configuration data used to initialize the 'GuardContext' instance
- */
- private void init(Properties properties) {
- // used to store error messages
- StringBuilder sb = new StringBuilder();
-
- // fetch these parameters, if they exist
- String disabledString =
- PolicyEngineConstants.getManager().getEnvironmentProperty(Util.PROP_GUARD_DISABLED);
-
- if (disabledString != null) {
- // decode optional 'guard.disabled' parameter
- disabled = Boolean.valueOf(disabledString);
- if (disabled) {
- // skip everything else
- return;
- }
- }
-
- // extract 'guard.java.persistence.jdbc.*' parameters,
- // which are all mandatory
- dbProperties = new Properties();
- setProperty(dbProperties, Util.ONAP_KEY_URL, PersistenceUnitProperties.JDBC_URL, sb);
- setProperty(dbProperties, Util.ONAP_KEY_USER, PersistenceUnitProperties.JDBC_USER, sb);
- setProperty(dbProperties, Util.ONAP_KEY_PASS, PersistenceUnitProperties.JDBC_PASSWORD, sb);
- String driver = properties.getProperty("guard." + PersistenceUnitProperties.JDBC_DRIVER);
- if (driver != null) {
- dbProperties.setProperty(PersistenceUnitProperties.JDBC_DRIVER, driver);
- }
- dbProperties.setProperty(Util.PROP_GUARD_PERSISTENCE_UNIT,
- properties.getProperty(Util.PROP_GUARD_PERSISTENCE_UNIT, Util.PU_KEY));
-
- // if there are any errors, update 'errorMessage' & disable guard queries
- if (sb.length() != 0) {
- // remove the terminating ", ", and extract resulting error message
- sb.setLength(sb.length() - 2);
- errorMessage = sb.toString();
- disabled = true;
- logger.error("Initialization failure: {}", errorMessage);
- }
- }
-
- /**
- * Fetch a property from the PolicyEngine environment, and store it in
- * a corresponding property in 'properties'.
- *
- * @param properties the location to store the properties
- * @param srcName source environment property name
- * @param destName destination property name
- * @param log a 'StringBuilder' used to construct an error message, if needed
- */
- private void setProperty(Properties properties, String srcName, String destName, StringBuilder log) {
- String value =
- PolicyEngineConstants.getManager().getEnvironmentProperty(srcName);
- if (value == null) {
- log.append("'").append(srcName).append("' is not defined, ");
- } else {
- properties.setProperty(destName, value);
- }
- }
-
- /**
- * Do an asynchronous (non-blocking) HTTP REST query to see if this
- * operation is permitted by 'guard'. The response is returned by
- * inserting a 'PolicyGuardResponse' instance into Drools memory.
- *
- * @param workingMemory the Drools response is inserted here
- * @param actor the processor being acted upon (e.g. "APPC")
- * @param recipe otherwise known as "operation" (e.g. "Restart")
- * @param target a further qualifier on 'actor'? (e.g. "VM")
- * @param requestId the UUID string identifying the overall request
- */
- public void asyncQuery(
- WorkingMemory workingMemory,
- String actor, String recipe, String target,
- String requestId) {
-
- asyncQuery(workingMemory, actor, recipe, target, requestId, null);
- }
-
- /**
- * Do an asynchronous (non-blocking) HTTP REST query to see if this
- * operation is permitted by 'guard'. The response is returned by
- * inserting a 'PolicyGuardResponse' instance into Drools memory.
- *
- * @param workingMemory the Drools response is inserted here
- * @param actor the processor being acted upon (e.g. "APPC")
- * @param recipe otherwise known as "operation" (e.g. "Restart")
- * @param target a further qualifier on 'actor'? (e.g. "VM")
- * @param requestId the UUID string identifying the overall request
- * @param controlLoopName the 'controlLoopName' value or 'null'
- * (if 'null', it is ommitted from the query to 'guard')
- */
- public void asyncQuery(
- final WorkingMemory workingMemory,
- final String actor, final String recipe, final String target,
- final String requestId, final String controlLoopName) {
-
- if (disabled) {
- logger.error("query skipped: {}", errorMessage);
- workingMemory.insert(
- new PolicyGuardResponse("Deny", UUID.fromString(requestId), recipe));
- return;
- }
-
- CallGuardTask cgt = new CallGuardTask(workingMemory, controlLoopName,
- actor, recipe, target, requestId, () -> null);
-
- PolicyEngineConstants.getManager().getExecutorService().execute(cgt);
- }
-
- /**
- * Create an 'EntityManagerFactory', if needed, and then create a new
- * 'EntityManager' instance.
- *
- * @return a new 'EntityManager' instance
- */
- private EntityManager createEntityManager() {
- if (emf == null) {
- // 'EntityManagerFactory' does not exist yet -- create one
-
- // copy database properties to a 'HashMap'
- HashMap<Object, Object> propertiesMap = new HashMap<>(dbProperties);
-
- // use 'ClassLoader' from Drools session
- propertiesMap.put("eclipselink.classloader",
- GuardContext.class.getClassLoader());
-
- // create DB tables, if needed
- propertiesMap.put("eclipselink.ddl-generation", "create-tables");
-
- // create entity manager factory
- String persistenceUnit = dbProperties.getProperty(Util.PROP_GUARD_PERSISTENCE_UNIT);
- emf = Persistence.createEntityManagerFactory(persistenceUnit, propertiesMap);
- }
-
- // create and return the 'EntityManager'
- return emf.createEntityManager();
- }
-
- /**
- * This is a synchronous (blocking) method, which creates a database entity
- * for an in-progress request.
- *
- * @param starttime this is used as the 'starttime' timestamp in the record
- * @param endtime this is used as the 'endtime' timestamp in the record
- * @param closedLoopControlName uniquely identifies the Drools rules
- * @param actor the processor being acted upon (e.g. "APPC")
- * @param recipe otherwise known as "operation" (e.g. "Restart")
- * @param target a further qualifier on 'actor'? (e.g. "VM")
- * @param requestId the UUID string identifying the overall request
- * @param subRequestId further qualifier on 'requestId'
- * @param message indicates success status, or reason for failure
- * @param outcome 'PolicyResult' enumeration string
- * @return 'true' if the operation was successful, and 'false' if not
- */
- public boolean createDbEntry(
- Instant starttime, Instant endtime, String closedLoopControlName,
- String actor, String recipe, String target,
- String requestId, String subRequestId, String message, String outcome) {
-
- if (disabled) {
- if (errorMessage != null) {
- logger.error("Database update skipped: {}", errorMessage);
- }
- return false;
- }
-
- EntityManager em = null;
- boolean rval = false;
-
- try {
- em = createEntityManager();
-
- // create the new DB table entry
- OperationsHistory newEntry = new OperationsHistory();
-
- // populate the new DB table entry
- newEntry.setClosedLoopName(closedLoopControlName);
- newEntry.setRequestId(requestId);
- newEntry.setActor(actor);
- newEntry.setOperation(recipe);
- newEntry.setTarget(target);
- newEntry.setStarttime(new Timestamp(starttime.toEpochMilli()));
- newEntry.setSubrequestId(subRequestId);
-
- newEntry.setEndtime(new Timestamp(endtime.toEpochMilli()));
- newEntry.setMessage(message);
- newEntry.setOutcome(outcome);
-
- // store the new entry in the DB
- em.getTransaction().begin();
- em.persist(newEntry);
- em.getTransaction().commit();
-
- rval = true;
- } finally {
- // free EntityManager
- if (em != null) {
- em.close();
- }
- }
- return rval;
- }
-
- /**
- * This is an asynchronous (non-blocking) method, which creates a database
- * entity for an in-progress request.
- *
- * @param starttime this is used as the 'starttime' timestamp in the record
- * @param endtime this is used as the 'endtime' timestamp in the record
- * @param closedLoopControlName uniquely identifies the Drools rules
- * @param actor the processor being acted upon (e.g. "APPC")
- * @param recipe otherwise known as "operation" (e.g. "Restart")
- * @param target a further qualifier on 'actor'? (e.g. "VM")
- * @param requestId the UUID string identifying the overall request
- * @param subRequestId further qualifier on 'requestId'
- * @param message indicates success status, or reason for failure
- * @param outcome 'PolicyResult' enumeration string
- */
- public void asyncCreateDbEntry(
- final Instant starttime, final Instant endtime,
- final String closedLoopControlName,
- final String actor, final String recipe, final String target,
- final String requestId, final String subRequestId,
- final String message, final String outcome) {
- if (disabled) {
- if (errorMessage != null) {
- logger.error("Database update skipped: {}", errorMessage);
- }
- return;
- }
-
- PolicyEngineConstants.getManager().getExecutorService().execute(() -> {
- try {
- // using a separate thread, call the synchronous 'createDbEntry'
- // method
- createDbEntry(starttime, endtime, closedLoopControlName,
- actor, recipe, target, requestId, subRequestId,
- message, outcome);
- } catch (Exception e) {
- logger.error("GuardContext.asyncCreateDbEntry", e);
- }
- });
- }
-
- /**
- * This method is used as part of serialization -- 'namedSerializable'
- * is serialized instead of 'this'.
- *
- * @return the object to be serialized
- */
- private Object writeReplace() throws ObjectStreamException {
- return namedSerializable;
- }
-}
diff --git a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/GuardResult.java b/controlloop/m2/guard/src/main/java/org/onap/policy/guard/GuardResult.java
deleted file mode 100644
index 6b11c1afa..000000000
--- a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/GuardResult.java
+++ /dev/null
@@ -1,25 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2017-2018 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-public enum GuardResult {
- LOCK_ACQUIRED, LOCK_DENIED, LOCK_EXCEPTION;
-}
diff --git a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardRequest.java b/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardRequest.java
deleted file mode 100644
index 8887e00b7..000000000
--- a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardRequest.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2017-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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import java.util.UUID;
-
-public class PolicyGuardRequest {
- private String actor;
- private String target;
- private UUID requestId;
- private String operation;
-
- /**
- * Construct an instance.
- *
- * @param actor the actor
- * @param target the target
- * @param requestId the request Id
- * @param operation the operation
- */
- public PolicyGuardRequest(String actor, String target, UUID requestId, String operation) {
- super();
- this.actor = actor;
- this.target = target;
- this.requestId = requestId;
- this.operation = operation;
- }
-
- @Override
- public String toString() {
- return "PolicyGuardRequest [actor=" + actor + ", target=" + target + ", requestId=" + requestId + ", operation="
- + operation + "]";
- }
-
- public String getActor() {
- return actor;
- }
-
- public void setActor(String actor) {
- this.actor = actor;
- }
-
- public String getTarget() {
- return target;
- }
-
- public void setTarget(String target) {
- this.target = target;
- }
-
- public UUID getRequestId() {
- return requestId;
- }
-
- public void setRequestId(UUID requestId) {
- this.requestId = requestId;
- }
-
- public String getOperation() {
- return operation;
- }
-
- public void setOperation(String operation) {
- this.operation = operation;
- }
-}
diff --git a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardResponse.java b/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardResponse.java
deleted file mode 100644
index 574c50b79..000000000
--- a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardResponse.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2017-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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import java.util.UUID;
-
-public class PolicyGuardResponse {
- private UUID requestId;
- private String operation;
- private String result;
-
- /**
- * Create an instance.
- *
- * @param result the result
- * @param req the request Id
- * @param op the operation
- */
- public PolicyGuardResponse(String result, UUID req, String op) {
- this.result = result;
- this.requestId = req;
- this.operation = op;
- }
-
- @Override
- public String toString() {
- return "PolicyGuardResponse [requestId=" + requestId + ", operation=" + operation + ", result=" + result + "]";
- }
-
- public UUID getRequestId() {
- return requestId;
- }
-
- public void setRequestId(UUID requestId) {
- this.requestId = requestId;
- }
-
- public String getResult() {
- return result;
- }
-
- public void setResult(String result) {
- this.result = result;
- }
-
- public String getOperation() {
- return operation;
- }
-
- public void setOperation(String operation) {
- this.operation = operation;
- }
-}
diff --git a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java b/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java
deleted file mode 100644
index d9ace1d83..000000000
--- a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java
+++ /dev/null
@@ -1,139 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * ONAP
- * ================================================================================
- * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019 Samsung Electronics Co., Ltd.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.UUID;
-import org.apache.commons.lang3.tuple.Pair;
-import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
-import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.models.decisions.concepts.DecisionRequest;
-import org.onap.policy.models.decisions.concepts.DecisionResponse;
-import org.onap.policy.rest.RestManager;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class PolicyGuardXacmlHelper {
- private static final Logger logger = LoggerFactory.getLogger(PolicyGuardXacmlHelper.class);
-
- private String url;
- private String user;
- private String pwd;
-
- /**
- * Constructor.
- */
- public PolicyGuardXacmlHelper() {
- this.url = PolicyEngineConstants.getManager().getEnvironmentProperty("guard.url");
- this.user = PolicyEngineConstants.getManager().getEnvironmentProperty("pdpx.username");
- this.pwd = PolicyEngineConstants.getManager().getEnvironmentProperty("pdpx.password");
- }
-
- /**
- * Call PDP.
- *
- * @param xacmlReq the XACML request
- * @return the response
- */
- public String callPdp(PolicyGuardXacmlRequestAttributes xacmlReq) {
- //
- // Create a request suitable for API
- //
- DecisionRequest decisionRequest = new DecisionRequest();
- decisionRequest.setOnapName("Policy");
- decisionRequest.setOnapComponent("Drools PDP");
- decisionRequest.setOnapInstance("usecase template");
- decisionRequest.setRequestId(UUID.randomUUID().toString());
- decisionRequest.setAction("guard");
- Map<String, String> guard = new HashMap<>();
- guard.put("actor", xacmlReq.getActorId());
- guard.put("operation", xacmlReq.getOperationId());
- guard.put("target", xacmlReq.getTargetId());
- if (xacmlReq.getClnameId() != null) {
- guard.put("clname", xacmlReq.getClnameId());
- }
- if (xacmlReq.getVfCount() != null) {
- guard.put("vfCount", Integer.toString(xacmlReq.getVfCount()));
- }
- Map<String, Object> resources = new HashMap<>();
- resources.put("guard", guard);
- decisionRequest.setResource(resources);
-
- try {
- //
- // Call RESTful PDP
- //
- NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, this.url, decisionRequest.toString());
- String response = callRestfulPdp(decisionRequest);
- NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, this.url, response);
-
- return response;
- } catch (Exception e) {
- logger.error("Exception in sending RESTful request: ", e);
- }
-
- return Util.DENY;
- }
-
- /**
- * This makes an HTTP POST call to a running PDP RESTful servlet to get a decision.
- *
- * @param decisionRequest The Decision request
- * @return response from guard which contains "Permit" or "Deny"
- * @throws CoderException Exception when converting to/from JSON the message body
- */
- private String callRestfulPdp(DecisionRequest decisionRequest) throws CoderException {
- StandardCoder coder = new StandardCoder();
-
- String jsonBody = coder.encode(decisionRequest);
- RestManager restManager = new RestManager();
-
- Map<String, String> headers = new HashMap<>();
- headers.put("Accepts", "application/json");
-
- logger.info("Guard Decision Request: {}", jsonBody);
-
- Pair<Integer, String> httpDetails = restManager.post(url, user, pwd, headers, "application/json", jsonBody);
-
- if (httpDetails == null) {
- logger.error("Guard rest call returned a null pair - defaulting to DENY");
- return Util.DENY;
- }
-
- logger.info("Guard Decision REST Response {} {}", httpDetails.getLeft(), httpDetails.getRight());
-
- if (httpDetails.getLeft() == 200) {
- DecisionResponse decision = coder.decode(httpDetails.getRight(), DecisionResponse.class);
- logger.info("Guard Decision {}", decision);
- return decision.getStatus();
- }
-
- return Util.DENY;
- }
-
-}
diff --git a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributes.java b/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributes.java
deleted file mode 100644
index c888f94c1..000000000
--- a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributes.java
+++ /dev/null
@@ -1,123 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2017-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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import com.att.research.xacml.std.annotations.XACMLAction;
-import com.att.research.xacml.std.annotations.XACMLRequest;
-import com.att.research.xacml.std.annotations.XACMLResource;
-import com.att.research.xacml.std.annotations.XACMLSubject;
-
-@XACMLRequest(ReturnPolicyIdList = true, CombinedDecision = true)
-public class PolicyGuardXacmlRequestAttributes {
-
- @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:guard:clname:clname-id")
- String clnameId;
-
- @XACMLSubject(includeInResults = true, attributeId = "urn:org:onap:guard:actor:actor-id")
- String actorId;
-
- @XACMLAction(includeInResults = true, attributeId = "urn:org:onap:guard:operation:operation-id")
- String operationId;
-
- @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:target:target-id")
- String targetId;
-
- @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:request:request-id")
- String requestId;
-
- @XACMLResource(includeInResults = true, attributeId = "urn:org:onap:guard:request:vf-count")
- Integer vfCount;
-
- /**
- * Construct an instance.
- *
- * @param clnameId the control loop Id
- * @param actorId the actor Id
- * @param operationId the operation Id
- * @param targetId the target Id
- * @param requestId the request Id
- * @param vfCount the new number of VF Modules
- */
- public PolicyGuardXacmlRequestAttributes(String clnameId, String actorId, String operationId, String targetId,
- String requestId, Integer vfCount) {
- super();
- this.clnameId = clnameId;
- this.actorId = actorId;
- this.operationId = operationId;
- this.targetId = targetId;
- this.requestId = requestId;
- this.vfCount = vfCount;
- }
-
- @Override
- public String toString() {
- return "PolicyGuardXacmlRequestAttributes [actorId=" + actorId + ", operationId=" + operationId + ", targetId="
- + targetId + ", requestId=" + requestId + "]";
- }
-
- public String getActorId() {
- return actorId;
- }
-
- public void setActorId(String actorId) {
- this.actorId = actorId;
- }
-
- public String getOperationId() {
- return operationId;
- }
-
- public void setOperationId(String operationId) {
- this.operationId = operationId;
- }
-
- public String getTargetId() {
- return targetId;
- }
-
- public void setTargetId(String targetId) {
- this.targetId = targetId;
- }
-
- public String getRequestId() {
- return requestId;
- }
-
- public void setRequestId(String requestId) {
- this.requestId = requestId;
- }
-
- public String getClnameId() {
- return clnameId;
- }
-
- public void setClnameId(String clnameId) {
- this.clnameId = clnameId;
- }
-
- public Integer getVfCount() {
- return vfCount;
- }
-
- public void setVfCount(Integer vfCount) {
- this.vfCount = vfCount;
- }
-}
diff --git a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java b/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java
deleted file mode 100644
index 60ccce05d..000000000
--- a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/PolicyGuardYamlToXacml.java
+++ /dev/null
@@ -1,210 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2017, 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.List;
-import java.util.function.Consumer;
-import org.onap.policy.controlloop.policy.guard.Constraint;
-import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
-import org.onap.policy.controlloop.policy.guard.GuardPolicy;
-import org.onap.policy.controlloop.policy.guard.MatchParameters;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class PolicyGuardYamlToXacml {
- private static final Logger logger = LoggerFactory.getLogger(PolicyGuardYamlToXacml.class);
-
- private PolicyGuardYamlToXacml() {
- // Construction of this static class is not allowed
- }
-
- /**
- * Convert from Yaml to Xacml.
- *
- * @param yamlFile the Yaml file
- * @param xacmlTemplate the Xacml template
- * @param xacmlPolicyOutput the Xacml output
- */
- public static void fromYamlToXacml(String yamlFile, String xacmlTemplate, String xacmlPolicyOutput) {
- fromYamlToXacml(yamlFile, xacmlTemplate, xacmlPolicyOutput, PolicyGuardYamlToXacml::generateXacmlGuard,
- constraint -> {
- logger.debug("num: {}", constraint.getFreq_limit_per_target());
- logger.debug("duration: {}", constraint.getTime_window());
- logger.debug("time_in_range: {}", constraint.getActive_time_range());
- });
- }
-
- /**
- * Convert from Yaml to Xacml.
- *
- * @param yamlFile the Yaml file
- * @param xacmlTemplate the Xacml template
- * @param xacmlPolicyOutput the Xacml output
- * @param generator function to generate the yaml from the xacml
- * @param logConstraint function to log relevant fields of the constraint
- */
- public static void fromYamlToXacml(String yamlFile, String xacmlTemplate, String xacmlPolicyOutput,
- Generator generator, Consumer<Constraint> logConstraint) {
-
- ControlLoopGuard yamlGuardObject = Util.loadYamlGuard(yamlFile);
- GuardPolicy guardPolicy = yamlGuardObject.getGuards().get(0);
- logger.debug("clname: {}", guardPolicy.getMatch_parameters().getControlLoopName());
- logger.debug("actor: {}", guardPolicy.getMatch_parameters().getActor());
- logger.debug("recipe: {}", guardPolicy.getMatch_parameters().getRecipe());
- Constraint constraint = guardPolicy.getLimit_constraints().get(0);
- logConstraint.accept(constraint);
-
- Path xacmlTemplatePath = Paths.get(xacmlTemplate);
- String xacmlTemplateContent;
-
- try {
- xacmlTemplateContent = new String(Files.readAllBytes(xacmlTemplatePath));
-
- String xacmlPolicyContent = generator.apply(xacmlTemplateContent,
- guardPolicy.getMatch_parameters(), constraint);
-
- Files.write(Paths.get(xacmlPolicyOutput), xacmlPolicyContent.getBytes());
-
- } catch (IOException e) {
- logger.error("fromYamlToXacml threw: ", e);
- }
- }
-
- /**
- * Generate a Xacml guard.
- *
- * @param xacmlTemplateContent the Xacml template content
- * @param matchParameters the paremeters to use
- * @param constraint the constraint to use
- * @return the guard
- */
- private static String generateXacmlGuard(String xacmlTemplateContent, MatchParameters matchParameters,
- Constraint constraint) {
-
- xacmlTemplateContent = doCommonReplacements(xacmlTemplateContent, matchParameters, constraint);
-
- String targetsRegex = "";
- if (isNullOrEmptyList(matchParameters.getTargets())) {
- targetsRegex = ".*";
- } else {
- StringBuilder targetsRegexSb = new StringBuilder();
- boolean addBarChar = false;
- for (String t : matchParameters.getTargets()) {
- targetsRegexSb.append(t);
- if (addBarChar) {
- targetsRegexSb.append("|");
- } else {
- addBarChar = true;
- }
- }
- targetsRegex = targetsRegexSb.toString();
- }
- xacmlTemplateContent = xacmlTemplateContent.replace("${targets}", targetsRegex);
-
- xacmlTemplateContent = xacmlTemplateContent.replace("${limit}",
- constraint.getFreq_limit_per_target().toString());
-
- xacmlTemplateContent = xacmlTemplateContent.replace("${twValue}", constraint.getTime_window().get("value"));
-
- xacmlTemplateContent = xacmlTemplateContent.replace("${twUnits}", constraint.getTime_window().get("units"));
-
- logger.debug(xacmlTemplateContent);
-
- return xacmlTemplateContent;
- }
-
- private static String doCommonReplacements(String xacmlTemplateContent, MatchParameters matchParameters,
- Constraint constraint) {
-
- replaceNullOrEmpty(matchParameters.getControlLoopName(), matchParameters::setControlLoopName, ".*");
- xacmlTemplateContent = xacmlTemplateContent.replace("${clname}", matchParameters.getControlLoopName());
-
- replaceNullOrEmpty(matchParameters.getActor(), matchParameters::setActor, ".*");
- xacmlTemplateContent = xacmlTemplateContent.replace("${actor}", matchParameters.getActor());
-
- replaceNullOrEmpty(matchParameters.getRecipe(), matchParameters::setRecipe, ".*");
- xacmlTemplateContent = xacmlTemplateContent.replace("${recipe}", matchParameters.getRecipe());
-
- xacmlTemplateContent = xacmlTemplateContent.replace("${guardActiveStart}",
- constraint.getActive_time_range().get("start"));
-
- xacmlTemplateContent = xacmlTemplateContent.replace("${guardActiveEnd}",
- constraint.getActive_time_range().get("end"));
-
- return xacmlTemplateContent;
- }
-
- private static void replaceNullOrEmpty(String text, Consumer<String> replacer, String newValue) {
- if (isNullOrEmpty(text)) {
- replacer.accept(newValue);
- }
- }
-
- public static boolean isNullOrEmpty(String string) {
- return string == null || string.trim().isEmpty();
- }
-
- public static boolean isNullOrEmptyList(List<String> list) {
- return list == null || list.isEmpty();
- }
-
- /**
- * Convert from Yaml to Xacml blacklist.
- *
- * @param yamlFile the Yaml file
- * @param xacmlTemplate the Xacml template
- * @param xacmlPolicyOutput the Xacml output
- */
- public static void fromYamlToXacmlBlacklist(String yamlFile, String xacmlTemplate, String xacmlPolicyOutput) {
- fromYamlToXacml(yamlFile, xacmlTemplate, xacmlPolicyOutput, PolicyGuardYamlToXacml::generateXacmlGuardBlacklist,
- constraint -> {
- logger.debug("freq_limit_per_target: {}", constraint.getFreq_limit_per_target());
- logger.debug("time_window: {}", constraint.getTime_window());
- logger.debug("active_time_range: {}", constraint.getActive_time_range());
- });
- }
-
- private static String generateXacmlGuardBlacklist(String xacmlTemplateContent, MatchParameters matchParameters,
- Constraint constraint) {
-
- String result = doCommonReplacements(xacmlTemplateContent, matchParameters, constraint);
-
- for (String target : constraint.getBlacklist()) {
- result = result.replace("${blackListElement}",
- "<AttributeValue DataType=\"http://www.w3.org/2001/XMLSchema#string\">" + target
- + "</AttributeValue>" + "\n\t\t\t\t\t\t\\${blackListElement}\n");
- }
-
- result = result.replace("\t\t\t\t\t\t\\${blackListElement}\n", "");
-
- return result;
- }
-
- @FunctionalInterface
- private static interface Generator {
- public String apply(String xacmlTemplateContent, MatchParameters matchParameters,
- Constraint constraint);
- }
-}
diff --git a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/Util.java b/controlloop/m2/guard/src/main/java/org/onap/policy/guard/Util.java
deleted file mode 100644
index d1eed1bb4..000000000
--- a/controlloop/m2/guard/src/main/java/org/onap/policy/guard/Util.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2017-2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.charset.StandardCharsets;
-import org.apache.commons.io.IOUtils;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-
-public final class Util {
- /*
- * Keys for guard properties
- */
- public static final String PROP_GUARD_URL = "guard.url";
- public static final String PROP_GUARD_USER = "pdpx.username";
- public static final String PROP_GUARD_PASS = "pdpx.password";
- public static final String PROP_GUARD_DISABLED = "guard.disabled";
- public static final String PROP_GUARD_PERSISTENCE_UNIT = "guard.persistenceUnit";
-
- /*
- * Keys for ONAP properties
- */
- public static final String ONAP_KEY_URL = "guard.jdbc.url";
- public static final String ONAP_KEY_USER = "sql.db.username";
- public static final String ONAP_KEY_PASS = "sql.db.password";
-
- /*
- * Guard responses
- */
- public static final String INDETERMINATE = "Indeterminate";
- public static final String PERMIT = "Permit";
- public static final String DENY = "Deny";
-
- /*
- * Junit props
- */
- protected static final String PU_KEY = "OperationsHistoryPU";
- protected static final String JUNITPU = "OperationsHistoryPUTest";
-
- private static final Logger logger = LoggerFactory.getLogger(Util.class);
-
- public static class Pair<A, B> {
- public final A parameterA;
- public final B parameterB;
-
- public Pair(A parameterA, B parameterB) {
- this.parameterA = parameterA;
- this.parameterB = parameterB;
- }
- }
-
- private Util() {
- // This static class cannot be instantiated
- }
-
- /**
- * Load a Yaml file.
- *
- * @param testFile the Yaml file
- * @return the policies
- */
- public static Pair<ControlLoopPolicy, String> loadYaml(String testFile) {
- try (InputStream is = new FileInputStream(new File(testFile))) {
- String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
- //
- // Read the yaml into our Java Object
- //
- Yaml yaml = new Yaml(new Constructor(ControlLoopPolicy.class));
- Object obj = yaml.load(contents);
-
- logger.debug(contents);
-
- return new Pair<>((ControlLoopPolicy) obj, contents);
- } catch (IOException e) {
- logger.error(e.getLocalizedMessage(), e);
- }
- return null;
- }
-
- /**
- * Load a Yaml guard.
- *
- * @param testFile the Yaml file
- * @return the guard
- */
- public static ControlLoopGuard loadYamlGuard(String testFile) {
- try (InputStream is = new FileInputStream(new File(testFile))) {
- String contents = IOUtils.toString(is, StandardCharsets.UTF_8);
- //
- // Read the yaml into our Java Object
- //
- Yaml yaml = new Yaml(new Constructor(ControlLoopGuard.class));
- Object obj = yaml.load(contents);
- return (ControlLoopGuard) obj;
- } catch (IOException e) {
- logger.error(e.getLocalizedMessage(), e);
- }
- return null;
- }
-
- /**
- * Sets Guard Properties.
- *
- * <p>see /guard/src/test/java/org/onap/policy/guard/UtilTest.java for setting test properties
- */
- public static void setGuardEnvProps(String url, String username, String password) {
- PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_URL, url);
- PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_USER, username);
- PolicyEngineConstants.getManager().setEnvironmentProperty(org.onap.policy.guard.Util.PROP_GUARD_PASS, password);
- }
-
- public static void setGuardEnvProp(String key, String value) {
- PolicyEngineConstants.getManager().setEnvironmentProperty(key, value);
- }
-
- public static String getGuardProp(String propName) {
- return PolicyEngineConstants.getManager().getEnvironmentProperty(propName);
- }
-}
diff --git a/controlloop/m2/guard/src/main/resources/META-INF/persistence.xml b/controlloop/m2/guard/src/main/resources/META-INF/persistence.xml
deleted file mode 100644
index cf7e28190..000000000
--- a/controlloop/m2/guard/src/main/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" ?>
-<!--
- ============LICENSE_START=======================================================
- drools-applications
- ================================================================================
- Copyright (C) 2018-2020 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.
- ============LICENSE_END=========================================================
- -->
-<persistence xmlns="http://java.sun.com/xml/ns/persistence"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
- http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">
-
- <persistence-unit name="OperationsHistoryPU" transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
- <class>org.onap.policy.guard.OperationsHistory</class>
-
- <properties>
- <property name="eclipselink.ddl-generation" value="create-tables"/>
- <property name="eclipselink.logging.level" value="INFO" />
- <property name="javax.persistence.jdbc.driver" value="org.mariadb.jdbc.Driver" />
- <property name="javax.persistence.jdbc.url" value="jdbc:mariadb://mariadb:3306/operationshistory"/>
- <property name="javax.persistence.jdbc.user" value="policy_user"/>
- <property name="javax.persistence.jdbc.password" value="cG9saWN5X3VzZXI="/>
- <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
- <property name="javax.persistence.schema-generation.create-source" value="metadata"/>
- </properties>
- </persistence-unit>
-
-</persistence>
diff --git a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/CallGuardTaskTest.java b/controlloop/m2/guard/src/test/java/org/onap/policy/guard/CallGuardTaskTest.java
deleted file mode 100644
index 3a647b130..000000000
--- a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/CallGuardTaskTest.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2017-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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import static org.mockito.ArgumentMatchers.argThat;
-import static org.mockito.ArgumentMatchers.isNotNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.util.function.Supplier;
-import org.drools.core.WorkingMemory;
-import org.junit.Test;
-
-public class CallGuardTaskTest {
-
- private static final String REQ_ID = "1-2-3-4-5";
- private static final String REQ_MATCHER = "0+1-0+2-0+3-0+4-0+5";
- private static final String VF_COUNT_ACTOR = "SO";
- private static final String INCR_VF_COUNT_RECIPE = "VF Module Create";
-
- /**
- * Tests that "run" works, and inserts guard response into working memory.
- */
- @Test
- public void testRun() {
- // plain - doesn't need VF module count
- //doTestRun(Util.INDETERMINATE, "act", "rec", () -> null);
-
- // SO actor, but plain recipe - doesn't need VF module count
- //doTestRun(Util.INDETERMINATE, VF_COUNT_ACTOR, "rec", () -> null);
-
- // plain actor, but scale-out recipe - doesn't need VF module count
- //doTestRun(Util.INDETERMINATE, "act", "VF Module Create", () -> null);
-
- // needs VF count
- //doTestRun(Util.INDETERMINATE, VF_COUNT_ACTOR, INCR_VF_COUNT_RECIPE, () -> 22);
-
- // needs VF count, but it's missing ==> DENY
- doTestRun(Util.DENY, VF_COUNT_ACTOR, INCR_VF_COUNT_RECIPE, () -> null);
- }
-
- private void doTestRun(String status, String actor, String recipe, Supplier<Integer> vfCount) {
- WorkingMemory mockWorkingSession = mock(WorkingMemory.class);
- when(mockWorkingSession.insert(isNotNull())).thenReturn(null);
- // Create CallGuardTask and run
- CallGuardTask cgt = new CallGuardTask(mockWorkingSession, "cl", actor, recipe, "tar", REQ_ID, vfCount);
- cgt.run();
- verify(mockWorkingSession).insert(argThat((Object obj) -> {
- if (!(obj instanceof PolicyGuardResponse)) {
- return false;
- }
- // Check if the inserted response is PolicyGuardResponse, is Indeterminate,
- // and has same reqID
- PolicyGuardResponse response = (PolicyGuardResponse) obj;
- // req ID has form 00000001-0002-0003-0004-000000000005
- return status.equals(response.getResult()) && response.getRequestId().toString().matches(REQ_MATCHER);
- }));
- }
-}
diff --git a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardContextTest.java b/controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardContextTest.java
deleted file mode 100644
index 1b375cf21..000000000
--- a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardContextTest.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.ArgumentMatchers.isNotNull;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.time.Instant;
-import java.util.Properties;
-import java.util.UUID;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import org.drools.core.WorkingMemory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.onap.policy.drools.core.PolicyContainer;
-import org.onap.policy.drools.core.PolicySession;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-
-public class GuardContextTest {
-
- private static Properties prop;
- private static GuardContext guardContext;
- private static WorkingMemory workingMemory;
- private static LinkedBlockingQueue<Object> queue = new LinkedBlockingQueue<>();
-
- /**
- * Class-level initialization.
- */
- @BeforeClass
- public static void setup() throws IOException {
- PolicyEngineConstants.getManager().configure(new Properties());
- PolicyEngineConstants.getManager().start();
-
- prop = new Properties();
- prop.setProperty("guard.pdp.rest.url", "http://www.google.com/");
- prop.setProperty("guard.pdp.rest.client.user", "testuser");
- prop.setProperty("guard.pdp.rest.client.password", "testpassword");
- prop.setProperty("guard.pdp.rest.timeout", "1000");
- prop.setProperty("guard.pdp.rest.environment", "dev");
-
- workingMemory = mock(WorkingMemory.class);
- when(workingMemory.insert(isNotNull())).thenAnswer(
- invocation -> {
- queue.add(invocation.getArgument(0));
- return null;
- });
- }
-
- @AfterClass
- public static void stop() {
- PolicyEngineConstants.getManager().stop();
- }
-
- @Test
- public void testGuardDbResponse() throws InterruptedException {
- Properties props = new Properties(prop);
- props.setProperty(Util.PROP_GUARD_PERSISTENCE_UNIT, Util.JUNITPU);
- props.setProperty("guard.disabled", "false");
- props.setProperty("guard.javax.persistence.jdbc.user", "user");
- props.setProperty("guard.javax.persistence.jdbc.password", "secret");
- props.setProperty("guard.javax.persistence.jdbc.driver", "org.h2.Driver");
- props.setProperty("guard.javax.persistence.jdbc.url", "jdbc:h2:mem:testGuardDbResponse");
-
- guardContext = new GuardContext(props);
- assertNotNull(guardContext);
-
- guardContext.asyncCreateDbEntry(Instant.now().minusSeconds(1), Instant.now(),
- "testCLName", "testActor", "testRecipe", "testTarget",
- UUID.randomUUID().toString(), "1", "testMessage", "testOutcome");
-
- queue.clear();
- guardContext.asyncQuery(workingMemory, "testActor", "testRecipe",
- "testTarget", UUID.randomUUID().toString(), "testCLName");
- Object response = queue.poll(10, TimeUnit.SECONDS);
- assertNotNull(response);
- }
-
- @Test
- public void testBadValues() throws InterruptedException {
- Properties props = new Properties(prop);
- props.setProperty("guard.disabled", "true");
- props.setProperty("guard.pdp.rest.client.user", "");
- props.setProperty("guard.pdp.rest.client.password", "");
- props.setProperty("guard.pdp.rest.url", "bad,testuser,testpassword");
-
- guardContext = new GuardContext(props);
-
- guardContext.asyncCreateDbEntry(Instant.now().minusSeconds(1), Instant.now(),
- "testCLName", "testActor", "testRecipe", "testTarget",
- UUID.randomUUID().toString(), "1", "testMessage", "testOutcome");
-
- queue.clear();
- guardContext.asyncQuery(workingMemory, "testActor", "testRecipe",
- "testTarget", UUID.randomUUID().toString());
- Object response = queue.poll(10, TimeUnit.SECONDS);
- assertNotNull(response);
- }
-
- @Test
- public void testPolicyGuardResponse() {
- UUID requestId = UUID.randomUUID();
- PolicyGuardResponse emptyResponse1 = new PolicyGuardResponse(null, null, null);
-
- assertNotNull(emptyResponse1);
-
- PolicyGuardResponse response = new PolicyGuardResponse("Some Result", requestId, "Some Details");
-
- response.setRequestId(requestId);
- assertEquals(requestId, response.getRequestId());
-
- response.setResult("Some Result");
- assertEquals("Some Result", response.getResult());
-
- assertEquals("PolicyGuardResponse [requestId=", response.toString().substring(0, 31));
- }
-
- @Test
- public void testConstructors() {
- PolicySession mockPolicySession = Mockito.mock(PolicySession.class);
- PolicyContainer mockPolicyContainer = Mockito.mock(PolicyContainer.class);
-
- when(mockPolicySession.getPolicyContainer()).thenReturn(mockPolicyContainer);
- when(mockPolicyContainer.getArtifactId()).thenReturn("testArtifactId");
- when(mockPolicyContainer.getGroupId()).thenReturn("testGroupId");
-
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
- guardContext = new GuardContext(mockPolicySession);
- });
-
- assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> {
- guardContext = new GuardContext(mockPolicySession, "testSerializableName");
- });
-
- verify(mockPolicySession, atLeast(1)).getPolicyContainer();
- verify(mockPolicyContainer, atLeast(1)).getArtifactId();
- verify(mockPolicyContainer, atLeast(1)).getGroupId();
- }
-
- @Test
- public void testCreateDbEntry() {
- Properties props = new Properties();
- props.setProperty(Util.PROP_GUARD_PERSISTENCE_UNIT, Util.JUNITPU);
- Instant startTime = Instant.now();
- Instant endTime = Instant.now();
-
- guardContext = new GuardContext(props);
- assertFalse(guardContext.createDbEntry(startTime, endTime, "testClosedLoopControlName", "testActor",
- "testRecipe", "testTarget", "testRequestId", "testSubRequestId", "testMessage", "testOutcome"));
-
- PolicyEngineConstants.getManager().setEnvironmentProperty("guard.disabled", "true");
- assertFalse(guardContext.createDbEntry(startTime, endTime, "testClosedLoopControlName", "testActor",
- "testRecipe", "testTarget", "testRequestId", "testSubRequestId", "testMessage", "testOutcome"));
-
- PolicyEngineConstants.getManager().setEnvironmentProperty("guard.disabled", "");
- PolicyEngineConstants.getManager().setEnvironmentProperty("guard.jdbc.url", "jdbc:h2:mem:testCreateDbEntry");
- PolicyEngineConstants.getManager().setEnvironmentProperty("sql.db.username", "user");
- PolicyEngineConstants.getManager().setEnvironmentProperty("sql.db.password", "secret");
- guardContext = new GuardContext(props);
- assertTrue(guardContext.createDbEntry(startTime, endTime, "testClosedLoopControlName", "testActor",
- "testRecipe", "testTarget", "testRequestId", "testSubRequestId", "testMessage", "testOutcome"));
-
- PolicyEngineConstants.getManager().setEnvironmentProperty("guard.disabled", "");
- }
-}
diff --git a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardResultTest.java b/controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardResultTest.java
deleted file mode 100644
index 6fe0f2b50..000000000
--- a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardResultTest.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-
-public class GuardResultTest {
-
- @Test
- public void testGuardResult() {
- assertEquals(3, GuardResult.values().length);
- assertNotNull(GuardResult.LOCK_ACQUIRED);
- assertNotNull(GuardResult.LOCK_DENIED);
- assertNotNull(GuardResult.LOCK_EXCEPTION);
-
- assertEquals(GuardResult.LOCK_ACQUIRED, GuardResult.valueOf("LOCK_ACQUIRED"));
- assertEquals(GuardResult.LOCK_DENIED, GuardResult.valueOf("LOCK_DENIED"));
- assertEquals(GuardResult.LOCK_EXCEPTION, GuardResult.valueOf("LOCK_EXCEPTION"));
- }
-}
diff --git a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardUtilTest.java b/controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardUtilTest.java
deleted file mode 100644
index e17207634..000000000
--- a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/GuardUtilTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-
-import com.google.common.io.Files;
-import java.io.File;
-import java.io.IOException;
-import org.junit.Test;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
-import org.onap.policy.guard.Util.Pair;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-
-public class GuardUtilTest {
- @Test
- public void testLoadYamlOk() throws IOException {
- File tempYamlFile = File.createTempFile("ONAPPF", "yaml");
- tempYamlFile.deleteOnExit();
-
- ControlLoopPolicy clPolicy = new ControlLoopPolicy();
-
- Yaml clYaml = new Yaml(new Constructor(ControlLoopPolicy.class));
- String clYamlString = clYaml.dump(clPolicy);
-
- SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile);
-
- Pair<ControlLoopPolicy, String> result = Util.loadYaml(tempYamlFile.getCanonicalPath());
-
- assertEquals(clPolicy, result.parameterA);
- assertEquals(clYamlString, result.parameterB);
- }
-
- @Test
- public void testLoadYamlError() throws IOException {
- File tempDir = Files.createTempDir();
- tempDir.deleteOnExit();
-
- // Read from a directory forces an IO exception
- assertNull(Util.loadYaml(tempDir.getCanonicalPath()));
- }
-
- @Test
- public void testLoadGuardYamlOk() throws IOException {
- File tempYamlFile = File.createTempFile("ONAPPF", "yaml");
- tempYamlFile.deleteOnExit();
-
- ControlLoopGuard clGuardPolicy = new ControlLoopGuard();
-
- Yaml clYaml = new Yaml(new Constructor(ControlLoopPolicy.class));
- String clYamlString = clYaml.dump(clGuardPolicy);
-
- SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile);
-
- ControlLoopGuard result = Util.loadYamlGuard(tempYamlFile.getCanonicalPath());
-
- assertEquals(clGuardPolicy, result);
- }
-
- @Test
- public void testLoadGuardYamlError() throws IOException {
- File tempDir = Files.createTempDir();
- tempDir.deleteOnExit();
-
- // Read from a directory forces an IO exception
- assertNull(Util.loadYamlGuard(tempDir.getCanonicalPath()));
- }
-
- @Test
- public void testMisc() {
- Util.setGuardEnvProp("Actor", "Judy Garland");
- assertEquals("Judy Garland", Util.getGuardProp("Actor"));
-
- Util.setGuardEnvProps("http://somewhere.over.the.rainbow", "Dorothy", "Toto");
-
- assertEquals("http://somewhere.over.the.rainbow", Util.getGuardProp(Util.PROP_GUARD_URL));
- assertEquals("Dorothy", Util.getGuardProp(Util.PROP_GUARD_USER));
- assertEquals("Toto", Util.getGuardProp(Util.PROP_GUARD_PASS));
- }
-}
diff --git a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardRequestTest.java b/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardRequestTest.java
deleted file mode 100644
index cdc862acb..000000000
--- a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardRequestTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * Modifications Copyright (C) 2019-2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.UUID;
-import org.junit.Test;
-
-public class PolicyGuardRequestTest {
-
- private static final String KANSAS = "Kansas";
- private static final String GET_BACK_HOME = "GetBackHome";
- private static final String DOROTHY = "Dorothy";
-
- @Test
- public void testPolicyGuardRequest() {
- UUID requestId = UUID.randomUUID();
-
- assertNotNull(new PolicyGuardRequest(null, null, null, null));
-
- PolicyGuardRequest request = new PolicyGuardRequest(DOROTHY, KANSAS, requestId, GET_BACK_HOME);
-
- request.setRequestId(requestId);
- assertEquals(requestId, request.getRequestId());
-
- request.setActor(DOROTHY);
- assertEquals(DOROTHY, request.getActor());
-
- request.setTarget(KANSAS);
- assertEquals(KANSAS, request.getTarget());
-
- request.setOperation(GET_BACK_HOME);
- assertEquals(GET_BACK_HOME, request.getOperation());
-
- assertEquals("PolicyGuardRequest [actor=Dorothy", request.toString().substring(0, 33));
- }
-}
diff --git a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardResponseTest.java b/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardResponseTest.java
deleted file mode 100644
index 629555297..000000000
--- a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardResponseTest.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * Modifications Copyright (C) 2019-2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.UUID;
-import org.junit.Test;
-
-public class PolicyGuardResponseTest {
-
- private static final String GET_BACK_HOME = "GetBackHome";
- private static final String BACK_HOME = "BackHome";
-
- @Test
- public void testPolicyGuardResponse() {
- UUID requestId = UUID.randomUUID();
-
- assertNotNull(new PolicyGuardResponse(null, null, null));
-
- PolicyGuardResponse response = new PolicyGuardResponse(BACK_HOME, requestId, GET_BACK_HOME);
-
- response.setRequestId(requestId);
- assertEquals(requestId, response.getRequestId());
-
- response.setResult(BACK_HOME);
- assertEquals(BACK_HOME, response.getResult());
-
- response.setOperation(GET_BACK_HOME);
- assertEquals(GET_BACK_HOME, response.getOperation());
-
- assertEquals("PolicyGuardResponse [requestId=", response.toString().substring(0, 31));
- }
-}
diff --git a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlHelperTest.java b/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlHelperTest.java
deleted file mode 100644
index 47af1fbc6..000000000
--- a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlHelperTest.java
+++ /dev/null
@@ -1,150 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2017-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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.Properties;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.utils.logging.LoggerUtil;
-
-public class PolicyGuardXacmlHelperTest {
-
- private static final String TARGET = "target";
- private static final String REQUEST_ID = "requestId";
- private static final String RECIPE = "recipe";
- private static final String GUARD_URL = "guard.url";
- private static final String ACTOR = "actor";
- private static final Integer VF_COUNT = 100;
-
- /**
- * Set up test class.
- */
- @BeforeClass
- public static void setupSimulator() throws Exception {
- LoggerUtil.setLevel("ROOT", "INFO");
- LoggerUtil.setLevel("org.eclipse.jetty", "WARN");
-
- HttpServletServerFactoryInstance.getServerFactory().destroy();
- org.onap.policy.simulators.Util.buildGuardSim();
-
- //
- // Set guard properties
- //
- org.onap.policy.guard.Util.setGuardEnvProps("http://localhost:6669/policy/pdpx/v1/decision", "python", "test");
- }
-
- /**
- * Shuts down simulator and performs 1 more test for the case where the connection fails.
- */
- @AfterClass
- public static void tearDownSimulator() {
- HttpServletServerFactoryInstance.getServerFactory().destroy();
-
- // Null/ Bad Connection Case
- PolicyGuardXacmlRequestAttributes xacmlReq = new PolicyGuardXacmlRequestAttributes(
- org.onap.policy.simulators.GuardSimulatorJaxRs.DENY_CLNAME, ACTOR, RECIPE, TARGET,
- REQUEST_ID, VF_COUNT);
- String rawDecision = new PolicyGuardXacmlHelper().callPdp(xacmlReq);
- assertNotNull(rawDecision);
- assertEquals(Util.DENY, rawDecision);
- }
-
- @Test
- public void testSimulator() {
- PolicyGuardXacmlRequestAttributes request = new PolicyGuardXacmlRequestAttributes("clname_id", "actor_id",
- "operation_id", "target_id", "request_id", VF_COUNT);
- String xacmlResponse = new PolicyGuardXacmlHelper().callPdp(request);
- assertNotNull(xacmlResponse);
- }
-
- @Test
- /*
- * Tests PolicyGuardXacmlHelper.callPdp method to determine if it returns DENY, PERMIT, or
- * INDETERMINATE as expected.
- */
- public void testCallPdp() {
- // Deny Case
- PolicyGuardXacmlRequestAttributes xacmlReq = new PolicyGuardXacmlRequestAttributes(
- org.onap.policy.simulators.GuardSimulatorJaxRs.DENY_CLNAME, ACTOR, RECIPE, TARGET,
- REQUEST_ID, VF_COUNT);
- String rawDecision = new PolicyGuardXacmlHelper().callPdp(xacmlReq);
- assertNotNull(rawDecision);
- assertEquals(Util.DENY, rawDecision);
-
- // Permit Case
- xacmlReq = new PolicyGuardXacmlRequestAttributes("clname", ACTOR, RECIPE, TARGET, REQUEST_ID, VF_COUNT);
- rawDecision = new PolicyGuardXacmlHelper().callPdp(xacmlReq);
- assertNotNull(rawDecision);
- assertEquals(Util.PERMIT, rawDecision);
-
- // Indeterminate case is in tearDown for efficiency
- }
-
- @Test
- public void testInit() {
- final Properties savedEnvironment = (Properties) PolicyEngineConstants.getManager().getEnvironment().clone();
-
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_URL,
- "http://localhost:6669/pdp/api/getDecision,Dorothy");
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_URL,
- "http://localhost:6669/pdp/api/getDecision,Dorothy,Toto");
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_URL,
- "http://localhost:6969/policy/pdpx/v1/decision");
-
- PolicyEngineConstants.getManager().getEnvironment().setProperty("pdpx.timeout", "thisIsNotANumber");
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().getEnvironment().setProperty("pdpx.timeout", "1000");
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().getEnvironment().remove("pdpx.password");
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().getEnvironment().setProperty("pdpx.username", "python");
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().getEnvironment().setProperty(GUARD_URL, "///");
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().getEnvironment().setProperty("guard.disabled", "");
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().getEnvironment().setProperty("guard.disabled", "true");
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().getEnvironment().clear();
- assertNotNull(new PolicyGuardXacmlHelper());
-
- PolicyEngineConstants.getManager().setEnvironment(savedEnvironment);
- }
-}
diff --git a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributesTest.java b/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributesTest.java
deleted file mode 100644
index 3d49d99c1..000000000
--- a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardXacmlRequestAttributesTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * ================================================================================
- * Modifications Copyright (C) 2018-2020 AT&T. 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.UUID;
-import org.junit.Test;
-
-public class PolicyGuardXacmlRequestAttributesTest {
-
- @Test
- public void testPolicyGuardXacmlRequestAttributes() {
- PolicyGuardXacmlRequestAttributes attributes =
- new PolicyGuardXacmlRequestAttributes(null, null, null, null, null, null);
- assertNotNull(attributes);
-
- UUID requestId = UUID.randomUUID();
- attributes.setRequestId(requestId.toString());
- assertEquals(requestId.toString(), attributes.getRequestId());
-
- UUID operationId = UUID.randomUUID();
- attributes.setOperationId(operationId.toString());
- assertEquals(operationId.toString(), attributes.getOperationId());
-
- UUID actorId = UUID.randomUUID();
- attributes.setActorId(actorId.toString());
- assertEquals(actorId.toString(), attributes.getActorId());
-
- UUID targetId = UUID.randomUUID();
- attributes.setTargetId(targetId.toString());
- assertEquals(targetId.toString(), attributes.getTargetId());
-
- attributes.setTargetId(targetId.toString());
- assertEquals(targetId.toString(), attributes.getTargetId());
-
- UUID controlLoopId = UUID.randomUUID();
- attributes.setClnameId(controlLoopId.toString());
- assertEquals(controlLoopId.toString(), attributes.getClnameId());
-
- attributes.setClnameId(null);
- assertEquals(null, attributes.getClnameId());
-
- Integer vfCount = 20;
- attributes.setVfCount(vfCount);
- assertEquals(vfCount, attributes.getVfCount());
-
- attributes.setVfCount(null);
- assertEquals(null, attributes.getVfCount());
-
- assertEquals("PolicyGuardXacmlRequestAttributes [actorId=", attributes.toString().substring(0, 43));
- }
-}
diff --git a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardYamlToXacmlTest.java b/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardYamlToXacmlTest.java
deleted file mode 100644
index a8110ed04..000000000
--- a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/PolicyGuardYamlToXacmlTest.java
+++ /dev/null
@@ -1,248 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2017-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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.policy.controlloop.policy.guard.Constraint;
-import org.onap.policy.controlloop.policy.guard.ControlLoopGuard;
-import org.onap.policy.controlloop.policy.guard.GuardPolicy;
-import org.onap.policy.controlloop.policy.guard.MatchParameters;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-
-public class PolicyGuardYamlToXacmlTest {
- private static final String SOME_START_TIME = "someStartTime";
- private static final String SOME_END_TIME = "someEndTime";
- private static final String HOURS = "hours";
- private static final String TARGET2 = "WickedWitchOfTheWest";
- private static final String TARGET1 = "Wizard";
- private static final String ONAPPF_FILE = "ONAPPF";
- private static final String RECIPE = "GoToOz";
- private static final String TEXT1 = "WestWitches";
- private static final String TEXT2 = "EastWitches";
- private static final String OUT_XACML = ".out.xacml";
- private ControlLoopGuard clGuard;
-
- /**
- * Set up test cases.
- */
- @Before
- public void createControlLoopGuard() {
- clGuard = new ControlLoopGuard();
- MatchParameters matchParameters = new MatchParameters();
- matchParameters.setControlLoopName("WizardOfOz");
- matchParameters.setActor("Dorothy");
- matchParameters.setRecipe(RECIPE);
- List<String> targets = new ArrayList<>();
- targets.add(TARGET1);
- targets.add(TARGET2);
- matchParameters.setTargets(targets);
- GuardPolicy guardPolicy = new GuardPolicy();
- guardPolicy.setMatch_parameters(matchParameters);
- Constraint limitConstraint = new Constraint();
- limitConstraint.setFreq_limit_per_target(5);
- Map<String, String> timeWindow = new HashMap<>();
- timeWindow.put("value", "10");
- timeWindow.put("units", HOURS);
- limitConstraint.setTime_window(timeWindow);
- Map<String, String> activeTimeRange = new HashMap<>();
- activeTimeRange.put("start", SOME_START_TIME);
- activeTimeRange.put("end", SOME_END_TIME);
- limitConstraint.setActive_time_range(activeTimeRange);
- LinkedList<Constraint> limitConstraints = new LinkedList<>();
- limitConstraints.add(limitConstraint);
- guardPolicy.setLimit_constraints(limitConstraints);
- LinkedList<GuardPolicy> guardList = new LinkedList<>();
- guardList.add(guardPolicy);
- clGuard.setGuards(guardList);
- }
-
- @Test
- public void testGenerateXacmlGuardFull() throws IOException {
- File tempYamlFile = File.createTempFile(ONAPPF_FILE, "yaml");
- tempYamlFile.deleteOnExit();
-
- File tempXacmlTemplateFile = new File("src/test/resources/frequency_limiter_template.xml");
-
- File tempXacmlOutputFile = File.createTempFile(ONAPPF_FILE, OUT_XACML);
- tempXacmlOutputFile.deleteOnExit();
-
- Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class));
- String clYamlString = clYaml.dump(clGuard);
-
- SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile);
- PolicyGuardYamlToXacml.fromYamlToXacml(tempYamlFile.getCanonicalPath(),
- tempXacmlTemplateFile.getCanonicalPath(), tempXacmlOutputFile.getCanonicalPath());
-
- String result = SupportTextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath());
-
- // Assert no mote "${}" are left
- assertFalse(result.contains("${"));
- assertFalse(result.contains("}"));
- // Assert all substitutions are made
- assertTrue(result.contains("cl"));
- assertTrue(result.contains("actor"));
- assertTrue(result.contains(RECIPE));
- assertTrue(result.contains(TARGET1));
- assertTrue(result.contains(TARGET2));
- assertTrue(result.contains("10"));
- assertTrue(result.contains(HOURS));
- assertTrue(result.contains(SOME_START_TIME));
- assertTrue(result.contains(SOME_END_TIME));
- }
-
- @Test
- public void testGenerateXacmlGuardPartial() throws IOException {
- final File tempYamlFile = File.createTempFile(ONAPPF_FILE, "yaml");
- tempYamlFile.deleteOnExit();
-
- final File tempXacmlTemplateFile = new File("src/test/resources/frequency_limiter_template.xml");
-
- final File tempXacmlOutputFile = File.createTempFile(ONAPPF_FILE, OUT_XACML);
- tempXacmlOutputFile.deleteOnExit();
-
- MatchParameters matchParameters = clGuard.getGuards().get(0).getMatch_parameters();
- matchParameters.setControlLoopName(null);
- matchParameters.setActor(null);
- matchParameters.setRecipe(null);
- matchParameters.setTargets(null);
-
- Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class));
- String clYamlString = clYaml.dump(clGuard);
-
- SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile);
- PolicyGuardYamlToXacml.fromYamlToXacml(tempYamlFile.getCanonicalPath(),
- tempXacmlTemplateFile.getCanonicalPath(), tempXacmlOutputFile.getCanonicalPath());
-
- String result = SupportTextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath());
-
- // Assert no mote "${}" are left
- assertFalse(result.contains("${"));
- assertFalse(result.contains("}"));
- // Assert all substitutions are made
- assertTrue(result.contains("cl"));
- assertTrue(result.contains("actor"));
- assertFalse(result.contains(RECIPE));
- assertFalse(result.contains(TARGET1));
- assertFalse(result.contains(TARGET2));
- assertTrue(result.contains("10"));
- assertTrue(result.contains(HOURS));
- assertTrue(result.contains(SOME_START_TIME));
- assertTrue(result.contains(SOME_END_TIME));
- }
-
- @Test
- public void testIsNullOrEmpty() {
- assertTrue(PolicyGuardYamlToXacml.isNullOrEmpty(""));
- assertTrue(PolicyGuardYamlToXacml.isNullOrEmpty(null));
- assertFalse(PolicyGuardYamlToXacml.isNullOrEmpty("hello"));
- }
-
- @Test
- public void testIsNullOrEmptyList() {
- List<String> list = new ArrayList<>();
- assertTrue(PolicyGuardYamlToXacml.isNullOrEmptyList(null));
- assertTrue(PolicyGuardYamlToXacml.isNullOrEmptyList(list));
-
- list.add("hello");
- assertFalse(PolicyGuardYamlToXacml.isNullOrEmptyList(list));
- }
-
- @Test
- public void testGenerateXacmlGuardBlacklist() throws IOException {
- final File tempYamlFile = File.createTempFile(ONAPPF_FILE, "yaml");
- tempYamlFile.deleteOnExit();
-
- final File tempXacmlTemplateFile = new File("src/test/resources/blacklist_template.xml");
-
- final File tempXacmlOutputFile = File.createTempFile(ONAPPF_FILE, OUT_XACML);
- tempXacmlOutputFile.deleteOnExit();
-
- List<String> blacklist = new ArrayList<>();
- blacklist.add(TEXT1);
- blacklist.add(TEXT2);
- clGuard.getGuards().get(0).getLimit_constraints().get(0).setBlacklist(blacklist);
-
- Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class));
- String clYamlString = clYaml.dump(clGuard);
-
- SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile);
- PolicyGuardYamlToXacml.fromYamlToXacmlBlacklist(tempYamlFile.getCanonicalPath(),
- tempXacmlTemplateFile.getCanonicalPath(), tempXacmlOutputFile.getCanonicalPath());
-
- String result = SupportTextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath());
- // Assert no mote "${}" are left
- assertFalse(result.contains("${"));
- assertFalse(result.contains("}"));
- // Assert all substitutions are made
- assertTrue(result.contains(TEXT1));
- assertTrue(result.contains(TEXT2));
- }
-
- @Test
- public void testGenerateXacmlGuardBlacklistPartial() throws IOException {
- final File tempYamlFile = File.createTempFile(ONAPPF_FILE, "yaml");
- tempYamlFile.deleteOnExit();
-
- final File tempXacmlTemplateFile = new File("src/test/resources/blacklist_template.xml");
-
- final File tempXacmlOutputFile = File.createTempFile(ONAPPF_FILE, OUT_XACML);
- tempXacmlOutputFile.deleteOnExit();
-
- List<String> blacklist = new ArrayList<>();
- blacklist.add(TEXT1);
- blacklist.add(TEXT2);
- GuardPolicy guardPolicy = clGuard.getGuards().get(0);
- guardPolicy.getLimit_constraints().get(0).setBlacklist(blacklist);
-
- MatchParameters matchParameters = guardPolicy.getMatch_parameters();
- matchParameters.setControlLoopName(null);
- matchParameters.setActor(null);
- matchParameters.setRecipe(null);
- matchParameters.setTargets(null);
-
- Yaml clYaml = new Yaml(new Constructor(ControlLoopGuard.class));
- String clYamlString = clYaml.dump(clGuard);
-
- SupportTextFileUtils.putStringAsFile(clYamlString, tempYamlFile);
- PolicyGuardYamlToXacml.fromYamlToXacmlBlacklist(tempYamlFile.getCanonicalPath(),
- tempXacmlTemplateFile.getCanonicalPath(), tempXacmlOutputFile.getCanonicalPath());
-
- String result = SupportTextFileUtils.getTextFileAsString(tempXacmlOutputFile.getCanonicalPath());
- // Assert no mote "${}" are left
- assertFalse(result.contains("${"));
- assertFalse(result.contains("}"));
- // Assert all substitutions are made
- assertTrue(result.contains(TEXT1));
- assertTrue(result.contains(TEXT2));
- }
-}
diff --git a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/SupportTextFileUtils.java b/controlloop/m2/guard/src/test/java/org/onap/policy/guard/SupportTextFileUtils.java
deleted file mode 100644
index 98c33c761..000000000
--- a/controlloop/m2/guard/src/test/java/org/onap/policy/guard/SupportTextFileUtils.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * guard
- * ================================================================================
- * Copyright (C) 2018 Ericsson. All rights reserved.
- * Modifications Copyright (C) 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.guard;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import org.drools.core.util.IoUtils;
-
-/**
- * The Class TextFileUtils is class that provides useful functions for handling text files.
- * Functions to read and wrtie text files to strings and strings are provided.
- *
- * @author Liam Fallon (liam.fallon@ericsson.com)
- */
-public class SupportTextFileUtils {
-
- private SupportTextFileUtils() {
- // do nothing
- }
-
- /**
- * Method to return the contents of a text file as a string.
- *
- * @param textFilePath The path to the file as a string
- * @return A string containing the contents of the file
- * @throws IOException on errors reading text from the file
- */
- public static String getTextFileAsString(final String textFilePath) {
- return IoUtils.readFileAsString(new File(textFilePath));
- }
-
- /**
- * Method to write contents of a string to a text file.
- *
- * @param outString The string to write
- * @param textFile The file to write the string to
- * @throws IOException on errors reading text from the file
- */
- public static void putStringAsFile(final String outString, final File textFile) throws IOException {
- try (final FileOutputStream textFileOutputStream = new FileOutputStream(textFile)) {
- textFileOutputStream.write(outString.getBytes(StandardCharsets.UTF_8));
- }
- }
-}
diff --git a/controlloop/m2/guard/src/test/resources/META-INF/persistence.xml b/controlloop/m2/guard/src/test/resources/META-INF/persistence.xml
deleted file mode 100644
index 8e8be4ed2..000000000
--- a/controlloop/m2/guard/src/test/resources/META-INF/persistence.xml
+++ /dev/null
@@ -1,43 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- drools-applications
- ================================================================================
- Copyright (C) 2018-2020 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.
- ============LICENSE_END=========================================================
- -->
-<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence persistence_1_0.xsd" version="1.0">
-
- <!-- In-mem DB for junit -->
- <persistence-unit name="OperationsHistoryPUTest"
- transaction-type="RESOURCE_LOCAL">
- <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
-
- <class>org.onap.policy.guard.OperationsHistory</class>
-
- <properties>
- <property name="eclipselink.ddl-generation" value="create-tables" />
- <property name="eclipselink.logging.level" value="FINE" />
- <property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect"/>
- <property name="javax.persistence.jdbc.driver" value="org.h2.Driver" />
- <property name="javax.persistence.jdbc.url" value="jdbc:h2:mem:testdb;DATABASE_TO_UPPER=FALSE" />
- <property name="javax.persistence.jdbc.user" value="policy" />
- <property name="javax.persistence.jdbc.password" value="P01icY" />
- <property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
- <property name="javax.persistence.schema-generation.create-source" value="metadata"/>
- </properties>
- </persistence-unit>
-
-</persistence>
diff --git a/controlloop/m2/guard/src/test/resources/blacklist_template.xml b/controlloop/m2/guard/src/test/resources/blacklist_template.xml
deleted file mode 100644
index 1563e4a7d..000000000
--- a/controlloop/m2/guard/src/test/resources/blacklist_template.xml
+++ /dev/null
@@ -1,117 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<!--
- ============LICENSE_START=======================================================
- drools-applications
- ================================================================================
- Copyright (C) 2018-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.
- ============LICENSE_END=========================================================
- -->
-<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
- PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069"
- Version="1"
- RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
- <Description>Policy for frequency limiter.</Description>
- <Target>
- <AnyOf>
- <AllOf>
- <Match
- MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">.*</AttributeValue>-->
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
- <AttributeDesignator
- Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
- AttributeId="urn:org:onap:guard:clname:clname-id"
- DataType="http://www.w3.org/2001/XMLSchema#string"
- MustBePresent="false" />
- </Match>
-
- <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
- <Match
- MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
- <AttributeDesignator
- Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
- AttributeId="urn:org:onap:guard:actor:actor-id"
- DataType="http://www.w3.org/2001/XMLSchema#string"
- MustBePresent="false" />
- </Match>
- <Match
- MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
- <AttributeDesignator
- Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
- AttributeId="urn:org:onap:guard:operation:operation-id"
- DataType="http://www.w3.org/2001/XMLSchema#string"
- MustBePresent="false" />
- </Match>
- </AllOf>
- </AnyOf>
- </Target>
- <Rule
- RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21"
- Effect="Deny">
- <Description>DENY - only if target is in black list and guard is
- active.</Description>
- <Condition>
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
- <VariableReference
- VariableId="isGuardActive" />
- <VariableReference
- VariableId="isInBlackList" />
- </Apply>
- </Condition>
- </Rule>
- <VariableDefinition VariableId="isInBlackList">
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:3.0:function:any-of">
- <Function
- FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-equal" />
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-one-and-only">
- <AttributeDesignator
- Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
- AttributeId="urn:org:onap:guard:target:target-id"
- DataType="http://www.w3.org/2001/XMLSchema#string"
- MustBePresent="false" />
- </Apply>
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:1.0:function:string-bag">
- ${blackListElement}
- <!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">vserver.vserver-name</AttributeValue>-->
- </Apply>
- </Apply>
- </VariableDefinition>
- <VariableDefinition VariableId="isGuardActive">
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
- <AttributeDesignator
- AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time"
- DataType="http://www.w3.org/2001/XMLSchema#time"
- Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
- MustBePresent="false" />
- </Apply>
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
- </Apply>
- </VariableDefinition>
-</Policy>
diff --git a/controlloop/m2/guard/src/test/resources/frequency_limiter_template.xml b/controlloop/m2/guard/src/test/resources/frequency_limiter_template.xml
deleted file mode 100644
index d26432f86..000000000
--- a/controlloop/m2/guard/src/test/resources/frequency_limiter_template.xml
+++ /dev/null
@@ -1,127 +0,0 @@
-<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
-<!--
- ============LICENSE_START=======================================================
- drools-applications
- ================================================================================
- Copyright (C) 2018-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.
- ============LICENSE_END=========================================================
- -->
-<Policy xmlns="urn:oasis:names:tc:xacml:3.0:core:schema:wd-17"
- PolicyId="urn:com:att:xacml:policy:id:25e12b06-11d5-4895-b2a2-6f6c594de069"
- Version="1"
- RuleCombiningAlgId="urn:oasis:names:tc:xacml:3.0:rule-combining-algorithm:permit-unless-deny">
- <Description>Policy for frequency limiter.</Description>
- <Target>
- <AnyOf>
- <AllOf>
-
- <Match
- MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <!-- <AttributeValue DataType="http://www.w3.org/2001/XMLSchema#string">.*</AttributeValue>-->
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#string">${clname}</AttributeValue>
- <AttributeDesignator
- Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
- AttributeId="urn:org:onap:guard:clname:clname-id"
- DataType="http://www.w3.org/2001/XMLSchema#string"
- MustBePresent="false" />
- </Match>
-
- <!-- <Match MatchId="urn:oasis:names:tc:xacml:1.0:function:string-equal">-->
- <Match
- MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#string">${actor}</AttributeValue>
- <AttributeDesignator
- Category="urn:oasis:names:tc:xacml:1.0:subject-category:access-subject"
- AttributeId="urn:org:onap:guard:actor:actor-id"
- DataType="http://www.w3.org/2001/XMLSchema#string"
- MustBePresent="false" />
- </Match>
- <Match
- MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#string">${recipe}</AttributeValue>
- <AttributeDesignator
- Category="urn:oasis:names:tc:xacml:3.0:attribute-category:action"
- AttributeId="urn:org:onap:guard:operation:operation-id"
- DataType="http://www.w3.org/2001/XMLSchema#string"
- MustBePresent="false" />
- </Match>
-
- <Match
- MatchId="urn:oasis:names:tc:xacml:1.0:function:string-regexp-match">
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#string">${targets}</AttributeValue>
- <AttributeDesignator
- Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
- AttributeId="urn:org:onap:guard:target:target-id"
- DataType="http://www.w3.org/2001/XMLSchema#string"
- MustBePresent="false" />
- </Match>
-
- </AllOf>
- </AnyOf>
- </Target>
- <Rule
- RuleId="urn:com:att:xacml:rule:id:e1e8c5c0-e2ba-47d5-9289-6c015305ed21"
- Effect="Deny">
- <Description>DENY - only if number of operations performed in
- the past is larger than the limit and the Guard is active.</Description>
- <Condition>
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:1.0:function:and">
- <VariableReference
- VariableId="isGuardActive" />
- <VariableReference
- VariableId="isHistoryGreaterThanLimit" />
- </Apply>
- </Condition>
- </Rule>
- <VariableDefinition VariableId="isGuardActive">
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:2.0:function:time-in-range">
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:1.0:function:time-one-and-only">
- <AttributeDesignator
- AttributeId="urn:oasis:names:tc:xacml:1.0:environment:current-time"
- DataType="http://www.w3.org/2001/XMLSchema#time"
- Category="urn:oasis:names:tc:xacml:3.0:attribute-category:environment"
- MustBePresent="false" />
- </Apply>
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveStart}</AttributeValue>
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#time">${guardActiveEnd}</AttributeValue>
- </Apply>
- </VariableDefinition>
- <VariableDefinition
- VariableId="isHistoryGreaterThanLimit">
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-greater-than-or-equal">
- <Apply
- FunctionId="urn:oasis:names:tc:xacml:1.0:function:integer-one-and-only">
- <AttributeDesignator
- Category="urn:oasis:names:tc:xacml:3.0:attribute-category:resource"
- AttributeId="com:att:research:xacml:test:sql:resource:operations:count"
- DataType="http://www.w3.org/2001/XMLSchema#integer"
- Issuer="com:att:research:xacml:guard:historydb:tw:${twValue}:${twUnits}"
- MustBePresent="false" />
- </Apply>
- <AttributeValue
- DataType="http://www.w3.org/2001/XMLSchema#integer">${limit}</AttributeValue>
- </Apply>
- </VariableDefinition>
-</Policy>
diff --git a/controlloop/m2/lock/pom.xml b/controlloop/m2/lock/pom.xml
deleted file mode 100644
index a6aa87a50..000000000
--- a/controlloop/m2/lock/pom.xml
+++ /dev/null
@@ -1,50 +0,0 @@
-<?xml version="1.0"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <parent>
- <artifactId>m2</artifactId>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <version>1.7.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>lock</artifactId>
- <name>lock</name>
- <description>Generic Lock used for Locking Target Entities</description>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>base</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-management</artifactId>
- <version>${version.policy.drools-pdp}</version>
- <scope>provided</scope>
- </dependency>
-
- </dependencies>
-
-</project>
diff --git a/controlloop/m2/lock/src/main/java/org/onap/policy/drools/m2/lock/LockAdjunct.java b/controlloop/m2/lock/src/main/java/org/onap/policy/drools/m2/lock/LockAdjunct.java
deleted file mode 100644
index 937317cfa..000000000
--- a/controlloop/m2/lock/src/main/java/org/onap/policy/drools/m2/lock/LockAdjunct.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/lock
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.m2.lock;
-
-import java.io.Serializable;
-import org.onap.policy.drools.core.lock.Lock;
-import org.onap.policy.drools.core.lock.LockCallback;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.m2.base.Transaction;
-
-/*
- * Adjunct data placed within the transaction, to contain locks
- * on control loop use case basis. This same instance is shared
- * among all actor operation instances within the transaction
- * regardless of what actor is in the policy chain. As a result,
- * the lock gets passed from one to the next, and is only freed
- * when the transaction completes.
- */
-public class LockAdjunct implements Transaction.Adjunct, LockCallback,
- Serializable {
- private static final long serialVersionUID = 1L;
-
- /**
- * This is the callback interface, which is only used if the lock is
- * initially not available, and we end up waiting for it.
- */
- public interface Requestor {
- /**
- * This method is called once the lock has been acquired.
- */
- void lockAvailable();
-
- /**
- * This method is called to notify the requestor that the lock could not
- * be obtained.
- */
- void lockUnavailable();
- }
-
- // lock associated with all of the AOTS and SDNR operations
- // within the transaction
- private Lock lock = null;
-
- // the initial requestor of the lock
- // (only set if we don't immediately acquire the lock)
- private Requestor requestor = null;
-
- /**
- * allocate a lock on behalf of the requestor.
- *
- * @param requestor
- * the AOTS or SDNR operation requesting the lock
- * @param key
- * string key identifying the lock
- * @param ownerKey
- * string key identifying the owner
- * @param waitForLock
- * used to determine if an operation should wait for a lock to
- * become available or fail immediately
- * @return 'true' if we immediately acquired the lock, 'false' if the lock
- * is currently in use by another transaction, and we need to wait
- */
- public boolean getLock(Requestor requestor, String key, String ownerKey,
- boolean waitForLock) {
- if (lock != null) {
- if (lock.isActive()) {
- // we already have an active lock
- return true;
- }
-
- // We may have timed out earlier waiting for the lock, or
- // we may have lost the lock after persistent restore. In
- // any case, free the lock we have now, and allocate a new one.
- lock.free();
- }
-
- // register the requestor in case the lockUnavailable() callback runs
- // immediately. Previously the requestor would be set after the
- // lock constructor ran but now the lockUnavailable() callback
- // could be executed while the constructor is still on the stack which
- // would result in a null requestor, thus the callback never
- // notifying the requestor that the lock was unavailable.
- this.requestor = requestor;
-
- // try to allocate a new lock
- lock = PolicyEngineConstants.getManager().createLock(
- key, ownerKey, 600, this, waitForLock);
- // return the boolean value of the lock.isactive
- return lock.isActive();
- }
-
- /*=================================*/
- /* 'Transaction.Adjunct' interface */
- /*=================================*/
-
- /**
- * Notification that the transaction has completed.
- *
- * {@inheritDoc}
- */
- @Override
- public void cleanup(Transaction transaction) {
- if (lock != null) {
- // free the lock or cancel the reservation
- lock.free();
- }
- }
-
- /*==========================*/
- /* 'LockCallback' interface */
- /*==========================*/
-
- /**
- * Notification that the lock is available.
- *
- * {@inheritDoc}
- */
- @Override
- public void lockAvailable(Lock lock) {
- this.lock = lock;
- if (requestor != null) {
- // notify requestor
- requestor.lockAvailable();
- }
- }
-
- /**
- * Notification that the lock is not available.
- *
- * {@inheritDoc}
- */
- @Override
- public void lockUnavailable(Lock lock) {
- this.lock = lock;
- if (requestor != null) {
- // notify requestor
- requestor.lockUnavailable();
- }
- }
-}
diff --git a/controlloop/m2/lock/src/test/java/org/onap/policy/drools/m2/lock/LockAdjunctTest.java b/controlloop/m2/lock/src/test/java/org/onap/policy/drools/m2/lock/LockAdjunctTest.java
deleted file mode 100644
index 2b4a29b34..000000000
--- a/controlloop/m2/lock/src/test/java/org/onap/policy/drools/m2/lock/LockAdjunctTest.java
+++ /dev/null
@@ -1,90 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/lock
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.drools.m2.lock;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Properties;
-import java.util.UUID;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.drools.core.lock.Lock;
-import org.onap.policy.drools.core.lock.LockCallback;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.m2.base.Transaction;
-
-public class LockAdjunctTest {
-
- public class TestOwner implements LockCallback {
-
- @Override
- public void lockAvailable(Lock arg0) {
- return;
- }
-
- @Override
- public void lockUnavailable(Lock arg0) {
- return;
- }
- }
-
- private LockCallback owner;
- private Lock lock;
-
- @BeforeClass
- public static void start() {
- PolicyEngineConstants.getManager().configure(new Properties());
- PolicyEngineConstants.getManager().start();
- }
-
- @AfterClass
- public static void stop() {
- PolicyEngineConstants.getManager().stop();
- }
-
- @Test
- public void testLockAdjunct() {
- owner = new TestOwner();
- lock = PolicyEngineConstants.getManager().createLock("key", "ownerKey", 60, owner, false);
- LockAdjunct lockA = new LockAdjunct();
-
- assertNotNull(lockA);
-
- lockA.lockUnavailable(lock);
- assertTrue(lock.isActive());
- assertTrue(lockA.getLock(null, "key", "ownerKey", false));
- LockAdjunct lockB = new LockAdjunct();
- assertFalse(lockB.getLock(null, "key", "ownerKey", false));
- assertTrue(lock.free());
-
- lockB.lockAvailable(lock);
- assertFalse(lock.isActive());
- assertTrue(lockB.getLock(null, "key", "ownerKey", false));
- assertFalse(lock.free());
-
- UUID uuid = UUID.randomUUID();
- Transaction transaction = new Transaction(null, "1111", uuid, null);
- lockA.cleanup(transaction);
- }
-}
diff --git a/controlloop/m2/pom.xml b/controlloop/m2/pom.xml
deleted file mode 100644
index bdf82d5e4..000000000
--- a/controlloop/m2/pom.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<?xml version="1.0"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
-
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-applications.controlloop</groupId>
- <artifactId>controlloop</artifactId>
- <version>1.7.1-SNAPSHOT</version>
- </parent>
-
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>m2</artifactId>
-
- <name>M2 Control Loop Model</name>
- <packaging>pom</packaging>
-
- <modules>
- <module>util</module>
- <module>guard</module>
- <module>base</module>
- <module>appclcm</module>
- <module>lock</module>
- <module>adapters</module>
- <module>test</module>
- <module>feature-controlloop-m2</module>
- </modules>
-
-</project>
diff --git a/controlloop/m2/test/pom.xml b/controlloop/m2/test/pom.xml
deleted file mode 100644
index ee610711b..000000000
--- a/controlloop/m2/test/pom.xml
+++ /dev/null
@@ -1,95 +0,0 @@
-<?xml version="1.0"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>m2</artifactId>
- <version>1.7.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>test</artifactId>
-
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <executions>
- <execution>
- <id>default-test</id>
- <configuration>
- <systemPropertyVariables>
- <project.version>${project.version}</project.version>
- </systemPropertyVariables>
- </configuration>
- <goals>
- <goal>test</goal>
- </goals>
- </execution>
- </executions>
- <configuration>
- <skip>false</skip>
- </configuration>
- </plugin>
- </plugins>
- </build>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-core</artifactId>
- <version>${version.policy.drools-pdp}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-management</artifactId>
- <version>${version.policy.drools-pdp}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>feature-drools-init</artifactId>
- <version>${version.policy.drools-pdp}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.models.policy-models-interactions</groupId>
- <artifactId>model-yaml</artifactId>
- <version>${policy.models.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>appclcm</artifactId>
- <version>${project.version}</version>
- <scope>test</scope>
- </dependency>
-
- </dependencies>
-</project>
diff --git a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java b/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java
deleted file mode 100644
index 31003cba3..000000000
--- a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/AppcLcmTest.java
+++ /dev/null
@@ -1,333 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/test
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.test;
-
-import static org.awaitility.Awaitility.await;
-import static org.junit.Assert.assertNotNull;
-import static org.onap.policy.guard.Util.ONAP_KEY_PASS;
-import static org.onap.policy.guard.Util.ONAP_KEY_URL;
-import static org.onap.policy.guard.Util.ONAP_KEY_USER;
-import static org.onap.policy.guard.Util.PROP_GUARD_URL;
-import static org.onap.policy.m2.test.Util.assertSubset;
-import static org.onap.policy.m2.test.Util.json;
-
-import com.google.gson.JsonObject;
-import java.io.File;
-import java.time.Duration;
-import java.util.Properties;
-import java.util.UUID;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicReference;
-import org.awaitility.Durations;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.onap.policy.drools.system.PolicyController;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.drools.util.KieUtils;
-import org.onap.policy.drools.utils.PropertyUtil;
-import org.onap.policy.m2.test.Util.Input;
-import org.onap.policy.m2.test.Util.Output;
-
-public class AppcLcmTest {
- private static String closedLoopControlName = null;
- private static Output dcae = null;
- private static Output appcResponse = null;
- private static Input notification = null;
- private static Input appcRequest = null;
- private static Properties properties = null;
- private static PolicyController policyController = null;
-
- /**
- * Initialization method, which creates the following:
- * 1) VUSPLCM artifact
- * 2) The associated PolicyController and Drools session
- * 3) DMAAP/UEB topic writers and readers
- * .
- */
- @BeforeClass
- public static void init() throws Exception {
- Util.commonInit();
-
- String projectVersion = System.getProperty("project.version");
- assertNotNull(projectVersion);
- closedLoopControlName = "appclcm-" + UUID.randomUUID().toString();
-
- File kmodule = new File("src/test/resources/appclcm/kmodule.xml");
-
- String pom = Util.openAndReplace("src/test/resources/appclcm/pom.xml",
- "${project.version}", projectVersion);
-
- String yaml = Util.fileToString(new File("src/test/resources/appclcm/CLRulevUSPAPPCLCMGuardTemplate.yaml"));
-
- // build a '.drl' file (as a String), by replacing '${variable}' names
- String drl = Util.openAndReplace(
- "src/test/resources/appclcm/M2CLRulevUSPAPPCLCMGuardTemplate.drl",
- "${closedLoopControlName}", closedLoopControlName,
- "${controlLoopYaml}", Util.convertYaml(yaml),
- "${notificationTopic}", "NOTIFICATION-APPCLCM-TOPIC",
- "${operationTopic}", "APPC-REQUEST-APPCLCM-TOPIC",
- "${policyName}", "appclcm",
- "${policyScope}", "service=vUSP;resource=vCTS;type=operational",
- "${policyVersion}",
- "org.onap.policy.m2.test:appclcm:" + projectVersion,
- "${unique}", "2");
-
- // this creates the JAR file, and installs it in the local repository
- KieUtils.installArtifact(kmodule, Util.stringToFile(pom, ".xml"),
- "src/main/resources/rules/rules.drl", Util.stringToFile(drl, ".drl"));
-
- properties = PropertyUtil.getProperties("src/test/resources/appclcm/controller.properties");
- properties.setProperty("rules.version", projectVersion);
- //properties.setProperty("pdpx.username", "");
- //properties.setProperty("pdpx.password", "");
-
- // create PolicyController, which creates the Drools session
- PolicyEngineConstants.getManager().setEnvironmentProperty(PROP_GUARD_URL, "http://127.0.0.1:8443/pdp/");
- PolicyEngineConstants.getManager().setEnvironmentProperty(ONAP_KEY_URL, "jdbc:h2:file:./H2DB");
- PolicyEngineConstants.getManager().setEnvironmentProperty(ONAP_KEY_USER, "sa");
- PolicyEngineConstants.getManager().setEnvironmentProperty(ONAP_KEY_PASS, "");
- policyController =
- PolicyEngineConstants.getManager().createPolicyController("appclcm", properties);
- policyController.start();
-
- // create writers
- dcae = new Output("org.onap.DCAE-APPCLCM-TOPIC");
- appcResponse = new Output("APPC-RESPONSE-APPCLCM-TOPIC");
-
- // create readers
- notification = new Input("NOTIFICATION-APPCLCM-TOPIC");
- appcRequest = new Input("APPC-REQUEST-APPCLCM-TOPIC");
- }
-
- /**
- * Clean up.
- */
- @AfterClass
- public static void cleanup() {
- // close readers
- notification.close();
- appcRequest.close();
-
- // close writers
- dcae.close();
- appcResponse.close();
-
- // shut down PolicyController and Drools session
- policyController.stop();
- PolicyEngineConstants.getManager().stop();
-
- // clean up REST servers
- Util.commonShutdown();
- }
-
- /**
- * This is a sunny-day scenario.
- */
- @Test
- public void sunnyDayTest() throws Exception {
- Request req = new Request();
-
- // send initial ONSET message
- dcae.send(req.msg);
-
- // receive active notification, and restart operation
- awaitAndAssert(10, Durations.TWO_HUNDRED_MILLISECONDS, notification,
- json("notification", "ACTIVE"));
-
- appcOperation(req, "Restart", 400, "Restart Successful");
-
- // send ABATED
- req.msg.addProperty("closedLoopEventStatus", "ABATED");
- dcae.send(req.msg);
-
- // receive final success notification
- awaitAndAssert(10, Durations.TWO_HUNDRED_MILLISECONDS, notification,
- json("notification", "FINAL: SUCCESS"));
-
- // sleep to allow DB update
- Thread.sleep(1000);
- }
-
- /**
- * In this scenario, all requests fail until the final 'Evacuate'.
- */
- @Test
- public void initialFailure() throws Exception {
- Request req = new Request();
-
- // send initial ONSET message
- dcae.send(req.msg);
-
- // active notification, and restart 1 operation
- awaitAndAssert(10, Durations.TWO_HUNDRED_MILLISECONDS, notification,
- json("notification", "ACTIVE"));
-
- appcOperation(req, "Restart", 450, "Restart 1 Failed");
- appcOperation(req, "Restart", 450, "Restart 2 Failed");
- appcOperation(req, "Rebuild", 450, "Rebuild Failed");
- appcOperation(req, "Migrate", 450, "Migrate Failed");
- appcOperation(req, "Evacuate", 400, "Evacuate Successful");
-
- // send ABATED
- req.msg.addProperty("closedLoopEventStatus", "ABATED");
- dcae.send(req.msg);
-
- // receive final success notification
- awaitAndAssert(10, Durations.TWO_HUNDRED_MILLISECONDS, notification,
- json("notification", "FINAL: SUCCESS"));
-
- // sleep to allow DB update
- Thread.sleep(1000);
- }
-
- private void awaitAndAssert(int maxWaitSecond, Duration pollIntervalMilli, Input notification,
- JsonObject jsonObj) {
- AtomicReference<JsonObject> obj = new AtomicReference<>();
- await().atMost(maxWaitSecond, TimeUnit.SECONDS)
- .with().pollInterval(pollIntervalMilli)
- .until(() -> {
- obj.set(notification.poll());
- return obj.get() != null;
- });
- assertSubset(jsonObj, obj.get());
- }
-
- private void appcOperation(Request req, String name, int responseCode, String responseMessage)
- throws Exception {
- String lcName = name.toLowerCase();
- assertSubset(json("notification", "OPERATION",
- "message", ".*operation=" + name + ",.*"),
- notification.poll());
-
- // receive request
- JsonObject opRequest = appcRequest.poll();
- assertSubset(json("version", "2.0",
- "rpc-name", lcName,
- "correlation-id", ".*",
- "type", "request",
- "body",
- json("input", json("common-header",
- json("request-id", req.requestId),
- "action", name
- ))),
- opRequest);
-
- // send response
- JsonObject ch = opRequest
- .getAsJsonObject("body")
- .getAsJsonObject("input")
- .getAsJsonObject("common-header");
- JsonObject opResponse =
- json("correlation-id", opRequest.get("correlation-id"),
- "body", json("output",
- json("common-header",
- json("flags", json(),
- "api-ver", "2.00",
- "originator-id", ch.get("originator-id"),
- "sub-request-id", ch.get("sub-request-id"),
- "request-id", req.requestId,
- "timestamp", ch.get("timestamp")
- ),
- "status",
- json("code", responseCode,
- "message", responseMessage
- ))),
- "type", "response",
- "version", "2.0",
- "rpc-name", lcName
- );
- appcResponse.send(opResponse);
-
- // receive success or failure notification
- String expectedNotification =
- (responseCode == 400 ? "OPERATION: SUCCESS" : "OPERATION: FAILURE");
- assertSubset(json("notification", expectedNotification,
- "message", ".*operation=" + name + ",.*"),
- notification.poll());
- }
-
- /* ============================================================ */
-
- /**
- * An instance of this class is created for each Transaction. It allocates
- * any identifiers, such as 'requestId', and creates the initial ONSET
- * message.
- */
- class Request {
- String requestId;
- String triggerId;
- JsonObject msg;
-
- Request() {
- long time = System.currentTimeMillis();
- requestId = UUID.randomUUID().toString();
- triggerId = "trigger-" + time;
-
- msg = json("closedLoopEventClient", "configuration.dcae.microservice.stringmatcher.xml",
- "policyVersion", "1610",
- "triggerSourceName", "ctsf0002vm014",
- "policyName", "vUSP_vCTS_CL_7.Config_MS_ClosedLoop_"
- + "104b1445_6b30_11e7_852e_0050568c4ccf_StringMatch_1wo2qh0",
- "policyScope", "resource=F5,service=vSCP,type=configuration,"
- + "closedLoopControlName=vSCP_F5_Firewall_d925ed73-8231-4d02-9545-db4e101f88f8",
- "triggerID", triggerId,
- "target_type", "VM",
- "AAI",
- json("vserver.l-interface.l3-interface-ipv6-address-list.l3-inteface-ipv6-address", null,
- "vserver.selflink", "https://compute-aic.dpa3.cci.att.com:8774/v2/d0719b845a804b368f8ac0bba39e188b/servers/7953d05b-6698-4aa6-87bd-39bed606133a",
- "vserver.is-closed-loop-disabled", "false",
- "vserver.l-interface.network-name", "vUSP_DPA3_OAM_3750",
- "vserver.l-interface.l3-interface-ipv4-address-list.l3-inteface-ipv4-address", //continues
- "135.144.3.50",
- "vserver.vserver-id", "78fe4342-8f85-49ba-be9f-d0c1bdf1ba7b",
- "generic-vnf.service-id", "e433710f-9217-458d-a79d-1c7aff376d89",
- "complex.city", "AAIDefault",
- "vserver.in-maint", "N",
- "complex.state", "NJ",
- "vserver.vserver-name", "ctsf0002vm025",
- "complex.physical-location-id", "LSLEILAA",
- "tenant.tenant-id", "d0719b845a804b368f8ac0bba39e188b",
- "vserver.prov-status", "PROV",
- "generic-vnf.vnf-name", "ctsf0002v",
- "vserver.l-interface.interface-name", // continues
- "ctsf0002v-ALU-LCP-Pair07-oziwyxlxwdyc-1-a4psuz5awjw7-ALU-LCP-ETH2-ygmny7m7rpb5",
- "generic-vnf.vnf-type", "vUSP-vCTS",
- "cloud-region.identity-url", "https://auth.pdk11.cci.att.com:5000/v2.0"
- ),
- "closedLoopAlarmStart", "1507143409107000",
- "closedLoopEventStatus", "ONSET",
- "closedLoopControlName", closedLoopControlName,
- "version", "1.0.2",
- "target", "vserver.vserver-name",
- "resourceInstance", json("resourceName", "",
- "resourceInstanceName", ""
- ),
- "requestID", requestId,
- "from", "DCAE",
- "serviceInstance", json("serviceInstanceName", "",
- "serviceName", ""
- )
- );
- }
- }
-}
diff --git a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/SimDmaap.java b/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/SimDmaap.java
deleted file mode 100644
index 1c11fccdb..000000000
--- a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/SimDmaap.java
+++ /dev/null
@@ -1,264 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/test
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.test;
-
-import java.util.Map;
-import java.util.concurrent.BlockingQueue;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.PathParam;
-import javax.ws.rs.Produces;
-import javax.ws.rs.QueryParam;
-import javax.ws.rs.core.MediaType;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * This class simulates a UEB/DMAAP server.
- */
-
-@Path("/")
-public class SimDmaap {
- private static Logger logger = LoggerFactory.getLogger(SimDmaap.class);
-
- // maps topic name to 'Topic' instance
- static Map<String, Topic> topicTable = new ConcurrentHashMap<>();
-
- /**
- * Each instance of this class corresponds to a DMAAP or UEB topic.
- */
- static class Topic {
- // topic name
- String topic;
-
- // maps group name into group instance
- Map<String, Group> groupTable = new ConcurrentHashMap<>();
-
- /**
- * Create or get a Topic.
- *
- * @param name the topic name
- * @return the associated Topic instance
- */
- static Topic createOrGet(String name) {
- // look up the topic name
- Topic topicObj = topicTable.get(name);
- if (topicObj == null) {
- // no entry found -- the following will create one, without
- // the need for explicit synchronization
- topicTable.putIfAbsent(name, new Topic(name));
- topicObj = topicTable.get(name);
- }
- return topicObj;
- }
-
- /**
- * Constructor - initialize the 'topic' field.
- *
- * @param topic the topic name
- */
- private Topic(String topic) {
- this.topic = topic;
- }
-
- /**
- * Handle an incoming '/events/{topic}' POST REST message.
- *
- * @param the body of the REST message
- * @return the appropriate JSON response
- */
- String post(String data) {
- // start of message processing
- long startTime = System.currentTimeMillis();
-
- // current and ending indices to the 'data' field
- int cur = 0;
- int end = data.length();
-
- // the number of messages retrieved so far
- int messageCount = 0;
-
- while (cur < end) {
- // The body of the message may consist of multiple JSON messages,
- // each preceded by 3 integers separated by '.'. The second one
- // is the length, in bytes (the third seems to be some kind of
- // channel identifier).
-
- int leftBrace = data.indexOf('{', cur);
- if (leftBrace < 0) {
- // no more messages
- break;
- }
- String[] prefix = data.substring(cur, leftBrace).split("\\.");
- if (prefix.length == 3) {
- try {
- // determine length of message, and advance current position
- int length = Integer.parseInt(prefix[1]);
- cur = leftBrace + length;
-
- // extract message, and update count -- each '\' is converted
- // to '\\', and each double quote has a '\' character placed
- // before it, so the overall message can be placed in double
- // quotes, and parsed as a literal string
- String message = data.substring(leftBrace, cur)
- .replace("\\", "\\\\").replace("\"", "\\\"")
- .replace("\n", "\\n");
- messageCount += 1;
-
- // send to all listening groups
- for (Group group : groupTable.values()) {
- group.messages.add(message);
- }
- } catch (Exception e) {
- logger.info("{}: {}", prefix[1], e);
- break;
- }
- } else if (cur == 0) {
- // there is only a single message -- extract it, and update count
- String message = data.substring(leftBrace, end)
- .replace("\\", "\\\\").replace("\"", "\\\"")
- .replace("\n", "\\n");
- messageCount += 1;
-
- // send to all listening grops
- for (Group group : groupTable.values()) {
- group.messages.add(message);
- }
- break;
- } else {
- // don't know what this is -- toss it
- break;
- }
- }
-
- // generate response message
- long elapsedTime = System.currentTimeMillis() - startTime;
- return "{\n"
- + " \"count\": " + messageCount + ",\n"
- + " \"serverTimeMs\": " + elapsedTime + "\n"
- + "}";
- }
-
- /**
- * read one or more incoming messages.
- *
- * @param group the 'consumerGroup' value
- * @param timeout how long to wait for a message, in milliseconds
- * @param limit the maximum number of messages to receive
- * @return a JSON array, containing 0-limit messages
- */
- String get(String group, long timeout, int limit)
- throws InterruptedException {
- // look up the group -- create one if it doesn't exist
- Group groupObj = groupTable.get(group);
- if (groupObj == null) {
- // no entry found -- the following will create one, without
- // the need for explicit synchronization
- groupTable.putIfAbsent(group, new Group());
- groupObj = groupTable.get(group);
- }
-
- // pass it on to the 'Group' instance
- return groupObj.get(timeout, limit);
- }
- }
-
- /* ============================================================ */
-
- /**
- * Each instance of this class corresponds to a Consumer Group.
- */
- static class Group {
- // messages queued for this group
- private BlockingQueue<String> messages = new LinkedBlockingQueue<>();
-
- /**
- * Retrieve messages sent to this group.
- *
- * @param timeout how long to wait for a message, in milliseconds
- * @param limit the maximum number of messages to receive
- * @return a JSON array, containing 0-limit messages
- */
- String get(long timeout, int limit) throws InterruptedException {
- String message = messages.poll(timeout, TimeUnit.MILLISECONDS);
- if (message == null) {
- // timed out without messages
- return "[]";
- }
-
- // use 'StringBuilder' to assemble the response -- add the first message
- StringBuilder builder = new StringBuilder();
- builder.append("[\"").append(message);
-
- // add up to '<limit>-1' more messages
- for (int i = 1; i < limit; i += 1) {
- // fetch the next message -- don't wait if it isn't currently there
- message = messages.poll();
- if (message == null) {
- // no more currently available
- break;
- }
- builder.append("\",\"").append(message);
- }
- builder.append("\"]");
- return builder.toString();
- }
- }
-
- /* ============================================================ */
-
- /**
- * Process an HTTP POST to /events/{topic}.
- */
- @POST
- @Path("/events/{topic}")
- @Consumes("application/cambria")
- @Produces(MediaType.APPLICATION_JSON)
- public String send(@PathParam("topic") String topic,
- String data) {
- logger.info("Send: topic={}", topic);
- return Topic.createOrGet(topic).post(data);
- }
-
- /**
- * Process an HTTP GET to /events/{topic}/{group}/{id}.
- */
- @GET
- @Path("/events/{topic}/{group}/{id}")
- @Consumes(MediaType.TEXT_PLAIN)
- @Produces(MediaType.APPLICATION_JSON)
- public String receive(@PathParam("topic") String topic,
- @PathParam("group") String group,
- @PathParam("id") String id,
- @QueryParam("timeout") long timeout,
- @QueryParam("limit") int limit)
- throws InterruptedException {
-
- logger.info("Receive: topic={}, group={}, id={}, timeout={}, limit={}",
- topic, group, id, timeout, limit);
- return Topic.createOrGet(topic).get(group, timeout, limit);
- }
-}
diff --git a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/SimGuard.java b/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/SimGuard.java
deleted file mode 100644
index 67df8503a..000000000
--- a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/SimGuard.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/test
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.test;
-
-import com.google.gson.JsonObject;
-import javax.ws.rs.Consumes;
-import javax.ws.rs.POST;
-import javax.ws.rs.Path;
-import javax.ws.rs.Produces;
-import javax.ws.rs.core.MediaType;
-import org.onap.policy.common.utils.coder.CoderException;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * minimal Guard Simulator -- just enough to support the current tests.
- */
-@Path("/")
-public class SimGuard {
- private static Logger logger = LoggerFactory.getLogger(SimGuard.class);
-
- // used for JSON <-> String conversion
- private static StandardCoder coder = new StandardCoder();
-
- /**
- * Process an HTTP POST to /pdp/.
- */
- @POST
- @Path("/pdp/")
- @Consumes(MediaType.APPLICATION_JSON)
- @Produces(MediaType.APPLICATION_JSON)
- public String query(String data) throws CoderException {
-
- JsonObject msg = coder.decode(data, JsonObject.class);
- logger.info("SimGuard query:\n{}", Util.prettyPrint(msg));
-
- JsonObject response = new JsonObject();
- response.addProperty("status", "Permit");
- logger.info("Returning:\n{}", Util.prettyPrint(response));
-
- return response.toString();
- }
-}
diff --git a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/Util.java b/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/Util.java
deleted file mode 100644
index f6740f83b..000000000
--- a/controlloop/m2/test/src/test/java/org/onap/policy/m2/test/Util.java
+++ /dev/null
@@ -1,500 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/test
- * ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2020 Bell Canada.
- * ================================================================================
- * 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.m2.test;
-
-import static org.junit.Assert.assertTrue;
-
-import com.att.nsa.cambria.client.CambriaBatchingPublisher;
-import com.att.nsa.cambria.client.CambriaClientBuilders;
-import com.att.nsa.cambria.client.CambriaClientBuilders.ConsumerBuilder;
-import com.att.nsa.cambria.client.CambriaClientBuilders.PublisherBuilder;
-import com.att.nsa.cambria.client.CambriaConsumer;
-import com.google.gson.Gson;
-import com.google.gson.GsonBuilder;
-import com.google.gson.JsonElement;
-import com.google.gson.JsonObject;
-import com.google.gson.JsonPrimitive;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Properties;
-import java.util.UUID;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.TimeUnit;
-import org.eclipse.jetty.server.Server;
-import org.eclipse.jetty.server.ServerConnector;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.servlet.ServletHolder;
-import org.onap.policy.common.utils.coder.StandardCoder;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class Util {
- private static Logger logger = LoggerFactory.getLogger(Util.class);
-
- // used for JSON <-> String conversion
- private static StandardCoder coder = new StandardCoder();
-
- // used for pretty-printing: gson.toJson(JsonObject obj)
- private static Gson gson =
- new GsonBuilder().setPrettyPrinting().serializeNulls().create();
-
- // contains the currently running set of servers
- private static List<Server> runningServers = new LinkedList<>();
-
- /**
- * Read from an 'InputStream' until EOF or until it is closed. This method
- * may block, depending on the type of 'InputStream'.
- *
- * @param input This is the input stream
- * @return A 'String' containing the contents of the input stream
- */
- public static String inputStreamToString(InputStream input) {
- StringBuilder sb = new StringBuilder();
- byte[] buffer = new byte[8192];
- int length;
-
- try {
- while ((length = input.read(buffer)) > 0) {
- sb.append(new String(buffer, 0, length));
- }
- } catch (IOException e) {
- // return what we have so far
- }
- return sb.toString();
- }
-
- /**
- * Read in a file, converting the contents to a string.
- *
- * @param file the input file
- * @return a String containing the contents of the file
- */
- public static String fileToString(File file)
- throws IOException, FileNotFoundException {
- try (FileInputStream fis = new FileInputStream(file)) {
- String string = inputStreamToString(fis);
- return string;
- }
- }
-
- /**
- * Create a file containing the contents of the specified string.
- *
- * @param string the input string
- * @param suffix the suffix to pass to 'createTempFile
- * @return a File, whose contents contain the string
- */
- public static File stringToFile(String string, String suffix)
- throws IOException {
- File file = File.createTempFile("templates-util", suffix);
- file.deleteOnExit();
-
- try (FileOutputStream fos = new FileOutputStream(file)) {
- fos.write(string.getBytes());
- }
- return file;
- }
-
- /**
- * Create a file containing the contents of the specified string.
- *
- * @param string the input string
- * @return a File, whose contents contain the string
- */
- public static File stringToFile(String string)
- throws IOException {
- return stringToFile(string, "");
- }
-
- /**
- * This method converts a YAML string into one that can be embedded into
- * a '.drl' file.
- *
- * @param yaml the input string, which is typically read from a file
- * @return the converted string
- */
- public static String convertYaml(String yaml) {
- yaml = yaml.replace("\n", "%0A");
- yaml = yaml.replace("\r", "");
- yaml = yaml.replace(":", "%3A");
- yaml = yaml.replace(' ', '+');
- return yaml;
- }
-
- /**
- * This is a convenience method which reads a file into a string, and
- * then does a set of string replacements on it. The real purpose is to
- * make it easy to do '${parameter}' replacements in files, as part of
- * building a Drools artifact.
- *
- * @param fileName this is the input file name
- * @param args these parameters come in pairs:
- * 'input-string' and 'output-string'.
- * @return a String containing the contents of the file, with the parameters
- * replaced
- */
- public static String openAndReplace(String fileName, String... args)
- throws IOException, FileNotFoundException {
- String text = fileToString(new File(fileName));
- for (int i = 0; i < args.length; i += 2) {
- text = text.replace(args[i], args[i + 1]);
- }
- return text;
- }
-
- /**
- * Convert an Object to a JsonElement.
- *
- * @param object the object to convert
- * @return a JsonElement that corresponds to 'object'
- */
- public static JsonElement toJsonElement(Object object) {
- if (object == null || object instanceof JsonElement) {
- return (JsonElement) object;
- }
- if (object instanceof Number) {
- return new JsonPrimitive((Number) object);
- }
- if (object instanceof Boolean) {
- return new JsonPrimitive((Boolean) object);
- }
- if (object instanceof Character) {
- return new JsonPrimitive((Character) object);
- }
- return new JsonPrimitive(object.toString());
- }
-
- /**
- * This is a convenience method to build a 'JsonObject', and populate
- * it with a set of keyword/value pairs.
- *
- * @param data this parameter comes in pairs: 'keyword', and 'value'
- * @return the populated JsonObject
- */
- public static JsonObject json(Object... data) {
- JsonObject obj = new JsonObject();
- for (int i = 0; i < data.length; i += 2) {
- obj.add(data[i].toString(), toJsonElement(data[i + 1]));
- }
- return obj;
- }
-
- /**
- * Convert a JsonElement to a String (pretty-printing).
- *
- * @param jsonElement the object to convert
- * @return a pretty-printed string
- */
- public static String prettyPrint(JsonElement jsonElement) {
- return gson.toJson(jsonElement);
- }
-
- /**
- * This method is used to check whether a JSON message has a set of fields
- * populated with the values expected.
- *
- * @param subset this is a 'JsonObject', which contains field names and
- * values (the values are interpreted as regular expressions). The values
- * may also be 'JsonObject' instances, in which case they are compared
- * recursively.
- * @param whole ordinarily, this will be a 'JsonObject', and will contain
- * a superset of the fields in 'subset'. If not, the 'assert' fails.
- */
- public static void assertSubset(JsonObject subset, Object whole) {
- StringBuilder sb = new StringBuilder();
- assertSubsetAssist(sb, "", subset, toJsonElement(whole));
- String sbString = sb.toString();
- assertTrue(sbString, sbString.isEmpty());
- }
-
- /**
- * This is similar to 'assertSubset', but just returns 'true' if the
- * pattern matches.
- *
- * @param subset this is a 'JsonObject', which contains field names and
- * values (the values are interpreted as regular expressions). The values
- * may also be 'JsonObject' instances, in which case they are compared
- * recursively.
- * @param whole ordinarily, this will be a 'JsonObject', and will contain
- * a superset of the fields in 'subset'. If not, the 'assert' fails.
- * @return 'true' if 'whole' is a superset of 'subset'
- */
- public static boolean testSubset(JsonObject subset, Object whole) {
- StringBuilder sb = new StringBuilder();
- assertSubsetAssist(sb, "", subset, toJsonElement(whole));
- return sb.length() == 0;
- }
-
- /**
- * This is an internal support method for 'assertSubset' and 'testSubset',
- * and handles the recursive comparison.
- *
- * @param sb a 'StringBuilder', which is appended to when there are
- * mismatches
- * @param prefix the field name being compared (the empty string indicates
- * the top-level field).
- * @param subset the 'JsonObject' being compared at this level
- * @param argWhole the value being tested -- if it is not a 'JsonObject',
- * the comparison fails
- */
- private static void assertSubsetAssist(StringBuilder sb, String prefix, JsonObject subset, JsonElement argWhole) {
- if (!(argWhole.isJsonObject())) {
- sb.append(prefix).append(" is not a JsonObject\n");
- return;
- }
- JsonObject whole = argWhole.getAsJsonObject();
- for (String key : subset.keySet()) {
- String fullKey = (prefix.isEmpty() ? key : prefix + "." + key);
- JsonElement value = subset.get(key);
- JsonElement value2 = whole.get(key);
- if (value.isJsonObject()) {
- assertSubsetAssist(sb, fullKey, value.getAsJsonObject(), value2);
- } else if (!value.equals(value2)
- && (value2 == null || !value2.toString().matches(value.toString()))) {
- sb.append(fullKey)
- .append(": got ")
- .append(String.valueOf(value2))
- .append(", expected ")
- .append(String.valueOf(value))
- .append("\n");
- }
- }
- }
-
- /**
- * Do whatever needs to be done to start the server. I don't know exactly
- * what abstractions the various pieces provide, but the following code
- * ties the pieces together, and starts up the server.
- *
- * @param name used as the 'ServerConnector' name, and also used to generate
- * a name for the server thread
- * @param host the host IP address to bind to
- * @param port the port to bind to
- * @param clazz the class containing the provider methods
- */
- public static void startRestServer(String name, String host, int port, Class<?> clazz) {
- ServletContextHandler context =
- new ServletContextHandler(ServletContextHandler.SESSIONS);
- context.setContextPath("/");
-
- final Server jettyServer = new Server();
-
- ServerConnector connector = new ServerConnector(jettyServer);
- connector.setName(name);
- connector.setReuseAddress(true);
- connector.setPort(port);
- connector.setHost(host);
-
- jettyServer.addConnector(connector);
- jettyServer.setHandler(context);
-
- ServletHolder holder =
- context.addServlet(org.glassfish.jersey.servlet.ServletContainer.class.getName(), "/*");
- holder.setInitParameter(
- "jersey.config.server.provider.classnames",
- "org.onap.policy.common.gson.GsonMessageBodyHandler"
- + "," + clazz.getName());
-
- synchronized (runningServers) {
- runningServers.add(jettyServer);
- }
-
- new Thread(() -> {
- try {
- jettyServer.start();
- jettyServer.join();
- logger.info("{}: back from jettyServer.join()", name);
- } catch (Exception e) {
- logger.info(name + ": Exception starting jettyServer", e);
- }
- }, "REST Server: " + name).start();
- }
-
- private static boolean initNeeded = true;
-
- /**
- * This method starts services shared by all of the tests. The services are
- * started the first time it is invoked -- subsequent invocations have no
- * effect.
- */
- public static void commonInit() {
- if (initNeeded) {
- initNeeded = false;
-
- // start DMAAP Simulator
- startRestServer("simdmaap", "127.0.0.1", 3904, SimDmaap.class);
-
- // start Guard Simulator
- startRestServer("simguard", "127.0.0.1", 8443, SimGuard.class);
-
- // start PolicyEngine
- PolicyEngineConstants.getManager().configure(new Properties());
- PolicyEngineConstants.getManager().start();
- }
- }
-
- /**
- * This method shuts down all of the servers that were started.
- */
- public static void commonShutdown() {
- synchronized (runningServers) {
- for (Server server : runningServers) {
- try {
- server.stop();
- } catch (Exception e) {
- logger.info("Exception shutting down server: {}", e);
- }
- }
- runningServers.clear();
- initNeeded = true;
- }
- }
-
- /* ============================================================ */
-
- /**
- * This class is used to create an outgoing (publisher) topic message
- * channel. 'topic' is the only parameter -- everything else is hard-wired.
- */
- public static class Output {
- CambriaBatchingPublisher publisher;
- String topic;
-
- /**
- * Constructor - create the outgoing topic message channel.
- *
- * @param topic a DMAAP or UEB topic name
- */
- public Output(String topic) throws Exception {
- this.topic = topic;
- PublisherBuilder builder =
- new CambriaClientBuilders.PublisherBuilder();
- builder
- .usingHosts("127.0.0.1")
- .onTopic(topic)
- .withSocketTimeout(5000);
- publisher = builder.build();
- }
-
- /**
- * Send a JSON message out this channel.
- *
- * @param msg a 'JsonObject' containing the message to be sent
- */
- public void send(JsonObject msg) throws Exception {
- logger.info("Sending message, topic = {}\n{}",
- topic, gson.toJson(msg));
- publisher.send("123", msg.toString());
- }
-
- /**
- * Close the channel.
- */
- public void close() {
- publisher.close();
- }
- }
-
- /* ============================================================ */
-
- /**
- * This class is used to create an incoming (consumer) topic message channel,
- * as well as a Thread that reads from it. Incoming messages are placed in
- * a 'LinkedBlockingQueue', which may be polled for messages.
- */
- public static class Input extends Thread {
- CambriaConsumer consumer;
- String topic;
- LinkedBlockingQueue<JsonObject> queue = new LinkedBlockingQueue<>();
- volatile boolean running = true;
-
- /**
- * Constructor - create the incoming topic message channel.
- *
- * @param topic a DMAAP or UEB topic name
- */
- public Input(String topic) throws Exception {
- this.topic = topic;
-
- // initialize reader
- ConsumerBuilder builder = new CambriaClientBuilders.ConsumerBuilder();
- builder
- .knownAs(UUID.randomUUID().toString(), "1")
- .usingHosts("127.0.0.1")
- .onTopic(topic)
- .waitAtServer(15000)
- .receivingAtMost(100)
- .withSocketTimeout(20000);
- consumer = builder.build();
- start();
- }
-
- /**
- * This is the Thread main loop. It fetches messages, and queues them.
- */
- @Override
- public void run() {
- while (running) {
- try {
- for (String message : consumer.fetch()) {
- // a message was received -- parse it as JSON
- JsonObject msg = coder.decode(message, JsonObject.class);
-
- // construct a message to print, and print it
- logger.info("Received message, topic = {}\n{}",
- topic, gson.toJson(msg));
-
- // queue the message
- queue.add(msg);
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
-
- /**
- * Return the first message in the queue. If none are available, wait up
- * to 30 seconds for one to appear.
- *
- * @return a 'JsonObject' if a message has been received, and 'null' if not
- */
- public JsonObject poll() throws InterruptedException {
- return queue.poll(30, TimeUnit.SECONDS);
- }
-
- /**
- * Stop the thread, and close the channel.
- */
- public void close() {
- running = false;
- consumer.close();
- }
- }
-}
diff --git a/controlloop/m2/test/src/test/resources/appclcm/CLRulevUSPAPPCLCMGuardTemplate.yaml b/controlloop/m2/test/src/test/resources/appclcm/CLRulevUSPAPPCLCMGuardTemplate.yaml
deleted file mode 100644
index ee25b03bb..000000000
--- a/controlloop/m2/test/src/test/resources/appclcm/CLRulevUSPAPPCLCMGuardTemplate.yaml
+++ /dev/null
@@ -1,83 +0,0 @@
-controlLoop:
- version: 2.0.0
- controlLoopName: ControlLoop-vUSP-vCTS-cbed919f-2212-4ef7-8051-fe6308da1bda
- services:
- - serviceName: vUSP
- resources:
- - resourceName: vCTS
- resourceType: VF
- - resourceName: vCOM
- resourceType: VF
- - resourceName: vRAR
- resourceType: VF
- - resourceName: vLCS
- resourceType: VF
- - resourceName: v3CB
- resourceType: VF
- trigger_policy: unique-policy-id-1-restart
- timeout: 60
-
-policies:
- - id: unique-policy-id-1-restart
- name: Restart Policy
- description:
- actor: APPCLCM
- recipe: Restart
- target:
- type: VM
- retry: 1
- timeout: 35
- success: final_success
- failure: unique-policy-id-2-rebuild
- failure_timeout: unique-policy-id-2-rebuild
- failure_retries: unique-policy-id-2-rebuild
- failure_guard: unique-policy-id-2-rebuild
- failure_exception: final_failure_exception
-
- - id: unique-policy-id-2-rebuild
- name: Rebuild Policy
- description:
- actor: APPCLCM
- recipe: Rebuild
- target:
- type: VM
- retry: 0
- timeout: 35
- success: final_success
- failure: unique-policy-id-3-migrate
- failure_timeout: unique-policy-id-3-migrate
- failure_retries: unique-policy-id-3-migrate
- failure_guard: unique-policy-id-3-migrate
- failure_exception: final_failure_exception
-
- - id: unique-policy-id-3-migrate
- name: Migrate Policy
- description:
- actor: APPCLCM
- recipe: Migrate
- target:
- type: VM
- retry: 0
- timeout: 35
- success: final_success
- failure: unique-policy-id-4-evacuate
- failure_timeout: unique-policy-id-4-evacuate
- failure_retries: unique-policy-id-4-evacuate
- failure_guard: unique-policy-id-4-evacuate
- failure_exception: final_failure_exception
-
- - id: unique-policy-id-4-evacuate
- name: Evacuate Policy
- description:
- actor: APPCLCM
- recipe: Evacuate
- target:
- type: VM
- retry: 0
- timeout: 35
- success: final_success
- failure: final_failure
- failure_timeout: final_failure_timeout
- failure_retries: final_failure_retries
- failure_guard: final_failure_guard
- failure_exception: final_failure_exception
diff --git a/controlloop/m2/test/src/test/resources/appclcm/M2CLRulevUSPAPPCLCMGuardTemplate.drl b/controlloop/m2/test/src/test/resources/appclcm/M2CLRulevUSPAPPCLCMGuardTemplate.drl
deleted file mode 100644
index 0e947c8e1..000000000
--- a/controlloop/m2/test/src/test/resources/appclcm/M2CLRulevUSPAPPCLCMGuardTemplate.drl
+++ /dev/null
@@ -1,649 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * m2/test
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.controlloop.p_${unique};
-
-import org.drools.core.spi.KnowledgeHelper;
-
-import org.onap.policy.appclcm.AppcLcmDmaapWrapper;
-import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.ControlLoopEventStatus;
-import org.onap.policy.controlloop.ControlLoopException;
-import org.onap.policy.controlloop.ControlLoopNotification;
-import org.onap.policy.controlloop.ControlLoopNotificationType;
-import org.onap.policy.controlloop.VirtualControlLoopNotification;
-import org.onap.policy.controlloop.compiler.ControlLoopCompiler;
-import org.onap.policy.controlloop.policy.ControlLoop;
-import org.onap.policy.controlloop.policy.ControlLoopPolicy;
-import org.onap.policy.drools.core.PolicySession;
-import org.onap.policy.drools.droolsinit.DroolsInitFeature;
-import org.onap.policy.drools.system.PolicyController;
-import org.onap.policy.drools.system.PolicyEngineConstants;
-import org.onap.policy.guard.GuardContext;
-import org.onap.policy.guard.PolicyGuardResponse;
-
-import org.onap.policy.m2.base.GuardAdjunct;
-import org.onap.policy.m2.base.Transaction;
-import org.onap.policy.m2.base.Util;
-import org.onap.policy.m2.appclcm.AppcLcmOperation;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.ByteArrayInputStream;
-import java.net.URLDecoder;
-import java.time.Instant;
-import java.util.LinkedList;
-import java.util.Properties;
-
-declare Params
- closedLoopControlName : String
- controlLoopYaml : String
- notificationTopic : String
- operationTopic : String
-end
-
-declare Context
- logger : Logger
- metricsLogger : Logger
- auditLogger : Logger
- policy : ControlLoopPolicy
- guardContext : GuardContext
- maxObjectCount : long
- closedLoopControlName : String
- controlLoopYaml : String
- notificationTopic : String
- operationTopic : String
-end
-
-// this object is to provide support for timeouts
-// due to a bug in drools' built in timers
-declare ControlLoopTimer
- closedLoopControlName : String
- requestId : String
- delay : String
- expired : boolean
- //timerType is the type of timer: either "ClosedLoop" or "Operation"
- timerType : String
-end
-
-function void sendNotification(Context context,
- KnowledgeHelper drools,
- ControlLoopNotification notification)
-{
- if (notification != null)
- {
- notification.setFrom("policy");
- notification.setPolicyName(drools.getRule().getName());
- notification.setPolicyScope("${policyScope}");
- notification.setPolicyVersion("${policyVersion}");
-
- Util.deliver(context.getNotificationTopic(), notification);
- }
-}
-
-function Context setParams(Context context)
-{
- context.setClosedLoopControlName("${closedLoopControlName}");
- context.setControlLoopYaml("${controlLoopYaml}");
- context.setNotificationTopic("${notificationTopic}");
- context.setOperationTopic("${operationTopic}");
- context.setPolicy(ControlLoopCompiler.compile
- (new ByteArrayInputStream
- (URLDecoder.decode(context.getControlLoopYaml(),
- "UTF-8").getBytes()), null));
- return context;
-}
-
-rule "${policyName}.INIT"
- salience 100
- when
- $init : DroolsInitFeature.Init()
- not(Context(closedLoopControlName == "${closedLoopControlName}"))
- then
- {
- Logger logger = LoggerFactory.getLogger("${policyName}.drl");
- Logger metricsLogger = LoggerFactory.getLogger("com.att.eelf.metrics");
- Logger auditLogger = LoggerFactory.getLogger("com.att.eelf.audit");
- logger.info("This is ${policyName}.INIT");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
-
- Context context = new Context();
- context.setLogger(logger);
- // add metricsLogger to context
- context.setMetricsLogger(metricsLogger);
- context.setAuditLogger(auditLogger);
- context = setParams(context);
-
- PolicySession session = PolicySession.getCurrentSession();
-
- context.setGuardContext(new GuardContext(session));
-
- try
- {
- // initially, set a default maximum object count of 1000
- context.setMaxObjectCount(1000);
-
- // 'IllegalArgumentException' if the properties can't be found
- PolicyController policyController =
- Util.getPolicyController(session);
- Properties properties = policyController.getProperties();
-
- String maxObjectCount =
- properties.getProperty("overload.maxObjectCount","").trim();
- if (!maxObjectCount.isEmpty())
- {
- // A value has been specified in the properties file --
- // 'NumberFormatException' if the value is bad
- context.setMaxObjectCount(Long.valueOf(maxObjectCount));
- }
- }
- catch (IllegalArgumentException e)
- {
- logger.error("${policyName}.INIT: Can't locate properties", e);
- }
- catch (Exception e)
- {
- logger.error
- ("${policyName}.INIT: Can't decode 'overload.maxObjectCount'", e);
- }
-
- insert(context);
- }
-end
-
-/*
- * This rule fires when a drools update occurs. Its purpose is to
- * update the expandable parameters of the context object to reflect
- * the new state of the policy.
- */
-rule "${policyName}.REINIT"
- salience 100
- when
- $init : DroolsInitFeature.Init()
- $context : Context(closedLoopControlName == "${closedLoopControlName}"
- && (controlLoopYaml != "${controlLoopYaml}"
- || notificationTopic != "${notificationTopic}" || operationTopic != "${operationTopic}"))
- then
- {
- Logger logger = $context.getLogger();
- // get metricsLogger from context
- Logger metricsLogger = $context.getMetricsLogger();
- logger.info("This is ${policyName}.REINIT");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
-
- $context = setParams($context);
-
- modify($context)
- {
- }
- }
-end
-
-/*
- * Fires when an incoming 'ONSET' event occurs, without an associated
- * 'Transaction' instance
- */
-rule "${policyName}.EVENT.NO-TRANSACTION"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $event : VirtualControlLoopEvent(closedLoopControlName == $context.closedLoopControlName, closedLoopEventStatus == ControlLoopEventStatus.ONSET)
- not(Transaction(closedLoopControlName == $context.closedLoopControlName, requestId == $event.requestId))
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- Logger auditLogger = $context.getAuditLogger();
- logger.info("This is ${policyName}.EVENT.NO-TRANSACTION");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
-
- // check for overload
- if (drools.getWorkingMemory().getFactCount() >
- $context.getMaxObjectCount())
- {
- // send 'Overload' notification
- ControlLoopNotification notification =
- new VirtualControlLoopNotification($event);
- notification.setNotification(ControlLoopNotificationType.REJECTED);
- notification.setMessage("Overload in progress");
- sendNotification($context, drools, notification);
-
- // discard event, and return
- auditLogger.info(Instant.now() + "Event End: FAIL: Overload in progress");
- retract($event);
- return;
- }
-
- Transaction transaction =
- new Transaction(drools.getWorkingMemory(),
- $context.getClosedLoopControlName(),
- $event.getRequestId(),
- $context.getPolicy());
-
- //
- // Setup the Overall Control Loop timer
- //
- ControlLoopTimer clTimer =
- new ControlLoopTimer($event.getClosedLoopControlName(), $event.getRequestId().toString(),
- transaction.getTimeout(), false, "ClosedLoop");
-
- insert(clTimer);
-
- // check that the event and a&ai is valid
- if (!transaction.isControlLoopEventValid($event) ||
- !AppcLcmOperation.isAaiValid(transaction, $event)) {
- ControlLoopNotification notification =
- new VirtualControlLoopNotification($event);
- notification.setNotification(ControlLoopNotificationType.REJECTED);
- notification.setMessage(transaction.getNotificationMessage());
- sendNotification($context, drools, notification);
-
- // discard event, and return
- auditLogger.info(Instant.now() + "Event End: FAIL: Invalid event/AAI");
- retract($event);
- return;
- }
-
- // this adjunct needs to be in place before the first 'Operation'
- // is created
- GuardAdjunct.create(transaction, $context.getGuardContext());
- insert(transaction);
-
- // this creates the initial 'Operation'
- transaction.setControlLoopEvent($event);
- retract($event);
-
- // send out an active notification
- ControlLoopNotification notification = transaction.getNotification(null);
- notification.setNotification(ControlLoopNotificationType.ACTIVE);
- sendNotification($context, drools, notification);
- }
-end
-
-/*
- * Fires when 'ONSET' and 'ABATED' events have occured before an appc request was processed
- */
-rule "${policyName}.TRANSACTION.ABATED.NO-REQUEST"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $transaction: Transaction(closedLoopControlName == $context.closedLoopControlName, state != AppcLcmOperation.LCM_PENDING &&
- state != "COMPLETE" && state != AppcLcmOperation.LCM_COMPLETE)
- $event : VirtualControlLoopEvent(closedLoopControlName == $context.closedLoopControlName, closedLoopEventStatus == ControlLoopEventStatus.ABATED, requestId == $transaction.requestId)
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- logger.info("${policyName}.TRANSACTION.ABATED.NO-REQUEST");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
-
- $transaction.incomingMessage($event);
- modify($transaction)
- {
- }
- }
-end
-
-rule "${policyName}.TRANSACTION.LCM.GUARD_PENDING.RESPONSE"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $transaction: Transaction(closedLoopControlName == $context.closedLoopControlName, state == AppcLcmOperation.LCM_GUARD_PENDING)
- $response : PolicyGuardResponse(requestId == $transaction.getRequestId())
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- logger.info("This is ${policyName}.TRANSACTION.LCM.GUARD_PENDING.RESPONSE");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- sendNotification($context, drools,
- $transaction.incomingMessage($response));
- //
- // insert operation timeout object
- //
- ControlLoopTimer opTimer =
- new ControlLoopTimer($transaction.getClosedLoopControlName(), $transaction.getRequestId().toString(),
- $transaction.getOperationTimeout(), false, "Operation");
- insert(opTimer);
-
- modify($transaction)
- {
- }
- retract($response);
- }
-end
-
-/*
- * Initial state for LCM operations (Restart/Rebuild/Migrate)
- */
-rule "${policyName}.TRANSACTION.LCM.BEGIN"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $transaction : Transaction(closedLoopControlName == $context.closedLoopControlName, state == AppcLcmOperation.LCM_BEGIN)
- ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, requestId == $transaction.getRequestId().toString(), !expired, timerType == "Operation")
- not(VirtualControlLoopEvent(closedLoopControlName == $context.closedLoopControlName, closedLoopEventStatus == ControlLoopEventStatus.ABATED, requestId == $transaction.requestId))
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- logger.info("This is ${policyName}.TRANSACTION.LCM.BEGIN");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- Object request = null;
- try {
- request = $transaction.getCurrentOperation().getRequest();
- } catch (ControlLoopException e) {
- logger.error("request could not be formed due to: "+e.getMessage());
- return;
- }
- Util.deliver($context.getOperationTopic(), request);
-
- // send notification
- sendNotification($context, drools,
- $transaction.initialOperationNotification());
-
- modify($transaction)
- {
- }
- }
-end
-
-/*
- * We are waiting for an LCM response, and one has occurred
- * (it may or may not be the one we were expecting)
- */
-rule "${policyName}.TRANSACTION.LCM.PENDING.RESPONSE"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $transaction: Transaction(closedLoopControlName == $context.closedLoopControlName, state == AppcLcmOperation.LCM_PENDING)
- $opTimer : ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, requestId == $transaction.getRequestId().toString(), !expired, timerType == "Operation")
- $response : AppcLcmDmaapWrapper(body.output.commonHeader.requestId == $transaction.getRequestId())
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- logger.info("This is ${policyName}.TRANSACTION.LCM.PENDING.RESPONSE");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- ControlLoopNotification notification = $transaction.incomingMessage($response);
- sendNotification($context, drools, notification);
- if (notification != null) {
- retract($opTimer);
- }
- modify($transaction)
- {
- }
- retract($response);
- }
-end
-
-/*
-*
-* This is the timer that manages the timeout for an individual operation.
-* Due to a bug in the drools code, the drools timer needed to be split from most of the objects in the when clause
-*
-*/
-rule "${policyName}.LCM.OPERATION.TIMER.FIRED"
- timer (expr: $timeout)
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $opTimer : ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, $timeout : delay, !expired, timerType == "Operation")
- then
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- Logger auditLogger = $context.getAuditLogger();
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- modify($opTimer){setExpired(true)};
- end
-
-/*
- * We are waiting for an LCM response, but the timer expired before
- * receiving one.
- */
-rule "${policyName}.TRANSACTION.LCM.PENDING.TIMEOUT"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $transaction: Transaction(closedLoopControlName == $context.closedLoopControlName, state == AppcLcmOperation.LCM_PENDING, $timeout : getOperationTimeout())
- $opTimer : ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, requestId == $transaction.getRequestId().toString(), expired, timerType == "Operation")
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- logger.info("This is ${policyName}.TRANSACTION.LCM.PENDING.TIMEOUT: "
- + $transaction.getOperationTimeout());
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- sendNotification($context, drools, $transaction.timeout());
- retract($opTimer);
- modify($transaction)
- {
- }
- }
-end
-
-rule "${policyName}.TRANSACTION.LCM.PENDING.ERROR"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $transaction: Transaction(closedLoopControlName == $context.closedLoopControlName, state == AppcLcmOperation.LCM_ERROR)
- $timers : LinkedList()
- from collect (ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, requestId == $transaction.getRequestId().toString(), timerType == "Operation"))
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- logger.info("This is ${policyName}.TRANSACTION.LCM.ERROR");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- $transaction.processError();
- for (Object timer : $timers) {
- retract(timer);
- }
- modify($transaction)
- {
- }
- }
-end
-
-/*
- * We are in the 'LCM_COMPLETE' state, meaning no operations are in progress,
- * and no 'ABATED' message is expected so the transaction can complete.
- */
-rule "${policyName}.TRANSACTION.COMPLETE.NOT-ABATED"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}", getPolicy().getControlLoop().getAbatement() == false)
- $transaction: Transaction(closedLoopControlName == $context.closedLoopControlName, state == "COMPLETE")
- $clTimer : ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, requestId == $transaction.getRequestId().toString(), timerType == "ClosedLoop")
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- Logger auditLogger = $context.getAuditLogger();
- logger.info("This is ${policyName}.TRANSACTION.COMPLETE.NOT-ABATED");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- auditLogger.info(Instant.now() + " Event End: SUCCESS: NOT-ABATED");
- retract($transaction);
- retract($clTimer);
- $transaction.cleanup();
-
- sendNotification($context, drools, $transaction.finalNotification());
- }
-end
-
-/*
- * We are in the 'COMPLETE' state, meaning no operations are in progress,
- * and we have received an 'ABATED' message.
- */
-rule "${policyName}.TRANSACTION.COMPLETE.ABATED"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}", getPolicy().getControlLoop().getAbatement() == true)
- $transaction: Transaction(closedLoopControlName == $context.closedLoopControlName, state == "COMPLETE")
- $event : VirtualControlLoopEvent(closedLoopControlName == $context.closedLoopControlName, closedLoopEventStatus == ControlLoopEventStatus.ABATED, requestId == $transaction.requestId)
- $clTimer : ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, requestId == $transaction.getRequestId().toString(), timerType == "ClosedLoop")
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- Logger auditLogger = $context.getAuditLogger();
- logger.info("This is ${policyName}.TRANSACTION.COMPLETE.ABATED");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- auditLogger.info(Instant.now() + "Event End: SUCCESS: ABATED");
- retract($event);
- retract($transaction);
- retract($clTimer);
- $transaction.cleanup();
-
- sendNotification($context, drools, $transaction.finalNotification());
- }
-end
-
-/*
- * We are in the 'COMPLETE' state, meaning no operations are in progress,
- * and the overall transaction failed, so no ABATED message is expected.
- */
-rule "${policyName}.TRANSACTION.COMPLETE.FAILED"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $transaction: Transaction(closedLoopControlName == $context.closedLoopControlName, state == "COMPLETE", finalResultFailure)
- $clTimer : ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, requestId == $transaction.getRequestId().toString(), timerType == "ClosedLoop")
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- Logger auditLogger = $context.getAuditLogger();
- logger.info("This is ${policyName}.TRANSACTION.COMPLETE.FAILED");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- auditLogger.info(Instant.now() + "Transaction End: FAIL: Final Result Failure");
- retract($transaction);
- retract($clTimer);
- $transaction.cleanup();
-
- sendNotification($context, drools, $transaction.finalNotification());
- }
-end
-
-/*
-*
-* This is the timer that manages the overall control loop timeout.
-* Due to a bug in the drools code, the drools timer needed to be split from most of the objects in the when clause
-*
-*/
-rule "${policyName}.CLOSED_LOOP.TIMER.FIRED"
- timer (expr: $timeout)
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $clTimer : ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, $timeout : delay, !expired, timerType == "ClosedLoop")
- then
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- logger.info("This is ${policyName}.CLOSED_LOOP.TIMER.FIRED");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- modify($clTimer){setExpired(true)};
- end
-
-/*
- * The overall transaction has timed out.
- */
-rule "${policyName}.TRANSACTION.TIMEOUT"
- when
- $context : Context(closedLoopControlName == "${closedLoopControlName}")
- $transaction: Transaction(closedLoopControlName == $context.closedLoopControlName)
- $clTimer : ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, requestId == $transaction.getRequestId().toString(), expired, timerType == "ClosedLoop")
- $opTimers : LinkedList()
- from collect (ControlLoopTimer(closedLoopControlName == $context.closedLoopControlName, requestId == $transaction.getRequestId().toString(), timerType == "Operation"))
- then
- {
- Logger logger = $context.getLogger();
- Logger metricsLogger = $context.getMetricsLogger();
- Logger auditLogger = $context.getAuditLogger();
- logger.info("This is ${policyName}.TRANSACTION.TIMEOUT");
- metricsLogger.info("{} {} {}", Instant.now(), drools.getRule().getName(), drools.getRule().getPackage());
- auditLogger.info(Instant.now() + "Transaction End: FAIL: Transaction Timeout");
- retract($transaction);
- retract($clTimer);
- // Drools does not support generics, so the time of the objects in opTimers
- // can't be set to OperationTimer. Therefore, timer must be an Object.
- for (Object timer : $opTimers) {
- retract(timer);
- }
- $transaction.cleanup();
- $transaction.clTimeout();
-
- sendNotification($context, drools, $transaction.finalNotification());
- }
-end
-
-/* ============================================================ */
-
-/*
- * This rule is an audit runs at a low priority, and cleans up any unclaimed
- * 'ControlLoopEvent' instances. The assumption is that all other rules are
- * structured so that incoming messages will be processed, and retracted
- * from Drools memory (whether or not they are retained within the
- * transaction).
- */
-rule "${policyName}.UNCLAIMED-EVENT"
- salience -1000
- when
- $context : Context()
- $event : VirtualControlLoopEvent()
- then
- {
- Logger logger = $context.getLogger();
- Logger auditLogger = $context.getAuditLogger();
- logger.debug("${policyName}.UNCLAIMED-EVENT: " + $event);
- auditLogger.info(Instant.now() + "Event End: FAIL: UNCLAIMED-EVENT - See error log");
- retract($event);
- }
-end
-
-/*
- * This rule is an audit runs at a low priority, and cleans up any unclaimed
- * 'PolicyGuardResponse' instances. The assumption is that all other rules are
- * structured so that incoming messages will be processed, and retracted
- * from Drools memory (whether or not they are retained within the
- * transaction).
- */
-rule "${policyName}.UNCLAIMED-POLICY-GUARD-RESPONSE"
- salience -1000
- when
- $context : Context()
- $response : PolicyGuardResponse()
- then
- {
- Logger logger = $context.getLogger();
- logger.error("${policyName}.UNCLAIMED-POLICY-GUARD-RESPONSE: "
- + $response);
- retract($response);
- }
-end
-
-/*
- * This rule is an audit runs at a low priority, and cleans up any unclaimed
- * 'Response' instances. The assumption is that all other rules are
- * structured so that incoming messages will be processed, and retracted
- * from Drools memory (whether or not they are retained within the
- * transaction).
- */
-rule "${policyName}.UNCLAIMED-LCM-RESPONSE"
- salience -1000
- when
- $context : Context()
- $response : AppcLcmDmaapWrapper()
- then
- {
- Logger logger = $context.getLogger();
- logger.error("${policyName}.UNCLAIMED-LCM-RESPONSE: " + $response);
- retract($response);
- }
-end
diff --git a/controlloop/m2/test/src/test/resources/appclcm/controller.properties b/controlloop/m2/test/src/test/resources/appclcm/controller.properties
deleted file mode 100644
index 6eca45733..000000000
--- a/controlloop/m2/test/src/test/resources/appclcm/controller.properties
+++ /dev/null
@@ -1,58 +0,0 @@
-###
-# ============LICENSE_START=======================================================
-# ONAP
-# ================================================================================
-# Modifications Copyright (C) 2020 Bell Canada.
-# ================================================================================
-# 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.
-# ============LICENSE_END=========================================================
-###
-
-# CONTROLLER section
-controller.name=appclcm
-
-persistence.type=auto
-
-dmaap.source.topics=org.onap.DCAE-APPCLCM-TOPIC
-
-dmaap.source.topics.org.onap.DCAE-APPCLCM-TOPIC.events=org.onap.policy.controlloop.VirtualControlLoopEvent
-dmaap.source.topics.org.onap.DCAE-APPCLCM-TOPIC.events.org.onap.policy.controlloop.VirtualControlLoopEvent.filter=[?($.closedLoopControlName =~ /.*/)]
-dmaap.source.topics.org.onap.DCAE-APPCLCM-TOPIC.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gson
-dmaap.source.topics.org.onap.DCAE-APPCLCM-TOPIC.servers=127.0.0.1
-
-ueb.source.topics=APPC-RESPONSE-APPCLCM-TOPIC
-
-ueb.source.topics.APPC-RESPONSE-APPCLCM-TOPIC.events=org.onap.policy.appclcm.AppcLcmDmaapWrapper
-ueb.source.topics.APPC-RESPONSE-APPCLCM-TOPIC.events.org.onap.policy.appclcm.AppcLcmDmaapWrapper.filter=[?($.type == 'response')]
-ueb.source.topics.APPC-RESPONSE-APPCLCM-TOPIC.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson
-ueb.source.topics.APPC-RESPONSE-APPCLCM-TOPIC.servers=127.0.0.1
-
-ueb.sink.topics=NOTIFICATION-APPCLCM-TOPIC,APPC-REQUEST-APPCLCM-TOPIC
-
-ueb.sink.topics.APPC-REQUEST-APPCLCM-TOPIC.events=org.onap.policy.appclcm.AppcLcmDmaapWrapper
-ueb.sink.topics.APPC-REQUEST-APPCLCM-TOPIC.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson
-ueb.sink.topics.APPC-REQUEST-APPCLCM-TOPIC.servers=127.0.0.1
-
-ueb.sink.topics.NOTIFICATION-APPCLCM-TOPIC.events=org.onap.policy.controlloop.VirtualControlLoopNotification
-ueb.sink.topics.NOTIFICATION-APPCLCM-TOPIC.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gson
-ueb.sink.topics.NOTIFICATION-APPCLCM-TOPIC.servers=127.0.0.1
-
-guard.javax.persistence.jdbc.driver=org.h2.Driver
-#guard.javax.persistence.jdbc.url=jdbc:h2:file:./H2DB
-#guard.javax.persistence.jdbc.user=sa
-#guard.javax.persistence.jdbc.password=
-#guard.pdp.rest.url=http\://127.0.0.1\:8443/pdp/
-
-rules.artifactId=appclcm
-rules.groupId=org.onap.policy.m2.test
-##rules.version=1.0.0-SNAPSHOT
diff --git a/controlloop/m2/test/src/test/resources/appclcm/kmodule.xml b/controlloop/m2/test/src/test/resources/appclcm/kmodule.xml
deleted file mode 100644
index fc9b66f3e..000000000
--- a/controlloop/m2/test/src/test/resources/appclcm/kmodule.xml
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
- <kbase name="rules">
- <ksession name="appclcm"/>
- </kbase>
-</kmodule>
diff --git a/controlloop/m2/test/src/test/resources/appclcm/pom.xml b/controlloop/m2/test/src/test/resources/appclcm/pom.xml
deleted file mode 100644
index 0cf8b7b92..000000000
--- a/controlloop/m2/test/src/test/resources/appclcm/pom.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <groupId>org.onap.policy.m2.test</groupId>
- <artifactId>appclcm</artifactId>
- <version>${project.version}</version>
-</project>
diff --git a/controlloop/m2/util/pom.xml b/controlloop/m2/util/pom.xml
deleted file mode 100644
index 3decb3431..000000000
--- a/controlloop/m2/util/pom.xml
+++ /dev/null
@@ -1,41 +0,0 @@
-<?xml version="1.0"?>
-<!--
- ============LICENSE_START=======================================================
- ONAP Policy Engine - Drools PDP
- ================================================================================
- Copyright (C) 2020 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.
- ============LICENSE_END=========================================================
- -->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <groupId>org.onap.policy.drools-applications.controlloop.m2</groupId>
- <artifactId>m2</artifactId>
- <version>1.7.1-SNAPSHOT</version>
- </parent>
-
- <artifactId>util</artifactId>
-
- <dependencies>
- <dependency>
- <groupId>org.onap.policy.drools-pdp</groupId>
- <artifactId>policy-core</artifactId>
- <version>${version.policy.drools-pdp}</version>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-</project>
diff --git a/controlloop/m2/util/src/main/java/org/onap/policy/util/DroolsSessionCommonSerializable.java b/controlloop/m2/util/src/main/java/org/onap/policy/util/DroolsSessionCommonSerializable.java
deleted file mode 100644
index 0d60b2598..000000000
--- a/controlloop/m2/util/src/main/java/org/onap/policy/util/DroolsSessionCommonSerializable.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * util
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.util;
-
-import java.io.ObjectStreamException;
-import java.io.Serializable;
-import java.util.HashMap;
-import org.onap.policy.drools.core.PolicySession;
-
-/**
- * This class provides a way to serialize/deserialize objects by locating
- * an already existing object on the remote end, and using that instead. It
- * is useful for objects that may be shared by multiple transactions.
- */
-public class DroolsSessionCommonSerializable implements Serializable {
- private static final long serialVersionUID = 1L;
-
- // identifies an object within a Drools session
- private String name;
-
- // the object is serialized, but is only used if the corresponding object
- // on the remote end can't be located for some reason
- private Object object;
-
- /**
- * Constructor - initialize instance, and also store a reference to
- * the object in a 'PolicySession' adjunct.
- *
- * @param name identifies the object within the Drools session
- * @param object the shared object
- */
- public DroolsSessionCommonSerializable(String name, Object object) {
- this.name = name;
- this.object = object;
-
- // store a reference to the object within the adjunct
- // (only works if we can locate the Drools session)
- Adjunct adjunct = getAdjunct();
- if (adjunct != null) {
- adjunct.put(name, object);
- }
- }
-
- /**
- * Return this object as a String.
- *
- * {@inheritDoc}
- */
- @Override
- public String toString() {
- return "DroolsSessionCommonSerializable[" + name + "]";
- }
-
- /**
- * This method runs as part of deserialization. If we are able to locate
- * the 'PolicySession' and adjunct, and fetch the replacement object from
- * the adjunct, that is used. Otherwise, the deserialized object is used
- * (which is likely a duplicate).
- *
- * @return the local named object (if available), or the deserialized
- * object
- */
- protected Object readResolve() throws ObjectStreamException {
- Adjunct adjunct = getAdjunct();
- Object replacementObject;
-
- if (adjunct != null && (replacementObject = adjunct.get(name)) != null) {
- // we found the adjunct, as well as the replacement object -- use
- // the replacement object
- return replacementObject;
- }
-
- // either we couldn't find the adjunct, or couldn't locate the object
- // within the adjunct
- return object;
- }
-
- /**
- * This method will:
- * 1) Locate the 'PolicySession' (only works from within the Drools thread),
- * 2) Find or create the adjunct.
- *
- * @return the adjunct, or 'null' if we aren't running within a
- * Drools session
- */
- private Adjunct getAdjunct() {
- // PolicySession - this only works from within the Drools thread
- PolicySession session = PolicySession.getCurrentSession();
- Adjunct adjunct = null;
- if (session != null) {
- // we found the 'PolicySession' -- now, look for the adjunct
- Object adj = session.getAdjunct(Adjunct.class);
- if (!(adj instanceof Adjunct)) {
- // adjunct does not exist, or has the wrong type -- create it
- adjunct = new Adjunct();
- session.setAdjunct(Adjunct.class, adjunct);
- } else {
- // found the adjunct -- return it
- adjunct = (Adjunct) adj;
- }
- }
- return adjunct;
- }
-
- /* ============================================================ */
-
- /**
- * While 'HashMap&lt;String, Object&gt;' could be used directly instead of defining
- * a subclass, you can't do run-time type checking of a parameterized type.
- * As a result, the 'getAdjunct' method (above) would get compile-time
- * warnings.
- */
- private static class Adjunct extends HashMap<String, Object> {
- private static final long serialVersionUID = 1L;
- }
-}
diff --git a/controlloop/m2/util/src/test/java/org/onap/policy/util/DroolsSessionCommonSerializableTest.java b/controlloop/m2/util/src/test/java/org/onap/policy/util/DroolsSessionCommonSerializableTest.java
deleted file mode 100644
index 24c04f70d..000000000
--- a/controlloop/m2/util/src/test/java/org/onap/policy/util/DroolsSessionCommonSerializableTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * util
- * ================================================================================
- * Copyright (C) 2020 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.
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.policy.util;
-
-import static org.junit.Assert.assertNotNull;
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mockito;
-import org.onap.policy.drools.core.PolicySession;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
-
-@RunWith(PowerMockRunner.class)
-public class DroolsSessionCommonSerializableTest {
-
- private DroolsSessionCommonSerializable droolsSessionCommonSerializable;
-
- @Test
- public void test() {
- Object object = new Object();
- droolsSessionCommonSerializable = new DroolsSessionCommonSerializable("drools", object);
- assertNotNull(droolsSessionCommonSerializable.toString());
- }
-
- @PrepareForTest(PolicySession.class)
- @Test
- public void testConstructorGetNullAdjunct() {
- PowerMockito.mockStatic(PolicySession.class);
- PolicySession mockPolicySession = Mockito.mock(PolicySession.class);
- Object mockObject = Mockito.mock(Object.class);
-
- when(PolicySession.getCurrentSession()).thenReturn(mockPolicySession);
- when(mockPolicySession.getAdjunct(any(Class.class))).thenReturn(null);
-
- droolsSessionCommonSerializable = new DroolsSessionCommonSerializable("testName", mockObject);
-
- verify(mockPolicySession).getAdjunct(any(Class.class));
- assertNotNull(droolsSessionCommonSerializable.toString());
- }
-
- @PrepareForTest(PolicySession.class)
- @Test
- public void testConstructorGetAdjunct() {
- PowerMockito.mockStatic(PolicySession.class);
- PolicySession mockPolicySession = Mockito.mock(PolicySession.class);
- Object mockObject = Mockito.mock(Object.class);
-
- when(PolicySession.getCurrentSession()).thenReturn(mockPolicySession);
- when(mockPolicySession.getAdjunct(any(Class.class))).thenReturn(mockObject);
-
- droolsSessionCommonSerializable = new DroolsSessionCommonSerializable("testName", mockObject);
-
- verify(mockPolicySession).getAdjunct(any(Class.class));
- assertNotNull(droolsSessionCommonSerializable.toString());
- }
-
- @Test
- public void testReadResolve() throws Exception {
- Object mockObject = Mockito.mock(Object.class);
- droolsSessionCommonSerializable = new DroolsSessionCommonSerializable("testName", mockObject);
-
- assertNotNull(Whitebox.invokeMethod(droolsSessionCommonSerializable, "readResolve"));
- assertNotNull(droolsSessionCommonSerializable.toString());
- }
-}
diff --git a/controlloop/pom.xml b/controlloop/pom.xml
index 638b8f8c5..02023668f 100644
--- a/controlloop/pom.xml
+++ b/controlloop/pom.xml
@@ -36,7 +36,6 @@
<modules>
<module>common</module>
- <module>m2</module>
<module>packages</module>
</modules>
</project>