This repository has been archived by the owner on Nov 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworking to push to print file data to a gcs bucket (#138)
* reworking to push to gcs bucket * [ci skip] auto patch increment skip-checks: true Co-authored-by: ras-rm-bot <[email protected]>
- Loading branch information
1 parent
9963d19
commit 35a7f69
Showing
10 changed files
with
110 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,4 +12,5 @@ | |
public class AppConfig { | ||
private Rabbitmq rabbitmq; | ||
private Logging logging; | ||
private GCS gcs; | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/uk/gov/ons/ctp/response/action/export/config/GCS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package uk.gov.ons.ctp.response.action.export.config; | ||
|
||
import lombok.Data; | ||
|
||
/** Config POJO for GCS params */ | ||
@Data | ||
public class GCS { | ||
private String bucket; | ||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/uk/gov/ons/ctp/response/action/export/message/UploadObjectGCS.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package uk.gov.ons.ctp.response.action.export.message; | ||
|
||
import com.google.cloud.storage.*; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class UploadObjectGCS { | ||
private static final Logger log = LoggerFactory.getLogger(UploadObjectGCS.class); | ||
private final Storage storage; | ||
|
||
public UploadObjectGCS(Storage storage) { | ||
this.storage = storage; | ||
} | ||
|
||
public boolean uploadObject(String filename, String bucket, byte[] data) { | ||
BlobId blobId = BlobId.of(bucket, filename); | ||
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("application/json").build(); | ||
Boolean isSuccess = false; | ||
log.info("file_name: ", filename + " bucket: " + bucket + ", Uploading to GCS bucket"); | ||
try { | ||
storage.create(blobInfo, data); | ||
isSuccess = true; | ||
log.info("file_name: " + filename + " bucket: " + bucket + ", Upload Successful!"); | ||
} catch (StorageException exception) { | ||
log.error( | ||
"file_name: " | ||
+ filename | ||
+ " bucket: " | ||
+ bucket | ||
+ ", Error uploading the generated file to GCS", | ||
exception); | ||
} | ||
return isSuccess; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters