Search in sources :

Example 56 with ActorGateway

use of org.apache.flink.runtime.instance.ActorGateway in project flink by apache.

the class ClusterClient method runDetached.

/**
	 * Submits a JobGraph detached.
	 * @param jobGraph The JobGraph
	 * @param classLoader User code class loader to deserialize the results and errors (may contain custom classes).
	 * @return JobSubmissionResult
	 * @throws ProgramInvocationException
	 */
public JobSubmissionResult runDetached(JobGraph jobGraph, ClassLoader classLoader) throws ProgramInvocationException {
    waitForClusterToBeReady();
    final ActorGateway jobManagerGateway;
    try {
        jobManagerGateway = getJobManagerGateway();
    } catch (Exception e) {
        throw new ProgramInvocationException("Failed to retrieve the JobManager gateway.", e);
    }
    try {
        logAndSysout("Submitting Job with JobID: " + jobGraph.getJobID() + ". Returning after job submission.");
        JobClient.submitJobDetached(jobManagerGateway, flinkConfig, jobGraph, timeout, classLoader);
        return new JobSubmissionResult(jobGraph.getJobID());
    } catch (JobExecutionException e) {
        throw new ProgramInvocationException("The program execution failed: " + e.getMessage(), e);
    }
}
Also used : JobSubmissionResult(org.apache.flink.api.common.JobSubmissionResult) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) JobRetrievalException(org.apache.flink.runtime.client.JobRetrievalException) URISyntaxException(java.net.URISyntaxException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) IOException(java.io.IOException) CompilerException(org.apache.flink.optimizer.CompilerException)

Example 57 with ActorGateway

use of org.apache.flink.runtime.instance.ActorGateway in project flink by apache.

the class ClusterClient method cancel.

/**
	 * Cancels a job identified by the job id.
	 * @param jobId the job id
	 * @throws Exception In case an error occurred.
	 */
public void cancel(JobID jobId) throws Exception {
    final ActorGateway jobManagerGateway = getJobManagerGateway();
    final Future<Object> response;
    try {
        response = jobManagerGateway.ask(new JobManagerMessages.CancelJob(jobId), timeout);
    } catch (final Exception e) {
        throw new ProgramInvocationException("Failed to query the job manager gateway.", e);
    }
    final Object result = Await.result(response, timeout);
    if (result instanceof JobManagerMessages.CancellationSuccess) {
        logAndSysout("Job cancellation with ID " + jobId + " succeeded.");
    } else if (result instanceof JobManagerMessages.CancellationFailure) {
        final Throwable t = ((JobManagerMessages.CancellationFailure) result).cause();
        logAndSysout("Job cancellation with ID " + jobId + " failed because of " + t.getMessage());
        throw new Exception("Failed to cancel the job with id " + jobId, t);
    } else {
        throw new Exception("Unknown message received while cancelling: " + result.getClass().getName());
    }
}
Also used : ActorGateway(org.apache.flink.runtime.instance.ActorGateway) JobManagerMessages(org.apache.flink.runtime.messages.JobManagerMessages) JobRetrievalException(org.apache.flink.runtime.client.JobRetrievalException) URISyntaxException(java.net.URISyntaxException) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) IOException(java.io.IOException) CompilerException(org.apache.flink.optimizer.CompilerException)

Example 58 with ActorGateway

use of org.apache.flink.runtime.instance.ActorGateway 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 59 with ActorGateway

use of org.apache.flink.runtime.instance.ActorGateway in project flink by apache.

the class CliFrontendSavepointTest method testDisposeSavepointSuccess.

// ------------------------------------------------------------------------
// Dispose savepoint
// ------------------------------------------------------------------------
@Test
public void testDisposeSavepointSuccess() throws Exception {
    replaceStdOutAndStdErr();
    try {
        String savepointPath = "expectedSavepointPath";
        ActorGateway jobManager = mock(ActorGateway.class);
        Promise<Object> triggerResponse = new scala.concurrent.impl.Promise.DefaultPromise<>();
        when(jobManager.ask(Mockito.eq(new DisposeSavepoint(savepointPath)), any(FiniteDuration.class))).thenReturn(triggerResponse.future());
        triggerResponse.success(getDisposeSavepointSuccess());
        CliFrontend frontend = new MockCliFrontend(CliFrontendTestUtils.getConfigDir(), jobManager);
        String[] parameters = { "-d", savepointPath };
        int returnCode = frontend.savepoint(parameters);
        assertEquals(0, returnCode);
        verify(jobManager, times(1)).ask(Mockito.eq(new DisposeSavepoint(savepointPath)), any(FiniteDuration.class));
        String outMsg = buffer.toString();
        assertTrue(outMsg.contains(savepointPath));
        assertTrue(outMsg.contains("disposed"));
    } 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) DisposeSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) Test(org.junit.Test)

Example 60 with ActorGateway

use of org.apache.flink.runtime.instance.ActorGateway in project flink by apache.

the class CliFrontendSavepointTest method testDisposeSavepointFailure.

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

Aggregations

ActorGateway (org.apache.flink.runtime.instance.ActorGateway)102 Test (org.junit.Test)81 Configuration (org.apache.flink.configuration.Configuration)44 AkkaActorGateway (org.apache.flink.runtime.instance.AkkaActorGateway)41 FiniteDuration (scala.concurrent.duration.FiniteDuration)37 JobID (org.apache.flink.api.common.JobID)36 JavaTestKit (akka.testkit.JavaTestKit)34 ActorRef (akka.actor.ActorRef)30 IOException (java.io.IOException)26 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)25 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)22 JobManagerMessages (org.apache.flink.runtime.messages.JobManagerMessages)22 JobVertex (org.apache.flink.runtime.jobgraph.JobVertex)20 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)17 TaskManagerServicesConfiguration (org.apache.flink.runtime.taskexecutor.TaskManagerServicesConfiguration)16 SubmitJob (org.apache.flink.runtime.messages.JobManagerMessages.SubmitJob)15 ExecutionConfig (org.apache.flink.api.common.ExecutionConfig)14 TaskDeploymentDescriptor (org.apache.flink.runtime.deployment.TaskDeploymentDescriptor)14 TriggerSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint)13 SubmitTask (org.apache.flink.runtime.messages.TaskMessages.SubmitTask)13