Search in sources :

Example 1 with RestClusterClient

use of org.infinispan.client.rest.RestClusterClient in project infinispan by infinispan.

the class BackupManagerIT method testClusterBackupFromFile.

@Test
public void testClusterBackupFromFile() throws Exception {
    String name = "testClusterBackup";
    performTest(client -> {
        RestClusterClient cluster = client.cluster();
        RestResponse response = await(cluster.createBackup(name));
        assertEquals(202, response.getStatus());
        return awaitOk(() -> cluster.getBackup(name, false));
    }, client -> await(client.cacheManager("clustered").deleteBackup(name)), (zip, client) -> {
        RestClusterClient c = client.cluster();
        RestResponse response = await(c.restore(name, zip.getPath()));
        assertEquals(202, response.getStatus());
        return awaitCreated(() -> c.getRestore(name));
    }, this::assertWildcardContent, true);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClusterClient(org.infinispan.client.rest.RestClusterClient) Test(org.junit.Test)

Example 2 with RestClusterClient

use of org.infinispan.client.rest.RestClusterClient in project infinispan by infinispan.

the class BackupManagerIT method testClusterBackupUpload.

@Test
public void testClusterBackupUpload() throws Exception {
    String name = "testClusterBackup";
    performTest(client -> {
        RestClusterClient cluster = client.cluster();
        RestResponse response = await(cluster.createBackup(name));
        assertEquals(202, response.getStatus());
        return awaitOk(() -> cluster.getBackup(name, false));
    }, client -> await(client.cacheManager("clustered").deleteBackup(name)), (zip, client) -> {
        RestClusterClient c = client.cluster();
        RestResponse response = await(c.restore(name, zip));
        assertEquals(202, response.getStatus());
        return awaitCreated(() -> c.getRestore(name));
    }, this::assertWildcardContent, false);
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) RestClusterClient(org.infinispan.client.rest.RestClusterClient) Test(org.junit.Test)

Example 3 with RestClusterClient

use of org.infinispan.client.rest.RestClusterClient in project infinispan by infinispan.

the class AbstractAuthorization method testRestNonAdminsMustNotAccessBackupsAndRestores.

@Test
public void testRestNonAdminsMustNotAccessBackupsAndRestores() {
    for (TestUser user : TestUser.NON_ADMINS) {
        RestClusterClient client = getServerTest().rest().withClientConfiguration(restBuilders.get(user)).get().cluster();
        assertStatus(FORBIDDEN, client.createBackup("backup"));
        assertStatus(FORBIDDEN, client.getBackup("backup", true));
        assertStatus(FORBIDDEN, client.getBackupNames());
        assertStatus(FORBIDDEN, client.deleteBackup("backup"));
        assertStatus(FORBIDDEN, client.restore("restore", "somewhere"));
        assertStatus(FORBIDDEN, client.getRestoreNames());
        assertStatus(FORBIDDEN, client.getRestore("restore"));
        assertStatus(FORBIDDEN, client.deleteRestore("restore"));
    }
}
Also used : TestUser(org.infinispan.server.test.api.TestUser) RestClusterClient(org.infinispan.client.rest.RestClusterClient) Test(org.junit.Test)

Example 4 with RestClusterClient

use of org.infinispan.client.rest.RestClusterClient in project infinispan by infinispan.

the class AbstractAuthorization method testRestAdminsMustAccessBackupsAndRestores.

@Test
public void testRestAdminsMustAccessBackupsAndRestores() throws IOException {
    String BACKUP_NAME = "backup";
    RestClusterClient client = getServerTest().rest().withClientConfiguration(restBuilders.get(TestUser.ADMIN)).get().cluster();
    assertStatus(ACCEPTED, client.createBackup(BACKUP_NAME));
    RestResponse response = awaitStatus(() -> client.getBackup(BACKUP_NAME, false), ACCEPTED, OK);
    String fileName = response.getHeader("Content-Disposition").split("=")[1];
    File backupZip = new File(getServers().getServerDriver().getRootDir(), fileName);
    try (InputStream is = response.getBodyAsStream()) {
        Files.copy(is, backupZip.toPath(), StandardCopyOption.REPLACE_EXISTING);
    } finally {
        response.close();
    }
    assertStatus(NO_CONTENT, client.deleteBackup(BACKUP_NAME));
    assertStatus(OK, client.getBackupNames());
    assertStatus(ACCEPTED, client.restore(BACKUP_NAME, backupZip));
    assertStatus(OK, client.getRestoreNames());
    awaitStatus(() -> client.getRestore(BACKUP_NAME), ACCEPTED, CREATED);
    assertStatus(NO_CONTENT, client.deleteRestore(BACKUP_NAME));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) InputStream(java.io.InputStream) RestClusterClient(org.infinispan.client.rest.RestClusterClient) File(java.io.File) Test(org.junit.Test)

Aggregations

RestClusterClient (org.infinispan.client.rest.RestClusterClient)4 Test (org.junit.Test)4 RestResponse (org.infinispan.client.rest.RestResponse)3 File (java.io.File)1 InputStream (java.io.InputStream)1 TestUser (org.infinispan.server.test.api.TestUser)1