Search in sources :

Example 46 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class ResourceManagerJobMasterTest method createAndStartResourceManagerService.

private void createAndStartResourceManagerService() throws Exception {
    final TestingLeaderElectionService leaderElectionService = new TestingLeaderElectionService();
    resourceManagerService = TestingResourceManagerService.newBuilder().setRpcService(rpcService).setJmLeaderRetrieverFunction(requestedJobId -> {
        if (requestedJobId.equals(jobId)) {
            return jobMasterLeaderRetrievalService;
        } else {
            throw new FlinkRuntimeException(String.format("Unknown job id %s", jobId));
        }
    }).setRmLeaderElectionService(leaderElectionService).build();
    resourceManagerService.start();
    resourceManagerService.isLeader(UUID.randomUUID());
    leaderElectionService.getConfirmationFuture().thenRun(() -> {
        resourceManagerGateway = resourceManagerService.getResourceManagerGateway().orElseThrow(() -> new AssertionError("RM not available after confirming leadership."));
    }).get(TIMEOUT.getSize(), TIMEOUT.getUnit());
}
Also used : FencingTokenException(org.apache.flink.runtime.rpc.exceptions.FencingTokenException) RegistrationResponse(org.apache.flink.runtime.registration.RegistrationResponse) TestingRpcService(org.apache.flink.runtime.rpc.TestingRpcService) ExceptionUtils(org.apache.flink.util.ExceptionUtils) CompletableFuture(java.util.concurrent.CompletableFuture) TestingJobMasterGateway(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGateway) SettableLeaderRetrievalService(org.apache.flink.runtime.leaderretrieval.SettableLeaderRetrievalService) JobMaster(org.apache.flink.runtime.jobmaster.JobMaster) ResourceManagerException(org.apache.flink.runtime.resourcemanager.exceptions.ResourceManagerException) After(org.junit.After) TestLogger(org.apache.flink.util.TestLogger) TestingJobMasterGatewayBuilder(org.apache.flink.runtime.jobmaster.utils.TestingJobMasterGatewayBuilder) Assert.fail(org.junit.Assert.fail) JobMasterRegistrationSuccess(org.apache.flink.runtime.jobmaster.JobMasterRegistrationSuccess) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) Before(org.junit.Before) HighAvailabilityServices(org.apache.flink.runtime.highavailability.HighAvailabilityServices) TestingLeaderElectionService(org.apache.flink.runtime.leaderelection.TestingLeaderElectionService) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) JobMasterId(org.apache.flink.runtime.jobmaster.JobMasterId) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) UUID(java.util.UUID) RpcUtils(org.apache.flink.runtime.rpc.RpcUtils) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JobID(org.apache.flink.api.common.JobID) Time(org.apache.flink.api.common.time.Time) TestingLeaderElectionService(org.apache.flink.runtime.leaderelection.TestingLeaderElectionService) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException)

Example 47 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class RestServerEndpoint method checkAllEndpointsAndHandlersAreUnique.

private static void checkAllEndpointsAndHandlersAreUnique(final List<Tuple2<RestHandlerSpecification, ChannelInboundHandler>> handlers) {
    // check for all handlers that
    // 1) the instance is only registered once
    // 2) only 1 handler is registered for each endpoint (defined by (version, method, url))
    // technically the first check is redundant since a duplicate instance also returns the same
    // headers which
    // should fail the second check, but we get a better error message
    final Set<String> uniqueEndpoints = new HashSet<>();
    final Set<ChannelInboundHandler> distinctHandlers = Collections.newSetFromMap(new IdentityHashMap<>());
    for (Tuple2<RestHandlerSpecification, ChannelInboundHandler> handler : handlers) {
        boolean isNewHandler = distinctHandlers.add(handler.f1);
        if (!isNewHandler) {
            throw new FlinkRuntimeException("Duplicate REST handler instance found." + " Please ensure each instance is registered only once.");
        }
        final RestHandlerSpecification headers = handler.f0;
        for (RestAPIVersion supportedAPIVersion : headers.getSupportedAPIVersions()) {
            final String parameterizedEndpoint = supportedAPIVersion.toString() + headers.getHttpMethod() + headers.getTargetRestEndpointURL();
            // normalize path parameters; distinct path parameters still clash at runtime
            final String normalizedEndpoint = parameterizedEndpoint.replaceAll(":[\\w-]+", ":param");
            boolean isNewEndpoint = uniqueEndpoints.add(normalizedEndpoint);
            if (!isNewEndpoint) {
                throw new FlinkRuntimeException(String.format("REST handler registration overlaps with another registration for: version=%s, method=%s, url=%s.", supportedAPIVersion, headers.getHttpMethod(), headers.getTargetRestEndpointURL()));
            }
        }
    }
}
Also used : RestAPIVersion(org.apache.flink.runtime.rest.versioning.RestAPIVersion) RestHandlerSpecification(org.apache.flink.runtime.rest.handler.RestHandlerSpecification) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) ChannelInboundHandler(org.apache.flink.shaded.netty4.io.netty.channel.ChannelInboundHandler) HashSet(java.util.HashSet)

Example 48 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class SerializedJobExecutionResultTest method testSerialization.

@Test
public void testSerialization() throws Exception {
    final ClassLoader classloader = getClass().getClassLoader();
    JobID origJobId = new JobID();
    long origTime = 65927436589267L;
    Map<String, SerializedValue<OptionalFailure<Object>>> origMap = new HashMap<>();
    origMap.put("name1", new SerializedValue<>(OptionalFailure.of(723L)));
    origMap.put("name2", new SerializedValue<>(OptionalFailure.of("peter")));
    origMap.put("name3", new SerializedValue<>(OptionalFailure.ofFailure(new ExpectedTestException())));
    SerializedJobExecutionResult result = new SerializedJobExecutionResult(origJobId, origTime, origMap);
    // serialize and deserialize the object
    SerializedJobExecutionResult cloned = CommonTestUtils.createCopySerializable(result);
    assertEquals(origJobId, cloned.getJobId());
    assertEquals(origTime, cloned.getNetRuntime());
    assertEquals(origTime, cloned.getNetRuntime(TimeUnit.MILLISECONDS));
    assertEquals(origMap, cloned.getSerializedAccumulatorResults());
    // convert to deserialized result
    JobExecutionResult jResult = result.toJobExecutionResult(classloader);
    JobExecutionResult jResultCopied = result.toJobExecutionResult(classloader);
    assertEquals(origJobId, jResult.getJobID());
    assertEquals(origJobId, jResultCopied.getJobID());
    assertEquals(origTime, jResult.getNetRuntime());
    assertEquals(origTime, jResult.getNetRuntime(TimeUnit.MILLISECONDS));
    assertEquals(origTime, jResultCopied.getNetRuntime());
    assertEquals(origTime, jResultCopied.getNetRuntime(TimeUnit.MILLISECONDS));
    for (Map.Entry<String, SerializedValue<OptionalFailure<Object>>> entry : origMap.entrySet()) {
        String name = entry.getKey();
        OptionalFailure<Object> value = entry.getValue().deserializeValue(classloader);
        if (value.isFailure()) {
            try {
                jResult.getAccumulatorResult(name);
                fail("expected failure");
            } catch (FlinkRuntimeException ex) {
                assertTrue(ExceptionUtils.findThrowable(ex, ExpectedTestException.class).isPresent());
            }
            try {
                jResultCopied.getAccumulatorResult(name);
                fail("expected failure");
            } catch (FlinkRuntimeException ex) {
                assertTrue(ExceptionUtils.findThrowable(ex, ExpectedTestException.class).isPresent());
            }
        } else {
            assertEquals(value.get(), jResult.getAccumulatorResult(name));
            assertEquals(value.get(), jResultCopied.getAccumulatorResult(name));
        }
    }
}
Also used : ExpectedTestException(org.apache.flink.runtime.operators.testutils.ExpectedTestException) HashMap(java.util.HashMap) SerializedValue(org.apache.flink.util.SerializedValue) JobExecutionResult(org.apache.flink.api.common.JobExecutionResult) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) HashMap(java.util.HashMap) Map(java.util.Map) JobID(org.apache.flink.api.common.JobID) Test(org.junit.Test)

Example 49 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class SubtaskExecutionAttemptAccumulatorsHandlerTest method testHandleRequest.

@Test
public void testHandleRequest() throws Exception {
    // Instance the handler.
    final RestHandlerConfiguration restHandlerConfiguration = RestHandlerConfiguration.fromConfiguration(new Configuration());
    final SubtaskExecutionAttemptAccumulatorsHandler handler = new SubtaskExecutionAttemptAccumulatorsHandler(() -> null, Time.milliseconds(100L), Collections.emptyMap(), SubtaskExecutionAttemptAccumulatorsHeaders.getInstance(), new DefaultExecutionGraphCache(restHandlerConfiguration.getTimeout(), Time.milliseconds(restHandlerConfiguration.getRefreshInterval())), TestingUtils.defaultExecutor());
    // Instance a empty request.
    final HandlerRequest<EmptyRequestBody> request = HandlerRequest.create(EmptyRequestBody.getInstance(), new SubtaskAttemptMessageParameters());
    final Map<String, OptionalFailure<Accumulator<?, ?>>> userAccumulators = new HashMap<>(3);
    userAccumulators.put("IntCounter", OptionalFailure.of(new IntCounter(10)));
    userAccumulators.put("LongCounter", OptionalFailure.of(new LongCounter(100L)));
    userAccumulators.put("Failure", OptionalFailure.ofFailure(new FlinkRuntimeException("Test")));
    // Instance the expected result.
    final StringifiedAccumulatorResult[] accumulatorResults = StringifiedAccumulatorResult.stringifyAccumulatorResults(userAccumulators);
    final int attemptNum = 1;
    final int subtaskIndex = 2;
    // Instance the tested execution.
    final ArchivedExecution execution = new ArchivedExecution(accumulatorResults, null, new ExecutionAttemptID(), attemptNum, ExecutionState.FINISHED, null, null, null, subtaskIndex, new long[ExecutionState.values().length]);
    // Invoke tested method.
    final SubtaskExecutionAttemptAccumulatorsInfo accumulatorsInfo = handler.handleRequest(request, execution);
    final ArrayList<UserAccumulator> userAccumulatorList = new ArrayList<>(userAccumulators.size());
    for (StringifiedAccumulatorResult accumulatorResult : accumulatorResults) {
        userAccumulatorList.add(new UserAccumulator(accumulatorResult.getName(), accumulatorResult.getType(), accumulatorResult.getValue()));
    }
    final SubtaskExecutionAttemptAccumulatorsInfo expected = new SubtaskExecutionAttemptAccumulatorsInfo(subtaskIndex, attemptNum, execution.getAttemptId().toString(), userAccumulatorList);
    // Verify.
    assertEquals(expected, accumulatorsInfo);
}
Also used : RestHandlerConfiguration(org.apache.flink.runtime.rest.handler.RestHandlerConfiguration) ExecutionAttemptID(org.apache.flink.runtime.executiongraph.ExecutionAttemptID) Configuration(org.apache.flink.configuration.Configuration) RestHandlerConfiguration(org.apache.flink.runtime.rest.handler.RestHandlerConfiguration) HashMap(java.util.HashMap) SubtaskAttemptMessageParameters(org.apache.flink.runtime.rest.messages.job.SubtaskAttemptMessageParameters) StringifiedAccumulatorResult(org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult) ArrayList(java.util.ArrayList) ArchivedExecution(org.apache.flink.runtime.executiongraph.ArchivedExecution) SubtaskExecutionAttemptAccumulatorsInfo(org.apache.flink.runtime.rest.messages.job.SubtaskExecutionAttemptAccumulatorsInfo) EmptyRequestBody(org.apache.flink.runtime.rest.messages.EmptyRequestBody) LongCounter(org.apache.flink.api.common.accumulators.LongCounter) UserAccumulator(org.apache.flink.runtime.rest.messages.job.UserAccumulator) FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException) DefaultExecutionGraphCache(org.apache.flink.runtime.rest.handler.legacy.DefaultExecutionGraphCache) OptionalFailure(org.apache.flink.util.OptionalFailure) IntCounter(org.apache.flink.api.common.accumulators.IntCounter) Test(org.junit.Test)

Example 50 with FlinkRuntimeException

use of org.apache.flink.util.FlinkRuntimeException in project flink by apache.

the class CheckpointFailureManager method checkFailureAgainstCounter.

private void checkFailureAgainstCounter(CheckpointException exception, long checkpointId, Consumer<FlinkRuntimeException> errorHandler) {
    if (checkpointId == UNKNOWN_CHECKPOINT_ID || checkpointId > lastSucceededCheckpointId) {
        checkFailureCounter(exception, checkpointId);
        if (continuousFailureCounter.get() > tolerableCpFailureNumber) {
            clearCount();
            errorHandler.accept(new FlinkRuntimeException(EXCEEDED_CHECKPOINT_TOLERABLE_FAILURE_MESSAGE));
        }
    }
}
Also used : FlinkRuntimeException(org.apache.flink.util.FlinkRuntimeException)

Aggregations

FlinkRuntimeException (org.apache.flink.util.FlinkRuntimeException)78 IOException (java.io.IOException)28 Test (org.junit.Test)13 JobID (org.apache.flink.api.common.JobID)10 HashMap (java.util.HashMap)8 ArrayList (java.util.ArrayList)7 CompletableFuture (java.util.concurrent.CompletableFuture)7 ExecutionException (java.util.concurrent.ExecutionException)7 Nonnull (javax.annotation.Nonnull)7 Configuration (org.apache.flink.configuration.Configuration)6 Collectors (java.util.stream.Collectors)5 JobGraph (org.apache.flink.runtime.jobgraph.JobGraph)5 JobResultStore (org.apache.flink.runtime.highavailability.JobResultStore)4 RocksDBException (org.rocksdb.RocksDBException)4 List (java.util.List)3 Map (java.util.Map)3 CheckpointMetrics (org.apache.flink.runtime.checkpoint.CheckpointMetrics)3 TaskStateSnapshot (org.apache.flink.runtime.checkpoint.TaskStateSnapshot)3 ExecutionAttemptID (org.apache.flink.runtime.executiongraph.ExecutionAttemptID)3 JobResult (org.apache.flink.runtime.jobmaster.JobResult)3