Changesets · Branches · Tags · Compare
| Changeset | 93b61d08db12c0f9e751dcfb3b56499da7408febb49b93b6433304ef62103fd5 |
|---|---|
| Author | ndr_brt <andrea.bertagnolli@gmail.com> · 2024-07-31 16:41 +02:00 |
| Committer | GitHub <noreply@github.com> · 2024-07-31 16:41 +02:00 |
| Parents | 0a7c8f90128e |
2 files changed
modified extensions/data-plane/data-plane-self-registration/src/main/java/org/eclipse/edc/connector/dataplane/registration/DataplaneSelfRegistrationExtension.java +13 −5
| @@ -20,6 +20,7 @@ | ||
| 20 | 20 | import org.eclipse.edc.connector.dataplane.spi.pipeline.PipelineService; |
| 21 | 21 | import org.eclipse.edc.runtime.metamodel.annotation.Extension; |
| 22 | 22 | import org.eclipse.edc.runtime.metamodel.annotation.Inject; |
| 23 | +import org.eclipse.edc.runtime.metamodel.annotation.Setting; | |
| 23 | 24 | import org.eclipse.edc.spi.EdcException; |
| 24 | 25 | import org.eclipse.edc.spi.system.ServiceExtension; |
| 25 | 26 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| @@ -48,6 +49,12 @@ | ||
| 48 | 49 | public static final String NAME = "Dataplane Self Registration"; |
| 49 | 50 | private final AtomicBoolean isRegistered = new AtomicBoolean(false); |
| 50 | 51 | private final AtomicReference<String> registrationError = new AtomicReference<>("Data plane self registration not complete"); |
| 52 | + | |
| 53 | + private static final boolean DEFAULT_SELF_UNREGISTRATION = false; | |
| 54 | + | |
| 55 | + @Setting(value = "Enable data-plane un-registration at shutdown (not suggested for clustered environments)", type = "boolean", defaultValue = DEFAULT_SELF_UNREGISTRATION + "") | |
| 56 | + static final String SELF_UNREGISTRATION = "edc.data.plane.self.unregistration"; | |
| 57 | + | |
| 51 | 58 | @Inject |
| 52 | 59 | private DataPlaneSelectorService dataPlaneSelectorService; |
| 53 | 60 | @Inject |
| @@ -86,7 +93,6 @@ | ||
| 86 | 93 | .allowedTransferType(transferTypes.collect(toSet())) |
| 87 | 94 | .build(); |
| 88 | 95 | |
| 89 | - | |
| 90 | 96 | var monitor = context.getMonitor().withPrefix("DataPlaneHealthCheck"); |
| 91 | 97 | var check = new DataPlaneHealthCheck(); |
| 92 | 98 | healthCheckService.addReadinessProvider(check); |
| @@ -105,10 +111,12 @@ | ||
| 105 | 111 | |
| 106 | 112 | @Override |
| 107 | 113 | public void shutdown() { |
| 108 | - dataPlaneSelectorService.unregister(context.getRuntimeId()) | |
| 109 | - .onSuccess(it -> context.getMonitor().info("data plane successfully unregistered")) | |
| 110 | - .onFailure(failure -> context.getMonitor().severe("error during data plane de-registration. %s: %s" | |
| 111 | - .formatted(failure.getReason(), failure.getFailureDetail()))); | |
| 114 | + if (context.getConfig().getBoolean(SELF_UNREGISTRATION, DEFAULT_SELF_UNREGISTRATION)) { | |
| 115 | + dataPlaneSelectorService.unregister(context.getRuntimeId()) | |
| 116 | + .onSuccess(it -> context.getMonitor().info("data plane successfully unregistered")) | |
| 117 | + .onFailure(failure -> context.getMonitor().severe("error during data plane de-registration. %s: %s" | |
| 118 | + .formatted(failure.getReason(), failure.getFailureDetail()))); | |
| 119 | + } | |
| 112 | 120 | } |
| 113 | 121 | |
| 114 | 122 | private @NotNull Stream<String> toTransferTypes(FlowType pull, Set<String> types) { |
modified extensions/data-plane/data-plane-self-registration/src/test/java/org/eclipse/edc/connector/dataplane/registration/DataplaneSelfRegistrationExtensionTest.java +17 −1
| @@ -23,6 +23,7 @@ | ||
| 23 | 23 | import org.eclipse.edc.spi.monitor.Monitor; |
| 24 | 24 | import org.eclipse.edc.spi.result.ServiceResult; |
| 25 | 25 | import org.eclipse.edc.spi.system.ServiceExtensionContext; |
| 26 | +import org.eclipse.edc.spi.system.configuration.ConfigFactory; | |
| 26 | 27 | import org.eclipse.edc.spi.system.health.HealthCheckService; |
| 27 | 28 | import org.eclipse.edc.web.spi.configuration.context.ControlApiUrl; |
| 28 | 29 | import org.junit.jupiter.api.BeforeEach; |
| @@ -33,13 +34,16 @@ | ||
| 33 | 34 | import java.net.MalformedURLException; |
| 34 | 35 | import java.net.URI; |
| 35 | 36 | import java.net.URL; |
| 37 | +import java.util.Map; | |
| 36 | 38 | import java.util.Set; |
| 37 | 39 | |
| 38 | 40 | import static org.assertj.core.api.Assertions.assertThat; |
| 39 | 41 | import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 42 | +import static org.eclipse.edc.connector.dataplane.registration.DataplaneSelfRegistrationExtension.SELF_UNREGISTRATION; | |
| 40 | 43 | import static org.mockito.ArgumentMatchers.any; |
| 41 | 44 | import static org.mockito.ArgumentMatchers.anyString; |
| 42 | 45 | import static org.mockito.Mockito.mock; |
| 46 | +import static org.mockito.Mockito.never; | |
| 43 | 47 | import static org.mockito.Mockito.verify; |
| 44 | 48 | import static org.mockito.Mockito.when; |
| 45 | 49 | |
| @@ -102,13 +106,25 @@ | ||
| 102 | 106 | } |
| 103 | 107 | |
| 104 | 108 | @Test |
| 105 | - void shouldUnregisterInstanceAtShutdown(DataplaneSelfRegistrationExtension extension, ServiceExtensionContext context) { | |
| 109 | + void shouldNotUnregisterInstanceAtShutdown(DataplaneSelfRegistrationExtension extension, ServiceExtensionContext context) { | |
| 106 | 110 | when(context.getRuntimeId()).thenReturn("runtimeId"); |
| 107 | 111 | when(dataPlaneSelectorService.unregister(any())).thenReturn(ServiceResult.success()); |
| 108 | 112 | extension.initialize(context); |
| 109 | 113 | |
| 110 | 114 | extension.shutdown(); |
| 111 | 115 | |
| 116 | + verify(dataPlaneSelectorService, never()).unregister(any()); | |
| 117 | + } | |
| 118 | + | |
| 119 | + @Test | |
| 120 | + void shouldUnregisterInstanceAtShutdown_whenConfigured(DataplaneSelfRegistrationExtension extension, ServiceExtensionContext context) { | |
| 121 | + when(context.getRuntimeId()).thenReturn("runtimeId"); | |
| 122 | + when(context.getConfig()).thenReturn(ConfigFactory.fromMap(Map.of(SELF_UNREGISTRATION, "true"))); | |
| 123 | + when(dataPlaneSelectorService.unregister(any())).thenReturn(ServiceResult.success()); | |
| 124 | + extension.initialize(context); | |
| 125 | + | |
| 126 | + extension.shutdown(); | |
| 127 | + | |
| 112 | 128 | verify(dataPlaneSelectorService).unregister("runtimeId"); |
| 113 | 129 | } |
| 114 | 130 | } |