@@ -34,37 +34,27 @@ public class CcStoreS3 implements CcStore {
3434 String bucket ;
3535 String root ;
3636 String manifestId ;
37+ String payloadId ;
3738 StoreType storeType ;
3839 AmazonS3 awsS3 ;
3940 AWSConfig config ;
40- @ Override
41- public String RootPath () {
42- return bucket ;
43- }
41+
4442 public CcStoreS3 (){
4543 AWSConfig acfg = new AWSConfig ();
4644 acfg .aws_access_key_id = System .getenv (EnvironmentVariables .CC_PROFILE + "_" + EnvironmentVariables .AWS_ACCESS_KEY_ID );
4745 acfg .aws_secret_access_key_id = System .getenv (EnvironmentVariables .CC_PROFILE + "_" + EnvironmentVariables .AWS_SECRET_ACCESS_KEY );
4846 acfg .aws_region = System .getenv (EnvironmentVariables .CC_PROFILE + "_" + EnvironmentVariables .AWS_DEFAULT_REGION );
4947 acfg .aws_bucket = System .getenv (EnvironmentVariables .CC_PROFILE + "_" + EnvironmentVariables .AWS_S3_BUCKET );
50- acfg .aws_mock = Boolean .parseBoolean (System .getenv (EnvironmentVariables .CC_PROFILE + "_" +"S3_MOCK" ));//convert to boolean;//stringformat
51- acfg .aws_endpoint = System .getenv (EnvironmentVariables .CC_PROFILE + "_" +"S3_ENDPOINT" );
52- acfg .aws_disable_ssl = Boolean .parseBoolean (System .getenv (EnvironmentVariables .CC_PROFILE + "_" +"S3_DISABLE_SSL" ));//convert to bool?
53- acfg .aws_force_path_style = Boolean .parseBoolean (System .getenv (EnvironmentVariables .CC_PROFILE + "_" +"S3_FORCE_PATH_STYLE" ));//convert to bool
48+ acfg .aws_endpoint = System .getenv (EnvironmentVariables .CC_PROFILE + "_" +"AWS_ENDPOINT" );
5449 config = acfg ;
55- //System.out.println(EnvironmentVariables.CC_PROFILE + "_" + EnvironmentVariables.AWS_DEFAULT_REGION+"::"+config.aws_region);
56- //System.out.println(EnvironmentVariables.CC_PROFILE + "_" + EnvironmentVariables.AWS_ACCESS_KEY_ID+"::"+config.aws_access_key_id);
57- //System.out.println(EnvironmentVariables.CC_PROFILE + "_" + EnvironmentVariables.AWS_SECRET_ACCESS_KEY+"::"+config.aws_secret_access_key_id);
58- //System.out.println(EnvironmentVariables.CC_PROFILE + "_" + EnvironmentVariables.AWS_S3_BUCKET+"::"+config.aws_bucket);
50+
5951 Region clientRegion = RegionUtils .getRegion (config .aws_region );//.toUpperCase().replace("-", "_"));//Regions.valueOf(config.aws_region.toUpperCase().replace("-", "_"));
6052 try {
6153 AmazonS3 s3Client = null ;
62- if (config .aws_mock ){
63- System .out .println ("mocking s3 with minio" );
64- //System.out.println(EnvironmentVariables.CC_PROFILE + "_S3_MOCK::"+config.aws_mock);
65- //System.out.println(EnvironmentVariables.CC_PROFILE + "_S3_ENDPOINT::"+config.aws_endpoint);
66- //System.out.println(EnvironmentVariables.CC_PROFILE + "_S3_DISABLE_SSL::"+config.aws_disable_ssl);
67- //System.out.println(EnvironmentVariables.CC_PROFILE + "_S3_FORCE_PATH_STYLE::"+config.aws_force_path_style);
54+ if (!config .aws_endpoint .equals ("" )){
55+ System .out .println (String .format ("Using alt endpoint: %s" ,config .aws_endpoint ));
56+ config .aws_force_path_style =true ;
57+ config .aws_disable_ssl =true ;
6858 AWSCredentials credentials = new BasicAWSCredentials (config .aws_access_key_id , config .aws_secret_access_key_id );
6959 ClientConfiguration clientConfiguration = new ClientConfiguration ();
7060 clientConfiguration .setSignerOverride ("AWSS3V4SignerType" );
@@ -97,20 +87,28 @@ public CcStoreS3(){
9787 }
9888 storeType = StoreType .S3 ;
9989 manifestId = System .getenv (EnvironmentVariables .CC_MANIFEST_ID );
100- localRootPath = Constants .LocalRootPath ;
90+ payloadId = System .getenv (EnvironmentVariables .CC_PAYLOAD_ID );
91+ localRootPath = Constants .LOCAL_ROOT_PATH ;
10192 bucket = config .aws_bucket ;// + Constants.RemoteRootPath;
10293 root = System .getenv (EnvironmentVariables .CC_ROOT );
10394 }
95+
10496 @ Override
105- public boolean HandlesDataStoreType (StoreType storeType ){
97+ public String rootPath () {
98+ return bucket ;
99+ }
100+
101+ @ Override
102+ public boolean handlesDataStoreType (StoreType storeType ){
106103 return this .storeType == storeType ;
107104 }
105+
108106 @ Override
109- public boolean PutObject (PutObjectInput input ) {
107+ public boolean putObject (PutObjectInput input ) {
110108 String path = root + "/" + manifestId + "/" + input .getFileName () + "." + input .getFileExtension ();
111109 byte [] data ;
112110 switch (input .getObjectState ()){
113- case LocalDisk :
111+ case LOCAL_DISK :
114112 //read from local
115113 File file = new File (path );
116114 data = new byte [(int ) file .length ()];
@@ -120,26 +118,27 @@ public boolean PutObject(PutObjectInput input) {
120118 catch (Exception e ){
121119 //@TODOprint?
122120 }
123- UploadToS3 (config .aws_bucket , path , data );
121+ uploadToS3 (config .aws_bucket , path , data );
124122 break ;
125- case Memory :
123+ case MEMORY :
126124 data = input .getData ();
127- UploadToS3 (config .aws_bucket , path , data );
125+ uploadToS3 (config .aws_bucket , path , data );
128126 break ;
129127 default :
130128 return false ;
131129 }
132130
133131 return true ;
134132 }
133+
135134 @ Override
136- public boolean PullObject (PullObjectInput input ) {
135+ public boolean pullObject (PullObjectInput input ) {
137136 String path = root + "/" + manifestId + "/" + input .getFileName () + "." + input .getFileExtension ();
138137 byte [] data ;
139138 String localPath = input .getDestRootPath () + "/" + input .getFileName () + "." + input .getFileExtension ();
140139 try {
141140 //get the object from s3
142- data = DownloadBytesFromS3 (path );
141+ data = downloadBytesFromS3 (path );
143142 //create localpath writer
144143 InputStream stream = new ByteArrayInputStream (data );
145144 //write it.
@@ -149,38 +148,45 @@ public boolean PullObject(PullObjectInput input) {
149148 }
150149 return false ;
151150 }
151+
152152 private void writeInputStreamToDisk (InputStream input , String outputDestination ) throws IOException {
153153 String directory = new File (outputDestination ).getParent ();
154154 File f = new File (directory );
155155 if (!f .exists ()){
156156 f .mkdirs ();
157157 }
158158 byte [] bytes = input .readAllBytes ();
159- OutputStream os = new FileOutputStream (new File (outputDestination ));
160- os .write (bytes );
159+ try (OutputStream os = new FileOutputStream (new File (outputDestination ))) {
160+ os .write (bytes );
161+ } catch (Exception e ) {
162+ e .printStackTrace ();
163+ };
161164 }
165+
162166 @ Override
163- public byte [] GetObject (GetObjectInput input ) throws AmazonS3Exception {
164- String path = root + "/" + manifestId + "/" + input .getFileName () + "." + input .getFileExtension ();
167+ public byte [] getObject (GetObjectInput input ) throws AmazonS3Exception {
168+ String path = root + "/" + payloadId + "/" + input .getFileName () + "." + input .getFileExtension ();
165169 byte [] data ;
166170 try {
167- data = DownloadBytesFromS3 (path );
171+ data = downloadBytesFromS3 (path );
168172 } catch (Exception e ) {
169173 throw new AmazonS3Exception (e .toString ());
170174 }
171175 return data ;
172176 }
177+
173178 @ Override
174- public Payload GetPayload () throws AmazonS3Exception {
175- String filepath = root + "/" + manifestId + "/" + Constants .PayloadFileName ;
179+ public Payload getPayload () throws AmazonS3Exception {
180+ String filepath = root + "/" + payloadId + "/" + Constants .PAYLOAD_FILE_NAME ;
176181 try {
177- byte [] body = DownloadBytesFromS3 (filepath );
178- return ReadJsonModelPayloadFromBytes (body );
182+ byte [] body = downloadBytesFromS3 (filepath );
183+ return readJsonModelPayloadFromBytes (body );
179184 } catch (Exception e ){
180185 throw new AmazonS3Exception (e .toString ());
181186 }
182187 }
183- private byte [] DownloadBytesFromS3 (String key ) throws Exception {
188+
189+ private byte [] downloadBytesFromS3 (String key ) throws Exception {
184190 S3Object fullObject = null ;
185191 boolean spaces = key .contains (" " );
186192 if (spaces ){
@@ -205,15 +211,17 @@ private byte[] DownloadBytesFromS3(String key) throws Exception{
205211 }
206212 }
207213 }
208- private Payload ReadJsonModelPayloadFromBytes (byte [] bytes ) throws Exception {
214+
215+ private Payload readJsonModelPayloadFromBytes (byte [] bytes ) throws Exception {
209216 final ObjectMapper mapper = new ObjectMapper (); // jackson databind
210217 try {
211218 return mapper .readValue (bytes , Payload .class );
212219 } catch (Exception e ) {
213220 throw e ;
214221 }
215222 }
216- private void UploadToS3 (String bucketName , String objectKey , byte [] fileBytes ) {
223+
224+ private void uploadToS3 (String bucketName , String objectKey , byte [] fileBytes ) {
217225 try {
218226 //File file = new File(objectPath);
219227 InputStream stream = new ByteArrayInputStream (fileBytes );
0 commit comments