Skip to content

Commit

Permalink
Bump up to jakartified LRA 2.0 (#3769)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Kec <daniel.kec@oracle.com>
  • Loading branch information
danielkec authored Feb 7, 2022
1 parent ea7c59d commit 2bcf608
Show file tree
Hide file tree
Showing 22 changed files with 125 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates.
* Copyright (c) 2020, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -46,13 +46,16 @@ public class MpConfigSourcesTest {
void testHelidonMap() {
Map<String, String> values = Map.of(
"key.first", "first",
"key.second", "second"
"key.second", "second",
"key.third", "<>{}().,:;/|\\~`?!@#$%^&*-=+*"
);
org.eclipse.microprofile.config.spi.ConfigSource mpSource = MpConfigSources.create(ConfigSources.create(values).build());

assertThat(mpSource.getValue("key.first"), is("first"));
assertThat(mpSource.getValue("key.second"), is("second"));
assertThat(mpSource.getValue("key.third"), is("<>{}().,:;/|\\~`?!@#$%^&*-=+*"));
}

@Test
void testHelidonParsable() {
ParsableImpl helidonSource = new ParsableImpl();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
* Copyright (c) 2017, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,7 +43,7 @@ public static Map<String, String> flattenNodes(ConfigNode.ObjectNode objectNode)
.filter(e -> e.getValue() instanceof ValueNodeImpl)
.collect(Collectors.toMap(
e -> e.getKey().toString(),
e -> Config.Key.escapeName(((ValueNodeImpl) e.getValue()).get())
e -> ((ValueNodeImpl) e.getValue()).get()
));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2020 Oracle and/or its affiliates.
* Copyright (c) 2017, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -181,7 +181,7 @@ private Map<String, String> tokenToValueMap(Map<String, String> flattenValueNode
+ "allowed.",
t));
}
return v;
return Config.Key.escapeName(v);
})));
}

Expand Down
2 changes: 1 addition & 1 deletion dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@
<version.lib.microprofile-reactive-streams-operators-core>2.0</version.lib.microprofile-reactive-streams-operators-core>
<version.lib.microprofile-rest-client>3.0</version.lib.microprofile-rest-client>
<version.lib.microprofile-tracing>3.0</version.lib.microprofile-tracing>
<version.lib.microprofile-lra-api>1.0</version.lib.microprofile-lra-api>
<version.lib.microprofile-lra-api>2.0-RC1</version.lib.microprofile-lra-api>
<version.lib.microstream>05.00.02-MS-GA</version.lib.microstream>
<version.lib.mockito>2.23.4</version.lib.mockito>
<version.lib.mongodb.reactivestreams>1.11.0</version.lib.mongodb.reactivestreams>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,7 @@
package io.helidon.lra.coordinator.client.narayana;

import java.net.URI;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -66,6 +67,7 @@ public void init(Supplier<URI> coordinatorUriSupplier, long timeout, TimeUnit ti
this.coordinatorTimeout = timeout;
this.coordinatorTimeoutUnit = timeoutUnit;
this.retry = Retry.builder()
.overallTimeout(Duration.ofMillis(timeoutUnit.toMillis(timeout)))
.retryPolicy(Retry.JitterRetryPolicy.builder()
.calls(RETRY_ATTEMPTS)
.build())
Expand Down Expand Up @@ -195,7 +197,7 @@ public Single<Optional<URI>> join(URI lraId,
switch (res.status().code()) {
case 412:
return connectionError(res.lastEndpointURI()
+ "Too late to join LRA - LRAID: " + lraId, 412);
+ " Too late to join LRA - LRAID: " + lraId, 412);
case 404:
// Narayana returns 404 for already terminated lras
case 410:
Expand Down
4 changes: 2 additions & 2 deletions lra/coordinator/server/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2021 Oracle and/or its affiliates.
# Copyright (c) 2021, 2022 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@ helidon.lra.coordinator:
connection:
url: "jdbc:h2:file:./lra-coordinator"
username: "h2"
password: ""
password: ${EMPTY}
poolName: "h2"
statements:
create-lra-table: >-
Expand Down
10 changes: 8 additions & 2 deletions lra/coordinator/server/src/test/java/CoordinatorTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,6 +15,7 @@
*/

import java.net.URI;
import java.util.Map;
import java.util.concurrent.TimeUnit;

import io.helidon.common.LazyValue;
Expand Down Expand Up @@ -52,7 +53,12 @@ static void beforeAll() {

coordinatorService = CoordinatorService.builder()
.url(coordinatorUri::get)
.config(Config.builder(() -> ConfigSources.classpath("application.yaml").build())
.config(Config.builder(
() -> ConfigSources.create(Map.of(
"helidon.lra.coordinator.db.connection.url", "jdbc:h2:file:./target/lra-coordinator"
)).build(),
() -> ConfigSources.classpath("application.yaml").build()
)
.build().get(CoordinatorService.CONFIG_PREFIX))
.build();
server = WebServer.builder()
Expand Down
13 changes: 1 addition & 12 deletions microprofile/lra/jax-rs/pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2021 Oracle and/or its affiliates.
~ Copyright (c) 2021, 2022 Oracle and/or its affiliates.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,17 +30,6 @@
<description>MicroProfile Long Running Actions implementation</description>

<dependencies>
<dependency>
<!--
TODO 3.0.0-JAKARTA
need to use this version to work around the same groupId/artifactId and
different package names in Jakarta
Needed for MP LRA API -->
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<scope>provided</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.eclipse.microprofile.lra</groupId>
<artifactId>microprofile-lra-api</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,6 +17,7 @@
package io.helidon.microprofile.lra;

import java.net.URI;
import java.time.Duration;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -55,6 +56,7 @@ interface HandlerMaker {
AnnotationHandler make(AnnotationInstance annotationInstance,
CoordinatorClient coordinatorClient,
InspectionService inspectionService,
ParticipantService participantService);
ParticipantService participantService,
Duration timeout);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -54,7 +54,7 @@ public class CoordinatorLocatorService {
CoordinatorLocatorService(@ConfigProperty(name = "mp.lra.coordinator.client") Optional<String> clientFqdn,
@ConfigProperty(name = CONF_KEY_COORDINATOR_URL, defaultValue = CONF_DEFAULT_COORDINATOR_URL)
String coordinatorUrl,
@ConfigProperty(name = CONF_KEY_COORDINATOR_TIMEOUT, defaultValue = "10")
@ConfigProperty(name = CONF_KEY_COORDINATOR_TIMEOUT, defaultValue = "30")
Long coordinatorTimeout,
@ConfigProperty(name = CONF_KEY_COORDINATOR_TIMEOUT_UNIT, defaultValue = "SECONDS")
TimeUnit coordinatorTimeoutUnit) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -17,11 +17,13 @@
package io.helidon.microprofile.lra;

import java.lang.reflect.Method;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import io.helidon.common.Reflected;
Expand All @@ -38,15 +40,18 @@
import org.eclipse.microprofile.lra.annotation.ws.rs.Leave;
import org.jboss.jandex.AnnotationInstance;

import static io.helidon.lra.coordinator.client.CoordinatorClient.CONF_KEY_COORDINATOR_TIMEOUT;
import static io.helidon.lra.coordinator.client.CoordinatorClient.CONF_KEY_COORDINATOR_TIMEOUT_UNIT;

@Reflected
class HandlerService {

private static final Map<String, AnnotationHandler.HandlerMaker> HANDLER_SUPPLIERS =
Map.of(
LRA.class.getName(), LraAnnotationHandler::new,
Leave.class.getName(), (a, client, i, p) -> new LeaveAnnotationHandler(client, p),
Status.class.getName(), (a, client, i, p) -> new NoopAnnotationHandler(),
AfterLRA.class.getName(), (a, client, i, p) -> new NoopAnnotationHandler()
Leave.class.getName(), (a, c, i, p, t) -> new LeaveAnnotationHandler(c, p),
Status.class.getName(), (a, c, i, p, t) -> new NoopAnnotationHandler(),
AfterLRA.class.getName(), (a, c, i, p, t) -> new NoopAnnotationHandler()
);

private static final Set<String> STAND_ALONE_ANNOTATIONS = Set.of(
Expand All @@ -62,17 +67,23 @@ class HandlerService {
private final ParticipantService participantService;
private final Map<Method, List<AnnotationHandler>> handlerCache = new ConcurrentHashMap<>();
private final boolean propagate;
private final Duration coordinatorTimeout;

@Inject
HandlerService(CoordinatorClient coordinatorClient,
InspectionService inspectionService,
ParticipantService participantService,
@ConfigProperty(name = "mp.lra.propagation.active", defaultValue = "true")
boolean propagate) {
boolean propagate,
@ConfigProperty(name = CONF_KEY_COORDINATOR_TIMEOUT, defaultValue = "30")
Long coordinatorTimeout,
@ConfigProperty(name = CONF_KEY_COORDINATOR_TIMEOUT_UNIT, defaultValue = "SECONDS")
TimeUnit coordinatorTimeoutUnit) {
this.coordinatorClient = coordinatorClient;
this.inspectionService = inspectionService;
this.participantService = participantService;
this.propagate = propagate;
this.coordinatorTimeout = Duration.of(coordinatorTimeout, coordinatorTimeoutUnit.toChronoUnit());
}

List<AnnotationHandler> getHandlers(Method method) {
Expand Down Expand Up @@ -106,7 +117,11 @@ private List<AnnotationHandler> createHandlers(Method m) {
// Non LRA annotation on LRA method, skipping
return null;
}
return handlerMaker.make(lraAnnotation, coordinatorClient, inspectionService, participantService);
return handlerMaker.make(lraAnnotation,
coordinatorClient,
inspectionService,
participantService,
coordinatorTimeout);
}).filter(Objects::nonNull)
.collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@
import java.time.Duration;
import java.util.Optional;
import java.util.concurrent.CompletionException;
import java.util.concurrent.TimeUnit;
import java.util.logging.Logger;

import io.helidon.common.context.Contexts;
Expand All @@ -48,12 +47,15 @@ class LraAnnotationHandler implements AnnotationHandler {
private final InspectionService.Lra annotation;
private final CoordinatorClient coordinatorClient;
private final ParticipantService participantService;
private Duration coordinatorTimeout;

LraAnnotationHandler(AnnotationInstance annotation,
CoordinatorClient coordinatorClient,
InspectionService inspectionService,
ParticipantService participantService) {
ParticipantService participantService,
Duration coordinatorTimeout) {
this.participantService = participantService;
this.coordinatorTimeout = coordinatorTimeout;
this.annotation = inspectionService.lraAnnotation(annotation);
this.coordinatorClient = coordinatorClient;
}
Expand Down Expand Up @@ -198,7 +200,7 @@ private void setParentContext(ContainerRequestContext reqCtx, URI lraId) {
private <T> T awaitCoordinator(Single<T> single) {
try {
// Connection timeout should be handled by client impl separately
return single.await(5, TimeUnit.SECONDS);
return single.await(coordinatorTimeout);
} catch (CompletionException e) {
Throwable cause = e.getCause();
if (cause instanceof CoordinatorConnectionException) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -38,6 +38,7 @@
import jakarta.inject.Inject;
import jakarta.ws.rs.core.Response;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.lra.LRAResponse;
import org.eclipse.microprofile.lra.annotation.LRAStatus;
import org.eclipse.microprofile.lra.annotation.ParticipantStatus;

Expand All @@ -57,9 +58,8 @@ class NonJaxRsResource {

private final ExecutorService exec;

// TODO 3.0.0-JAKARTA
private static final Map<ParticipantStatus, Supplier<Response>> PARTICIPANT_RESPONSE_BUILDERS =
Map.of(/*
Map.of(
ParticipantStatus.Compensating, () -> LRAResponse.compensating(ParticipantStatus.Compensating),
ParticipantStatus.Compensated, () -> LRAResponse.compensated(ParticipantStatus.Compensated),
ParticipantStatus.Active, () -> Response.ok(ParticipantStatus.Active.name()).build(),
Expand All @@ -68,7 +68,6 @@ class NonJaxRsResource {
ParticipantStatus.Completing, () -> LRAResponse.compensating(ParticipantStatus.Completing),
ParticipantStatus.Completed, () -> LRAResponse.compensating(ParticipantStatus.Completed),
ParticipantStatus.FailedToComplete, () -> LRAResponse.failedToComplete(ParticipantStatus.FailedToComplete)
*/
);

private final ParticipantService participantService;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021 Oracle and/or its affiliates.
* Copyright (c) 2021, 2022 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -125,7 +125,6 @@
@AddConfig(key = "server.sockets.2.name", value = CoordinatorClusterDeploymentService.COORDINATOR_B_NAME)
@AddConfig(key = "server.sockets.2.port", value = "0")
@AddConfig(key = "server.sockets.2.bind-address", value = "localhost")
@Disabled("3.0.0-JAKARTA")
public class LoadBalancedCoordinatorTest {

private static final Logger LOGGER = Logger.getLogger(LoadBalancedCoordinatorTest.class.getName());
Expand Down
Loading

0 comments on commit 2bcf608

Please sign in to comment.