2 * ============LICENSE_START=======================================================
3 * SdncActorServiceProvider
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.actor.sdnc;
23 import com.google.common.collect.ImmutableList;
24 import com.google.common.collect.ImmutableMap;
26 import java.util.Collections;
27 import java.util.List;
28 import java.util.UUID;
30 import org.onap.policy.aai.AaiGetVnfResponse;
31 import org.onap.policy.controlloop.ControlLoopOperation;
32 import org.onap.policy.controlloop.VirtualControlLoopEvent;
33 import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
34 import org.onap.policy.controlloop.policy.Policy;
35 import org.onap.policy.sdnc.SdncHealNetworkInfo;
36 import org.onap.policy.sdnc.SdncHealRequest;
37 import org.onap.policy.sdnc.SdncHealRequestHeaderInfo;
38 import org.onap.policy.sdnc.SdncHealRequestInfo;
39 import org.onap.policy.sdnc.SdncHealServiceInfo;
40 import org.onap.policy.sdnc.SdncRequest;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
46 public class SdncActorServiceProvider implements Actor {
47 private static final Logger logger = LoggerFactory.getLogger(SdncActorServiceProvider.class);
49 // Strings for Sdnc Actor
50 private static final String SDNC_ACTOR = "SDNC";
52 // Strings for targets
53 private static final String TARGET_VM = "VM";
55 // Strings for recipes
56 private static final String RECIPE_REROUTE = "Reroute";
58 private static final ImmutableList<String> recipes = ImmutableList.of(RECIPE_REROUTE);
59 private static final ImmutableMap<String, List<String>> targets =
60 new ImmutableMap.Builder<String, List<String>>().put(RECIPE_REROUTE, ImmutableList.of(TARGET_VM)).build();
63 public String actor() {
68 public List<String> recipes() {
69 return ImmutableList.copyOf(recipes);
73 public List<String> recipeTargets(String recipe) {
74 return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
78 public List<String> recipePayloads(String recipe) {
79 return Collections.emptyList();
83 * Construct a request.
85 * @param onset the onset event
86 * @param operation the control loop operation
87 * @param policy the policy
88 * @return the constructed request
90 public static SdncRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation,
93 if (!policy.getRecipe().equalsIgnoreCase(RECIPE_REROUTE)) {
97 // Construct an Sdnc request
98 String serviceInstance = onset.getAai().get("service-instance.service-instance-id");
99 if (serviceInstance == null || serviceInstance.isEmpty()) {
100 // This indicates that AAI Enrichment needs to be done by event producer.
103 SdncHealServiceInfo serviceInfo = new SdncHealServiceInfo();
104 serviceInfo.setServiceInstanceId(serviceInstance);
106 String networkId = onset.getAai().get("network-information.network-id");
107 if (networkId == null || networkId.isEmpty()) {
108 // This indicates that AAI Enrichment needs to be done by event producer.
111 SdncHealNetworkInfo networkInfo = new SdncHealNetworkInfo();
112 networkInfo.setNetworkId(networkId);
114 SdncHealRequestInfo requestInfo = new SdncHealRequestInfo();
115 requestInfo.setRequestAction("ReoptimizeSOTNInstance");
117 SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo();
118 headerInfo.setSvcAction("reoptimize");
119 headerInfo.setSvcRequestId(UUID.randomUUID().toString());
121 SdncRequest request = new SdncRequest();
122 request.setNsInstanceId(serviceInstance);
123 request.setRequestId(onset.getRequestId());
125 SdncHealRequest healRequest = new SdncHealRequest();
126 healRequest.setRequestHeaderInfo(headerInfo);
127 healRequest.setNetworkInfo(networkInfo);
128 healRequest.setRequestInfo(requestInfo);
129 healRequest.setServiceInfo(serviceInfo);
130 request.setHealRequest(healRequest);