Class CdbUpgradeSession
CdbUpgradeSession
represents a session against
the Cdb database that can be used for accessing data models that are
in the process of being deleted by a cdb upgrade.
The operations supported by an upgrade session are the same as those
of a normal session, the only difference being that keypaths on the
format (fmt, arguments) will be treated as ConfCdbUpgradePaths
rather than ConfPaths.
For information on specific methods, refer to the
CdbSession
documentation.-
Constructor Summary
ConstructorDescriptionCdbUpgradeSession
(Cdb cdb) CdbUpgradeSession
(Cdb cdb, CdbDBType dbtype) CdbUpgradeSession
(Cdb cdb, CdbDBType dbtype, EnumSet<CdbLockType> lockflags) -
Method Summary
Modifier and TypeMethodDescriptionvoid
cd
(ConfCdbUpgradePath path) void
Change working directory to container specified by path stringvoid
create
(ConfCdbUpgradePath path) void
similar toCdbSession.create(ConfPath)
but specifies element using path stringvoid
delete
(ConfCdbUpgradePath path) void
similar toCdbSession.delete(ConfPath)
but specifies element using path stringboolean
exists
(ConfCdbUpgradePath path) boolean
Checks whether an element exists.getCase
(String choice, ConfCdbUpgradePath path) Retrieve the currently selected case.getElem
(ConfCdbUpgradePath path) similar toCdbSession.getElem(ConfPath)
but specifies element using path stringint
int
getNumberOfInstances
(String fmt, Object... arguments) similar toCdbSession.getNumberOfInstances(ConfPath)
but specifies element using path stringgetObject
(int numOfObjects, ConfCdbUpgradePath path) In some cases it can be motivated to read multiple values in one request - this will be more efficient since it only incurs a single round trip to the server, but usage is a bit more complex.List<ConfObject[]>
getObjects
(int numOfObjects, int instance, int numOfInstances, ConfCdbUpgradePath path) List<ConfObject[]>
getObjects
(int numOfObjects, int instance, int numOfInstances, String fmt, Object... arguments) Similar to cdb.getObject(), but reads multiple instances of a dynamic container based on the "instance integer" otherwise given within square brackets in the path - here the path must specify the dynamic container without the instance integer.getValues
(ConfXMLParam[] params, ConfCdbUpgradePath path) getValues
(ConfXMLParam[] params, String fmt, Object... arguments) Read an arbitrary set of sub-elements of a container element.int
index
(ConfCdbUpgradePath path) int
similar toCdbSession.index(ConfPath)
but specifies element using path stringboolean
isDefault
(ConfCdbUpgradePath path) boolean
similar toCdbSession.isDefault(ConfPath)
but specifies element using path stringint
nextIndex
(ConfCdbUpgradePath path) int
similar toCdbSession.nextIndex(ConfPath)
but specifies element using path stringvoid
pushd
(ConfCdbUpgradePath path) void
similar toCdbSession.pushd(ConfPath)
but specifies position using path stringvoid
setCase
(String choice, String scase, ConfCdbUpgradePath path) void
When we use the YANG choice construct in the data model, this function can be used to select the current case.void
setElem
(ConfValue value, ConfCdbUpgradePath path) void
similar toCdbSession.setElem(ConfValue, ConfPath)
but specifies element using path stringvoid
setObject
(ConfValue[] values, ConfCdbUpgradePath path) void
similar toCdbSession.setObject(ConfValue[], ConfPath)
but specifies element using path stringvoid
setValues
(ConfXMLParam[] params, ConfCdbUpgradePath path) void
setValues
(ConfXMLParam[] params, String fmt, Object... arguments) similar toCdbSession.setValues(ConfXMLParam[], ConfPath)
but specifies element using path stringtoString()
Methods inherited from class com.tailf.cdb.CdbSession
cd, create, delete, endSession, exists, getCase, getCdb, getcwd, getcwdPath, getDbType, getElem, getNumberOfInstances, getObject, getObjects, getValues, index, isDefault, nextIndex, numInstances, numInstances, popd, pushd, setCase, setElem, setNamespace, setObject, setValues, setValues
-
Constructor Details
-
CdbUpgradeSession
- Throws:
IOException
ConfException
-
CdbUpgradeSession
- Throws:
ConfException
IOException
-
CdbUpgradeSession
public CdbUpgradeSession(Cdb cdb, CdbDBType dbtype, EnumSet<CdbLockType> lockflags) throws ConfException, IOException - Throws:
ConfException
IOException
-
-
Method Details
-
exists
- Throws:
ConfException
IOException
-
exists
Description copied from class:CdbSession
Checks whether an element exists. The element is specified using a path string and optionally string substitution parameters- Overrides:
exists
in classCdbSession
- Parameters:
fmt
- path stringarguments
- optional parameters for substitution in fmt- Returns:
- true if exists
- Throws:
ConfException
IOException
-
cd
- Throws:
ConfException
IOException
-
cd
Description copied from class:CdbSession
Change working directory to container specified by path string- Overrides:
cd
in classCdbSession
- Parameters:
fmt
- path stringarguments
- optional parameters for substitution in fmt- Throws:
ConfException
IOException
-
pushd
- Throws:
ConfException
IOException
-
pushd
Description copied from class:CdbSession
similar toCdbSession.pushd(ConfPath)
but specifies position using path string- Overrides:
pushd
in classCdbSession
- Parameters:
fmt
- path stringarguments
- optional parameters for substitution in fmt- Throws:
ConfException
IOException
-
getNumberOfInstances
- Throws:
ConfException
IOException
-
getNumberOfInstances
Description copied from class:CdbSession
similar toCdbSession.getNumberOfInstances(ConfPath)
but specifies element using path string- Overrides:
getNumberOfInstances
in classCdbSession
- Parameters:
fmt
- path stringarguments
- optional parameters for substitution in fmt- Returns:
- number of instances
- Throws:
ConfException
IOException
-
nextIndex
- Throws:
ConfException
IOException
-
nextIndex
Description copied from class:CdbSession
similar toCdbSession.nextIndex(ConfPath)
but specifies element using path string- Overrides:
nextIndex
in classCdbSession
- Parameters:
fmt
- path stringarguments
- optional parameters for substitution in fmt- Returns:
- position of next key
- Throws:
ConfException
IOException
-
index
- Throws:
ConfException
IOException
-
index
Description copied from class:CdbSession
similar toCdbSession.index(ConfPath)
but specifies element using path string- Overrides:
index
in classCdbSession
- Parameters:
fmt
- path stringarguments
- optional parameters for substitution in fmt- Returns:
- position of key
- Throws:
ConfException
IOException
-
isDefault
- Throws:
ConfException
IOException
-
isDefault
Description copied from class:CdbSession
similar toCdbSession.isDefault(ConfPath)
but specifies element using path string- Overrides:
isDefault
in classCdbSession
- Parameters:
fmt
- path stringarguments
- optional parameters for substitution in fmt- Returns:
- true/false if a leaf has a default value defined
- Throws:
ConfException
IOException
-
getElem
- Throws:
ConfException
IOException
-
getElem
Description copied from class:CdbSession
similar toCdbSession.getElem(ConfPath)
but specifies element using path string- Overrides:
getElem
in classCdbSession
- Parameters:
fmt
- path stringarguments
- optional parameters for substitution in fmt- Returns:
- element represented by a ConfValue
- Throws:
ConfException
IOException
-
setElem
- Throws:
ConfException
IOException
-
setElem
public void setElem(ConfValue value, String fmt, Object... arguments) throws ConfException, IOException Description copied from class:CdbSession
similar toCdbSession.setElem(ConfValue, ConfPath)
but specifies element using path string- Overrides:
setElem
in classCdbSession
fmt
- path stringarguments
- optional parameters for substitution in fmt- Throws:
ConfException
IOException
-
create
- Throws:
ConfException
IOException
-
create
Description copied from class:CdbSession
similar toCdbSession.create(ConfPath)
but specifies element using path string- Overrides:
create
in classCdbSession
- Parameters:
fmt
- path stringarguments
- optional parameters for substitution in fmt- Throws:
ConfException
IOException
-
delete
- Throws:
IOException
ConfException
-
delete
Description copied from class:CdbSession
similar toCdbSession.delete(ConfPath)
but specifies element using path string- Overrides:
delete
in classCdbSession
- Parameters:
fmt
- path stringarguments
- optional parameters for substitution in fmt- Throws:
IOException
ConfException
-
getObject
public ConfObject[] getObject(int numOfObjects, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOException
ConfException
-
getObject
public ConfObject[] getObject(int numOfObjects, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSession
In some cases it can be motivated to read multiple values in one request - this will be more efficient since it only incurs a single round trip to the server, but usage is a bit more complex. This function reads at most numOfObjects values from the container element specified by the path, and returns them in an array. When reading from a container with mixed configuration and operational data (i.e. a config container that has some number of operational elements), some elements will have the "wrong" type - i.e. operational data in a session for CDB_RUNNING/CDB_STARTUP, or config data in a session for CDB_OPERATIONAL. Leaf elements of the "wrong" type will have a "value" of ConfNoExists in the array, while static or (existing) optional sub-container elements will have ConfXMLTag in all cases. Sub-containers or leafs provided by external data providers will always be represented with ConfNoExists, whether config or not. On success, the function returns the actual number of elements in the container. I.e. if the return value is bigger than n, only the values for the first n elements are in the array, and the remaining values have been discarded. Note that given the specification of the array contents, there is always a fixed upper bound on the number of actual elements, and if there are no optional sub-containers, the number is constant. As an example, this code could be used to read the values for interface "eth0" on host "buzz":String path = "/mtest/servers/server{www}/interface{%s}"; ConfObject[] objArr = cdbsess.getObject(4, path, "eth0"); ConfBuf name = (ConfBuf) objArr[0]; ConfInt64 mtu = (ConfInt64) objArr[1];
- Overrides:
getObject
in classCdbSession
- Parameters:
numOfObjects
- number of objects to retrieve- Returns:
- ConfObject[]
- Throws:
IOException
ConfException
-
getObjects
public List<ConfObject[]> getObjects(int numOfObjects, int instance, int numOfInstances, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOException
ConfException
-
getObjects
public List<ConfObject[]> getObjects(int numOfObjects, int instance, int numOfInstances, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSession
Similar to cdb.getObject(), but reads multiple instances of a dynamic container based on the "instance integer" otherwise given within square brackets in the path - here the path must specify the dynamic container without the instance integer. At most numOfObject values from each of numOfInstances instances, starting at instance instance, are read and placed in a List of arrays of objects. The List contains an array for each instance, to at most numOfInstances and the arrays are at most numOfObjects large. On success, the highest actual number of values in any of the instances read is returned. An exception with code ConfException.ERR_NOEXISTS will be returned if we attempt to read more instances than actually exist (i.e. if instance + nobj - 1 is outside the range of actually existing instances). Example - read the data for all interfaces on the host "buzz":String path = "/mtest/servers/server"; int n = cdbsess.numInstances(path); List<ConfObject[]> objArrList = cdbsess.getObjects(4, 0, n, path); ConfBuf[] name = new ConfBuf[n]; ConfIPv4[] ip = new ConfIPv4[n]; ConfUInt16[] port = new ConfUInt16[n]; for (int i = 0; i < objArrList.size(); i++) { ConfObject[] objArr = objArrList.get(i); name[i] = (ConfBuf) objArr[0]; ip[i] = (ConfIPv4) objArr[1]; port[i] = (ConfUInt16) objArr[2]; }
- Overrides:
getObjects
in classCdbSession
- Parameters:
numOfObjects
- number of objects to retrieveinstance
- instance integernumOfInstances
- number if instances to retrieve- Returns:
- List<ConfObject[]>
- Throws:
IOException
ConfException
-
setObject
public void setObject(ConfValue[] values, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOException
ConfException
-
setObject
public void setObject(ConfValue[] values, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSession
similar toCdbSession.setObject(ConfValue[], ConfPath)
but specifies element using path string- Overrides:
setObject
in classCdbSession
fmt
- path stringarguments
- optional parameters for substitution in fmt- Throws:
IOException
ConfException
-
setValues
public void setValues(ConfXMLParam[] params, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOException
ConfException
-
setValues
public void setValues(ConfXMLParam[] params, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSession
similar toCdbSession.setValues(ConfXMLParam[], ConfPath)
but specifies element using path string- Overrides:
setValues
in classCdbSession
- Throws:
IOException
ConfException
-
getValues
public ConfXMLParam[] getValues(ConfXMLParam[] params, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOException
ConfException
-
getValues
public ConfXMLParam[] getValues(ConfXMLParam[] params, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSession
Read an arbitrary set of sub-elements of a container element. The values array must be pre-populated with ConfXMLParam with or without an subArray of derived elements. The ConfXMLParam array can point to a location using a path or by the use of the derived element ConfXMLParamCdbStart carry the instance identification in it. 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 did not exist will have ConfNoExists value rather than being omitted from the array. However requesting a dynamic container that does not exist, or requesting non-CDB data, or operational vs config data, is an error. In this rather complex example we first read only the "name" and "enabled" values for all interfaces, and then read "ip" and "mask" for those that were enabled - a total of two requests. Note that since the "interface" container begin/end elements are in the array, the path must not include the "interface" component. When reading values from a single container, it is generally simpler to have the container component (and keys or instance integer) in the path instead.String path = "/mtest/servers/server"; int n = cdbsess.getNumberOfInstances(path); List<ConfObject[]> objArrList = cdbsess.getObjects(4,0,n,path); //when reading ip/port, we need 5 elements per interface: //begin + name (key) + ip + port + end ConfXMLParam[] values = new ConfXMLParam[5*n]; int j = 0; for (int i=0; i<n; i++) { values[j++] = new ConfXMLParamCdbStart(ns, "server", i); values[j++] = new ConfXMLParamLeaf(ns, "name"); values[j++] = new ConfXMLParamLeaf(ns, "ip"); values[j++] = new ConfXMLParamLeaf(ns, "port"); values[j++] = new ConfXMLParamStop(ns, "server"); } path = "/mtest/servers"; ConfXMLParam[] resvalues = cdbsess.getValues(values, path); // extract name for enabled interfaces String name = null; int noOfInterfaces = 0; for (int i = 0; i < n; i++) { ConfIPv4 ip4 = (ConfIPv4) resvalues[i*5+2].getValue(); name = resvalues[i*5+1].getValue().toString(); path = "/mtest/servers/server{%s}/interface"; noOfInterfaces = cdbsess.getNumberOfInstances(path, name); System.out.println("name = "+ name); } int n_if = j; j = 0; values = new ConfXMLParam[noOfInterfaces*4]; for (int i=0; i<noOfInterfaces; i++) { values[j++] = new ConfXMLParamCdbStart(ns.hash(), ns.mtest_interface, i); values[j++] = new ConfXMLParamLeaf(ns.hash(), ns.mtest_name); values[j++] = new ConfXMLParamLeaf(ns.hash(), ns.mtest_mtu); values[j++] = new ConfXMLParamStop(ns.hash(), ns.mtest_interface); } path = "/mtest/servers/server{%s}"; resvalues = cdbsess.getValues(values, path, name); ...
- Overrides:
getValues
in classCdbSession
- Returns:
- ConfXMLParam[]
- Throws:
IOException
ConfException
-
getCase
- Throws:
IOException
ConfException
-
getCase
public ConfObject getCase(String choice, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSession
Retrieve the currently selected case.
When we use the YANG choice construct in the data model, this method can be used to find the currently selected case, avoiding useless
CdbSession.getElem(ConfPath)
etc requests for elements that belong to other cases.The
fmt
give the path to the container where the choice is defined,The
choice
is the name of the choice. The case value is returned as typeConfTag
.If no case is currently selected (i.e. for an optional choice that does not have a default case), the function will fail with a an exception with code
ConfException.ERR_NOEXISTS
.- Overrides:
getCase
in classCdbSession
- Parameters:
choice
- the name of the choicefmt
- format string pointing to the choicearguments
- replacement arguments for fmt string- Returns:
- ConfObject case value as
ConfTag
- Throws:
IOException
ConfException
-
setCase
public void setCase(String choice, String scase, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOException
ConfException
-
setCase
public void setCase(String choice, String scase, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSession
When we use the YANG choice construct in the data model, this function can be used to select the current case.
When configuration data is modified by northbound agents, the current case is implicitly selected (and elements for other cases potentially deleted) by the setting of elements in a choice.
For operational data in CDB however, this is under direct control of the application, which needs to explicitly set the current case. Setting the case will also automatically delete elements belonging to other cases, but it is up to the application to not set any elements in the "wrong" case. The fmt, ... arguments give the path to the container where the choice is defined, and choice and scase are the choice and case names. For an optional choice, it is possible to have no case at all selected. To indicate that the previously selected case should be deleted without selecting another case, we can pass NULL for the scase argument.
- Overrides:
setCase
in classCdbSession
- Parameters:
choice
- choice stringscase
- case stringfmt
- format string pointing to the choicearguments
- replacement arguments for fmt string- Throws:
IOException
ConfException
-
toString
- Overrides:
toString
in classCdbSession
-