summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--lib/junixsocket-1.3.jarbin0 -> 16162 bytes
-rw-r--r--lib/junixsocket-demo-1.3.jarbin0 -> 15753 bytes
-rw-r--r--lib/junixsocket-mysql-1.3.jarbin0 -> 1799 bytes
-rw-r--r--lib/junixsocket-rmi-1.3.jarbin0 -> 11598 bytes
-rw-r--r--pom.xml84
-rw-r--r--src/main/java/org/openslx/Test.java46
-rw-r--r--src/main/java/org/openslx/dnbd3/DNBD3Client.java29
-rw-r--r--src/main/java/org/openslx/dnbd3/DNBD3Image.java49
-rw-r--r--src/main/java/org/openslx/dnbd3/DNBD3Server.java116
-rw-r--r--src/test/java/org/openslx/AppTest.java38
11 files changed, 366 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a65ec10
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,4 @@
+.classpath
+.settings
+.project
+target
diff --git a/lib/junixsocket-1.3.jar b/lib/junixsocket-1.3.jar
new file mode 100644
index 0000000..b26e049
--- /dev/null
+++ b/lib/junixsocket-1.3.jar
Binary files differ
diff --git a/lib/junixsocket-demo-1.3.jar b/lib/junixsocket-demo-1.3.jar
new file mode 100644
index 0000000..8fded38
--- /dev/null
+++ b/lib/junixsocket-demo-1.3.jar
Binary files differ
diff --git a/lib/junixsocket-mysql-1.3.jar b/lib/junixsocket-mysql-1.3.jar
new file mode 100644
index 0000000..f576e4d
--- /dev/null
+++ b/lib/junixsocket-mysql-1.3.jar
Binary files differ
diff --git a/lib/junixsocket-rmi-1.3.jar b/lib/junixsocket-rmi-1.3.jar
new file mode 100644
index 0000000..37fbd91
--- /dev/null
+++ b/lib/junixsocket-rmi-1.3.jar
Binary files differ
diff --git a/pom.xml b/pom.xml
new file mode 100644
index 0000000..127fbde
--- /dev/null
+++ b/pom.xml
@@ -0,0 +1,84 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.openslx</groupId>
+ <artifactId>dnbd3-mgr</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ <packaging>jar</packaging>
+
+ <name>dnbd3-mgr</name>
+ <url>http://maven.apache.org</url>
+
+ <properties>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>3.8.1</version>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- unix socks -->
+ <dependency>
+ <groupId>org.newsclub</groupId>
+ <artifactId>junixsocket</artifactId>
+ <version>1.3</version>
+ <scope>system</scope>
+ <systemPath>${project.basedir}/lib/junixsocket-1.3.jar</systemPath>
+ </dependency>
+
+ <!-- xml -->
+ <dependency>
+ <groupId>org.jdom</groupId>
+ <artifactId>jdom</artifactId>
+ <version>2.0.2</version>
+ </dependency>
+ <dependency>
+ <groupId>jaxen</groupId>
+ <artifactId>jaxen</artifactId>
+ <version>1.1.3</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>maven-cobertura-plugin</artifactId>
+ <groupId>maven-plugins</groupId>
+ </exclusion>
+ <exclusion>
+ <artifactId>maven-findbugs-plugin</artifactId>
+ <groupId>maven-plugins</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>xalan</groupId>
+ <artifactId>xalan</artifactId>
+ <version>2.7.1</version>
+ </dependency>
+ <dependency>
+ <groupId>xerces</groupId>
+ <artifactId>xercesImpl</artifactId>
+ <version>2.10.0</version>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <source>1.6</source>
+ <target>1.6</target>
+ <optimize>true</optimize>
+ <debug>true</debug>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
diff --git a/src/main/java/org/openslx/Test.java b/src/main/java/org/openslx/Test.java
new file mode 100644
index 0000000..4e44552
--- /dev/null
+++ b/src/main/java/org/openslx/Test.java
@@ -0,0 +1,46 @@
+package org.openslx;
+
+import java.util.List;
+
+import org.openslx.dnbd3.DNBD3Client;
+import org.openslx.dnbd3.DNBD3Image;
+import org.openslx.dnbd3.DNBD3Server;
+
+public class Test {
+
+ public static void main(String[] args) {
+
+ try {
+ DNBD3Server server = new DNBD3Server();
+
+ System.out.println("Exported images (atime, vid, rid, file):");
+ System.out.println("========================================");
+ List<DNBD3Image> images = server.getImages();
+ for (DNBD3Image image : images) {
+ System.out.print(image.getAtime() + "\t");
+ System.out.print(image.getVid() + "\t");
+ System.out.print(image.getRid() + "\t");
+ System.out.print(image.getPath());
+ System.out.println();
+ }
+ System.out.println();
+ System.out.println("Number images: " + images.size());
+ System.out.println();
+
+ System.out.println("Connected clients (ip, file)");
+ System.out.println("============================");
+ List<DNBD3Client> clients = server.getClients();
+ for (DNBD3Client client : clients) {
+ System.out.print(client.getIp() + "\t");
+ System.out.print(client.getImage());
+ System.out.println();
+ }
+ System.out.println();
+ System.out.println("Number clients: " + clients.size());
+ System.out.println();
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+}
diff --git a/src/main/java/org/openslx/dnbd3/DNBD3Client.java b/src/main/java/org/openslx/dnbd3/DNBD3Client.java
new file mode 100644
index 0000000..1f0ced5
--- /dev/null
+++ b/src/main/java/org/openslx/dnbd3/DNBD3Client.java
@@ -0,0 +1,29 @@
+package org.openslx.dnbd3;
+
+public class DNBD3Client {
+
+ private String ip;
+ private String image;
+
+ public DNBD3Client(String ip, String image) {
+ this.ip = ip;
+ this.image = image;
+ }
+
+ public String getIp() {
+ return ip;
+ }
+
+ public void setIp(String ip) {
+ this.ip = ip;
+ }
+
+ public String getImage() {
+ return image;
+ }
+
+ public void setImage(String image) {
+ this.image = image;
+ }
+
+}
diff --git a/src/main/java/org/openslx/dnbd3/DNBD3Image.java b/src/main/java/org/openslx/dnbd3/DNBD3Image.java
new file mode 100644
index 0000000..e1b3429
--- /dev/null
+++ b/src/main/java/org/openslx/dnbd3/DNBD3Image.java
@@ -0,0 +1,49 @@
+package org.openslx.dnbd3;
+
+public class DNBD3Image {
+
+ private String atime;
+ private String vid;
+ private String rid;
+ private String path;
+
+ public DNBD3Image(String atime, String vid, String rid, String path) {
+ this.atime = atime;
+ this.vid = vid;
+ this.rid = rid;
+ this.path = path;
+ }
+
+ public String getAtime() {
+ return atime;
+ }
+
+ public void setAtime(String atime) {
+ this.atime = atime;
+ }
+
+ public String getVid() {
+ return vid;
+ }
+
+ public void setVid(String vid) {
+ this.vid = vid;
+ }
+
+ public String getRid() {
+ return rid;
+ }
+
+ public void setRid(String rid) {
+ this.rid = rid;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+}
diff --git a/src/main/java/org/openslx/dnbd3/DNBD3Server.java b/src/main/java/org/openslx/dnbd3/DNBD3Server.java
new file mode 100644
index 0000000..ce575dd
--- /dev/null
+++ b/src/main/java/org/openslx/dnbd3/DNBD3Server.java
@@ -0,0 +1,116 @@
+package org.openslx.dnbd3;
+
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jdom2.Document;
+import org.jdom2.Element;
+import org.jdom2.JDOMException;
+import org.jdom2.filter.Filters;
+import org.jdom2.input.SAXBuilder;
+import org.jdom2.xpath.XPathExpression;
+import org.jdom2.xpath.XPathFactory;
+import org.newsclub.net.unix.AFUNIXSocket;
+import org.newsclub.net.unix.AFUNIXSocketAddress;
+
+public class DNBD3Server {
+
+ private final String UNIXSOCK = "/run/dnbd3-server.sock";
+
+ private static final int CMDSTOP = 0;
+ private static final int CMDRELOAD = 1;
+ private static final int CMDINFO = 2;
+
+ public void doReload() throws IOException {
+ AFUNIXSocket sock = connect();
+ sendCommand(sock, CMDRELOAD);
+ sock.close();
+ }
+
+ public void doShutdown() throws IOException {
+ AFUNIXSocket sock = connect();
+ sendCommand(sock, CMDSTOP);
+ sock.close();
+ }
+
+ public List<DNBD3Image> getImages() throws IOException {
+ List<DNBD3Image> images = new ArrayList<DNBD3Image>();
+ AFUNIXSocket sock = connect();
+ sendCommand(sock, CMDINFO);
+
+ try {
+ String atime, vid, rid, file;
+ InputStream is = sock.getInputStream();
+ SAXBuilder builder = new SAXBuilder();
+ Document document = (Document) builder.build(is);
+ XPathFactory xpfac = XPathFactory.instance();
+ XPathExpression<Element> xp;
+ xp = xpfac.compile("//dnbd3-server/images/image", Filters.element());
+ for (Element e : xp.evaluate(document)) {
+ atime = e.getAttributeValue("atime");
+ vid = e.getAttributeValue("vid");
+ rid = e.getAttributeValue("rid");
+ file = e.getAttributeValue("file");
+ images.add(new DNBD3Image(atime, vid, rid, file));
+ }
+ is.close();
+
+ } catch (JDOMException ex) {
+ ex.printStackTrace();
+ }
+
+ sock.close();
+ return images;
+ }
+
+ public List<DNBD3Client> getClients() throws IOException {
+ List<DNBD3Client> clients = new ArrayList<DNBD3Client>();
+ AFUNIXSocket sock = connect();
+ sendCommand(sock, CMDINFO);
+
+ try {
+ String ip, image;
+ InputStream is = sock.getInputStream();
+ SAXBuilder builder = new SAXBuilder();
+ Document document = (Document) builder.build(is);
+ XPathFactory xpfac = XPathFactory.instance();
+ XPathExpression<Element> xp;
+ xp = xpfac.compile("//dnbd3-server/clients/client", Filters.element());
+ for (Element e : xp.evaluate(document)) {
+ ip = e.getAttributeValue("ip");
+ image = e.getAttributeValue("file");
+ clients.add(new DNBD3Client(ip, image));
+ }
+ is.close();
+
+ } catch (JDOMException ex) {
+ ex.printStackTrace();
+ }
+
+ sock.close();
+ return clients;
+ }
+
+////////////////////////////////////////////////////////////////////////////////
+
+ private AFUNIXSocket connect() throws IOException {
+ AFUNIXSocket sock = null;
+ File socketFile = new File(UNIXSOCK);
+ sock = AFUNIXSocket.newInstance();
+ sock.connect(new AFUNIXSocketAddress(socketFile));
+ return sock;
+ }
+
+ private void sendCommand(AFUNIXSocket sock, int cmd) throws IOException {
+ OutputStream os = sock.getOutputStream();
+ DataOutputStream dos = new DataOutputStream(os);
+ dos.writeInt(cmd);
+ os.close();
+ }
+
+}
diff --git a/src/test/java/org/openslx/AppTest.java b/src/test/java/org/openslx/AppTest.java
new file mode 100644
index 0000000..ff6e16e
--- /dev/null
+++ b/src/test/java/org/openslx/AppTest.java
@@ -0,0 +1,38 @@
+package org.openslx;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Unit test for simple App.
+ */
+public class AppTest
+ extends TestCase
+{
+ /**
+ * Create the test case
+ *
+ * @param testName name of the test case
+ */
+ public AppTest( String testName )
+ {
+ super( testName );
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite( AppTest.class );
+ }
+
+ /**
+ * Rigourous Test :-)
+ */
+ public void testApp()
+ {
+ assertTrue( true );
+ }
+}