diff options
author | 2018-03-21 15:22:10 +0000 | |
---|---|---|
committer | 2018-03-22 13:58:39 +0000 | |
commit | af861a9d8e28d49d357ead4a4acad82554510b6f (patch) | |
tree | 8f21c330990242ed4a2b40b13bae811a9affc7fb /controlloop/common/actors/actor.vfc/src/main | |
parent | 512a8f5b4dc9afaf382dd76531dcbc0667551c58 (diff) |
Removed checkstyle warnings
Removed checkstyle warnings in:
policy/drools-applications/controlloop/common/actors
policy/drools-applications/controlloop/common/eventmanager
policy/drools-applications/controlloop/common/feature-controlloop-utils
Issue-ID: POLICY-705
Change-Id: Iccf99b291bc62bc3ba2082ccdb4c1f9e12107896
Signed-off-by: mmis <michael.morris@ericsson.com>
Diffstat (limited to 'controlloop/common/actors/actor.vfc/src/main')
-rw-r--r-- | controlloop/common/actors/actor.vfc/src/main/java/org/onap/policy/controlloop/actor/vfc/VFCActorServiceProvider.java | 225 |
1 files changed, 119 insertions, 106 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 c2de78c2c..839b07e2b 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 @@ -1,6 +1,6 @@ /*- * ============LICENSE_START======================================================= - * Copyright (C) 2017 Intel Corp. All rights reserved. + * Copyright (C) 2017-2018 Intel Corp. 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. @@ -18,120 +18,133 @@ package org.onap.policy.controlloop.actor.vfc; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + import java.util.Collections; import java.util.List; import java.util.UUID; -import org.onap.policy.controlloop.VirtualControlLoopEvent; -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.aai.AAIGETVnfResponse; +import org.onap.policy.aai.AAIManager; 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.drools.system.PolicyEngine; import org.onap.policy.rest.RESTManager; -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 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.slf4j.Logger; import org.slf4j.LoggerFactory; public class VFCActorServiceProvider implements Actor { - private static final Logger logger = LoggerFactory.getLogger(VFCActorServiceProvider.class); - - // Strings for VFC Actor - private static final String VFC_ACTOR = "VFC"; - - // Strings for targets - private static final String TARGET_VM = "VM"; - - // Strings for recipes - private static final String RECIPE_RESTART = "Restart"; - - private static final ImmutableList<String> recipes = ImmutableList.of(RECIPE_RESTART); - private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>() - .put(RECIPE_RESTART, ImmutableList.of(TARGET_VM)).build(); - - @Override - public String actor() { - return VFC_ACTOR; - } - - @Override - public List<String> recipes() { - return ImmutableList.copyOf(recipes); - } - - @Override - public List<String> recipeTargets(String recipe) { - return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList())); - } - - @Override - public List<String> recipePayloads(String recipe) { - return Collections.emptyList(); - } - - public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, - Policy policy, AAIGETVnfResponse vnfResponse) { - - // Construct an VFC request - VFCRequest request = new VFCRequest(); - String serviceInstance = onset.getAAI().get("service-instance.service-instance-id"); - if (serviceInstance == null || "".equals(serviceInstance)) - { - AAIGETVnfResponse tempVnfResp = vnfResponse; - if(tempVnfResp == null) //if the response is null, we haven't queried - { - tempVnfResp = getAAIServiceInstance(onset); //This does the AAI query since we haven't already - if (tempVnfResp == null) - return null; - } - serviceInstance = tempVnfResp.getServiceId(); - } - request.setNSInstanceId(serviceInstance); - request.setRequestId(onset.getRequestID()); - request.setHealRequest(new VFCHealRequest()); - request.getHealRequest().setVnfInstanceId(onset.getAAI().get("generic-vnf.vnf-id")); - request.getHealRequest().setCause(operation.getMessage()); - request.getHealRequest().setAdditionalParams(new VFCHealAdditionalParams()); - - if (policy.getRecipe().toLowerCase().equalsIgnoreCase(RECIPE_RESTART)) { - request.getHealRequest().getAdditionalParams().setAction("restartvm"); - request.getHealRequest().getAdditionalParams().setActionInfo(new VFCHealActionVmInfo()); - request.getHealRequest().getAdditionalParams().getActionInfo().setVmid(onset.getAAI().get("vserver.vserver-id")); - request.getHealRequest().getAdditionalParams().getActionInfo().setVmname(onset.getAAI().get("vserver.vserver-name")); - } - else { - return null; - } - return request; - } - - private static AAIGETVnfResponse getAAIServiceInstance(VirtualControlLoopEvent event) { - AAIGETVnfResponse response = null; - UUID requestID = event.getRequestID(); - String vnfName = event.getAAI().get("generic-vnf.vnf-name"); - String vnfID = event.getAAI().get("generic-vnf.vnf-id"); - String aaiUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url"); - String aaiUsername = PolicyEngine.manager.getEnvironmentProperty("aai.username"); - String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password"); - try { - if (vnfName != null) { - String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; - response = new AAIManager(new RESTManager()).getQueryByVnfName(url, aaiUsername, aaiPassword, requestID, vnfName); - } else if (vnfID != null) { - String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf/"; - response = new AAIManager(new RESTManager()).getQueryByVnfID(url, aaiUsername, aaiPassword, requestID, vnfID); - } else { - logger.error("getAAIServiceInstance failed"); - } - } catch (Exception e) { - logger.error("getAAIServiceInstance exception: ", e); - } - return response; - } + private static final Logger logger = LoggerFactory.getLogger(VFCActorServiceProvider.class); + + // Strings for VFC Actor + private static final String VFC_ACTOR = "VFC"; + + // Strings for targets + private static final String TARGET_VM = "VM"; + + // Strings for recipes + private static final String RECIPE_RESTART = "Restart"; + + private static final ImmutableList<String> recipes = ImmutableList.of(RECIPE_RESTART); + private static final ImmutableMap<String, List<String>> targets = + new ImmutableMap.Builder<String, List<String>>().put(RECIPE_RESTART, ImmutableList.of(TARGET_VM)).build(); + + @Override + public String actor() { + return VFC_ACTOR; + } + + @Override + public List<String> recipes() { + return ImmutableList.copyOf(recipes); + } + + @Override + public List<String> recipeTargets(String recipe) { + return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList())); + } + + @Override + public List<String> recipePayloads(String recipe) { + return Collections.emptyList(); + } + + /** + * Construct a request. + * + * @param onset the onset event + * @param operation the control loop operation + * @param policy the policy + * @param vnfResponse the VNF response + * @return the constructed request + */ + public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, + Policy policy, AAIGETVnfResponse vnfResponse) { + + // Construct an VFC request + VFCRequest request = new VFCRequest(); + String serviceInstance = onset.getAAI().get("service-instance.service-instance-id"); + if (serviceInstance == null || "".equals(serviceInstance)) { + AAIGETVnfResponse tempVnfResp = vnfResponse; + if (tempVnfResp == null) { // if the response is null, we haven't queried + // This does the AAI query since we haven't already + tempVnfResp = getAaiServiceInstance(onset); + if (tempVnfResp == null) { + return null; + } + } + serviceInstance = tempVnfResp.getServiceId(); + } + request.setNSInstanceId(serviceInstance); + request.setRequestId(onset.getRequestID()); + request.setHealRequest(new VFCHealRequest()); + request.getHealRequest().setVnfInstanceId(onset.getAAI().get("generic-vnf.vnf-id")); + request.getHealRequest().setCause(operation.getMessage()); + request.getHealRequest().setAdditionalParams(new VFCHealAdditionalParams()); + + if (policy.getRecipe().toLowerCase().equalsIgnoreCase(RECIPE_RESTART)) { + request.getHealRequest().getAdditionalParams().setAction("restartvm"); + request.getHealRequest().getAdditionalParams().setActionInfo(new VFCHealActionVmInfo()); + request.getHealRequest().getAdditionalParams().getActionInfo() + .setVmid(onset.getAAI().get("vserver.vserver-id")); + request.getHealRequest().getAdditionalParams().getActionInfo() + .setVmname(onset.getAAI().get("vserver.vserver-name")); + } else { + return null; + } + return request; + } + + private static AAIGETVnfResponse getAaiServiceInstance(VirtualControlLoopEvent event) { + AAIGETVnfResponse response = null; + UUID requestId = event.getRequestID(); + String vnfName = event.getAAI().get("generic-vnf.vnf-name"); + String vnfId = event.getAAI().get("generic-vnf.vnf-id"); + String aaiUrl = PolicyEngine.manager.getEnvironmentProperty("aai.url"); + String aaiUsername = PolicyEngine.manager.getEnvironmentProperty("aai.username"); + String aaiPassword = PolicyEngine.manager.getEnvironmentProperty("aai.password"); + try { + if (vnfName != null) { + String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf?vnf-name="; + response = new AAIManager(new RESTManager()).getQueryByVnfName(url, aaiUsername, aaiPassword, requestId, + vnfName); + } else if (vnfId != null) { + String url = aaiUrl + "/aai/v11/network/generic-vnfs/generic-vnf/"; + response = new AAIManager(new RESTManager()).getQueryByVnfID(url, aaiUsername, aaiPassword, requestId, + vnfId); + } else { + logger.error("getAAIServiceInstance failed"); + } + } catch (Exception e) { + logger.error("getAAIServiceInstance exception: ", e); + } + return response; + } } |