bd06ef133c8999166b7eeba979000815eca29c5a
[policy/drools-applications.git] /
1 /*-
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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=========================================================
17  */
18
19 package org.onap.policy.controlloop.actor.vfc;
20
21 import java.util.Collections;
22 import java.util.List;
23
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;
32
33 import com.google.common.collect.ImmutableList;
34 import com.google.common.collect.ImmutableMap;
35
36
37 public class VFCActorServiceProvider implements Actor {
38
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"))
42             .build();
43
44     @Override
45     public String actor() {
46         return "VFC";
47     }
48
49     @Override
50     public List<String> recipes() {
51         return ImmutableList.copyOf(recipes);
52     }
53
54     @Override
55     public List<String> recipeTargets(String recipe) {
56         return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
57     }
58
59     @Override
60     public List<String> recipePayloads(String recipe) {
61         return Collections.emptyList();
62     }
63
64     public static VFCRequest constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy) {
65
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;
73
74         request.healRequest.additionalParams = new VFCHealAdditionalParams();
75         switch (policy.getRecipe()) {
76             case "Restart":
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");
83                 break;
84             default:
85                 //TODO: default
86                 break;
87         }
88         return request;
89     }
90
91
92 }