diff options
author | Jorge Hernandez <jh1730@att.com> | 2017-09-19 19:11:51 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2017-09-19 19:11:51 +0000 |
commit | 2313dd4767975e7d814e52613afab8054b84208c (patch) | |
tree | 0f8c734b57692e907def02787515bef4b9cca8f5 /controlloop/common/actors | |
parent | d57ce70f4454210c4ed04476af564ca10bb66292 (diff) | |
parent | 78d55c53a2ec15267bcd5d16a830b99f784aa5c4 (diff) |
Merge "Adding reading service-id from AA&I"
Diffstat (limited to 'controlloop/common/actors')
-rw-r--r-- | controlloop/common/actors/actor.vfc/pom.xml | 7 | ||||
-rw-r--r-- | controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java | 68 |
2 files changed, 61 insertions, 14 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; + } } |