summaryrefslogtreecommitdiffstats
path: root/controlloop/common
diff options
context:
space:
mode:
Diffstat (limited to 'controlloop/common')
-rw-r--r--controlloop/common/actors/actor.vfc/pom.xml7
-rw-r--r--controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java68
-rw-r--r--controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java6
-rw-r--r--controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AAINQResponseTest.java8
-rw-r--r--controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java13
5 files changed, 74 insertions, 28 deletions
diff --git a/controlloop/common/actors/actor.vfc/pom.xml b/controlloop/common/actors/actor.vfc/pom.xml
index de6f05841..c52b6aed7 100644
--- a/controlloop/common/actors/actor.vfc/pom.xml
+++ b/controlloop/common/actors/actor.vfc/pom.xml
@@ -28,5 +28,12 @@
<version>1.1.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.onap.policy.drools-applications</groupId>
+ <artifactId>aai</artifactId>
+ <version>1.1.0-SNAPSHOT</version>
+ <scope>provided</scope>
+ </dependency>
+
</dependencies>
</project>
diff --git a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java
index bd06ef133..49b93e8aa 100644
--- a/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java
+++ b/controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java
@@ -5,9 +5,9 @@
* 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.
@@ -19,27 +19,35 @@
package org.onap.policy.controlloop.actor.vfc;
import java.util.Collections;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
-import org.onap.policy.controlloop.ControlLoopOperation;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.actorServiceProvider.spi.Actor;
-import org.onap.policy.controlloop.policy.Policy;
-import org.onap.policy.vfc.VFCHealActionVmInfo;
-import org.onap.policy.vfc.VFCHealAdditionalParams;
-import org.onap.policy.vfc.VFCHealRequest;
import org.onap.policy.vfc.VFCRequest;
+import org.onap.policy.vfc.VFCHealRequest;
+import org.onap.policy.vfc.VFCHealAdditionalParams;
+import org.onap.policy.vfc.VFCHealActionVmInfo;
+import org.onap.policy.controlloop.ControlLoopOperation;
+import org.onap.policy.controlloop.policy.Policy;
+import org.onap.policy.controlloop.actorServiceProvider.spi.Actor;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import org.onap.policy.aai.AAIManager;
+import org.onap.policy.aai.AAIGETVnfResponse;
+
+import java.util.UUID;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class VFCActorServiceProvider implements Actor {
+ private static final Logger logger = LoggerFactory.getLogger(VFCActorServiceProvider.class);
private static final ImmutableList<String> recipes = ImmutableList.of("Restart");
private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
- .put("Restart", ImmutableList.of("VM"))
- .build();
+ .put("Restart", ImmutableList.of("VM")).build();
@Override
public String actor() {
@@ -61,12 +69,14 @@ public class VFCActorServiceProvider implements Actor {
return Collections.emptyList();
}
- public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) {
+ public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation,
+ Policy policy) {
// Construct an VFC request
VFCRequest request = new VFCRequest();
// TODO: Verify service-instance-id is part of onset event
- request.nsInstanceId = onset.AAI.get("service-instance.service-instance-id");
+ request.nsInstanceId = getAAIServiceInstance(onset); // onset.AAI.get("service-instance.service-instance-id");
+
request.healRequest = new VFCHealRequest();
request.healRequest.vnfInstanceId = onset.AAI.get("generic-vnf.vnf-id");
request.healRequest.cause = operation.message;
@@ -82,11 +92,41 @@ public class VFCActorServiceProvider implements Actor {
request.healRequest.additionalParams.actionInfo.vmname = onset.AAI.get("vserver.vserver-name");
break;
default:
- //TODO: default
+ // TODO: default
break;
}
return request;
}
-
+ private static String getAAIServiceInstance(VirtualControlLoopEvent event) {
+ AAIGETVnfResponse response = null;
+ UUID requestID = event.requestID;
+ String serviceInstance = event.AAI.get("service-instance.service-instance-id");
+ String vnfName = event.AAI.get("generic-vnf.vnf-name");
+ String vnfID = event.AAI.get("generic-vnf.vnf-id");
+
+ String urlBase = "http://localhost:6666";
+ String username = "testUser";
+ String password = "testPass";
+ if (serviceInstance == null) {
+ try {
+ AAIManager manager = new AAIManager();
+ if (vnfName != null) {
+ String url = urlBase + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name=";
+ response = manager.getQueryByVnfName(url, username, password, requestID, vnfName);
+ serviceInstance = response.serviceId;
+ } else if (vnfID != null) {
+ String url = urlBase + "/aai/v11/network/generic-vnfs/generic-vnf/";
+ response = manager.getQueryByVnfID(url, username, password, requestID, vnfID);
+ serviceInstance = response.serviceId;
+ } else {
+ logger.error("getAAIServiceInstance failed");
+
+ }
+ } catch (Exception e) {
+ logger.error("getAAIServiceInstance exception: ", e);
+ }
+ }
+ return serviceInstance;
+ }
}
diff --git a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
index f891a2c6a..4b5d6c935 100644
--- a/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
+++ b/controlloop/common/eventmanager/src/main/java/org/onap/policy/controlloop/eventmanager/ControlLoopEventManager.java
@@ -540,7 +540,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (vnfResponse == null) {
throw new ControlLoopException("AAI Response is null (query by vnf-id)");
}
- if (vnfResponse != null && isClosedLoopDisabled(vnfResponse) == true) {
+ if (isClosedLoopDisabled(vnfResponse) == true) {
throw new ControlLoopException("is-closed-loop-disabled is set to true");
}
} else if (event.AAI.get("generic-vnf.vnf-name") != null) {
@@ -548,7 +548,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (vnfResponse == null) {
throw new ControlLoopException("AAI Response is null (query by vnf-name)");
}
- if (vnfResponse != null && isClosedLoopDisabled(vnfResponse) == true) {
+ if (isClosedLoopDisabled(vnfResponse) == true) {
throw new ControlLoopException("is-closed-loop-disabled is set to true");
}
} else if (event.AAI.get("vserver.vserver-name") != null) {
@@ -556,7 +556,7 @@ public class ControlLoopEventManager implements LockCallback, Serializable {
if (vserverResponse == null) {
throw new ControlLoopException("AAI Response is null (query by vserver-name)");
}
- if (vserverResponse != null && isClosedLoopDisabled(vserverResponse) == true) {
+ if (isClosedLoopDisabled(vserverResponse) == true) {
throw new ControlLoopException("is-closed-loop-disabled is set to true");
}
}
diff --git a/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AAINQResponseTest.java b/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AAINQResponseTest.java
index be11942c5..6b1b624ef 100644
--- a/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AAINQResponseTest.java
+++ b/controlloop/common/model-impl/aai/src/test/java/org/onap/policy/aai/AAINQResponseTest.java
@@ -19,14 +19,12 @@
*/
package org.onap.policy.aai;
-import static org.junit.Assert.*;
-import java.util.List;
-import java.util.LinkedList;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.util.LinkedList;
import org.junit.Test;
import org.onap.policy.aai.util.Serialization;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class AAINQResponseTest {
private static final Logger logger = LoggerFactory.getLogger(AAINQResponseTest.class);
diff --git a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java
index 4de0f81f9..7bd745936 100644
--- a/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java
+++ b/controlloop/common/model-impl/appc/src/main/java/org/onap/policy/appc/ResponseValue.java
@@ -33,25 +33,26 @@ public enum ResponseValue {
private ResponseValue(String value) {
this.value = value;
}
-
+
+ @Override
public String toString() {
return this.value;
}
public static ResponseValue toResponseValue(String value) {
- if (value.toString().equals(ACCEPT.toString())) {
+ if (value.equals(ACCEPT.toString())) {
return ACCEPT;
}
- if (value.toString().equals(ERROR.toString())) {
+ if (value.equals(ERROR.toString())) {
return ERROR;
}
- if (value.toString().equals(REJECT.toString())) {
+ if (value.equals(REJECT.toString())) {
return REJECT;
}
- if (value.toString().equals(SUCCESS.toString())) {
+ if (value.equals(SUCCESS.toString())) {
return SUCCESS;
}
- if (value.toString().equals(FAILURE.toString())) {
+ if (value.equals(FAILURE.toString())) {
return FAILURE;
}