Package com.tailf.ned
Class NedWorker
The NedWorker is used by the NedMux for running a worker thread
for executing NedConnection tasks.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static class
static enum
Indicates the mode of Transaction ID supported by the NED.Nested classes/interfaces inherited from class java.lang.Thread
Thread.State, Thread.UncaughtExceptionHandler
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Deprecated.static final int
Deprecated.UseNedErrorCode.CONNECT_BADKEY
instead.static final int
Deprecated.UseNedErrorCode.CONNECT_BADAUTH
instead.static final int
Deprecated.UseNedErrorCode.CONNECT_CONNECTION_REFUSED
instead.static final int
Deprecated.UseNedErrorCode.CONNECT_HOST_KEY_REJECTED
instead.static final int
Deprecated.UseNedErrorCode.CONNECT_HOSTUNREACH
instead.static final int
Deprecated.UseNedErrorCode.CONNECT_TIMEOUT
instead.Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
This method is called by the NED to indicate that the abort method has been successfully completed.void
This method is called by the NED to indicate that the command method has been successfully completed.void
commandResponse
(ConfXMLParam[] reply) This method is called by the NED to indicate that the command method has been successfully completed when the NED also has a reply.void
This method should be invoked by a NedConnection instance when it has completed a commit operation to indicate a successful completion of the commit.void
connectError
(int intCode) Deprecated.Use the methodconnectError(NedErrorCode)
insteadvoid
connectError
(int intCode, String info) Deprecated.Use the methodconnectError(NedErrorCode, String)
insteadvoid
connectError
(NedErrorCode code) void
connectError
(NedErrorCode code, String info) This method should be invoked if the NED fails to perform the connect() operation.void
This method is invoked by a NedConnection instance when it has completed to create a notification subsription.void
error
(int op, NedErrorCode errCode, String reason) This function should be called when a callback like abort,persist, etc cannot be completed.void
This function should be called when a callback like abort,persist, etc cannot be completed.void
This error report function is kept for backward compatible reasons and should if possible be avoided.This method returns the current path associated with the action being processed.Get the phase of the device.int
This method returns an integer that represents the transaction we are going from.This method returns the ssh public key directory as defined in the auth map.int
This method returns the load operation that should be used when populating the transaction in any of the show methods.getNedId()
This method returns the ned-id for the ned associated with this worker.This method returns the backend password as defined in the auth map.This method returns the backend user name as defined in the auth map.This method returns the backend secondary password as defined in the auth map.This method returns the source IP address if such an address is configured in the ncs configuration.int
This method returns an integer that represents the transaction we are going to, i.e the proposed new system state.void
This method is called by the NED to send a response to the getTransId request.int
getUsid()
This method returns an integer that represents the user session that initiated this NedWorker.void
This method is called by the NED to send a response to the initialize request.void
isAliveResponse
(boolean alive) boolean
The initialize call can request the trans_id response to be suppressed.boolean
This method helps NED determine whether an action has been invoked with the verbose parameter.void
Send log messages to NCS.void
notification
(String data) Send notification to NCS once subsciption has been created.void
This method is called by the NED to indicate that the persist method has been successfully completed.void
prepareDryResponse
(String output) 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.void
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.void
This method should be invoked by a NedConnection instance when it has completed a prepare operation to indicate a successful completion of the prepare.void
This method should be invoked by a NedConnection instance when it has completed a revert operation to indicate a successful completion of the revert.void
run()
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.void
This method allows the NED to set transaction ID provisionally fromNedCliBase.show(NedWorker, String)
orNedGenericBase.show(NedWorker, int)
NED callback.void
setTimeout
(int ms) When the NED worker gets invoked, it gets passed three timeout values, connect/read/write timeouts.void
showCliResponse
(String config) This method is invoked by a NedCli instance in response to a show method invocation.void
void
This method is invoked by a NedGeneric when it has completed populating the transaction with the requested configuration sub-tree.void
This method is invoked during the showStatsFilter() request to indicate that the NED has successfully populated the requested transaction.void
showStatsPathResponse
(NedTTL[] ttls) This method is invoked during the showStatsPath() request to indicate that the NED has successfully populated the requested subtree.void
Send trace message to the NCS.void
This method should be invoked by a NedConnection instance when it has completed a uninitialize operation to indicate a successful uninitializationMethods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
Field Details
-
CONNECT_CONNECTION_REFUSED
Deprecated.UseNedErrorCode.CONNECT_CONNECTION_REFUSED
instead.- See Also:
-
CONNECT_TIMEOUT
Deprecated.UseNedErrorCode.CONNECT_TIMEOUT
instead.- See Also:
-
CONNECT_BADPASS
Deprecated.UseNedErrorCode.CONNECT_BADAUTH
instead.- See Also:
-
CONNECT_BADKEY
Deprecated.UseNedErrorCode.CONNECT_BADKEY
instead.- See Also:
-
CONNECT_HOSTUNREACH
Deprecated.UseNedErrorCode.CONNECT_HOSTUNREACH
instead.- See Also:
-
CONNECT_HOST_KEY_REJECTED
Deprecated.UseNedErrorCode.CONNECT_HOST_KEY_REJECTED
instead.- See Also:
-
CONNECT_BADAUTH
Deprecated.UseNedErrorCode.CONNECT_BADAUTH
instead.- See Also:
-
-
Constructor Details
-
NedWorker
-
-
Method Details
-
log
Send log messages to NCS. The log messages will end up at... FIXME- Parameters:
msg
-- Throws:
Exception
-
trace
Send trace message to the NCS. The message will end up at... FIXME -
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
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
Get the phase of the device. -
run
public void run() -
commitResponse
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
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
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
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
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
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
- Throws:
IOException
NedException
-
showGenericResponse
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
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
This method is invoked during the showStatsFilter() request to indicate that the NED has successfully populated the requested transaction.- Throws:
IOException
NedException
-
abortResponse
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
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
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
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
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
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
This method returns the backend user name as defined in the auth map.- Returns:
- name of user to connect to backend as
-
getPassword
This method returns the backend password as defined in the auth map.- Returns:
- password to connect to backend with
-
getSecondaryPassword
This method returns the backend secondary password as defined in the auth map.- Returns:
- secondary password to connect to backend with
-
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
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
- Throws:
IOException
NedException
-
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
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
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
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
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 usingsetAdditionalInfo(String)
. -
setProvisionalTransId
This method allows the NED to set transaction ID provisionally fromNedCliBase.show(NedWorker, String)
orNedGenericBase.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
-
error
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
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 NedErrorCodereason
- textual description of the reason for the error
-
error
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 errorreason
- textual description of the reason for the error
-
connectError
- Throws:
NedException
-
connectError
This method should be invoked if the NED fails to perform the connect() operation.- Parameters:
code
- is the reason for the connect to fail. SeeNedErrorCode.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.Use the methodconnectError(NedErrorCode)
instead- Throws:
NedException
-
connectError
Deprecated.Use the methodconnectError(NedErrorCode, String)
instead- Throws:
NedException
-
NedErrorCode.CONNECT_BADAUTH
instead.