Skip to content

Commit

Permalink
Atomic removed rollback (#138)
Browse files Browse the repository at this point in the history
* Update README.md

* removed rollback
  • Loading branch information
ndc-dxc authored Aug 30, 2024
1 parent 45bdde0 commit 7ef0901
Show file tree
Hide file tree
Showing 8 changed files with 5 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<RepositoryInstance> getCurrentInstances() {
return instances.entrySet().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RepositoryInstance> getCurrentInstances() {
return repositoryService.getActiveRepos().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public interface InstanceManager {

void switchInstances(Repository repository);

void rollbackInstance(Repository repository);

List<RepositoryInstance> getCurrentInstances();

@Data
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-local.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 7ef0901

Please sign in to comment.