2  * ============LICENSE_START=======================================================
 
   3  * APPCActorServiceProvider
 
   4  * ================================================================================
 
   5  * Copyright (C) 2017 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 java.util.Collections;
 
  24 import java.util.List;
 
  26 import org.onap.policy.controlloop.VirtualControlLoopEvent;
 
  27 import org.onap.policy.appc.CommonHeader;
 
  28 import org.onap.policy.appc.Request;
 
  29 import org.onap.policy.controlloop.ControlLoopOperation;
 
  30 import org.onap.policy.controlloop.policy.Policy;
 
  31 import org.onap.policy.vnf.trafficgenerator.PGRequest;
 
  32 import org.onap.policy.vnf.trafficgenerator.PGStream;
 
  33 import org.onap.policy.vnf.trafficgenerator.PGStreams;
 
  34 import org.onap.policy.controlloop.actorServiceProvider.spi.Actor;
 
  36 import com.google.common.collect.ImmutableList;
 
  37 import com.google.common.collect.ImmutableMap;
 
  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 = ImmutableList.of(RECIPE_RESTART, RECIPE_REBUILD, RECIPE_MIGRATE, RECIPE_MODIFY);
 
  52         private static final ImmutableMap<String, List<String>> targets = new ImmutableMap.Builder<String, List<String>>()
 
  53                         .put(RECIPE_RESTART, ImmutableList.of(TARGET_VM))
 
  54                         .put(RECIPE_REBUILD, ImmutableList.of(TARGET_VM))
 
  55                         .put(RECIPE_MIGRATE, ImmutableList.of(TARGET_VM))
 
  56                         .put(RECIPE_MODIFY, ImmutableList.of(TARGET_VNF))
 
  58         private static final ImmutableMap<String, List<String>> payloads = new ImmutableMap.Builder<String, List<String>>()
 
  59                         .put(RECIPE_MODIFY, ImmutableList.of("generic-vnf.vnf-id"))
 
  63         public String actor() {
 
  68         public List<String> recipes() {
 
  69                 return ImmutableList.copyOf(recipes);
 
  73         public List<String> recipeTargets(String recipe) {
 
  74                 return ImmutableList.copyOf(targets.getOrDefault(recipe, Collections.emptyList()));
 
  78         public List<String> recipePayloads(String recipe) {
 
  79                 return ImmutableList.copyOf(payloads.getOrDefault(recipe, Collections.emptyList()));
 
  83          * Constructs an APPC request conforming to the legacy API.
 
  84          * The legacy API will be deprecated in future releases as
 
  85          * all legacy functionality is moved into the LCM API.
 
  88          *         the event that is reporting the alert for policy
 
  89          *            to perform an action
 
  91          *         the control loop operation specifying the actor,
 
  92          *         operation, target, etc.
 
  94          *         the policy the was specified from the yaml generated
 
  95          *         by CLAMP or through the Policy GUI/API
 
  96          * @return an APPC request conforming to the legacy API
 
  97          * @throws AAIException 
 
  99         public static Request constructRequest(VirtualControlLoopEvent onset, ControlLoopOperation operation,
 
 100                         Policy policy, String targetVnf) {
 
 102                  * Construct an APPC request
 
 104                 Request request = new Request();
 
 105                 request.setCommonHeader(new CommonHeader());
 
 106                 request.getCommonHeader().setRequestID(onset.getRequestID());
 
 107                 request.getCommonHeader().setSubRequestID(operation.getSubRequestId());
 
 108                 request.setAction(policy.getRecipe().substring(0, 1).toUpperCase() 
 
 109                                 + policy.getRecipe().substring(1));
 
 112                  * For now Policy generates the PG Streams as a demo, in the
 
 113                  * future the payload can be provided by CLAMP
 
 115                 request.getPayload().put("generic-vnf.vnf-id", targetVnf);
 
 117                 PGRequest pgRequest = new PGRequest();
 
 118                 pgRequest.pgStreams = new PGStreams();
 
 121                 for (int i = 0; i < 5; i++) {
 
 122                         pgStream = new PGStream();
 
 123                         pgStream.streamId = "fw_udp"+(i+1);
 
 124                         pgStream.isEnabled = "true";
 
 125                         pgRequest.pgStreams.pgStream.add(pgStream);
 
 127                 request.getPayload().put("pg-streams", pgRequest.pgStreams);