Search in sources :

Example 1 with DisposeSavepointFailure

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

the class CliFrontend method disposeSavepoint.

/**
	 * Sends a {@link org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint}
	 * message to the job manager.
	 */
private int disposeSavepoint(SavepointOptions options) {
    try {
        String savepointPath = options.getSavepointPath();
        if (savepointPath == null) {
            throw new IllegalArgumentException("Missing required argument: savepoint path. " + "Usage: bin/flink savepoint -d <savepoint-path>");
        }
        String jarFile = options.getJarFilePath();
        ActorGateway jobManager = getJobManagerGateway(options);
        List<BlobKey> blobKeys = null;
        if (jarFile != null) {
            logAndSysout("Disposing savepoint '" + savepointPath + "' with JAR " + jarFile + ".");
            List<File> libs = null;
            try {
                libs = PackagedProgram.extractContainedLibraries(new File(jarFile).toURI().toURL());
                if (!libs.isEmpty()) {
                    List<Path> libPaths = new ArrayList<>(libs.size());
                    for (File f : libs) {
                        libPaths.add(new Path(f.toURI()));
                    }
                    logAndSysout("Uploading JAR files.");
                    LOG.debug("JAR files: " + libPaths);
                    blobKeys = BlobClient.uploadJarFiles(jobManager, clientTimeout, config, libPaths);
                    LOG.debug("Blob keys: " + blobKeys.toString());
                }
            } finally {
                if (libs != null) {
                    PackagedProgram.deleteExtractedLibraries(libs);
                }
            }
        } else {
            logAndSysout("Disposing savepoint '" + savepointPath + "'.");
        }
        Object msg = new DisposeSavepoint(savepointPath);
        Future<Object> response = jobManager.ask(msg, clientTimeout);
        Object result;
        try {
            logAndSysout("Waiting for response...");
            result = Await.result(response, clientTimeout);
        } catch (Exception e) {
            throw new Exception("Disposing the savepoint with path" + savepointPath + " failed.", e);
        }
        if (result.getClass() == JobManagerMessages.getDisposeSavepointSuccess().getClass()) {
            logAndSysout("Savepoint '" + savepointPath + "' disposed.");
            return 0;
        } else if (result instanceof DisposeSavepointFailure) {
            DisposeSavepointFailure failure = (DisposeSavepointFailure) result;
            if (failure.cause() instanceof ClassNotFoundException) {
                throw new ClassNotFoundException("Savepoint disposal failed, because of a " + "missing class. This is most likely caused by a custom state " + "instance, which cannot be disposed without the user code class " + "loader. Please provide the program jar with which you have created " + "the savepoint via -j <JAR> for disposal.", failure.cause().getCause());
            } else {
                throw failure.cause();
            }
        } else {
            throw new IllegalStateException("Unknown JobManager response of type " + result.getClass());
        }
    } catch (Throwable t) {
        return handleError(t);
    }
}
Also used : Path(org.apache.flink.core.fs.Path) ArrayList(java.util.ArrayList) 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) DisposeSavepointFailure(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepointFailure) BlobKey(org.apache.flink.runtime.blob.BlobKey) DisposeSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) File(java.io.File)

Example 2 with DisposeSavepointFailure

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

Example 3 with DisposeSavepointFailure

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

the class CliFrontendSavepointTest method testDisposeClassNotFoundException.

/**
	 * Tests that a disposal failure due a  ClassNotFoundException triggers a
	 * note about the JAR option.
	 */
@Test
public void testDisposeClassNotFoundException() throws Exception {
    replaceStdOutAndStdErr();
    try {
        Future<Object> classNotFoundFailure = Futures.<Object>successful(new DisposeSavepointFailure(new ClassNotFoundException("Test exception")));
        ActorGateway jobManager = mock(ActorGateway.class);
        when(jobManager.ask(any(DisposeSavepoint.class), any(FiniteDuration.class))).thenReturn(classNotFoundFailure);
        CliFrontend frontend = new MockCliFrontend(CliFrontendTestUtils.getConfigDir(), jobManager);
        String[] parameters = { "-d", "any-path" };
        int returnCode = frontend.savepoint(parameters);
        assertTrue(returnCode != 0);
        String out = buffer.toString();
        assertTrue(out.contains("Please provide the program jar with which you have created " + "the savepoint via -j <JAR> for disposal"));
    } finally {
        restoreStdOutAndStdErr();
    }
}
Also used : DisposeSavepoint(org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint) ActorGateway(org.apache.flink.runtime.instance.ActorGateway) 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) Test(org.junit.Test)

Aggregations

ActorGateway (org.apache.flink.runtime.instance.ActorGateway)3 DisposeSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepoint)3 DisposeSavepointFailure (org.apache.flink.runtime.messages.JobManagerMessages.DisposeSavepointFailure)3 TriggerSavepoint (org.apache.flink.runtime.messages.JobManagerMessages.TriggerSavepoint)2 Test (org.junit.Test)2 FiniteDuration (scala.concurrent.duration.FiniteDuration)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 ArrayList (java.util.ArrayList)1 InvalidProgramException (org.apache.flink.api.common.InvalidProgramException)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 Path (org.apache.flink.core.fs.Path)1 BlobKey (org.apache.flink.runtime.blob.BlobKey)1