Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NOD-410] Fix #2

Merged
merged 9 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .devops/deploy-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ variables:

${{ if eq(parameters['ENV'], 'dev') }}:
AZURE_SUBSCRIPTION: $(DEV_AZURE_SUBSCRIPTION)
APP_NAME: $(DEV_WEB_APP_NAME)
APP_NAME: "pagopa-d-weu"
STAGE: "d"
RESOURCE_GROUP: 'pagopa-d-weu-nodo-re-to-tablestorage-rg'
RESOURCE_GROUP: 'pagopa-d-weu-nodo-re-to-datastore-rg'
dockerRegistryServiceConnection: $(DEV_CONTAINER_REGISTRY_SERVICE_CONN)
dockerNamespace: $(DEV_CONTAINER_NAMESPACE)
${{ if eq(parameters['ENV'], 'uat') }}:
AZURE_SUBSCRIPTION: $(UAT_AZURE_SUBSCRIPTION)
APP_NAME: $(UAT_WEB_APP_NAME)
APP_NAME: "pagopa-u-weu"
STAGE: "u"
RESOURCE_GROUP: 'pagopa-u-weu-nodo-re-to-tablestorage-rg'
RESOURCE_GROUP: 'pagopa-u-weu-nodo-re-to-datastore-rg'
dockerRegistryServiceConnection: $(UAT_CONTAINER_REGISTRY_SERVICE_CONN)
dockerNamespace: $(UAT_CONTAINER_NAMESPACE)
${{ if eq(parameters['ENV'], 'prod') }}:
AZURE_SUBSCRIPTION: $(PROD_AZURE_SUBSCRIPTION)
APP_NAME: $(PROD_WEB_APP_NAME)
APP_NAME: "pagopa-p-weu"
STAGE: "p"
RESOURCE_GROUP: 'pagopa-p-weu-nodo-re-to-tablestorage-rg'
RESOURCE_GROUP: 'pagopa-p-weu-nodo-re-to-datastore-rg'
dockerRegistryServiceConnection: $(PROD_CONTAINER_REGISTRY_SERVICE_CONN)
dockerNamespace: $(PROD_CONTAINER_NAMESPACE)

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>it.gov.pagopa</groupId>
<artifactId>nodoretotablestorage</artifactId>
<version>0.1.1-14</version>
<version>0.1.1-15</version>
<packaging>jar</packaging>

<name>Nodo RE to Table Storage Fn</name>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.nodoretodatastore;
package it.gov.pagopa.nodoretotablestorage;

import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.microsoft.azure.functions.annotation.Cardinality;
import com.microsoft.azure.functions.annotation.EventHubTrigger;
import com.microsoft.azure.functions.annotation.FunctionName;
import it.gov.pagopa.nodoretodatastore.util.ObjectMapperUtils;
import it.gov.pagopa.nodoretotablestorage.util.ObjectMapperUtils;

import java.io.ByteArrayOutputStream;
import java.nio.charset.StandardCharsets;
Expand All @@ -35,7 +35,7 @@ public class NodoReEventToDataStore {
*/

private Pattern replaceDashPattern = Pattern.compile("-([a-zA-Z])");
private static String NA = "NA";
private static String na = "NA";
private static String uniqueIdField = "uniqueId";
private static String insertedDateField = "insertedDate";
private static String insertedTimestampField = "insertedTimestamp";
Expand All @@ -56,22 +56,19 @@ private static TableServiceClient getTableServiceClient(){
return tableServiceClient;
}

private void addToBatch(Logger logger, Map<String,List<TableTransactionAction>> partitionEvents, Map<String, Object> reEvent) {
if(reEvent.get(uniqueIdField) == null) {
logger.warning("event has no '" + uniqueIdField + "' field");
}
else {
private void addToBatch(Map<String,List<TableTransactionAction>> partitionEvents, Map<String, Object> reEvent) {
if(reEvent.get(uniqueIdField) != null) {
TableEntity entity = new TableEntity((String) reEvent.get(partitionKeyField), (String)reEvent.get(uniqueIdField));
entity.setProperties(reEvent);
if(!partitionEvents.containsKey(entity.getPartitionKey())){
partitionEvents.put(entity.getPartitionKey(),new ArrayList<TableTransactionAction>());
partitionEvents.put(entity.getPartitionKey(),new ArrayList<>());
}
partitionEvents.get(entity.getPartitionKey()).add(new TableTransactionAction(TableTransactionActionType.UPSERT_REPLACE,entity));
}
}

private String replaceDashWithUppercase(String input) {
if(!input.contains("-")){
if(!input.contains("-")) {
return input;
}
Matcher matcher = replaceDashPattern.matcher(input);
Expand Down Expand Up @@ -121,9 +118,8 @@ public void processNodoReEvent (

TableClient tableClient = getTableServiceClient().getTableClient(tableName);

logger.info(String.format("Persisting %d events", reEvents.size()));
try {
if (reEvents.size() == properties.length) {
try {
if (reEvents.size() == properties.length) {
Map<String,List<TableTransactionAction>> partitionEvents = new HashMap<>();

for(int index=0; index< properties.length; index++) {
Expand All @@ -133,33 +129,31 @@ public void processNodoReEvent (
reEvent.put(s, v);
});

String insertedDateValue = reEvent.get(insertedTimestampField) != null ? ((String)reEvent.get(insertedTimestampField)).substring(0, 10) : NA;
String insertedDateValue = reEvent.get(insertedTimestampField) != null ? ((String)reEvent.get(insertedTimestampField)).substring(0, 10) : na;
reEvent.put(insertedDateField, insertedDateValue);

zipPayload(logger, reEvent);

String idDominio = reEvent.get(idDominioField) != null ? reEvent.get(idDominioField).toString() : NA;
String idDominio = reEvent.get(idDominioField) != null ? reEvent.get(idDominioField).toString() : na;

addToBatch(logger, partitionEvents, getEvent(insertedDateValue, reEvent));
addToBatch(logger, partitionEvents, getEvent(insertedDateValue + "-" + idDominio, reEvent));
addToBatch(partitionEvents, getEvent(insertedDateValue, reEvent));
addToBatch(partitionEvents, getEvent(insertedDateValue + "-" + idDominio, reEvent));
}

// save batch by partition keys
partitionEvents.forEach((pe, values)->{
partitionEvents.forEach((pe, values) -> {
try {
tableClient.submitTransaction(values);
} catch (Throwable t){
} catch (Exception t) {
logger.severe("Could not save on tableStorage,partition "+pe+", "+values.size()+" rows,error:"+ t.toString());
}
});

logger.info("Done processing events");
} else {
logger.severe("Error processing events, lengths do not match ["+reEvents.size()+","+properties.length+"]");
}
} catch (NullPointerException e) {
logger.severe("NullPointerException exception on cosmos nodo-re-events msg ingestion at "+ LocalDateTime.now()+ " : " + e.getMessage());
} catch (Throwable e) {
} catch (Exception e) {
logger.severe("Generic exception on table storage nodo-re-events msg ingestion at "+ LocalDateTime.now()+ " : " + e.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.nodoretodatastore.exception;
package it.gov.pagopa.nodoretotablestorage.exception;

public class AppException extends Exception {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.nodoretodatastore.util;
package it.gov.pagopa.nodoretotablestorage.util;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down