mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
commit
690d7c10b8
|
@ -9,16 +9,12 @@ import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import javax.net.ssl.SSLException;
|
import javax.net.ssl.SSLException;
|
||||||
import java.util.Map;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class FilerGrpcClient {
|
public class FilerGrpcClient {
|
||||||
|
|
||||||
public final int VOLUME_SERVER_ACCESS_DIRECT = 0;
|
|
||||||
public final int VOLUME_SERVER_ACCESS_PUBLIC_URL = 1;
|
|
||||||
public final int VOLUME_SERVER_ACCESS_FILER_PROXY = 2;
|
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(FilerGrpcClient.class);
|
private static final Logger logger = LoggerFactory.getLogger(FilerGrpcClient.class);
|
||||||
static SslContext sslContext;
|
static SslContext sslContext;
|
||||||
|
|
||||||
|
@ -30,6 +26,9 @@ public class FilerGrpcClient {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final int VOLUME_SERVER_ACCESS_DIRECT = 0;
|
||||||
|
public final int VOLUME_SERVER_ACCESS_PUBLIC_URL = 1;
|
||||||
|
public final int VOLUME_SERVER_ACCESS_FILER_PROXY = 2;
|
||||||
public final Map<String, FilerProto.Locations> vidLocations = new HashMap<>();
|
public final Map<String, FilerProto.Locations> vidLocations = new HashMap<>();
|
||||||
private final ManagedChannel channel;
|
private final ManagedChannel channel;
|
||||||
private final SeaweedFilerGrpc.SeaweedFilerBlockingStub blockingStub;
|
private final SeaweedFilerGrpc.SeaweedFilerBlockingStub blockingStub;
|
||||||
|
@ -55,7 +54,7 @@ public class FilerGrpcClient {
|
||||||
.negotiationType(NegotiationType.TLS)
|
.negotiationType(NegotiationType.TLS)
|
||||||
.sslContext(sslContext));
|
.sslContext(sslContext));
|
||||||
|
|
||||||
filerAddress = String.format("%s:%d", host, grpcPort-10000);
|
filerAddress = String.format("%s:%d", host, grpcPort - 10000);
|
||||||
|
|
||||||
FilerProto.GetFilerConfigurationResponse filerConfigurationResponse =
|
FilerProto.GetFilerConfigurationResponse filerConfigurationResponse =
|
||||||
this.getBlockingStub().getFilerConfiguration(
|
this.getBlockingStub().getFilerConfiguration(
|
||||||
|
@ -104,23 +103,36 @@ public class FilerGrpcClient {
|
||||||
public void setAccessVolumeServerDirectly() {
|
public void setAccessVolumeServerDirectly() {
|
||||||
this.volumeServerAccess = VOLUME_SERVER_ACCESS_DIRECT;
|
this.volumeServerAccess = VOLUME_SERVER_ACCESS_DIRECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAccessVolumeServerDirectly() {
|
public boolean isAccessVolumeServerDirectly() {
|
||||||
return this.volumeServerAccess == VOLUME_SERVER_ACCESS_DIRECT;
|
return this.volumeServerAccess == VOLUME_SERVER_ACCESS_DIRECT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccessVolumeServerByPublicUrl() {
|
public void setAccessVolumeServerByPublicUrl() {
|
||||||
this.volumeServerAccess = VOLUME_SERVER_ACCESS_PUBLIC_URL;
|
this.volumeServerAccess = VOLUME_SERVER_ACCESS_PUBLIC_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAccessVolumeServerByPublicUrl() {
|
public boolean isAccessVolumeServerByPublicUrl() {
|
||||||
return this.volumeServerAccess == VOLUME_SERVER_ACCESS_PUBLIC_URL;
|
return this.volumeServerAccess == VOLUME_SERVER_ACCESS_PUBLIC_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccessVolumeServerByFilerProxy() {
|
public void setAccessVolumeServerByFilerProxy() {
|
||||||
this.volumeServerAccess = VOLUME_SERVER_ACCESS_FILER_PROXY;
|
this.volumeServerAccess = VOLUME_SERVER_ACCESS_FILER_PROXY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAccessVolumeServerByFilerProxy() {
|
public boolean isAccessVolumeServerByFilerProxy() {
|
||||||
return this.volumeServerAccess == VOLUME_SERVER_ACCESS_FILER_PROXY;
|
return this.volumeServerAccess == VOLUME_SERVER_ACCESS_FILER_PROXY;
|
||||||
}
|
}
|
||||||
public String getFilerAddress() {
|
|
||||||
return this.filerAddress;
|
public String getChunkUrl(String chunkId, String url, String publicUrl) {
|
||||||
|
switch (this.volumeServerAccess) {
|
||||||
|
case VOLUME_SERVER_ACCESS_PUBLIC_URL:
|
||||||
|
return String.format("http://%s/%s", publicUrl, chunkId);
|
||||||
|
case VOLUME_SERVER_ACCESS_FILER_PROXY:
|
||||||
|
return String.format("http://%s/?proxyChunkId=%s", this.filerAddress, chunkId);
|
||||||
|
default:
|
||||||
|
return String.format("http://%s/%s", url, chunkId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,13 +116,7 @@ public class SeaweedRead {
|
||||||
IOException lastException = null;
|
IOException lastException = null;
|
||||||
for (long waitTime = 1000L; waitTime < 10 * 1000; waitTime += waitTime / 2) {
|
for (long waitTime = 1000L; waitTime < 10 * 1000; waitTime += waitTime / 2) {
|
||||||
for (FilerProto.Location location : locations.getLocationsList()) {
|
for (FilerProto.Location location : locations.getLocationsList()) {
|
||||||
String host = location.getUrl();
|
String url = filerGrpcClient.getChunkUrl(chunkView.fileId, location.getUrl(), location.getPublicUrl());
|
||||||
if (filerGrpcClient.isAccessVolumeServerByPublicUrl()) {
|
|
||||||
host = location.getPublicUrl();
|
|
||||||
} else if (filerGrpcClient.isAccessVolumeServerByFilerProxy()) {
|
|
||||||
host = filerGrpcClient.getFilerAddress();
|
|
||||||
}
|
|
||||||
String url = String.format("http://%s/%s", host, chunkView.fileId);
|
|
||||||
try {
|
try {
|
||||||
data = doFetchOneFullChunkData(chunkView, url);
|
data = doFetchOneFullChunkData(chunkView, url);
|
||||||
lastException = null;
|
lastException = null;
|
||||||
|
|
|
@ -53,13 +53,7 @@ public class SeaweedWrite {
|
||||||
String fileId = response.getFileId();
|
String fileId = response.getFileId();
|
||||||
String auth = response.getAuth();
|
String auth = response.getAuth();
|
||||||
|
|
||||||
String host = response.getUrl();
|
String targetUrl = filerGrpcClient.getChunkUrl(fileId, response.getUrl(), response.getPublicUrl());
|
||||||
if (filerGrpcClient.isAccessVolumeServerByPublicUrl()) {
|
|
||||||
host = response.getPublicUrl();
|
|
||||||
} else if (filerGrpcClient.isAccessVolumeServerByFilerProxy()) {
|
|
||||||
host = filerGrpcClient.getFilerAddress();
|
|
||||||
}
|
|
||||||
String targetUrl = String.format("http://%s/%s", host, fileId);
|
|
||||||
|
|
||||||
ByteString cipherKeyString = com.google.protobuf.ByteString.EMPTY;
|
ByteString cipherKeyString = com.google.protobuf.ByteString.EMPTY;
|
||||||
byte[] cipherKey = null;
|
byte[] cipherKey = null;
|
||||||
|
|
Loading…
Reference in a new issue