Search in sources :

Example 1 with RestoreResult

use of com.enonic.xp.node.RestoreResult in project xp by enonic.

the class SnapshotResourceTest method restore.

@Test
public void restore() throws Exception {
    final RestoreResult restoreResult = RestoreResult.create().repositoryId(RepositoryId.from("repo-id")).name("name").message("He's dead, Jim.").indices(Arrays.asList("bc02aa")).failed(false).build();
    Mockito.when(this.snapshotService.restore(isA(RestoreParams.class))).thenReturn(restoreResult);
    final String result = request().path("repo/snapshot/restore").entity(readFromFile("restore_params.json"), MediaType.APPLICATION_JSON_TYPE).post().getAsString();
    assertJson("restore.json", result);
}
Also used : RestoreResult(com.enonic.xp.node.RestoreResult) RestoreParams(com.enonic.xp.node.RestoreParams) Test(org.junit.jupiter.api.Test)

Example 2 with RestoreResult

use of com.enonic.xp.node.RestoreResult 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 3 with RestoreResult

use of com.enonic.xp.node.RestoreResult in project xp by enonic.

the class SnapshotServiceImplTest method doRestoreLatest.

private void doRestoreLatest() {
    final RepositoryId newRepoId = RepositoryId.from("new-repo");
    this.repositoryService.createRepository(CreateRepositoryParams.create().repositoryId(newRepoId).build());
    assertNotNull(this.repositoryService.get(newRepoId));
    this.snapshotService.snapshot(SnapshotParams.create().snapshotName("my-snapshot-latest").build());
    this.repositoryService.deleteRepository(DeleteRepositoryParams.from(newRepoId));
    assertNull(this.repositoryService.get(newRepoId));
    final RestoreResult restoreResult = this.snapshotService.restore(RestoreParams.create().repositoryId(newRepoId).latest(true).build());
    assertEquals("my-snapshot-latest", restoreResult.getName());
    // The system repo does not know about this repo now
    assertNull(this.repositoryService.get(newRepoId));
    this.snapshotService.restore(RestoreParams.create().repositoryId(SystemConstants.SYSTEM_REPO_ID).snapshotName("my-snapshot-latest").build());
    assertNotNull(this.repositoryService.get(newRepoId));
    assertNotNull(this.repositoryService.get(SystemConstants.SYSTEM_REPO_ID));
    assertNotNull(this.repositoryService.get(TEST_REPO_ID));
}
Also used : RestoreResult(com.enonic.xp.node.RestoreResult) RepositoryId(com.enonic.xp.repository.RepositoryId)

Example 4 with RestoreResult

use of com.enonic.xp.node.RestoreResult in project xp by enonic.

the class SnapshotResourceTest method restore_latest.

@Test
public void restore_latest() throws Exception {
    final RestoreResult restoreResult = RestoreResult.create().repositoryId(RepositoryId.from("repo-id")).name("name").message("He's dead, Jim.").indices(Arrays.asList("bc02aa")).failed(false).build();
    Mockito.when(this.snapshotService.restore(isA(RestoreParams.class))).thenReturn(restoreResult);
    final String result = request().path("repo/snapshot/restore").entity(readFromFile("restore_latest_params.json"), MediaType.APPLICATION_JSON_TYPE).post().getAsString();
    assertJson("restore.json", result);
}
Also used : RestoreResult(com.enonic.xp.node.RestoreResult) RestoreParams(com.enonic.xp.node.RestoreParams) Test(org.junit.jupiter.api.Test)

Aggregations

RestoreResult (com.enonic.xp.node.RestoreResult)4 RestoreParams (com.enonic.xp.node.RestoreParams)2 RepositoryId (com.enonic.xp.repository.RepositoryId)2 Test (org.junit.jupiter.api.Test)2 RepositoryIds (com.enonic.xp.repository.RepositoryIds)1