2  * ============LICENSE_START=======================================================
 
   3  * APPCActorServiceProvider
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017-2018 AT&T 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.appc;
 
  23 import com.google.common.collect.ImmutableList;
 
  24 import com.google.common.collect.ImmutableMap;
 
  26 import java.util.Collections;
 
  27 import java.util.List;
 
  29 import org.onap.policy.appc.CommonHeader;
 
  30 import org.onap.policy.appc.Request;
 
  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.vnf.trafficgenerator.PGRequest;
 
  36 import org.onap.policy.vnf.trafficgenerator.PGStream;
 
  37 import org.onap.policy.vnf.trafficgenerator.PGStreams;
 
  40 public class APPCActorServiceProvider implements Actor {
 
  41     // Strings for targets
 
  42     private static final String TARGET_VM = "VM";
 
  43     private static final String TARGET_VNF = "VNF";
 
  45     // Strings for recipes
 
  46     private static final String RECIPE_RESTART = "Restart";
 
  47     private static final String RECIPE_REBUILD = "Rebuild";
 
  48     private static final String RECIPE_MIGRATE = "Migrate";
 
  49     private static final String RECIPE_MODIFY = "ModifyConfig";
 
  51     private static final ImmutableList<String> recipes =
 
  52             ImmutableList.of(RECIPE_RESTART, RECIPE_REBUILD, RECIPE_MIGRATE, RECIPE_MODIFY);
 
  53     private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
 
  54             .put(RECIPE_RESTART, ImmutableList.of(TARGET_VM)).put(RECIPE_REBUILD, ImmutableList.of(TARGET_VM))
 
  55             .put(RECIPE_MIGRATE, ImmutableList.of(TARGET_VM)).put(RECIPE_MODIFY, ImmutableList.of(TARGET_VNF)).build();
 
  56     private static final ImmutableMap<String, List<String>> payloads = new ImmutableMap.Builder<String, List<String>>()
 
  57             .put(RECIPE_MODIFY, ImmutableList.of("generic-vnf.vnf-id")).build();
 
  60     public String actor() {
 
  65     public List<String> recipes() {
 
  66         return ImmutableList.copyOf(recipes);
 
  70     public List<String> recipeTargets(String recipe) {
 
  71         return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
 
  75     public List<String> recipePayloads(String recipe) {
 
  76         return ImmutableList.copyOf(payloads.getOrDefault(recipe, Collections.emptyList()));
 
  80      * Constructs an APPC request conforming to the legacy API. The legacy API will be deprecated in
 
  81      * future releases as all legacy functionality is moved into the LCM API.
 
  83      * @param onset the event that is reporting the alert for policy to perform an action
 
  84      * @param operation the control loop operation specifying the actor, operation, target, etc.
 
  85      * @param policy the policy the was specified from the yaml generated by CLAMP or through the
 
  87      * @return an APPC request conforming to the legacy API
 
  89     public static Request constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation, Policy policy,
 
  92          * Construct an APPC request
 
  94         Request request = new Request();
 
  95         request.setCommonHeader(new CommonHeader());
 
  96         request.getCommonHeader().setRequestId(onset.getRequestId());
 
  97         request.getCommonHeader().setSubRequestId(operation.getSubRequestId());
 
  98         request.setAction(policy.getRecipe().substring(0, 1).toUpperCase() + policy.getRecipe().substring(1));
 
 101          * For now Policy generates the PG Streams as a demo, in the future the payload can be
 
 104         request.getPayload().put("generic-vnf.vnf-id", targetVnf);
 
 106         PGRequest pgRequest = new PGRequest();
 
 107         pgRequest.pgStreams = new PGStreams();
 
 110         for (int i = 0; i < 5; i++) {
 
 111             pgStream = new PGStream();
 
 112             pgStream.streamId = "fw_udp" + (i + 1);
 
 113             pgStream.isEnabled = "true";
 
 114             pgRequest.pgStreams.pgStream.add(pgStream);
 
 116         request.getPayload().put("pg-streams", pgRequest.pgStreams);