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.aai;
24 import jakarta.ws.rs.client.Invocation.Builder;
25 import jakarta.ws.rs.client.WebTarget;
26 import java.net.URLEncoder;
27 import java.nio.charset.StandardCharsets;
29 import java.util.concurrent.CompletableFuture;
30 import org.onap.policy.aai.AaiConstants;
31 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
32 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
33 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
34 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
35 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
36 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
39 * A&AI get-pnf operator.
41 public class AaiGetPnfOperation extends AaiGetOperation {
42 private static final String URI_SEP = "/";
44 public static final String NAME = "Pnf";
47 private static final String KEY_PREFIX = AaiConstants.CONTEXT_PREFIX + NAME + ".";
50 * Constructs the object.
52 * @param params operation parameters
53 * @param config configuration for this operation
55 public AaiGetPnfOperation(ControlLoopOperationParams params, HttpConfig config) {
56 super(params, config);
60 * Gets the "context key" for the PNF query response associated with the given
63 * @param targetEntity target entity
64 * @return the "context key" for the response associated with the given target
66 public static String getKey(String targetEntity) {
67 return (KEY_PREFIX + targetEntity);
71 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
72 Map<String, Object> headers = makeHeaders();
74 var str = new StringBuilder(getClient().getBaseUrl());
76 String target = getRequiredProperty(OperationProperties.AAI_TARGET_ENTITY, "target entity");
77 String path = getPath() + URI_SEP + URLEncoder.encode(target, StandardCharsets.UTF_8);
78 WebTarget web = getClient().getWebTarget().path(path);
81 web = addQuery(web, str, "?", "depth", "0");
83 Builder webldr = web.request();
84 addHeaders(webldr, headers);
86 var url = str.toString();
88 logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
90 return handleResponse(outcome, url, callback -> webldr.async().get(callback));