2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2017 Intel Corp. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
19 package org.onap.policy.controlloop.actor.vfc;
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.List;
26 import org.onap.policy.controlloop.VirtualControlLoopEvent;
27 import org.onap.policy.vfc.VFCRequest;
28 import org.onap.policy.vfc.VFCHealRequest;
29 import org.onap.policy.vfc.VFCHealAdditionalParams;
30 import org.onap.policy.vfc.VFCHealActionVmInfo;
31 import org.onap.policy.controlloop.ControlLoopOperation;
32 import org.onap.policy.controlloop.policy.Policy;
34 import org.onap.policy.controlloop.actorServiceProvider.spi.Actor;
35 import com.google.common.collect.ImmutableList;
36 import com.google.common.collect.ImmutableMap;
39 public class VFCActorServiceProvider implements Actor {
41 private static final ImmutableList<String> recipes = ImmutableList.of("Restart");
42 private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
43 .put("Restart", ImmutableList.of("VM"))
47 public String actor() {
52 public List<String> recipes() {
53 return ImmutableList.copyOf(recipes);
57 public List<String> recipeTargets(String recipe) {
58 return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
62 public List<String> recipePayloads(String recipe) {
63 return Collections.emptyList();
66 public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) {
68 // Construct an VFC request
69 VFCRequest request = new VFCRequest();
70 // TODO: Verify service-instance-id is part of onset event
71 request.nsInstanceId = onset.AAI.get("service-instance.service-instance-id");
72 request.healRequest = new VFCHealRequest();
73 request.healRequest.vnfInstanceId = onset.AAI.get("generic-vnf.vnf-id");
74 request.healRequest.cause = operation.message;
76 request.healRequest.additionalParams = new VFCHealAdditionalParams();
77 switch (policy.getRecipe()) {
79 // TODO: check target??
80 request.healRequest.additionalParams.action = "restartvm";
81 request.healRequest.additionalParams.actionInfo = new VFCHealActionVmInfo();
82 // TODO: Verify vserver-id and vserver-name is part of onset event
83 request.healRequest.additionalParams.actionInfo.vmid = onset.AAI.get("vserver.vserver-id");
84 request.healRequest.additionalParams.actionInfo.vmname = onset.AAI.get("vserver.vserver-name");