|
From: <sa...@us...> - 2003-11-27 15:53:37
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv24316/org/jrobin/core
Modified Files:
Archive.java RrdDb.java RrdToolkit.java
Log Message:
Added RRDToolkit class to perform some less frequent but very useful operations on a RRD file as whole. So far so good: you can now add and remove datasource definitions to a RRD still preserving already existing data in it.
Index: Archive.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Archive.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** Archive.java 27 Nov 2003 14:15:11 -0000 1.5
--- Archive.java 27 Nov 2003 15:53:33 -0000 1.6
***************
*** 408,417 ****
throw new RrdException("Incompatible number of rows");
}
! int count = Math.min(
! parentDb.getHeader().getDsCount(),
! arc.parentDb.getHeader().getDsCount());
for(int i = 0; i < count; i++) {
! states[i].copyStateTo(arc.states[i]);
! robins[i].copyStateTo(arc.robins[i]);
}
}
--- 408,419 ----
throw new RrdException("Incompatible number of rows");
}
! int count = parentDb.getHeader().getDsCount();
for(int i = 0; i < count; i++) {
! String dsName = parentDb.getDatasource(i).getDsName();
! if(arc.getParentDb().getDatasource(dsName) != null) {
! int j = arc.getParentDb().getDsIndex(dsName);
! states[i].copyStateTo(arc.states[j]);
! robins[i].copyStateTo(arc.robins[j]);
! }
}
}
Index: RrdDb.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** RrdDb.java 27 Nov 2003 14:15:11 -0000 1.5
--- RrdDb.java 27 Nov 2003 15:53:33 -0000 1.6
***************
*** 662,672 ****
RrdDb rrd = (RrdDb) other;
header.copyStateTo(rrd.header);
! int dsCount = Math.min(header.getDsCount(), rrd.header.getDsCount());
! for(int i = 0; i < dsCount; i++) {
! datasources[i].copyStateTo(rrd.datasources[i]);
}
! int arcCount = Math.min(header.getArcCount(), rrd.header.getArcCount());
! for(int i = 0; i < arcCount; i++) {
! archives[i].copyStateTo(rrd.archives[i]);
}
}
--- 662,729 ----
RrdDb rrd = (RrdDb) other;
header.copyStateTo(rrd.header);
! for(int i = 0; i < datasources.length; i++) {
! Datasource matchingDatasource = rrd.getDatasource(datasources[i].getDsName());
! if(matchingDatasource != null) {
! datasources[i].copyStateTo(matchingDatasource);
! }
}
! for(int i = 0; i < archives.length; i++) {
! Archive matchingArchive = rrd.getArchive(
! archives[i].getConsolFun(), archives[i].getSteps());
! if(matchingArchive != null) {
! archives[i].copyStateTo(matchingArchive);
! }
! }
! }
!
! /**
! * Returns Datasource object corresponding to the given datasource name.
! * @param dsName Datasource name
! * @return Datasource object corresponding to the give datasource name or null
! * if not found.
! * @throws IOException Thrown in case of I/O error
! */
! public Datasource getDatasource(String dsName) throws IOException {
! try {
! return getDatasource(getDsIndex(dsName));
! }
! catch (RrdException e) {
! return null;
! }
! }
!
! /**
! * Returns index of Archive object with the given consolidation function and the number
! * of steps. Exception is thrown if such archive could not be found.
! * @param consolFun Consolidation function
! * @param steps Number of archive steps
! * @return Requested Archive object
! * @throws IOException Thrown in case of I/O error
! * @throws RrdException Thrown if no such archive could be found
! */
! public int getArcIndex(String consolFun, int steps) throws RrdException, IOException {
! for(int i = 0; i < archives.length; i++) {
! if(archives[i].getConsolFun().equals(consolFun) &&
! archives[i].getSteps() == steps) {
! return i;
! }
! }
! throw new RrdException("Could not find archive " + consolFun + "/" + steps);
! }
!
! /**
! * Returns Archive object with the given consolidation function and the number
! * of steps.
! * @param consolFun Consolidation function
! * @param steps Number of archive steps
! * @return Requested Archive object or null if no such archive could be found
! * @throws IOException Thrown in case of I/O error
! */
! public Archive getArchive(String consolFun, int steps) throws IOException {
! try {
! return getArchive(getArcIndex(consolFun, steps));
! }
! catch (RrdException e) {
! return null;
}
}
Index: RrdToolkit.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** RrdToolkit.java 27 Nov 2003 14:37:20 -0000 1.2
--- RrdToolkit.java 27 Nov 2003 15:53:33 -0000 1.3
***************
*** 66,71 ****
*/
- /*
- Still buggy! Will fix later
public void removeDatasource(String sourcePath, String destPath, String dsName)
throws IOException, RrdException {
--- 66,69 ----
***************
*** 82,86 ****
rrdDest.close();
}
- */
/**
--- 80,83 ----
***************
*** 112,117 ****
DsDef dsDef = new DsDef("XXX", "GAUGE", 666, -1, Double.NaN);
RrdToolkit.getInstance().addDatasource("demo.rrd", "demo2.rrd", dsDef);
! ArcDef arcDef = new ArcDef("LAST", 0.666, 77, 888);
! RrdToolkit.getInstance().addArchive("demo2.rrd", "demo3.rrd", arcDef);
}
}
--- 109,113 ----
DsDef dsDef = new DsDef("XXX", "GAUGE", 666, -1, Double.NaN);
RrdToolkit.getInstance().addDatasource("demo.rrd", "demo2.rrd", dsDef);
! RrdToolkit.getInstance().removeDatasource("demo2.rrd", "demo3.rrd", "sun");
}
}
|