From c6012167b9692eb38bcb479f233543e93c51c998 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Thu, 2 Jul 2020 09:30:52 -0400 Subject: Rename XxxActorServiceProvider to XxxActor Renamed the actors and their test classes. Addressed review comments: - some license dates Issue-ID: POLICY-2684 Change-Id: Ic9d83e146ef36bb305496d541166cb9f80544025 Signed-off-by: Jim Hahn --- .../policy/controlloop/actor/sdnc/SdncActor.java | 223 +++++++++++++++++++++ .../actor/sdnc/SdncActorServiceProvider.java | 223 --------------------- ...licy.controlloop.actorserviceprovider.spi.Actor | 2 +- 3 files changed, 224 insertions(+), 224 deletions(-) create mode 100644 models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActor.java delete mode 100644 models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java (limited to 'models-interactions/model-actors/actor.sdnc/src/main') diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActor.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActor.java new file mode 100644 index 000000000..a5cf65f34 --- /dev/null +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActor.java @@ -0,0 +1,223 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP + * ================================================================================ + * Copyright (C) 2018-2019 Huawei Intellectual Property. All rights reserved. + * Modifications Copyright (C) 2019 Nordix Foundation. + * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. + * ================================================================================ + * 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. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.controlloop.actor.sdnc; + +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.ControlLoopOperation; +import org.onap.policy.controlloop.VirtualControlLoopEvent; +import org.onap.policy.controlloop.actorserviceprovider.impl.HttpActor; +import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator; +import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpActorParams; +import org.onap.policy.controlloop.policy.Policy; +import org.onap.policy.sdnc.SdncHealNetworkInfo; +import org.onap.policy.sdnc.SdncHealRequest; +import org.onap.policy.sdnc.SdncHealRequestHeaderInfo; +import org.onap.policy.sdnc.SdncHealRequestInfo; +import org.onap.policy.sdnc.SdncHealServiceInfo; +import org.onap.policy.sdnc.SdncHealVfModuleInfo; +import org.onap.policy.sdnc.SdncHealVfModuleParameter; +import org.onap.policy.sdnc.SdncHealVfModuleParametersInfo; +import org.onap.policy.sdnc.SdncHealVfModuleRequestInput; +import org.onap.policy.sdnc.SdncHealVnfInfo; +import org.onap.policy.sdnc.SdncRequest; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class SdncActor extends HttpActor { + private static final Logger logger = LoggerFactory.getLogger(SdncActor.class); + + public static final String NAME = "SDNC"; + + // TODO old code: remove lines down to **HERE** + + // Strings for Sdnc Actor + private static final String SDNC_ACTOR = "SDNC"; + + // Strings for targets + private static final String TARGET_VM = "VM"; + + // Strings for recipes + private static final String RECIPE_REROUTE = "Reroute"; + + // Strings for recipes + private static final String RECIPE_BW_ON_DEMAND = "BandwidthOnDemand"; + + private static final ImmutableList recipes = ImmutableList.of(RECIPE_REROUTE); + private static final ImmutableMap> targets = new ImmutableMap.Builder>() + .put(RECIPE_REROUTE, ImmutableList.of(TARGET_VM)).build(); + + // **HERE** + + /** + * Constructs the object. + */ + public SdncActor() { + super(NAME, HttpActorParams.class); + + addOperator(new HttpOperator(NAME, RerouteOperation.NAME, RerouteOperation::new)); + addOperator(new HttpOperator(NAME, BandwidthOnDemandOperation.NAME, BandwidthOnDemandOperation::new)); + } + + + // TODO old code: remove lines down to **HERE** + + @Override + public String actor() { + return SDNC_ACTOR; + } + + @Override + public List recipes() { + return ImmutableList.copyOf(recipes); + } + + @Override + public List recipeTargets(String recipe) { + return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList())); + } + + @Override + public List recipePayloads(String recipe) { + return Collections.emptyList(); + } + + /** + * Construct a request. + * + * @param onset the onset event + * @param operation the control loop operation + * @param policy the policy + * @return the constructed request + */ + public SdncRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) { + switch (policy.getRecipe()) { + case RECIPE_REROUTE: + return constructReOptimizeRequest(onset); + case RECIPE_BW_ON_DEMAND: + logger.info("Construct request for receipe {}", RECIPE_BW_ON_DEMAND); + return constructBwOnDemandRequest(onset); + default: + logger.info("Unsupported recipe {}", policy.getRecipe()); + return null; + } + } + + private SdncRequest constructBwOnDemandRequest(VirtualControlLoopEvent onset) { + // Construct an Sdnc request + String serviceInstance = onset.getAai().get("service-instance.service-instance-id"); + if (serviceInstance == null || serviceInstance.isEmpty()) { + // This indicates that AAI Enrichment needs to be done by event producer. + return null; + } + SdncHealVfModuleParameter bandwidth = new SdncHealVfModuleParameter(); + bandwidth.setName("bandwidth"); + bandwidth.setValue(onset.getAai().get("bandwidth")); + + SdncHealVfModuleParameter timeStamp = new SdncHealVfModuleParameter(); + timeStamp.setName("bandwidth-change-time"); + timeStamp.setValue(onset.getAai().get("bandwidth-change-time")); + + SdncHealVfModuleParametersInfo vfParametersInfo = new SdncHealVfModuleParametersInfo(); + vfParametersInfo.addParameters(bandwidth); + vfParametersInfo.addParameters(timeStamp); + + SdncHealVfModuleRequestInput vfRequestInfo = new SdncHealVfModuleRequestInput(); + vfRequestInfo.setVfModuleParametersInfo(vfParametersInfo); + + SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo(); + serviceInfo.setServiceInstanceId(serviceInstance); + + SdncHealRequestInfo requestInfo = new SdncHealRequestInfo(); + requestInfo.setRequestAction("SdwanBandwidthChange"); + + SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo(); + headerInfo.setSvcAction("update"); + headerInfo.setSvcRequestId(UUID.randomUUID().toString()); + + SdncRequest request = new SdncRequest(); + request.setNsInstanceId(serviceInstance); + request.setRequestId(onset.getRequestId()); + request.setUrl("/GENERIC-RESOURCE-API:vf-module-topology-operation"); + + SdncHealVnfInfo vnfInfo = new SdncHealVnfInfo(); + vnfInfo.setVnfId(onset.getAai().get("vnfId")); + + SdncHealVfModuleInfo vfModuleInfo = new SdncHealVfModuleInfo(); + vfModuleInfo.setVfModuleId(""); + + SdncHealRequest healRequest = new SdncHealRequest(); + healRequest.setVnfInfo(vnfInfo); + healRequest.setVfModuleInfo(vfModuleInfo); + healRequest.setRequestHeaderInfo(headerInfo); + healRequest.setVfModuleRequestInput(vfRequestInfo); + healRequest.setRequestInfo(requestInfo); + healRequest.setServiceInfo(serviceInfo); + request.setHealRequest(healRequest); + return request; + } + + private SdncRequest constructReOptimizeRequest(VirtualControlLoopEvent onset) { + // Construct an Sdnc request + String serviceInstance = onset.getAai().get("service-instance.service-instance-id"); + if (serviceInstance == null || serviceInstance.isEmpty()) { + // This indicates that AAI Enrichment needs to be done by event producer. + return null; + } + SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo(); + serviceInfo.setServiceInstanceId(serviceInstance); + + String networkId = onset.getAai().get("network-information.network-id"); + if (networkId == null || networkId.isEmpty()) { + // This indicates that AAI Enrichment needs to be done by event producer. + return null; + } + SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo(); + networkInfo.setNetworkId(networkId); + + SdncHealRequestInfo requestInfo = new SdncHealRequestInfo(); + requestInfo.setRequestAction("ReoptimizeSOTNInstance"); + + SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo(); + headerInfo.setSvcAction("reoptimize"); + headerInfo.setSvcRequestId(UUID.randomUUID().toString()); + + SdncRequest request = new SdncRequest(); + request.setNsInstanceId(serviceInstance); + request.setRequestId(onset.getRequestId()); + request.setUrl("/GENERIC-RESOURCE-API:network-topology-operation"); + + SdncHealRequest healRequest = new SdncHealRequest(); + healRequest.setRequestHeaderInfo(headerInfo); + healRequest.setNetworkInfo(networkInfo); + healRequest.setRequestInfo(requestInfo); + healRequest.setServiceInfo(serviceInfo); + request.setHealRequest(healRequest); + return request; + } + + // **HERE** +} diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java deleted file mode 100644 index cd9ad1ac2..000000000 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java +++ /dev/null @@ -1,223 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * SdncActorServiceProvider - * ================================================================================ - * Copyright (C) 2018-2019 Huawei Intellectual Property. All rights reserved. - * Modifications Copyright (C) 2019 Nordix Foundation. - * Modifications Copyright (C) 2019-2020 AT&T Intellectual Property. - * ================================================================================ - * 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. - * See the License for the specific language governing permissions and - * limitations under the License. - * ============LICENSE_END========================================================= - */ - -package org.onap.policy.controlloop.actor.sdnc; - -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.ControlLoopOperation; -import org.onap.policy.controlloop.VirtualControlLoopEvent; -import org.onap.policy.controlloop.actorserviceprovider.impl.HttpActor; -import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator; -import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpActorParams; -import org.onap.policy.controlloop.policy.Policy; -import org.onap.policy.sdnc.SdncHealNetworkInfo; -import org.onap.policy.sdnc.SdncHealRequest; -import org.onap.policy.sdnc.SdncHealRequestHeaderInfo; -import org.onap.policy.sdnc.SdncHealRequestInfo; -import org.onap.policy.sdnc.SdncHealServiceInfo; -import org.onap.policy.sdnc.SdncHealVfModuleInfo; -import org.onap.policy.sdnc.SdncHealVfModuleParameter; -import org.onap.policy.sdnc.SdncHealVfModuleParametersInfo; -import org.onap.policy.sdnc.SdncHealVfModuleRequestInput; -import org.onap.policy.sdnc.SdncHealVnfInfo; -import org.onap.policy.sdnc.SdncRequest; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SdncActorServiceProvider extends HttpActor { - private static final Logger logger = LoggerFactory.getLogger(SdncActorServiceProvider.class); - - public static final String NAME = "SDNC"; - - // TODO old code: remove lines down to **HERE** - - // Strings for Sdnc Actor - private static final String SDNC_ACTOR = "SDNC"; - - // Strings for targets - private static final String TARGET_VM = "VM"; - - // Strings for recipes - private static final String RECIPE_REROUTE = "Reroute"; - - // Strings for recipes - private static final String RECIPE_BW_ON_DEMAND = "BandwidthOnDemand"; - - private static final ImmutableList recipes = ImmutableList.of(RECIPE_REROUTE); - private static final ImmutableMap> targets = new ImmutableMap.Builder>() - .put(RECIPE_REROUTE, ImmutableList.of(TARGET_VM)).build(); - - // **HERE** - - /** - * Constructs the object. - */ - public SdncActorServiceProvider() { - super(NAME, HttpActorParams.class); - - addOperator(new HttpOperator(NAME, RerouteOperation.NAME, RerouteOperation::new)); - addOperator(new HttpOperator(NAME, BandwidthOnDemandOperation.NAME, BandwidthOnDemandOperation::new)); - } - - - // TODO old code: remove lines down to **HERE** - - @Override - public String actor() { - return SDNC_ACTOR; - } - - @Override - public List recipes() { - return ImmutableList.copyOf(recipes); - } - - @Override - public List recipeTargets(String recipe) { - return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList())); - } - - @Override - public List recipePayloads(String recipe) { - return Collections.emptyList(); - } - - /** - * Construct a request. - * - * @param onset the onset event - * @param operation the control loop operation - * @param policy the policy - * @return the constructed request - */ - public SdncRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) { - switch (policy.getRecipe()) { - case RECIPE_REROUTE: - return constructReOptimizeRequest(onset); - case RECIPE_BW_ON_DEMAND: - logger.info("Construct request for receipe {}", RECIPE_BW_ON_DEMAND); - return constructBwOnDemandRequest(onset); - default: - logger.info("Unsupported recipe {}", policy.getRecipe()); - return null; - } - } - - private SdncRequest constructBwOnDemandRequest(VirtualControlLoopEvent onset) { - // Construct an Sdnc request - String serviceInstance = onset.getAai().get("service-instance.service-instance-id"); - if (serviceInstance == null || serviceInstance.isEmpty()) { - // This indicates that AAI Enrichment needs to be done by event producer. - return null; - } - SdncHealVfModuleParameter bandwidth = new SdncHealVfModuleParameter(); - bandwidth.setName("bandwidth"); - bandwidth.setValue(onset.getAai().get("bandwidth")); - - SdncHealVfModuleParameter timeStamp = new SdncHealVfModuleParameter(); - timeStamp.setName("bandwidth-change-time"); - timeStamp.setValue(onset.getAai().get("bandwidth-change-time")); - - SdncHealVfModuleParametersInfo vfParametersInfo = new SdncHealVfModuleParametersInfo(); - vfParametersInfo.addParameters(bandwidth); - vfParametersInfo.addParameters(timeStamp); - - SdncHealVfModuleRequestInput vfRequestInfo = new SdncHealVfModuleRequestInput(); - vfRequestInfo.setVfModuleParametersInfo(vfParametersInfo); - - SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo(); - serviceInfo.setServiceInstanceId(serviceInstance); - - SdncHealRequestInfo requestInfo = new SdncHealRequestInfo(); - requestInfo.setRequestAction("SdwanBandwidthChange"); - - SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo(); - headerInfo.setSvcAction("update"); - headerInfo.setSvcRequestId(UUID.randomUUID().toString()); - - SdncRequest request = new SdncRequest(); - request.setNsInstanceId(serviceInstance); - request.setRequestId(onset.getRequestId()); - request.setUrl("/GENERIC-RESOURCE-API:vf-module-topology-operation"); - - SdncHealVnfInfo vnfInfo = new SdncHealVnfInfo(); - vnfInfo.setVnfId(onset.getAai().get("vnfId")); - - SdncHealVfModuleInfo vfModuleInfo = new SdncHealVfModuleInfo(); - vfModuleInfo.setVfModuleId(""); - - SdncHealRequest healRequest = new SdncHealRequest(); - healRequest.setVnfInfo(vnfInfo); - healRequest.setVfModuleInfo(vfModuleInfo); - healRequest.setRequestHeaderInfo(headerInfo); - healRequest.setVfModuleRequestInput(vfRequestInfo); - healRequest.setRequestInfo(requestInfo); - healRequest.setServiceInfo(serviceInfo); - request.setHealRequest(healRequest); - return request; - } - - private SdncRequest constructReOptimizeRequest(VirtualControlLoopEvent onset) { - // Construct an Sdnc request - String serviceInstance = onset.getAai().get("service-instance.service-instance-id"); - if (serviceInstance == null || serviceInstance.isEmpty()) { - // This indicates that AAI Enrichment needs to be done by event producer. - return null; - } - SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo(); - serviceInfo.setServiceInstanceId(serviceInstance); - - String networkId = onset.getAai().get("network-information.network-id"); - if (networkId == null || networkId.isEmpty()) { - // This indicates that AAI Enrichment needs to be done by event producer. - return null; - } - SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo(); - networkInfo.setNetworkId(networkId); - - SdncHealRequestInfo requestInfo = new SdncHealRequestInfo(); - requestInfo.setRequestAction("ReoptimizeSOTNInstance"); - - SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo(); - headerInfo.setSvcAction("reoptimize"); - headerInfo.setSvcRequestId(UUID.randomUUID().toString()); - - SdncRequest request = new SdncRequest(); - request.setNsInstanceId(serviceInstance); - request.setRequestId(onset.getRequestId()); - request.setUrl("/GENERIC-RESOURCE-API:network-topology-operation"); - - SdncHealRequest healRequest = new SdncHealRequest(); - healRequest.setRequestHeaderInfo(headerInfo); - healRequest.setNetworkInfo(networkInfo); - healRequest.setRequestInfo(requestInfo); - healRequest.setServiceInfo(serviceInfo); - request.setHealRequest(healRequest); - return request; - } - - // **HERE** -} diff --git a/models-interactions/model-actors/actor.sdnc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor b/models-interactions/model-actors/actor.sdnc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor index f4d1e975e..0c66fdf75 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor +++ b/models-interactions/model-actors/actor.sdnc/src/main/resources/META-INF/services/org.onap.policy.controlloop.actorserviceprovider.spi.Actor @@ -1 +1 @@ -org.onap.policy.controlloop.actor.sdnc.SdncActorServiceProvider \ No newline at end of file +org.onap.policy.controlloop.actor.sdnc.SdncActor -- cgit 1.2.3-korg