summaryrefslogtreecommitdiffstats
path: root/controlloop/common/actors/actor.vfc/src
diff options
context:
space:
mode:
authorRitu Sood <ritu.sood@intel.com>2017-09-17 15:34:16 -0700
committerRitu Sood <ritu.sood@intel.com>2017-09-17 15:47:45 -0700
commit78d55c53a2ec15267bcd5d16a830b99f784aa5c4 (patch)
treef2c563587c91a20fea399f51d69f570236c45d24 /controlloop/common/actors/actor.vfc/src
parent49137f3c5ecd0a3c2fbc7e9195ef18aa5b43fc11 (diff)
Adding reading service-id from AA&I
For VFC adding getting service-id from AA&I. Issue-Id: POLICY-57 Change-Id: I740c7749bfb2d395851cbd5eb3e486bf4eb9b560 Signed-off-by: Ritu Sood <ritu.sood@intel.com>
Diffstat (limited to 'controlloop/common/actors/actor.vfc/src')
-rw-r--r--controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java68
1 files changed, 54 insertions, 14 deletions
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;
+ }
}