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.actorserviceprovider.impl;
24 import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
25 import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
26 import org.onap.policy.common.parameters.ValidationResult;
27 import org.onap.policy.controlloop.actorserviceprovider.Util;
28 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
29 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
30 import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
33 * Operator that uses HTTP. The operator's parameters must be an {@link HttpParams}.
35 public class HttpOperator extends TypedOperator<HttpConfig,HttpOperation<?>> {
38 * Constructs the object.
40 * @param actorName name of the actor with which this operator is associated
41 * @param name operation name
43 protected HttpOperator(String actorName, String name) {
44 this(actorName, name, null);
48 * Constructs the object.
50 * @param actorName name of the actor with which this operator is associated
51 * @param name operation name
52 * @param operationMaker function to make an operation
54 public HttpOperator(String actorName, String name,
55 OperationMaker<HttpConfig, HttpOperation<?>> operationMaker) {
56 super(actorName, name, operationMaker);
60 * Makes a new configuration using the specified parameters.
62 * @param parameters operator parameters
63 * @return a new configuration
65 protected HttpConfig makeConfiguration(Map<String, Object> parameters) {
66 HttpParams params = Util.translate(getFullName(), parameters, HttpParams.class);
67 ValidationResult result = params.validate(getFullName());
68 if (!result.isValid()) {
69 throw new ParameterValidationRuntimeException("invalid parameters", result);
72 return new HttpConfig(getBlockingExecutor(), params, getClientFactory());
75 // these may be overridden by junit tests
77 protected HttpClientFactory getClientFactory() {
78 return HttpClientFactoryInstance.getClientFactory();