Search in sources :

Example 1 with RepositoryIds

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;
}
Also used : RepositoryIds(com.enonic.xp.repository.RepositoryIds) RestoreResult(com.enonic.xp.node.RestoreResult) RepositoryId(com.enonic.xp.repository.RepositoryId)

Example 2 with RepositoryIds

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());
}
Also used : Path(java.nio.file.Path) RepositoryIds(com.enonic.xp.repository.RepositoryIds) Test(org.junit.jupiter.api.Test)

Example 3 with RepositoryIds

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());
}
Also used : Path(java.nio.file.Path) RepositoryIds(com.enonic.xp.repository.RepositoryIds) Test(org.junit.jupiter.api.Test)

Example 4 with RepositoryIds

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();
}
Also used : RepositoryIds(com.enonic.xp.repository.RepositoryIds)

Example 5 with RepositoryIds

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());
}
Also used : RefreshMode(com.enonic.xp.node.RefreshMode) NodeStorageService(com.enonic.xp.repo.impl.storage.NodeStorageService) EventPublisher(com.enonic.xp.event.EventPublisher) Node(com.enonic.xp.node.Node) RepositoryIds(com.enonic.xp.repository.RepositoryIds) Branch(com.enonic.xp.branch.Branch) Component(org.osgi.service.component.annotations.Component) RepositoryId(com.enonic.xp.repository.RepositoryId) ImmutableList(com.google.common.collect.ImmutableList) UpdateNodeCommand(com.enonic.xp.repo.impl.node.UpdateNodeCommand) ContextAccessor(com.enonic.xp.context.ContextAccessor) RefreshCommand(com.enonic.xp.repo.impl.node.RefreshCommand) NodeEvents(com.enonic.xp.repo.impl.NodeEvents) ContextBuilder(com.enonic.xp.context.ContextBuilder) ByteSource(com.google.common.io.ByteSource) SystemConstants(com.enonic.xp.security.SystemConstants) RepositoryEvents(com.enonic.xp.repo.impl.RepositoryEvents) FindNodesByParentCommand(com.enonic.xp.repo.impl.node.FindNodesByParentCommand) InternalContext(com.enonic.xp.repo.impl.InternalContext) NodeSearchService(com.enonic.xp.repo.impl.search.NodeSearchService) AttachedBinary(com.enonic.xp.node.AttachedBinary) NodeId(com.enonic.xp.node.NodeId) UpdateNodeParams(com.enonic.xp.node.UpdateNodeParams) NodeBranchEntries(com.enonic.xp.node.NodeBranchEntries) BinaryService(com.enonic.xp.repo.impl.binary.BinaryService) IndexServiceInternal(com.enonic.xp.repo.impl.index.IndexServiceInternal) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) DeleteNodeByIdCommand(com.enonic.xp.repo.impl.node.DeleteNodeByIdCommand) Context(com.enonic.xp.context.Context) Reference(org.osgi.service.component.annotations.Reference) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) RepositoryConstants(com.enonic.xp.repository.RepositoryConstants) Repository(com.enonic.xp.repository.Repository) FindNodesByParentParams(com.enonic.xp.node.FindNodesByParentParams) ImmutableList(com.google.common.collect.ImmutableList) FindNodesByParentResult(com.enonic.xp.node.FindNodesByParentResult) RepositoryId(com.enonic.xp.repository.RepositoryId)

Aggregations

RepositoryIds (com.enonic.xp.repository.RepositoryIds)6 RepositoryId (com.enonic.xp.repository.RepositoryId)2 Path (java.nio.file.Path)2 Test (org.junit.jupiter.api.Test)2 Branch (com.enonic.xp.branch.Branch)1 Context (com.enonic.xp.context.Context)1 ContextAccessor (com.enonic.xp.context.ContextAccessor)1 ContextBuilder (com.enonic.xp.context.ContextBuilder)1 EventPublisher (com.enonic.xp.event.EventPublisher)1 UpdateIndexSettingsResult (com.enonic.xp.index.UpdateIndexSettingsResult)1 AttachedBinary (com.enonic.xp.node.AttachedBinary)1 FindNodesByParentParams (com.enonic.xp.node.FindNodesByParentParams)1 FindNodesByParentResult (com.enonic.xp.node.FindNodesByParentResult)1 Node (com.enonic.xp.node.Node)1 NodeBranchEntries (com.enonic.xp.node.NodeBranchEntries)1 NodeId (com.enonic.xp.node.NodeId)1 RefreshMode (com.enonic.xp.node.RefreshMode)1 RestoreResult (com.enonic.xp.node.RestoreResult)1 UpdateNodeParams (com.enonic.xp.node.UpdateNodeParams)1 InternalContext (com.enonic.xp.repo.impl.InternalContext)1