@Override public void onFailure(Call<T> call, Throwable t) { promise.failure(t); } });
@Override public void onResponse(Call<T> call, Response<T> response) { promise.success(response); }
private static ExecutionContext defaultExecutionContext() { return ExecutionContext$.MODULE$.global(); } // --------------------------------------------------------------------------------------------
@Override public GetClusterStatusResponse getClusterStatus() { ActorGateway jmGateway; try { jmGateway = getJobManagerGateway(); Future<Object> future = jmGateway.ask(GetClusterStatus.getInstance(), timeout); Object result = Await.result(future, timeout); if (result instanceof GetClusterStatusResponse) { return (GetClusterStatusResponse) result; } else { throw new RuntimeException("Received the wrong reply " + result + " from cluster."); } } catch (Exception e) { throw new RuntimeException("Couldn't retrieve the cluster status.", e); } }
@Override public Future<Response<T>> adapt(Call<T> call) { Promise<Response<T>> promise = Promise.apply(); call.enqueue(new Callback<T>() { @Override public void onResponse(Call<T> call, Response<T> response) { promise.success(response); } @Override public void onFailure(Call<T> call, Throwable t) { promise.failure(t); } }); return promise.future(); } }
@Override public void shutDownCluster() { LOG.info("Sending shutdown request to the Application Master"); try { final Future<Object> response = Patterns.ask(applicationClient.get(), new YarnMessages.LocalStopYarnSession(ApplicationStatus.SUCCEEDED, "Flink YARN Client requested shutdown"), new Timeout(akkaDuration)); Await.ready(response, akkaDuration); } catch (final Exception e) { LOG.warn("Error while stopping YARN cluster.", e); } }
@Override @SuppressWarnings("unchecked") public Future<Object> ask(Object message, FiniteDuration timeout) { messageArrived = true; if (message.getClass().isAssignableFrom(messageClass)) { return Future$.MODULE$.successful(process((M) message)); } fail("Expected TriggerSavepoint message, got: " + message.getClass()); return null; }
/** * This method is only available if the cluster hasn't been started in detached mode. */ @Override public GetClusterStatusResponse getClusterStatus() { try { final Future<Object> clusterStatusOption = getJobManagerGateway().ask( GetClusterStatus.getInstance(), akkaDuration); return (GetClusterStatusResponse) Await.result(clusterStatusOption, akkaDuration); } catch (Exception e) { throw new RuntimeException("Unable to get ClusterClient status from Application Client", e); } }
@Override public Future<T> adapt(Call<T> call) { Promise<T> promise = Promise.apply(); call.enqueue(new Callback<T>() { @Override public void onResponse(Call<T> call, Response<T> response) { if (response.isSuccessful()) { promise.success(response.body()); } else { promise.failure(new HttpException(response)); } } @Override public void onFailure(Call<T> call, Throwable t) { promise.failure(t); } }); return promise.future(); } }
@Override public void onFailure(Call<T> call, Throwable t) { promise.failure(t); } });
private void stopAfterJob(JobID jobID) { Preconditions.checkNotNull(jobID, "The job id must not be null"); try { Future<Object> replyFuture = getJobManagerGateway().ask( new ShutdownClusterAfterJob(jobID), akkaDuration); Await.ready(replyFuture, akkaDuration); } catch (Exception e) { throw new RuntimeException("Unable to tell application master to stop once the specified job has been finised", e); } }
@Override public Future<Object> ask(Object message, FiniteDuration timeout) { messageArrived = true; if (message instanceof JobManagerMessages.StopJob) { JobManagerMessages.StopJob stopJob = (JobManagerMessages.StopJob) message; Assert.assertEquals(expectedJobID, stopJob.jobID()); return Future$.MODULE$.successful(new JobManagerMessages.StoppingSuccess(stopJob.jobID())); } fail("Expected StopJob message, got: " + message.getClass()); return null; } }
/** * 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 jobManager = getJobManagerGateway(); Object cancelMsg = new JobManagerMessages.CancelJob(jobId); Future<Object> response = jobManager.ask(cancelMsg, timeout); final Object rc = Await.result(response, timeout); if (rc instanceof JobManagerMessages.CancellationSuccess) { // no further action required } else if (rc instanceof JobManagerMessages.CancellationFailure) { throw new Exception("Canceling the job with ID " + jobId + " failed.", ((JobManagerMessages.CancellationFailure) rc).cause()); } else { throw new IllegalStateException("Unexpected response: " + rc); } }
/** * Stops a program on Flink cluster whose job-manager is configured in this client's configuration. * Stopping works only for streaming programs. Be aware, that the program might continue to run for * a while after sending the stop command, because after sources stopped to emit data all operators * need to finish processing. * * @param jobId * the job ID of the streaming program to stop * @throws Exception * If the job ID is invalid (ie, is unknown or refers to a batch job) or if sending the stop signal * failed. That might be due to an I/O problem, ie, the job-manager is unreachable. */ public void stop(final JobID jobId) throws Exception { final ActorGateway jobManager = getJobManagerGateway(); Future<Object> response = jobManager.ask(new JobManagerMessages.StopJob(jobId), timeout); final Object rc = Await.result(response, timeout); if (rc instanceof JobManagerMessages.StoppingSuccess) { // no further action required } else if (rc instanceof JobManagerMessages.StoppingFailure) { throw new Exception("Stopping the job with ID " + jobId + " failed.", ((JobManagerMessages.StoppingFailure) rc).cause()); } else { throw new IllegalStateException("Unexpected response: " + rc); } }
/** * Cancels a job identified by the job id and triggers a savepoint. * @param jobId the job id * @param savepointDirectory directory the savepoint should be written to * @return path where the savepoint is located * @throws Exception In case an error occurred. */ public String cancelWithSavepoint(JobID jobId, @Nullable String savepointDirectory) throws Exception { final ActorGateway jobManager = getJobManagerGateway(); Object cancelMsg = new JobManagerMessages.CancelJobWithSavepoint(jobId, savepointDirectory); Future<Object> response = jobManager.ask(cancelMsg, timeout); final Object rc = Await.result(response, timeout); if (rc instanceof JobManagerMessages.CancellationSuccess) { JobManagerMessages.CancellationSuccess success = (JobManagerMessages.CancellationSuccess) rc; return success.savepointPath(); } else if (rc instanceof JobManagerMessages.CancellationFailure) { throw new Exception("Cancel & savepoint for the job with ID " + jobId + " failed.", ((JobManagerMessages.CancellationFailure) rc).cause()); } else { throw new IllegalStateException("Unexpected response: " + rc); } }
/** * Requests and returns the accumulators for the given job identifier. Accumulators can be * requested while a is running or after it has finished. * @param jobID The job identifier of a job. * @param loader The class loader for deserializing the accumulator results. * @return A Map containing the accumulator's name and its value. */ public Map<String, OptionalFailure<Object>> getAccumulators(JobID jobID, ClassLoader loader) throws Exception { ActorGateway jobManagerGateway = getJobManagerGateway(); Future<Object> response; try { response = jobManagerGateway.ask(new RequestAccumulatorResults(jobID), timeout); } catch (Exception e) { throw new Exception("Failed to query the job manager gateway for accumulators.", e); } Object result = Await.result(response, timeout); if (result instanceof AccumulatorResultsFound) { Map<String, SerializedValue<OptionalFailure<Object>>> serializedAccumulators = ((AccumulatorResultsFound) result).result(); return AccumulatorHelper.deserializeAccumulators(serializedAccumulators, loader); } else if (result instanceof AccumulatorResultsErroneous) { throw ((AccumulatorResultsErroneous) result).cause(); } else { throw new Exception("Failed to fetch accumulators for the job " + jobID + "."); } }
private Status sendMessageToLocalRouters( QakkaMessage message ) { int maxRetries = 5; int retries = 0; while ( retries++ < maxRetries ) { try { Timeout t = new Timeout( 1, TimeUnit.SECONDS ); // ask ClientActor and wait (up to timeout) for response Future<Object> fut = Patterns.ask( actorSystemManager.getClientActor(), message, t ); final QakkaMessage response = (QakkaMessage)Await.result( fut, t.duration() ); if ( response != null && response instanceof QueueAckResponse) { QueueAckResponse qprm = (QueueAckResponse)response; return qprm.getStatus(); } else if ( response != null ) { logger.debug("UNKNOWN RESPONSE sending message, retrying {}", retries ); } else { logger.trace("TIMEOUT sending message, retrying {}", retries ); } } catch ( TimeoutException e ) { logger.trace( "TIMEOUT sending message, retrying " + retries, e ); } catch ( Exception e ) { logger.debug("ERROR sending message, retrying " + retries, e ); } } throw new QakkaRuntimeException( "Error sending message " + message + "after " + retries ); }