package org.onap.policy.controlloop.actorserviceprovider.impl;
import java.util.Map;
-import lombok.AccessLevel;
import lombok.Getter;
-import org.onap.policy.common.endpoints.http.client.HttpClient;
import org.onap.policy.common.endpoints.http.client.HttpClientFactory;
import org.onap.policy.common.endpoints.http.client.HttpClientFactoryInstance;
import org.onap.policy.common.parameters.ValidationResult;
+import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.Util;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
+import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ParameterValidationRuntimeException;
/**
- * Operator that uses HTTP. The operator's parameters must be a {@link HttpParams}.
+ * Operator that uses HTTP. The operator's parameters must be an {@link HttpParams}.
*/
public class HttpOperator extends OperatorPartial {
- @Getter(AccessLevel.PROTECTED)
- private HttpClient client;
-
- @Getter
- private long timeoutSec;
+ /**
+ * Function to make an operation.
+ */
+ @SuppressWarnings("rawtypes")
+ private final OperationMaker<HttpConfig, HttpOperation> operationMaker;
/**
- * URI path for this particular operation.
+ * Current configuration. This is set by {@link #doConfigure(Map)}.
*/
@Getter
- private String path;
+ private HttpConfig currentConfig;
+
+ /**
+ * Constructs the object.
+ *
+ * @param actorName name of the actor with which this operator is associated
+ * @param name operation name
+ */
+ protected HttpOperator(String actorName, String name) {
+ this(actorName, name, null);
+ }
/**
* Constructs the object.
*
* @param actorName name of the actor with which this operator is associated
* @param name operation name
+ * @param operationMaker function to make an operation
*/
- public HttpOperator(String actorName, String name) {
+ public HttpOperator(String actorName, String name,
+ @SuppressWarnings("rawtypes") OperationMaker<HttpConfig, HttpOperation> operationMaker) {
super(actorName, name);
+ this.operationMaker = operationMaker;
}
/**
*/
@Override
protected void doConfigure(Map<String, Object> parameters) {
+ currentConfig = makeConfiguration(parameters);
+ }
+
+ /**
+ * Makes a new configuration using the specified parameters.
+ *
+ * @param parameters operator parameters
+ * @return a new configuration
+ */
+ protected HttpConfig makeConfiguration(Map<String, Object> parameters) {
HttpParams params = Util.translate(getFullName(), parameters, HttpParams.class);
ValidationResult result = params.validate(getFullName());
if (!result.isValid()) {
throw new ParameterValidationRuntimeException("invalid parameters", result);
}
- client = getClientFactory().get(params.getClientName());
- path = params.getPath();
- timeoutSec = params.getTimeoutSec();
+ return new HttpConfig(getBlockingExecutor(), params, getClientFactory());
+ }
+
+ @Override
+ public Operation buildOperation(ControlLoopOperationParams params) {
+ if (operationMaker == null) {
+ throw new UnsupportedOperationException("cannot make operation for " + getFullName());
+ }
+
+ verifyRunning();
+
+ return operationMaker.apply(params, currentConfig);
}
- // these may be overridden by junits
+ // these may be overridden by junit tests
protected HttpClientFactory getClientFactory() {
return HttpClientFactoryInstance.getClientFactory();