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