2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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.openecomp.policy.aai.AAINQF199;
23 import java.util.HashMap;
25 import java.util.UUID;
27 import org.openecomp.policy.aai.AAIGETResponse;
28 import org.openecomp.policy.aai.util.Serialization;
29 import org.openecomp.policy.rest.RESTManager;
30 import org.openecomp.policy.rest.RESTManager.Pair;
32 import com.google.gson.JsonSyntaxException;
34 public final class AAINQF199Manager {
36 public static AAINQF199Response postQuery(String url, String username, String password, AAINQF199Request request, UUID requestID) {
38 Map<String, String> headers = new HashMap<String, String>();
39 headers.put("X-FromAppId", "POLICY");
40 headers.put("X-TransactionId", requestID.toString());
41 headers.put("Accept", "application/json");
43 url = url + "/aai/search/named-query";
45 Pair<Integer, String> httpDetails = RESTManager.post(url, username, password, headers, "application/json", Serialization.gsonPretty.toJson(request));
47 if (httpDetails == null) {
48 System.out.println("AAI POST Null Response to " + url);
52 System.out.println(url);
53 System.out.println(httpDetails.a);
54 System.out.println(httpDetails.b);
55 if (httpDetails.a == 200) {
57 AAINQF199Response response = Serialization.gsonPretty.fromJson(httpDetails.b, AAINQF199Response.class);
59 } catch (JsonSyntaxException e) {
60 System.err.println("Failed to deserialize into AAIResponse" + e.getLocalizedMessage());
67 public static AAIGETResponse getQuery(String urlGet, String username, String password, UUID requestID, String vnfId) {
69 Map<String, String> headers = new HashMap<String, String>();
70 headers.put("X-FromAppId", "POLICY");
71 headers.put("X-TransactionId", requestID.toString());
72 headers.put("Accept", "application/json");
74 urlGet = urlGet + "/aai/v8/network/generic-vnfs/generic-vnf/" + vnfId;
77 AAIGETResponse responseGet = null;
79 while(attemptsLeft-- > 0){
81 Pair<Integer, String> httpDetailsGet = RESTManager.get(urlGet, username, password, headers);
82 if (httpDetailsGet == null) {
83 System.out.println("AAI GET Null Response to " + urlGet);
87 System.out.println(urlGet);
88 System.out.println(httpDetailsGet.a);
89 System.out.println(httpDetailsGet.b);
91 if (httpDetailsGet.a == 200) {
93 responseGet = Serialization.gsonPretty.fromJson(httpDetailsGet.b, AAIGETResponse.class);
95 } catch (JsonSyntaxException e) {
96 System.err.println("Failed to deserialize into AAIResponse" + e.getLocalizedMessage());
101 } catch (InterruptedException e) {}