Skip to content

Commit b661719

Browse files
Sabrina Juarez GarciaBeta Bot
authored andcommitted
Cherry pick branch 'genexuslabs:AzureFunctions' into beta
1 parent d611ae7 commit b661719

25 files changed

+25
-111
lines changed

gxazureserverless/pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@
1414
<name>GeneXus Azure Functions Handler</name>
1515

1616
<dependencies>
17-
<dependency>
18-
<groupId>${project.groupId}</groupId>
19-
<artifactId>gxclassR</artifactId>
20-
<version>${project.version}</version>
21-
</dependency>
22-
23-
<dependency>
24-
<groupId>${project.groupId}</groupId>
25-
<artifactId>gxcommon</artifactId>
26-
<version>${project.version}</version>
27-
</dependency>
2817

2918
<dependency>
3019
<groupId>${project.groupId}</groupId>

gxazureserverless/src/main/java/com/genexus/cloud/serverless/azure/handler/AzureBlobStorageHandler.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
package com.genexus.cloud.serverless.azure.handler;
2-
import com.genexus.cloud.serverless.Helper;
32
import com.genexus.cloud.serverless.model.*;
43

54
import com.microsoft.azure.functions.annotation.*;
@@ -18,7 +17,7 @@ public AzureBlobStorageHandler() throws Exception {
1817
super();
1918
}
2019
public void run(
21-
@BlobTrigger(name = "content", path = "%blob_path%", dataType = "binary") byte[] content,
20+
@BlobTrigger(name = "content", source = "EventGrid", path = "%blob_path%", dataType = "binary") byte[] content,
2221
@BindingName("name") String name,
2322
final ExecutionContext context
2423
) throws Exception {
@@ -28,17 +27,13 @@ public void run(
2827

2928
switch (executor.getMethodSignatureIdx()) {
3029
case 0:
31-
3230
EventMessage msg = new EventMessage();
3331
msg.setMessageId(context.getInvocationId());
3432
msg.setMessageSourceType(EventMessageSourceType.BLOB);
35-
3633
Instant nowUtc = Instant.now();
3734
msg.setMessageDate(Date.from(nowUtc));
3835
msg.setMessageData(Base64.getEncoder().encodeToString(content));
39-
4036
List<EventMessageProperty> msgAtts = msg.getMessageProperties();
41-
4237
msgAtts.add(new EventMessageProperty("Id", context.getInvocationId()));
4338
msgAtts.add(new EventMessageProperty("name", name));
4439

@@ -48,7 +43,6 @@ public void run(
4843
case 2:
4944
rawMessage = Base64.getEncoder().encodeToString(content);
5045
}
51-
5246
try {
5347
EventMessageResponse response = dispatchEvent(msgs, rawMessage);
5448
if (response.hasFailed()) {

gxazureserverless/src/main/java/com/genexus/cloud/serverless/azure/handler/AzureCosmosDBHandler.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public void run(
2525
EventMessages msgs = new EventMessages();
2626
EventMessagesList eventMessagesList = new EventMessagesList();
2727
String rawMessage= "";
28-
2928
setupServerlessMappings(context.getFunctionName());
3029

3130
switch (executor.getMethodSignatureIdx()) {
@@ -39,20 +38,18 @@ public void run(
3938
rawMessage = Helper.toJSONString(items);
4039
break;
4140
}
42-
4341
try {
4442
EventMessageResponse response = dispatchEvent(msgs, eventMessagesList, rawMessage);
4543
if (response.hasFailed()) {
4644
logger.error(String.format("Messages were not handled. Error: %s", response.getErrorMessage()));
4745
throw new RuntimeException(response.getErrorMessage()); //Throw the exception so the runtime can Retry the operation.
4846
}
49-
5047
} catch (Exception e) {
5148
logger.error("HandleRequest execution error", e);
5249
throw e; //Throw the exception so the runtime can Retry the operation.
5350
}
54-
5551
}
52+
5653
private EventMessagesList setupEventMessagesList(List<Map<String,Object>> jsonList)
5754
{
5855
EventMessagesList messagesList = new EventMessagesList();
@@ -61,10 +58,10 @@ private EventMessagesList setupEventMessagesList(List<Map<String,Object>> jsonLi
6158
}
6259
return messagesList;
6360
}
61+
6462
private EventMessages setupEventMessages(Guid.GUID eventId, List<Map<String,Object>> jsonList)
6563
{
6664
EventMessages msgs = new EventMessages();
67-
6865
for (Map<String, Object> json : jsonList) {
6966

7067
String idValue = "";
@@ -73,7 +70,6 @@ private EventMessages setupEventMessages(Guid.GUID eventId, List<Map<String,Obje
7370
msg.setMessageSourceType(EventMessageSourceType.COSMOSDB);
7471

7572
List<EventMessageProperty> msgAtts = msg.getMessageProperties();
76-
7773
for (Map.Entry<String, Object> entry : json.entrySet()) {
7874
String key = entry.getKey();
7975
String value = entry.getValue().toString();

gxazureserverless/src/main/java/com/genexus/cloud/serverless/azure/handler/AzureEventGridCloudHandler.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public class AzureEventGridCloudHandler extends AzureEventHandler{
2323
public void run(
2424
@EventGridTrigger(name = "eventgridEvent") String eventJson,
2525
final ExecutionContext context) throws Exception {
26-
2726
context.getLogger().info("GeneXus Event Grid CloudEvents trigger handler. Function processed: " + context.getFunctionName() + " Invocation Id: " + context.getInvocationId());
2827
setupServerlessMappings(context.getFunctionName());
2928
setupEventGridMessage(eventJson);
@@ -34,32 +33,28 @@ public void run(
3433
logger.error(String.format("Messages were not handled. Error: %s", response.getErrorMessage()));
3534
throw new RuntimeException(response.getErrorMessage()); //Throw the exception so the runtime can Retry the operation.
3635
}
37-
3836
} catch (Exception e) {
3937
logger.error("HandleRequest execution error", e);
4038
throw e; //Throw the exception so the runtime can Retry the operation.
4139
}
4240
}
4341
protected void setupEventGridMessage(String eventJson) throws JsonProcessingException {
44-
4542
switch (executor.getMethodSignatureIdx()) {
4643
case 0:
47-
4844
try {
4945
ObjectMapper objectMapper = new ObjectMapper();
5046
objectMapper.registerModule(io.cloudevents.jackson.JsonFormat.getCloudEventJacksonModule());
5147
CloudEvent cloudEvent = objectMapper.readValue(eventJson, CloudEvent.class);
5248

5349
EventMessage msg = new EventMessage();
50+
5451
msg.setMessageId(cloudEvent.getId());
5552
msg.setMessageSourceType(cloudEvent.getType());
5653
msg.setMessageVersion("");
57-
5854
msg.setMessageDate(new Date());
5955
msg.setMessageData(Objects.requireNonNull(cloudEvent.getData()).toString());
6056

6157
List<EventMessageProperty> msgAtts = msg.getMessageProperties();
62-
6358
msgAtts.add(new EventMessageProperty("Id", cloudEvent.getId()));
6459
msgAtts.add(new EventMessageProperty("Subject", cloudEvent.getSubject()));
6560
msgAtts.add(new EventMessageProperty("DataContentType", cloudEvent.getDataContentType()));
@@ -70,7 +65,7 @@ protected void setupEventGridMessage(String eventJson) throws JsonProcessingExce
7065
if (cloudEvent.getSpecVersion() != null)
7166
msgAtts.add(new EventMessageProperty("SpecVersion", cloudEvent.getSpecVersion().toString()));
7267
if (cloudEvent.getTime() != null)
73-
msgAtts.add(new EventMessageProperty("Time", cloudEvent.getTime().toString()));
68+
msgAtts.add(new EventMessageProperty("Time", cloudEvent.getTime().toString()));
7469

7570
msgs.add(msg);
7671
}
@@ -83,5 +78,4 @@ protected void setupEventGridMessage(String eventJson) throws JsonProcessingExce
8378
rawMessage = eventJson;
8479
}
8580
}
86-
8781
}

gxazureserverless/src/main/java/com/genexus/cloud/serverless/azure/handler/AzureEventGridHandler.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,23 @@ public void run(
3131
logger.error(String.format("Messages were not handled. Error: %s", response.getErrorMessage()));
3232
throw new RuntimeException(response.getErrorMessage()); //Throw the exception so the runtime can Retry the operation.
3333
}
34-
3534
} catch (Exception e) {
3635
logger.error("HandleRequest execution error", e);
3736
throw e; //Throw the exception so the runtime can Retry the operation.
3837
}
39-
40-
4138
}
42-
protected void setupEventGridMessage(EventGridEvent event) {
4339

40+
protected void setupEventGridMessage(EventGridEvent event) {
4441
switch (executor.getMethodSignatureIdx()) {
4542
case 0:
4643
EventMessage msg = new EventMessage();
4744
msg.setMessageId(event.getId());
4845
msg.setMessageSourceType(event.getEventType());
4946
msg.setMessageVersion(event.getDataVersion());
50-
5147
msg.setMessageDate(new Date());
5248
msg.setMessageData(event.getData().toString());
5349

5450
List<EventMessageProperty> msgAtts = msg.getMessageProperties();
55-
5651
msgAtts.add(new EventMessageProperty("Id", event.getId()));
5752

5853
msgAtts.add(new EventMessageProperty("Subject",event.getSubject()));
@@ -61,7 +56,6 @@ protected void setupEventGridMessage(EventGridEvent event) {
6156
msgAtts.add(new EventMessageProperty("EventTime",event.getEventTime().toString()));
6257

6358
msgs.add(msg);
64-
6559
break;
6660
case 1:
6761
case 2:

gxazureserverless/src/main/java/com/genexus/cloud/serverless/azure/handler/AzureEventHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,5 @@ protected AzureFunctionConfiguration createFunctionConfiguration() {
5353
@Override
5454
protected void InitializeServerlessConfig(){
5555
}
56-
5756
}
5857

gxazureserverless/src/main/java/com/genexus/cloud/serverless/azure/handler/AzureFunctionConfiguration.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,22 @@ public class AzureFunctionConfiguration extends ServerlessFunctionConfiguration
1212

1313
public AzureFunctionConfiguration() {
1414
}
15-
public AzureFunctionConfiguration(String functionName, String gxEntrypoint)
16-
{
15+
public AzureFunctionConfiguration(String functionName, String gxEntrypoint) {
1716
this.functionName = functionName;
1817
this.gxEntrypoint = gxEntrypoint;
1918
}
2019
public void setFunctionName(String functionName) {
21-
2220
this.functionName = functionName;
2321
}
2422
public void setGXEntrypoint(String gxEntrypoint) {
25-
2623
this.gxEntrypoint = gxEntrypoint;
2724
}
2825

2926
public String getFunctionName() {
3027
return functionName;
3128
}
32-
public String getGXEntrypoint() {
3329

30+
public String getGXEntrypoint() {
3431
return gxEntrypoint;
3532
}
3633
@Override
@@ -42,5 +39,4 @@ public boolean isValidConfiguration () {
4239
public String getGXClassName() {
4340
return getGXEntrypoint();
4441
}
45-
4642
}

gxazureserverless/src/main/java/com/genexus/cloud/serverless/azure/handler/AzureFunctionConfigurationHelper.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
public class AzureFunctionConfigurationHelper {
1818
private final static ILogger logger = LogManager.initialize(".", AzureFunctionConfiguration.class);
1919
private final static String FUNCTION_CONFIG_PATH = "gxazmappings.json";
20-
public static List<AzureFunctionConfiguration> getFunctionsMapConfiguration() throws FunctionConfigurationException {
2120

21+
public static List<AzureFunctionConfiguration> getFunctionsMapConfiguration() throws FunctionConfigurationException {
2222
File configFile = new File(FUNCTION_CONFIG_PATH);
2323

2424
if (configFile.exists()) {
@@ -36,21 +36,19 @@ public static List<AzureFunctionConfiguration> getFunctionsMapConfiguration() th
3636
}
3737
}
3838

39-
public static String getFunctionConfigurationEntryPoint(String functionName, AzureFunctionConfiguration functionConfiguration)
40-
{
39+
public static String getFunctionConfigurationEntryPoint(String functionName, AzureFunctionConfiguration functionConfiguration) {
4140
if (functionConfiguration != null)
4241
return functionConfiguration.getGXClassName();
4342
else return null;
4443
}
4544

4645
public static AzureFunctionConfiguration getAzureFunctionConfiguration(String functionName, List<AzureFunctionConfiguration> mappings) throws FunctionConfigurationException {
47-
Optional<AzureFunctionConfiguration> config = null;
46+
Optional<AzureFunctionConfiguration> config = Optional.empty();
4847
if (mappings != null) {
4948
config = mappings.stream()
5049
.filter(c -> functionName.equals(c.getFunctionName()))
5150
.findFirst();
5251
}
5352
return config.orElseThrow(() -> new FunctionConfigurationException(String.format("Configuration not found for Azure function %s at gxazmappings.json.", functionName)));
5453
}
55-
5654
}

gxazureserverless/src/main/java/com/genexus/cloud/serverless/azure/handler/AzureQueueHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ public void run(
3131
EventMessage msg = new EventMessage();
3232
msg.setMessageId(id);
3333
msg.setMessageSourceType(EventMessageSourceType.QUEUE_MESSAGE);
34-
3534
msg.setMessageDate(new Date());
3635
msg.setMessageData(message);
37-
3836
List<EventMessageProperty> msgAtts = msg.getMessageProperties();
3937

4038
msgAtts.add(new EventMessageProperty("Id", id));
@@ -45,7 +43,6 @@ public void run(
4543
msgAtts.add(new EventMessageProperty("PopReceipt", popReceipt));
4644
msgs.add(msg);
4745
}
48-
4946
try {
5047
EventMessageResponse response = dispatchEvent(msgs, message);
5148
if (response.hasFailed()) {

gxazureserverless/src/main/java/com/genexus/cloud/serverless/azure/handler/AzureServiceBusQueueHandler.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.microsoft.azure.functions.ExecutionContext;
88
import com.microsoft.azure.functions.annotation.*;
99

10-
import java.util.Date;
1110
import java.util.List;
1211

1312
public class AzureServiceBusQueueHandler extends AzureEventHandler {
@@ -35,15 +34,13 @@ public void run(
3534
logger.error(String.format("Messages were not handled. Error: %s", response.getErrorMessage()));
3635
throw new RuntimeException(response.getErrorMessage()); //Throw the exception so the runtime can Retry the operation.
3736
}
38-
3937
} catch (Exception e) {
4038
logger.error("HandleRequest execution error", e);
4139
throw e; //Throw the exception so the runtime can Retry the operation.
4240
}
4341
}
4442

4543
protected void setupServiceBusMessages(List<ServiceBusReceivedMessage> messages) {
46-
4744
switch (executor.getMethodSignatureIdx()) {
4845
case 0:
4946
msgs = ServiceBusMessagesSetup.setupservicebuslistmsgs(messages);

0 commit comments

Comments
 (0)