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
ConstructorsConstructorDescriptionCdbUpgradeSession(Cdb cdb) CdbUpgradeSession(Cdb cdb, CdbDBType dbtype) CdbUpgradeSession(Cdb cdb, CdbDBType dbtype, EnumSet<CdbLockType> lockflags) -
Method Summary
Modifier and TypeMethodDescriptionvoidcd(ConfCdbUpgradePath path) voidChange working directory to container specified by path stringvoidcreate(ConfCdbUpgradePath path) voidsimilar toCdbSession.create(ConfPath)but specifies element using path stringvoiddelete(ConfCdbUpgradePath path) voidsimilar toCdbSession.delete(ConfPath)but specifies element using path stringbooleanexists(ConfCdbUpgradePath path) booleanChecks 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 stringintintgetNumberOfInstances(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.intindex(ConfCdbUpgradePath path) intsimilar toCdbSession.index(ConfPath)but specifies element using path stringbooleanisDefault(ConfCdbUpgradePath path) booleansimilar toCdbSession.isDefault(ConfPath)but specifies element using path stringintnextIndex(ConfCdbUpgradePath path) intsimilar toCdbSession.nextIndex(ConfPath)but specifies element using path stringvoidpushd(ConfCdbUpgradePath path) voidsimilar toCdbSession.pushd(ConfPath)but specifies position using path stringvoidsetCase(String choice, String scase, ConfCdbUpgradePath path) voidWhen we use the YANG choice construct in the data model, this function can be used to select the current case.voidsetElem(ConfValue value, ConfCdbUpgradePath path) voidsimilar toCdbSession.setElem(ConfValue, ConfPath)but specifies element using path stringvoidsetObject(ConfValue[] values, ConfCdbUpgradePath path) voidsimilar toCdbSession.setObject(ConfValue[], ConfPath)but specifies element using path stringvoidsetValues(ConfXMLParam[] params, ConfCdbUpgradePath path) voidsetValues(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, popd, pushd, setCase, setElem, setNamespace, setObject, setValues, setValues
-
Constructor Details
-
CdbUpgradeSession
- Throws:
IOExceptionConfException
-
CdbUpgradeSession
- Throws:
ConfExceptionIOException
-
CdbUpgradeSession
public CdbUpgradeSession(Cdb cdb, CdbDBType dbtype, EnumSet<CdbLockType> lockflags) throws ConfException, IOException - Throws:
ConfExceptionIOException
-
-
Method Details
-
exists
- Throws:
ConfExceptionIOException
-
exists
Description copied from class:CdbSessionChecks whether an element exists. The element is specified using a path string and optionally string substitution parameters- Overrides:
existsin classCdbSession- Parameters:
fmt- path stringarguments- optional parameters for substitution in fmt- Returns:
- true if exists
- Throws:
ConfExceptionIOException
-
cd
- Throws:
ConfExceptionIOException
-
cd
Description copied from class:CdbSessionChange working directory to container specified by path string- Overrides:
cdin classCdbSession- Parameters:
fmt- path stringarguments- optional parameters for substitution in fmt- Throws:
ConfExceptionIOException
-
pushd
- Throws:
ConfExceptionIOException
-
pushd
Description copied from class:CdbSessionsimilar toCdbSession.pushd(ConfPath)but specifies position using path string- Overrides:
pushdin classCdbSession- Parameters:
fmt- path stringarguments- optional parameters for substitution in fmt- Throws:
ConfExceptionIOException
-
getNumberOfInstances
- Throws:
ConfExceptionIOException
-
getNumberOfInstances
Description copied from class:CdbSessionsimilar toCdbSession.getNumberOfInstances(ConfPath)but specifies element using path string- Overrides:
getNumberOfInstancesin classCdbSession- Parameters:
fmt- path stringarguments- optional parameters for substitution in fmt- Returns:
- number of instances
- Throws:
ConfExceptionIOException
-
nextIndex
- Throws:
ConfExceptionIOException
-
nextIndex
Description copied from class:CdbSessionsimilar toCdbSession.nextIndex(ConfPath)but specifies element using path string- Overrides:
nextIndexin classCdbSession- Parameters:
fmt- path stringarguments- optional parameters for substitution in fmt- Returns:
- position of next key
- Throws:
ConfExceptionIOException
-
index
- Throws:
ConfExceptionIOException
-
index
Description copied from class:CdbSessionsimilar toCdbSession.index(ConfPath)but specifies element using path string- Overrides:
indexin classCdbSession- Parameters:
fmt- path stringarguments- optional parameters for substitution in fmt- Returns:
- position of key
- Throws:
ConfExceptionIOException
-
isDefault
- Throws:
ConfExceptionIOException
-
isDefault
Description copied from class:CdbSessionsimilar toCdbSession.isDefault(ConfPath)but specifies element using path string- Overrides:
isDefaultin classCdbSession- Parameters:
fmt- path stringarguments- optional parameters for substitution in fmt- Returns:
- true/false if a leaf has a default value defined
- Throws:
ConfExceptionIOException
-
getElem
- Throws:
ConfExceptionIOException
-
getElem
Description copied from class:CdbSessionsimilar toCdbSession.getElem(ConfPath)but specifies element using path string- Overrides:
getElemin classCdbSession- Parameters:
fmt- path stringarguments- optional parameters for substitution in fmt- Returns:
- element represented by a ConfValue
- Throws:
ConfExceptionIOException
-
setElem
- Throws:
ConfExceptionIOException
-
setElem
public void setElem(ConfValue value, String fmt, Object... arguments) throws ConfException, IOException Description copied from class:CdbSessionsimilar toCdbSession.setElem(ConfValue, ConfPath)but specifies element using path string- Overrides:
setElemin classCdbSessionfmt- path stringarguments- optional parameters for substitution in fmt- Throws:
ConfExceptionIOException
-
create
- Throws:
ConfExceptionIOException
-
create
Description copied from class:CdbSessionsimilar toCdbSession.create(ConfPath)but specifies element using path string- Overrides:
createin classCdbSession- Parameters:
fmt- path stringarguments- optional parameters for substitution in fmt- Throws:
ConfExceptionIOException
-
delete
- Throws:
IOExceptionConfException
-
delete
Description copied from class:CdbSessionsimilar toCdbSession.delete(ConfPath)but specifies element using path string- Overrides:
deletein classCdbSession- Parameters:
fmt- path stringarguments- optional parameters for substitution in fmt- Throws:
IOExceptionConfException
-
getObject
public ConfObject[] getObject(int numOfObjects, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOExceptionConfException
-
getObject
public ConfObject[] getObject(int numOfObjects, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSessionIn 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:
getObjectin classCdbSession- Parameters:
numOfObjects- number of objects to retrieve- Returns:
- ConfObject[]
- Throws:
IOExceptionConfException
-
getObjects
public List<ConfObject[]> getObjects(int numOfObjects, int instance, int numOfInstances, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOExceptionConfException
-
getObjects
public List<ConfObject[]> getObjects(int numOfObjects, int instance, int numOfInstances, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSessionSimilar 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.getNumberOfInstances(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:
getObjectsin classCdbSession- Parameters:
numOfObjects- number of objects to retrieveinstance- instance integernumOfInstances- number if instances to retrieve- Returns:
- List<ConfObject[]>
- Throws:
IOExceptionConfException
-
setObject
public void setObject(ConfValue[] values, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOExceptionConfException
-
setObject
public void setObject(ConfValue[] values, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSessionsimilar toCdbSession.setObject(ConfValue[], ConfPath)but specifies element using path string- Overrides:
setObjectin classCdbSessionfmt- path stringarguments- optional parameters for substitution in fmt- Throws:
IOExceptionConfException
-
setValues
public void setValues(ConfXMLParam[] params, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOExceptionConfException
-
setValues
public void setValues(ConfXMLParam[] params, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSessionsimilar toCdbSession.setValues(ConfXMLParam[], ConfPath)but specifies element using path string- Overrides:
setValuesin classCdbSession- Throws:
IOExceptionConfException
-
getValues
public ConfXMLParam[] getValues(ConfXMLParam[] params, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOExceptionConfException
-
getValues
public ConfXMLParam[] getValues(ConfXMLParam[] params, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSessionRead 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:
getValuesin classCdbSession- Returns:
- ConfXMLParam[]
- Throws:
IOExceptionConfException
-
getCase
- Throws:
IOExceptionConfException
-
getCase
public ConfObject getCase(String choice, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSessionRetrieve 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
fmtgive the path to the container where the choice is defined,The
choiceis 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:
getCasein 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:
IOExceptionConfException
-
setCase
public void setCase(String choice, String scase, ConfCdbUpgradePath path) throws IOException, ConfException - Throws:
IOExceptionConfException
-
setCase
public void setCase(String choice, String scase, String fmt, Object... arguments) throws IOException, ConfException Description copied from class:CdbSessionWhen 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:
setCasein classCdbSession- Parameters:
choice- choice stringscase- case stringfmt- format string pointing to the choicearguments- replacement arguments for fmt string- Throws:
IOExceptionConfException
-
toString
- Overrides:
toStringin classCdbSession
-