Java Code Examples for org.apache.flink.util.OptionalFailure#isFailure()

The following examples show how to use org.apache.flink.util.OptionalFailure#isFailure() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AccumulatorHelper.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Merge two collections of accumulators. The second will be merged into the
 * first.
 *
 * @param target
 *            The collection of accumulators that will be updated
 * @param toMerge
 *            The collection of accumulators that will be merged into the
 *            other
 */
public static void mergeInto(Map<String, OptionalFailure<Accumulator<?, ?>>> target, Map<String, Accumulator<?, ?>> toMerge) {
	for (Map.Entry<String, Accumulator<?, ?>> otherEntry : toMerge.entrySet()) {
		OptionalFailure<Accumulator<?, ?>> ownAccumulator = target.get(otherEntry.getKey());
		if (ownAccumulator == null) {
			// Create initial counter (copy!)
			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> otherEntry.getValue().clone()));
		}
		else if (ownAccumulator.isFailure()) {
			continue;
		}
		else {
			Accumulator<?, ?> accumulator = ownAccumulator.getUnchecked();
			// Both should have the same type
			compareAccumulatorTypes(otherEntry.getKey(),
				accumulator.getClass(), otherEntry.getValue().getClass());
			// Merge target counter with other counter

			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> mergeSingle(accumulator, otherEntry.getValue().clone())));
		}
	}
}
 
Example 2
Source File: StringifiedAccumulatorResult.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private static StringifiedAccumulatorResult stringifyAccumulatorResult(
		String name,
		@Nullable OptionalFailure<Accumulator<?, ?>> accumulator) {
	if (accumulator == null) {
		return new StringifiedAccumulatorResult(name, "null", "null");
	}
	else if (accumulator.isFailure()) {
		return new StringifiedAccumulatorResult(
			name,
			"null",
			ExceptionUtils.stringifyException(accumulator.getFailureCause()));
	}
	else {
		Object localValue;
		String simpleName = "null";
		try {
			simpleName = accumulator.getUnchecked().getClass().getSimpleName();
			localValue = accumulator.getUnchecked().getLocalValue();
		}
		catch (RuntimeException exception) {
			LOG.error("Failed to stringify accumulator [" + name + "]", exception);
			localValue = ExceptionUtils.stringifyException(exception);
		}
		return new StringifiedAccumulatorResult(name, simpleName, localValue != null ? localValue.toString() : "null");
	}
}
 
Example 3
Source File: RestClusterClientTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<AsynchronousOperationInfo>> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, SavepointDisposalStatusMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final TriggerId actualTriggerId = request.getPathParameter(TriggerIdPathParameter.class);

	if (actualTriggerId.equals(triggerId)) {
		final OptionalFailure<AsynchronousOperationInfo> nextResponse = responses.poll();

		if (nextResponse != null) {
			if (nextResponse.isFailure()) {
				throw new RestHandlerException("Failure", HttpResponseStatus.BAD_REQUEST, nextResponse.getFailureCause());
			} else {
				return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(nextResponse.getUnchecked()));
			}
		} else {
			throw new AssertionError();
		}
	} else {
		throw new AssertionError();
	}
}
 
Example 4
Source File: AccumulatorHelper.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Merge two collections of accumulators. The second will be merged into the
 * first.
 *
 * @param target
 *            The collection of accumulators that will be updated
 * @param toMerge
 *            The collection of accumulators that will be merged into the
 *            other
 */
public static void mergeInto(Map<String, OptionalFailure<Accumulator<?, ?>>> target, Map<String, Accumulator<?, ?>> toMerge) {
	for (Map.Entry<String, Accumulator<?, ?>> otherEntry : toMerge.entrySet()) {
		OptionalFailure<Accumulator<?, ?>> ownAccumulator = target.get(otherEntry.getKey());
		if (ownAccumulator == null) {
			// Create initial counter (copy!)
			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> otherEntry.getValue().clone()));
		}
		else if (ownAccumulator.isFailure()) {
			continue;
		}
		else {
			Accumulator<?, ?> accumulator = ownAccumulator.getUnchecked();
			// Both should have the same type
			compareAccumulatorTypes(otherEntry.getKey(),
				accumulator.getClass(), otherEntry.getValue().getClass());
			// Merge target counter with other counter

			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> mergeSingle(accumulator, otherEntry.getValue().clone())));
		}
	}
}
 
Example 5
Source File: StringifiedAccumulatorResult.java    From flink with Apache License 2.0 6 votes vote down vote up
private static StringifiedAccumulatorResult stringifyAccumulatorResult(
		String name,
		@Nullable OptionalFailure<Accumulator<?, ?>> accumulator) {
	if (accumulator == null) {
		return new StringifiedAccumulatorResult(name, "null", "null");
	}
	else if (accumulator.isFailure()) {
		return new StringifiedAccumulatorResult(
			name,
			"null",
			ExceptionUtils.stringifyException(accumulator.getFailureCause()));
	}
	else {
		Object localValue;
		String simpleName = "null";
		try {
			simpleName = accumulator.getUnchecked().getClass().getSimpleName();
			localValue = accumulator.getUnchecked().getLocalValue();
		}
		catch (RuntimeException exception) {
			LOG.error("Failed to stringify accumulator [" + name + "]", exception);
			localValue = ExceptionUtils.stringifyException(exception);
		}
		return new StringifiedAccumulatorResult(name, simpleName, localValue != null ? localValue.toString() : "null");
	}
}
 
Example 6
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<AsynchronousOperationInfo>> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, SavepointDisposalStatusMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final TriggerId actualTriggerId = request.getPathParameter(TriggerIdPathParameter.class);

	if (actualTriggerId.equals(triggerId)) {
		final OptionalFailure<AsynchronousOperationInfo> nextResponse = responses.poll();

		if (nextResponse != null) {
			if (nextResponse.isFailure()) {
				throw new RestHandlerException("Failure", HttpResponseStatus.BAD_REQUEST, nextResponse.getFailureCause());
			} else {
				return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(nextResponse.getUnchecked()));
			}
		} else {
			throw new AssertionError();
		}
	} else {
		throw new AssertionError();
	}
}
 
Example 7
Source File: AccumulatorHelper.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Merge two collections of accumulators. The second will be merged into the
 * first.
 *
 * @param target
 *            The collection of accumulators that will be updated
 * @param toMerge
 *            The collection of accumulators that will be merged into the
 *            other
 */
public static void mergeInto(Map<String, OptionalFailure<Accumulator<?, ?>>> target, Map<String, Accumulator<?, ?>> toMerge) {
	for (Map.Entry<String, Accumulator<?, ?>> otherEntry : toMerge.entrySet()) {
		OptionalFailure<Accumulator<?, ?>> ownAccumulator = target.get(otherEntry.getKey());
		if (ownAccumulator == null) {
			// Create initial counter (copy!)
			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> otherEntry.getValue().clone()));
		}
		else if (ownAccumulator.isFailure()) {
			continue;
		}
		else {
			Accumulator<?, ?> accumulator = ownAccumulator.getUnchecked();
			// Both should have the same type
			compareAccumulatorTypes(otherEntry.getKey(),
				accumulator.getClass(), otherEntry.getValue().getClass());
			// Merge target counter with other counter

			target.put(
				otherEntry.getKey(),
				wrapUnchecked(otherEntry.getKey(), () -> mergeSingle(accumulator, otherEntry.getValue().clone())));
		}
	}
}
 
Example 8
Source File: StringifiedAccumulatorResult.java    From flink with Apache License 2.0 6 votes vote down vote up
private static StringifiedAccumulatorResult stringifyAccumulatorResult(
		String name,
		@Nullable OptionalFailure<Accumulator<?, ?>> accumulator) {
	if (accumulator == null) {
		return new StringifiedAccumulatorResult(name, "null", "null");
	}
	else if (accumulator.isFailure()) {
		return new StringifiedAccumulatorResult(
			name,
			"null",
			ExceptionUtils.stringifyException(accumulator.getFailureCause()));
	}
	else {
		Object localValue;
		String simpleName = "null";
		try {
			simpleName = accumulator.getUnchecked().getClass().getSimpleName();
			localValue = accumulator.getUnchecked().getLocalValue();
		}
		catch (RuntimeException exception) {
			LOG.error("Failed to stringify accumulator [" + name + "]", exception);
			localValue = ExceptionUtils.stringifyException(exception);
		}
		return new StringifiedAccumulatorResult(name, simpleName, localValue != null ? localValue.toString() : "null");
	}
}
 
Example 9
Source File: RestClusterClientTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected CompletableFuture<AsynchronousOperationResult<AsynchronousOperationInfo>> handleRequest(@Nonnull HandlerRequest<EmptyRequestBody, SavepointDisposalStatusMessageParameters> request, @Nonnull DispatcherGateway gateway) throws RestHandlerException {
	final TriggerId actualTriggerId = request.getPathParameter(TriggerIdPathParameter.class);

	if (actualTriggerId.equals(triggerId)) {
		final OptionalFailure<AsynchronousOperationInfo> nextResponse = responses.poll();

		if (nextResponse != null) {
			if (nextResponse.isFailure()) {
				throw new RestHandlerException("Failure", HttpResponseStatus.BAD_REQUEST, nextResponse.getFailureCause());
			} else {
				return CompletableFuture.completedFuture(AsynchronousOperationResult.completed(nextResponse.getUnchecked()));
			}
		} else {
			throw new AssertionError();
		}
	} else {
		throw new AssertionError();
	}
}
 
Example 10
Source File: ExecutionGraph.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
private static SerializedValue<OptionalFailure<Object>> serializeAccumulator(String name, OptionalFailure<Accumulator<?, ?>> accumulator) {
	try {
		if (accumulator.isFailure()) {
			return new SerializedValue<>(OptionalFailure.ofFailure(accumulator.getFailureCause()));
		}
		return new SerializedValue<>(OptionalFailure.of(accumulator.getUnchecked().getLocalValue()));
	} catch (IOException ioe) {
		LOG.error("Could not serialize accumulator " + name + '.', ioe);
		try {
			return new SerializedValue<>(OptionalFailure.ofFailure(ioe));
		} catch (IOException e) {
			throw new RuntimeException("It should never happen that we cannot serialize the accumulator serialization exception.", e);
		}
	}
}
 
Example 11
Source File: ExecutionGraph.java    From flink with Apache License 2.0 5 votes vote down vote up
private static SerializedValue<OptionalFailure<Object>> serializeAccumulator(String name, OptionalFailure<Accumulator<?, ?>> accumulator) {
	try {
		if (accumulator.isFailure()) {
			return new SerializedValue<>(OptionalFailure.ofFailure(accumulator.getFailureCause()));
		}
		return new SerializedValue<>(OptionalFailure.of(accumulator.getUnchecked().getLocalValue()));
	} catch (IOException ioe) {
		LOG.error("Could not serialize accumulator " + name + '.', ioe);
		try {
			return new SerializedValue<>(OptionalFailure.ofFailure(ioe));
		} catch (IOException e) {
			throw new RuntimeException("It should never happen that we cannot serialize the accumulator serialization exception.", e);
		}
	}
}
 
Example 12
Source File: ExecutionGraph.java    From flink with Apache License 2.0 5 votes vote down vote up
private static SerializedValue<OptionalFailure<Object>> serializeAccumulator(String name, OptionalFailure<Accumulator<?, ?>> accumulator) {
	try {
		if (accumulator.isFailure()) {
			return new SerializedValue<>(OptionalFailure.ofFailure(accumulator.getFailureCause()));
		}
		return new SerializedValue<>(OptionalFailure.of(accumulator.getUnchecked().getLocalValue()));
	} catch (IOException ioe) {
		LOG.error("Could not serialize accumulator " + name + '.', ioe);
		try {
			return new SerializedValue<>(OptionalFailure.ofFailure(ioe));
		} catch (IOException e) {
			throw new RuntimeException("It should never happen that we cannot serialize the accumulator serialization exception.", e);
		}
	}
}