Service Connection Deletion

Overview

Here described is an example of Deleting Service connection .

Delete Service Connection

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

This deactivates and deletes the Service connection

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

Retrieve Service Connection Details using Name

Code snippet to retrieve the connection details


/**
* This method takes the service connection name as input and retrieves the service connection details.
* @param restTemplate 
* @param connName service name 
* @return service connection Node details
*/

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

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

	return connDetails;
}

Code snippet to delete the service connections


/**
* This API is used to delete network connection using connection name.
*
* */

public String deleteServiceConnection (OMSRestTemplate restTemplate, String connectionName) {
	/**Retrieve connection details using connectionn name*/
	JsonNode connDetails = ServiceUtil.getServiceDetailsByName (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("path")) {
			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();
}

Request and Response Sample

JSON Request

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

JSON Response


{
	"message": "Remove order action for order ID2353 and connection ser-11dpm12 completed successfully. ",
	"messageId": "OH1018I",
	"messageSeverity": "I",
	"status": "SUCCESS",
	"connectionName": "ser-11dpm12",
	"connectionId": 1550,
	"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 service connection*/
		connService.deleteServiceConnection(omsRestTemplate, "ser-11dpm12");
	}
}

Service Class Code


public class ConnectionService extends Service{
	/**
	* This API is used to delete network connection using connection name.
	*
	* */
	public String deleteServiceConnection (OMSRestTemplate restTemplate, String connectionName) {
		/**Retrieve connection details using connectionn name*/
		JsonNode connDetails = ServiceUtil.getServiceDetailsByName (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 getServiceDetailsByName (OMSRestTemplate restTemplate, String connectionName) {
		/**Rest URL to retrieve all the template folders*/
		String connectionDetailsUrl = restTemplate.getUrlPrefix() + "/data/otn/connection/path?guiLabel=" + connectionName;

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