2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 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.drools.apps.controller.usecases.step;
23 import java.util.ArrayList;
24 import java.util.LinkedHashMap;
25 import java.util.List;
27 import org.onap.policy.controlloop.actor.guard.DecisionOperation;
28 import org.onap.policy.controlloop.actor.guard.GuardActor;
29 import org.onap.policy.controlloop.actor.so.VfModuleCreate;
30 import org.onap.policy.controlloop.actorserviceprovider.Operation;
31 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
34 * Wrapper for a Guard operation. Note: this makes a clone of the operation parameters,
35 * replacing the payload. It overrides the operation's property names with that are
36 * relevant for guards. In addition, it overrides the relevant loadXxx() methods to load
37 * the data into the payload instead of into the operation's properties. It also
38 * increments or decrements the VF Count, depending whether the operation is a "VF Module
41 public class GuardStep2 extends Step2 {
42 public static final String PAYLOAD_KEY_TARGET_ENTITY = "target";
43 public static final String PAYLOAD_KEY_VF_COUNT = "vfCount";
45 private final Operation policyOper;
49 * Constructs the object using information from another step.
51 * @param otherStep step whose information should be used
53 public GuardStep2(Step2 otherStep, String closedLoopControlName) {
54 super(otherStep, GuardActor.NAME, DecisionOperation.NAME);
56 if (!otherStep.isInitialized()) {
57 throw new IllegalStateException("policy operation must be initialized before the guard operation");
60 this.policyOper = otherStep.getOperation();
62 Map<String, Object> payload = new LinkedHashMap<>();
63 payload.put("actor", otherStep.getActorName());
64 payload.put("operation", otherStep.getOperationName());
65 payload.put("requestId", params.getRequestId());
66 payload.put("clname", closedLoopControlName);
68 params = params.toBuilder().payload(payload).build();
72 public boolean acceptsEvent() {
77 * Builds the list of properties on the policy's actual operation.
80 public List<String> getPropertyNames() {
81 List<String> names = new ArrayList<>(1);
83 // include VF Count if the policy's operation needs it
84 if (policyOper.getPropertyNames().contains(OperationProperties.DATA_VF_COUNT)) {
85 names.add(OperationProperties.DATA_VF_COUNT);
92 * Load the target entity into the payload instead of the operation's properties.
95 protected void loadTargetEntity(String propName) {
96 params.getPayload().put(PAYLOAD_KEY_TARGET_ENTITY, getTargetEntity());
100 * Load the VF Count into the payload instead of the operation's properties.
101 * Increments the count for "VF Module Create". Decrements it otherwise.
104 protected void loadVfCount(String propName) {
105 // run guard with the proposed VF count
106 int count = getVfCount();
107 if (VfModuleCreate.NAME.equals(policyOper.getName())) {
113 params.getPayload().put(PAYLOAD_KEY_VF_COUNT, count);