From 78d55c53a2ec15267bcd5d16a830b99f784aa5c4 Mon Sep 17 00:00:00 2001 From: Ritu Sood Date: Sun, 17 Sep 2017 15:34:16 -0700 Subject: 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 --- controlloop/common/actors/actor.vfc/pom.xml | 7 +++ .../actor/vfc/VFCActorServiceProvider.java | 68 +++++++++++++++++----- 2 files changed, 61 insertions(+), 14 deletions(-) (limited to 'controlloop') 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 @@ 1.1.0-SNAPSHOT provided + + org.onap.policy.drools-applications + aai + 1.1.0-SNAPSHOT + provided + + 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 recipes = ImmutableList.of("Restart"); private static final ImmutableMap> targets = new ImmutableMap.Builder>() - .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; + } } -- cgit 1.2.3-korg