* ============LICENSE_START=======================================================
* ONAP
* ================================================================================
- * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
package org.onap.policy.controlloop.actor.aai;
+import jakarta.ws.rs.client.Entity;
+import jakarta.ws.rs.client.Invocation.Builder;
+import jakarta.ws.rs.client.WebTarget;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.CompletableFuture;
-import javax.ws.rs.client.Entity;
-import javax.ws.rs.client.Invocation.Builder;
-import javax.ws.rs.client.WebTarget;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-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";
-
/**
* Constructs the object.
*
super(params, config, String.class, PROPERTY_NAMES);
}
- /**
- * Gets the vserver name from the enrichment data.
- *
- * @return the vserver name
- */
- protected String getVserver() {
- String vserver = this.params.getContext().getEnrichment().get(VSERVER_VSERVER_NAME);
- if (StringUtils.isBlank(vserver)) {
- throw new IllegalArgumentException("missing " + VSERVER_VSERVER_NAME + " in enrichment data");
- }
-
- return vserver;
- }
-
- /**
- * Queries the vserver, if necessary.
- */
- @Override
- protected CompletableFuture<OperationOutcome> startPreprocessorAsync() {
- if (params.isPreprocessed()) {
- return null;
- }
-
- String vserver = getVserver();
- 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
public void generateSubRequestId(int attempt) {
setSubRequestId(String.valueOf(attempt));
final Map<String, String> request = makeRequest();
Map<String, Object> headers = makeHeaders();
- StringBuilder str = new StringBuilder(getClient().getBaseUrl());
+ var str = new StringBuilder(getClient().getBaseUrl());
String path = getPath();
WebTarget web = getClient().getWebTarget().path(path);
webldr.header(header.getKey(), header.getValue());
}
- String url = str.toString();
+ var url = str.toString();
String strRequest = prettyPrint(request);
logMessage(EventType.OUT, CommInfrastructure.REST, url, strRequest);
* @return the vserver link
*/
protected String getVserverLink() {
- String resourceLink = getProperty(OperationProperties.AAI_VSERVER_LINK);
- if (resourceLink != null) {
- return resourceLink;
- }
-
- String vserver = getVserver();
- StandardCoderObject tenant = params.getContext().getProperty(AaiGetTenantOperation.getKey(vserver));
- if (tenant == null) {
- throw new IllegalStateException("cannot perform custom query - cannot determine resource-link");
- }
-
- 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 resourceLink;
+ return getRequiredProperty(OperationProperties.AAI_VSERVER_LINK, "vserver link");
}
@Override
return outcome;
}
-
- /**
- * Injects the response into the context.
- */
- @Override
- protected CompletableFuture<OperationOutcome> postProcessResponse(OperationOutcome outcome, String url,
- Response rawResponse, String response) {
-
- if (params.getContext() != null) {
- logger.info("{}: caching response for {}", getFullName(), params.getRequestId());
- params.getContext().setProperty(AaiCqResponse.CONTEXT_KEY, new AaiCqResponse(response));
- }
-
- return super.postProcessResponse(outcome, url, rawResponse, response);
- }
}