-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: Use generic request executor for http pollerer and ldes-client (#…
…333)
- Loading branch information
Showing
13 changed files
with
243 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 3 additions & 53 deletions
56
.../java/be/vlaanderen/informatievlaanderen/ldes/ldio/config/LdioLdesClientConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,29 @@ | ||
package be.vlaanderen.informatievlaanderen.ldes.ldio.config; | ||
|
||
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.executor.RequestExecutor; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.services.RequestExecutorFactory; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.valueobjects.AuthStrategy; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldi.services.ComponentExecutor; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldi.types.LdiAdapter; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldi.types.LdiComponent; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldio.LdesClientRunner; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldio.LdioLdesClient; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldio.LdioLdesClientProperties; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldio.configurator.LdioInputConfigurator; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldio.requestexecutor.LdioRequestExecutorSupplier; | ||
import be.vlaanderen.informatievlaanderen.ldes.ldio.valueobjects.ComponentProperties; | ||
import ldes.client.treenodesupplier.domain.valueobject.StatePersistence; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Stream; | ||
|
||
import static be.vlaanderen.informatievlaanderen.ldes.ldi.requestexecutor.valueobjects.AuthStrategy.NO_AUTH; | ||
import static be.vlaanderen.informatievlaanderen.ldes.ldio.LdioLdesClientProperties.*; | ||
|
||
public class LdioLdesClientConfigurator implements LdioInputConfigurator { | ||
|
||
public static final String DEFAULT_API_KEY_HEADER = "X-API-KEY"; | ||
|
||
private final RequestExecutorFactory requestExecutorFactory = new RequestExecutorFactory(); | ||
private final LdioRequestExecutorSupplier ldioRequestExecutorSupplier = new LdioRequestExecutorSupplier(); | ||
private final StatePersistenceFactory statePersistenceFactory = new StatePersistenceFactory(); | ||
|
||
@Override | ||
public LdiComponent configure(LdiAdapter adapter, ComponentExecutor componentExecutor, | ||
ComponentProperties properties) { | ||
RequestExecutor requestExecutor = getRequestExecutorWithPossibleRetry(properties); | ||
RequestExecutor requestExecutor = ldioRequestExecutorSupplier.getRequestExecutor(properties); | ||
StatePersistence statePersistence = statePersistenceFactory.getStatePersistence(properties); | ||
LdesClientRunner ldesClientRunner = new LdesClientRunner(requestExecutor, properties, componentExecutor, | ||
statePersistence); | ||
return new LdioLdesClient(componentExecutor, ldesClientRunner); | ||
} | ||
|
||
protected RequestExecutor getRequestExecutorWithPossibleRetry(ComponentProperties props) { | ||
final RequestExecutor requestExecutor = getRequestExecutor(props); | ||
boolean retriesEnabled = props.getOptionalBoolean(RETRIES_ENABLED).orElse(Boolean.TRUE); | ||
if (retriesEnabled) { | ||
int maxRetries = props.getOptionalInteger(MAX_RETRIES).orElse(5); | ||
List<Integer> statusesToRetry = props.getOptionalProperty(STATUSES_TO_RETRY) | ||
.map(csv -> Stream.of(csv.split(",")).map(String::trim).map(Integer::parseInt).toList()) | ||
.orElse(new ArrayList<>()); | ||
return requestExecutorFactory.createRetryExecutor(requestExecutor, maxRetries, statusesToRetry); | ||
} else { | ||
return requestExecutor; | ||
} | ||
} | ||
|
||
private RequestExecutor getRequestExecutor(ComponentProperties componentProperties) { | ||
Optional<AuthStrategy> authentication = AuthStrategy | ||
.from(componentProperties.getOptionalProperty(LdioLdesClientProperties.AUTH_TYPE) | ||
.orElse(NO_AUTH.name())); | ||
if (authentication.isPresent()) { | ||
return switch (authentication.get()) { | ||
case NO_AUTH -> requestExecutorFactory.createNoAuthExecutor(); | ||
case API_KEY -> | ||
requestExecutorFactory.createApiKeyExecutor( | ||
componentProperties.getOptionalProperty(LdioLdesClientProperties.API_KEY_HEADER) | ||
.orElse(DEFAULT_API_KEY_HEADER), | ||
componentProperties.getProperty(LdioLdesClientProperties.API_KEY)); | ||
case OAUTH2_CLIENT_CREDENTIALS -> | ||
requestExecutorFactory.createClientCredentialsExecutor( | ||
componentProperties.getProperty(LdioLdesClientProperties.CLIENT_ID), | ||
componentProperties.getProperty(LdioLdesClientProperties.CLIENT_SECRET), | ||
componentProperties.getProperty(LdioLdesClientProperties.TOKEN_ENDPOINT)); | ||
}; | ||
} | ||
throw new UnsupportedOperationException( | ||
"Requested authentication not available: " | ||
+ componentProperties.getOptionalProperty(AUTH_TYPE).orElse("No auth type provided")); | ||
} | ||
|
||
} |
131 changes: 0 additions & 131 deletions
131
...ava/be/vlaanderen/informatievlaanderen/ldes/ldio/config/LdioLdesClientAutoConfigTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.