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;
 
  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 org.onap.policy.aai.AaiConstants;
 
  30 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
 
  31 import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType;
 
  32 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 
  33 import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
 
  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         StringBuilder str = new StringBuilder(getClient().getBaseUrl());
 
  75         String target = getRequiredProperty(OperationProperties.AAI_TARGET_ENTITY, "target entity");
 
  76         String path = getPath() + URI_SEP + URLEncoder.encode(target, StandardCharsets.UTF_8);
 
  77         WebTarget web = getClient().getWebTarget().path(path);
 
  80         web = addQuery(web, str, "?", "depth", "0");
 
  82         Builder webldr = web.request();
 
  83         addHeaders(webldr, headers);
 
  85         String url = str.toString();
 
  87         logMessage(EventType.OUT, CommInfrastructure.REST, url, null);
 
  89         return handleResponse(outcome, url, callback -> webldr.async().get(callback));