Search in sources :

Example 1 with TriggerSavepointFailure

use of org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointFailure in project flink by apache.

the class CliFrontend method triggerSavepoint.

/**
	 * Sends a {@link org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint}
	 * message to the job manager.
	 */
private int triggerSavepoint(SavepointOptions options, JobID jobId, String savepointDirectory) {
    try {
        ActorGateway jobManager = getJobManagerGateway(options);
        logAndSysout("Triggering savepoint for job " + jobId + ".");
        Future<Object> response = jobManager.ask(new TriggerSavepoint(jobId, Option.apply(savepointDirectory)), new FiniteDuration(1, TimeUnit.HOURS));
        Object result;
        try {
            logAndSysout("Waiting for response...");
            result = Await.result(response, FiniteDuration.Inf());
        } catch (Exception e) {
            throw new Exception("Triggering a savepoint for the job " + jobId + " failed.", e);
        }
        if (result instanceof TriggerSavepointSuccess) {
            TriggerSavepointSuccess success = (TriggerSavepointSuccess) result;
            logAndSysout("Savepoint completed. Path: " + success.savepointPath());
            logAndSysout("You can resume your program from this savepoint with the run command.");
            return 0;
        } else if (result instanceof TriggerSavepointFailure) {
            TriggerSavepointFailure failure = (TriggerSavepointFailure) result;
            throw failure.cause();
        } else {
            throw new IllegalStateException("Unknown JobManager response of type " + result.getClass());
        }
    } catch (Throwable t) {
        return handleError(t);
    }
}
Also used : TriggerSavepointFailure(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointFailure) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) TriggerSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint) FiniteDuration(scala.concurrent.duration.FiniteDuration) ProgramInvocationException(org.apache.flink.client.program.ProgramInvocationException) ProgramMissingJobException(org.apache.flink.client.program.ProgramMissingJobException) InvalidProgramException(org.apache.flink.api.common.InvalidProgramException) ProgramParametrizationException(org.apache.flink.client.program.ProgramParametrizationException) FileNotFoundException(java.io.FileNotFoundException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IllegalConfigurationException(org.apache.flink.configuration.IllegalConfigurationException) CliArgsException(org.apache.flink.client.cli.CliArgsException) IOException(java.io.IOException) TriggerSavepointSuccess(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointSuccess)

Example 2 with TriggerSavepointFailure

use of org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointFailure in project flink by apache.

the class CliFrontendSavepointTest method testTriggerSavepointFailure.

@Test
public void testTriggerSavepointFailure() throws Exception {
    replaceStdOutAndStdErr();
    try {
        JobID jobId = new JobID();
        ActorGateway jobManager = mock(ActorGateway.class);
        Promise<Object> triggerResponse = new scala.concurrent.impl.Promise.DefaultPromise<>();
        when(jobManager.ask(Mockito.eq(new TriggerSavepoint(jobId, Option.<String>empty())), any(FiniteDuration.class))).thenReturn(triggerResponse.future());
        Exception testException = new Exception("expectedTestException");
        triggerResponse.success(new TriggerSavepointFailure(jobId, testException));
        CliFrontend frontend = new MockCliFrontend(CliFrontendTestUtils.getConfigDir(), jobManager);
        String[] parameters = { jobId.toString() };
        int returnCode = frontend.savepoint(parameters);
        assertTrue(returnCode != 0);
        verify(jobManager, times(1)).ask(Mockito.eq(new TriggerSavepoint(jobId, Option.<String>empty())), any(FiniteDuration.class));
        assertTrue(buffer.toString().contains("expectedTestException"));
    } finally {
        restoreStdOutAndStdErr();
    }
}
Also used : TriggerSavepointFailure(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointFailure) FiniteDuration(scala.concurrent.duration.FiniteDuration) TriggerSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint) DisposeSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) TriggerSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Aggregations

ActorGateway (org.apache.flink.runtime.instance.ActorGateway)2 TriggerSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint)2 TriggerSavepointFailure (org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointFailure)2 FiniteDuration (scala.concurrent.duration.FiniteDuration)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)1 JobID (org.apache.flink.api.common.JobID)1 CliArgsException (org.apache.flink.client.cli.CliArgsException)1 ProgramInvocationException (org.apache.flink.client.program.ProgramInvocationException)1 ProgramMissingJobException (org.apache.flink.client.program.ProgramMissingJobException)1 ProgramParametrizationException (org.apache.flink.client.program.ProgramParametrizationException)1 IllegalConfigurationException (org.apache.flink.configuration.IllegalConfigurationException)1 DisposeSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint)1 TriggerSavepointSuccess (org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointSuccess)1 Test (org.junit.Test)1