mirror of
https://github.com/BlueMap-Minecraft/BlueMap.git
synced 2024-09-27 14:52:57 +02:00
S3 storage: fix issues from code review
This commit is contained in:
parent
09473e7b72
commit
43adac0dbf
@ -8,15 +8,14 @@
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
|
@SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"})
|
||||||
@DebugDump
|
|
||||||
@ConfigSerializable
|
@ConfigSerializable
|
||||||
public class S3Config extends StorageConfig implements S3StorageSettings {
|
public class S3Config extends StorageConfig implements S3StorageSettings {
|
||||||
private String endpoint = null;
|
@DebugDump private String endpoint = null;
|
||||||
private String region = "";
|
@DebugDump private String region = "";
|
||||||
private String accessKey = "";
|
@DebugDump private String accessKey = "";
|
||||||
private String secretKey = "";
|
private String secretKey = "";
|
||||||
private String bucket = "";
|
@DebugDump private String bucket = "";
|
||||||
private Compression compression = Compression.GZIP;
|
@DebugDump private Compression compression = Compression.GZIP;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<String> getEndpoint() {
|
public Optional<String> getEndpoint() {
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
import de.bluecolored.bluemap.core.util.OnCloseOutputStream;
|
import de.bluecolored.bluemap.core.util.OnCloseOutputStream;
|
||||||
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
|
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
|
||||||
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
|
||||||
|
import software.amazon.awssdk.core.exception.SdkException;
|
||||||
import software.amazon.awssdk.core.sync.RequestBody;
|
import software.amazon.awssdk.core.sync.RequestBody;
|
||||||
import software.amazon.awssdk.regions.Region;
|
import software.amazon.awssdk.regions.Region;
|
||||||
import software.amazon.awssdk.services.s3.S3Client;
|
import software.amazon.awssdk.services.s3.S3Client;
|
||||||
@ -62,10 +63,9 @@ public Optional<CompressedInputStream> readMapTile(String mapId, int lod, Vector
|
|||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
return Optional.of(new CompressedInputStream(is, compression));
|
return Optional.of(new CompressedInputStream(is, compression));
|
||||||
} catch (Exception e) {
|
} catch (NoSuchKeyException e) {
|
||||||
if (e instanceof NoSuchKeyException) {
|
return Optional.empty();
|
||||||
return Optional.empty();
|
} catch (SdkException e) {
|
||||||
}
|
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -104,10 +104,9 @@ public long getLastModified() {
|
|||||||
return info.lastModified().getEpochSecond();
|
return info.lastModified().getEpochSecond();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (NoSuchKeyException e) {
|
||||||
if (e instanceof NoSuchKeyException) {
|
return Optional.empty();
|
||||||
return Optional.empty();
|
} catch (SdkException e) {
|
||||||
}
|
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -123,10 +122,8 @@ public void deleteMapTile(String mapId, int lod, Vector2i tile) throws IOExcepti
|
|||||||
.key(path)
|
.key(path)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (NoSuchKeyException ignored) {
|
||||||
if (e instanceof NoSuchKeyException) {
|
} catch (SdkException e) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,10 +163,9 @@ public Optional<InputStream> readMeta(String mapId, String name) throws IOExcept
|
|||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
return Optional.of(is);
|
return Optional.of(is);
|
||||||
} catch (Exception e) {
|
} catch (NoSuchKeyException e) {
|
||||||
if (e instanceof NoSuchKeyException) {
|
return Optional.empty();
|
||||||
return Optional.empty();
|
} catch (SdkException e) {
|
||||||
}
|
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -197,10 +193,9 @@ public long getSize() {
|
|||||||
return info.contentLength();
|
return info.contentLength();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (Exception e) {
|
} catch (NoSuchKeyException e) {
|
||||||
if (e instanceof NoSuchKeyException) {
|
return Optional.empty();
|
||||||
return Optional.empty();
|
} catch (SdkException e) {
|
||||||
}
|
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -216,10 +211,8 @@ public void deleteMeta(String mapId, String name) throws IOException {
|
|||||||
.key(path)
|
.key(path)
|
||||||
.build()
|
.build()
|
||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (NoSuchKeyException ignored) {
|
||||||
if (e instanceof NoSuchKeyException) {
|
} catch (SdkException e) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -238,22 +231,21 @@ public void purgeMap(String mapId, Function<ProgressInfo, Boolean> onProgress) t
|
|||||||
var filesList = files.contents().stream().collect(Collectors.toList());
|
var filesList = files.contents().stream().collect(Collectors.toList());
|
||||||
for (int i = 0; i < filesList.size(); i++) {
|
for (int i = 0; i < filesList.size(); i++) {
|
||||||
var file = filesList.get(i);
|
var file = filesList.get(i);
|
||||||
client.deleteObject(
|
try {
|
||||||
DeleteObjectRequest
|
client.deleteObject(
|
||||||
.builder()
|
DeleteObjectRequest
|
||||||
.bucket(bucket)
|
.builder()
|
||||||
.key(file.key())
|
.bucket(bucket)
|
||||||
.build()
|
.key(file.key())
|
||||||
);
|
.build()
|
||||||
|
);
|
||||||
|
} catch (NoSuchKeyException ignored) {}
|
||||||
|
|
||||||
if (!onProgress.apply(
|
if (!onProgress.apply(
|
||||||
new ProgressInfo((double) (i + 1) / filesList.size())
|
new ProgressInfo((double) (i + 1) / filesList.size())
|
||||||
)) return;
|
)) return;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (SdkException e) {
|
||||||
if (e instanceof NoSuchKeyException) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
throw new IOException(e);
|
throw new IOException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user