2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020-2021 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;
24 import java.util.concurrent.CompletableFuture;
25 import javax.ws.rs.client.Invocation.Builder;
26 import javax.ws.rs.client.WebTarget;
27 import org.onap.policy.aai.AaiConstants;
28 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
29 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
30 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
31 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
32 import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
33 import org.onap.policy.controlloop.actorserviceprovider.parameters.HttpConfig;
36 * A&AI get-tenant operator.
38 public class AaiGetTenantOperation extends AaiGetOperation {
40 public static final String NAME = "Tenant";
43 private static final String KEY_PREFIX = AaiConstants.CONTEXT_PREFIX + NAME + ".";
46 * Constructs the object.
48 * @param params operation parameters
49 * @param config configuration for this operation
51 public AaiGetTenantOperation(ControlLoopOperationParams params, HttpConfig config) {
52 super(params, config);
56 * Gets the "context key" for the tenant query response associated with the given
59 * @param targetEntity target entity
60 * @return the "context key" for the response associated with the given target
62 public static String getKey(String targetEntity) {
63 return (KEY_PREFIX + targetEntity);
67 protected CompletableFuture<OperationOutcome> startOperationAsync(int attempt, OperationOutcome outcome) {
68 final Map<String, Object> headers = makeHeaders();
70 StringBuilder str = new StringBuilder(getClient().getBaseUrl());
72 String path = getPath();
73 WebTarget web = getClient().getWebTarget().path(path);
76 String target = getRequiredProperty(OperationProperties.AAI_TARGET_ENTITY, "target entity");
78 web = addQuery(web, str, "?", "search-node-type", "vserver");
79 web = addQuery(web, str, "&", "filter", "vserver-name:EQUALS:" + target);
81 Builder webldr = web.request();
82 addHeaders(webldr, headers);
84 String url = str.toString();
86 logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
88 return handleResponse(outcome, url, callback -> webldr.async().get(callback));