From: Sasa M. <sa...@us...> - 2004-11-19 12:00:11
|
Update of /cvsroot/jrobin/src/org/jrobin/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4753/org/jrobin/core Modified Files: RrdDb.java RrdDef.java RrdToolkit.java Log Message: Added split() method to the RrdToolkit class to split single RRD file into several new ones. Each new file contains only a single datasource. All archived values are preserved. Index: RrdDef.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDef.java,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** RrdDef.java 21 Sep 2004 08:42:09 -0000 1.17 --- RrdDef.java 19 Nov 2004 12:00:01 -0000 1.18 *************** *** 26,33 **** package org.jrobin.core; ! import java.util.ArrayList; ! import java.util.Date; ! import java.util.GregorianCalendar; ! import java.util.StringTokenizer; import java.io.*; --- 26,30 ---- package org.jrobin.core; ! import java.util.*; import java.io.*; *************** *** 457,460 **** --- 454,467 ---- } + void saveSingleDatasource(String dsName) { + Iterator it = dsDefs.iterator(); + while(it.hasNext()) { + DsDef dsDef = (DsDef) it.next(); + if(!dsDef.getDsName().equals(dsName)) { + it.remove(); + } + } + } + void removeArchive(String consolFun, int steps) throws RrdException { ArcDef arcDef = findArchive(consolFun, steps); *************** *** 615,617 **** --- 622,638 ---- return true; } + + /** + * Removes all datasource definitions. + */ + public void removeDatasources() { + dsDefs.clear(); + } + + /** + * Removes all RRA archive definitions. + */ + public void removeArchives() { + arcDefs.clear(); + } } Index: RrdDb.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdDb.java,v retrieving revision 1.33 retrieving revision 1.34 diff -C2 -d -r1.33 -r1.34 *** RrdDb.java 22 Oct 2004 12:30:50 -0000 1.33 --- RrdDb.java 19 Nov 2004 12:00:01 -0000 1.34 *************** *** 1112,1115 **** --- 1112,1131 ---- } + /** + * Returns the number of datasources defined in the file + * @return The number of datasources defined in the file + */ + public int getDsCount() { + return datasources.length; + } + + /** + * Returns the number of RRA arcihves defined in the file + * @return The number of RRA arcihves defined in the file + */ + public int getArcCount() { + return archives.length; + } + public static void main(String[] args) { System.out.println("JRobin Java Library :: RRDTool choice for the Java world"); Index: RrdToolkit.java =================================================================== RCS file: /cvsroot/jrobin/src/org/jrobin/core/RrdToolkit.java,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** RrdToolkit.java 27 Aug 2004 09:42:42 -0000 1.11 --- RrdToolkit.java 19 Nov 2004 12:00:01 -0000 1.12 *************** *** 39,42 **** --- 39,45 ---- * <p>All these operations can be performed on the copy of the original RRD file, or on the * original file itself (with possible backup file creation)</p> + * + * <p><b><u>IMPORTANT</u></b>: NEVER use methods found in this class on 'live' RRD files + * (files which are currently in use).</p> */ public class RrdToolkit { *************** *** 441,444 **** --- 444,469 ---- } } + + public void split(String sourcePath) throws IOException, RrdException { + RrdDb rrdSource = new RrdDb(sourcePath); + String[] dsNames = rrdSource.getDsNames(); + for(int i = 0; i < dsNames.length; i++) { + RrdDef rrdDef = rrdSource.getRrdDef(); + rrdDef.setPath(createSplitPath(dsNames[i], sourcePath)); + rrdDef.saveSingleDatasource(dsNames[i]); + RrdDb rrdDest = new RrdDb(rrdDef); + rrdSource.copyStateTo(rrdDest); + rrdDest.close(); + } + rrdSource.close(); + } + + private String createSplitPath(String dsName, String sourcePath) { + File file = new File(sourcePath); + String newName = dsName + "-" + file.getName(); + String path = file.getAbsolutePath(); + String parentDir = path.substring(0, 1 + path.lastIndexOf(Util.getFileSeparator())); + return parentDir + newName; + } } |