Get All Network Connections Examples (Bulk Information Transfer)

Overview

GET /data/otn/networkinventory/connections request shall be used to retrieve list of all Network Connections stored in OMS

Here described is an example of Get All Network Connections

GET All Network Connections

Below is code snippet to retrieve all the network connections.


public class BulkUplaodService extends Service {
	/***
	* retrieveDataForConnection
	* */
	public List<String> retrieveDataForConnection (OMSRestTemplate restTemplate, String urlSuffix) {
		List<String> retData = new ArrayList <String>();
		/** Url to retrieve networkconnections json file*/
		String custUrl = restTemplate.getUrlPrefix() + urlSuffix; //"//data/otn/networkinventory/connections";
		//?userid=ECmdKGhCKVqxOwMqdli62w==&password=zGwL2f+0s44QqnRUAhJSKQ==";

		/**retrieve json file path*/
		JsonNode response = restTemplate.getForObject(custUrl, JsonNode.class);
		System.out.println( response );
		String statusUrl = restTemplate.getUrlPrefix() + "/data/otn/networkinventory/connectionstatus";
		JsonNode filePaths = null;
		for (int i = 0 ; i < 5 ; i++ ){
			response = restTemplate.getForObject(statusUrl, JsonNode.class);
			if (response.get("responseHeader").get ("responseStatus").textValue().equalsIgnoreCase("success")) {
				filePaths = response.get("responseFiles");
				break;
			}
			try {
				Thread.sleep(10000);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		//JsonNode respFiles = response.get("responseFiles");
		if (filePaths != null) downloadFilesForConnection(restTemplate, retData, filePaths, ""); 
		return retData;
	}

JSON Request to get the network connections


/data/otn/networkinventory/connections

JSON Response


{
	"responseHeader": {
		"originatorApp": "NPT",
		"objectType": "connections",
		"objectScope": "connections",
		"responseStatus": "IN_PROGRESS",
		"fileGenerationTime": null,
		"errorCode": null,
		"errorReason": null,
		"errorParams": null
	},
	"responseFiles": null
}

JSON Request to get the network connection status


//data/otn/networkinventory/connectionstatus

JSON Response


/OTN_2-13/data_extraction/npt/inventory/connection/connections.tar.gz

Download the JSON Response files

Below is code snippet to download the targ.gz files.


private void downloadFilesForConnection(OMSRestTemplate restTemplate, List<String> retData, JsonNode networkDataFileList, String urlPrefix {
	String url;
	Iterator<JsonNode> it = networkDataFileList.iterator();

	while (ithasNext ()) {
		String filePath = it.next().textValue();
		url = urlPrefix + filePath.replace("oms1350/", "") ; //+ "?userid=ECmdKGhCKVqxOwMqdli62w==&password=zGwL2f+0s44QqnRUAhJSKQ==";
		System.out.println( "URL"+ url );
		String fileName = filePath.substring(filePath.lastIndexOf("/")+1);
		System.out.println(fileName);
		ResponseEntity<byte[]> response = restTemplate.getForEntity(url, byte[].class);

		if (response.getStatusCode() == HttpStatus.OK) {
			try {
				System.out.println (Paths.get(fileName));
				Files.write(Paths.get(fileName), response.getBody());
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
}

Request


/OTN_2-13/data_extraction/npt/inventory/connection/connections.tar.gz

Response


connections.tar.gz

Main Class

Following shows the client code snippet in main class retrieve all the network connections.


public class OmsRestClientApplication {
	public static void main(String[] args) {
		AuthInfo authInfo = new AuthInfo();
		authInfo.setServerIP("135.250.184.42");
		authInfo.setServerPort("8443");
		authInfo.setServerUser("alcatel");
		authInfo.setServerPwd("Lucent1.!");
		authInfo.setPresentationIP("135.250.184.43");

		/**create OMSRestTemplate instance**/
		OMSRestTemplate omsRestTemplate = new OMSRestTemplate ();

		/**authenticate*/
		omsRestTemplate.authenticate(authInfo);

		BulkUplaodService bSvc = new BulkUplaodService ();
		List<String> resp = bSvc.getAllConnections(omsRestTemplate);
	}
}