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.List;
24 import org.onap.policy.controlloop.ControlLoopOperation;
25 import org.onap.policy.controlloop.VirtualControlLoopEvent;
26 import org.onap.policy.controlloop.actorServiceProvider.spi.Actor;
27 import org.onap.policy.controlloop.policy.Policy;
28 import org.onap.policy.vfc.VFCHealActionVmInfo;
29 import org.onap.policy.vfc.VFCHealAdditionalParams;
30 import org.onap.policy.vfc.VFCHealRequest;
31 import org.onap.policy.vfc.VFCRequest;
33 import com.google.common.collect.ImmutableList;
34 import com.google.common.collect.ImmutableMap;
37 public class VFCActorServiceProvider implements Actor {
39 private static final ImmutableList<String> recipes = ImmutableList.of("Restart");
40 private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
41 .put("Restart", ImmutableList.of("VM"))
45 public String actor() {
50 public List<String> recipes() {
51 return ImmutableList.copyOf(recipes);
55 public List<String> recipeTargets(String recipe) {
56 return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
60 public List<String> recipePayloads(String recipe) {
61 return Collections.emptyList();
64 public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) {
66 // Construct an VFC request
67 VFCRequest request = new VFCRequest();
68 // TODO: Verify service-instance-id is part of onset event
69 request.nsInstanceId = onset.AAI.get("service-instance.service-instance-id");
70 request.healRequest = new VFCHealRequest();
71 request.healRequest.vnfInstanceId = onset.AAI.get("generic-vnf.vnf-id");
72 request.healRequest.cause = operation.message;
74 request.healRequest.additionalParams = new VFCHealAdditionalParams();
75 switch (policy.getRecipe()) {
77 // TODO: check target??
78 request.healRequest.additionalParams.action = "restartvm";
79 request.healRequest.additionalParams.actionInfo = new VFCHealActionVmInfo();
80 // TODO: Verify vserver-id and vserver-name is part of onset event
81 request.healRequest.additionalParams.actionInfo.vmid = onset.AAI.get("vserver.vserver-id");
82 request.healRequest.additionalParams.actionInfo.vmname = onset.AAI.get("vserver.vserver-name");