aboutsummaryrefslogtreecommitdiffstats
path: root/models-interactions/model-actors/actor.sdnc
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2020-01-23 18:56:40 -0500
committerJim Hahn <jrh3@att.com>2020-02-03 16:38:39 -0500
commit89ce8bc6075096d015cdc8735634e0be14fe0357 (patch)
tree166892169d2a52ebdddafc0f2c8bba2308fdad0d /models-interactions/model-actors/actor.sdnc
parentd789d26741b22fca83168ab209e517fbfbcefcc6 (diff)
Actor redesign.
Left original code intact so that it can continue to be used until everything has been converted to use the new approach. Simply added new methods and classes. (A few minor edits were required to the old code, e.g., added constructors to the Actor implementations). Code to be removed is annotated with "TODO". This only contains one revised actor, SDNC. This actor combines code from actor.sdnc, sdnc, and drools-applications. Coverage tests are incomplete, but I anticipate some simplification to this design in a couple of days; coverage will be added at that time. Issue-ID: POLICY-1625 Signed-off-by: Jim Hahn <jrh3@att.com> Change-Id: I4b75730e3621a9ee026ad10e557abe92df10dcf4
Diffstat (limited to 'models-interactions/model-actors/actor.sdnc')
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperator.java102
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperator.java81
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncActorServiceProvider.java56
-rw-r--r--models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperator.java144
4 files changed, 373 insertions, 10 deletions
diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperator.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperator.java
new file mode 100644
index 000000000..0e721bf8c
--- /dev/null
+++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperator.java
@@ -0,0 +1,102 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. 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.
+ * 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 java.util.UUID;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+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;
+
+public class BandwidthOnDemandOperator extends SdncOperator {
+ public static final String NAME = "BandwidthOnDemand";
+
+ /**
+ * Constructs the object.
+ *
+ * @param actorName name of the actor with which this operator is associated
+ */
+ public BandwidthOnDemandOperator(String actorName) {
+ super(actorName, NAME);
+ }
+
+ @Override
+ protected SdncRequest constructRequest(VirtualControlLoopEvent onset) {
+ String serviceInstance = onset.getAai().get("service-instance.service-instance-id");
+ if (StringUtils.isBlank(serviceInstance)) {
+ throw new IllegalArgumentException("missing enrichment data, service-instance-id");
+ }
+
+ 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;
+ }
+}
diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperator.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperator.java
new file mode 100644
index 000000000..59af31f4f
--- /dev/null
+++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperator.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. 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.
+ * 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 java.util.UUID;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+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.SdncRequest;
+
+public class RerouteOperator extends SdncOperator {
+ public static final String NAME = "Reroute";
+
+ /**
+ * Constructs the object.
+ *
+ * @param actorName name of the actor with which this operator is associated
+ */
+ public RerouteOperator(String actorName) {
+ super(actorName, NAME);
+ }
+
+ @Override
+ protected SdncRequest constructRequest(VirtualControlLoopEvent onset) {
+ String serviceInstance = onset.getAai().get("service-instance.service-instance-id");
+ if (StringUtils.isBlank(serviceInstance)) {
+ throw new IllegalArgumentException("missing enrichment data, service-instance-id");
+ }
+ SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
+ serviceInfo.setServiceInstanceId(serviceInstance);
+
+ String networkId = onset.getAai().get("network-information.network-id");
+ if (StringUtils.isBlank(networkId)) {
+ throw new IllegalArgumentException("missing enrichment data, network-id");
+ }
+ 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;
+ }
+}
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
index 24d019f41..13276f929 100644
--- 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
@@ -4,7 +4,7 @@
* ================================================================================
* Copyright (C) 2018-2019 Huawei Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2019 Nordix Foundation.
- * Modifications Copyright (C) 2019 AT&T Intellectual Property.
+ * 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.
@@ -26,10 +26,14 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.UUID;
+import java.util.function.Function;
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.actorserviceprovider.Util;
+import org.onap.policy.controlloop.actorserviceprovider.impl.ActorImpl;
+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;
@@ -45,10 +49,13 @@ import org.onap.policy.sdnc.SdncRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
-public class SdncActorServiceProvider implements Actor {
+public class SdncActorServiceProvider extends ActorImpl {
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";
@@ -62,8 +69,36 @@ public class SdncActorServiceProvider implements Actor {
private static final String RECIPE_BW_ON_DEMAND = "BandwidthOnDemand";
private static final ImmutableList<String> recipes = ImmutableList.of(RECIPE_REROUTE);
- private static final ImmutableMap<String, List<String>> targets =
- new ImmutableMap.Builder<String, List<String>>().put(RECIPE_REROUTE, ImmutableList.of(TARGET_VM)).build();
+ private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
+ .put(RECIPE_REROUTE, ImmutableList.of(TARGET_VM)).build();
+
+ // **HERE**
+
+ /**
+ * Constructs the object.
+ */
+ public SdncActorServiceProvider() {
+ // @formatter:off
+ super(NAME,
+ new RerouteOperator(NAME),
+ new BandwidthOnDemandOperator(NAME));
+
+ // @formatter:on
+ }
+
+ @Override
+ protected Function<String, Map<String, Object>> makeOperatorParameters(Map<String, Object> actorParameters) {
+ String actorName = getName();
+
+ // @formatter:off
+ return Util.translate(actorName, actorParameters, HttpActorParams.class)
+ .doValidation(actorName)
+ .makeOperationParameters(actorName);
+ // @formatter:on
+ }
+
+
+ // TODO old code: remove lines down to **HERE**
@Override
public String actor() {
@@ -93,16 +128,15 @@ public class SdncActorServiceProvider implements Actor {
* @param policy the policy
* @return the constructed request
*/
- public SdncRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation,
- Policy policy) {
+ 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);
+ logger.info("Construct request for receipe {}", RECIPE_BW_ON_DEMAND);
return constructBwOnDemandRequest(onset);
default:
- logger.info("Unsupported recipe {} " + policy.getRecipe());
+ logger.info("Unsupported recipe {}", policy.getRecipe());
return null;
}
}
@@ -199,4 +233,6 @@ public class SdncActorServiceProvider implements Actor {
request.setHealRequest(healRequest);
return request;
}
+
+ // **HERE**
}
diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperator.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperator.java
new file mode 100644
index 000000000..c2e4c8f8b
--- /dev/null
+++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperator.java
@@ -0,0 +1,144 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP
+ * ================================================================================
+ * Copyright (C) 2020 AT&T Intellectual Property. 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.
+ * 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 java.util.HashMap;
+import java.util.Map;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import lombok.AccessLevel;
+import lombok.Getter;
+import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
+import org.onap.policy.common.endpoints.http.client.HttpClient;
+import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil;
+import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
+import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.controlloop.ControlLoopOperation;
+import org.onap.policy.controlloop.VirtualControlLoopEvent;
+import org.onap.policy.controlloop.actorserviceprovider.Util;
+import org.onap.policy.controlloop.actorserviceprovider.impl.OperatorPartial;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
+import org.onap.policy.controlloop.policy.PolicyResult;
+import org.onap.policy.sdnc.SdncRequest;
+import org.onap.policy.sdnc.SdncResponse;
+import org.onap.policy.sdnc.util.Serialization;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Superclass for SDNC Operators.
+ */
+public abstract class SdncOperator extends OperatorPartial {
+ private static final Logger logger = LoggerFactory.getLogger(SdncOperator.class);
+
+ @Getter(AccessLevel.PROTECTED)
+ private HttpClient client;
+
+ /**
+ * URI path for this particular operation.
+ */
+ private String path;
+
+ /**
+ * Constructs the object.
+ *
+ * @param actorName name of the actor with which this operator is associated
+ * @param name operation name
+ */
+ public SdncOperator(String actorName, String name) {
+ super(actorName, name);
+ }
+
+ // TODO add a junit for this and for plug-in via ActorService
+ @Override
+ protected void doConfigure(Map<String, Object> parameters) {
+ HttpParams params = Util.translate(getFullName(), parameters, HttpParams.class);
+ ValidationResult result = params.validate(getFullName());
+ if (!result.isValid()) {
+ throw new ParameterValidationRuntimeException("invalid parameters", result);
+ }
+
+ client = HttpClientFactoryInstance.getClientFactory().get(params.getClientName());
+ path = params.getPath();
+ }
+
+ @Override
+ protected ControlLoopOperation doOperation(ControlLoopOperationParams params, int attempt,
+ ControlLoopOperation operation) {
+
+ SdncRequest request = constructRequest(params.getContext().getEvent());
+ PolicyResult result = doRequest(request);
+
+ return setOutcome(params, operation, result);
+ }
+
+ /**
+ * Constructs the request.
+ *
+ * @param onset event for which the request should be constructed
+ * @return a new request
+ */
+ protected abstract SdncRequest constructRequest(VirtualControlLoopEvent onset);
+
+ /**
+ * Posts the request and retrieves the response.
+ *
+ * @param sdncRequest request to be posted
+ * @return the result of the request
+ */
+ private PolicyResult doRequest(SdncRequest sdncRequest) {
+ Map<String, Object> headers = new HashMap<>();
+
+ headers.put("Accept", "application/json");
+ String sdncUrl = client.getBaseUrl();
+
+ String sdncRequestJson = Serialization.gsonPretty.toJson(sdncRequest);
+
+ // TODO move this into a utility
+ NetLoggerUtil.log(EventType.OUT, CommInfrastructure.REST, sdncUrl, sdncRequestJson);
+ logger.info("[OUT|{}|{}|]{}{}", CommInfrastructure.REST, sdncUrl, NetLoggerUtil.SYSTEM_LS, sdncRequestJson);
+
+ Entity<SdncRequest> entity = Entity.entity(sdncRequest, MediaType.APPLICATION_JSON);
+
+ // TODO modify this to use asynchronous client operations
+ Response rawResponse = client.post(path, entity, headers);
+ String strResponse = HttpClient.getBody(rawResponse, String.class);
+
+ // TODO move this into a utility
+ NetLoggerUtil.log(EventType.IN, CommInfrastructure.REST, sdncUrl, strResponse);
+ logger.info("[IN|{}|{}|]{}{}", "Sdnc", sdncUrl, NetLoggerUtil.SYSTEM_LS, strResponse);
+ logger.info("Response to Sdnc Heal post:");
+ logger.info(strResponse);
+
+ SdncResponse response = Serialization.gsonPretty.fromJson(strResponse, SdncResponse.class);
+
+ if (response.getResponseOutput() == null || !"200".equals(response.getResponseOutput().getResponseCode())) {
+ logger.info("Sdnc Heal Restcall failed with http error code {}", rawResponse.getStatus());
+ return PolicyResult.FAILURE;
+ }
+
+ return PolicyResult.SUCCESS;
+ }
+}