Skip to content

Commit

Permalink
Move to world.gfi.nfs4j package and add exception handling on API
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed Dec 18, 2018
1 parent 937b516 commit 3c61bd6
Show file tree
Hide file tree
Showing 42 changed files with 454 additions and 181 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ This project has been designed as an alternative to [winnfsd](https://github.com

## Quickstart

- Download latest binaries from [Github Releases](https://github.com/Toilal/nfs4j-daemon/releases).
- Download latest binaries from [Github Releases](https://github.com/gfi-centre-ouest/nfs4j-daemon/releases).

- Run `nfs4j-daemon`. With default options, it will publish the current working directory through NFS.

Expand Down
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
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>io.github.toilal.nsf4j</groupId>
<groupId>world.gfi.nsf4j</groupId>
<artifactId>nfs4j-daemon</artifactId>
<version>1.0-SNAPSHOT</version>

<name>Pure Java NFS v3/v4.1 server backed by dCache nfs4j</name>
<url>https://toilal.github.io/nfs4j-daemon</url>
<url>https://gfi-centre-ouest.github.io/nfs4j-daemon</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -43,7 +43,7 @@
<outputDirectory>dist/jar</outputDirectory>
<archive>
<manifest>
<mainClass>io.github.toilal.nsf4j.Main</mainClass>
<mainClass>world.gfi.nfs4j.Main</mainClass>
</manifest>
</archive>
</configuration>
Expand Down Expand Up @@ -91,7 +91,7 @@
<stayAlive>false</stayAlive>
<restartOnCrash>false</restartOnCrash>
<classPath>
<mainClass>io.github.toilal.nsf4j.Main</mainClass>
<mainClass>world.gfi.nfs4j.Main</mainClass>
<addDependencies>true</addDependencies>
</classPath>
<jre>
Expand Down
90 changes: 0 additions & 90 deletions src/main/java/io/github/toilal/nsf4j/api/Api.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
package io.github.toilal.nsf4j;

import io.github.toilal.nsf4j.api.Api;
import io.github.toilal.nsf4j.api.JsonTransformer;
import io.github.toilal.nsf4j.config.Config;
import io.github.toilal.nsf4j.config.ShareConfig;
import io.github.toilal.nsf4j.fs.AttachableFileSystem;
import io.github.toilal.nsf4j.fs.DefaultFileSystemFactory;
import io.github.toilal.nsf4j.fs.RootFileSystem;
import io.github.toilal.nsf4j.fs.handle.UniqueAtomicLongGenerator;
import io.github.toilal.nsf4j.fs.permission.DefaultPermissionsMapperFactory;
import io.github.toilal.nsf4j.fs.permission.PermissionsMapper;
import io.github.toilal.nsf4j.status.Status;
import io.github.toilal.nsf4j.status.StatusShare;
package world.gfi.nfs4j;

import org.dcache.nfs.ExportFile;
import org.dcache.nfs.v3.MountServer;
import org.dcache.nfs.v3.NfsServerV3;
Expand All @@ -25,6 +13,21 @@
import org.dcache.oncrpc4j.rpc.OncRpcProgram;
import org.dcache.oncrpc4j.rpc.OncRpcSvc;
import org.dcache.oncrpc4j.rpc.OncRpcSvcBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import world.gfi.nfs4j.api.Api;
import world.gfi.nfs4j.api.JsonTransformer;
import world.gfi.nfs4j.config.Config;
import world.gfi.nfs4j.config.ShareConfig;
import world.gfi.nfs4j.exceptions.AttachException;
import world.gfi.nfs4j.fs.AttachableFileSystem;
import world.gfi.nfs4j.fs.DefaultFileSystemFactory;
import world.gfi.nfs4j.fs.RootFileSystem;
import world.gfi.nfs4j.fs.handle.UniqueAtomicLongGenerator;
import world.gfi.nfs4j.fs.permission.DefaultPermissionsMapperFactory;
import world.gfi.nfs4j.fs.permission.PermissionsMapper;
import world.gfi.nfs4j.status.Status;
import world.gfi.nfs4j.status.StatusShare;

import java.io.Closeable;
import java.io.FileInputStream;
Expand All @@ -42,6 +45,8 @@
* nfs4j Daemon.
*/
public class Daemon implements Closeable {
private static final Logger LOG = LoggerFactory.getLogger(Daemon.class);

private final OncRpcSvc nfsSvc;
private final PermissionsMapper defaultPermissionsMapper;
private final DefaultPermissionsMapperFactory permissionsMapperFactory;
Expand All @@ -52,7 +57,7 @@ public class Daemon implements Closeable {
private Api api;
private OncRpcEmbeddedPortmap portmapSvc = null;

public Daemon(Config config) {
public Daemon(Config config) throws AttachException {
this.config = config;

ExportFile exportFile;
Expand Down Expand Up @@ -119,18 +124,31 @@ public Daemon(Config config) {
}
}

public AttachableFileSystem attach(ShareConfig share) {
public AttachableFileSystem attach(ShareConfig share) throws AttachException {
PermissionsMapper permissionsMapper = defaultPermissionsMapper;
if (share.getPermissions() != null) {
permissionsMapper = permissionsMapperFactory.newPermissionsMapper(share.getPermissions());
}
AttachableFileSystem shareVfs = fsFactory.newFileSystem(share.getPath(), permissionsMapper, uniqueHandleGenerator);
vfs.attachFileSystem(shareVfs, share.getAlias());
String alias = share.getAlias();
if (alias == null) {
alias = share.buildDefaultAlias();
} else if (share.isAppendDefaultAlias()) {
alias = alias + share.buildDefaultAlias();
}
vfs.attachFileSystem(shareVfs, alias);
share.setPath(shareVfs.getRoot());
share.setAlias(shareVfs.getAlias());
LOG.info("Share has been attached: " + share);
return shareVfs;
}

public AttachableFileSystem detach(ShareConfig share) {
return vfs.detachFileSystem(share.getAlias());
public AttachableFileSystem detach(ShareConfig share) throws AttachException {
AttachableFileSystem detached = vfs.detachFileSystem(share.getAlias());
share.setPath(detached.getRoot());
share.setAlias(detached.getAlias());
LOG.info("Share has been detached: " + share);
return detached;
}

public void start() throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package io.github.toilal.nsf4j;
package world.gfi.nfs4j;

import io.github.toilal.nsf4j.config.ApiConfig;
import io.github.toilal.nsf4j.config.Config;
import io.github.toilal.nsf4j.config.CustomConstructor;
import io.github.toilal.nsf4j.config.CustomRepresenter;
import io.github.toilal.nsf4j.config.ShareConfig;
import org.yaml.snakeyaml.Yaml;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;
import world.gfi.nfs4j.config.ApiConfig;
import world.gfi.nfs4j.config.Config;
import world.gfi.nfs4j.config.CustomConstructor;
import world.gfi.nfs4j.config.CustomRepresenter;
import world.gfi.nfs4j.config.ShareConfig;

import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -156,10 +156,7 @@ public Void call() throws Exception {
for (ShareConfig share : config.getShares()) {
if (share.getAlias() == null) {
if (config.getShares().size() > 1) {
String defaultAlias = share.getPath().toAbsolutePath().normalize().toString().replace(":", "").replace(File.separator, "/");
if (!defaultAlias.startsWith("/")) {
defaultAlias = "/" + defaultAlias;
}
String defaultAlias = share.buildDefaultAlias();
share.setAlias(defaultAlias);
} else {
share.setAlias("/");
Expand Down
Loading

0 comments on commit 3c61bd6

Please sign in to comment.