Skip to content

Commit

Permalink
Merge pull request #149 from xm-online/feature/spec_update_fix
Browse files Browse the repository at this point in the history
Feature/spec update fix
  • Loading branch information
sergeysenja1992 committed Jun 5, 2024
2 parents 45a0936 + 71b9f76 commit 7779bfd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

public class MapSpecResolver implements SagaSpecResolver {

Expand All @@ -23,9 +24,18 @@ public Optional<SagaTransactionSpec> findTransactionSpec(String tenant, SagaType
public void update(String tenant, String updatedKey, SagaSpec spec) {
Map<String, SagaSpec> tenantMap = getTenantMap(tenant);
tenantMap.put(updatedKey, spec);
updateRetryPolicy(spec);
updateTenantSpec(tenant);
}

private void updateRetryPolicy(SagaSpec spec) {
spec.getTransactions().forEach(tx -> tx.setTasks(
tx.getTasks().stream().peek(
task -> task.applyAsDefaultTransactionConfig(tx)
).collect(Collectors.toList())
));
}

private void updateTenantSpec(String tenant) {
Map<String, SagaSpec> tenantMap = getTenantMap(tenant);
tenantMap.values().stream().reduce(SagaSpec::mergeSpec).ifPresent(it -> sagaSpecs.put(tenant, it));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public void onRefresh(String updatedKey, String config) {
sagaSpecResolver.remove(tenant, updatedKey);
log.info("Spec for tenant '{}' were removed: {}", tenant, updatedKey);
} else {
updateRetryPolicy(spec);
sagaSpecResolver.update(tenant, updatedKey, spec);
log.info("Spec for tenant '{}' were updated: {}", tenant, updatedKey);
}
Expand All @@ -62,14 +61,6 @@ public void onRefresh(String updatedKey, String config) {
}
}

private void updateRetryPolicy(SagaSpec spec) {
spec.getTransactions().forEach(tx -> tx.setTasks(
tx.getTasks().stream().peek(
task -> task.applyAsDefaultTransactionConfig(tx)
).collect(Collectors.toList())
));
}

private String extractTenant(final String updatedKey) {
if (matcher.match(PATH_PATTERN, updatedKey)) {
return matcher.extractUriTemplateVariables(PATH_PATTERN, updatedKey).get(TENANT_NAME);
Expand Down

0 comments on commit 7779bfd

Please sign in to comment.