use of com.enonic.xp.repository.RepositoryIds in project xp by enonic.
the class SnapshotServiceImpl method doRestore.
private RestoreResult doRestore(final RestoreParams restoreParams) {
checkSnapshotRepository();
final String snapshotName = restoreParams.isLatest() ? determineNameOfLatestSnapshot() : restoreParams.getSnapshotName();
validateSnapshot(snapshotName);
final RepositoryId repositoryToRestore = restoreParams.getRepositoryId();
boolean restoreAll = repositoryToRestore == null;
final RepositoryIds repositoriesBeforeRestore = restoreAll ? repositoryEntryService.findRepositoryEntryIds() : null;
this.eventPublisher.publish(RepositoryEvents.restoreInitialized());
if (restoreAll) {
LOG.info("Restoring all repositories from snapshot");
} else {
LOG.info("Restoring repository {} from snapshot", repositoryToRestore);
}
final RestoreResult result = SnapshotRestoreExecutor.create().snapshotName(snapshotName).repositoriesToClose(restoreAll ? repositoriesBeforeRestore : RepositoryIds.from(repositoryToRestore)).repositoriesToRestore(restoreAll ? RepositoryIds.empty() : RepositoryIds.from(repositoryToRestore)).client(this.client).snapshotRepositoryName(SNAPSHOT_REPOSITORY_NAME).indexServiceInternal(this.indexServiceInternal).build().execute();
if (restoreAll) {
final RepositoryIds repositoriesAfterRestore = repositoryEntryService.findRepositoryEntryIds();
repositoriesBeforeRestore.stream().filter(Predicate.not(repositoriesAfterRestore::contains)).forEach(repositoryId -> {
LOG.info("Deleting repository {} indices missing in snapshot", repositoryId);
indexServiceInternal.deleteIndices(IndexNameResolver.resolveIndexNames(repositoryId).toArray(String[]::new));
});
}
LOG.info("Snapshot Restore completed");
this.eventPublisher.publish(RepositoryEvents.restored());
return result;
}
use of com.enonic.xp.repository.RepositoryIds in project xp by enonic.
the class FileDumpReaderTest method repositories.
@Test
public void repositories() throws Exception {
final Path meta = createFolder(this.dumpFolder, "meta");
createFolder(meta, "repo1");
createFolder(meta, "repo2");
final RepositoryIds repositories = fileDumpReader.getRepositories();
assertEquals(2, repositories.getSize());
}
use of com.enonic.xp.repository.RepositoryIds in project xp by enonic.
the class FileDumpReaderTest method ignore_file_in_repo_dir.
@Test
public void ignore_file_in_repo_dir() throws Exception {
final Path meta = createFolder(this.dumpFolder, "meta");
createFolder(meta, "repo1");
createFolder(meta, "repo2");
createFile(meta, "fisk");
final RepositoryIds repositories = fileDumpReader.getRepositories();
assertEquals(2, repositories.getSize());
}
use of com.enonic.xp.repository.RepositoryIds in project xp by enonic.
the class SnapshotServiceImpl method doSnapshot.
private SnapshotResult doSnapshot(final SnapshotParams snapshotParams) {
checkSnapshotRepository();
final RepositoryIds repositoriesToSnapshot = Optional.ofNullable(snapshotParams.getRepositoryId()).map(RepositoryIds::from).orElseGet(repositoryEntryService::findRepositoryEntryIds);
return SnapshotExecutor.create().snapshotName(snapshotParams.getSnapshotName()).repositories(repositoriesToSnapshot).client(this.client).snapshotRepositoryName(SNAPSHOT_REPOSITORY_NAME).build().execute();
}
use of com.enonic.xp.repository.RepositoryIds in project xp by enonic.
the class RepositoryEntryServiceImpl method findRepositoryEntryIds.
@Override
public RepositoryIds findRepositoryEntryIds() {
final ImmutableList.Builder<RepositoryId> repositoryIds = ImmutableList.builder();
final FindNodesByParentParams findNodesByParentParams = FindNodesByParentParams.create().parentPath(RepositoryConstants.REPOSITORY_STORAGE_PARENT_PATH).size(-1).build();
final FindNodesByParentResult findNodesByParentResult = createContext().callWith(() -> FindNodesByParentCommand.create().params(findNodesByParentParams).indexServiceInternal(this.indexServiceInternal).storageService(this.nodeStorageService).searchService(this.nodeSearchService).build().execute());
findNodesByParentResult.getNodeIds().stream().map(nodeId -> RepositoryId.from(nodeId.toString())).forEach(repositoryIds::add);
return RepositoryIds.from(repositoryIds.build());
}
Aggregations