Package com.tailf.ned

Class NedWorker

Object
Thread
com.tailf.ned.NedWorker
All Implemented Interfaces:
ch.ethz.ssh2.auth.AgentProxy, NedTracer, Runnable

public class NedWorker extends Thread implements NedTracer, ch.ethz.ssh2.auth.AgentProxy
The NedWorker is used by the NedMux for running a worker thread for executing NedConnection tasks.
  • Field Details

  • Constructor Details

  • Method Details

    • log

      public void log(String msg) throws Exception
      Send log messages to NCS. The log messages will end up at... FIXME
      Parameters:
      msg -
      Throws:
      Exception
    • trace

      public void trace(String msg, String direction, String device_id)
      Send trace message to the NCS. The message will end up at... FIXME
      Specified by:
      trace in interface NedTracer
      Parameters:
      msg -
      direction -
      device_id -
    • setTimeout

      public void setTimeout(int ms)
      When the NED worker gets invoked, it gets passed three timeout values, connect/read/write timeouts. The NED code shall try to honor these timeouts. However, if the NED code fails to do that, the NCS itself has a timeout. The timeouts are config parameters under /devices/device/connect-timeout, /devices/device/read-timeout, and /devices/device/write-timeout. NCS will add 3 seconds to that timeout, and if the NED doesn't honor the timeouts, NCS will internally timeout the request. This method can be used to increase the timeout. I.e a NED that knows it is doing useful work, can prolong the configured timeouts.
      Parameters:
      ms - the number of milliseconds to set the new timeout to.
    • setAdditionalInfo

      public void setAdditionalInfo(String info)
      Set information to be passed back to the caller, typically parse information if the user invokes a show action with the verbose parameter.
      Parameters:
      info -
    • getDevicePhase

      public String getDevicePhase()
      Get the phase of the device.
    • run

      public void run()
      Specified by:
      run in interface Runnable
      Overrides:
      run in class Thread
    • commitResponse

      public void commitResponse() throws IOException, NedException
      This method should be invoked by a NedConnection instance when it has completed a commit operation to indicate a successful completion of the commit.
      Throws:
      IOException
      NedException
    • prepareResponse

      public void prepareResponse() throws IOException, NedException
      This method should be invoked by a NedConnection instance when it has completed a prepare operation to indicate a successful completion of the prepare.
      Throws:
      IOException
      NedException
    • prepareDryResponse

      public void prepareDryResponse(String output) throws IOException, NedException
      This method should be invoked by a NedConnection instance when it has completed a prepare dry operation to indicate a successful completion of and the result of the dry run.
      Throws:
      IOException
      NedException
    • prepareDryUnsupportedResponse

      public void prepareDryUnsupportedResponse() throws IOException, NedException
      This method should be invoked by a NedConnection instance when a prepare dry operation is invoked and the NED is not able to support such an operation.
      Throws:
      IOException
      NedException
    • revertResponse

      public void revertResponse() throws IOException, NedException
      This method should be invoked by a NedConnection instance when it has completed a revert operation to indicate a successful completion of the revert.
      Throws:
      IOException
      NedException
    • showCliResponse

      public void showCliResponse(String config) throws IOException, NedException
      This method is invoked by a NedCli instance in response to a show method invocation. The config string should consist the relevant parts of the output from issuing the equivalent of 'show running-config' in a Cisco like CLI. The output must correspond to the data model provided in the capabilities sent as a response to the (re)connect request.
      Parameters:
      config -
      Throws:
      IOException
      NedException
    • showCliResponse

      public void showCliResponse(ArrayList<String> l) throws IOException, NedException
      Throws:
      IOException
      NedException
    • showGenericResponse

      public void showGenericResponse() throws IOException, NedException
      This method is invoked by a NedGeneric when it has completed populating the transaction with the requested configuration sub-tree. It indicates that the operation was successful.
      Throws:
      IOException
      NedException
    • showStatsPathResponse

      public void showStatsPathResponse(NedTTL[] ttls) throws IOException, NedException
      This method is invoked during the showStatsPath() request to indicate that the NED has successfully populated the requested subtree.
      Parameters:
      ttls - an array of ttls for different paths. The NED may optionally provide different cache timeouts for different paths.
      Throws:
      IOException
      NedException
    • showStatsFilterResponse

      public void showStatsFilterResponse() throws IOException, NedException
      This method is invoked during the showStatsFilter() request to indicate that the NED has successfully populated the requested transaction.
      Throws:
      IOException
      NedException
    • abortResponse

      public void abortResponse() throws IOException, NedException
      This method is called by the NED to indicate that the abort method has been successfully completed. If the NED is unable to complete the abort the error method should be invoked instead.
      Throws:
      IOException
      NedException
    • persistResponse

      public void persistResponse() throws IOException, NedException
      This method is called by the NED to indicate that the persist method has been successfully completed. If the NED is unable to complete the persist the error method should be invoked instead.
      Throws:
      IOException
      NedException
    • commandResponse

      public void commandResponse() throws IOException, NedException
      This method is called by the NED to indicate that the command method has been successfully completed. If the NED is unable to complete the command the error method should be invoked instead.
      Throws:
      IOException
      NedException
    • commandResponse

      public void commandResponse(ConfXMLParam[] reply) throws IOException, NedException
      This method is called by the NED to indicate that the command method has been successfully completed when the NED also has a reply. If the NED is unable to complete the command the error method should be invoked instead.
      Parameters:
      reply - is the return value from executing the command
      Throws:
      IOException
      NedException
    • getCurrentPath

      public ConfPath getCurrentPath()
      This method returns the current path associated with the action being processed. This method only returns valid data when called during an action invokation.
      Returns:
      a ConfPath to the node which contains the action.
    • getFromTransactionId

      public int getFromTransactionId()
      This method returns an integer that represents the transaction we are going from. In the normal case this is normally just 'running', but not always. It's possible to use Maapi.attach() on this transaction Id. Maapi.attach(int,int,int) Some complicated NEDs may require to read data from the system the way it looked like before the current transaction arrived.
      Returns:
      a transaction integer.
    • getToTransactionId

      public int getToTransactionId()
      This method returns an integer that represents the transaction we are going to, i.e the proposed new system state. It's possible to use Maapi.attach() on this transaction Id. Maapi.attach(int,int,int) Some complicated NEDs may require to read data from the system the way it is going to look like once the current transaction is committed.
      Returns:
      a transaction integer.
    • getUsid

      public int getUsid()
      This method returns an integer that represents the user session that initiated this NedWorker. If we wish to do Maapi.attach() to any of the from/to transactions we need the user session id
      Returns:
      a user session id
    • getNedId

      public String getNedId()
      This method returns the ned-id for the ned associated with this worker.
      Returns:
      the ned-id of the ned associated with this worker
    • getRemoteUser

      public String getRemoteUser()
      This method returns the backend user name as defined in the auth map.
      Returns:
      name of user to connect to backend as
    • getPassword

      public String getPassword()
      This method returns the backend password as defined in the auth map.
      Returns:
      password to connect to backend with
    • getSecondaryPassword

      public String getSecondaryPassword()
      This method returns the backend secondary password as defined in the auth map.
      Returns:
      secondary password to connect to backend with
    • getKeyDir

      public String getKeyDir()
      This method returns the ssh public key directory as defined in the auth map.
      Returns:
      null or a directory containing ssh public keys
    • getLoadOp

      public int getLoadOp()
      This method returns the load operation that should be used when populating the transaction in any of the show methods.
    • getTransIdResponse

      public void getTransIdResponse(String id) throws IOException, NedException
      This method is called by the NED to send a response to the getTransId request. If the NED is unable to complete the command the error method should be invoked instead.
      Parameters:
      id - is a string representing a transaction id
      Throws:
      IOException
      NedException
    • isAliveResponse

      public void isAliveResponse(boolean alive) throws IOException, NedException
      Throws:
      IOException
      NedException
    • getSourceAddress

      public InetSocketAddress getSourceAddress()
      This method returns the source IP address if such an address is configured in the ncs configuration. If not configured this method returns null.
      Returns:
      the source IP address or null if not configured
    • initializeResponse

      public void initializeResponse(String id) throws IOException, NedException
      This method is called by the NED to send a response to the initialize request. If the NED is unable to complete the command the error method should be invoked instead.
      Parameters:
      id - is a string representing a transaction id
      Throws:
      IOException
      NedException
    • uninitializeResponse

      public void uninitializeResponse() throws IOException, NedException
      This method should be invoked by a NedConnection instance when it has completed a uninitialize operation to indicate a successful uninitialization
      Throws:
      IOException
      NedException
    • createSubscriptionResponse

      public void createSubscriptionResponse() throws IOException, NedException
      This method is invoked by a NedConnection instance when it has completed to create a notification subsription. If the NED is unable to create the subscription the error method should be invoked instead.
      Throws:
      IOException
      NedException
    • notification

      public void notification(String data)
      Send notification to NCS once subsciption has been created.
      Parameters:
      data -
    • isSuppressTransId

      public boolean isSuppressTransId()
      The initialize call can request the trans_id response to be suppressed. This method must be called to check if that is the case.
    • isVerbose

      public boolean isVerbose()
      This method helps NED determine whether an action has been invoked with the verbose parameter. If an action has been invoked with the verbose parameter, then the NED may choose to report additional information using setAdditionalInfo(String).
    • setProvisionalTransId

      public void setProvisionalTransId(String id)
      This method allows the NED to set transaction ID provisionally from NedCliBase.show(NedWorker, String) or NedGenericBase.show(NedWorker, int) NED callback. If NSO needs to fetch the transaction ID immediately after the show() callback, it will first check whether the show() callback has indicated any provisional transaction ID and in such case use this value. If no provisional transaction ID has been supplied, then NSO will call getTransId() as needed. If a CLI NED has multiple top tags, then show() callback may be called multiple times as a part of single operation. In such case the NSO will only use the provisional transaction ID if show() has been called on all top tags as a part of such logical operation, and the last provisional transaction ID set by the NED will be used.
    • currentCommand

      public NedCmd currentCommand()
    • error

      public void error(int op, String reason)
      This function should be called when a callback like abort,persist, etc cannot be completed.
      Parameters:
      op - is the command originally issued from NCS, ie a NedCmd.getCommand() integer like NedCmd.CONNECT_CLI, NedCmd.CONNECT_GENERIC, NedCmd.PREPARE_CLI, ...
      reason - is the reason for the error
    • error

      public void error(int op, String error, String reason)
      This error report function is kept for backward compatible reasons and should if possible be avoided. The "error" string parameter is expected to be the string representation of on of the NedErrorCode values. If this is not the case this function will fallback to NED_EXTERNAL_ERROR code and concatenate the original error string together with the reason.
      Parameters:
      op - is the command originally issued from NCS, ie a NedCmd.getCommand() integer like NedCmd.CONNECT_CLI, NedCmd.CONNECT_GENERIC, NedCmd.PREPARE_CLI, ...
      error - string representation of a NedErrorCode
      reason - textual description of the reason for the error
    • error

      public void error(int op, NedErrorCode errCode, String reason)
      This function should be called when a callback like abort,persist, etc cannot be completed.
      Parameters:
      op - is the command originally issued from NCS, ie a NedCmd.getCommand() integer like NedCmd.CONNECT_CLI, NedCmd.CONNECT_GENERIC, NedCmd.PREPARE_CLI, ...
      errCode - NedErrorCode for the error
      reason - textual description of the reason for the error
    • connectError

      public void connectError(NedErrorCode code) throws NedException
      Throws:
      NedException
    • connectError

      public void connectError(NedErrorCode code, String info) throws NedException
      This method should be invoked if the NED fails to perform the connect() operation.
      Parameters:
      code - is the reason for the connect to fail. See NedErrorCode.CONNECT_CONNECTION_REFUSED, NedErrorCode.CONNECT_TIMEOUT, etc.
      info - is a string describing the connect error. Normally this parameter is not needed. If it is given, it will be appended to the error message all the way to the northbound agent invoking the NED connect call
      Throws:
      NedException
    • connectError

      @Deprecated public void connectError(int intCode) throws NedException
      Deprecated.
      Use the method connectError(NedErrorCode) instead
      Throws:
      NedException
    • connectError

      @Deprecated public void connectError(int intCode, String info) throws NedException
      Deprecated.
      Use the method connectError(NedErrorCode, String) instead
      Throws:
      NedException