Skip to content

Commit

Permalink
breakdown the lambda PerformFunction
Browse files Browse the repository at this point in the history
  • Loading branch information
Yen, David (398B-Affiliate) committed May 16, 2024
1 parent bfa7cef commit 5e5345b
Showing 1 changed file with 30 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,35 @@ public String PerformFunction(String input, Context context) throws Exception {
throw e;
}


String returableJsonStr = createNewOutput(s3Utils, granules, cmrFilePath, granuleId, internalBucket, stagingDirectory);
/**
* remove the .mp file from s3
*/
if (StringUtils.isNotEmpty(mpFileBucket) && StringUtils.isNotEmpty(mpFileKey)) {
AdapterLogger.LogInfo(this.className + " cleaning up .mp file");
s3Utils.delete(region, mpFileBucket, mpFileKey);
}
return returableJsonStr;
}

/**
*
* Upload cmr.json to s3 bucket
* Add UMM-G file to payload/file objects
*
* @param s3Utils
* @param granules
* @param cmrFilePath
* @param granuleId
* @param internalBucket
* @param stagingDirectory
* @return A string represents the output payload
* @throws IOException
*/
public String createNewOutput(S3Utils s3Utils, JSONArray granules, String cmrFilePath, String granuleId, String internalBucket,
String stagingDirectory)
throws IOException{
/*
* Upload cmr.json to s3 bucket
* Add UMM-G file to payload/file objects
Expand All @@ -213,34 +242,23 @@ public String PerformFunction(String input, Context context) throws Exception {
s3Utils.upload(region, internalBucket,
Paths.get(stagingDirectory, "/" + granuleId + ".cmr.json").toString(),
cmrFile);
JSONArray files = (JSONArray) ((JSONObject) granules.get(0)).get("files");

JSONObject ummFile = new JSONObject();
ummFile.put("bucket", internalBucket);
ummFile.put("fileName", granuleId + ".cmr.json");
ummFile.put("type", "metadata");
ummFile.put("size", cmrFile.length());
ummFile.put("key", Paths.get(stagingDirectory, granuleId + ".cmr.json").toString());

files.add(ummFile);

AdapterLogger.LogInfo("Cleaning tmp for granule: " + granuleId);
FileUtils.cleanDirectory(new File("/tmp"));
//jo = input,config...
//need to output {granules:[]}

/**
* combining output objects
*/
JSONObject returnable = new JSONObject();
returnable.put("granules", granules);
AdapterLogger.LogInfo(this.className + " Finished processing with granuleId:" + granuleId);
/**
* remove the .mp file
*/
if (StringUtils.isNotEmpty(mpFileBucket) && StringUtils.isNotEmpty(mpFileKey)) {
AdapterLogger.LogInfo(this.className + " cleaning up .mp file");
s3Utils.delete(region, mpFileBucket, mpFileKey);
}
return returnable.toJSONString();
}
/**
Expand Down

0 comments on commit 5e5345b

Please sign in to comment.