aboutsummaryrefslogtreecommitdiff
path: root/other/java/client/src
diff options
context:
space:
mode:
authorjoeslay <54322500+joeslay@users.noreply.github.com>2019-09-02 11:39:40 +0100
committerGitHub <noreply@github.com>2019-09-02 11:39:40 +0100
commite91139348e795b64ac3329885c29e68c8863393d (patch)
tree476f3da86e1867487b46835406eecbf6cf286f68 /other/java/client/src
parent595a1beff00196c9b207787833578ba1de1847e5 (diff)
parent60c9215a00d9b72be6f7d0e5382227d2b57de9d5 (diff)
downloadseaweedfs-e91139348e795b64ac3329885c29e68c8863393d.tar.xz
seaweedfs-e91139348e795b64ac3329885c29e68c8863393d.zip
Merge pull request #2 from chrislusf/master
merge seaweed master
Diffstat (limited to 'other/java/client/src')
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/FilerClient.java10
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java46
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/FilerSslContext.java64
-rw-r--r--other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java2
-rw-r--r--other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java23
5 files changed, 114 insertions, 31 deletions
diff --git a/other/java/client/src/main/java/seaweedfs/client/FilerClient.java b/other/java/client/src/main/java/seaweedfs/client/FilerClient.java
index f4bd0944b..1ea4cb889 100644
--- a/other/java/client/src/main/java/seaweedfs/client/FilerClient.java
+++ b/other/java/client/src/main/java/seaweedfs/client/FilerClient.java
@@ -34,13 +34,12 @@ public class FilerClient {
public boolean mkdirs(String path, int mode, int uid, int gid, String userName, String[] groupNames) {
- Path pathObject = Paths.get(path);
- String parent = pathObject.getParent().toString();
- String name = pathObject.getFileName().toString();
-
if ("/".equals(path)) {
return true;
}
+ Path pathObject = Paths.get(path);
+ String parent = pathObject.getParent().toString();
+ String name = pathObject.getFileName().toString();
mkdirs(parent, mode, uid, gid, userName, groupNames);
@@ -195,6 +194,9 @@ public class FilerClient {
.build()).getEntry();
return fixEntryAfterReading(entry);
} catch (Exception e) {
+ if (e.getMessage().indexOf("filer: no entry is found in filer store")>0){
+ return null;
+ }
LOG.warn("lookupEntry {}/{}: {}", directory, entryName, e);
return null;
}
diff --git a/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java b/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java
index c28c1dcf2..3626c76de 100644
--- a/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java
+++ b/other/java/client/src/main/java/seaweedfs/client/FilerGrpcClient.java
@@ -2,39 +2,46 @@ package seaweedfs.client;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
-import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
import io.grpc.netty.shaded.io.grpc.netty.NegotiationType;
import io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder;
import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext;
-import io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import javax.net.ssl.SSLException;
-import java.io.File;
import java.util.concurrent.TimeUnit;
-import java.util.logging.Logger;
public class FilerGrpcClient {
- private static final Logger logger = Logger.getLogger(FilerGrpcClient.class.getName());
+ private static final Logger logger = LoggerFactory.getLogger(FilerGrpcClient.class);
private final ManagedChannel channel;
private final SeaweedFilerGrpc.SeaweedFilerBlockingStub blockingStub;
private final SeaweedFilerGrpc.SeaweedFilerStub asyncStub;
private final SeaweedFilerGrpc.SeaweedFilerFutureStub futureStub;
+ static SslContext sslContext;
+
+ static {
+ try {
+ sslContext = FilerSslContext.loadSslContext();
+ } catch (SSLException e) {
+ logger.warn("failed to load ssl context", e);
+ }
+ }
public FilerGrpcClient(String host, int grpcPort) {
- this(ManagedChannelBuilder.forAddress(host, grpcPort).usePlaintext());
+ this(host, grpcPort, sslContext);
}
- public FilerGrpcClient(String host, int grpcPort,
- String caFilePath,
- String clientCertFilePath,
- String clientPrivateKeyFilePath) throws SSLException {
+ public FilerGrpcClient(String host, int grpcPort, SslContext sslContext) {
+
+ this(sslContext == null ?
+ ManagedChannelBuilder.forAddress(host, grpcPort).usePlaintext() :
+ NettyChannelBuilder.forAddress(host, grpcPort)
+ .negotiationType(NegotiationType.TLS)
+ .sslContext(sslContext));
- this(NettyChannelBuilder.forAddress(host, grpcPort)
- .negotiationType(NegotiationType.TLS)
- .sslContext(buildSslContext(caFilePath,clientCertFilePath,clientPrivateKeyFilePath)));
}
public FilerGrpcClient(ManagedChannelBuilder<?> channelBuilder) {
@@ -60,17 +67,4 @@ public class FilerGrpcClient {
return futureStub;
}
- private static SslContext buildSslContext(String trustCertCollectionFilePath,
- String clientCertChainFilePath,
- String clientPrivateKeyFilePath) throws SSLException {
- SslContextBuilder builder = GrpcSslContexts.forClient();
- if (trustCertCollectionFilePath != null) {
- builder.trustManager(new File(trustCertCollectionFilePath));
- }
- if (clientCertChainFilePath != null && clientPrivateKeyFilePath != null) {
- builder.keyManager(new File(clientCertChainFilePath), new File(clientPrivateKeyFilePath));
- }
- return builder.build();
- }
-
}
diff --git a/other/java/client/src/main/java/seaweedfs/client/FilerSslContext.java b/other/java/client/src/main/java/seaweedfs/client/FilerSslContext.java
new file mode 100644
index 000000000..5a88c1da3
--- /dev/null
+++ b/other/java/client/src/main/java/seaweedfs/client/FilerSslContext.java
@@ -0,0 +1,64 @@
+package seaweedfs.client;
+
+import com.google.common.base.Strings;
+import com.moandjiezana.toml.Toml;
+import io.grpc.netty.shaded.io.grpc.netty.GrpcSslContexts;
+import io.grpc.netty.shaded.io.netty.handler.ssl.SslContext;
+import io.grpc.netty.shaded.io.netty.handler.ssl.SslContextBuilder;
+import io.grpc.netty.shaded.io.netty.handler.ssl.util.InsecureTrustManagerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.net.ssl.SSLException;
+import java.io.File;
+
+public class FilerSslContext {
+
+ private static final Logger logger = LoggerFactory.getLogger(FilerSslContext.class);
+
+ public static SslContext loadSslContext() throws SSLException {
+ String securityFileName = "security.toml";
+ String home = System.getProperty("user.home");
+ File f1 = new File("./"+securityFileName);
+ File f2 = new File(home + "/.seaweedfs/"+securityFileName);
+ File f3 = new File(home + "/etc/seaweedfs/"+securityFileName);
+
+ File securityFile = f1.exists()? f1 : f2.exists() ? f2 : f3.exists()? f3 : null;
+
+ if (securityFile==null){
+ return null;
+ }
+
+ Toml toml = new Toml().read(securityFile);
+ logger.debug("reading ssl setup from {}", securityFile);
+
+ String trustCertCollectionFilePath = toml.getString("grpc.ca");
+ logger.debug("loading ca from {}", trustCertCollectionFilePath);
+ String clientCertChainFilePath = toml.getString("grpc.client.cert");
+ logger.debug("loading client ca from {}", clientCertChainFilePath);
+ String clientPrivateKeyFilePath = toml.getString("grpc.client.key");
+ logger.debug("loading client key from {}", clientPrivateKeyFilePath);
+
+ if (Strings.isNullOrEmpty(clientPrivateKeyFilePath) && Strings.isNullOrEmpty(clientPrivateKeyFilePath)){
+ return null;
+ }
+
+ // possibly fix the format https://netty.io/wiki/sslcontextbuilder-and-private-key.html
+
+ return buildSslContext(trustCertCollectionFilePath, clientCertChainFilePath, clientPrivateKeyFilePath);
+ }
+
+
+ private static SslContext buildSslContext(String trustCertCollectionFilePath,
+ String clientCertChainFilePath,
+ String clientPrivateKeyFilePath) throws SSLException {
+ SslContextBuilder builder = GrpcSslContexts.forClient();
+ if (trustCertCollectionFilePath != null) {
+ builder.trustManager(new File(trustCertCollectionFilePath));
+ }
+ if (clientCertChainFilePath != null && clientPrivateKeyFilePath != null) {
+ builder.keyManager(new File(clientCertChainFilePath), new File(clientPrivateKeyFilePath));
+ }
+ return builder.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
+ }
+}
diff --git a/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java b/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
index a906a689b..a307983bb 100644
--- a/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
+++ b/other/java/client/src/main/java/seaweedfs/client/SeaweedRead.java
@@ -86,7 +86,7 @@ public class SeaweedRead {
return 0;
}
- public static List<ChunkView> viewFromVisibles(List<VisibleInterval> visibleIntervals, long offset, long size) {
+ protected static List<ChunkView> viewFromVisibles(List<VisibleInterval> visibleIntervals, long offset, long size) {
List<ChunkView> views = new ArrayList<>();
long stop = offset + size;
diff --git a/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java b/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java
new file mode 100644
index 000000000..87165af0c
--- /dev/null
+++ b/other/java/client/src/test/java/seaweedfs/client/SeaweedFilerTest.java
@@ -0,0 +1,23 @@
+package seaweedfs.client;
+
+import java.util.List;
+
+public class SeaweedFilerTest {
+ public static void main(String[] args){
+
+ FilerClient filerClient = new FilerClient("localhost", 18888);
+
+ List<FilerProto.Entry> entries = filerClient.listEntries("/");
+
+ for (FilerProto.Entry entry : entries) {
+ System.out.println(entry.toString());
+ }
+
+ filerClient.mkdirs("/new_folder", 0755);
+ filerClient.touch("/new_folder/new_empty_file", 0755);
+ filerClient.touch("/new_folder/new_empty_file2", 0755);
+ filerClient.rm("/new_folder/new_empty_file", false);
+ filerClient.rm("/new_folder", true);
+
+ }
+}