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);
}
}
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();
}
}
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();
}
}
Aggregations