You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

CPS-392 - Getting issue details... STATUS

Investigate A&AI Interface, especially how to retrieve inventory, current list of xNF functions

Consider som PoC Code

Documentation:

AAI REST API Documentation - Honolulu

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.

Example curl command
curl 'https://aai:8443/aai/v23/network/pnfs'

PoC code:

Write code to show that it is possible to retrieve the current list of xNF functions.


POC code for Inventory Retriever
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";
    }

    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();
    }
    
}


  • No labels