Infrastructure Connection Deletion

Overview

Here described is an example of Deleting infrastructure connection .

Delete Infrastructure Connection

REST API to delete Infrastructure connection POST /data/otn/connections/{id}/delete.

This deactivates and deletes the Infrastucture connection

deleteInfraConnection method takes connection name as input, and retrieves the connection details, and makes REST call to delete connection.

Retrieve Infrastructure Connection Details using Name

Code snippet to retrieve the connection details


/**
* This method takes the infrastructure connection name as input and retrieves the infrastructure connection details.
* @param restTemplate 
* @param connName infraconnection name 
* @return Infrastructure connection Node details
*/
public static JsonNode getInfraDetailsByName (OMSRestTemplate restTemplate, String connectionName) { 
	/**Rest URL to retrieve all the template folders*/
	String connectionDetailsUrl = restTemplate.getUrlPrefix() + "/data/otn/connection/trail?guiLabel=" + connectionName;

	/**Retrieve all the folders*/
	JsonNode connDetails = restTemplate.getForObject(connectionDetailsUrl, JsonNode.class);

	return connDetails;
}

Code snippet to delete the infrastructure connections


/**
* This API is used to delete network connection using connection name.
*
* */
public String deleteInfraConnection (OMSRestTemplate restTemplate, String connectionName) {
	/**Retrieve connection details using connectionn name*/
	JsonNode connDetails = ServiceUtil.getInfraDetailsByName (restTemplate, connectionName);
	System.out.println( "connDetails - " + connDetails);
	Iterator<JsonNode> it = connDetails.get("items").iterator();;

	/**fetch connectionId from conn detail node*/
	String connId = null ;
	while (it.hasNext() ) {
		JsonNode n = it.next();
		System.out.println( " n : "+ n);
		if (n.get("className").asText().equals("trail")) {
			connId = n.get("id").asText();
			break;
		}
	} 
	String connDeleteUrl = restTemplate.getUrlPrefix() + "/data/otn/connections/" + connId + "/delete?type=NtwConnDelete";
	JsonNode resp = restTemplate.postForObject (connDeleteUrl, null, JsonNode.class);
	return resp.toString();//resp.toString();
}

Request and Response Sample

JSON Request


/oms1350/data/otn/connections/8206/delete?type=NtwConnDelete

JSON Response


{
	"message":"Remove order action for order ID13846 and connection L0-CP-INFRA-CONN completed successfully. ",
	"messageId":"OH1018I",
	"messageSeverity":"I",
	"status":"SUCCESS",
	"connectionName":"L0-CP-INFRA-CONN",
	"connectionId":8206,
	"orderNumber":"",
	"orderId":"",
	"orderStep":0,
	"errorField":"",
	"errorValue":""
}

Complete Code

Main class - OmsRestClientApplication.java


public class OmsRestClientApplication {
	public static void main(String[] args) {
		/**Authentication Information like Machine IP, username and password*/
		AuthInfo authInfo = new AuthInfo(); 
		authInfo.setServerIP("135.250.76.157");
		authInfo.setServerPort("8443");
		authInfo.setServerUser("alcatel");
		authInfo.setServerPwd("Lucent1.!");
		authInfo.setPresentationIP("135.250.76.46");

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

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

		/**Instantiate connection service instance*/
		ConnectionService connService = new ConnectionService ();

		/**invoke delete infrastructure connection*/
		connService.deleteInfraConnection(omsRestTemplate, "L0-CP-INFRA-CONN");
	}
}

Service Class Code


public class ConnectionService extends Service{
	/**
	* This API is used to delete network connection using connection name.
	*
	* */
	public String deleteInfraConnection (OMSRestTemplate restTemplate, String connectionName) {
		/**Retrieve connection details using connectionn name*/
		JsonNode connDetails = ServiceUtil.getInfraDetailsByName (restTemplate, connectionName);
		Iterator<JsonNode> it = connDetails.get("items").iterator();;

		/**fetch connectionId from conn detail node*/
		String connId = null ;
		while (it.hasNext() ) {
			JsonNode n = it.next();
			if (n.get("className").asText().equals("trail")) {
				connId = n.get("id").asText();
				break;
			}
		}
		String connDeleteUrl = restTemplate.getUrlPrefix() + "/data/otn/connections/" + connId + "/delete?type=NtwConnDelete"; 
		JsonNode resp = restTemplate.postForObject (connDeleteUrl, null, JsonNode.class);

		return resp.toString();//resp.toString();
	}
}

Service Util Code


public class ServiceUtil {
	public static JsonNode getInfraDetailsByName (OMSRestTemplate restTemplate, String connectionName) {
		/**Rest URL to retrieve all the template folders*/
		String connectionDetailsUrl = restTemplate.getUrlPrefix() + "/data/otn/connection/trail?guiLabel=" + connectionName;

		/**Retrieve all the folders*/
		JsonNode connDetails = restTemplate.getForObject(connectionDetailsUrl, JsonNode.class);

		return connDetails;
	}
}