|
From: <sa...@us...> - 2003-11-27 14:37:25
|
Update of /cvsroot/jrobin/src/org/jrobin/core
In directory sc8-pr-cvs1:/tmp/cvs-serv10071/org/jrobin/core
Modified Files:
RrdToolkit.java Util.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: RrdToolkit.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** RrdToolkit.java 27 Nov 2003 14:15:11 -0000 1.1
--- RrdToolkit.java 27 Nov 2003 14:37:20 -0000 1.2
***************
*** 35,39 ****
* the original RRD file is copied to the new one.
* @param sourcePath path to a RRD file to import data from (will not be modified)
! * @param destPath path to new RRD file (will be created)
* @param newDatasource Datasource definition to be added to the new RRD file
* @throws IOException Thrown in case of I/O error
--- 35,39 ----
* the original RRD file is copied to the new one.
* @param sourcePath path to a RRD file to import data from (will not be modified)
! * @param destPath path to a new RRD file (will be created)
* @param newDatasource Datasource definition to be added to the new RRD file
* @throws IOException Thrown in case of I/O error
***************
*** 42,45 ****
--- 42,48 ----
public void addDatasource(String sourcePath, String destPath, DsDef newDatasource)
throws IOException, RrdException {
+ if(Util.sameFilePath(sourcePath, destPath)) {
+ throw new RrdException("Source and destination paths are the same");
+ }
RrdDb rrdSource = new RrdDb(sourcePath);
RrdDef rrdDef = rrdSource.getRrdDef();
***************
*** 57,67 ****
* the original RRD file is copied to the new one.
* @param sourcePath path to a RRD file to import data from (will not be modified)
! * @param destPath path to new RRD file (will be created)
* @param dsName Name of the Datasource to be removed from the new RRD file
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown in case of JRobin specific error
*/
public void removeDatasource(String sourcePath, String destPath, String dsName)
throws IOException, RrdException {
RrdDb rrdSource = new RrdDb(sourcePath);
RrdDef rrdDef = rrdSource.getRrdDef();
--- 60,76 ----
* the original RRD file is copied to the new one.
* @param sourcePath path to a RRD file to import data from (will not be modified)
! * @param destPath path to a new RRD file (will be created)
* @param dsName Name of the Datasource to be removed from the new RRD file
* @throws IOException Thrown in case of I/O error
* @throws RrdException Thrown in case of JRobin specific error
*/
+
+ /*
+ Still buggy! Will fix later
public void removeDatasource(String sourcePath, String destPath, String dsName)
throws IOException, RrdException {
+ if(Util.sameFilePath(sourcePath, destPath)) {
+ throw new RrdException("Source and destination paths are the same");
+ }
RrdDb rrdSource = new RrdDb(sourcePath);
RrdDef rrdDef = rrdSource.getRrdDef();
***************
*** 73,81 ****
rrdDest.close();
}
public static void main(String[] args) throws RrdException, IOException {
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", "XXX");
}
}
--- 82,117 ----
rrdDest.close();
}
+ */
+
+ /**
+ * Creates a new RRD file with one more archive in it. RRD file is created based on the
+ * existing one (the original RRD file is not modified at all). All data from
+ * the original RRD file is copied to the new one.
+ * @param sourcePath path to a RRD file to import data from (will not be modified)
+ * @param destPath path to a new RRD file (will be created)
+ * @param newArchive Archive definition to be added to the new RRD file
+ * @throws IOException Thrown in case of I/O error
+ * @throws RrdException Thrown in case of JRobin specific error
+ */
+ public void addArchive(String sourcePath, String destPath, ArcDef newArchive)
+ throws IOException, RrdException {
+ if(Util.sameFilePath(sourcePath, destPath)) {
+ throw new RrdException("Source and destination paths are the same");
+ }
+ RrdDb rrdSource = new RrdDb(sourcePath);
+ RrdDef rrdDef = rrdSource.getRrdDef();
+ rrdDef.setPath(destPath);
+ rrdDef.addArchive(newArchive);
+ RrdDb rrdDest = new RrdDb(rrdDef);
+ rrdSource.copyStateTo(rrdDest);
+ rrdSource.close();
+ rrdDest.close();
+ }
public static void main(String[] args) throws RrdException, IOException {
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);
}
}
Index: Util.java
===================================================================
RCS file: /cvsroot/jrobin/src/org/jrobin/core/Util.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** Util.java 17 Nov 2003 08:09:42 -0000 1.4
--- Util.java 27 Nov 2003 14:37:20 -0000 1.5
***************
*** 32,35 ****
--- 32,36 ----
import java.util.GregorianCalendar;
import java.io.File;
+ import java.io.IOException;
/**
***************
*** 196,199 ****
--- 197,206 ----
public static String getJRobinDemoDirectory() {
return (homeDirFile.exists() || homeDirFile.mkdirs())? homeDirPath: null;
+ }
+
+ static boolean sameFilePath(String path1, String path2) throws IOException {
+ File file1 = new File(path1);
+ File file2 = new File(path2);
+ return file1.getCanonicalPath().equals(file2.getCanonicalPath());
}
|