public class Maapi extends Object
This class implements the Management Agent API (MAAPI).
The purpose of the class is twofold:
Maapi can be used to implement our own proprietary management agent.
This class implements the Management Agent API (MAAPI).
The purpose of the class is twofold:
MAAPI can be used to implement our own proprietary management agent.
Example:
// Setup socket to server Socket s = new Socket("localhost",Conf.CONF_PORT); // Start MAAPI session for admin user, originating from localhost Maapi maapi = new Maapi(s); maapi.startUserSession("admin", InetAddress.getByName("localhost"), "maapi", new String[] { "admin" }, MaapiUserSessionFlag.PROTO_TCP); // Start a read transaction towards the running configuration. int th = maapi.startTrans(Conf.DB_RUNNING, Conf.MODE_READ); // Set the namespace for the upcoming data operations maapi.setNamespace(th, "http://tail-f.com/test/mtest/1.0"); // Read the maxLeaseTime setting in the running configuration. ConfObject r = maapi.getElem(th, "/mtest/servers/server{www}/ip"); // Done, the transaction and user session is automatically // ended when the socket is closed. s.close();
Modifier and Type | Field and Description |
---|---|
static int |
CANDIDATE_COMMIT_NO_COMMIT_QUEUE |
static int |
CANDIDATE_COMMIT_NO_DEVICE_MGR |
static int |
CANDIDATE_COMMIT_NO_REVISION_DROP
DEPRECATED - use COMMIT_NCS_* flags instead.
|
static int |
CANDIDATE_COMMIT_USE_COMMIT_QUEUE |
static int |
COMMIT_NCS_ASYNC_COMMIT_QUEUE |
static int |
COMMIT_NCS_BYPASS_COMMIT_QUEUE |
static int |
COMMIT_NCS_NO_FASTMAP |
static int |
COMMIT_NCS_NO_NETWORKING |
static int |
COMMIT_NCS_NO_OUT_OF_SYNC_CHECK |
static int |
COMMIT_NCS_NO_OVERWRITE |
static int |
COMMIT_NCS_NO_REVISION_DROP
|
static int |
COMMIT_NCS_SYNC_COMMIT_QUEUE |
static int |
COMMIT_NCS_THROUGH_COMMIT_QUEUE |
static int |
COMMIT_NO_COMMIT_QUEUE |
static int |
COMMIT_NO_DEVICE_MGR |
static int |
COMMIT_NO_REVISION_DROP
DEPRECATED - use COMMIT_NCS_* flags instead.
|
static int |
COMMIT_USE_COMMIT_QUEUE |
static int |
IA_CLIENT_MAAPI |
static int |
MAAPI_UPGRADE_KILL_ON_TIMEOUT
Flag to use in initUpgrade()
|
Constructor and Description |
---|
Maapi(Socket socket)
Creates a new instance of
Maapi supplying a established
open socket to ConfD/NCS daemon. |
Modifier and Type | Method and Description |
---|---|
void |
aaaReload(boolean synchronous)
When the ConfD/NCS AAA tree is populated by an external data provider,
this method can be used by the data provider to notify ConfD/NCS when
there is a change to the AAA data.
|
void |
abortTrans(int tid)
Abort a transaction specified by transaction handle tid.
|
void |
abortUpgrade()
Note, This method is only applicable for Confd.
|
void |
applyTrans(int tid,
boolean keepOpen)
Apply a current transaction with transaction handle tid.
|
void |
applyTrans(int tid,
boolean keepOpen,
int flags)
Apply a current transaction with transaction handle tid
with additional flags (NCS Specific).
|
void |
attach(int tid,
int nsi)
Same as
attach(int, int, int) with the exception
that the User session id is implicit for the attached transaction. |
void |
attach(int tid,
int nsi,
int usid)
Attach to a current transaction.
|
void |
attach(int tid,
String ns)
Same as
attach(int, String, int) with the exception
that the User session id is implicit for the attached transaction. |
void |
attach(int tid,
String ns,
int usid)
Attach to a current transaction.
|
int |
attachInit()
Attach to transaction available in phase0.
|
MaapiAuthentication |
authenticate(String user,
String passwd)
If we are implementing a proprietary Management Agent with MAAPI API, the
method
startUserSession(String,InetAddress,String,String[],
MaapiUserSessionFlag) requires the application to tell ConfD/NCS
which groups the user are member of. |
MaapiAuthentication |
authenticate2(String user,
String passwd,
InetAddress src_addr,
int src_port,
String context,
MaapiUserSessionFlag proto)
If we are implementing a proprietary Management Agent with MAAPI API, the
method
startUserSession(String,InetAddress,String,String[],
MaapiUserSessionFlag) requires the application to tell ConfD/NCS
which groups the user are member of. |
void |
candidateAbortCommit()
This function cancels a pending confirmed commit.
|
void |
candidateAbortCommitPersistent(String persistId)
Cancel an ongoing persistent commit with the cookie given by persistId.
|
void |
candidateCommit() |
void |
candidateCommit(int flags)
This function copies the candidate to running.
|
void |
candidateCommitInfo(String label,
String comment)
This method can be used to set the "Label" and/or "Comment"
that is stored in the rollback file when the candidate is committed
to running.
|
void |
candidateCommitInfo(String persistId,
String label,
String comment)
This method can be used to set the "Label" and/or "Comment"
that is stored in the rollback file when the candidate is committed
to running.
|
void |
candidateCommitPersistent(String persistId)
Confirm an ongoing persistent commit with the cookie given by persistId.
|
void |
candidateCommitPersistent(String persistId,
int flags) |
void |
candidateConfirmedCommit(int t)
This method also copies the candidate into running.
|
void |
candidateConfirmedCommitInfo(int timeoutsecs,
String label,
String comment)
This method does the same as
candidateConfirmedCommitPersistent(int, java.lang.String, java.lang.String) , but allows for
setting the "Label" and/or "Comment" that is stored in the
rollback file when the candidate is committed to running. |
void |
candidateConfirmedCommitInfo(int timeoutsecs,
String persist,
String persistId,
String label,
String comment)
This method does the same as
candidateConfirmedCommitPersistent(int, java.lang.String, java.lang.String) , but allows for
setting the "Label" and/or "Comment" that is stored in the
rollback file when the candidate is committed to running. |
void |
candidateConfirmedCommitPersistent(int timeoutsecs,
String persist,
String persistId) |
void |
candidateConfirmedCommitPersistent(int timeoutsecs,
String persist,
String persistId,
int flags)
This method can be used to start or extend a persistent confirmed
commit, see the Tail-f Commit Capability section in the NETCONF Server
chapter in the User Guide.
|
void |
candidateReset()
This function copies running into candidate.
|
void |
candidateValidate()
This function validates the candidate.
|
void |
cd(int tid,
String fmt,
Object... arguments)
This function mimics the behavior of the UNIX "cd" command.
|
void |
clearOpCache()
Same as
clearOpCache(ConfPath) , with the only difference that
if clears all cached data from "/" and down. |
void |
clearOpCache(ConfPath path)
Request clearing of the operational data cache (see the Operational Data
the User Guide).
|
String |
CLIPrompt(int usid,
String prompt,
boolean echo)
Prompts user for a string.
|
String |
CLIPrompt(int usid,
String prompt,
boolean echo,
int timeout)
Prompts user for a string.
|
String |
CLIPromptOneOf(int usid,
String prompt,
String[] choice)
Prompt user for one of the strings given in the choice parameter.
|
String |
CLIPromptOneOf(int usid,
String prompt,
String[] choice,
int timeout)
Prompt user for one of the strings given in the choice parameter.
|
String |
CLIReadEOF(int usid,
boolean echo)
Read a multi line string from the CLI.
|
String |
CLIReadEOF(int usid,
boolean echo,
int timeout)
Read a multi line string from the CLI.
|
void |
CLIWrite(int usid,
String buf)
Write to the CLI.
|
CommitQueueResult |
commitQueueResult(int tid,
int timeout)
This method must be called if applyTrans() or prepareTrans() was
called, and one of the flags COMMIT_NCS_ASYNC_COMMIT_QUEUE or
COMMIT_NCS_SYNC_COMMIT_QUEUE was set, and must not be called
otherwise.
|
void |
commitTrans(int tid)
Commit a transaction specified by transaction handle tid.
|
void |
commitUpgrade()
Note, This method is only applicable for Confd.
|
int |
confirmedCommitInProgress()
Checks whether a confirmed commit is pending.
|
void |
copy_tree(int tid,
boolean useSharedCreate,
ConfPath from,
ConfPath to)
This function is used to copy an entire subtree in the configuration from
one point to another.
|
void |
copy_tree(int tid,
ConfPath from,
ConfPath to) |
void |
copy(int thfrom,
int thto)
If we open two transactions from the same user sessions but towards
different data stores, such as one transaction towards the candidate and
one towards running, we can copy all data from one data store to the
other with this method.
|
void |
copyRunningToStartup()
Copies running to startup.
|
void |
create(int tid,
ConfPath path)
Create an entity in the XML tree.
|
void |
create(int tid,
String fmt,
Object... arguments)
Create a new list entry in the XML tree.
|
void |
delete(int tid,
ConfPath path)
Deletes a node and all its children from the XML data tree.
|
void |
delete(int tid,
String fmt,
Object... arguments)
Deletes a node and all its children from the XML data tree.
|
void |
deleteConfig(int db)
This function empties a data store.
|
ConfObject[][] |
deref(int tid,
String fmt,
Object... arguments)
This method dereferences a leafref and returns a list of the objects the
leafref "points" to.
|
void |
detach(int tid)
Detaches an attached MAAPI socket.
|
void |
diffIterate(int tid,
MaapiDiffIterate iter)
Iterates through the transaction diff.
|
void |
diffIterate(int tid,
MaapiDiffIterate iter,
Object initstate,
String fmt,
Object... args)
Iterates through the transaction diff.
|
void |
diffIterate(int tid,
MaapiDiffIterate iter,
String fmt,
Object... args)
Iterates through the transaction diff.
|
void |
diffIterate(int tid,
Object initstate,
EnumSet<DiffIterateFlags> flags,
MaapiDiffIterate iter,
ConfPath path)
Iterates through the transaction diff.
|
void |
disconnectRemote(String address)
Disconnect all remote connections between CONFD_IPC_PORT (see the IPC
section in the Advanced Topics chapter in the User Guide) and address.
|
boolean |
doDisplay(int tid,
String fmt,
Object... args)
If the data model uses the YANG 'when' or 'tailf:display-when'
statement, this function can be used to determine if the item
given by the path in fmt should be displayed or not.
|
void |
endUserSession()
Ends the current user session on this
Maapi instance. |
boolean |
exists(int tid,
ConfPath path)
Boolean function which return 1 or 0 if a path defines an existing
element in the XML data tree.
|
boolean |
exists(int tid,
String fmt,
Object... arguments) |
ConfKey |
findNext(MaapiCursor c,
ConfFindNextType type,
ConfKey key)
The findNext method makes it possible to jump forward to an element
in the model at a position defined by the MaapiCursor
After the findNext call the same MaapiCursor can be used in subsequent
getNext calls.
|
void |
finishTrans(int tid)
Finish the transaction specified by transaction handle tid.
|
ConfAttributeValue[] |
getAttrs(int tid,
ConfAttributeType[] attribs,
String fmt,
Object... args)
Retrieve attributes for a configuration node.
|
static ArrayList<ConfNamespace> |
getAutoNsList() |
static ArrayList<ConfNamespace> |
getAutoNsList(ArrayList<ConfNamespace> defaultNsList) |
ConfTag |
getCase(int tid,
String choice,
ConfPath path) |
ConfTag |
getCase(int tid,
String choice,
String fmt,
Object... arguments)
This returns the current 'case' for a 'choice' construct.
|
CLIInteraction |
getCLIInteraction(int usid)
Get CLIInteraction object which enables communication with the user via
the CLI.
|
String |
getCwd(int tid)
Returns the current position as previously set by Maapi.cd(),
Maapi.pushd(), or Maapi.popd() as a String.
|
ConfPath |
getCwdPath(int tid)
Returns the current position like Maapi.getCwd(), but as a ConfPath
instead of as a String.
|
ConfValue |
getElem(int tid,
ConfPath path) |
ConfValue |
getElem(int tid,
String fmt,
Object... arguments)
This reads a value from the path in fmt and returns the result.
|
int |
getMyUserSession()
Returns the usid associated with this
Maapi |
ConfKey |
getNext(MaapiCursor c)
Iterates and gets the keys for the next element pinpointed by the
MaapiCursor initially retrieved by
newCursor(int, String, Object...) . |
ArrayList<ConfNamespace> |
getNsList()
Get a list of the installed namespaces retrieved from the loaded
MaapiSchemas . |
int |
getNumberOfInstances(int tid,
ConfPath path) |
int |
getNumberOfInstances(int tid,
String fmt,
Object... arguments)
Return the number of instances in a list.
|
ConfObject[] |
getObject(int tid,
String fmt,
Object... arguments)
This reads a container object or a list entry object from the path in fmt
and returns the result.
|
List<ConfObject[]> |
getObjects(MaapiCursor c,
int numOfObjects,
int numOfInstances)
Get several list instances with one request.
|
int |
getRunningDbStatus()
Query ConfD/NCS for its consistency state.
|
static MaapiSchemas |
getSchemas()
Returns the currently loaded schema.
|
Socket |
getSocket() |
MaapiUserSession |
getUserSession(int usid)
Return a
MaapiUserSession given by the usid . |
int[] |
getUserSessions()
Return all user sessions id's currently connected to ConfD/NCS.
|
<T extends ConfXMLParam> |
getValues(int th,
T[] params,
ConfPath path)
Read an arbitrary set of sub-elements of a container element.
|
<T extends ConfXMLParam> |
getValues(int th,
T[] params,
String fmt,
Object... arguments)
Read an arbitrary set of sub-elements of a container element.
|
<T extends List<ConfXMLParam>> |
getValues(int th,
T params,
ConfPath path)
Read an arbitrary set of sub-elements of a container element.
|
<T extends List<ConfXMLParam>> |
getValues(int th,
T params,
String fmt,
Object... arguments)
Read an arbitrary set of sub-elements of a container element.
|
void |
initUpgrade(int timeoutsecs,
int flags)
Note, This method is only applicable for Confd.
|
void |
insert(int tid,
boolean createBackPointer,
String fmt,
Object... arguments)
This function inserts a new element in an ordered list of elements.
|
void |
insert(int tid,
String fmt,
Object... arguments) |
boolean |
isCandidateModified()
Returns true if candidate has been modified, i.e if there are pending non
committed changes to the candidate data store.
|
int |
isLockSet(int db)
This methods checks if a lock is taken or not.
|
boolean |
isRunningModified()
Returns true if running has been modified since the last copy to startup,
false if it has not been modified.
|
void |
iterate(int tid,
Object initstate,
EnumSet<ConfIterateFlags> flags,
MaapiIterate iter,
ConfPath path)
Iterates through all the data in a transaction.
|
void |
killUserSession(int usid)
Ends another users session, effectively logging out that user.
|
MaapiRollback[] |
listRollback()
Get list of available rollback files.
|
void |
loadConfig(int tid,
EnumSet<MaapiConfigFlag> flags,
String filename)
This function loads a configuration from filename into the server.
|
void |
loadConfigCmds(int tid,
EnumSet<MaapiConfigFlag> flags,
String cmds,
String fmt,
Object... arguments)
This function loads a configuration from a string into the server.
|
MaapiOutputStream |
loadConfigStream(int tid,
EnumSet<MaapiConfigFlag> flags)
Load configuration from a
OuputStream into ConfD/NCS. |
void |
loadRollback(int tid,
int nr)
Load rollback file into a given transaction.
|
MaapiSchemas |
loadSchemas()
Load Schemas method that downloads all schemas from server into a
MaapiSchemas container, from which specified schemas can be accessed and
traversed.
|
MaapiSchemas |
loadSchemas(String[] namespaceURIs)
Load Schemas method that downloads a specified number of schemas
the server into a MaapiSchemas container, from which specified schemas
can be accessed and transversed.
|
void |
lock(int db)
This function is used to take a lock on one of the databases.
|
int |
lockPartial(int db,
String xpath)
Same as
lockPartial(int,String[]) except only one xpath
expression is given. |
int |
lockPartial(int db,
String[] xpaths)
It is possible to manipulate partial locks on the databases, i.e.
|
void |
move(int tid,
ConfKey tokey,
String fmt,
Object... arguments)
This function moves an existing object.
|
void |
move(int tid,
String tokey,
String fmt,
Object... arguments)
This function moves an existing object
|
void |
moveOrdered(int tid,
MoveWhereFlag where,
ConfKey tokey,
String fmt,
Object... arguments)
For a list with the YANG ordered-by user statement, this function can be
used to change the order of entries, by moving one entry to a new
position.
|
void |
ncsApplyTemplate(int tid,
String template,
ConfPath rootIKP,
Properties variables,
boolean createShared,
boolean createBackpointer) |
void |
ncsApplyTemplate(int tid,
String template,
ConfPath rootIKP,
Properties variables,
String document,
boolean createShared,
boolean createBackpointer) |
String[] |
ncsGetTemplateVariables(String template) |
void |
ncsMovePrivateData(int initTid,
ConfPath from,
ConfPath to)
Used in service data migrations, after config data has been moved in
the data upgrade, also the service ncs specific private data has to be
moved.
|
Set<String> |
ncsTemplates() |
MaapiCursor |
newCursor(int tid,
ConfPath path)
Creates a cursor for an list specified by
fmt |
MaapiCursor |
newCursor(int tid,
String fmt,
Object... arguments)
Creates a cursor for an list specified by
fmt |
void |
performUpgrade(String[] loadpathdirs)
Note, This method is only applicable for Confd.
|
void |
popd(int tid)
Pops the top position of the directory stack and changes directory
|
void |
prepareTrans(int tid)
Prepares the transaction specified by transaction handle tid.
|
void |
prepareTrans(int tid,
int flags)
Prepares the transaction specified by transaction handle tid.
|
void |
prioMessage(String to,
String message)
Send a high priority message to a specific user, a specific user session
or all users depending on the to parameter.
|
void |
pushd(int tid,
String fmt,
Object... arguments)
Behaves like cd() with the exception that we can subsequently call popd()
and return to the previous position in the XML data tree.
|
<T extends ResultType> |
queryStart(int th,
String expr,
String context,
int chunkSize,
int offset,
List<String> select,
Class<T> cls)
Initiate (or starts) a new XPath query attached to the
transaction given in
th . |
<T extends ResultType> |
queryStart(int th,
String expr,
String context,
int chunkSize,
int offset,
List<String> select,
List<String> sort,
boolean reverseSortOrder,
Class<T> cls)
Initiate (or starts) a new XPath query attached to the
transaction given in
th . |
void |
reloadConfig()
Request that the daemon reloads its configuration files.
|
MaapiSchemas |
reloadSchemas()
This method throws away any old MaapiSchemas container and downloads a
new from the server.
|
MaapiSchemas |
reloadSchemas(String[] namespaceURIs)
This method throws away any old MaapiSchemas container and downloads a
new from the server.
|
ConfXMLParam[] |
requestAction(ConfXMLParam[] params,
int nshash,
String fmt,
Object... arguments)
Same as
requestAction(ConfXMLParam[], String, Object...)
Since actions are not associated with transactions, the
namespace hash nshash must be provided and the path
to the action, i.e. |
ConfXMLParam[] |
requestAction(ConfXMLParam[] params,
String fmt,
Object... arguments)
Invokes an action defined in the data model annotated with
tailf:action (see tailf_yang_extensions(5)). |
ConfXMLParam[] |
requestAction(List<ConfXMLParam> params,
int nshash,
String fmt,
Object... arguments) |
ConfXMLParam[] |
requestAction(List<ConfXMLParam> params,
String fmt,
Object... arguments)
Same as
requestAction(ConfXMLParam[], String, Object...)
with the difference that the params is List
instead of ConfXMLParam array. |
ConfXMLParam[] |
requestActionTh(int tid,
ConfXMLParam[] params,
String fmt,
Object... arguments)
Same as
requestAction(ConfXMLParam[], String, Object...)
with the difference that the fmt is not required to have a namespace
prefix in the root tag. |
ConfXMLParam[] |
requestActionTh(int tid,
List<ConfXMLParam> params,
String fmt,
Object... arguments) |
void |
revert(int tid)
Remove all changes in the transaction.
|
MaapiInputStream |
rollbackConfig(int tid,
String fmt,
String... args)
This function can be used to save the equivalent of a rollback file for a
given configuration before it is committed (or a subtree thereof) in
curly bracket format.
|
void |
safeCreate(int tid,
ConfPath path)
Create a new list entity in the XML tree.
|
void |
safeCreate(int tid,
String fmt,
Object... arguments)
Create a new entity in the XML tree.
|
void |
safeDelete(int tid,
String fmt,
Object... arguments)
Deletes a node and all its children from the XML data tree.
|
ConfValue |
safeGetElem(int tid,
ConfPath path)
Reads a value from the
path specified |
ConfValue |
safeGetElem(int tid,
String fmt,
Object... arguments)
This reads a value from the path in fmt and returns the result.
|
ConfObject[] |
safeGetObject(int tid,
String fmt,
Object... arguments)
This is a variant of getObject() that returns null if the object doesn't
exist
|
MaapiInputStream |
saveConfig(int tid,
EnumSet<MaapiConfigFlag> flags)
Save the entire config in different formats.
|
MaapiInputStream |
saveConfig(int tid,
EnumSet<MaapiConfigFlag> flags,
ConfPath path)
Save the subtree in different formats.
|
MaapiInputStream |
saveConfig(int tid,
EnumSet<MaapiConfigFlag> flags,
String fmt,
Object... args)
Save the subtree in different formats, with ability to XPath Filtering.
|
void |
setAttr(int tid,
ConfAttributeValue attr,
String fmt,
Object... args)
Set an attribute for a configuration node.
|
void |
setComment(int tid,
String comment)
Set the "Comment" that is stored in the rollback file when a
transaction towards running is committed.
|
boolean |
setDelayedWhen(int th,
boolean on)
This function enables/disables the "delayed when" mode of a transaction.
|
void |
setElem(int tid,
ConfObject value,
ConfPath path)
Set value to a leaf node.
|
void |
setElem(int tid,
ConfObject value,
String fmt,
Object... arguments)
Set value to a leaf node.
|
void |
setElem(int tid,
String value,
ConfPath path)
Set value to a leaf node.
|
void |
setElem(int tid,
String value,
String fmt,
Object... arguments)
Set value to a leaf node.
|
void |
setFlags(int tid,
EnumSet<MaapiFlag> flags)
This method can modify some aspects of the read/write session, see
MaapiFlag The flags are an Enumset of
MaapiFlag |
void |
setLabel(int tid,
String label)
Set the "Label" that is stored in the rollback file when a
transaction towards running is committed.
|
void |
setNamespace(int tid,
int nsid) |
void |
setNamespace(int tid,
String ns)
Before can invoke any of read or write functions, we must indicate which
namespace we are going to use.
|
void |
setObject(int tid,
ConfObject[] values,
String fmt,
Object... arguments)
This writes a container object or a list entry object from the path in
fmt and returns the result.
|
void |
setReadOnlyMode(boolean flag)
Control if the node should accept write transactions
|
void |
setRunningDbStatus(int status)
Explicitly sets the systems notion of the consistency
state.
|
void |
setUserSession(int usid)
Associate this Maapi instance with an already existing user session.
|
void |
setValues(int th,
ConfXMLParam[] params,
ConfPath path)
Set arbitrary sub-elements of a container element in one bulk operation.
|
void |
setValues(int th,
ConfXMLParam[] params,
String fmt,
Object... arguments)
Set arbitrary sub-elements of a container element in one bulk operation.
|
void |
setValues(int th,
List<ConfXMLParam> params,
ConfPath path)
Set arbitrary sub-elements of a container element in one bulk operation.
|
void |
setValues(int th,
List<ConfXMLParam> params,
String fmt,
Object... arguments)
Set arbitrary sub-elements of a container element in one bulk operation.
|
void |
sharedCreate(int tid,
boolean createBackpointer,
ConfPath path)
This is the variant of create() to use from FASTMAP code.
|
void |
sharedCreate(int tid,
ConfPath path) |
void |
sharedCreate(int tid,
String fmt,
Object... arguments) |
void |
sharedSetElem(int tid,
ConfObject value,
ConfPath path)
Set value to a leaf node from NCS FastMap code.
|
void |
sharedSetElem(int tid,
ConfObject value,
String fmt,
Object... arguments)
Set value to a leaf node from NCS FastMap code
This method is the equivalent of setElem() except that it
can only be called from NCS FastMap service code.
|
void |
sharedSetElem(int tid,
String value,
String fmt,
Object... arguments)
Set value to a leaf node from NCS FastMap code.
|
void |
sharedSetValues(int th,
ConfXMLParam[] params,
boolean createBackpointer,
ConfPath path)
Set arbitrary sub-elements of a container element in one bulk operation
from NCS FastMap code.
|
void |
sharedSetValues(int th,
ConfXMLParam[] params,
ConfPath path)
Set arbitrary sub-elements of a container element in one bulk operation
from NCS FastMap code.
|
void |
sharedSetValues(int th,
ConfXMLParam[] params,
String fmt,
Object... arguments)
Set arbitrary sub-elements of a container element in one bulk operation
from NCS FastMap code.
|
void |
sharedSetValues(int th,
List<ConfXMLParam> params,
ConfPath path)
Set arbitrary sub-elements of a container element in one bulk operation
from NCS FastMap code.
|
void |
sharedSetValues(int th,
List<ConfXMLParam> params,
String fmt,
Object... arguments)
Set arbitrary sub-elements of a container element in one bulk operation
from NCS FastMap code.
|
void |
snmpSendNotification(String notifName,
String notifyTarget,
String ctxName,
SnmpVarbind[] varbinds)
Send SNMP notification.
|
void |
startPhase(int phase)
Once the ConfD/NCS daemon has been started in phase0 it is possible to
use this function to tell the daemon to proceed to startPhase 1 or 2.
|
void |
startPhase(int phase,
boolean synchronous)
Once the ConfD/NCS daemon has been started in phase0 it is possible to
use this function to tell the daemon to proceed to start phase 1 or 2.
|
int |
startTrans(int dbname,
int mode)
Start a new transaction towards the specified database
dbname with a transaction mode mode . |
int |
startTrans(int dbname,
int mode,
String vendor,
String product,
String version,
String clientId) |
int |
startTrans2(int dbname,
int mode,
int usid)
Start a new transaction towards database within an existing
user session specified by
usid . |
int |
startTransFlags(int dbname,
int mode,
int usid,
EnumSet<MaapiFlag> flags)
Start a new transaction towards the specified database
dbname with a transaction mode mode with
additional flags to control read/write sessions. |
int |
startTransInTrans(int mode,
int usid,
int th)
Start a new transaction within an existing user session and another
transaction as backend
|
void |
startUserSession(String user,
InetAddress srcip,
String context,
String[] groups,
MaapiUserSessionFlag proto)
Establish a new user session on this
Maapi instance. |
void |
startUserSession(String user,
InetAddress srcip,
String context,
String[] groups,
MaapiUserSessionFlag proto,
String vendor,
String product,
String version,
String clientId) |
void |
stop()
Requests that the daemon stops, returns when daemon has stopped.
|
void |
stop(boolean synchronous)
Stops the daemon.
|
void |
sysMessage(String to,
String message)
Send a message to a specific user, a specific user session or all users
depending on the to parameter.
|
String |
toString() |
void |
unlock(int db)
This function releases a lock previously acquired using the lock()
method.
|
void |
unlockPartial(int lockId)
This methods releases a lock previously acquired using the lockPartial()
method.
|
void |
userMessage(String to,
String message,
String sender)
Send a message to a specific user, a specific user session or all users
depending on the to parameter.
|
void |
validateTrans(int tid,
boolean unlock,
boolean force)
Validates a transaction specified by transaction handle tid
|
void |
waitStart(int phase)
Wait until the daemon has completed a certain start phase.
|
void |
waitStarted()
Wait until the daemon is fully started, i.e.
|
ConfPath |
xpath2kpath(String xpath)
Convert a XPath path to a ConfPath object.
|
void |
xpathEval(int th,
MaapiXPathEvalResult xpatheval,
MaapiXPathEvalTrace xpathtrace,
String expr,
Object initstate,
String fmt,
Object... arguments)
Evaluated the xpath expression as supplied in by
expr . |
String |
xpathEvalExpr(int th,
String expr,
MaapiXPathEvalTrace xpathtrace,
String fmt,
Object... arg)
Evaluate the xpath expression given in
expr parameter
and return the result as a string. |
public static final int CANDIDATE_COMMIT_NO_COMMIT_QUEUE
public static final int CANDIDATE_COMMIT_NO_DEVICE_MGR
public static final int CANDIDATE_COMMIT_NO_REVISION_DROP
candidateCommit(int)
public static final int CANDIDATE_COMMIT_USE_COMMIT_QUEUE
public static final int COMMIT_NCS_ASYNC_COMMIT_QUEUE
public static final int COMMIT_NCS_BYPASS_COMMIT_QUEUE
public static final int COMMIT_NCS_NO_FASTMAP
public static final int COMMIT_NCS_NO_NETWORKING
public static final int COMMIT_NCS_NO_OUT_OF_SYNC_CHECK
public static final int COMMIT_NCS_NO_OVERWRITE
public static final int COMMIT_NCS_NO_REVISION_DROP
public static final int COMMIT_NCS_SYNC_COMMIT_QUEUE
public static final int COMMIT_NCS_THROUGH_COMMIT_QUEUE
public static final int COMMIT_NO_COMMIT_QUEUE
public static final int COMMIT_NO_DEVICE_MGR
public static final int COMMIT_NO_REVISION_DROP
applyTrans(int,boolean,int)
,
prepareTrans(int,int)
public static final int COMMIT_USE_COMMIT_QUEUE
public static final int IA_CLIENT_MAAPI
public static final int MAAPI_UPGRADE_KILL_ON_TIMEOUT
public Maapi(Socket socket) throws IOException, ConfException
Maapi
supplying a established
open socket to ConfD/NCS daemon.
Since the ConfD/NCS daemon expects initialization within
5 seconds after a new socket is established this constructor should be
called directly for a new socket. For instance:
Maapi maapi = new Maapi(new Socket("localhost", Conf.PORT));
When establishing a connection to ConfD/NCS the
MaapiSchemas
will be loaded once automatically
by the library.
If encrypted communication towards ConfD/NCS is desired,
an environment variable "CONFD_IPC_ACCESS_FILE" or "NCS_IPC_ACCESS_FILE"
need to be set.
This variable is expected to point to a file containing a secret salt.
example:
export CONFD_IPC_ACCESS_FILE=./secret_file.txt
An alternative to the environment variable is to set an java system
property with the same name pointing to the file.
socket
- A socket connected to ConfD/NCS.ConfException
- If ConfD/NCS refuses to establish
connection the reason could be obtained through
Throwable.getMessage()
IOException
- signals I/O exception on the underlying socketpublic void aaaReload(boolean synchronous) throws IOException, ConfException
confd --clear-aaa-cache
or ncs
--clear-aaa-cache
.synchronous
- Whether to wait for the daemon to complete reloading
the AAA data before returning.IOException
ConfException
public void abortTrans(int tid) throws IOException, ConfException
validateTrans
or prepareTrans
.tid
- Transaction IdentifierMaapiException
IOException
ConfException
public void abortUpgrade() throws IOException, ConfException
IOException
ConfException
public void applyTrans(int tid, boolean keepOpen) throws IOException, ConfException
Invoking the transaction methods in exactly the right order can be a bit complicated.
The right order to invoke the methods is:
Usually we do not require this fine grained control
over the two-phase commit protocol. It is easier to use
applyTrans
which validates, prepares and eventually aborts or commits.
A call to applyTrans
must also eventually be
followed by a call to finishTrans(int)
which will terminate
the transaction.
For a readonly transaction, i.e. one started with
Conf.MODE_READ
, or for a read-write transaction where we
haven't actually done any writes, we do not
need to call any of the validate/prepare/commit/abort or apply methods,
since there is nothing for them to do.
Calling finishTrans
to terminate the
transaction is sufficient.
The parameter keepopen can optionally be set to true, then the changes to the transaction are not discarded if validation fails. This feature is typically used by management applications that wish to present the validation errors to an operator and allow the operator to fix the validation errors and then later retry the apply sequence.
tid
- Transaction id of transaction to commitkeepOpen
- If validation fails should the transaction be kept
open or notConfException
- If the transaction is in badstate, for
example if applyTrans
is called twice.IOException
public void applyTrans(int tid, boolean keepOpen, int flags) throws IOException, ConfException
Some NCS specific flags can be used:
COMMIT_NCS_NO_REVISION_DROP
means that NCS will not
run its data model revision algorithm, thus requiring all participating
managed devices to have all parts of the data models for all data
contained in this transaction, i.e., this flag forces NCS to never
silently drop any data set operations towards a device.
COMMIT_NCS_NO_NETWORKING
means that the NCS device
manager will not see these changes. Even if transaction manipulates
data below /devices/device/config, nothing will be sent to the
managed devices. Thus this is a way to manipulate CDB in NCS without
generating any southbound traffic.
COMMIT_NCS_ASYNC_COMMIT_QUEUE
means that if some device
is non-operational or has data waiting in the commit queue, the data
in this transaction will be placed in the queue. If this flag is set
and the function returns ok, the function commitQueueResult() must
be called. commitQueueResult() will return the commit queue id for
the transaction, if any device was involved in the commit.
COMMIT_NCS_SYNC_COMMIT_QUEUE
means that if some device
is non-operational or has data waiting in the commit queue, the data
in this transaction will be placed in the queue. If this flag is set
and the function returns ok, the function commitQueueResult() must
be called. commitQueueResult() will wait for the transaction to be
committed to the devices, if any device was involved in the commit.
COMMIT_NCS_THROUGH_COMMIT_QUEUE
means that if some device
is non-operational or has data waiting in the commit queue, the data
in this transaction will be placed in the queue.
COMMIT_NCS_BYPASS_COMMIT_QUEUE
means that even if some
device has data in the commit queue, this transaction will bypass
the queue.
COMMIT_NCS_NO_OVERWRITE
means that NCS will check
that the data that should be modified has not changed on the
device compared to NCS's view of the data. This is
fine-granular sync check; NCS verifies that NCS and the
device is in sync regarding the data that will be modified.
If they are not in sync, the transaction is aborted.
The flags are bits and can be ORed together.
tid
- Transaction id of transaction to commitkeepOpen
- If validation fails should the transaction be kept
open or notflags
- Bitwise ORed flagsMaapiException
IOException
ConfException
public void attach(int tid, int nsi) throws IOException, ConfException
attach(int, int, int)
with the exception
that the User session id is implicit for the attached transaction.tid
- Transaction identifiernsi
- Namespace identifier. Use 0 if we don't care which
namespace is the default to choose if path elements
are not properly prefixed.IOException
ConfException
public void attach(int tid, int nsi, int usid) throws IOException, ConfException
While a transaction is executing, we have a number of situations where we wish to invoke user Java code which can interact in the transaction. One such situation is when we wish to write semantic validation code which is invoked in the validation phase of a transaction.
This code needs to execute within the context of the executing transaction, it must thus have access to the "shadow" storage where all not-yet-committed data is kept.
This method attaches to a existing transaction. See user guide chapter "Semantic Validation" for example code.
Another situation where we wish to attach to the executing transaction is when we are using the notifications API and subscribe to notification of type NOTIF_COMMIT_DIFF and wish to read the committed diffs from the transaction.
tid
- Transaction identifiernsi
- Namespace identifier. Use 0 if we don't care which
namespace is the default to choose if path elements
are not properly prefixed.usid
- UsidMaapiException
IOException
ConfException
public void attach(int tid, String ns) throws IOException, ConfException
attach(int, String, int)
with the exception
that the User session id is implicit for the attached transaction.tid
- Transaction identifierns
- Namespace identifierIOException
ConfException
public void attach(int tid, String ns, int usid) throws IOException, ConfException
While a transaction is executing, we have a number of situations where we wish to invoke user Java code which can interact in the transaction. One such situation is when we wish to write semantic validation code which is invoked in the validation phase of a transaction.
This code needs to execute within the context of the executing transaction, it must thus have access to the "shadow" storage where all not-yet-committed data is kept.
This method attaches to a existing transaction. See user guide chapter "Semantic Validation" for example code.
Another situation where we wish to attach to the executing transaction is when we are using the notifications API and subscribe to notification of type NOTIF_COMMIT_DIFF and wish to read the committed diffs from the transaction.
tid
- Transaction identifierns
- Namespace identifierusid
- UsidMaapiException
IOException
ConfException
public int attachInit() throws IOException, ConfException
This method is used to attach the Maapi socket to the special transaction available in phase0 used for CDB initialization and upgrade.
IOException
ConfException
public MaapiAuthentication authenticate(String user, String passwd) throws IOException, ConfException
startUserSession(String,InetAddress,String,String[],
MaapiUserSessionFlag)
requires the application to tell ConfD/NCS
which groups the user are member of.
ConfD/NCS itself has the capability to authenticate users. It is possible for a MAAPI application to let ConfD/NCS authenticate the user, as per the AAA configuration in the system configuration file
user
- passwd
- ConfException
IOException
public MaapiAuthentication authenticate2(String user, String passwd, InetAddress src_addr, int src_port, String context, MaapiUserSessionFlag proto) throws IOException, ConfException
startUserSession(String,InetAddress,String,String[],
MaapiUserSessionFlag)
requires the application to tell ConfD/NCS
which groups the user are member of.
ConfD/NCS itself has the capability to authenticate users. It is possible for a MAAPI application to let ConfD/NCS authenticate the user, as per the AAA configuration in the system configuration file
user
- passwd
- src_addr
- src_port
- context
- proto
- ConfException
IOException
public void candidateAbortCommit() throws IOException, ConfException
ConfException
IOException
public void candidateAbortCommitPersistent(String persistId) throws IOException, ConfException
candidateAbortCommit()
.persistId
- cookie for ongoing persistent confirmed commitIOException
ConfException
- If error. If the errorCode
for the
ConfException
is ConfException.ERR_NOEXISTS
it means that there is an ongoing persistent
confirmed commit, but persistId
did not give the
right cookie for it.public void candidateCommit() throws IOException, ConfException
IOException
ConfException
public void candidateCommit(int flags) throws IOException, ConfException
applyTrans(int,boolean)
ConfException
IOException
public void candidateCommitInfo(String label, String comment) throws IOException, ConfException
candidateCommit()
. Otherwise the
method will confirm the ongoing confirmed commit. For a persistent
confirmed commit, the cookie can be given by persistId if needed.
Note: To ensure that the "Label" and/or "Comment" are stored
in the rollback file in all cases when doing a confirmed commit,
they must be given both with the confirmed commit (using
candidateConfirmedCommitInfo(int, java.lang.String, java.lang.String)
) and
with the confirming commit (using this method).label
- value for "Label" in the rollback filecomment
- value for "Comment" in the rollback fileIOException
ConfException
- If error. If the errorCode
for the
ConfException
is ConfException.ERR_NOEXISTS
it means that there is an ongoing persistent confirmed commit,
but persistId
did not give the
right cookie for it.public void candidateCommitInfo(String persistId, String label, String comment) throws IOException, ConfException
candidateCommit()
. Otherwise the
method will confirm the ongoing confirmed commit. For a persistent
confirmed commit, the cookie can be given by persistId if needed.
Note: To ensure that the "Label" and/or "Comment" are stored
in the rollback file in all cases when doing a confirmed commit,
they must be given both with the confirmed commit (using
candidateConfirmedCommitInfo(int, java.lang.String, java.lang.String)
) and
with the confirming commit (using this method).persistId
- value for an already ongoing persistent confirmed commitlabel
- value for "Label" in the rollback filecomment
- value for "Comment" in the rollback fileIOException
ConfException
- If error. If the errorCode
for the
ConfException
is ConfException.ERR_NOEXISTS
it means that there is an ongoing persistent confirmed commit,
but persistId
did not give the
right cookie for it.public void candidateCommitPersistent(String persistId) throws IOException, ConfException
candidateCommit()
.
Throws ConfException if error. If the errorCode for the ConfException is
ConfException.ERR_NOEXISTS it means that there is an ongoing persistent
confirmed commit, but persist_id did not give the right cookie for it.persistId
- IOException
ConfException
- If error. If the errorCode
for the
ConfException
is ConfException.ERR_NOEXISTS
it means that there is an ongoing persistent confirmed commit,
but persistId
did not give the
right cookie for it.public void candidateCommitPersistent(String persistId, int flags) throws IOException, ConfException
IOException
ConfException
public void candidateConfirmedCommit(int t) throws IOException, ConfException
t
- Timeout in secondsConfException
IOException
public void candidateConfirmedCommitInfo(int timeoutsecs, String label, String comment) throws IOException, ConfException
candidateConfirmedCommitPersistent(int, java.lang.String, java.lang.String)
, but allows for
setting the "Label" and/or "Comment" that is stored in the
rollback file when the candidate is committed to running. To set
only the "Label", give comment as null, and to set only the
"Comment", give label as null.
Note: To ensure that the "Label" and/or "Comment" are stored in the
rollback file in all cases when doing a confirmed commit, they must
be given both with the confirmed commit (using this method) and
with the confirming commit (using candidateCommitInfo(java.lang.String, java.lang.String)
).timeoutsecs
- timeout for the confirmed commitlabel
- value for "Label" in the rollback filecomment
- value for "Comment" in the rollback fileIOException
ConfException
- If error. If the errorCode
for the
ConfException
is ConfException.ERR_NOEXISTS
it means that there is an ongoing persistent
confirmed commit, but persistId
did not give the right
cookie for it.public void candidateConfirmedCommitInfo(int timeoutsecs, String persist, String persistId, String label, String comment) throws IOException, ConfException
candidateConfirmedCommitPersistent(int, java.lang.String, java.lang.String)
, but allows for
setting the "Label" and/or "Comment" that is stored in the
rollback file when the candidate is committed to running. To set
only the "Label", give comment as null, and to set only the
"Comment", give label as null.
Note: To ensure that the "Label" and/or "Comment" are stored in the
rollback file in all cases when doing a confirmed commit, they must
be given both with the confirmed commit (using this method) and
with the confirming commit (using candidateCommitInfo(java.lang.String, java.lang.String)
).timeoutsecs
- timeout for the confirmed commitpersist
- value for a new persistent confirmed commitpersistId
- value for an already ongoing persistent confirmed commitlabel
- value for "Label" in the rollback filecomment
- value for "Comment" in the rollback fileIOException
ConfException
- If error. If the errorCode
for the
ConfException
is ConfException.ERR_NOEXISTS
it means that there is an ongoing persistent
confirmed commit, but persistId
did not give the right
cookie for it.public void candidateConfirmedCommitPersistent(int timeoutsecs, String persist, String persistId) throws IOException, ConfException
IOException
ConfException
public void candidateConfirmedCommitPersistent(int timeoutsecs, String persist, String persistId, int flags) throws IOException, ConfException
persist
parameter sets the cookie for the
persistent confirmed commit, while the persistId
gives
the cookie for an already ongoing persistent confirmed commit.
This gives the following
possibilities:
persist = "cookie", persistId = null
Start a persistent confirmed commit
with the cookie "cookie", or extend an already ongoing non-persistent
confirmed commit and turn it into a persistent confirmed commit.
persist = "newcookie", persistId = "oldcookie"
Extend an ongoing
persistent confirmed commit that uses the cookie "oldcookie" and change
the cookie to "newcookie".
persist = null, persistId = "cookie"
Extend an ongoing persistent confirmed commit that uses the cookie
"oldcookie" and turn it into a non-persistent confirmed commit.
persist = null, persistId = null
Does the same as
candidateConfirmedCommit(int)
.
persist = "cookie", persistId = null
, and to extend it
with persist = "cookie", persistId = "cookie"
.
Throws ConfExceptiontimeoutsecs
- timeout for the confirmed commitpersist
- value for a new persistent confirmed commitpersistId
- value for an already ongoing persistent confirmed commitflags
- see applyTrans(int,boolean)
IOException
ConfException
- If error. If the errorCode
for the
ConfException
is ConfException.ERR_NOEXISTS
it means that there is an ongoing persistent
confirmed commit, but persistId
did not give the right
cookie for it.public void candidateReset() throws IOException, ConfException
ConfException
IOException
public void candidateValidate() throws IOException, ConfException
ConfException
IOException
public void cd(int tid, String fmt, Object... arguments) throws ConfException, IOException
The cd() function is also very useful when writing generic code for accessing parts of the configuration tree.
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtMaapiException
IOException
ConfException
public void clearOpCache() throws IOException, ConfException
clearOpCache(ConfPath)
, with the only difference that
if clears all cached data from "/" and down.IOException
ConfException
public void clearOpCache(ConfPath path) throws IOException, ConfException
path
- ConfPath to the subtree for which cached data should be
clearedIOException
ConfException
public String CLIPrompt(int usid, String prompt, boolean echo) throws ConfException, IOException
The echo parameter is used to control if the input should be echoed or not. If set to 'true' all input will be visible and if set to 'false' only stars will be shown instead of the actual characters entered by the user. The resulting string will be returned.
This function is intended to be called from inside an action callback when invoked from the CLI.
usid
- ID of sessionprompt
- Prompt stringecho
- If the answer should be echoed or notConfException
IOException
public String CLIPrompt(int usid, String prompt, boolean echo, int timeout) throws ConfException, IOException
The echo parameter is used to control if the input should be echoed or not. If set to 'true' all input will be visible and if set to 'false' only stars will be shown instead of the actual characters entered by the user. The resulting string will be returned.
This function is intended to be called from inside an action callback when invoked from the CLI.
usid
- ID of sessionprompt
- Prompt stringecho
- If the answer should be echoed or nottimeout
- Idle timeout in secondsConfException
IOException
public String CLIPromptOneOf(int usid, String prompt, String[] choice) throws ConfException, IOException
For example:
String res = maapi.CLIPromptOneOf(usid, "Do you want to proceed (yes/no): ", new String[] { "yes", "no" });For example:
Do you want to proceed (yes/no): maybe The value must be one of: yes,no. Do you want to proceed (yes/no):This function is intended to be called from inside an action callback when invoked from the CLI.
usid
- ID of sessionprompt
- Prompt stringchoice
- An array of choices to accept from userConfException
IOException
public String CLIPromptOneOf(int usid, String prompt, String[] choice, int timeout) throws ConfException, IOException
For example:
String res = maapi.CLIPromptOneOf(usid, "Do you want to proceed (yes/no): ", new String[] { "yes", "no" }, 60);For example:
Do you want to proceed (yes/no): maybe The value must be one of: yes,no. Do you want to proceed (yes/no):This function is intended to be called from inside an action callback when invoked from the CLI.
usid
- ID of sessionprompt
- Prompt stringchoice
- An array of choices to accept from usertimeout
- Idle timeout in secondsConfException
IOException
public String CLIReadEOF(int usid, boolean echo) throws ConfException, IOException
The user has to end the input using ctrl-D. The entered characters will be returned. The echo parameters controls if the entered characters should be echoed or not. If set to 'true' the answer will be visible and if set to 'false' stars will be echoed instead.
This method is intended to be called from inside an action call- back when invoked from the CLI.
ConfException
IOException
public String CLIReadEOF(int usid, boolean echo, int timeout) throws ConfException, IOException
The user has to end the input using ctrl-D. The entered characters will be returned. The echo parameters controls if the entered characters should be echoed or not. If set to 'true' the answer will be visible and if set to 'false' stars will be echoed instead.
This function is intended to be called from inside an action call- back when invoked from the CLI.
ConfException
IOException
public void CLIWrite(int usid, String buf) throws ConfException, IOException
This method is intended to be called from inside an action callback when invoked from the CLI.
usid
- ID of sessionbuf
- Text to write to CLIConfException
IOException
public CommitQueueResult commitQueueResult(int tid, int timeout) throws IOException, ConfException
tid
- Transaction id of committed transactiontimeout
- Timeout in seconds. -1 means infintity. Only
applicable if the sync flag was set.ConfException
IOException
public void commitTrans(int tid) throws IOException, ConfException
validateTrans(int,boolean,boolean)
and
prepareTrans
must be called prior to
commitTrans
tid
- Transaction IdentifierMaapiException
IOException
ConfException
public void commitUpgrade() throws IOException, ConfException
IOException
ConfException
public int confirmedCommitInProgress() throws IOException, ConfException
ConfException
IOException
public void copy_tree(int tid, boolean useSharedCreate, ConfPath from, ConfPath to) throws IOException, ConfException
tid
- Transaction IdentifieruseSharedCreate
- from
- to
- ConfException
IOException
public void copy_tree(int tid, ConfPath from, ConfPath to) throws IOException, ConfException
IOException
ConfException
public void copy(int thfrom, int thto) throws IOException, ConfException
thfrom
- thto
- ConfException
IOException
public void copyRunningToStartup() throws IOException, ConfException
ConfException
IOException
public void create(int tid, ConfPath path) throws IOException, ConfException
maapi.create(th, "/servers/server{www}");If we are creating a new server element as above, we must also populate all other XML elements below which do not have a default value in the YANG model. Thus, assuming 'port' is mandatory we must also:
maapi.setElem(th, "80", "/servers/server{www}/port");before we try to commit the data.
tid
- Transaction Identifierpath
- ConfException
- if the object already existsIOException
public void create(int tid, String fmt, Object... arguments) throws IOException, ConfException
maapi.create(th, "/servers/server{www}");If we are creating a new server element as above, we must also populate all other XML elements below, which do not have a default value in the YANG model. Thus we must also:
maapi.setElem(th, "80", "/servers/server{www}/port");before we try to commit the data.
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtConfException
- if the object already existsIOException
public void delete(int tid, ConfPath path) throws IOException, ConfException
tid
- Transaction Identifierpath
- ConfException
IOException
public void delete(int tid, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtConfException
IOException
public void deleteConfig(int db) throws IOException, ConfException
ConfException
IOException
public ConfObject[][] deref(int tid, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtMaapiException
IOException
ConfException
public void detach(int tid) throws IOException, ConfException
finish
phase in validation code.
An attached MAAPI socket will be
automatically detached when the transaction terminates.
This method performs an explicit detach.tid
- Transaction IdentifierMaapiException
IOException
ConfException
public void diffIterate(int tid, MaapiDiffIterate iter) throws IOException, ConfException
For all diffs in the transaction
the supplied
MaapiDiffIterate.iterate(ConfObject[],DiffIterateOperFlag,
ConfObject,ConfObject,Object)
(callback) method will be called.
This method can be called from an attached MAAPI session. The purpose of the function is to iterate through the transaction diff. It can typically be used in conjunction with the notification API when we subscribe to NOTIF_COMMIT_DIFF events.
For all diffs in the transaction the supplied callback function
iterate
will be called. The iterate
callback
receives the keypath which uniquely identifies which element in the
XML tree that is affected, the operation, and an optional value.
iterate
is called for each modified list entry, and for each
modified leaf node. If the node is a list entry, op is one of
MOP_CREATED
, MOP_DELETED
or
MOP_MODIFIED
If the node is a leaf node, op
is one of MOP_DELETED
or MOP_VALUE_SET
.
If iterate
returns ITER_STOP
, no more
iteration is done. If
iterate
returns ITER_RECURSE
iteration
continues with all children
to the node. If iterate
returns
ITER_CONTINUE
iteration ignores
the children to the node (if any), and continues with the node's sibling.
The different commit messages are not subjected to AAA checks, i.e. regardless of which path we have and which context was used to create the MAAPI socket, all changed values are sent on the socket.
tid
- Transaction handleiter
- A MaapiDiffIterate objectMaapiException
- Failed diffIterateIOException
- Failed to read/write maapi socketConfException
public void diffIterate(int tid, MaapiDiffIterate iter, Object initstate, String fmt, Object... args) throws IOException, ConfException
For all diffs in the transaction
the supplied
MaapiDiffIterate.iterate(ConfObject[],DiffIterateOperFlag,
ConfObject,ConfObject,Object)
(callback) method will be called.
This method can be called from an attached MAAPI session. The purpose of the function is to iterate through the transaction diff. It can typically be used in conjunction with the notification API when we subscribe to NOTIF_COMMIT_DIFF events.
For all diffs in the transaction the supplied callback function
iterate
will be called. The iterate
callback
receives the keypath which uniquely identifies which element in the
XML tree that is affected, the operation, and an optional value.
iterate
is called for each modified list entry, and for each
modified leaf node. If the node is a list entry, op is one of
MOP_CREATED
, MOP_DELETED
or
MOP_MODIFIED
If the node is a leaf node, op
is one of MOP_DELETED
or MOP_VALUE_SET
.
If iterate
returns ITER_STOP
, no more
iteration is done. If
iterate
returns ITER_RECURSE
iteration
continues with all children
to the node. If iterate
returns
ITER_CONTINUE
iteration ignores
the children to the node (if any), and continues with the node's sibling.
The different commit messages are not subjected to AAA checks, i.e. regardless of which path we have and which context was used to create the MAAPI socket, all changed values are sent on the socket.
tid
- Transaction handleiter
- A MaapiDiffIterate objectMaapiException
- Failed diffIterateIOException
- Failed to read/write maapi socketConfException
public void diffIterate(int tid, MaapiDiffIterate iter, String fmt, Object... args) throws IOException, ConfException
For all diffs in the transaction
the supplied
MaapiDiffIterate.iterate(ConfObject[],DiffIterateOperFlag,
ConfObject,ConfObject,Object)
(callback) method will be called.
This method can be called from an attached MAAPI session. The purpose of the function is to iterate through the transaction diff. It can typically be used in conjunction with the notification API when we subscribe to NOTIF_COMMIT_DIFF events.
For all diffs in the transaction the supplied callback function
iterate
will be called. The iterate
callback
receives the keypath which uniquely identifies which element in the
XML tree that is affected, the operation, and an optional value.
iterate
is called for each modified list entry, and for each
modified leaf node. If the node is a list entry, op is one of
MOP_CREATED
, MOP_DELETED
or
MOP_MODIFIED
If the node is a leaf node, op
is one of MOP_DELETED
or MOP_VALUE_SET
.
If iterate
returns ITER_STOP
, no more
iteration is done. If
iterate
returns ITER_RECURSE
iteration
continues with all children
to the node. If iterate
returns
ITER_CONTINUE
iteration ignores
the children to the node (if any), and continues with the node's sibling.
The different commit messages are not subjected to AAA checks, i.e. regardless of which path we have and which context was used to create the MAAPI socket, all changed values are sent on the socket.
tid
- Transaction handleiter
- A MaapiDiffIterate objectMaapiException
- Failed diffIterateIOException
- Failed to read/write maapi socketConfException
public void diffIterate(int tid, Object initstate, EnumSet<DiffIterateFlags> flags, MaapiDiffIterate iter, ConfPath path) throws IOException, ConfException
For all diffs in the transaction
the supplied
MaapiDiffIterate.iterate(ConfObject[],DiffIterateOperFlag,
ConfObject,ConfObject,Object)
(callback) method will be called.
This method can be called from an attached MAAPI session. The purpose of the function is to iterate through the transaction diff. It can typically be used in conjunction with the notification API when we subscribe to NOTIF_COMMIT_DIFF events.
For all diffs in the transaction the supplied callback function
iterate
will be called. The iterate
callback
receives the keypath which uniquely identifies which element in the
XML tree that is affected, the operation, and an optional value.
iterate
is called for each modified list entry, and for each
modified leaf node. If the node is a list entry, op is one of
MOP_CREATED
, MOP_DELETED
or
MOP_MODIFIED
If the node is a leaf node, op
is one of MOP_DELETED
or MOP_VALUE_SET
.
If the flags argument is set to DiffIterateFlags.ITER_WANT_ATTR
also attribute changes will be iterated over with op
MOP_ATTR_SET
and new and old values as
ConfAttributeValue
If iterate
returns ITER_STOP
, no more
iteration is done. If
iterate
returns ITER_RECURSE
iteration
continues with all children
to the node. If iterate
returns
ITER_CONTINUE
iteration ignores
the children to the node (if any), and continues with the node's sibling.
The different commit messages are not subjected to AAA checks, i.e. regardless of which path we have and which context was used to create the MAAPI socket, all changed values are sent on the socket.
tid
- Transaction handleinitstate
- arbitrary object passed to the iteratorflags
- set of DiffIterateFlags
flags that controls the
iteration, for Maapi only DiffIterateFlags.ITER_WANT_ATTR
is supportediter
- A MaapiDiffIterate objectpath
- ConfPathMaapiException
- Failed diffIterateIOException
- Failed to read/write maapi socketConfException
public void disconnectRemote(String address) throws IOException, ConfException
address
- IOException
ConfException
public boolean doDisplay(int tid, String fmt, Object... args) throws IOException, ConfException
tid
- current transactionfmt
- path stringargs
- optional parameters for substitution in fmtIOException
ConfException
public void endUserSession() throws IOException, ConfException
Maapi
instance.
If the Maapi
socket is closed, the user
session is automatically ended.
MaapiException
- If there is no current session on this
Maapi
instanceIOException
- Signals I/O exception on the underlying
socketConfException
public boolean exists(int tid, ConfPath path) throws IOException, ConfException
tid
- Transaction Identifierpath
- ConfPath instanceMaapiException
IOException
ConfException
public boolean exists(int tid, String fmt, Object... arguments) throws IOException, ConfException
IOException
ConfException
public ConfKey findNext(MaapiCursor c, ConfFindNextType type, ConfKey key) throws IOException, ConfException
c
- MaapiCursor for pathtype
- ConfFindNextType if same element as key or element
after key should be retrievedkey
- ConfKey for the searched elementIOException
ConfException
public void finishTrans(int tid) throws IOException, ConfException
If the transaction is implemented by an
external database, this will invoke the finish
callback.
tid
- Transaction id of transaction to terminate.MaapiException
IOException
ConfException
public ConfAttributeValue[] getAttrs(int tid, ConfAttributeType[] attribs, String fmt, Object... args) throws IOException, ConfException
tid
- current transactionattribs
- array of ConfAttributeType denoting attributes to retrievefmt
- path indicating node to retrieve attributes fromargs
- variable argument list for c-style parameters in fmtPathIOException
ConfException
public static ArrayList<ConfNamespace> getAutoNsList()
public static ArrayList<ConfNamespace> getAutoNsList(ArrayList<ConfNamespace> defaultNsList)
public ConfTag getCase(int tid, String choice, ConfPath path) throws IOException, ConfException
IOException
ConfException
public ConfTag getCase(int tid, String choice, String fmt, Object... arguments) throws IOException, ConfException
When we use the YANG choice statement in the data model, this method
can be used to find the currently selected case,
avoiding useless getElem() etc requests for nodes that belong
to other cases. The fmt
arguments give the path to
the list entry or container where the choice is defined,
and choice is the name of the choice.The case value is returned as
ConfTag.
For a choice without a mandatory true statement where no case is
currently selected, the function will fail with
ERR_NOEXISTS if the choice doesn't have a default case.
If it has a default case, it will be returned
unless the MaapiFlag.NO_DEFAULTS
flag is in effect @see
MaapiFlag if the flag is set, the value returned will have type
ConfDefault
.
NOTE: The method will suppress all ERR_NOEXISTS errors this means that the method will not throw exception when ERR_NOEXISTS occurs it will print a warning message and return null.
tid
- current transaction handlechoice
- name of the choicefmt
- path string to the container or list where the
choice is definedarguments
- optional parameters for substitution in fmtMaapiException
IOException
ConfException
public CLIInteraction getCLIInteraction(int usid)
usid
- user session idpublic String getCwd(int tid) throws IOException, ConfException
tid
- current transactionIOException
ConfException
public ConfPath getCwdPath(int tid) throws IOException, ConfException
tid
- current transactionIOException
ConfException
public ConfValue getElem(int tid, ConfPath path) throws IOException, ConfException
IOException
ConfException
public ConfValue getElem(int tid, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtMaapiException
IOException
ConfException
public int getMyUserSession() throws IOException, ConfException
Maapi
MaapiException
- If no user session exists on this
Maapi
socketIOException
- Signals some I/O exception on the underlying
socketConfException
public ConfKey getNext(MaapiCursor c) throws IOException, ConfException
MaapiCursor
initially retrieved by
newCursor(int, String, Object...)
.
With the key(s) it is possible to navigate further down the model.
MaapiCursor initially retrieved by
newCursor(int, String, Object...)
.
With the key(s) it is possible to navigate further down the
model.
For example to read the port element from the 'server' example model, we would do:
MaapiCursor c = maapi.newCursor(th, "/mtest:mtest/servers/server"); ConfKey x = maapi.getNext(c); while (x != null) { ConfObject p; p = maapi.getElem(th, "/mtest:mtest/servers/server{%x}/port", x); // .... x = maapi.getNext(c); }
c
- MaapiCursorConfException
IOException
public ArrayList<ConfNamespace> getNsList()
MaapiSchemas
. The underlying socket is not required to
be open for this operation.public int getNumberOfInstances(int tid, ConfPath path) throws IOException, ConfException
IOException
ConfException
public int getNumberOfInstances(int tid, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtMaapiException
IOException
ConfException
public ConfObject[] getObject(int tid, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtMaapiException
IOException
ConfException
public List<ConfObject[]> getObjects(MaapiCursor c, int numOfObjects, int numOfInstances) throws IOException, ConfException
c
- MaapiCursor on current listnumOfObjects
- Number of object retrieved from a list instancenumOfInstances
- Number of list instances retrieved in this callIOException
ConfException
public int getRunningDbStatus() throws IOException, ConfException
If a transaction fails in the commit
phase, the
configuration database is in in a possibly inconsistent state.
This method queries ConfD/NCS on the consistency state.
ConfException
IOException
public static MaapiSchemas getSchemas()
public Socket getSocket()
public MaapiUserSession getUserSession(int usid) throws IOException, ConfException
MaapiUserSession
given by the usid
.usid
- ID of session to retrieveMaapiException
- If the user session with the given
ID
does not exitsIOException
- Signals I/O exception on the underlying
socketConfException
public int[] getUserSessions() throws IOException, ConfException
MaapiException
- -IOException
- Signals I/O exception on the underlying
socketConfException
public <T extends ConfXMLParam> T[] getValues(int th, T[] params, ConfPath path) throws IOException, ConfException
The params
array must be pre-populated
based on the specification of the ConfXMLParam
array
structure format. Where ConfXMLParamValue
value element set by
ConfXMLParamValue.setValue(ConfObject)
method is given as follow:
ConfNoExists
means that the value should be read from the
transaction and stored in the array.
ConfXMLParamStart
,ConfXMLParamStop
are used as per the specification.
All elements have the same position in the array after the call,
In order to simplify extraction of the values -
this means that optional elements that were requested but didn't
exist will have ConfNoExists
(as a the
ConfXMLParam.getValue()
return value in
the corresponding position in a ConfXMLParamValue
)
rather than being omitted from the array.
However requesting a list entry that doesn't exist will throw
a exception indicating that the instance does not exits.
T
- type of the elements contained in the structureth
- transaction handleparams
- pre-populated structure of the elements to be extractedpath
- the path pointing to the location of extractionMaapiException
- If the the call failed for some reason
see the Throwable.getMessage()
for details.IOException
- Signals I/O exception of some kindConfException
ConfXMLParam
,
ConfXMLParamValue
public <T extends ConfXMLParam> T[] getValues(int th, T[] params, String fmt, Object... arguments) throws IOException, ConfException
The params
array must be pre-populated
based on the specification of the ConfXMLParam
array
structure format. Where ConfXMLParamValue
value element set by
ConfXMLParamValue.setValue(ConfObject)
method is given as follow:
ConfNoExists
means that the value should be read from the
transaction and stored in the array.
ConfXMLParamStart
,ConfXMLParamStop
are used as per the specification.
All elements have the same position in the array after the call,
In order to simplify extraction of the values -
this means that optional elements that were requested but didn't
exist will have ConfNoExists
(as a the
ConfXMLParam.getValue()
return value in
the corresponding position in a ConfXMLParamValue
)
rather than being omitted from the array.
However requesting a list entry that doesn't exist will throw
a exception indicating that the instance does not exits.
T
- type of the elements contained in the structureth
- transaction handleparams
- pre-populated structure of the elements to be extractedfmt
- path stringarguments
- optional parameter for substitution in fmtMaapiException
- If the the call failed for some reason
see the Throwable.getMessage()
for details.IOException
- Signals I/O exception of some kindConfException
ConfXMLParam
,
ConfXMLParamValue
public <T extends List<ConfXMLParam>> T getValues(int th, T params, ConfPath path) throws IOException, ConfException
The params
list must be pre-populated
based on the specification of the ConfXMLParam
array
structure format. Where ConfXMLParamValue
value element set by
ConfXMLParamValue.setValue(ConfObject)
method is given as follow:
ConfNoExists
means that the value should be read from the
transaction and stored in the array.
ConfXMLParamStart
,ConfXMLParamStop
are used as per the specification.
All elements have the same position in the array after the call,
In order to simplify extraction of the values -
this means that optional elements that were requested but didn't
exist will have ConfNoExists
(as a the
ConfXMLParam.getValue()
return value in
the corresponding position in a ConfXMLParamValue
)
rather than being omitted from the array.
However requesting a list entry that doesn't exist will throw
a exception indicating that the instance does not exits.
T
- the type list holding the structureth
- transaction handlepath
- the path pointing to the location of extractionparams
- pre-populated structure of the elements to be extractedMaapiException
- If the the call failed for some reason
see the Throwable.getMessage()
for details.IOException
- Signals I/O exception of some kindConfException
ConfXMLParam
,
ConfXMLParamValue
public <T extends List<ConfXMLParam>> T getValues(int th, T params, String fmt, Object... arguments) throws IOException, ConfException
The params
list must be pre-populated
based on the specification of the ConfXMLParam
array
structure format. Where ConfXMLParamValue
value element set by
ConfXMLParamValue.setValue(ConfObject)
method is given as follow:
ConfNoExists
means that the value should be read from the
transaction and stored in the array.
ConfXMLParamStart
,ConfXMLParamStop
are used as per the specification.
All elements have the same position in the array after the call,
In order to simplify extraction of the values -
this means that optional elements that were requested but didn't
exist will have ConfNoExists
(as a the
ConfXMLParam.getValue()
return value in
the corresponding position in a ConfXMLParamValue
)
rather than being omitted from the array.
However requesting a list entry that doesn't exist will throw
a exception indicating that the instance does not exits.
T
- the type list holding the structureth
- transaction handlearguments
- optional parameter for substitution in fmtparams
- pre-populated structure of the elements to be extractedMaapiException
- If the the call failed for some reason
see the Throwable.getMessage()
for details.IOException
- Signals I/O exception of some kindConfException
ConfXMLParam
,
ConfXMLParamValue
public void initUpgrade(int timeoutsecs, int flags) throws IOException, ConfException
timeoutsecs
- specifies a maximum time to wait for users to exitflags
- bitflags for control of upgrade behaviorIOException
ConfException
public void insert(int tid, boolean createBackPointer, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction IdentifiercreateBackPointer
- When we insert items into lists that are
managed by FastMap code, we always want to set this parameter to
true. Since we insert into the list, effectively changing the keys
the FastMap diff-sets must be updated accordingly.fmt
- path stringarguments
- optional parameters for substitution in fmtConfException
IOException
public void insert(int tid, String fmt, Object... arguments) throws IOException, ConfException
IOException
ConfException
public boolean isCandidateModified() throws IOException, ConfException
IOException
ConfException
public int isLockSet(int db) throws IOException, ConfException
db
- Database to check. Possible values are
Conf.DB_STARTUP
, Conf.DB_RUNNING
, and
Conf.DB_CANDIDATE
ConfException
IOException
public boolean isRunningModified() throws IOException, ConfException
IOException
ConfException
public void iterate(int tid, Object initstate, EnumSet<ConfIterateFlags> flags, MaapiIterate iter, ConfPath path) throws IOException, ConfException
For all data elements in the transaction the supplied
MaapiIterate.iterate(ConfObject[],ConfObject,
ConfAttributeValue[],Object)
(callback) method will be called.
This method can be called from an attached MAAPI session.
The iterate
callback
receives the keypath which uniquely identifies which element in the
XML tree that is affected, the operation, and an optional value.
iterate
is called for each list entry, and for each
leaf node. If the node is a list entry, op is one of
MOP_CREATED
, MOP_DELETED
or
MOP_MODIFIED
If the node is a leaf node, op
is one of MOP_DELETED
or MOP_VALUE_SET
.
If the flags argument is set to ConfIterateFlags.ITER_WANT_ATTR
also attribute changes will be iterated over with op
MOP_ATTR_SET
and new and old values as
ConfAttributeValue
If iterate
returns ITER_STOP
, no more
iteration is done. If
iterate
returns ITER_RECURSE
iteration
continues with all children
to the node. If iterate
returns
ITER_CONTINUE
iteration ignores
the children to the node (if any), and continues with the node's sibling.
The different commit messages are not subjected to AAA checks, i.e. regardless of which path we have and which context was used to create the MAAPI socket, all changed values are sent on the socket.
tid
- Transaction handleinitstate
- arbitrary object passed to the iteratorflags
- set of ConfIterateFlags
flags that controls the
iteration, for Maapi only ConfIterateFlags.ITER_WANT_ATTR
is supportediter
- A MaapiIterate objectpath
- ConfPathIOException
ConfException
public void killUserSession(int usid) throws IOException, ConfException
usid
- ID of session to terminateMaapiException
- If the session with the ID
did not existsIOException
- Signals I/O exception on the underlying
socketConfException
public MaapiRollback[] listRollback() throws IOException, ConfException
IOException
ConfException
public void loadConfig(int tid, EnumSet<MaapiConfigFlag> flags, String filename) throws ConfException, IOException
saveConfig(int, EnumSet, String, Object...)
tid
- transaction id for started transactionflags
- One of MAAPI_CONFIG_XML
,
MAAPI_CONFIG_J
,
MAAPI_CONFIG_C
,
MAAPI_CONFIG_WITH_DEFAULTS
,
MAAPI_CONFIG_SHOW_DEFAULTS
,
MAAPI_CONFIG_C_IOS
,
MAAPI_CONFIG_MERGE
or
MAAPI_CONFIG_WITH_OPER
filename
- name of the configuration file relative directory where
ConfD/NCS started.MaapiException
ConfException
IOException
public void loadConfigCmds(int tid, EnumSet<MaapiConfigFlag> flags, String cmds, String fmt, Object... arguments) throws IOException, ConfException
saveConfig(int, EnumSet, String, Object...)
tid
- transaction id for started transactionflags
- One of MAAPI_CONFIG_XML
,
MAAPI_CONFIG_J
, MAAPI_CONFIG_C
,
MAAPI_CONFIG_WITH_DEFAULTS
,
MAAPI_CONFIG_SHOW_DEFAULTS
,
MAAPI_CONFIG_C_IOS
,
MAAPI_CONFIG_MERGE
or
MAAPI_CONFIG_WITH_OPER
cmds
- -MaapiException
IOException
ConfException
public MaapiOutputStream loadConfigStream(int tid, EnumSet<MaapiConfigFlag> flags) throws ConfException, IOException
OuputStream
into ConfD/NCS.
This method loads a configuration from a OutputStream
into the server.
The tid parameter is a transaction id. Thus the application must create and also apply the transaction. By default the complete configuration (as allowed by the user of the current transaction) is deleted before the file is loaded.
To merge the contents of the file use the
MaapiConfigFlag.MAAPI_CONFIG_MERGE
flag.
The MaapiConfigFlag.MAAPI_CONFIG_WITH_OPER
flag can be used
together with MaapiConfigFlag.MAAPI_CONFIG_XML
to mean that
any operational data in the file should be ignored
(instead of producing an error).
The other flags parameters are the same as for
saveConfig(int, EnumSet, String, Object...)
tid
- transaction id for started transactionflags
- One of
MAAPI_CONFIG_XML
,
MAAPI_CONFIG_J
,
MAAPI_CONFIG_C
,
MAAPI_CONFIG_WITH_DEFAULTS
,
MAAPI_CONFIG_SHOW_DEFAULTS
,
MAAPI_CONFIG_C_IOS
,
MAAPI_CONFIG_MERGE
or
MAAPI_CONFIG_WITH_OPER
MaapiException
ConfException
IOException
public void loadRollback(int tid, int nr) throws IOException, ConfException
tid
- Transaction Identifiernr
- Rollback numberIOException
ConfException
public MaapiSchemas loadSchemas() throws ConfException
When loaded the MaapiSchemas
object is stored
locally and new calls to this method will return the same instance.
MaapiException
- if loading failsConfException
public MaapiSchemas loadSchemas(String[] namespaceURIs) throws ConfException
When loaded the MaapiSchemas object is stored locally and new calls to this method will return the same instance.
namespaceURIs
- string array of URIs for the schemas to loadMaapiException
- if loading failsConfException
public void lock(int db) throws IOException, ConfException
Only one entity may own the lock at any given time.
You do not have to acquire the lock before you read or write to a transaction.
This lock is also taken by the CLI when the user enters exclusive mode. Depending on the configuration different locks will be taken, ie, if the system has been configured to have a candidate, and a writable running configuration then both a lock on running and a lock on the candidate database will be acquired.
The following locks are acquired when you enter configure exclusive mode in the CLI:
If the system is configured with a startup db, and no writable running or candidate: lock startup
If the system is configured with a writable running and no startup or candidate db: lock running
If the system is configured with a writable running and a startup db, and no candidate: lock running and startup.
If the system is configured with a writable running and a candidate db, and no startup: lock running and candidate.
db
- Database to lock. Possible values are STARTUP, RUNNING, and
CANDIDATEConfException
IOException
public int lockPartial(int db, String xpath) throws IOException, ConfException
lockPartial(int,String[])
except only one xpath
expression is given.IOException
ConfException
public int lockPartial(int db, String[] xpaths) throws IOException, ConfException
db
- Databasexpaths
- Array of xpath expressions to lockConfException
IOException
public void move(int tid, ConfKey tokey, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifiertokey
- fmt
- path stringarguments
- optional parameters for substitution in fmtConfException
IOException
public void move(int tid, String tokey, String fmt, Object... arguments) throws IOException, ConfException
Renames the object using the new instance key tokey represented as a string.
tid
- Transaction Identifiertokey
- fmt
- path stringarguments
- optional parameters for substitution in fmtConfException
IOException
public void moveOrdered(int tid, MoveWhereFlag where, ConfKey tokey, String fmt, Object... arguments) throws IOException, ConfException
tid
- current transactionwhere
- MoveWhereFlag movement flagtokey
- key as base for relative movementsfmt
- path stringarguments
- optional parameters for substitution in fmtIOException
ConfException
public void ncsApplyTemplate(int tid, String template, ConfPath rootIKP, Properties variables, boolean createShared, boolean createBackpointer) throws IOException, ConfException
IOException
ConfException
public void ncsApplyTemplate(int tid, String template, ConfPath rootIKP, Properties variables, String document, boolean createShared, boolean createBackpointer) throws IOException, ConfException
IOException
ConfException
public String[] ncsGetTemplateVariables(String template) throws IOException, ConfException
IOException
ConfException
public void ncsMovePrivateData(int initTid, ConfPath from, ConfPath to) throws IOException, ConfException
initTid
- the phase0 transaction retrieved by attachInitfrom
- the path to move the private data fromto
- the path to move the private data toIOException
ConfException
public Set<String> ncsTemplates() throws IOException, ConfException
IOException
ConfException
public MaapiCursor newCursor(int tid, ConfPath path) throws IOException, ConfException
Creates a cursor for an list specified by fmt
The MaapiCursor
is used to iterate keys over a list.
Whenever we wish to iterate over key entries we must first create a cursor.
The cursor instance is subsequently used in
getNext(MaapiCursor)
to retrieve the next key instance in
the list. When the cursor retrieves null the whole list has been
iterated and the cursor could not be reset.
tid
- current transaction idpath
- to a listIOException
ConfException
public MaapiCursor newCursor(int tid, String fmt, Object... arguments) throws IOException, ConfException
Creates a cursor for an list specified by fmt
The MaapiCursor
is used to iterate keys over a list.
Whenever we wish to iterate over key entries we must first create a cursor.
The cursor instance is subsequently used in
getNext(MaapiCursor)
to retrieve the next key instance in
the list. When the cursor retrieves null the whole list has been
iterated
A exhausted cursor could not be reset.
For example if we have:
module smp { namespace "http://tail-f.com/test"; prefix smp; import ietf-inet-types { prefix inet; } container servers { list server { key name; max-elements 64; leaf name { type string; } leaf ip { type inet:ip-address; mandatory true; } leaf port { type inet:port-number; mandatory true; } } } }Example usage:
MaapiCursor c = maapi.newCursor(th, "/mtest:mtest/servers/server"); ConfKey x; while((x = maapi.getNext(c)) != null) { ConfValue nameValue = maapi.getElem(th, "/mtest:mtest/servers/server{%x}/name",x); ConfValue ipValue = maapi.getElem(th, "/mtest:mtest/servers/server{%x}/ip",x); ConfValue portValue = maapi.getElem(th, "/mtest:mtest/servers/server{%x}/port",x); }
tid
- current transaction idfmt
- path string to a listarguments
- optional parameters for
substitution in fmtConfException
IOException
public void performUpgrade(String[] loadpathdirs) throws IOException, ConfException
loadpathdirs
- array of directoriesIOException
ConfException
public void popd(int tid) throws ConfException, IOException
tid
- Transaction IdentifierMaapiException
IOException
ConfException
public void prepareTrans(int tid) throws IOException, ConfException
commitTrans
or
abortTrans
must be
called.
It will invoke the prepare callback in all participants in the transaction. If all participants reply with OK, the second phase of the two-phase commit procedure is commenced.
tid
- Transaction IdentifierMaapiException
IOException
ConfException
public void prepareTrans(int tid, int flags) throws IOException, ConfException
commitTrans
or
abortTrans
must be
called.
It will invoke the prepare callback in all participants in the transaction. If all participants reply with OK, the second phase of the two-phase commit procedure is commenced.
For a definition of the flags, see applyTrans(int,boolean)
tid
- Transaction Identifierflags
- Bitwise ORed flagsMaapiException
IOException
ConfException
public void prioMessage(String to, String message) throws IOException, ConfException
to
- username, integer string session no or "all" for all usersmessage
- string message to sendIOException
ConfException
public void pushd(int tid, String fmt, Object... arguments) throws ConfException, IOException
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtMaapiException
IOException
ConfException
public <T extends ResultType> QueryResult<T> queryStart(int th, String expr, String context, int chunkSize, int offset, List<String> select, Class<T> cls) throws IOException, ConfException
th
.
Runs an XPath query with default sort order
If successful a
QueryResult
is returned which represents a query result.
th
- transaction handleexpr
- XPath expressioncontext
- A context nodechunkSize
- Result chunksize to fetchoffset
- The offset to start fetchselect
- A list of XPath "select" expressionscls
- Result typeIOException
- if the underlying socket or input stream is
closed for some reasonConfException
- if the XPath parser encounters error for some
reasonpublic <T extends ResultType> QueryResult<T> queryStart(int th, String expr, String context, int chunkSize, int offset, List<String> select, List<String> sort, boolean reverseSortOrder, Class<T> cls) throws IOException, ConfException
th
.
If successful a
QueryResult
is returned which represents a query result.
The XPath expr
string parameter is a primary XPath
expression which must evaluate to a node-set, the "results".
For each node in the results node-set every "select" expression is
evaluated with the result node as its context. For example,
given the YANG snippet:
list interface { key name; unique number; leaf name { type string; } leaf number { type uint32; mandatory true; } leaf enabled { type boolean; default true; } ... }and given that we want to find the name and number of all enabled interfaces - the expr could be
"/interface[enabled='true']"
, and the select
expressions would be { "name","number" }
.
Note that the select expressions can have any valid XPath expression,
so if you wanted to find out an interfaces name,
and whether its number is even or not, the expressions would be:
{ "name", "(number mod 2) == 0" }
.
The select
parameter determining what to
include in the result.
The chunksize
is
the possibility to return the result in groups of a particular size.
This option determines the fetch frequency for a iterator.
The "chunk" retrieval is done by the QueryResult.iterator()
iterator which process result locally and when it needs more
data it retrieve the next chunk (if available).
The offset
is the number of the first result in this
chunk (i.e. for the first chunk it will be 1).
If the underlying database supports multiple "tables" there is usually also support for "join" (the ability to make a filter span several tables), in ConfD/NCS this is usually not an issue - reference to "other" tables are naturally done using leafref, and thus it is possible to filter on "foreign keys" (to use SQL terminology).
th
- transaction handleexpr
- XPath expressioncontext
- A context nodechunkSize
- Result chunksize to fetchoffset
- The offset to start fetchselect
- A list of XPath "select" expressionssort
- A list of XPath exressions used for sortingreverseSortOrder
- Set this to true to get items in the reverse
order (only if "sort" is specified)cls
- Result typeIOException
- if the underlying socket or input stream is
closed for some reasonConfException
- if the XPath parser encounters error for some
reasonpublic void reloadConfig() throws IOException, ConfException
IOException
ConfException
public MaapiSchemas reloadSchemas() throws ConfException
Hence each call of this method will interact with the server.
MaapiException
ConfException
public MaapiSchemas reloadSchemas(String[] namespaceURIs) throws ConfException
Which namespaces are loaded is specified and do not need to be the same as the earlier loaded that is viped out. This method can therefore unload old schemas and add loading of new schemas.
namespaceURIs
- string array of URIs for the schemas to loadMaapiException
ConfException
public ConfXMLParam[] requestAction(ConfXMLParam[] params, int nshash, String fmt, Object... arguments) throws IOException, ConfException
requestAction(ConfXMLParam[], String, Object...)
Since actions are not associated with transactions, the
namespace hash nshash
must be provided and the path
to the action, i.e. the final element must be the name of the
action in the data model.
absolute - but see
requestActionTh(int,ConfXMLParam[],String,Object...)
.params
- action parametersnshash
- hashvalue for root namespace for the path represented by
the fmt
argumentfmt
- path stringarguments
- optional parameters for substitution in fmtConfException
IOException
public ConfXMLParam[] requestAction(ConfXMLParam[] params, String fmt, Object... arguments) throws IOException, ConfException
tailf:action
(see tailf_yang_extensions(5)).
The input parameters is specified as ConfXMLParam
as the input array param
which corresponds to
the input section of the action.
The output parameters returned from the method call returns
a array of ConfXMLParam
which corresponds to
the output section of the action.
Consider the following yang model:
module cs { namespace "http://example.com/test/cs/1.0"; prefix cs; import tailf-common { prefix tailf; } typedef math_op { type enumeration { enum add; enum sub; enum mul; enum div; enum square; } } container system { list computer { key name; leaf name { type string; } tailf:action math { tailf:actionpoint math_cs; input { list operation { min-elements 1; max-elements 3; leaf number { type int32; mandatory true; } leaf type { type math_op; mandatory true; } leaf-list operands { type int16; } } } output { container result { presence ""; leaf number { type int32; mandatory true; } leaf type { type math_op; mandatory true; } leaf value { type int16; mandatory true; } } } } } } }The following is a example of how to assemble the action parameters into and array of ConfXMLParam and its subclasses:
ConfNamespace n = new cs(); ConfXMLParam[] params = new ConfXMLParam[] { new ConfXMLParamStart(n, cs.cs_operation_), new ConfXMLParamValue(n, cs.cs_number_, new ConfInt32(13)), new ConfXMLParamValue(n, cs.cs_type_, new ConfEnumeration(0)), new ConfXMLParamValue(n, cs.cs_operands_, new ConfList(new ConfObject[] { new ConfInt16(13), new ConfInt16(25) })), new ConfXMLParamStop(n, cs.cs_operation_)};Using this we can call the action:
Maapi maapi = Maapi(socket); maapi.setNamespace( maapi.startUserSession("admin", InetAddress.getByName("localhost"), "maapi", new String[] { "admin" }, MaapiUserSessionFlag.PROTO_TCP); //Invokes the specified action with input arguments params //and returns the output parameters ConfXMLParam[] res = maapi.requestAction(params, "/system/computer{fred}/math");
The path given by fmt
and the varargs list
is the full path to the action, i.e. the final element must be the
name of the action element in the YANG model.
Since actions are not associated with transactions, the namespace
must be provided and the path must be absolute
transactions, the namespace must be provided and the path must be
absolute - but see
requestActionTh(int,ConfXMLParam[],String,Object...)
.
The Maapi
instance must have an established user
session before issue this method call.
params
- action input parametersfmt
- path string, this must be an absolute path with its
root element prefixed .i.e "/prefix:tagname/...."arguments
- optional parameters for substitution in fmtConfException
- If the methods invocation fails for some
reason. The errorCode or message could be obtain
through getErrorCode
, getMessage()
IOException
- Signals that a I/O
exception has occurred on the stream to ConfD/NCSpublic ConfXMLParam[] requestAction(List<ConfXMLParam> params, int nshash, String fmt, Object... arguments) throws IOException, ConfException
IOException
ConfException
public ConfXMLParam[] requestAction(List<ConfXMLParam> params, String fmt, Object... arguments) throws IOException, ConfException
requestAction(ConfXMLParam[], String, Object...)
with the difference that the params
is List
instead of ConfXMLParam
array.
The Maapi
instance must have an established user
session before issue this method call.
params
- action input parameters as List
fmt
- path string, this must be an absolute path with its
root element prefixed .i.e "/prefix:tagname/...."arguments
- optional parameters for substitution in fmtConfXMLParam
as the output parametersConfException
- If the methods invocation fails for some
reason. The errorCode or message could be obtain
through getErrorCode
, getMessage()
IOException
- Signals that a I/O
exception has occurred on the stream to ConfD/NCSpublic ConfXMLParam[] requestActionTh(int tid, ConfXMLParam[] params, String fmt, Object... arguments) throws IOException, ConfException
requestAction(ConfXMLParam[], String, Object...)
with the difference that the fmt is not required to have a namespace
prefix in the root tag. The root namespace is instead retrieved from
the transaction indicated by the tid argument.
Also, the user session of the transaction owner is used for the action
invocation.
This function may be convenient in some cases where actions are invoked
in conjunction with a transaction, and it must be used if the action
needs to access the transaction store.tid
- current transaction handleparams
- action parametersfmt
- path stringarguments
- optional parameters for substitution in fmtIOException
ConfException
public ConfXMLParam[] requestActionTh(int tid, List<ConfXMLParam> params, String fmt, Object... arguments) throws IOException, ConfException
IOException
ConfException
public void revert(int tid) throws IOException, ConfException
tid
- IOException
ConfException
public MaapiInputStream rollbackConfig(int tid, String fmt, String... args) throws MaapiException
tid
- transaction id for current transactionfmt
- path indicating where the configuration to be rootedargs
- variable argument list for c-style parameters in fmtPathMaapiException
public void safeCreate(int tid, ConfPath path) throws IOException, ConfException
tid
- Transaction Identifierpath
- ConfException
IOException
public void safeCreate(int tid, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtConfException
IOException
public void safeDelete(int tid, String fmt, Object... arguments) throws IOException, ConfException
Version of
delete
that doesn't throw an exception if the
element doesn't exist
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtConfException
IOException
public ConfValue safeGetElem(int tid, ConfPath path) throws IOException, ConfException
Reads a value from the path
specified
The path must lead to a leaf element in the data tree.
This is a equivalent method ofgetElem(int,String,Object[])
method which returns null if the element doesn't exist instead
of throwing a exception.
tid
- transaction handlepath
- leaf element in data treeConfException
IOException
public ConfValue safeGetElem(int tid, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtMaapiException
IOException
ConfException
public ConfObject[] safeGetObject(int tid, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifierfmt
- path stringarguments
- optional parameters for substitution in fmtMaapiException
IOException
ConfException
public MaapiInputStream saveConfig(int tid, EnumSet<MaapiConfigFlag> flags) throws ConfException, IOException
Retrieves an InputStream
with flags
parameter which controls the format as follows:
Flag | Description | |
Raw-XML | MaapiConfigFlag.XML_FORMAT ,
MaapiConfigFlag.MAAPI_CONFIG_XML
|
The configuration format is XML |
Pretty-XML | MaapiConfigFlag.XML_PRETTY ,
MaapiConfigFlag.MAAPI_CONFIG_XML_PRETTY
|
The configuration format is pretty printed XML |
Juniper CLI format | MaapiConfigFlag.MAAPI_CONFIG_J ,
MaapiConfigFlag.JUNIPER_CLI_FORMAT
|
The configuration is in curly brace Juniper CLI format |
Cisco XR CLI format | MaapiConfigFlag.MAAPI_CONFIG_C_IOS ,
MaapiConfigFlag.CISCO_XR_FORMAT
|
The configuration is in Cisco XR style format |
Cisco IOS CLI format | MaapiConfigFlag.MAAPI_CONFIG_C_IOS ,
MaapiConfigFlag.CISCO_IOS_FORMAT
|
The configuration is in Cisco IOS style format |
By default, the treatment of nodes with a tailf:hidden
statement depends on the state of the transaction. For a transaction
started via MAAPI, no nodes are hidden, while for a transaction started
by another northbound agent (e.g. CLI) and attached to, the nodes that
are hidden are the same as in that agent session. The default can be
overridden by using one of the flags
MaapiConfigFlag.MAAPI_CONFIG_HIDE_ALL
and
MaapiConfigFlag.MAAPI_CONFIG_UNHIDE_ALL
.
Entire configuration is dumped, except that namespaces with restricted export (from 'confdc/ncsc --export') are treated as follows:
When the MAAPI_CONFIG_XML or MAAPI_CONFIG_XML_PRETTY formats are used, the context of the user session that started the transaction is used to select namespaces with restricted export. If the "system" context is used, all namespaces are selected, regardless of export restriction.
When one of the CLI formats is used, the context used to select namespaces with restricted export is always "CLI".
The library will initialize a new socket to the end point specified by the initial socket (which was created during initialization of this Maapi instance) thus it is up to the use
tid
- transaction id of the current transactionflags
- format parameters (see the table above ) with additional
MAAPI_CONFIG_WITH_DEFAULTS
,
MAAPI_CONFIG_SHOW_DEFAULTS
for controlling
the defaultsConfException
- If the methods invocation fails for some
reason. The errorCode or message could be obtain
through getErrorCode
, getMessage()
IOException
- Signals that a I/O
exception has occurred on the stream to ConfD/NCSsaveConfig(int,EnumSet,ConfPath)
public MaapiInputStream saveConfig(int tid, EnumSet<MaapiConfigFlag> flags, ConfPath path) throws ConfException, IOException
Retrieves an InputStream
from a given path
specified by fmt
with flags
parameter
which controls the format as follows:
Flag | Description | |
Raw-XML | MaapiConfigFlag.XML_FORMAT ,
MaapiConfigFlag.MAAPI_CONFIG_XML
|
The configuration format is XML |
Pretty-XML | MaapiConfigFlag.XML_PRETTY ,
MaapiConfigFlag.MAAPI_CONFIG_XML_PRETTY
|
The configuration format is pretty printed XML |
Juniper CLI format | MaapiConfigFlag.MAAPI_CONFIG_J ,
MaapiConfigFlag.JUNIPER_CLI_FORMAT
|
The configuration is in curly brace Juniper CLI format |
Cisco XR CLI format | MaapiConfigFlag.MAAPI_CONFIG_C_IOS ,
MaapiConfigFlag.CISCO_XR_FORMAT
|
The configuration is in Cisco XR style format |
Cisco IOS CLI format | MaapiConfigFlag.MAAPI_CONFIG_C_IOS ,
MaapiConfigFlag.CISCO_IOS_FORMAT
|
The configuration is in Cisco IOS style format |
The provided path indicates from where the configuration is to be rooted. If for example fmt is "/aaa:aaa/authentication/users" we only dump a part of the AAA data. It must be a prefix pre pended keypath.
By default, the treatment of nodes with a tailf:hidden
statement depends on the state of the transaction. For a transaction
started via MAAPI, no nodes are hidden, while for a transaction started
by another northbound agent (e.g. CLI) and attached to, the nodes that
are hidden are the same as in that agent session. The default can be
overridden by using one of the flags
MaapiConfigFlag.MAAPI_CONFIG_HIDE_ALL
and
MaapiConfigFlag.MAAPI_CONFIG_UNHIDE_ALL
.
By default, the NCS service-meta-data attributes (refcounter,
backpointer, and original-value) are not included in the configuration.
The flag MaapiConfigFlag.MAAPI_CONFIG_WITH_SERVICE_META
can
be used to request that these attributes should be included.
The library will initialize a new socket to the end point specified by the initial socket (which was created during initialization of this Maapi instance) thus it is up to the use
tid
- transaction id of the current transactionflags
- format parameters (see the table above ) with additional
MAAPI_CONFIG_WITH_DEFAULTS
,
MAAPI_CONFIG_SHOW_DEFAULTS
for controlling
the defaultspath
- path indicating where the configuration to be rootedConfException
- If the methods invocation fails for some
reason. The errorCode or message could be obtain
through getErrorCode
, getMessage()
IOException
- Signals that a I/O
exception has occurred on the stream to ConfD/NCSpublic MaapiInputStream saveConfig(int tid, EnumSet<MaapiConfigFlag> flags, String fmt, Object... args) throws ConfException, IOException
Retrieves an InputStream
from a given path
specified by fmt
with flags
parameter
which controls the format as follows:
Flag | Description | |
Raw-XML | MaapiConfigFlag.XML_FORMAT ,
MaapiConfigFlag.MAAPI_CONFIG_XML
|
The configuration format is XML |
Pretty-XML | MaapiConfigFlag.XML_PRETTY ,
MaapiConfigFlag.MAAPI_CONFIG_XML_PRETTY
|
The configuration format is pretty printed XML |
Juniper CLI format | MaapiConfigFlag.MAAPI_CONFIG_J ,
MaapiConfigFlag.JUNIPER_CLI_FORMAT
|
The configuration is in curly brace Juniper CLI format |
Cisco XR CLI format | MaapiConfigFlag.MAAPI_CONFIG_C_IOS ,
MaapiConfigFlag.CISCO_XR_FORMAT
|
The configuration is in Cisco XR style format |
Cisco IOS CLI format | MaapiConfigFlag.MAAPI_CONFIG_C_IOS ,
MaapiConfigFlag.CISCO_IOS_FORMAT
|
The configuration is in Cisco IOS style format |
The provided path indicates from where the configuration is to be rooted. If for example fmt is "/aaa:aaa/authentication/users" we only dump a part of the AAA data. It must be a prefix pre pended keypath.
By default, the treatment of nodes with a tailf:hidden
statement depends on the state of the transaction. For a transaction
started via MAAPI, no nodes are hidden, while for a transaction started
by another northbound agent (e.g. CLI) and attached to, the nodes that
are hidden are the same as in that agent session. The default can be
overridden by using one of the flags
MaapiConfigFlag.MAAPI_CONFIG_HIDE_ALL
and
MaapiConfigFlag.MAAPI_CONFIG_UNHIDE_ALL
.
For MAAPI_CONFIG_XML and MAAPI_CONFIG_XML_PRETTY
it is alternatively possible to give an XPath filter, by
including the flag MaapiConfigFlag.MAAPI_CONFIG_XPATH
.
The library will initialize a new socket to the end point specified by the initial socket (which was created during initialization of this Maapi instance) thus it is up to the user to close the returning InputStream after reading the configuration.
tid
- transaction id of the current transactionflags
- format parameters (see the table above ) with additional
MAAPI_CONFIG_WITH_DEFAULTS
,
MAAPI_CONFIG_SHOW_DEFAULTS
for controlling
the defaultsfmt
- path indicating where the configuration to be rootedargs
- variable argument list for c-style parameters in fmtConfException
- If the methods invocation fails for some
reason. The errorCode or message could be obtain
through getErrorCode
, getMessage()
IOException
- Signals that a I/O
exception has occurred on the stream to ConfD/NCSsaveConfig(int,EnumSet,ConfPath)
public void setAttr(int tid, ConfAttributeValue attr, String fmt, Object... args) throws IOException, ConfException
tid
- current transactionattr
- ConfAttributeValue object denoting the attribute to setfmt
- path indicating node to retrieve attributes fromargs
- variable argument list for c-style parameters in fmtPathIOException
ConfException
public void setComment(int tid, String comment) throws IOException, ConfException
candidateCommitInfo(java.lang.String, java.lang.String)
method. For a confirmed commit, the "Comment" must also be given via the
candidateConfirmedCommitInfo(int, java.lang.String, java.lang.String)
method.tid
- Transaction Identifiercomment
- CommentMaapiException
IOException
ConfException
public boolean setDelayedWhen(int th, boolean on) throws IOException, ConfException
applyTrans(int, boolean)
.th
- transaction idon
- true if "delayed when" mode should be activated,
false if "delayed when" mode should be deactivated.IOException
ConfException
public void setElem(int tid, ConfObject value, ConfPath path) throws IOException, ConfException
There two different methods to set a value to a leaf node.
One where the value is a string and one where the value to set is a
ConfObject
. The string version
is useful when we have implemented a management agent where the user
enters values as strings.
The version with ConfObject
is useful when we
are setting values which we have just read from various API methods
that returns ConfObject
.
tid
- Transaction Identifiervalue
- path
- IOException
ConfException
public void setElem(int tid, ConfObject value, String fmt, Object... arguments) throws IOException, ConfException
There two different methods to set a value to a leaf node.
One where the value is a string and one where the value to set is a
ConfObject
. The string version
is useful when we have implemented a management agent where the user
enters values as strings.
The version with ConfObject
is useful when we
are setting values which we have just read from various API methods
that returns ConfObject
.
tid
- Transaction Identifiervalue
- fmt
- path stringarguments
- optional parameters for substitution in fmtIOException
ConfException
public void setElem(int tid, String value, ConfPath path) throws IOException, ConfException
There two different methods to set a value to a leaf node.
One where the value is a string and one where the value to set is a
ConfObject
. The string version
is useful when we have implemented a management agent where the user
enters values as strings.
The version with ConfObject
is useful when we
are setting values which we have just read from various API methods
that returns ConfObject
.
tid
- Transaction Identifiervalue
- path
- ConfPath instanceIOException
ConfException
public void setElem(int tid, String value, String fmt, Object... arguments) throws IOException, ConfException
There two different methods to set a value to a leaf node.
One where the value is a string and one where the value to set is a
ConfObject
. The string version
is useful when we have implemented a management agent where the user
enters values as strings.
The version with ConfObject
is useful when we
are setting values which we have just read from various API methods
that returns ConfObject
.
tid
- Transaction Identifiervalue
- fmt
- path stringarguments
- optional parameters for substitution in fmtIOException
ConfException
public void setFlags(int tid, EnumSet<MaapiFlag> flags) throws IOException, ConfException
MaapiFlag
tid
- current transactionflags
- Enumset of MaapiFlag
IOException
ConfException
public void setLabel(int tid, String label) throws IOException, ConfException
candidateCommitInfo(java.lang.String, java.lang.String)
method. For a confirmed commit, the "Label" must also be given via the
candidateConfirmedCommitInfo(int, java.lang.String, java.lang.String)
method.tid
- Transaction Identifierlabel
- LabelMaapiException
IOException
ConfException
public void setNamespace(int tid, int nsid) throws IOException, ConfException
IOException
ConfException
public void setNamespace(int tid, String ns) throws IOException, ConfException
The ns string is the namespace URL
tid
- Transaction Identifierns
- Namespace uriMaapiException
IOException
ConfException
public void setObject(int tid, ConfObject[] values, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifiervalues
- fmt
- path stringarguments
- optional parameters for substitution in fmtMaapiException
IOException
ConfException
public void setReadOnlyMode(boolean flag) throws ConfException, IOException
flag
- ModeConfException
IOException
public void setRunningDbStatus(int status) throws IOException, ConfException
ConfException
IOException
public void setUserSession(int usid) throws ConfException, IOException
This can be used instead
startUserSession(String,InetAddress, String, String[],
MaapiUserSessionFlag)
when we really do not want to start a new user session, e.g. if we want
to call an action on behalf of a given user session
usid
- user session idMaapiException
ConfException
IOException
public void setValues(int th, ConfXMLParam[] params, ConfPath path) throws IOException, ConfException
params
- path
- IOException
ConfException
public void setValues(int th, ConfXMLParam[] params, String fmt, Object... arguments) throws IOException, ConfException
params
- fmt
- arguments
- IOException
ConfException
public void setValues(int th, List<ConfXMLParam> params, ConfPath path) throws IOException, ConfException
params
- path
- IOException
ConfException
public void setValues(int th, List<ConfXMLParam> params, String fmt, Object... arguments) throws IOException, ConfException
params
- fmt
- arguments
- IOException
ConfException
public void sharedCreate(int tid, boolean createBackpointer, ConfPath path) throws IOException, ConfException
tid
- Transaction IdentifiercreateBackpointer
- path
- ConfException
IOException
public void sharedCreate(int tid, ConfPath path) throws IOException, ConfException
IOException
ConfException
public void sharedCreate(int tid, String fmt, Object... arguments) throws IOException, ConfException
IOException
ConfException
public void sharedSetElem(int tid, ConfObject value, ConfPath path) throws IOException, ConfException
tid
- Transaction Identifiervalue
- path
- IOException
ConfException
public void sharedSetElem(int tid, ConfObject value, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifiervalue
- fmt
- path stringarguments
- optional parameters for substitution in fmtIOException
ConfException
public void sharedSetElem(int tid, String value, String fmt, Object... arguments) throws IOException, ConfException
tid
- Transaction Identifiervalue
- fmt
- path stringarguments
- optional parameters for substitution in fmtIOException
ConfException
public void sharedSetValues(int th, ConfXMLParam[] params, boolean createBackpointer, ConfPath path) throws IOException, ConfException
params
- createBackpointer
- path
- IOException
ConfException
public void sharedSetValues(int th, ConfXMLParam[] params, ConfPath path) throws IOException, ConfException
params
- path
- IOException
ConfException
public void sharedSetValues(int th, ConfXMLParam[] params, String fmt, Object... arguments) throws IOException, ConfException
params
- fmt
- arguments
- IOException
ConfException
public void sharedSetValues(int th, List<ConfXMLParam> params, ConfPath path) throws IOException, ConfException
params
- path
- IOException
ConfException
public void sharedSetValues(int th, List<ConfXMLParam> params, String fmt, Object... arguments) throws IOException, ConfException
params
- fmt
- arguments
- IOException
ConfException
public void snmpSendNotification(String notifName, String notifyTarget, String ctxName, SnmpVarbind[] varbinds) throws ConfException
Sends a notification to the management targets defined for 'notifyTarget' in the snmpNotifyTable in SNMP-NOTIFICATION-MIB from the specified context. If no NotifyName is specified (or if it is ""), the notification is sent to all management targets.
notifName
- Notification namenotifyTarget
- Notification target namectxName
- Context name.varbinds
- An array of variable bindingsConfException
public void startPhase(int phase) throws IOException, ConfException
phase
- Which start phase to proceed to, 1 or 2IOException
ConfException
public void startPhase(int phase, boolean synchronous) throws IOException, ConfException
phase
- Which start phase to proceed to, 1 or 2synchronous
- Whether to wait for the daemon to complete the
transition to the requested start phase or return immediately.IOException
ConfException
public int startTrans(int dbname, int mode) throws IOException, ConfException
dbname
with a transaction mode mode
.
The main purpose of MAAPI is to provide read and write access into the transaction manager. Regardless of whether data is kept in CDB or in some* (or several) external data bases, the same API is used to access data.
ConfD/NCS acts as a mediator and multiplexes the different commands to the code which is responsible for each individual data element.
This function creates a new transaction towards a specified data
base. If successful, it returns a new transaction identifier,
a tid which must be used as a parameter in most of the
Maapi
methods which manipulate the transaction.
We will drive this transaction forward through the different states a
transaction goes through. If an external database is used, and it has
registered callback functions for the different transaction states, those
callbacks will be called when we in MAAPI invoke the different MAAPI
transaction manipulation functions. For example when we call
startTrans
the init
callback will be invoked
in all external databases. If data is kept in CDB, the system will
handle everything internally.
The parameter dbname
is supplied using on of
Conf.DB_STARTUP
,Conf.DB_RUNNING
,Conf.DB_CANDIDATE
Transaction mode mode
is supplied using
Conf.MODE_READ
, to start a read only transaction
Conf.MODE_READ_WRITE
to start a read write transaction.
A read only transaction will incur less resource usage, thus if no
writes will be done (e.g. the purpose of the transaction is only
to read operational data), it is best to use
Conf.MODE_READ
.
There are also some cases where starting a read-write transaction is not allowed, e.g. if we start a transaction towards the running data store is set to "writable-through-candidate" in confd.conf/ncs.conf, or if ConfD/NCS is running in HA slave mode.
dbname
- Database that the transaction should operate on.mode
- Read or write mode.MaapiException
- If the transaction could not be started
see the Throwable.getMessage()
IOException
- Signals I/O exception on the underlying socketConfException
public int startTrans(int dbname, int mode, String vendor, String product, String version, String clientId) throws IOException, ConfException
IOException
ConfException
public int startTrans2(int dbname, int mode, int usid) throws IOException, ConfException
usid
.
If we want to start new transactions inside actions, we can use this function to execute the new transaction within the existing user session.
See startTrans(int,int)
for available
options on dbname
and mode mode
.
dbname
- Database that the transaction should operate onmode
- Read or write modeusid
- The user session idMaapiException
- If the transaction could not be started
see the Throwable.getMessage()
IOException
- Signals I/O exception on the underlying socketConfException
public int startTransFlags(int dbname, int mode, int usid, EnumSet<MaapiFlag> flags) throws IOException, ConfException
dbname
with a transaction mode mode
with
additional flags
to control read/write sessions.
This method makes it possible to provide flags that can otherwise be
used with setFlags(int,EnumSet)
already when starting a
transaction, as well as setting the MaapiFlag.HIDE_INACTIVE
flag that can only be used with this function.
Otherwise its has functionality equivalent to Maapi.startTrans2().
dbname
- Database that the transaction should operate on. Possible
values are STARTUP, RUNNING, CANDIDATEmode
- Read or write mode. Possible values are READ and READ_WRITEusid
- User session idflags
- EnumSet of MaapiFlag values.IOException
ConfException
public int startTransInTrans(int mode, int usid, int th) throws IOException, ConfException
mode
- Read or write mode. Possible values are READ and READ_WRITEusid
- User session idth
- Backend transaction idMaapiException
IOException
ConfException
public void startUserSession(String user, InetAddress srcip, String context, String[] groups, MaapiUserSessionFlag proto) throws IOException, ConfException
Maapi
instance.
Once we have created a Maapi
communication instance,
we must also establish a user session.
It is up to the user of the Maapi
class to
authenticate users.
Maapi
can be used to to perform the actual
authentication through a call to authenticate(String,String)
but authentication may very well occur through some other
external means.
Thus, when we use this function to create a user session, we must provide all relevant information about the user. If we wish to execute read/write transactions over the MAAPI interface, we must first have an established user session.
A user session corresponds to a NETCONF manager who has just established an authenticated SSH connection, but not yet sent any NETCONF commands on the SSH connection.
The user
string is the login name of the user.
The user name is used when setting up the AAA environment for the
session.
The srcip
address specifies from where
did the session originate.
The context
parameter can be any string which is
precisely the context
string which will be
used to authorize all data access through the AAA system.
Each AAA rule has a context string which must match in order for a
AAA rule to match. (See the AAA chapter in the User Guide).
Using the string "system" for context has special significance:
'confd --status'
or
'ncs --status'
, nor 'show users'
in CLI etc.
It is not possible to create new user sessions until the system has reached start phase 2 with the above exception of a session with the context set to "system".
The photo
parameter specifies the protocol used
by the user for connecting to the device. Can be
one of MaapiUserSessionFlag.PROTO_SSH
,
MaapiUserSessionFlag.PROTO_CONSOLE
,
MaapiUserSessionFlag.PROTO_TCP
, and
MaapiUserSessionFlag.PROTO_SSL
user
- Login name of usersrcip
- Source ip where the user session originatecontext
- The context string parameter stated discussed above.groups
- An array of AAA groups that the user belongs to.proto
- Protocol used by the user for connecting to the device..MaapiException
- If ConfD/NCS could not create a new
session based on the parameters. To get detailed message
use Throwable.getMessage()
Signals
- I/O exception on the underlying socketIOException
ConfException
public void startUserSession(String user, InetAddress srcip, String context, String[] groups, MaapiUserSessionFlag proto, String vendor, String product, String version, String clientId) throws IOException, ConfException
IOException
ConfException
public void stop() throws IOException, ConfException
IOException
ConfException
public void stop(boolean synchronous) throws IOException, ConfException
synchronous
- Whether to wait for the daemon to stopIOException
ConfException
public void sysMessage(String to, String message) throws IOException, ConfException
to
- username, integer string session no or "all" for all usersmessage
- string message to sendIOException
ConfException
public void unlock(int db) throws IOException, ConfException
db
- Database to unlock. Possible values are STARTUP, RUNNING, and
CANDIDATEConfException
IOException
public void unlockPartial(int lockId) throws IOException, ConfException
lockId
- The previously specified lock identifierConfException
IOException
public void userMessage(String to, String message, String sender) throws IOException, ConfException
to
- username, integer string session no or "all" for all usersmessage
- string message to sendsender
- stringIOException
ConfException
public void validateTrans(int tid, boolean unlock, boolean force) throws IOException, ConfException
This method validates all data written in the transaction. This includes all XML checks, checking for uniqueness and dangling pointers. It also includes all defined semantic validation, i.e. user programs that have registered functions under validation points. (See user manual chapter Semantic Validation).
If this method throws an exception due to a validation error, the
transaction is still open for further editing. If unlock is true, the
transaction is open for further editing even if validation succeeds. If
unlock is false and the method returns, the next method to be called
MUST be prepareTrans(int)
or
finishTrans(int)
.
unlock = true can be used to implement a 'validate' command which can be
given in the middle of an editing session. The first thing that happens
is that a lock is set. If unlock = true, the lock is released on success.
The lock is always released on failure.
The force parameter should normally be false.
It has no effect for a transaction towards the running or
startup data stores, validation is always performed.
For a transaction towards the candidate data store, validation will
not be done unless force true. Avoiding this validation is preferable if
we are going to commit the candidate to running
e.g with candidateCommit()
, since otherwise the validation
will be done twice. However if we are implementing a 'validate' command,
we should set force = true
tid
- Transaction Identifierunlock
- if true the transaction is open for further editingforce
- if true validation will performed also for
candidate data storeMaapiException
IOException
ConfException
public void waitStart(int phase) throws IOException, ConfException
phase
- Which start phase to wait for: 0, 1, or 2IOException
ConfException
public void waitStarted() throws IOException, ConfException
IOException
ConfException
public ConfPath xpath2kpath(String xpath) throws IOException, ConfException
xpath
- IOException
ConfException
public void xpathEval(int th, MaapiXPathEvalResult xpatheval, MaapiXPathEvalTrace xpathtrace, String expr, Object initstate, String fmt, Object... arguments) throws IOException, ConfException
Evaluated the xpath expression as supplied in by
expr
.
result(ConfObject[],ConfValue,Object)
method of @see MaapiXPathEvalResult
is called
with the keypath (as ConfObject[]
) to the resulting
node as the first argument,
and, if the node is a leaf and has a
value (as ConfValue
), the value of that node
as the second argument otherwise it will return the string "undefined".
The expression will be evaluated using the root node as the context node, unless a path to an existing node is given as the fmt argument.
For each invocation the
result
method should return
ITER_CONTINUE
to tell the
xpath evaluator to continue with the
next resulting node. To stop the evaluation the result
can return ITER_STOP
instead.
The MaapiXPathEvalTrace
implementation of
a method trace(String)
that takes a
single string as argument.
If supplied (optional) it will be invoked when the xpath evaluator has trace output for the current expression.
Theinitstate
parameter can be used for any user
supplied opaque
data (i.e. whatever is supplied as initstate is passed as state
to the result
method for each invocation).th
- Transaction handlexpatheval
- A implementation of MaapiXPathEvalResult
callback methodxpathtrace
- A implementation of MaapiXPathEvalTrace
or
null if no trace is wantedexpr
- The XPath expressionfmt
- Path string (context node) root if not suppliedarguments
- Optional parameters for substitution in fmtMaapiException
- Failed MaapiXPathEvaluateIOException
- Failed to read/write maapi socketConfException
public String xpathEvalExpr(int th, String expr, MaapiXPathEvalTrace xpathtrace, String fmt, Object... arg) throws IOException, ConfException
expr
parameter
and return the result as a string.
It is possible to supply a path fmt
(optional) which will
be treated as the initial context node when evaluating expr.
If the path is relative, this is treated as the starting point,
and this is also the node that current()
will return
when used in the xpath expression.
If null is given, the current maapi position is used
(set by cd(int,String,Object...)
)
The MaapiXPathEvalTrace
implementation of
the method trace(String)
which
takes a single string as argument (optional) will be
invoked if supplied (optional) when the xpath implementation has
trace output for the current expression.
th
- Transaction handleexpr
- The xpath expressionxpathtrace
- A implementation of MaapiXPathEvalTrace
or null if no trace is wanted
A implementation of MaapiXPathEvalTrace
or null
if no trace is wantedfmt
- Path string (context node) root if not suppliedarg
- Optional parameters for substitution in fmtConfException
- Failed MaapiXPathEvaluateIOException
- Failed to read/write maapi socket