Search in sources :

Example 1 with RestServerEndpoint

use of org.apache.flink.runtime.rest.RestServerEndpoint in project flink by apache.

the class RestClusterClientSavepointTriggerTest method testTriggerSavepointRetry.

@Test
public void testTriggerSavepointRetry() throws Exception {
    final TriggerId triggerId = new TriggerId();
    final String expectedSavepointDir = "hello";
    final AtomicBoolean failRequest = new AtomicBoolean(true);
    try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint(request -> triggerId, trigger -> {
        if (failRequest.compareAndSet(true, false)) {
            throw new RestHandlerException("expected", HttpResponseStatus.SERVICE_UNAVAILABLE);
        } else {
            return new SavepointInfo(expectedSavepointDir, null);
        }
    })) {
        final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
        final String savepointPath = restClusterClient.triggerSavepoint(new JobID(), null, SavepointFormatType.CANONICAL).get();
        assertEquals(expectedSavepointDir, savepointPath);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) RestServerEndpoint(org.apache.flink.runtime.rest.RestServerEndpoint) SavepointInfo(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo) RestHandlerException(org.apache.flink.runtime.rest.handler.RestHandlerException) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 2 with RestServerEndpoint

use of org.apache.flink.runtime.rest.RestServerEndpoint in project flink by apache.

the class RestClusterClientSavepointTriggerTest method testTriggerSavepointDefaultDirectory.

@Test
public void testTriggerSavepointDefaultDirectory() throws Exception {
    final TriggerId triggerId = new TriggerId();
    final String expectedReturnedSavepointDir = "hello";
    try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint(request -> {
        assertThat(request.getTargetDirectory().isPresent(), is(false));
        assertFalse(request.isCancelJob());
        return triggerId;
    }, trigger -> {
        assertEquals(triggerId, trigger);
        return new SavepointInfo(expectedReturnedSavepointDir, null);
    })) {
        final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
        final String savepointPath = restClusterClient.triggerSavepoint(new JobID(), null, SavepointFormatType.CANONICAL).get();
        assertEquals(expectedReturnedSavepointDir, savepointPath);
    }
}
Also used : TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) RestServerEndpoint(org.apache.flink.runtime.rest.RestServerEndpoint) SavepointInfo(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 3 with RestServerEndpoint

use of org.apache.flink.runtime.rest.RestServerEndpoint in project flink by apache.

the class RestClusterClientSavepointTriggerTest method testTriggerSavepointTargetDirectory.

@Test
public void testTriggerSavepointTargetDirectory() throws Exception {
    final TriggerId triggerId = new TriggerId();
    final String expectedSubmittedSavepointDir = "world";
    final String expectedReturnedSavepointDir = "hello";
    try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint(triggerRequestBody -> {
        assertEquals(expectedSubmittedSavepointDir, triggerRequestBody.getTargetDirectory().get());
        assertFalse(triggerRequestBody.isCancelJob());
        return triggerId;
    }, statusRequestTriggerId -> {
        assertEquals(triggerId, statusRequestTriggerId);
        return new SavepointInfo(expectedReturnedSavepointDir, null);
    })) {
        final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
        final String savepointPath = restClusterClient.triggerSavepoint(new JobID(), expectedSubmittedSavepointDir, SavepointFormatType.CANONICAL).get();
        assertEquals(expectedReturnedSavepointDir, savepointPath);
    }
}
Also used : TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) RestServerEndpoint(org.apache.flink.runtime.rest.RestServerEndpoint) SavepointInfo(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 4 with RestServerEndpoint

use of org.apache.flink.runtime.rest.RestServerEndpoint in project flink by apache.

the class RestClusterClientSavepointTriggerTest method testTriggerSavepointCancelJob.

@Test
public void testTriggerSavepointCancelJob() throws Exception {
    final TriggerId triggerId = new TriggerId();
    final String expectedSavepointDir = "hello";
    try (final RestServerEndpoint restServerEndpoint = createRestServerEndpoint(request -> {
        assertTrue(request.isCancelJob());
        return triggerId;
    }, trigger -> {
        assertEquals(triggerId, trigger);
        return new SavepointInfo(expectedSavepointDir, null);
    })) {
        final RestClusterClient<?> restClusterClient = createRestClusterClient(restServerEndpoint.getServerAddress().getPort());
        final String savepointPath = restClusterClient.cancelWithSavepoint(new JobID(), null, SavepointFormatType.CANONICAL).get();
        assertEquals(expectedSavepointDir, savepointPath);
    }
}
Also used : TriggerId(org.apache.flink.runtime.rest.messages.TriggerId) TestRestServerEndpoint(org.apache.flink.runtime.rest.util.TestRestServerEndpoint) RestServerEndpoint(org.apache.flink.runtime.rest.RestServerEndpoint) SavepointInfo(org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

JobID (org.apache.flink.api.common.JobID)4 RestServerEndpoint (org.apache.flink.runtime.rest.RestServerEndpoint)4 TriggerId (org.apache.flink.runtime.rest.messages.TriggerId)4 SavepointInfo (org.apache.flink.runtime.rest.messages.job.savepoints.SavepointInfo)4 TestRestServerEndpoint (org.apache.flink.runtime.rest.util.TestRestServerEndpoint)4 Test (org.junit.Test)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 RestHandlerException (org.apache.flink.runtime.rest.handler.RestHandlerException)1