Physical Connection Deletion

Overview

A physical connection is a connection that uses wires, cables, or optical fibers to connect two physical ports in a network.

Here described is an example of OTS physical connection deletion.

Delete Physical Connection

REST API to delete physical connection DELETE /data/npr/physicalConns/{connectId}.

This deletes physical connection in Implemented state.

deletePhysicalConnection method takes physical connection name as input, and retrieves physical connection details, and makes REST call to delete physicalConnection.

Retrieve Physical Connection Details using Name

Code snippet to retrieve the connection details


/**
* This method takes the physical connection name as input and retrieves the physical connection details.
* @param restTemplate 
* @param connName physical connection name 
* @return Physical connection Node details
*/
public JsonNode retrieveConnectionDetails(OMSRestTemplate restTemplate, String connName) {
    JsonNode connDetail = null;
    String getNodesUrl = restTemplate.getUrlPrefix() + "/data/npr/physicalConns?guiLabel=" + connName;
    JsonNode retResp = restTemplate.getForObject(getNodesUrl, JsonNode.class);
    if (retResp != null && retResp.size() > 0) {
        connDetail = retResp.get(0);
    }
	
    return connDetail;
}

Code snippet to delete the physical connections


/**
* This method is used to delete the physical connection
* @param restTemplate
* @param connName physical connection name
* @return
*/
public JsonNode deletePhysicalConnection (OMSRestTemplate restTemplate, String connName) { 
    JsonNode retResp = null; 
    JsonNode connDetail = retrieveConnectionDetails (restTemplate, connName); 

    if ( connDetail != null ) { 
       String connId = connDetail.get("id").asText();

       /**Delete REST URL*/
       String deleteUrl = restTemplate.getUrlPrefix() + "/data/npr/physicalConns/" + connId ;

       /**Make HTTP DELETE REST call*/
       ResponseEntity <JsonNode> response = restTemplate.exchange (deleteUrl, HttpMethod.DELETE, null, JsonNode.class);
 
       System.out.println("physical connection " + retResp);
       return response != null ? response.getBody() : null; 
    }

    return retResp;
}

Request and Response Sample

JSON Request


/oms1350/data/npr/physicalConns/347

JSON Response


{
  "ok": true,
  "id": "3723591207055612",
  "responseMessage": "ok",
  "responseList": null,
  "HTTPResponse": 200,
  "httpresponse": 200
}

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 physical connection service instance*/
    PysicalConnectionService physConnSvc = new PysicalConnectionService();
    /**invoke delete physical connection*/
    physConnSvc.deletePhysicalConnection (omsRestTemplate, "REST-CLIENT-OTS");
  }

  Service Class Code

  public class PysicalConnectionService extends Service {

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

  public JsonNode retrieveConnectionDetails(OMSRestTemplate restTemplate, String connName) {
    JsonNode connDetail = null;
    String getNodesUrl = restTemplate.getUrlPrefix() + "/data/npr/physicalConns?guiLabel=" + connName;
    JsonNode retResp = restTemplate.getForObject(getNodesUrl, JsonNode.class);
    if (retResp != null && retResp.size() > 0) {
        connDetail = retResp.get(0);
    }

    return connDetail;
  }

  /**
  * This method is used to delete the physical connection
  * @param restTemplate
  * @param connName physical connection name
  * @return
  */
  public JsonNode deletePhysicalConnection (OMSRestTemplate restTemplate, String connName) { 
    JsonNode connDetail = retrieveConnectionDetails (restTemplate, connName);

    if ( connDetail != null ) {
        String connId = connDetail.get("id").asText();

        /**Delete REST URL*/
        String deleteUrl = restTemplate.getUrlPrefix() + "/data/npr/physicalConns/" + connId ;

        /**Make HTTP DELETE REST call*/
        ResponseEntity <JsonNode> response = restTemplate.exchange (deleteUrl, HttpMethod.DELETE, null, JsonNode.class);
        System.out.println("physical connection " + retResp);

        return response != null ? response.getBody() : null; 
      }

    return null;
  }
}