Skip to content

Commit

Permalink
set target bucket versioning bug fix (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
HeoKyungseok committed Mar 10, 2022
1 parent ad9a0df commit 8177419
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 12 deletions.
10 changes: 5 additions & 5 deletions src/main/java/ifs_mover/ObjectMover.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.SdkClientException;
import com.amazonaws.services.s3.model.BucketVersioningConfiguration;
import com.amazonaws.services.s3.model.ObjectMetadata;
import com.amazonaws.services.s3.model.PartETag;
import com.amazonaws.services.s3.model.Tag;
Expand Down Expand Up @@ -144,7 +145,8 @@ public void init() {
}

// check source bucket versioning
if (sourceRepository.getVersioning()) {
if (sourceRepository.isVersioning()) {
isVersioning = true;
targetRepository.setVersioning();
}

Expand Down Expand Up @@ -281,12 +283,10 @@ public void moveObjects() {
long size = failedJob.get(DBManager.MOVE_OBJECTS_TABLE_COLUMN_SIZE).longValue();
DBManager.updateJobFailedInfo(jobId, size);
}

if (isVersioning) {
try {
if (sourceRepository.getVersioning()) {
targetRepository.setVersioning();
}
targetRepository.setBucketVersioning(sourceRepository.getVersioningStatus());
} catch (AmazonServiceException ase) {
logger.warn("{} {}", ase.getErrorCode(), ase.getErrorMessage());
} catch (SdkClientException ace) {
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/ifs_mover/repository/IfsFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private void objectListRerun(String dirPath) {
}

@Override
public boolean getVersioning() {
public boolean isVersioning() {
return false;
}

Expand Down Expand Up @@ -266,4 +266,10 @@ public ObjectData getObject(String bucket, String key, String versionId) {
public ObjectData getObject(String bucket, String key, String versionId, long start, long end) {
return null;
}

@Override
public String getVersioningStatus() {
// TODO Auto-generated method stub
return null;
}
}
26 changes: 23 additions & 3 deletions src/main/java/ifs_mover/repository/IfsS3.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public class IfsS3 implements Repository, S3 {
private boolean isAWS;
private boolean isSecure;
private boolean isVersioning;
private String versioningStatus;
private AmazonS3 client;
private String errCode;
private String errMessage;
Expand Down Expand Up @@ -417,9 +418,10 @@ public int init(String type) {
}

@Override
public boolean getVersioning() {
public boolean isVersioning() {
try {
versionConfig = client.getBucketVersioningConfiguration(config.getBucket());
versioningStatus = versionConfig.getStatus();
if (versionConfig.getStatus().equals(BucketVersioningConfiguration.OFF)) {
isVersioning = false;
} else {
Expand Down Expand Up @@ -726,8 +728,16 @@ public String setTargetPrefix(String path) {
}

@Override
public void setBucketVersioning(String bucket, String status) {

public void setBucketVersioning(String status) {
if (status == null) {
return;
}

if (status.equals(BucketVersioningConfiguration.SUSPENDED)) {
client.setBucketVersioningConfiguration(new SetBucketVersioningConfigurationRequest(config.getBucket(),
new BucketVersioningConfiguration(BucketVersioningConfiguration.SUSPENDED)));
logger.info("set target bucket({}) versioning is Suspended", config.getBucket());
}
}

@Override
Expand Down Expand Up @@ -828,4 +838,14 @@ public void deleteObject(String bucket, String key, String versionId) {
client.deleteObject(bucket, key);
}
}

@Override
public String getVersioningStatus() {
if (versioningStatus == null) {
versionConfig = client.getBucketVersioningConfiguration(config.getBucket());
versioningStatus = versionConfig.getStatus();
}

return versioningStatus;
}
}
3 changes: 2 additions & 1 deletion src/main/java/ifs_mover/repository/Repository.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public interface Repository {
void setConfig(Config config, boolean isSource);
int check(String type);
int init(String type);
boolean getVersioning();
boolean isVersioning();
String getVersioningStatus();

List<String> getBucketList();
boolean createBuckets(List<String> list);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ifs_mover/repository/S3.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

public interface S3 {
void setVersioning();
void setBucketVersioning(String bucket, String status);
void setBucketVersioning(String status);
String startMultipart(String bucket, String key);
String uploadPart(String bucket, String key, String uploadId, InputStream is, int partNumber, long partSize);
String completeMultipart(String bucket, String key, String uploadId, List<PartETag> list);
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/ifs_mover/repository/Swift.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public int init(String type) {
}

@Override
public boolean getVersioning() {
public boolean isVersioning() {
return false;
}

Expand Down Expand Up @@ -639,4 +639,10 @@ public ObjectData getObject(String bucket, String key, String versionId, long st

return data;
}

@Override
public String getVersioningStatus() {
// TODO Auto-generated method stub
return null;
}
}

0 comments on commit 8177419

Please sign in to comment.