Skip to content

Commit e05d83a

Browse files
author
Stepheny Perez
authored
Merge pull request podaac#155 from podaac/release/2.1.0
Release/2.1.0
2 parents b05774c + 4fec720 commit e05d83a

5 files changed

Lines changed: 398 additions & 22 deletions

File tree

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
9+
# [2.1.0]
10+
### Added
11+
- **PODAAC-4445 & PODAAC-4574**
12+
- Add in new field `dataProcessingType` in the `MessageAttributes` section for SNS topics; would only populate when field exists
13+
- **PODAAC-4606**
14+
- Add in new field `trace` in the `MessageAttributes` section for SNS topics; would only populate when field exists
15+
### Changed
16+
### Deprecated
17+
### Removed
18+
### Fixed
19+
### Security
20+
- **PODAAC-4353**
21+
- Fixed Snyk warning.
22+
- com.amazonaws:aws-java-sdk-core@1.12.144 to com.amazonaws:aws-java-sdk-core@1.12.209
23+
- com.amazonaws:amazon-kinesis-client@1.14.7 to com.amazonaws:amazon-kinesis-client@1.14.8
24+
- com.amazonaws:aws-java-sdk-sns@1.12.144 to com.amazonaws:aws-java-sdk-sns@1.12.209
25+
- com.amazonaws:aws-java-sdk-kinesis@1.12.144 to com.amazonaws:aws-java-sdk-kinesis@1.12.209
26+
- com.amazonaws:aws-lambda-java-core@1.1.0 to com.amazonaws:aws-lambda-java-core@1.2.1
27+
- com.google.code.gson:gson@2.8.9 to com.google.code.gson:gson@2.9.0
28+
829
# [v2.0.3] - 2022-01-21
930
### Added
1031
### Changed

pom.xml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>gov.nasa.cumulus</groupId>
66
<artifactId>cnm-response</artifactId>
7-
<version>2.0.3</version>
7+
<version>2.1.0-rc.1</version>
88
<packaging>jar</packaging>
99

1010
<name>cnm-response</name>
@@ -27,25 +27,25 @@
2727
<dependency>
2828
<groupId>com.amazonaws</groupId>
2929
<artifactId>aws-java-sdk-core</artifactId>
30-
<version>1.12.144</version>
30+
<version>1.12.209</version>
3131
</dependency>
3232
<!-- https://mvnrepository.com/artifact/com.amazonaws/amazon-kinesis-client -->
3333
<dependency>
3434
<groupId>com.amazonaws</groupId>
3535
<artifactId>amazon-kinesis-client</artifactId>
36-
<version>1.14.7</version>
36+
<version>1.14.8</version>
3737
</dependency>
3838
<!-- https://mvnrepository.com/artifact/com.amazonaws/aws-java-sdk-sns -->
3939
<dependency>
4040
<groupId>com.amazonaws</groupId>
4141
<artifactId>aws-java-sdk-sns</artifactId>
42-
<version>1.12.144</version>
42+
<version>1.12.209</version>
4343
</dependency>
4444
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
4545
<dependency>
4646
<groupId>com.google.code.gson</groupId>
4747
<artifactId>gson</artifactId>
48-
<version>2.8.9</version>
48+
<version>2.9.0</version>
4949
</dependency>
5050
<dependency>
5151
<groupId>gov.nasa.earthdata</groupId>
@@ -56,7 +56,7 @@
5656
<dependency>
5757
<groupId>com.amazonaws</groupId>
5858
<artifactId>aws-java-sdk-kinesis</artifactId>
59-
<version>1.12.144</version>
59+
<version>1.12.209</version>
6060
</dependency>
6161
<dependency>
6262
<groupId>commons-io</groupId>
@@ -66,7 +66,7 @@
6666
<dependency>
6767
<groupId>com.amazonaws</groupId>
6868
<artifactId>aws-lambda-java-core</artifactId>
69-
<version>1.1.0</version>
69+
<version>1.2.1</version>
7070
</dependency>
7171
<dependency>
7272
<groupId>junit</groupId>
@@ -81,4 +81,4 @@
8181
<scope>test</scope>
8282
</dependency>
8383
</dependencies>
84-
</project>
84+
</project>

src/main/java/gov/nasa/cumulus/CNMResponse.java

Lines changed: 85 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.apache.commons.lang3.StringUtils;
1313
import org.apache.http.client.utils.URIBuilder;
1414

15+
import javax.annotation.Nullable;
1516
import java.io.IOException;
1617
import java.io.InputStream;
1718
import java.io.OutputStream;
@@ -63,7 +64,7 @@ public static JsonObject getResponseObject(String exception) {
6364
response.addProperty("status", "FAILURE");
6465

6566
//logic for failure types here
66-
JsonObject workflowException = new JsonParser().parse(exception).getAsJsonObject();
67+
JsonObject workflowException = JsonParser.parseString(exception).getAsJsonObject();
6768

6869
String error = workflowException.get("Error").getAsString();
6970
AdapterLogger.LogWarning(CNMResponse.class.getName() + " error:" + error);
@@ -232,6 +233,50 @@ public String buildGeneralError(JsonObject input, String cause) {
232233
return new Gson().toJson(failureJson);
233234
}
234235

236+
/**
237+
* Gets the value for the 'dataProcessingType' field, to be used
238+
* by the 'buildMessageAttributesHash' method.
239+
* <br><br>
240+
* Tries to use the 'OriginalCNM > Product > dataProcessingType' from the
241+
* 'input > config' section, of the provided Json, but in case of an error,
242+
* return a generic error string.
243+
*<br><br>
244+
* @param input the input > config section, as a JsonObject
245+
* @return the string to use as the 'dataProcessingType' value; null if not available
246+
*/
247+
public String getDataProcessingType(JsonObject input) {
248+
String dataProcessingType = null;
249+
// Implement a recursive json search function (find "dataProcessingType" else)
250+
try {
251+
if(input.has("OriginalCNM") &&
252+
input.getAsJsonObject("OriginalCNM").has("product") &&
253+
input.getAsJsonObject("OriginalCNM").getAsJsonObject("product").has("dataProcessingType")) {
254+
dataProcessingType = input.getAsJsonObject("OriginalCNM").getAsJsonObject("product").get("dataProcessingType").getAsString();
255+
}
256+
return dataProcessingType;
257+
} catch (Exception e) {
258+
AdapterLogger.LogError(this.className + " handleRequest error:\n" + e.getMessage());
259+
AdapterLogger.LogInfo("input content:\n" + input);
260+
return null;
261+
}
262+
}
263+
264+
public String getTrace(JsonObject input) {
265+
String trace = null;
266+
// Implement a recursive json search function (find "trace" else)
267+
try {
268+
if(input.has("OriginalCNM") &&
269+
input.getAsJsonObject("OriginalCNM").has("trace")) {
270+
trace = input.getAsJsonObject("OriginalCNM").get("trace").getAsString();
271+
}
272+
return trace;
273+
} catch (Exception e) {
274+
AdapterLogger.LogError(this.className + " handleRequest error:\n" + e.getMessage());
275+
AdapterLogger.LogInfo("input content:\n" + input);
276+
return null;
277+
}
278+
}
279+
235280
/**
236281
* Gets the value for the 'DataVersion' field, to be used
237282
* by the 'buildMessageAttributesHash' method.
@@ -304,21 +349,23 @@ public String buildMessage(JsonObject inputKey, JsonObject inputConfig) throws E
304349
* using the 'response > status' field from the 'output'
305350
* along with the provided values for 'collection' and 'dataversion'
306351
* <br><br>
307-
* @param output the final output json message, as String
308-
* @param method the method to use, 'Kinesis' or 'Sns' when sending
309-
* @param region the region to send the message to
310-
* @param endpoint the actual endpoint for the message
311-
* @param collection the collection value for the attribute hash
312-
* @param dataVersion the dataVersion value for the attribute hash
352+
* @param output the final output json message, as String
353+
* @param method the method to use, 'Kinesis' or 'Sns' when sending
354+
* @param region the region to send the message to
355+
* @param endpoint the actual endpoint for the message
356+
* @param collection the collection value for the attribute hash
357+
* @param dataVersion the dataVersion value for the attribute hash
358+
* @oaram dataProcessingType the dataProcessingType value for the attribute hash (can be null)
313359
*/
314360
public void sendMessage(String output, String method, String region,
315361
JsonElement endpoint, String collection,
316-
String dataVersion) {
362+
String dataVersion, @Nullable String dataProcessingType, @Nullable String trace) {
317363
// convert the final output to a JsonObject, so we can get 'response status'
318364
JsonObject outputJsonObj = new JsonParser().parse(output).getAsJsonObject();
319365
String final_status = outputJsonObj.getAsJsonObject("response").get("status").getAsString();
320366
if (method != null) {
321-
Map<String, MessageAttribute> attributeBOMap = buildMessageAttributesHash(collection, dataVersion, final_status);
367+
Map<String, MessageAttribute> attributeBOMap =
368+
buildMessageAttributesHash(collection, dataVersion, final_status, dataProcessingType, trace);
322369
Sender sender = SenderFactory.getSender(region, method);
323370
sender.addMessageAttributes(attributeBOMap);
324371
if (endpoint.isJsonArray()) {
@@ -346,10 +393,12 @@ public String PerformFunction(String input, Context context) throws Exception {
346393
// get collection and dataVersion for use in message attribute hash
347394
String collection = getCollection(inputKey);
348395
String dataVersion = getDataVersion(inputConfig);
396+
String dataProcessingType = getDataProcessingType(inputConfig);
397+
String trace = getTrace(inputConfig);
349398
String output;
350399
try {
351400
output = buildMessage(inputKey, inputConfig);
352-
sendMessage(output, method, region, responseEndpoint, collection, dataVersion);
401+
sendMessage(output, method, region, responseEndpoint, collection, dataVersion, dataProcessingType, trace);
353402
/* create new object:
354403
*
355404
* {cnm: output, input:input}
@@ -361,27 +410,51 @@ public String PerformFunction(String input, Context context) throws Exception {
361410
return new Gson().toJson(bigOutput);
362411
} catch (Exception ex) {
363412
AdapterLogger.LogError(this.className + " encountered exception with input String: " + input);
413+
AdapterLogger.LogError(this.className + " handleRequest error:" + ex.getMessage());
364414
output = buildGeneralError(inputKey, ex.getMessage());
365-
sendMessage(output, method, region, responseEndpoint, collection, dataVersion);
415+
sendMessage(output, method, region, responseEndpoint, collection, dataVersion, dataProcessingType, trace);
366416
// re-throw the exception now.
367417
throw ex;
368418
}
369419
}
370420

371-
Map<String, MessageAttribute> buildMessageAttributesHash(String collection_name, String dataVersion, String status) {
421+
Map<String, MessageAttribute> buildMessageAttributesHash(
422+
String collection_name,
423+
String dataVersion,
424+
String status,
425+
@Nullable String dataProcessingType,
426+
@Nullable String trace) {
372427
Map<String, MessageAttribute> attributeBOMap = new HashMap<>();
428+
373429
MessageAttribute collectionNameBO = new MessageAttribute();
374430
collectionNameBO.setType(MessageFilterTypeEnum.String);
375431
collectionNameBO.setValue(collection_name);
376432
attributeBOMap.put(this.COLLECTION_SHORT_NAME_ATTRIBUTE_KEY, collectionNameBO);
433+
377434
MessageAttribute statusBO = new MessageAttribute();
378435
statusBO.setType(MessageFilterTypeEnum.String);
379436
statusBO.setValue(status);
380437
attributeBOMap.put(this.CNM_RESPONSE_STATUS_ATTRIBUTE_KEY, statusBO);
438+
381439
MessageAttribute dataVersionBO = new MessageAttribute();
382440
dataVersionBO.setType(MessageFilterTypeEnum.String);
383441
dataVersionBO.setValue(dataVersion);
384442
attributeBOMap.put(this.DATA_VERSION_ATTRIBUTE_KEY, dataVersionBO);
443+
444+
if(null != dataProcessingType && !dataProcessingType.isEmpty()){
445+
MessageAttribute dataProcessingTypeBO = new MessageAttribute();
446+
dataProcessingTypeBO.setType(MessageFilterTypeEnum.String);
447+
dataProcessingTypeBO.setValue(dataProcessingType);
448+
attributeBOMap.put(this.DATA_PROCESSING_TYPE, dataProcessingTypeBO);
449+
}
450+
451+
if(null != trace && !trace.isEmpty()){
452+
MessageAttribute traceBO = new MessageAttribute();
453+
traceBO.setType(MessageFilterTypeEnum.String);
454+
traceBO.setValue(trace);
455+
attributeBOMap.put(this.TRACE, traceBO);
456+
}
457+
385458
return attributeBOMap;
386459
}
387460
}

src/main/java/gov/nasa/cumulus/IConstants.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ public interface IConstants {
77
String COLLECTION_SHORT_NAME_ATTRIBUTE_KEY = "COLLECTION";
88
String CNM_RESPONSE_STATUS_ATTRIBUTE_KEY = "CNM_RESPONSE_STATUS";
99
String DATA_VERSION_ATTRIBUTE_KEY = "DATA_VERSION";
10+
String DATA_PROCESSING_TYPE = "dataProcessingType";
11+
String TRACE = "trace";
1012
enum MessageFilterTypeEnum {
1113
String,
1214
Number

0 commit comments

Comments
 (0)