aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/controller-usecases/src
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-07-30 18:05:02 -0400
committerJim Hahn <jrh3@att.com>2020-08-21 09:56:12 -0400
commit6a37af48d1db199a0f5a9e9c48f7c5f834a90d1b (patch)
tree5855e16683cecd3e2b150847843152118899779e /controlloop/common/controller-usecases/src
parent56efff004af2d1be64c67f7c8091cb4553a0e86b (diff)
Add "special" Operation classes for new usecases
Created place-holder for new "usecases" controller. Note: as of yet, this is still just a normal java project; it will be turned into a full-fledged kie-based controller in a later review. Added some Operation and a few other support classes that will be needed. Note: the detmTarget() method and it's various supporting methods, detmXxx(), found in GetTargetEntityOperation2 were cloned from the pre-existing ControlLoopOperationManager2 class, and modified to fit the strategy of the new controller. Likewise for the junit tests of those methods. Issue-ID: POLICY-2748 Change-Id: Idffa135a11a56bd6afdd2728706fd40168e80912 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'controlloop/common/controller-usecases/src')
-rw-r--r--controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2.java204
-rw-r--r--controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2.java75
-rw-r--r--controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesConstants.java49
-rw-r--r--controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2Test.java348
-rw-r--r--controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2Test.java121
-rw-r--r--controlloop/common/controller-usecases/src/test/resources/config/event-manager.properties83
-rw-r--r--controlloop/common/controller-usecases/src/test/resources/config/usecases-controller.properties63
-rw-r--r--controlloop/common/controller-usecases/src/test/resources/config/usecases-http-client.properties52
8 files changed, 995 insertions, 0 deletions
diff --git a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2.java b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2.java
new file mode 100644
index 000000000..e1259e48d
--- /dev/null
+++ b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2.java
@@ -0,0 +1,204 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * 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.apps.controller.usecases;
+
+import static org.onap.policy.drools.apps.controller.usecases.UsecasesConstants.AAI_DEFAULT_GENERIC_VNF;
+import static org.onap.policy.drools.apps.controller.usecases.UsecasesConstants.GENERIC_VNF_VNF_ID;
+import static org.onap.policy.drools.apps.controller.usecases.UsecasesConstants.GENERIC_VNF_VNF_NAME;
+import static org.onap.policy.drools.apps.controller.usecases.UsecasesConstants.PNF_NAME;
+import static org.onap.policy.drools.apps.controller.usecases.UsecasesConstants.VSERVER_VSERVER_NAME;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.impl.OperationPartial;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.eventmanager.StepContext;
+import org.onap.policy.controlloop.policy.Target;
+
+/**
+ * An operation to get the target entity. This is a "pseudo" operation; it is not found
+ * within an ActorService, but is created directly. It gets/sets the targetEntity found
+ * within the step context's properties.
+ */
+public class GetTargetEntityOperation2 extends OperationPartial {
+
+ private final StepContext stepContext;
+ private final VirtualControlLoopEvent event;
+
+
+ /**
+ * Constructs the operation as a preprocessing step for a policy's operation.
+ *
+ * @param stepContext the step's context
+ * @param event event being processed
+ * @param params operation's parameters
+ */
+ public GetTargetEntityOperation2(StepContext stepContext, VirtualControlLoopEvent event,
+ ControlLoopOperationParams params) {
+ super(params, null, Collections.emptyList());
+ this.event = event;
+ this.stepContext = stepContext;
+ }
+
+ @Override
+ public List<String> getPropertyNames() {
+ String propName = detmTarget(params.getTarget());
+ return (propName == null ? Collections.emptyList() : List.of(propName));
+ }
+
+ @Override
+ public CompletableFuture<OperationOutcome> start() {
+ throw new UnsupportedOperationException("cannot start get-target-entity operation");
+ }
+
+ /**
+ * Determines the target entity.
+ *
+ * @param target policy target
+ *
+ * @return the property containing the target entity, or {@code null} if the target
+ * entity is already known
+ */
+ private String detmTarget(Target target) {
+ if (stepContext.contains(OperationProperties.AAI_TARGET_ENTITY)) {
+ // the target entity has already been determined
+ return null;
+ }
+
+ if (target == null) {
+ throw new IllegalArgumentException("The target is null");
+ }
+
+ if (target.getType() == null) {
+ throw new IllegalArgumentException("The target type is null");
+ }
+
+ switch (target.getType()) {
+ case PNF:
+ return detmPnfTarget();
+ case VM:
+ case VNF:
+ case VFMODULE:
+ return detmVfModuleTarget();
+ default:
+ throw new IllegalArgumentException("The target type is not supported");
+ }
+ }
+
+ /**
+ * Determines the PNF target entity.
+ *
+ * @return the property containing the target entity, or {@code null} if the target
+ * entity is already known
+ */
+ private String detmPnfTarget() {
+ if (!PNF_NAME.equalsIgnoreCase(event.getTarget())) {
+ throw new IllegalArgumentException("Target does not match target type");
+ }
+
+ String targetEntity = event.getAai().get(PNF_NAME);
+ if (targetEntity == null) {
+ throw new IllegalArgumentException("AAI section is missing " + PNF_NAME);
+ }
+
+ setTargetEntity(targetEntity);
+
+ return null;
+ }
+
+ /**
+ * Determines the VF Module target entity.
+ *
+ * @return the property containing the target entity, or {@code null} if the target
+ * entity is already known
+ */
+ private String detmVfModuleTarget() {
+ String targetFieldName = event.getTarget();
+ if (targetFieldName == null) {
+ throw new IllegalArgumentException("Target is null");
+ }
+
+ String targetEntity;
+
+ switch (targetFieldName.toLowerCase()) {
+ case VSERVER_VSERVER_NAME:
+ targetEntity = event.getAai().get(VSERVER_VSERVER_NAME);
+ break;
+ case GENERIC_VNF_VNF_ID:
+ targetEntity = event.getAai().get(GENERIC_VNF_VNF_ID);
+ break;
+ case GENERIC_VNF_VNF_NAME:
+ return detmVnfName();
+ default:
+ throw new IllegalArgumentException("Target does not match target type");
+ }
+
+ if (targetEntity == null) {
+ throw new IllegalArgumentException("Enrichment data is missing " + targetFieldName);
+ }
+
+ setTargetEntity(targetEntity);
+
+ return null;
+ }
+
+ /**
+ * Determines the VNF Name target entity.
+ *
+ * @return the property containing the target entity, or {@code null} if the target
+ * entity is already known
+ */
+ private String detmVnfName() {
+ // if the onset is enriched with the vnf-id, we don't need an A&AI response
+ String targetEntity = event.getAai().get(GENERIC_VNF_VNF_ID);
+ if (targetEntity == null) {
+ // don't have the data yet - add a step to retrieve it
+ return AAI_DEFAULT_GENERIC_VNF;
+ }
+
+ setTargetEntity(targetEntity);
+
+ return null;
+ }
+
+ @Override
+ public void setProperty(String name, Object value) {
+ // only care about one property
+ if (UsecasesConstants.AAI_DEFAULT_GENERIC_VNF.equals(name)) {
+ GenericVnf vnf = (GenericVnf) value;
+ setTargetEntity(vnf.getVnfId());
+ }
+ }
+
+ /**
+ * Sets the target entity within the properties.
+ *
+ * @param targetEntity the new target entity
+ */
+ private void setTargetEntity(String targetEntity) {
+ stepContext.setProperty(OperationProperties.AAI_TARGET_ENTITY, targetEntity);
+ }
+}
diff --git a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2.java b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2.java
new file mode 100644
index 000000000..f5b03d2f5
--- /dev/null
+++ b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2.java
@@ -0,0 +1,75 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * 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.apps.controller.usecases;
+
+import java.util.List;
+import java.util.concurrent.CompletableFuture;
+import lombok.Getter;
+import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.impl.OperationPartial;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.eventmanager.StepContext;
+
+/**
+ * A LOCK operation for a particular target entity. This is a "pseudo" operation; it is
+ * not found within an ActorService, but is created directly.
+ */
+public class LockOperation2 extends OperationPartial {
+
+ private final StepContext stepContext;
+
+ private static final List<String> PROPERTY_NAMES = List.of(OperationProperties.AAI_TARGET_ENTITY);
+
+ /**
+ * Set when {@link #setProperty(String, Object)} is invoked.
+ */
+ @Getter
+ private String targetEntity;
+
+
+ /**
+ * Constructs the lock operation as a preprocessing step for a policy's operation.
+ *
+ * @param stepContext the context to use to request the lock
+ * @param params operation's parameters
+ */
+ public LockOperation2(StepContext stepContext, ControlLoopOperationParams params) {
+ super(params, null, PROPERTY_NAMES);
+ this.stepContext = stepContext;
+ }
+
+ @Override
+ public CompletableFuture<OperationOutcome> start() {
+ if (targetEntity == null) {
+ throw new IllegalStateException("target lock entity has not been determined yet");
+ }
+
+ return stepContext.requestLock(targetEntity);
+ }
+
+ @Override
+ public void setProperty(String name, Object value) {
+ if (OperationProperties.AAI_TARGET_ENTITY.equals(name) && value != null) {
+ targetEntity = value.toString();
+ }
+ }
+}
diff --git a/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesConstants.java b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesConstants.java
new file mode 100644
index 000000000..17db745ad
--- /dev/null
+++ b/controlloop/common/controller-usecases/src/main/java/org/onap/policy/drools/apps/controller/usecases/UsecasesConstants.java
@@ -0,0 +1,49 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * 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.apps.controller.usecases;
+
+public class UsecasesConstants {
+
+ public static final String GET_TARGET_ENTITY_ACTOR = "pseudo/getTargetEntity";
+ public static final String GET_TARGET_ENTITY_OPERATION = "pseudo/getTargetEntity";
+
+ public static final String PROV_STATUS_ACTIVE = "ACTIVE";
+ public static final String VM_NAME = "VM_NAME";
+ public static final String VNF_NAME = "VNF_NAME";
+ public static final String GENERIC_VNF_VNF_ID = "generic-vnf.vnf-id";
+ public static final String GENERIC_VNF_VNF_NAME = "generic-vnf.vnf-name";
+ public static final String VSERVER_VSERVER_NAME = "vserver.vserver-name";
+ public static final String GENERIC_VNF_IS_CLOSED_LOOP_DISABLED = "generic-vnf.is-closed-loop-disabled";
+ public static final String VSERVER_IS_CLOSED_LOOP_DISABLED = "vserver.is-closed-loop-disabled";
+ public static final String PNF_IS_IN_MAINT = "pnf.in-maint";
+ public static final String GENERIC_VNF_PROV_STATUS = "generic-vnf.prov-status";
+ public static final String VSERVER_PROV_STATUS = "vserver.prov-status";
+ public static final String PNF_ID = "pnf.pnf-id";
+ public static final String PNF_NAME = "pnf.pnf-name";
+
+ // additional properties that the Operations may need
+
+ public static final String AAI_DEFAULT_GENERIC_VNF = "AAI/default/genericVnf";
+
+ private UsecasesConstants() {
+ super();
+ }
+}
diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2Test.java
new file mode 100644
index 000000000..238ac3d70
--- /dev/null
+++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/GetTargetEntityOperation2Test.java
@@ -0,0 +1,348 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * 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.apps.controller.usecases;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+import java.util.Map;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.eventmanager.StepContext;
+import org.onap.policy.controlloop.policy.Target;
+import org.onap.policy.controlloop.policy.TargetType;
+
+public class GetTargetEntityOperation2Test {
+ private static final String GENERIC_VNF_ID = "generic-vnf.vnf-id";
+ private static final String VSERVER_NAME = "vserver.vserver-name";
+ private static final String GENERIC_VNF_NAME = "generic-vnf.vnf-name";
+ private static final String MY_PNF = "my-pnf";
+ private static final String MY_VNF = "my-vnf";
+ private static final String MY_ACTOR = "my-actor";
+ private static final String MY_OPERATION = "my-operation";
+
+ @Mock
+ private StepContext stepContext;
+ @Mock
+ private ControlLoopOperationParams params;
+
+ private VirtualControlLoopEvent event;
+ private Target target;
+ private GenericVnf vnf;
+ private GetTargetEntityOperation2 oper;
+
+ /**
+ * Sets up.
+ */
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ event = new VirtualControlLoopEvent();
+ event.setTarget("pnf.pnf-name");
+ event.setAai(Map.of("pnf.pnf-name", MY_PNF));
+
+ target = new Target();
+ target.setType(TargetType.PNF);
+
+ vnf = new GenericVnf();
+ vnf.setVnfId(MY_VNF);
+
+ when(params.getTarget()).thenReturn(target);
+ when(params.getActor()).thenReturn(MY_ACTOR);
+ when(params.getOperation()).thenReturn(MY_OPERATION);
+
+ oper = new GetTargetEntityOperation2(stepContext, event, params);
+ }
+
+ @Test
+ public void testGetPropertyNames() {
+ // already have the data - no properties needed
+ assertThat(oper.getPropertyNames()).isEmpty();
+
+ // try an operation that needs data
+ remakeWithoutData();
+ assertEquals(List.of(UsecasesConstants.AAI_DEFAULT_GENERIC_VNF), oper.getPropertyNames());
+
+ // tell it the entity is available
+ when(stepContext.contains(OperationProperties.AAI_TARGET_ENTITY)).thenReturn(true);
+ assertThat(oper.getPropertyNames()).isEmpty();
+ }
+
+ @Test
+ public void testStart() {
+ assertThatThrownBy(() -> oper.start()).isInstanceOf(UnsupportedOperationException.class)
+ .hasMessage("cannot start get-target-entity operation");
+ }
+
+ /**
+ * Tests detmTarget() when the target has already been determined.
+ */
+ @Test
+ public void testDetmTargetRepeat() {
+ remakeWithoutData();
+ assertFalse(oper.getPropertyNames().isEmpty());
+
+ // tell it the entity is available
+ when(stepContext.contains(OperationProperties.AAI_TARGET_ENTITY)).thenReturn(true);
+ assertThat(oper.getPropertyNames()).isEmpty();
+
+ // repeat
+ assertThat(oper.getPropertyNames()).isEmpty();
+ }
+
+ /**
+ * Tests detmTarget() when the target is {@code null}.
+ */
+ @Test
+ public void testDetmTargetNull() {
+ remakeWithoutData();
+ when(params.getTarget()).thenReturn(null);
+
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
+ .withMessage("The target is null");
+ }
+
+ /**
+ * Tests detmTarget() when the target type is {@code null}.
+ */
+ @Test
+ public void testDetmTargetNullType() {
+ remakeWithoutData();
+ target.setType(null);
+
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
+ .withMessage("The target type is null");
+ }
+
+ /**
+ * Tests detmTarget() when the target type is VM and enrichment data is provided.
+ */
+ @Test
+ public void testDetmTargetVm() {
+ target.setType(TargetType.VM);
+ enrichTarget(VSERVER_NAME);
+ assertThat(oper.getPropertyNames()).isEmpty();
+ verifyTarget(MY_VNF);
+ }
+
+ /**
+ * Tests detmTarget() when the target type is VNF and enrichment data is provided.
+ */
+ @Test
+ public void testDetmTargetVnf() {
+ target.setType(TargetType.VNF);
+ enrichTarget(VSERVER_NAME);
+ assertThat(oper.getPropertyNames()).isEmpty();
+ verifyTarget(MY_VNF);
+ }
+
+ /**
+ * Tests detmTarget() when the target type is VF Module and enrichment data is
+ * provided.
+ */
+ @Test
+ public void testDetmTargetVfModule() {
+ target.setType(TargetType.VFMODULE);
+ enrichTarget(VSERVER_NAME);
+ assertThat(oper.getPropertyNames()).isEmpty();
+ verifyTarget(MY_VNF);
+ }
+
+ /**
+ * Tests detmTarget() when the target type is unknown.
+ */
+ @Test
+ public void testDetmTargetUnknownType() {
+ target.setType(TargetType.VFC);
+ enrichTarget(VSERVER_NAME);
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
+ .withMessage("The target type is not supported");
+ }
+
+ @Test
+ public void testDetmPnfTargetPnf() {
+ assertThat(oper.getPropertyNames()).isEmpty();
+ verifyTarget(MY_PNF);
+ }
+
+ /**
+ * Tests detmPnfTarget() when the target name is incorrect.
+ */
+ @Test
+ public void testDetmPnfTargetInvalidName() {
+ event.setTarget("unknown-pnf");
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
+ .withMessage("Target does not match target type");
+ }
+
+ /**
+ * Tests detmPnfTarget() when the enrichment data is missing.
+ */
+ @Test
+ public void testDetmPnfTargetPnfNoEnrichment() {
+ event.setAai(Map.of());
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
+ .withMessage("AAI section is missing pnf.pnf-name");
+ }
+
+ /**
+ * Tests detmVfModuleTarget() when the target is null.
+ */
+ @Test
+ public void testDetmVfModuleTargetNullTarget() {
+ target.setType(TargetType.VM);
+ event.setTarget(null);
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames()).withMessage("Target is null");
+ }
+
+ /**
+ * Tests detmVfModuleTarget() when the target is the vserver name.
+ */
+ @Test
+ public void testDetmVfModuleTargetVserverName() {
+ target.setType(TargetType.VM);
+ enrichTarget(VSERVER_NAME);
+ assertThat(oper.getPropertyNames()).isEmpty();
+ verifyTarget(MY_VNF);
+ }
+
+ /**
+ * Tests detmVfModuleTarget() when the target is the VNF ID.
+ */
+ @Test
+ public void testDetmVfModuleTargetVnfId() {
+ target.setType(TargetType.VM);
+ enrichTarget(GENERIC_VNF_ID);
+ assertThat(oper.getPropertyNames()).isEmpty();
+ verifyTarget(MY_VNF);
+ }
+
+ /**
+ * Tests detmVfModuleTarget() when the target is the VNF name. Note: the enrichment
+ * data is actually stored in the VNF ID field.
+ */
+ @Test
+ public void testDetmVfModuleTargetVnfName() {
+ target.setType(TargetType.VM);
+ enrichTarget(GENERIC_VNF_ID);
+
+ // set this AFTER setting enrichment data
+ event.setTarget("generic-vnf.vnf-name");
+
+ assertThat(oper.getPropertyNames()).isEmpty();
+ verifyTarget(MY_VNF);
+ }
+
+ /**
+ * Tests detmVfModuleTarget() when the target is unknown.
+ */
+ @Test
+ public void testDetmVfModuleTargetUnknown() {
+ target.setType(TargetType.VM);
+ enrichTarget(VSERVER_NAME);
+ event.setTarget("unknown-vnf");
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
+ .withMessage("Target does not match target type");
+ }
+
+ /**
+ * Tests detmVfModuleTarget() when the enrichment data is missing.
+ */
+ @Test
+ public void testDetmVfModuleTargetMissingEnrichment() {
+ target.setType(TargetType.VM);
+ event.setTarget(VSERVER_NAME);
+ assertThatIllegalArgumentException().isThrownBy(() -> oper.getPropertyNames())
+ .withMessage("Enrichment data is missing " + VSERVER_NAME);
+ }
+
+ /**
+ * Tests detmVnfName() when enrichment data is available.
+ */
+ @Test
+ public void testDetmVnfNameHaveData() {
+ target.setType(TargetType.VM);
+ event.setTarget(GENERIC_VNF_NAME);
+ event.setAai(Map.of(GENERIC_VNF_ID, MY_VNF));
+ assertThat(oper.getPropertyNames()).isEmpty();
+ verifyTarget(MY_VNF);
+ }
+
+ /**
+ * Tests detmVnfName() when enrichment data is missing.
+ */
+ @Test
+ public void testDetmVnfNameNoData() {
+ target.setType(TargetType.VM);
+ event.setTarget(GENERIC_VNF_NAME);
+ assertThat(oper.getPropertyNames()).isEqualTo(List.of(UsecasesConstants.AAI_DEFAULT_GENERIC_VNF));
+ }
+
+ @Test
+ public void testSetProperty() {
+ target.setType(TargetType.VM);
+ event.setTarget(GENERIC_VNF_NAME);
+
+ // not a property of interest - should be ignored
+ oper.setProperty("unknown-property", vnf);
+ verify(stepContext, never()).setProperty(any(), any());
+
+ // now set the desired property and try again
+ oper.setProperty(UsecasesConstants.AAI_DEFAULT_GENERIC_VNF, vnf);
+ verifyTarget(MY_VNF);
+ }
+
+ @Test
+ public void testGetActorName_testGetName() {
+ assertEquals(MY_ACTOR, oper.getActorName());
+ assertEquals(MY_OPERATION, oper.getName());
+ }
+
+ private void verifyTarget(String targetEntity) {
+ verify(stepContext).setProperty(OperationProperties.AAI_TARGET_ENTITY, targetEntity);
+ }
+
+ private void remakeWithoutData() {
+ target.setType(TargetType.VNF);
+ event.setTarget(GENERIC_VNF_NAME);
+ oper = new GetTargetEntityOperation2(stepContext, event, params);
+ }
+
+ private void enrichTarget(String enrichmentTargetType) {
+ event.setTarget(enrichmentTargetType);
+ event.setAai(Map.of(enrichmentTargetType, MY_VNF));
+ }
+}
diff --git a/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2Test.java b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2Test.java
new file mode 100644
index 000000000..dfbedc2c7
--- /dev/null
+++ b/controlloop/common/controller-usecases/src/test/java/org/onap/policy/drools/apps/controller/usecases/LockOperation2Test.java
@@ -0,0 +1,121 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * 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.apps.controller.usecases;
+
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertSame;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.Mockito.when;
+
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.CompletableFuture;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
+import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.eventmanager.StepContext;
+import org.onap.policy.controlloop.policy.Target;
+import org.onap.policy.controlloop.policy.TargetType;
+
+public class LockOperation2Test {
+ private static final String MY_PNF = "my-pnf";
+ private static final String MY_VNF = "my-vnf";
+ private static final String MY_ACTOR = "my-actor";
+ private static final String MY_OPERATION = "my-operation";
+
+ @Mock
+ private StepContext stepContext;
+ @Mock
+ private ControlLoopOperationParams params;
+
+ private VirtualControlLoopEvent event;
+ private Target target;
+ private CompletableFuture<OperationOutcome> future;
+ private GenericVnf vnf;
+ private LockOperation2 oper;
+
+ /**
+ * Sets up.
+ */
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+
+ event = new VirtualControlLoopEvent();
+ event.setTarget("pnf.pnf-name");
+ event.setAai(Map.of("pnf.pnf-name", MY_PNF));
+
+ target = new Target();
+ target.setType(TargetType.PNF);
+
+ future = new CompletableFuture<>();
+
+ vnf = new GenericVnf();
+ vnf.setVnfId(MY_VNF);
+
+ when(stepContext.requestLock(anyString())).thenReturn(future);
+
+ when(params.getTarget()).thenReturn(target);
+ when(params.getActor()).thenReturn(MY_ACTOR);
+ when(params.getOperation()).thenReturn(MY_OPERATION);
+
+ oper = new LockOperation2(stepContext, params);
+ }
+
+ @Test
+ public void testGetPropertyNames() {
+ assertThat(oper.getPropertyNames()).isEqualTo(List.of(OperationProperties.AAI_TARGET_ENTITY));
+ }
+
+ @Test
+ public void testStart() {
+ // missing data
+ assertThatIllegalStateException().isThrownBy(() -> oper.start())
+ .withMessage("target lock entity has not been determined yet");
+
+ oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "some-target");
+ assertSame(future, oper.start());
+ }
+
+ @Test
+ public void testSetProperty() {
+ oper.setProperty("unknown-property", "some data");
+ assertNull(oper.getTargetEntity());
+
+ oper.setProperty(OperationProperties.AAI_TARGET_ENTITY, "other data");
+ assertEquals("other data", oper.getTargetEntity());
+ }
+
+ @Test
+ public void testGetActorName_testGetName() {
+ assertEquals(MY_ACTOR, oper.getActorName());
+ assertEquals(MY_OPERATION, oper.getName());
+ }
+}
diff --git a/controlloop/common/controller-usecases/src/test/resources/config/event-manager.properties b/controlloop/common/controller-usecases/src/test/resources/config/event-manager.properties
new file mode 100644
index 000000000..bd82b50a7
--- /dev/null
+++ b/controlloop/common/controller-usecases/src/test/resources/config/event-manager.properties
@@ -0,0 +1,83 @@
+#
+# ============LICENSE_START======================================================
+# ONAP
+# ===============================================================================
+# 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========================================================
+#
+
+# DB parameters
+operation.history.url=jdbc:h2:mem:Usecases
+operation.history.userName=sa
+operation.history.password=
+
+# Actor parameters
+#
+# Note: every operation must have at least one entry, otherwise it will not be
+# configured and started. Thus some of them have a "placeholder" property.
+#
+
+#actor.service.GUARD.disabled=true
+actor.service.GUARD.clientName=GUARD
+actor.service.GUARD.onapName=my-onap-name
+actor.service.GUARD.onapComponent=my-onap-component
+actor.service.GUARD.onapInstance=my-onap-instance
+actor.service.GUARD.operations.Decision.path=decision
+
+actor.service.AAI.clientName=AAI
+actor.service.AAI.operations.CustomQuery.path=aai/v16/query
+actor.service.AAI.operations.Pnf.path=aai/v16/network/pnfs/pnf
+actor.service.AAI.operations.Tenant.path=aai/v16/search/nodes-query
+
+actor.service.APPC.sinkTopic=APPC-LCM-READ
+actor.service.APPC.sourceTopic=APPC-LCM-WRITE
+actor.service.APPC.operations.ConfigModify.placeholder=
+actor.service.APPC.operations.Migrate.placeholder=
+actor.service.APPC.operations.Restart.placeholder=
+actor.service.APPC.operations.Rebuild.placeholder=
+
+# legacy APPC - must specify sink and source for each operation
+actor.service.APPC.operations.ModifyConfig.sinkTopic=APPC-CL
+actor.service.APPC.operations.ModifyConfig.sourceTopic=APPC-CL
+
+actor.service.CDS.operations.any.host=localhost
+actor.service.CDS.operations.any.port=7878
+actor.service.CDS.operations.any.username=grpc-username
+actor.service.CDS.operations.any.password=grpc-password
+actor.service.CDS.operations.any.timeout=10
+
+actor.service.SDNC.clientName=SDNC
+actor.service.SDNC.operations.BandwidthOnDemand.path=\
+ GENERIC-RESOURCE-API:vf-module-topology-operation
+actor.service.SDNC.operations.Reroute.path=\
+ GENERIC-RESOURCE-API:network-topology-operation
+
+actor.service.SDNR.sinkTopic=SDNR-CL
+actor.service.SDNR.sourceTopic=SDNR-CL-RSP
+actor.service.SDNR.operations.any.placeholder=
+
+actor.service.SO.clientName=SO
+actor.service.SO.pollPath=orchestrationRequests/v5/
+actor.service.SO.maxPolls=20
+actor.service.SO.pollWaitSec=20
+actor.service.SO.operations.VF\ Module\ Create.path=serviceInstantiation/v7/serviceInstances
+actor.service.SO.operations.VF\ Module\ Delete.path=serviceInstances/v7
+
+actor.service.VFC.clientName=VFC
+actor.service.VFC.pollPath=jobs
+actor.service.VFC.maxPolls=20
+actor.service.VFC.pollWaitSec=20
+actor.service.VFC.operations.Restart.path=ns
+actor.service.VFC.operations.Restart.timeoutSec=60
diff --git a/controlloop/common/controller-usecases/src/test/resources/config/usecases-controller.properties b/controlloop/common/controller-usecases/src/test/resources/config/usecases-controller.properties
new file mode 100644
index 000000000..f90b1d18c
--- /dev/null
+++ b/controlloop/common/controller-usecases/src/test/resources/config/usecases-controller.properties
@@ -0,0 +1,63 @@
+#
+# ============LICENSE_START=======================================================
+# ONAP
+# ================================================================================
+# 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=========================================================
+#
+
+controller.name=usecases
+
+rules.groupId=org.onap.policy.controlloop
+rules.artifactId=usecases
+rules.version=1.1.0
+
+noop.source.topics=DCAE_TOPIC,APPC-CL,APPC-LCM-WRITE,SDNR-CL-RSP,POLICY-CL-MGT,APPC-LCM-READ
+
+noop.source.topics.DCAE_TOPIC.events=\
+ org.onap.policy.controlloop.CanonicalOnset,org.onap.policy.controlloop.CanonicalAbated
+noop.source.topics.DCAE_TOPIC.events.org.onap.policy.controlloop.CanonicalOnset.\
+ filter=[?($.closedLoopEventStatus == 'ONSET')]
+noop.source.topics.DCAE_TOPIC.events.org.onap.policy.controlloop.CanonicalAbated.\
+ filter=[?($.closedLoopEventStatus == 'ABATED')]
+noop.source.topics.DCAE_TOPIC.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gson
+
+noop.source.topics.APPC-CL.events=org.onap.policy.appc.Response,org.onap.policy.appc.Request
+noop.source.topics.APPC-CL.events.org.onap.policy.appc.Response.filter=[?($.CommonHeader && $.Status)]
+noop.source.topics.APPC-CL.events.org.onap.policy.appc.Request.filter=[?($.CommonHeader && $.Action)]
+noop.source.topics.APPC-CL.events.custom.gson=org.onap.policy.appc.util.Serialization,gsonPretty
+
+noop.source.topics.APPC-LCM-WRITE.events=org.onap.policy.appclcm.AppcLcmDmaapWrapper
+noop.source.topics.APPC-LCM-WRITE.events.org.onap.policy.appclcm.AppcLcmDmaapWrapper.filter=[?($.type == 'response')]
+noop.source.topics.APPC-LCM-WRITE.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson
+
+noop.source.topics.SDNR-CL-RSP.events=org.onap.policy.sdnr.PciResponseWrapper
+noop.source.topics.SDNR-CL-RSP.events.org.onap.policy.sdnr.PciResponseWrapper.filter=[?($.type == 'response')]
+noop.source.topics.SDNR-CL-RSP.events.custom.gson=org.onap.policy.sdnr.util.Serialization,gson
+
+noop.source.topics.POLICY-CL-MGT.events=org.onap.policy.controlloop.VirtualControlLoopNotification
+noop.source.topics.POLICY-CL-MGT.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty
+
+noop.source.topics.APPC-LCM-READ.events=org.onap.policy.appclcm.AppcLcmDmaapWrapper
+noop.source.topics.APPC-LCM-READ.events.custom.gson=org.onap.policy.appclcm.util.Serialization,gson
+
+noop.sink.topics=APPC-CL,APPC-LCM-READ,POLICY-CL-MGT,SDNR-CL,DCAE_CL_RSP
+
+noop.sink.topics.POLICY-CL-MGT.events=org.onap.policy.controlloop.VirtualControlLoopNotification
+noop.sink.topics.POLICY-CL-MGT.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty
+
+noop.sink.topics.DCAE_CL_RSP.events=org.onap.policy.controlloop.ControlLoopResponse
+noop.sink.topics.DCAE_CL_RSP.events.custom.gson=org.onap.policy.controlloop.util.Serialization,gsonPretty
+
diff --git a/controlloop/common/controller-usecases/src/test/resources/config/usecases-http-client.properties b/controlloop/common/controller-usecases/src/test/resources/config/usecases-http-client.properties
new file mode 100644
index 000000000..1e3e88cec
--- /dev/null
+++ b/controlloop/common/controller-usecases/src/test/resources/config/usecases-http-client.properties
@@ -0,0 +1,52 @@
+#
+# ============LICENSE_START=======================================================
+# ONAP
+# ================================================================================
+# 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=========================================================
+#
+
+http.client.services=GUARD,AAI,SDNC,SO,VFC
+
+http.client.services.GUARD.managed=true
+http.client.services.GUARD.host=localhost
+http.client.services.GUARD.port=6669
+http.client.services.GUARD.userName=pdpx
+http.client.services.GUARD.password=pdpx
+http.client.services.GUARD.contextUriPath=policy/pdpx/v1/
+
+http.client.services.AAI.managed=true
+http.client.services.AAI.host=localhost
+http.client.services.AAI.port=6666
+http.client.services.AAI.contextUriPath=
+
+http.client.services.SDNC.managed=true
+http.client.services.SDNC.host=localhost
+http.client.services.SDNC.port=6665
+http.client.services.SDNC.userName=sdnc
+http.client.services.SDNC.password=sdnc
+http.client.services.SDNC.contextUriPath=
+
+http.client.services.SO.managed=true
+http.client.services.SO.host=localhost
+http.client.services.SO.port=6667
+http.client.services.SO.contextUriPath=
+
+http.client.services.VFC.managed=true
+http.client.services.VFC.host=localhost
+http.client.services.VFC.port=6668
+http.client.services.VFC.userName=VFC
+http.client.services.VFC.password=VFC
+http.client.services.VFC.contextUriPath=api/nslcm/v1