2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2023 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.controlloop.actor.xacml;
24 import jakarta.ws.rs.client.Entity;
25 import jakarta.ws.rs.core.MediaType;
26 import java.util.List;
28 import java.util.concurrent.CompletableFuture;
29 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
30 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
31 import org.onap.policy.controlloop.actorserviceprovider.CallbackManager;
32 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
33 import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
34 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
35 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
36 import org.onap.policy.models.decisions.concepts.DecisionRequest;
37 import org.onap.policy.models.decisions.concepts.DecisionResponse;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
42 * Generic Decision Operation.
44 public abstract class DecisionOperation extends HttpOperation<DecisionResponse> {
45 private static final Logger logger = LoggerFactory.getLogger(DecisionOperation.class);
47 protected final DecisionConfig config;
51 * Constructs the object.
53 * @param params operation parameters
54 * @param config configuration for this operation
55 * @param propertyNames names of properties required by this operation
57 protected DecisionOperation(ControlLoopOperationParams params, HttpConfig config,
58 List<String> propertyNames) {
59 super(params, config, DecisionResponse.class, propertyNames);
60 this.config = (DecisionConfig) config;
64 public CompletableFuture<OperationOutcome> start() {
65 if (!config.isDisabled()) {
66 // enabled - do full guard operation
70 // guard is disabled, thus it is always treated as a success
71 logger.info("{}: guard disabled, always succeeds for {}", getFullName(), params.getRequestId());
73 final var executor = params.getExecutor();
74 final var callbacks = new CallbackManager();
76 return CompletableFuture.completedFuture(makeOutcome())
77 .whenCompleteAsync(callbackStarted(callbacks), executor)
78 .whenCompleteAsync(callbackCompleted(callbacks), executor);
82 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
83 DecisionRequest request = makeRequest();
85 Map<String, Object> headers = makeHeaders();
87 headers.put("Accept", MediaType.APPLICATION_JSON);
88 String url = getUrl();
90 String strRequest = prettyPrint(request);
91 logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
93 Entity<String> entity = Entity.entity(strRequest, MediaType.APPLICATION_JSON);
96 return handleResponse(outcome, url,
97 callback -> getClient().post(callback, getPath(), entity, headers));
102 * Makes a request from the payload.
104 * @return a new request
106 protected abstract DecisionRequest makeRequest();