Skip to content

Commit f668043

Browse files
committed
Basic WebDAV server, using key-value store and blobs on cloud files
1 parent 25aff52 commit f668043

95 files changed

Lines changed: 5976 additions & 47 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cloudata-files/pom.xml

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>com.cloudata</groupId>
8+
<artifactId>cloudata-parent</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
</parent>
11+
12+
<artifactId>cloudata-files</artifactId>
13+
14+
<properties>
15+
<jgit.version>3.1.0.201310021548-r</jgit.version>
16+
<jetty.version>9.1.0.v20131115</jetty.version>
17+
<jclouds.version>1.6.0</jclouds.version>
18+
</properties>
19+
20+
21+
<dependencies>
22+
<dependency>
23+
<groupId>com.cloudata</groupId>
24+
<artifactId>cloudata-server-shared</artifactId>
25+
<version>${project.version}</version>
26+
</dependency>
27+
28+
<dependency>
29+
<groupId>org.jclouds.provider</groupId>
30+
<artifactId>cloudfiles-us</artifactId>
31+
<version>${jclouds.version}</version>
32+
</dependency>
33+
34+
<dependency>
35+
<groupId>ch.qos.logback</groupId>
36+
<artifactId>logback-classic</artifactId>
37+
<version>1.0.11</version>
38+
</dependency>
39+
40+
<dependency>
41+
<groupId>com.google.protobuf</groupId>
42+
<artifactId>protobuf-java</artifactId>
43+
<version>2.5.0</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>com.google.guava</groupId>
47+
<artifactId>guava</artifactId>
48+
<version>15.0</version>
49+
</dependency>
50+
51+
<dependency>
52+
<groupId>org.eclipse.jetty</groupId>
53+
<artifactId>jetty-server</artifactId>
54+
<version>${jetty.version}</version>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.eclipse.jetty</groupId>
59+
<artifactId>jetty-webapp</artifactId>
60+
<version>${jetty.version}</version>
61+
</dependency>
62+
63+
64+
65+
66+
<!-- <dependency> <groupId>com.woorea</groupId> <artifactId>keystone-client</artifactId>
67+
<version>3.2.2-SNAPSHOT</version> </dependency> <dependency> <groupId>com.woorea</groupId>
68+
<artifactId>swift-client</artifactId> <version>3.2.2-SNAPSHOT</version> </dependency>
69+
<dependency> <groupId>com.woorea</groupId> <artifactId>jersey-connector</artifactId>
70+
<version>3.2.2-SNAPSHOT</version> </dependency> -->
71+
72+
73+
<dependency>
74+
<groupId>junit</groupId>
75+
<artifactId>junit</artifactId>
76+
<scope>test</scope>
77+
</dependency>
78+
79+
<dependency>
80+
<groupId>redis.clients</groupId>
81+
<artifactId>jedis</artifactId>
82+
<version>2.2.1</version>
83+
</dependency>
84+
85+
<dependency>
86+
<groupId>org.eclipse.jgit</groupId>
87+
<artifactId>org.eclipse.jgit.http.server</artifactId>
88+
<version>${jgit.version}</version>
89+
</dependency>
90+
91+
<dependency>
92+
<groupId>org.eclipse.jgit</groupId>
93+
<artifactId>org.eclipse.jgit</artifactId>
94+
<version>${jgit.version}</version>
95+
</dependency>
96+
<dependency>
97+
<groupId>com.google.inject.extensions</groupId>
98+
<artifactId>guice-servlet</artifactId>
99+
<version>3.0</version>
100+
</dependency>
101+
</dependencies>
102+
103+
<build>
104+
<plugins>
105+
<plugin>
106+
<artifactId>maven-assembly-plugin</artifactId>
107+
<version>2.2-beta-2</version>
108+
<configuration>
109+
<descriptors>
110+
<descriptor>src/main/assembly/assembly.xml</descriptor>
111+
</descriptors>
112+
</configuration>
113+
</plugin>
114+
</plugins>
115+
</build>
116+
</project>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<assembly>
2+
<id>bundle</id>
3+
<formats>
4+
<format>tar.gz</format>
5+
<format>dir</format>
6+
</formats>
7+
<includeBaseDirectory>false</includeBaseDirectory>
8+
<fileSets>
9+
<fileSet>
10+
<directory>src/main/bin</directory>
11+
<outputDirectory>bin</outputDirectory>
12+
<includes>
13+
<include>*.sh</include>
14+
</includes>
15+
<lineEnding>unix</lineEnding>
16+
<fileMode>0744</fileMode>
17+
</fileSet>
18+
</fileSets>
19+
<dependencySets>
20+
<dependencySet>
21+
<scope>runtime</scope>
22+
<useProjectArtifact>true</useProjectArtifact>
23+
<outputDirectory>lib</outputDirectory>
24+
<unpack>false</unpack>
25+
</dependencySet>
26+
</dependencySets>
27+
</assembly>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.cloudata.files;
2+
3+
import java.io.IOException;
4+
5+
import javax.inject.Inject;
6+
7+
import org.slf4j.Logger;
8+
import org.slf4j.LoggerFactory;
9+
10+
import com.cloudata.files.fs.FsClient;
11+
import com.cloudata.files.fs.FsCredentials;
12+
import com.cloudata.files.fs.FsVolume;
13+
import com.cloudata.files.webdav.netty.WebdavNettyServer;
14+
import com.google.common.base.Preconditions;
15+
import com.google.inject.Guice;
16+
import com.google.inject.Injector;
17+
18+
public class FileServer {
19+
private static final Logger log = LoggerFactory.getLogger(FileServer.class);
20+
21+
int httpPort = 8888;
22+
23+
@Inject
24+
WebdavNettyServer nettyServer;
25+
26+
@Inject
27+
FsClient fsClient;
28+
29+
public synchronized void start() throws Exception {
30+
Preconditions.checkState(!nettyServer.isStarted());
31+
nettyServer.start(httpPort);
32+
}
33+
34+
public static void main(String... args) throws Exception {
35+
Injector injector = Guice.createInjector(new FileServerModule());
36+
37+
final FileServer server = injector.getInstance(FileServer.class);
38+
39+
FsCredentials credentials = null;
40+
server.ensureFilesystem(FsVolume.fromHost("1"), credentials);
41+
42+
server.start();
43+
44+
Runtime.getRuntime().addShutdownHook(new Thread() {
45+
@Override
46+
public void run() {
47+
try {
48+
server.stop();
49+
} catch (Exception e) {
50+
log.warn("Error shutting down HTTP server", e);
51+
}
52+
}
53+
});
54+
}
55+
56+
private void ensureFilesystem(FsVolume volume, FsCredentials credentials) throws IOException {
57+
fsClient.ensureFilesystem(volume, credentials);
58+
}
59+
60+
public synchronized void stop() throws Exception {
61+
if (nettyServer != null) {
62+
nettyServer.stop();
63+
nettyServer = null;
64+
}
65+
}
66+
67+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.cloudata.files;
2+
3+
import java.io.File;
4+
import java.net.InetSocketAddress;
5+
6+
import com.cloudata.clients.keyvalue.KeyValueStore;
7+
import com.cloudata.clients.keyvalue.RedisKeyValueStore;
8+
import com.cloudata.files.blobs.BlobCache;
9+
import com.cloudata.files.blobs.BlobStore;
10+
import com.cloudata.files.blobs.LocalBlobStore;
11+
import com.cloudata.files.locks.InMemoryLockService;
12+
import com.cloudata.files.locks.LockService;
13+
import com.google.inject.AbstractModule;
14+
15+
public class FileServerModule extends AbstractModule {
16+
17+
@Override
18+
protected void configure() {
19+
bind(LockService.class).to(InMemoryLockService.class);
20+
21+
InetSocketAddress redisSocketAddress = new InetSocketAddress("localhost", 6379);
22+
KeyValueStore keyValueStore = new RedisKeyValueStore(redisSocketAddress);
23+
bind(KeyValueStore.class).toInstance(keyValueStore);
24+
25+
File basePath = new File("/tmp/blobs/store");
26+
File cacheDir = new File("/tmp/blobs/cache");
27+
BlobCache cache = new BlobCache(cacheDir);
28+
LocalBlobStore blobStore = new LocalBlobStore(cache, basePath);
29+
bind(BlobStore.class).toInstance(blobStore);
30+
}
31+
32+
}

0 commit comments

Comments
 (0)