You are viewing an old version of this content. View the current version.
Compare with Current
View Version History
« Previous
Version 23
Next »
CPS-392
-
Getting issue details...
STATUS
Investigate A&AI Interface, especially how to retrieve inventory, current list of xNF functions.
How to retrieve current list of xNF functions from A&AI?
Send GET request to this endpoint

Example curl command you can use to retrieve inventory from any pod within the cluster in which AAI is deployed to.
curl 'https://{serverRoot}/aai/v23/network/pnfs'
The above command returns a list of all the pnfs.
Proof of Concept code:
The below is Proof Of Concept code and it is not production ready. With this code, we are able to retrieve list of network functions from A&AI.
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
public class InventoryRetriever {
private String getAaiServiceUrlHttps() {
final String version = "v23";
return "https://aai:8443/aai/" + version + "/network/pnfs";
}
public String getXnfsFromAai() throws NoSuchAlgorithmException, KeyManagementException {
final TrustManager[] trustAllCerts = new TrustManager[] {new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new ArrayList<X509Certificate>().toArray(new X509Certificate[0]);
}
public void checkClientTrusted(final X509Certificate[] certs, final String authType) {
}
public void checkServerTrusted(final X509Certificate[] certs, final String authType) {
}
}
};
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
final HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
};
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
String nfData = "";
final String aaiNetworkEndPoint = getAaiServiceUrlHttps();
final URL url;
try {
url = new URL(aaiNetworkEndPoint);
final HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "Basic QUFJOkFBSQ==");
conn.setRequestProperty("accept", "application/json");
conn.setRequestProperty("conntent-type", "application/json");
conn.setRequestProperty("x-fromappid", "cps-ncmp");
conn.setRequestProperty("X-TransactionId", "get_aai_subscr");
conn.connect();
nfData = responseReader(conn);
} catch (final IOException e) {
e.printStackTrace();
}
return nfData;
}
private String responseReader(final HttpsURLConnection conn) {
BufferedReader in = null;
final StringBuilder response = new StringBuilder();
try {
in = new BufferedReader(new InputStreamReader(
conn.getInputStream(), StandardCharsets.UTF_8));
String inputLine;
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
} catch (final IOException e) {
e.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
return response.toString();
}
}
What to do next?
To write production ready code, the following things will need to be done.
- User Story to implement One way SSL communication needed to make Https calls.
-
- Currently the project is not set up to make HTTPS calls. For the POC the following code was added to workaround this issue.
final TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return new ArrayList<X509Certificate>().toArray(new X509Certificate[0]);
}
public void checkClientTrusted(final X509Certificate[] certs, final String authType) {
}
public void checkServerTrusted(final X509Certificate[] certs, final String authType) {
}
}
};
final SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
final HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(final String hostname, final SSLSession session) {
return true;
}
};
- User story to implement retrieving of the current list of xNF functions
- Part of the PoC code which does can be seen below
String nfData = "";
final String aaiNetworkEndPoint = getAaiServiceUrlHttps();
final URL url;
try {
url = new URL(aaiNetworkEndPoint);
final HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();
conn.setRequestProperty("Authorization", "Basic QUFJOkFBSQ==");
conn.setRequestProperty("accept", "application/json");
conn.setRequestProperty("conntent-type", "application/json");
conn.setRequestProperty("x-fromappid", "cps-ncmp");
conn.setRequestProperty("X-TransactionId", "get_aai_subscr");
conn.connect();
nfData = responseReader(conn);
} catch (final IOException e) {
e.printStackTrace();
}