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;
27 import java.util.concurrent.CompletableFuture;
28 import org.onap.policy.aai.AaiConstants;
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.OperationOutcome;
32 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
33 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
34 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
37 * A&AI get-tenant operator.
39 public class AaiGetTenantOperation extends AaiGetOperation {
41 public static final String NAME = "Tenant";
44 private static final String KEY_PREFIX = AaiConstants.CONTEXT_PREFIX + NAME + ".";
47 * Constructs the object.
49 * @param params operation parameters
50 * @param config configuration for this operation
52 public AaiGetTenantOperation(ControlLoopOperationParams params, HttpConfig config) {
53 super(params, config);
57 * Gets the "context key" for the tenant query response associated with the given
60 * @param targetEntity target entity
61 * @return the "context key" for the response associated with the given target
63 public static String getKey(String targetEntity) {
64 return (KEY_PREFIX + targetEntity);
68 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
69 final Map<String, Object> headers = makeHeaders();
71 var str = new StringBuilder(getClient().getBaseUrl());
73 String path = getPath();
74 WebTarget web = getClient().getWebTarget().path(path);
77 String target = getRequiredProperty(OperationProperties.AAI_TARGET_ENTITY, "target entity");
79 web = addQuery(web, str, "?", "search-node-type", "vserver");
80 web = addQuery(web, str, "&", "filter", "vserver-name:EQUALS:" + target);
82 Builder webldr = web.request();
83 addHeaders(webldr, headers);
85 var url = str.toString();
87 logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
89 return handleResponse(outcome, url, callback -> webldr.async().get(callback));