...
Investigate A&AI Interface, especially how to retrieve inventory, current list of xNF functionsConsider som PoC Code.
Documentation:
How to retrieve current list of xNF functions from A&AI
...
?
Send Get GET request to this endpoint
Image Removed
Image Added
Example curl command you can use to retrieve inventory from any pod within the cluster in which AAI is deployed to.
Code Block |
---|
title | Example curl command |
---|
|
curl 'https://aai:8443{serverRoot}/aai/v23/network/pnfs' |
PoC code:
Write code to show that it is possible to retrieve the current list of xNF functionsThe above command returns a list of all the pnfs.
Example of the data that is returned by the curl command.
Elite soft json viewer |
---|
|
{"pnf":[{"pnf-name":"dummyTest15","pnf-name2":"dummypnf-1597953056126","pnf-id":"927b2580-36d9-4f13-8421-3c9d43b7a75e","equip-type":"example-equip-type-val-20348","equip-vendor":"example-equip-vendor-val-52182","equip-model":"example-equip-model-val-8370","management-option":"example-management-option-val-72881","orchestration-status":"Active","ipaddress-v4-oam":"100.10.20.20","in-maint":false,"ipaddress-v6-oam":"","spare-equipment-indicator":false,"resource-version":"1622041203064"}]} |
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.
Code Block |
---|
language | java |
---|
theme | Eclipse |
---|
firstline | 1 |
---|
title | POC code for Inventory Retriever |
---|
linenumbers | true |
---|
collapse | true |
---|
|
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;
import lombok.Generated;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class InventoryRetriever {
private String getAaiServiceUrlHttps() {
final String version = "v23";
return "https://aai:8443/aai/" + version + "/network/pnfs";
}
/**
* get nfs from aai.
* @return []
*/
@Generated 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");
log.info("Reader info before connn ");
conn.connect();
log.info("Reader info after connn {}", conn.getResponseCode());
log.info("response message {}", conn.getResponseMessage());
nfData = responseReader(conn);
} catch (final IOException e) {
e.printStackTrace();
log.info("Reader info ERROR: in IR class ");
}
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.
Code Block |
---|
language | java |
---|
theme | Eclipse |
---|
firstline | 1 |
---|
title | Workaround Code for making HTTPS calls |
---|
linenumbers | true |
---|
collapse | true |
---|
|
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
Code Block |
---|
language | java |
---|
theme | Eclipse |
---|
firstline | 1 |
---|
title | Code to retrieve xNF functions from A&AI |
---|
linenumbers | true |
---|
collapse | true |
---|
|
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();
} |
Spike Presentation to the Team:
View file |
---|
name | CPS-392 A&AI Inventory List Spike Review-20210527_163153-Meeting Recording.mp4 |
---|
height | 250 |
---|
|