From 7ef09019279569755fe7aaf0b2177f57070fc057 Mon Sep 17 00:00:00 2001 From: ndc-dxc <162444006+ndc-dxc@users.noreply.github.com> Date: Fri, 30 Aug 2024 11:39:49 +0200 Subject: [PATCH] Atomic removed rollback (#138) * Update README.md * removed rollback --- .../integration/InMemoryInstanceManager.java | 5 ----- .../ndc/controller/HarvestJobController.java | 7 ------- .../ndc/harvester/HarvesterJob.java | 6 ------ .../ndc/harvester/HarvesterService.java | 2 -- .../ndc/repository/TripleStoreRepository.java | 18 ++++-------------- .../ndc/service/DefaultInstanceManager.java | 7 ------- .../ndc/service/InstanceManager.java | 2 -- .../resources/application-local.properties | 2 +- 8 files changed, 5 insertions(+), 44 deletions(-) diff --git a/src/integration/java/it/gov/innovazione/ndc/integration/InMemoryInstanceManager.java b/src/integration/java/it/gov/innovazione/ndc/integration/InMemoryInstanceManager.java index 21f6b66..cd5d29f 100644 --- a/src/integration/java/it/gov/innovazione/ndc/integration/InMemoryInstanceManager.java +++ b/src/integration/java/it/gov/innovazione/ndc/integration/InMemoryInstanceManager.java @@ -56,11 +56,6 @@ public void switchInstances(Repository repository) { instances.put(repository.getUrl(), toPut); } - @Override - public void rollbackInstance(Repository repository) { - switchInstances(repository); - } - @Override public List getCurrentInstances() { return instances.entrySet().stream() diff --git a/src/main/java/it/gov/innovazione/ndc/controller/HarvestJobController.java b/src/main/java/it/gov/innovazione/ndc/controller/HarvestJobController.java index 107fb44..51012a9 100644 --- a/src/main/java/it/gov/innovazione/ndc/controller/HarvestJobController.java +++ b/src/main/java/it/gov/innovazione/ndc/controller/HarvestJobController.java @@ -103,13 +103,6 @@ public void clearRepo(@RequestParam("repo_url") String repoUrl) { .build()); } - @PostMapping(value = "jobs/rollback", params = "repositoryId") - @ResponseStatus(HttpStatus.ACCEPTED) - public void rollback(@RequestParam("repositoryId") String repositoryId) { - log.info("Starting rollback job at " + LocalDateTime.now() + "for repository " + repositoryId); - harvesterJob.rollback(repositoryId); - } - @Getter @Builder private static class WebHarversterAlertableEvent implements AlertableEvent { diff --git a/src/main/java/it/gov/innovazione/ndc/harvester/HarvesterJob.java b/src/main/java/it/gov/innovazione/ndc/harvester/HarvesterJob.java index 4eafa2f..8e678ca 100644 --- a/src/main/java/it/gov/innovazione/ndc/harvester/HarvesterJob.java +++ b/src/main/java/it/gov/innovazione/ndc/harvester/HarvesterJob.java @@ -85,10 +85,4 @@ private JobExecutionResponse harvest(Repository repository, String correlationId return responseBuilder.build(); } - - public void rollback(String repositoryId) { - Repository repository = repositoryService.findActiveRepoById(repositoryId) - .orElseThrow(() -> new HarvestJobException(String.format("Repository %s not found", repositoryId))); - defaultInstanceManager.rollbackInstance(repository); - } } diff --git a/src/main/java/it/gov/innovazione/ndc/harvester/HarvesterService.java b/src/main/java/it/gov/innovazione/ndc/harvester/HarvesterService.java index 91508a4..d67962b 100644 --- a/src/main/java/it/gov/innovazione/ndc/harvester/HarvesterService.java +++ b/src/main/java/it/gov/innovazione/ndc/harvester/HarvesterService.java @@ -21,7 +21,6 @@ import java.util.Objects; import java.util.Optional; -import static it.gov.innovazione.ndc.repository.TripleStoreRepository.OLD_GRAPH_PREFIX; import static it.gov.innovazione.ndc.repository.TripleStoreRepository.ONLINE_GRAPH_PREFIX; import static it.gov.innovazione.ndc.repository.TripleStoreRepository.TMP_GRAPH_PREFIX; import static java.util.stream.Collectors.groupingBy; @@ -143,7 +142,6 @@ private void clearRepoAllInstances(String repoUrl) { cleanUpWithHarvesters(repoUrl, Instance.PRIMARY); cleanUpWithHarvesters(repoUrl, Instance.SECONDARY); cleanUpTripleStore(repoUrl, TMP_GRAPH_PREFIX); - cleanUpTripleStore(repoUrl, OLD_GRAPH_PREFIX); cleanUpTripleStore(repoUrl, ONLINE_GRAPH_PREFIX); cleanUpIndexedMetadata(repoUrl, Instance.PRIMARY); cleanUpIndexedMetadata(repoUrl, Instance.SECONDARY); diff --git a/src/main/java/it/gov/innovazione/ndc/repository/TripleStoreRepository.java b/src/main/java/it/gov/innovazione/ndc/repository/TripleStoreRepository.java index bb0d1aa..9b443bc 100644 --- a/src/main/java/it/gov/innovazione/ndc/repository/TripleStoreRepository.java +++ b/src/main/java/it/gov/innovazione/ndc/repository/TripleStoreRepository.java @@ -21,7 +21,6 @@ public class TripleStoreRepository { private static final String DROP_SILENT_GRAPH_WITH_LOG_ENABLE_3 = "DEFINE sql:log-enable 3%nDROP SILENT GRAPH <%s>%n"; public static final String TMP_GRAPH_PREFIX = "tmp"; - public static final String OLD_GRAPH_PREFIX = "old"; public static final String ONLINE_GRAPH_PREFIX = ""; private static final String RENAME_GRAPH = "DEFINE sql:log-enable 3%nMOVE SILENT GRAPH <%s> to <%s>%n"; @@ -63,7 +62,7 @@ private static String reworkRepoUrlIfNecessary(String repoUrl, String repoUrlPre } public void clearExistingNamedGraph(String repoUrl) { - clearExistingNamedGraph(repoUrl, ""); + clearExistingNamedGraph(repoUrl, ONLINE_GRAPH_PREFIX); } public void clearExistingNamedGraph(String repoUrl, String prefix) { @@ -93,28 +92,19 @@ public void save(String graphName, Model model) { public void switchInstances(it.gov.innovazione.ndc.model.harvester.Repository repository) { String tmpGraphName = reworkRepoUrlIfNecessary(repository.getUrl(), TMP_GRAPH_PREFIX); - String oldGraphName = reworkRepoUrlIfNecessary(repository.getUrl(), OLD_GRAPH_PREFIX); - clearExistingNamedGraph(repository.getUrl(), OLD_GRAPH_PREFIX); - rename(repository.getUrl(), oldGraphName); + clearExistingNamedGraph(repository.getUrl()); rename(tmpGraphName, repository.getUrl()); } - - public void rollbackInstance(it.gov.innovazione.ndc.model.harvester.Repository repository) { - String tmpGraphName = reworkRepoUrlIfNecessary(repository.getUrl(), TMP_GRAPH_PREFIX); - String oldGraphName = reworkRepoUrlIfNecessary(repository.getUrl(), OLD_GRAPH_PREFIX); - rename(repository.getUrl(), tmpGraphName); - rename(oldGraphName, repository.getUrl()); - rename(tmpGraphName, oldGraphName); - } - public void rename(String oldGraph, String newGraph) { try { String sparqlEndpoint = virtuosoClient.getSparqlEndpoint(); + log.info("Renaming {} into {}", oldGraph, newGraph); UpdateExecution .service(sparqlEndpoint) .updateString(getRenameCommand(oldGraph, newGraph)) .execute(); + log.info("Renamed {} into {}", oldGraph, newGraph); } catch (Exception e) { log.error(format("Could not rename %s into %s ", oldGraph, newGraph), e); throw new TripleStoreRepositoryException(format("Could not rename - '%s' -> '%s'", oldGraph, newGraph), e); diff --git a/src/main/java/it/gov/innovazione/ndc/service/DefaultInstanceManager.java b/src/main/java/it/gov/innovazione/ndc/service/DefaultInstanceManager.java index 9c2f8d1..1189e2b 100644 --- a/src/main/java/it/gov/innovazione/ndc/service/DefaultInstanceManager.java +++ b/src/main/java/it/gov/innovazione/ndc/service/DefaultInstanceManager.java @@ -51,13 +51,6 @@ public void switchInstances(Repository repository) { tripleStoreRepository.switchInstances(repository); } - public void rollbackInstance(Repository repository) { - // rollback instance on Repositories - configService.writeConfigKey(ACTIVE_INSTANCE, "system", getOldOnlineInstance(repository), repository.getId()); - // rollback instance on Virtuoso - tripleStoreRepository.rollbackInstance(repository); - } - @Override public List getCurrentInstances() { return repositoryService.getActiveRepos().stream() diff --git a/src/main/java/it/gov/innovazione/ndc/service/InstanceManager.java b/src/main/java/it/gov/innovazione/ndc/service/InstanceManager.java index 468984d..9ef30c0 100644 --- a/src/main/java/it/gov/innovazione/ndc/service/InstanceManager.java +++ b/src/main/java/it/gov/innovazione/ndc/service/InstanceManager.java @@ -16,8 +16,6 @@ public interface InstanceManager { void switchInstances(Repository repository); - void rollbackInstance(Repository repository); - List getCurrentInstances(); @Data diff --git a/src/main/resources/application-local.properties b/src/main/resources/application-local.properties index e14d0ac..71fcaba 100644 --- a/src/main/resources/application-local.properties +++ b/src/main/resources/application-local.properties @@ -1,4 +1,4 @@ -harvester.repositories=https://github.com/FrankMaverick/Leo-OpenData +harvester.repositories=https://github.com/istat/ts-ontologie-vocabolari-controllati virtuoso.sparql=http://localhost:8890/sparql-auth virtuoso.sparql-graph-store=http://localhost:8890/sparql-graph-crud-auth