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.controlloop.actor.so;
24 import java.util.function.BiFunction;
26 import org.onap.policy.common.parameters.ValidationResult;
27 import org.onap.policy.controlloop.actorserviceprovider.Operation;
28 import org.onap.policy.controlloop.actorserviceprovider.Util;
29 import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperator;
30 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
31 import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
34 public abstract class SoOperator extends HttpOperator {
37 * Path to use for the "get" request. A trailing "/" is added, if it is missing.
39 private String pathGet;
42 * Maximum number of "get" requests permitted, after the initial request, to retrieve
48 * Time, in seconds, to wait between issuing "get" requests.
50 private int waitSecGet;
53 public SoOperator(String actorName, String name) {
54 super(actorName, name);
58 protected void doConfigure(Map<String, Object> parameters) {
59 SoParams params = Util.translate(getFullName(), parameters, SoParams.class);
60 ValidationResult result = params.validate(getFullName());
61 if (!result.isValid()) {
62 throw new ParameterValidationRuntimeException("invalid parameters", result);
65 this.pathGet = params.getPathGet() + (params.getPathGet().endsWith("/") ? "" : "/");
66 this.maxGets = params.getMaxGets();
67 this.waitSecGet = params.getWaitSecGet();
69 super.doConfigure(params);
73 * Makes an operator that will construct operations.
75 * @param actorName actor name
76 * @param operation operation name
77 * @param operationMaker function to make an operation
78 * @return a new operator
80 public static SoOperator makeSoOperator(String actorName, String operation,
81 BiFunction<ControlLoopOperationParams, SoOperator, SoOperation> operationMaker) {
83 return new SoOperator(actorName, operation) {
85 public Operation buildOperation(ControlLoopOperationParams params) {
86 return operationMaker.apply(params, this);