import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import lombok.Getter;
-import org.apache.commons.lang3.StringUtils;
-import org.onap.policy.aai.AaiConstants;
import org.onap.policy.aai.AaiCqResponse;
import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
-import org.onap.policy.common.utils.coder.StandardCoderObject;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
+import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.impl.HttpOperation;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* A&AI Custom Query. Stores the {@link AaiCqResponse} in the context. In addition, if the
* applies to the vserver, thus the target entity may be set to an empty string.
*/
public class AaiCustomQueryOperation extends HttpOperation<String> {
- private static final Logger logger = LoggerFactory.getLogger(AaiCustomQueryOperation.class);
-
public static final String NAME = AaiCqResponse.OPERATION;
public static final String VSERVER_VSERVER_NAME = "vserver.vserver-name";
private static final List<String> PROPERTY_NAMES = List.of(OperationProperties.AAI_VSERVER_LINK);
- // TODO make this configurable
- private static final String PREFIX = "/aai/v16";
-
- @Getter
- private final String vserver;
-
/**
* Constructs the object.
*
*/
public AaiCustomQueryOperation(ControlLoopOperationParams params, HttpConfig config) {
super(params, config, String.class, PROPERTY_NAMES);
-
- this.vserver = params.getContext().getEnrichment().get(VSERVER_VSERVER_NAME);
- if (StringUtils.isBlank(this.vserver)) {
- throw new IllegalArgumentException("missing " + VSERVER_VSERVER_NAME + " in enrichment data");
- }
- }
-
- /**
- * Queries the vserver, if necessary.
- */
- @Override
- protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- ControlLoopOperationParams tenantParams =
- params.toBuilder().actor(AaiConstants.ACTOR_NAME).operation(AaiGetTenantOperation.NAME)
- .targetEntity(vserver).payload(null).retry(null).timeoutSec(null).build();
-
- return params.getContext().obtain(AaiGetTenantOperation.getKey(vserver), tenantParams);
}
@Override
* Constructs the custom query using the previously retrieved tenant data.
*/
private Map<String, String> makeRequest() {
- StandardCoderObject tenant = params.getContext().getProperty(AaiGetTenantOperation.getKey(vserver));
-
- String resourceLink = tenant.getString(RESULT_DATA, 0, RESOURCE_LINK);
- if (resourceLink == null) {
- throw new IllegalArgumentException("cannot perform custom query - no resource-link");
- }
-
- resourceLink = resourceLink.replace(PREFIX, "");
+ return Map.of("start", getVserverLink(), "query", "query/closed-loop");
+ }
- return Map.of("start", resourceLink, "query", "query/closed-loop");
+ /**
+ * Gets the vserver link, first checking the properties, and then the tenant data.
+ *
+ * @return the vserver link
+ */
+ protected String getVserverLink() {
+ return getRequiredProperty(OperationProperties.AAI_VSERVER_LINK, "vserver link");
}
@Override
return AaiUtil.makeHeaders(params);
}
- /**
- * Injects the response into the context.
- */
@Override
- protected CompletableFuture<OperationOutcome> postProcessResponse(OperationOutcome outcome, String url,
- Response rawResponse, String response) {
+ public OperationOutcome setOutcome(OperationOutcome outcome, OperationResult result, Response rawResponse,
+ String response) {
- logger.info("{}: caching response for {}", getFullName(), params.getRequestId());
- params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, new AaiCqResponse(response));
+ super.setOutcome(outcome, result, rawResponse, response);
+
+ if (response != null) {
+ outcome.setResponse(new AaiCqResponse(response));
+ }
- return super.postProcessResponse(outcome, url, rawResponse, response);
+ return outcome;
}
}