Search in sources :

Example 1 with TriggerSavepoint

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

the class CliFrontendSavepointTest method testTriggerSavepointSuccess.

// ------------------------------------------------------------------------
// Trigger savepoint
// ------------------------------------------------------------------------
@Test
public void testTriggerSavepointSuccess() 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());
        String savepointPath = "expectedSavepointPath";
        triggerResponse.success(new TriggerSavepointSuccess(jobId, -1, savepointPath, -1));
        CliFrontend frontend = new MockCliFrontend(CliFrontendTestUtils.getConfigDir(), jobManager);
        String[] parameters = { jobId.toString() };
        int returnCode = frontend.savepoint(parameters);
        assertEquals(0, returnCode);
        verify(jobManager, times(1)).ask(Mockito.eq(new TriggerSavepoint(jobId, Option.<String>empty())), any(FiniteDuration.class));
        assertTrue(buffer.toString().contains("expectedSavepointPath"));
    } finally {
        restoreStdOutAndStdErr();
    }
}
Also used : FiniteDuration(scala.concurrent.duration.FiniteDuration) TriggerSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint) DisposeSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint) TriggerSavepointSuccess(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointSuccess) 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)

Example 2 with TriggerSavepoint

use of org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint 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 3 with TriggerSavepoint

use of org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint 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)

Example 4 with TriggerSavepoint

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

the class CliFrontendSavepointTest method testTriggerSavepointFailureUnknownResponse.

@Test
public void testTriggerSavepointFailureUnknownResponse() 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());
        triggerResponse.success("UNKNOWN RESPONSE");
        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));
        String errMsg = buffer.toString();
        assertTrue(errMsg.contains("IllegalStateException"));
        assertTrue(errMsg.contains("Unknown JobManager response"));
    } finally {
        restoreStdOutAndStdErr();
    }
}
Also used : 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)

Example 5 with TriggerSavepoint

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

the class CliFrontendSavepointTest method testTriggerSavepointCustomTarget.

/**
	 * Tests that a CLI call with a custom savepoint directory target is
	 * forwarded correctly to the JM.
	 */
@Test
public void testTriggerSavepointCustomTarget() throws Exception {
    replaceStdOutAndStdErr();
    try {
        JobID jobId = new JobID();
        Option<String> customTarget = Option.apply("customTargetDirectory");
        ActorGateway jobManager = mock(ActorGateway.class);
        Promise<Object> triggerResponse = new scala.concurrent.impl.Promise.DefaultPromise<>();
        when(jobManager.ask(Mockito.eq(new TriggerSavepoint(jobId, customTarget)), any(FiniteDuration.class))).thenReturn(triggerResponse.future());
        String savepointPath = "expectedSavepointPath";
        triggerResponse.success(new TriggerSavepointSuccess(jobId, -1, savepointPath, -1));
        CliFrontend frontend = new MockCliFrontend(CliFrontendTestUtils.getConfigDir(), jobManager);
        String[] parameters = { jobId.toString(), customTarget.get() };
        int returnCode = frontend.savepoint(parameters);
        assertEquals(0, returnCode);
        verify(jobManager, times(1)).ask(Mockito.eq(new TriggerSavepoint(jobId, customTarget)), any(FiniteDuration.class));
        assertTrue(buffer.toString().contains("expectedSavepointPath"));
    } finally {
        restoreStdOutAndStdErr();
    }
}
Also used : FiniteDuration(scala.concurrent.duration.FiniteDuration) TriggerSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint) DisposeSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint) TriggerSavepointSuccess(org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointSuccess) 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)8 TriggerSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint)8 FiniteDuration (scala.concurrent.duration.FiniteDuration)8 Test (org.junit.Test)7 TriggerSavepointSuccess (org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepointSuccess)6 JobID (org.apache.flink.api.common.JobID)5 DisposeSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint)5 ActorRef (akka.actor.ActorRef)3 ActorSystem (akka.actor.ActorSystem)3 File (java.io.File)3 Configuration (org.apache.flink.configuration.Configuration)3 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)3 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)3 WaitForAllVerticesToBeRunning (org.apache.flink.runtime.testingUtils.TestingJobManagerMessages.WaitForAllVerticesToBeRunning)3 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)2 JobSnapshottingSettings (org.apache.flink.runtime.jobgraph.tasks.JobSnapshottingSettings)2 StandaloneLeaderRetrievalService (org.apache.flink.runtime.leaderretrieval.StandaloneLeaderRetrievalService)2 JobManagerMessages (org.apache.flink.runtime.messages.JobManagerMessages)2 CancelJob (org.apache.flink.runtime.messages.JobManagerMessages.CancelJob)2 SubmitJob (org.apache.flink.runtime.messages.JobManagerMessages.SubmitJob)2