2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.controlloop.actor.aai;
23 import java.net.URLEncoder;
24 import java.nio.charset.StandardCharsets;
26 import java.util.concurrent.CompletableFuture;
27 import javax.ws.rs.client.Invocation.Builder;
28 import javax.ws.rs.client.WebTarget;
29 import javax.ws.rs.core.MediaType;
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.parameters.ControlLoopOperationParams;
35 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
38 * A&AI get-pnf operator.
40 public class AaiGetPnfOperation extends AaiGetOperation {
41 private static final String URI_SEP = "/";
43 public static final String NAME = "Pnf";
46 private static final String KEY_PREFIX = AaiConstants.CONTEXT_PREFIX + NAME + ".";
49 * Constructs the object.
51 * @param params operation parameters
52 * @param config configuration for this operation
54 public AaiGetPnfOperation(ControlLoopOperationParams params, HttpConfig config) {
55 super(params, config);
59 * Gets the "context key" for the PNF query response associated with the given
62 * @param targetEntity target entity
63 * @return the "context key" for the response associated with the given target
65 public static String getKey(String targetEntity) {
66 return (KEY_PREFIX + targetEntity);
70 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
71 Map<String, Object> headers = makeHeaders();
73 headers.put("Accept", MediaType.APPLICATION_JSON);
75 StringBuilder str = new StringBuilder(getClient().getBaseUrl());
77 String path = getPath() + URI_SEP + URLEncoder.encode(params.getTargetEntity(), 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 String url = str.toString();
88 logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
90 return handleResponse(outcome, url, callback -> webldr.async().get(callback));