new plugin jerasure-purejava
authorMaximilian Quellmalz <maximilian.quellmalz@mailbox.tu-dresden.de>
Mon, 2 Jun 2014 12:30:05 +0000 (14:30 +0200)
committerMaximilian Quellmalz <maximilian.quellmalz@mailbox.tu-dresden.de>
Mon, 2 Jun 2014 12:30:05 +0000 (14:30 +0200)
.gitmodules
Splitter-ng-plugin-jerasure-purejava/.classpath [new file with mode: 0644]
Splitter-ng-plugin-jerasure-purejava/.gitignore [new file with mode: 0644]
Splitter-ng-plugin-jerasure-purejava/.project [new file with mode: 0644]
Splitter-ng-plugin-jerasure-purejava/.settings/org.eclipse.jdt.core.prefs [new file with mode: 0644]
Splitter-ng-plugin-jerasure-purejava/build.xml [new file with mode: 0644]
Splitter-ng-plugin-jerasure-purejava/jerasure [new submodule]
Splitter-ng-plugin-jerasure-purejava/src/hpijerasureplugin/HPIJerasurePlugin.java [new file with mode: 0644]
Splitter-ng-plugin-jerasure-purejava/src/hpijerasureplugin/JavaCRS.java [new file with mode: 0644]

index 01e1ffc..1cc8218 100644 (file)
@@ -1,3 +1,6 @@
 [submodule "Splitter-ng-plugin-jerasure/Jerasure-1.2-java"]
        path = Splitter-ng-plugin-jerasure/Jerasure-1.2-java
        url = git@github.com:spamverdacht/Jerasure.git
+[submodule "Splitter-ng-plugin-jerasure-purejava/jerasure"]
+       path = Splitter-ng-plugin-jerasure-purejava/jerasure
+       url = https://github.com/BloodyD/jerasure.git
diff --git a/Splitter-ng-plugin-jerasure-purejava/.classpath b/Splitter-ng-plugin-jerasure-purejava/.classpath
new file mode 100644 (file)
index 0000000..6a2fd3e
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+       <classpathentry kind="src" path="src"/>
+       <classpathentry kind="src" path="jerasure/src"/>
+       <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
+               <attributes>
+                       <attribute name="org.eclipse.jdt.launching.CLASSPATH_ATTR_LIBRARY_PATH_ENTRY" value="Splitter-ng-plugin-jerasure/lib"/>
+               </attributes>
+       </classpathentry>
+       <classpathentry combineaccessrules="false" exported="true" kind="src" path="/Splitter-ng"/>
+       <classpathentry kind="lib" path="lib/guava-13.0.1.jar"/>
+       <classpathentry kind="lib" path="lib/junit-4.4.jar"/>
+       <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/Splitter-ng-plugin-jerasure-purejava/.gitignore b/Splitter-ng-plugin-jerasure-purejava/.gitignore
new file mode 100644 (file)
index 0000000..3d5cee7
--- /dev/null
@@ -0,0 +1,7 @@
+*.o
+*.swp
+lib/
+*.org
+*.*~
+.directory
+/bin
diff --git a/Splitter-ng-plugin-jerasure-purejava/.project b/Splitter-ng-plugin-jerasure-purejava/.project
new file mode 100644 (file)
index 0000000..c7db132
--- /dev/null
@@ -0,0 +1,17 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+       <name>Splitter-ng-plugin-jerasure-purejava</name>
+       <comment></comment>
+       <projects>
+       </projects>
+       <buildSpec>
+               <buildCommand>
+                       <name>org.eclipse.jdt.core.javabuilder</name>
+                       <arguments>
+                       </arguments>
+               </buildCommand>
+       </buildSpec>
+       <natures>
+               <nature>org.eclipse.jdt.core.javanature</nature>
+       </natures>
+</projectDescription>
diff --git a/Splitter-ng-plugin-jerasure-purejava/.settings/org.eclipse.jdt.core.prefs b/Splitter-ng-plugin-jerasure-purejava/.settings/org.eclipse.jdt.core.prefs
new file mode 100644 (file)
index 0000000..7341ab1
--- /dev/null
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.7
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.7
diff --git a/Splitter-ng-plugin-jerasure-purejava/build.xml b/Splitter-ng-plugin-jerasure-purejava/build.xml
new file mode 100644 (file)
index 0000000..b1e567e
--- /dev/null
@@ -0,0 +1,83 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<project basedir="." default="makejar" name="Splitter-ng-plugin-jerasure-purejava">
+    <property environment="env"/>
+    <property name="Splitter-ng.location" value="../Splitter-ng"/>
+    <property name="Jerasure-1.2-java.location" value="Jerasure-1.2-java"/>
+    <property name="debuglevel" value="source,lines,vars"/>
+    <property name="target" value="1.7"/>
+    <property name="source" value="1.7"/>
+    <path id="Splitter-ng.classpath">
+        <pathelement location="${Splitter-ng.location}/bin"/>
+    </path>
+    <path id="Splitter-ng-plugin-jerasure.classpath">
+       <pathelement location="bin"/>
+        <fileset dir="lib">
+            <include name="*.jar"/>
+        </fileset>
+       <path refid="Splitter-ng.classpath"/>
+    </path>
+    <target name="init">
+        <mkdir dir="bin"/>
+        <copy includeemptydirs="false" todir="bin">
+            <fileset dir="src">
+                <exclude name="**/*.uad"/>
+                <exclude name="**/*.ucd"/>
+                <exclude name="**/*.uld"/>
+                <exclude name="**/*.upd"/>
+                <exclude name="**/*.udd"/>
+                <exclude name="**/*.uod"/>
+                <exclude name="**/*.usd"/>
+                <exclude name="**/*.utd"/>
+                <exclude name="**/*.uud"/>
+                <exclude name="**/*.odd"/>
+                <exclude name="**/*.ead"/>
+                <exclude name="**/*.ecd"/>
+                <exclude name="**/*.eld"/>
+                <exclude name="**/*.epd"/>
+                <exclude name="**/*.edd"/>
+                <exclude name="**/*.eod"/>
+                <exclude name="**/*.esd"/>
+                <exclude name="**/*.etd"/>
+                <exclude name="**/*.eud"/>
+                <exclude name="**/*.urd"/>
+                <exclude name="**/*.uml"/>
+                <exclude name="**/*.ecore"/>
+                <exclude name="**/*.ucls"/>
+                <exclude name="**/*.useq"/>
+                <exclude name="**/*.java"/>
+            </fileset>
+        </copy>
+    </target>
+    <target name="clean">
+        <delete dir="bin"/>
+    </target>
+    <target depends="clean" name="cleanall">
+       <ant antfile="build.xml" dir="${Splitter-ng.location}" inheritAll="false" target="clean"/>
+
+    </target>
+    <target depends="build-subprojects,build-project" name="build"/>
+    <target name="build-subprojects">
+        <ant antfile="build.xml" dir="${Splitter-ng.location}" inheritAll="false" target="build-project"/>
+    </target>
+    <target depends="init" name="build-project">
+        <echo message="${ant.project.name}: ${ant.file}"/>
+        <javac debug="true" debuglevel="${debuglevel}" destdir="bin" includeantruntime="false" source="${source}" target="${target}">
+            <src path="jerasure/src"/>
+            <src path="src"/>
+            <classpath refid="Splitter-ng-plugin-jerasure.classpath"/>
+        </javac>
+    </target>
+    <target description="Build all projects which reference this project. Useful to propagate changes." name="build-refprojects"/>
+    <target name ="makejar" depends="build" description="Create a jar for the project">
+         <jar jarfile="bin/${ant.project.name}.jar" >
+           <fileset dir="bin" includes="**/*.class" />
+           <fileset dir="lib" includes="**/*.jar" />
+         </jar>
+    </target>
+       <target name="dist" depends="makejar" description="Create a distribution Directory wirth splitter-ng and all Plugins">
+               <mkdir dir="../dist" />
+               <mkdir dir="../dist/plugin" />
+               <copy file="bin/${ant.project.name}.jar" todir="../dist/plugin/" />
+       </target>
+</project>
+
diff --git a/Splitter-ng-plugin-jerasure-purejava/jerasure b/Splitter-ng-plugin-jerasure-purejava/jerasure
new file mode 160000 (submodule)
index 0000000..c911546
--- /dev/null
@@ -0,0 +1 @@
+Subproject commit c9115461fda12a92d7b3f8ec5e1da144680a8457
diff --git a/Splitter-ng-plugin-jerasure-purejava/src/hpijerasureplugin/HPIJerasurePlugin.java b/Splitter-ng-plugin-jerasure-purejava/src/hpijerasureplugin/HPIJerasurePlugin.java
new file mode 100644 (file)
index 0000000..17d1452
--- /dev/null
@@ -0,0 +1,85 @@
+package hpijerasureplugin;
+
+
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.Map;
+
+import splitterng.plugin.CodecDescription;
+import splitterng.plugin.PluginDescription;
+import splitterng.plugin.interfaces.Plugable;
+import splitterng.plugin.interfaces.PluginManager;
+import splitterng.plugin.interfaces.SplitterCodec;
+
+public class HPIJerasurePlugin implements Plugable {
+
+       @SuppressWarnings("unused")
+       private PluginManager pluginManager;
+       private final String pluginID = "jerasure-java";
+       private final String pluginName = "Jerasure-java Plugin (HPI)";
+       private final String pluginDescriptionText = "Stellt CRS von Jerasure zur Verfügung"
+                       + "\n buffersize%(sizeof(int)*w*k) == 0 oder buffersize%(sizeof(int)*w*k*packetsize) == 0";
+       private final Collection <String> dependencies = Arrays.asList("");
+
+       // private Map<String, SplitterCodec> codecMap;
+       private Collection <CodecDescription> codecDescriptions;
+       private PluginDescription pluginDescription;
+
+       public HPIJerasurePlugin() {
+               
+
+               //System.out.println("codecDescriptions füllen: ");
+               this.codecDescriptions = new LinkedList<CodecDescription>();
+               this.codecDescriptions.add(JavaCRS.getCodecDescription());
+               this.pluginDescription = new PluginDescription(this.pluginID, this.pluginName,
+                               this.pluginDescriptionText,
+                               this.codecDescriptions,
+                               this.dependencies);
+               //System.out.println("Plugindescription gebaut: " + this.pluginDescription.toString());
+               //System.out.println("CodecDescriptions : " + this.pluginDescription.getCodecDescriptions());
+               
+       }
+
+//     @Override
+//     public boolean start() {
+//             return true;
+//     }
+//
+//     @Override
+//     public boolean stop() {
+//             return true;
+//     }
+
+//     @Override
+//     public void setPluginManager(PluginManager manager) {
+//             this.pluginManager = manager;
+//
+//     }
+
+        @Override
+        public Collection<CodecDescription> getCodecDescriptions() {
+                return codecDescriptions;
+        }
+
+       @Override
+       public SplitterCodec getNewSplitterCodec(String codecID,
+                       Map<String, Integer> codecParameter) throws IllegalArgumentException {
+               switch (codecID) {
+               case JavaCRS.codecID:
+                       return new JavaCRS(codecParameter);
+                       
+               //TODO JerasurePlugin: Weitere Codecs hier erzeugen
+                       
+               default:
+                       throw new IllegalArgumentException("CodecID not known: " + codecID );
+               }
+       }
+
+       @Override
+       public PluginDescription getPluginDescription() {
+               return pluginDescription;
+       }
+
+}
diff --git a/Splitter-ng-plugin-jerasure-purejava/src/hpijerasureplugin/JavaCRS.java b/Splitter-ng-plugin-jerasure-purejava/src/hpijerasureplugin/JavaCRS.java
new file mode 100644 (file)
index 0000000..6eb9ddd
--- /dev/null
@@ -0,0 +1,175 @@
+package hpijerasureplugin;
+
+
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import splitterng.plugin.CodecDescription;
+import splitterng.plugin.interfaces.SplitterCodec;
+import de.uni_postdam.hpi.cauchy.Cauchy;
+import de.uni_postdam.hpi.matrix.BitMatrix;
+import de.uni_postdam.hpi.matrix.Matrix;
+import de.uni_postdam.hpi.matrix.Schedule;
+
+public class JavaCRS implements SplitterCodec {
+
+       public final static String codecID = "JerasureJavaCRS";
+       public final static String codecName = "Jerasure-Java CRS";
+       public final static String codecDescriptionText = "This Codec implements CauchyReedSolomon in Java."
+                       + "When m = 2, w <=11 and k <= 1023, it will use the optimal RAID-6 matrix. Otherwise, it generates a good matrix by calling cauchy_original_coding_matrix()"
+                       + "and then cauchy_improve_coding_matrix()."
+                       + "\nRequirements:   (fragmentsize % (packetsize * w)) == 0";
+
+       public final static Map <String, Integer []> codecParameterMinMax;
+
+       private int k,m,w,packetsize;
+       
+       static {
+               Map <String, Integer []> tmpMap = new HashMap<String, Integer[]>();
+               tmpMap.put("k", new Integer[] {new Integer(1),new Integer(Integer.MAX_VALUE)});
+               tmpMap.put("m", new Integer[] {new Integer(1),new Integer(Integer.MAX_VALUE)});
+               tmpMap.put("w", new Integer[] {new Integer(1),new Integer(Integer.MAX_VALUE)});
+               tmpMap.put("packetsize", new Integer[] {new Integer(1),new Integer(Integer.MAX_VALUE)});
+               
+               codecParameterMinMax  = Collections.unmodifiableMap(tmpMap);                            
+       }
+       
+       
+       private static final CodecDescription codecDescription = new CodecDescription(
+       codecID, codecName, codecDescriptionText, codecParameterMinMax);
+       
+       private Matrix matrix;
+       private BitMatrix bitmatrix;
+       private Schedule[] schedules;
+       private byte[] coding_ptrs_flat;
+       private byte[][] data_ptrs;
+       private byte[]   data_ptrs_flat;
+       private byte[][] dataAndCoding_ptrs;
+       private boolean[] erasures;
+       private int numerased=0;
+
+       
+       public static final CodecDescription getCodecDescription(){
+               //System.out.println("JerasureCodecParity: getCodecDescription: "+JerasureCodecParity.codecDescription);
+               return JavaCRS.codecDescription;
+       }
+       
+       /**
+        * @param codecParameter
+        */
+       public JavaCRS(Map<String, Integer> codecParameter) {
+               super();
+               
+               //Test CodecParameter
+               for (Entry<String, Integer[]> requiredEntry : JavaCRS.codecParameterMinMax
+                               .entrySet()) {
+                       if (codecParameter.containsKey(requiredEntry.getKey())) {
+                               // Test ob Parameter vorhanden und in den gültigen grenzen
+                               // liegen
+                               //System.out.println("Test" +codecParameter.get(requiredEntry.getKey()) +" "+  requiredEntry.getValue()[0]);
+                               if (codecParameter.get(requiredEntry.getKey()) < requiredEntry.getValue()[0])
+                                       throw new IllegalArgumentException(
+                                                       "unzulässiger Wert für Parameter: "
+                                                                       + requiredEntry.getKey() + " < "
+                                                                       + requiredEntry.getValue()[0]);
+                               if (codecParameter.get(requiredEntry.getKey()) > requiredEntry.getValue()[1])
+                                       throw new IllegalArgumentException(
+                                                       "unzulässiger Wert für Parameter: "
+                                                                       + requiredEntry.getKey() + " > "
+                                                                       + requiredEntry.getValue()[1]);
+                       } else {
+                               throw new IllegalArgumentException("Missing Codec Parameter: "
+                                               + requiredEntry.getKey());
+                       }
+               }
+               
+               k=(int)codecParameter.get("k");
+               m=(int)codecParameter.get("m");
+               w=(int)codecParameter.get("w");
+               packetsize=(int)codecParameter.get("packetsize");
+               matrix= Cauchy.good_general_coding_matrix(k, m, w);
+               bitmatrix = new BitMatrix(matrix, w);
+               this.schedules = bitmatrix.toSchedules(k, w);
+               erasures = new boolean[k + m];
+               
+       }
+
+       @Override
+       public byte[][] decode(byte[][] dataAndCoding_ptrs, boolean [] erased){
+               //TODO Array Testen ob zulässig? eventuell nicht, da es hier bremsen könnte
+               int fragmentsize = dataAndCoding_ptrs[0].length;
+               /*
+               if (data_ptrs == null || (data_ptrs.length != k) || (data_ptrs[0].length != fragmentsize)){
+                       data_ptrs = new byte[k][fragmentsize];
+               }                       
+               
+               if (coding_ptrs_flat == null || (coding_ptrs_flat.length != m) || (coding_ptrs_flat[0].length != fragmentsize)){
+                       coding_ptrs_flat = new byte[m][fragmentsize];
+               }
+               
+               for (int i=0; i<k ; i++){
+                       data_ptrs[i]=dataAndCoding_ptrs[i];
+               }
+               for (int i=k; i<k+m ; i++){
+                       coding_ptrs_flat[i-k]=dataAndCoding_ptrs[i];
+               }
+               
+               //Preparing Erasures
+               numerased=0;
+               for (int i=0; i<m+k; i++){
+                       if (erased[i]==true){
+                               erasures[numerased]=i;
+                               numerased++;
+                       }
+               }
+               erasures[numerased]=-1;
+               
+
+               Jerasure.jerasure_bitmatrix_decode(k, m, w, bitmatrix, false, erasures, data_ptrs, coding_ptrs_flat, fragmentsize, packetsize);
+               */
+               return data_ptrs;
+       }
+
+       @Override
+       public byte[][] encode(byte[][] data_ptrs){
+               //TODO Array Testen ob zulässig? eventuell nicht, da es hier bremsen könnte
+               // buffersize%(sizeof(int)*w*k) == 0
+               int fragmentsize = data_ptrs[0].length;
+               
+               //Test reuse or create new
+               if (data_ptrs_flat == null || (data_ptrs_flat.length != k * fragmentsize)){
+                       data_ptrs_flat = new byte[k * fragmentsize];
+               }
+               //Fill into flat array
+               for (int i=0; i<k ; i++) {
+                       System.arraycopy(data_ptrs[i], 0, data_ptrs_flat, i * fragmentsize, fragmentsize);
+               }
+               
+               if (coding_ptrs_flat == null || (coding_ptrs_flat.length != m * fragmentsize)){
+                       coding_ptrs_flat = new byte[m * fragmentsize];
+               }
+               
+               //coding_ptrs_flat = CodingUtils.enOrDecode(data_ptrs_flat, schedules, k, m, w, packetsize);
+               coding_ptrs_flat = Schedule.do_scheduled_operations(data_ptrs_flat, coding_ptrs_flat, schedules, packetsize, w);
+               
+               if (dataAndCoding_ptrs == null || (dataAndCoding_ptrs.length != k+m) || (dataAndCoding_ptrs[0].length != fragmentsize)){
+                       dataAndCoding_ptrs = new byte[k+m][fragmentsize];
+               }
+               //Data Blocks
+               for (int i=0; i<k ; i++){
+                       dataAndCoding_ptrs[i]=data_ptrs[i];
+               }
+               for (int i=k; i<k+m ; i++){
+                       System.arraycopy(data_ptrs_flat, (i-k) * fragmentsize, dataAndCoding_ptrs[i], 0, fragmentsize);
+
+               }
+                               
+               return dataAndCoding_ptrs;
+       }
+
+
+}
\ No newline at end of file