Skip to content
Permalink
Browse files
Basic WebDAV server, using key-value store and blobs on cloud files
  • Loading branch information
justinsb committed Dec 20, 2013
1 parent 25aff52 commit f6680430ff8ee5027f8da73b69806cb552ed2154
Show file tree
Hide file tree
Showing 95 changed files with 5,976 additions and 47 deletions.
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>

<parent>
<groupId>com.cloudata</groupId>
<artifactId>cloudata-parent</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>cloudata-files</artifactId>

<properties>
<jgit.version>3.1.0.201310021548-r</jgit.version>
<jetty.version>9.1.0.v20131115</jetty.version>
<jclouds.version>1.6.0</jclouds.version>
</properties>


<dependencies>
<dependency>
<groupId>com.cloudata</groupId>
<artifactId>cloudata-server-shared</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.jclouds.provider</groupId>
<artifactId>cloudfiles-us</artifactId>
<version>${jclouds.version}</version>
</dependency>

<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.11</version>
</dependency>

<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>15.0</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
</dependency>




<!-- <dependency> <groupId>com.woorea</groupId> <artifactId>keystone-client</artifactId>
<version>3.2.2-SNAPSHOT</version> </dependency> <dependency> <groupId>com.woorea</groupId>
<artifactId>swift-client</artifactId> <version>3.2.2-SNAPSHOT</version> </dependency>
<dependency> <groupId>com.woorea</groupId> <artifactId>jersey-connector</artifactId>
<version>3.2.2-SNAPSHOT</version> </dependency> -->


<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>redis.clients</groupId>
<artifactId>jedis</artifactId>
<version>2.2.1</version>
</dependency>

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit.http.server</artifactId>
<version>${jgit.version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>${jgit.version}</version>
</dependency>
<dependency>
<groupId>com.google.inject.extensions</groupId>
<artifactId>guice-servlet</artifactId>
<version>3.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-2</version>
<configuration>
<descriptors>
<descriptor>src/main/assembly/assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>
</plugins>
</build>
</project>
@@ -0,0 +1,27 @@
<assembly>
<id>bundle</id>
<formats>
<format>tar.gz</format>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<fileSets>
<fileSet>
<directory>src/main/bin</directory>
<outputDirectory>bin</outputDirectory>
<includes>
<include>*.sh</include>
</includes>
<lineEnding>unix</lineEnding>
<fileMode>0744</fileMode>
</fileSet>
</fileSets>
<dependencySets>
<dependencySet>
<scope>runtime</scope>
<useProjectArtifact>true</useProjectArtifact>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
</assembly>
@@ -0,0 +1,67 @@
package com.cloudata.files;

import java.io.IOException;

import javax.inject.Inject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.cloudata.files.fs.FsClient;
import com.cloudata.files.fs.FsCredentials;
import com.cloudata.files.fs.FsVolume;
import com.cloudata.files.webdav.netty.WebdavNettyServer;
import com.google.common.base.Preconditions;
import com.google.inject.Guice;
import com.google.inject.Injector;

public class FileServer {
private static final Logger log = LoggerFactory.getLogger(FileServer.class);

int httpPort = 8888;

@Inject
WebdavNettyServer nettyServer;

@Inject
FsClient fsClient;

public synchronized void start() throws Exception {
Preconditions.checkState(!nettyServer.isStarted());
nettyServer.start(httpPort);
}

public static void main(String... args) throws Exception {
Injector injector = Guice.createInjector(new FileServerModule());

final FileServer server = injector.getInstance(FileServer.class);

FsCredentials credentials = null;
server.ensureFilesystem(FsVolume.fromHost("1"), credentials);

server.start();

Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
server.stop();
} catch (Exception e) {
log.warn("Error shutting down HTTP server", e);
}
}
});
}

private void ensureFilesystem(FsVolume volume, FsCredentials credentials) throws IOException {
fsClient.ensureFilesystem(volume, credentials);
}

public synchronized void stop() throws Exception {
if (nettyServer != null) {
nettyServer.stop();
nettyServer = null;
}
}

}
@@ -0,0 +1,32 @@
package com.cloudata.files;

import java.io.File;
import java.net.InetSocketAddress;

import com.cloudata.clients.keyvalue.KeyValueStore;
import com.cloudata.clients.keyvalue.RedisKeyValueStore;
import com.cloudata.files.blobs.BlobCache;
import com.cloudata.files.blobs.BlobStore;
import com.cloudata.files.blobs.LocalBlobStore;
import com.cloudata.files.locks.InMemoryLockService;
import com.cloudata.files.locks.LockService;
import com.google.inject.AbstractModule;

public class FileServerModule extends AbstractModule {

@Override
protected void configure() {
bind(LockService.class).to(InMemoryLockService.class);

InetSocketAddress redisSocketAddress = new InetSocketAddress("localhost", 6379);
KeyValueStore keyValueStore = new RedisKeyValueStore(redisSocketAddress);
bind(KeyValueStore.class).toInstance(keyValueStore);

File basePath = new File("/tmp/blobs/store");
File cacheDir = new File("/tmp/blobs/cache");
BlobCache cache = new BlobCache(cacheDir);
LocalBlobStore blobStore = new LocalBlobStore(cache, basePath);
bind(BlobStore.class).toInstance(blobStore);
}

}

0 comments on commit f668043

Please sign in to comment.