Java Code Examples for org.apache.flink.configuration.RestOptions

The following examples show how to use org.apache.flink.configuration.RestOptions. These examples are extracted from open source projects. 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 Project: Flink-CEPplus   Source File: RestClientConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a new {@link RestClientConfiguration} from the given {@link Configuration}.
 *
 * @param config configuration from which the REST client endpoint configuration should be created from
 * @return REST client endpoint configuration
 * @throws ConfigurationException if SSL was configured incorrectly
 */

public static RestClientConfiguration fromConfiguration(Configuration config) throws ConfigurationException {
	Preconditions.checkNotNull(config);

	final SSLHandlerFactory sslHandlerFactory;
	if (SSLUtils.isRestSSLEnabled(config)) {
		try {
			sslHandlerFactory = SSLUtils.createRestClientSSLEngineFactory(config);
		} catch (Exception e) {
			throw new ConfigurationException("Failed to initialize SSLContext for the REST client", e);
		}
	} else {
		sslHandlerFactory = null;
	}

	final long connectionTimeout = config.getLong(RestOptions.CONNECTION_TIMEOUT);

	final long idlenessTimeout = config.getLong(RestOptions.IDLENESS_TIMEOUT);

	int maxContentLength = config.getInteger(RestOptions.CLIENT_MAX_CONTENT_LENGTH);

	return new RestClientConfiguration(sslHandlerFactory, connectionTimeout, idlenessTimeout, maxContentLength);
}
 
Example 2
public TestingMiniClusterConfiguration build() {
	final Configuration modifiedConfiguration = new Configuration(configuration);
	modifiedConfiguration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, numSlotsPerTaskManager);
	modifiedConfiguration.setString(
		RestOptions.ADDRESS,
		modifiedConfiguration.getString(RestOptions.ADDRESS, "localhost"));
	modifiedConfiguration.setInteger(
		RestOptions.PORT,
		modifiedConfiguration.getInteger(RestOptions.PORT, 0));

	return new TestingMiniClusterConfiguration(
		modifiedConfiguration,
		numTaskManagers,
		rpcServiceSharing,
		commonBindAddress,
		numberDispatcherResourceManagerComponents,
		localCommunication);
}
 
Example 3
@Test
public void testBasicMapping() throws ConfigurationException {
	Configuration originalConfig = new Configuration();
	originalConfig.setString(RestOptions.ADDRESS, ADDRESS);
	originalConfig.setString(RestOptions.BIND_ADDRESS, BIND_ADDRESS);
	originalConfig.setString(RestOptions.BIND_PORT, BIND_PORT);
	originalConfig.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH, CONTENT_LENGTH);
	originalConfig.setString(WebOptions.TMP_DIR, temporaryFolder.getRoot().getAbsolutePath());

	final RestServerEndpointConfiguration result = RestServerEndpointConfiguration.fromConfiguration(originalConfig);
	Assert.assertEquals(ADDRESS, result.getRestAddress());
	Assert.assertEquals(BIND_ADDRESS, result.getRestBindAddress());
	Assert.assertEquals(BIND_PORT, result.getRestBindPortRange());
	Assert.assertEquals(CONTENT_LENGTH, result.getMaxContentLength());
	Assert.assertThat(
		result.getUploadDir().toAbsolutePath().toString(),
		containsString(temporaryFolder.getRoot().getAbsolutePath()));
}
 
Example 4
Source Project: Flink-CEPplus   Source File: RestServerEndpointITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRestServerBindPort() throws Exception {
	final int portRangeStart = 52300;
	final int portRangeEnd = 52400;
	final Configuration config = new Configuration();
	config.setString(RestOptions.ADDRESS, "localhost");
	config.setString(RestOptions.BIND_PORT, portRangeStart + "-" + portRangeEnd);

	final RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	try (RestServerEndpoint serverEndpoint1 = new TestRestServerEndpoint(serverConfig, Collections.emptyList());
		RestServerEndpoint serverEndpoint2 = new TestRestServerEndpoint(serverConfig, Collections.emptyList())) {

		serverEndpoint1.start();
		serverEndpoint2.start();

		assertNotEquals(serverEndpoint1.getServerAddress().getPort(), serverEndpoint2.getServerAddress().getPort());

		assertThat(serverEndpoint1.getServerAddress().getPort(), is(greaterThanOrEqualTo(portRangeStart)));
		assertThat(serverEndpoint1.getServerAddress().getPort(), is(lessThanOrEqualTo(portRangeEnd)));

		assertThat(serverEndpoint2.getServerAddress().getPort(), is(greaterThanOrEqualTo(portRangeStart)));
		assertThat(serverEndpoint2.getServerAddress().getPort(), is(lessThanOrEqualTo(portRangeEnd)));
	}
}
 
Example 5
Source Project: Flink-CEPplus   Source File: RestClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConnectionTimeout() throws Exception {
	final Configuration config = new Configuration();
	config.setLong(RestOptions.CONNECTION_TIMEOUT, 1);
	try (final RestClient restClient = new RestClient(RestClientConfiguration.fromConfiguration(config), Executors.directExecutor())) {
		restClient.sendRequest(
			unroutableIp,
			80,
			new TestMessageHeaders(),
			EmptyMessageParameters.getInstance(),
			EmptyRequestBody.getInstance())
			.get(60, TimeUnit.SECONDS);
	} catch (final ExecutionException e) {
		final Throwable throwable = ExceptionUtils.stripExecutionException(e);
		assertThat(throwable, instanceOf(ConnectTimeoutException.class));
		assertThat(throwable.getMessage(), containsString(unroutableIp));
	}
}
 
Example 6
Source Project: Flink-CEPplus   Source File: DispatcherProcess.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Entrypoint of the DispatcherProcessEntryPoint.
 *
 * <p>Other arguments are parsed to a {@link Configuration} and passed to the Dispatcher,
 * for instance: <code>--high-availability ZOOKEEPER --high-availability.zookeeper.quorum
 * "xyz:123:456"</code>.
 */
public static void main(String[] args) {
	try {
		ParameterTool params = ParameterTool.fromArgs(args);
		Configuration config = params.getConfiguration();
		LOG.info("Configuration: {}.", config);

		config.setInteger(JobManagerOptions.PORT, 0);
		config.setString(RestOptions.BIND_PORT, "0");

		final StandaloneSessionClusterEntrypoint clusterEntrypoint = new StandaloneSessionClusterEntrypoint(config);

		ClusterEntrypoint.runClusterEntrypoint(clusterEntrypoint);
	}
	catch (Throwable t) {
		LOG.error("Failed to start Dispatcher process", t);
		System.exit(1);
	}
}
 
Example 7
Source Project: Flink-CEPplus   Source File: LocalExecutor.java    License: Apache License 2.0 6 votes vote down vote up
private JobExecutorService createJobExecutorService(Configuration configuration) throws Exception {
	if (!configuration.contains(RestOptions.BIND_PORT)) {
		configuration.setString(RestOptions.BIND_PORT, "0");
	}

	final MiniClusterConfiguration miniClusterConfiguration = new MiniClusterConfiguration.Builder()
		.setConfiguration(configuration)
		.setNumTaskManagers(
			configuration.getInteger(
				ConfigConstants.LOCAL_NUMBER_TASK_MANAGER,
				ConfigConstants.DEFAULT_LOCAL_NUMBER_TASK_MANAGER))
		.setRpcServiceSharing(RpcServiceSharing.SHARED)
		.setNumSlotsPerTaskManager(
			configuration.getInteger(
				TaskManagerOptions.NUM_TASK_SLOTS, 1))
		.build();

	final MiniCluster miniCluster = new MiniCluster(miniClusterConfiguration);
	miniCluster.start();

	configuration.setInteger(RestOptions.PORT, miniCluster.getRestAddress().get().getPort());

	return miniCluster;
}
 
Example 8
Source Project: flink   Source File: RestClientConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates and returns a new {@link RestClientConfiguration} from the given {@link Configuration}.
 *
 * @param config configuration from which the REST client endpoint configuration should be created from
 * @return REST client endpoint configuration
 * @throws ConfigurationException if SSL was configured incorrectly
 */

public static RestClientConfiguration fromConfiguration(Configuration config) throws ConfigurationException {
	Preconditions.checkNotNull(config);

	final SSLHandlerFactory sslHandlerFactory;
	if (SSLUtils.isRestSSLEnabled(config)) {
		try {
			sslHandlerFactory = SSLUtils.createRestClientSSLEngineFactory(config);
		} catch (Exception e) {
			throw new ConfigurationException("Failed to initialize SSLContext for the REST client", e);
		}
	} else {
		sslHandlerFactory = null;
	}

	final long connectionTimeout = config.getLong(RestOptions.CONNECTION_TIMEOUT);

	final long idlenessTimeout = config.getLong(RestOptions.IDLENESS_TIMEOUT);

	int maxContentLength = config.getInteger(RestOptions.CLIENT_MAX_CONTENT_LENGTH);

	return new RestClientConfiguration(sslHandlerFactory, connectionTimeout, idlenessTimeout, maxContentLength);
}
 
Example 9
Source Project: flink   Source File: FlinkHttpObjectAggregator.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void decode(
		final ChannelHandlerContext ctx,
		final HttpObject msg,
		final List<Object> out) throws Exception {

	try {
		super.decode(ctx, msg, out);
	} catch (final TooLongFrameException e) {
		HandlerUtils.sendErrorResponse(
			ctx,
			false,
			new ErrorResponseBody(String.format(
				e.getMessage() + " Try to raise [%s]",
				RestOptions.SERVER_MAX_CONTENT_LENGTH.key())),
			HttpResponseStatus.REQUEST_ENTITY_TOO_LARGE,
			responseHeaders);
	}
}
 
Example 10
Source Project: flink   Source File: ClusterEntrypoint.java    License: Apache License 2.0 6 votes vote down vote up
protected static Configuration loadConfiguration(EntrypointClusterConfiguration entrypointClusterConfiguration) {
	final Configuration dynamicProperties = ConfigurationUtils.createConfiguration(entrypointClusterConfiguration.getDynamicProperties());
	final Configuration configuration = GlobalConfiguration.loadConfiguration(entrypointClusterConfiguration.getConfigDir(), dynamicProperties);

	final int restPort = entrypointClusterConfiguration.getRestPort();

	if (restPort >= 0) {
		configuration.setInteger(RestOptions.PORT, restPort);
	}

	final String hostname = entrypointClusterConfiguration.getHostname();

	if (hostname != null) {
		configuration.setString(JobManagerOptions.ADDRESS, hostname);
	}

	return configuration;
}
 
Example 11
Source Project: flink   Source File: TestingMiniClusterConfiguration.java    License: Apache License 2.0 6 votes vote down vote up
public TestingMiniClusterConfiguration build() {
	final Configuration modifiedConfiguration = new Configuration(configuration);
	modifiedConfiguration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, numSlotsPerTaskManager);
	modifiedConfiguration.setString(
		RestOptions.ADDRESS,
		modifiedConfiguration.getString(RestOptions.ADDRESS, "localhost"));
	modifiedConfiguration.setInteger(
		RestOptions.PORT,
		modifiedConfiguration.getInteger(RestOptions.PORT, 0));

	return new TestingMiniClusterConfiguration(
		modifiedConfiguration,
		numTaskManagers,
		rpcServiceSharing,
		commonBindAddress,
		numberDispatcherResourceManagerComponents,
		localCommunication);
}
 
Example 12
Source Project: flink   Source File: RestServerEndpointConfigurationTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testBasicMapping() throws ConfigurationException {
	Configuration originalConfig = new Configuration();
	originalConfig.setString(RestOptions.ADDRESS, ADDRESS);
	originalConfig.setString(RestOptions.BIND_ADDRESS, BIND_ADDRESS);
	originalConfig.setString(RestOptions.BIND_PORT, BIND_PORT);
	originalConfig.setInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH, CONTENT_LENGTH);
	originalConfig.setString(WebOptions.TMP_DIR, temporaryFolder.getRoot().getAbsolutePath());

	final RestServerEndpointConfiguration result = RestServerEndpointConfiguration.fromConfiguration(originalConfig);
	Assert.assertEquals(ADDRESS, result.getRestAddress());
	Assert.assertEquals(BIND_ADDRESS, result.getRestBindAddress());
	Assert.assertEquals(BIND_PORT, result.getRestBindPortRange());
	Assert.assertEquals(CONTENT_LENGTH, result.getMaxContentLength());
	Assert.assertThat(
		result.getUploadDir().toAbsolutePath().toString(),
		containsString(temporaryFolder.getRoot().getAbsolutePath()));
}
 
Example 13
Source Project: flink   Source File: RestServerEndpointITCase.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRestServerBindPort() throws Exception {
	final int portRangeStart = 52300;
	final int portRangeEnd = 52400;
	final Configuration config = new Configuration();
	config.setString(RestOptions.ADDRESS, "localhost");
	config.setString(RestOptions.BIND_PORT, portRangeStart + "-" + portRangeEnd);

	final RestServerEndpointConfiguration serverConfig = RestServerEndpointConfiguration.fromConfiguration(config);

	try (RestServerEndpoint serverEndpoint1 = new TestRestServerEndpoint(serverConfig, Collections.emptyList());
		RestServerEndpoint serverEndpoint2 = new TestRestServerEndpoint(serverConfig, Collections.emptyList())) {

		serverEndpoint1.start();
		serverEndpoint2.start();

		assertNotEquals(serverEndpoint1.getServerAddress().getPort(), serverEndpoint2.getServerAddress().getPort());

		assertThat(serverEndpoint1.getServerAddress().getPort(), is(greaterThanOrEqualTo(portRangeStart)));
		assertThat(serverEndpoint1.getServerAddress().getPort(), is(lessThanOrEqualTo(portRangeEnd)));

		assertThat(serverEndpoint2.getServerAddress().getPort(), is(greaterThanOrEqualTo(portRangeStart)));
		assertThat(serverEndpoint2.getServerAddress().getPort(), is(lessThanOrEqualTo(portRangeEnd)));
	}
}
 
Example 14
Source Project: flink   Source File: RestClientTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testConnectionTimeout() throws Exception {
	final Configuration config = new Configuration();
	config.setLong(RestOptions.CONNECTION_TIMEOUT, 1);
	try (final RestClient restClient = new RestClient(RestClientConfiguration.fromConfiguration(config), Executors.directExecutor())) {
		restClient.sendRequest(
			unroutableIp,
			80,
			new TestMessageHeaders(),
			EmptyMessageParameters.getInstance(),
			EmptyRequestBody.getInstance())
			.get(60, TimeUnit.SECONDS);
	} catch (final ExecutionException e) {
		final Throwable throwable = ExceptionUtils.stripExecutionException(e);
		assertThat(throwable, instanceOf(ConnectTimeoutException.class));
		assertThat(throwable.getMessage(), containsString(unroutableIp));
	}
}
 
Example 15
Source Project: flink   Source File: DispatcherProcess.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Entrypoint of the DispatcherProcessEntryPoint.
 *
 * <p>Other arguments are parsed to a {@link Configuration} and passed to the Dispatcher,
 * for instance: <code>--high-availability ZOOKEEPER --high-availability.zookeeper.quorum
 * "xyz:123:456"</code>.
 */
public static void main(String[] args) {
	try {
		ParameterTool params = ParameterTool.fromArgs(args);
		Configuration config = params.getConfiguration();
		LOG.info("Configuration: {}.", config);

		config.setInteger(JobManagerOptions.PORT, 0);
		config.setString(RestOptions.BIND_PORT, "0");

		final StandaloneSessionClusterEntrypoint clusterEntrypoint = new StandaloneSessionClusterEntrypoint(config);

		ClusterEntrypoint.runClusterEntrypoint(clusterEntrypoint);
	}
	catch (Throwable t) {
		LOG.error("Failed to start Dispatcher process", t);
		System.exit(1);
	}
}
 
Example 16
Source Project: flink   Source File: LocalExecutor.java    License: Apache License 2.0 6 votes vote down vote up
private JobExecutorService createJobExecutorService(Configuration configuration) throws Exception {
	if (!configuration.contains(RestOptions.BIND_PORT)) {
		configuration.setString(RestOptions.BIND_PORT, "0");
	}

	final MiniClusterConfiguration miniClusterConfiguration = new MiniClusterConfiguration.Builder()
		.setConfiguration(configuration)
		.setNumTaskManagers(
			configuration.getInteger(
				ConfigConstants.LOCAL_NUMBER_TASK_MANAGER,
				ConfigConstants.DEFAULT_LOCAL_NUMBER_TASK_MANAGER))
		.setRpcServiceSharing(RpcServiceSharing.SHARED)
		.setNumSlotsPerTaskManager(
			configuration.getInteger(
				TaskManagerOptions.NUM_TASK_SLOTS, 1))
		.build();

	final MiniCluster miniCluster = new MiniCluster(miniClusterConfiguration);
	miniCluster.start();

	configuration.setInteger(RestOptions.PORT, miniCluster.getRestAddress().get().getPort());

	return miniCluster;
}
 
Example 17
@BeforeClass
public static void setUp() throws Exception {
	final Configuration config = new Configuration();
	config.setInteger(RestOptions.PORT, 0);

	final MiniClusterConfiguration miniClusterConfiguration = new MiniClusterConfiguration.Builder()
		.setConfiguration(config)
		.setNumTaskManagers(1)
		.setNumSlotsPerTaskManager(1)
		.build();

	flink = new MiniCluster(miniClusterConfiguration);

	flink.start();
}
 
Example 18
@Test
public void testUpateWatermark() throws Exception {
	final Configuration clientConfiguration = new Configuration();
	clientConfiguration.setInteger(RestOptions.RETRY_MAX_ATTEMPTS, 0);

	final StreamExecutionEnvironment env = StreamExecutionEnvironment.createRemoteEnvironment(
		flink.getRestAddress().get().getHost(),
		flink.getRestAddress().get().getPort(),
		clientConfiguration);

	env.addSource(new TestSourceFunction(new JobManagerWatermarkTracker("fakeId")))
		.addSink(new SinkFunction<Integer>() {});
	env.execute();
}
 
Example 19
Source Project: Flink-CEPplus   Source File: JobRetrievalITCase.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	final Configuration clientConfig = new Configuration();
	clientConfig.setInteger(RestOptions.RETRY_MAX_ATTEMPTS, 0);
	clientConfig.setLong(RestOptions.RETRY_DELAY, 0);
	clientConfig.addAll(CLUSTER.getClientConfiguration());

	client = new RestClusterClient<>(
		clientConfig,
		StandaloneClusterId.getInstance()
	);
}
 
Example 20
Source Project: Flink-CEPplus   Source File: SchedulingITCase.java    License: Apache License 2.0 5 votes vote down vote up
private void executeSchedulingTest(Configuration configuration) throws Exception {
	configuration.setString(RestOptions.BIND_PORT, "0");

	final long slotIdleTimeout = 50L;
	configuration.setLong(JobManagerOptions.SLOT_IDLE_TIMEOUT, slotIdleTimeout);

	final int parallelism = 4;
	final MiniClusterConfiguration miniClusterConfiguration = new MiniClusterConfiguration.Builder()
		.setConfiguration(configuration)
		.setNumTaskManagers(parallelism)
		.setNumSlotsPerTaskManager(1)
		.build();

	try (MiniCluster miniCluster = new MiniCluster(miniClusterConfiguration)) {
		miniCluster.start();

		MiniClusterClient miniClusterClient = new MiniClusterClient(configuration, miniCluster);

		JobGraph jobGraph = createJobGraph(slotIdleTimeout << 1, parallelism);
		CompletableFuture<JobSubmissionResult> submissionFuture = miniClusterClient.submitJob(jobGraph);

		// wait for the submission to succeed
		JobSubmissionResult jobSubmissionResult = submissionFuture.get();

		CompletableFuture<JobResult> resultFuture = miniClusterClient.requestJobResult(jobSubmissionResult.getJobID());

		JobResult jobResult = resultFuture.get();

		assertThat(jobResult.getSerializedThrowable().isPresent(), is(false));
	}
}
 
Example 21
Source Project: Flink-CEPplus   Source File: ExecutionEnvironment.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link LocalEnvironment} for local program execution that also starts the
 * web monitoring UI.
 *
 * <p>The local execution environment will run the program in a multi-threaded fashion in
 * the same JVM as the environment was created in. It will use the parallelism specified in the
 * parameter.
 *
 * <p>If the configuration key 'rest.port' was set in the configuration, that particular
 * port will be used for the web UI. Otherwise, the default port (8081) will be used.
 */
@PublicEvolving
public static ExecutionEnvironment createLocalEnvironmentWithWebUI(Configuration conf) {
	checkNotNull(conf, "conf");

	conf.setBoolean(ConfigConstants.LOCAL_START_WEBSERVER, true);

	if (!conf.contains(RestOptions.PORT)) {
		// explicitly set this option so that it's not set to 0 later
		conf.setInteger(RestOptions.PORT, RestOptions.PORT.defaultValue());
	}

	return createLocalEnvironment(conf, -1);
}
 
Example 22
Source Project: flink   Source File: RestClusterClientTest.java    License: Apache License 2.0 5 votes vote down vote up
private RestClusterClient<StandaloneClusterId> createRestClusterClient(final int port) throws Exception {
	final Configuration clientConfig = new Configuration(restConfig);
	clientConfig.setInteger(RestOptions.PORT, port);
	return new RestClusterClient<>(
		clientConfig,
		createRestClient(),
		StandaloneClusterId.getInstance(),
		(attempt) -> 0,
		null);
}
 
Example 23
Source Project: Flink-CEPplus   Source File: YarnEntrypointUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the REST ports are correctly set when loading a {@link Configuration}
 * with unspecified REST options.
 */
@Test
public void testRestPortOptionsUnspecified() throws IOException {
	final Configuration initialConfiguration = new Configuration();

	final Configuration configuration = loadConfiguration(initialConfiguration);

	// having not specified the ports should set the rest bind port to 0
	assertThat(configuration.getString(RestOptions.BIND_PORT), is(equalTo("0")));
}
 
Example 24
Source Project: Flink-CEPplus   Source File: YarnEntrypointUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the binding REST port is set to the REST port if set.
 */
@Test
public void testRestPortSpecified() throws IOException {
	final Configuration initialConfiguration = new Configuration();
	final int port = 1337;
	initialConfiguration.setInteger(RestOptions.PORT, port);

	final Configuration configuration = loadConfiguration(initialConfiguration);

	// if the bind port is not specified it should fall back to the rest port
	assertThat(configuration.getString(RestOptions.BIND_PORT), is(equalTo(String.valueOf(port))));
}
 
Example 25
Source Project: Flink-CEPplus   Source File: YarnEntrypointUtilsTest.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Tests that the binding REST port has precedence over the REST port if both are set.
 */
@Test
public void testRestPortAndBindingPortSpecified() throws IOException {
	final Configuration initialConfiguration = new Configuration();
	final int port = 1337;
	final String bindingPortRange = "1337-7331";
	initialConfiguration.setInteger(RestOptions.PORT, port);
	initialConfiguration.setString(RestOptions.BIND_PORT, bindingPortRange);

	final Configuration configuration = loadConfiguration(initialConfiguration);

	// bind port should have precedence over the rest port
	assertThat(configuration.getString(RestOptions.BIND_PORT), is(equalTo(bindingPortRange)));
}
 
Example 26
Source Project: Flink-CEPplus   Source File: MiniClusterConfiguration.java    License: Apache License 2.0 5 votes vote down vote up
public MiniClusterConfiguration build() {
	final Configuration modifiedConfiguration = new Configuration(configuration);
	modifiedConfiguration.setInteger(TaskManagerOptions.NUM_TASK_SLOTS, numSlotsPerTaskManager);
	modifiedConfiguration.setString(
		RestOptions.ADDRESS,
		modifiedConfiguration.getString(RestOptions.ADDRESS, "localhost"));

	return new MiniClusterConfiguration(
		modifiedConfiguration,
		numTaskManagers,
		rpcServiceSharing,
		commonBindAddress);
}
 
Example 27
Source Project: flink   Source File: RestClusterClientConfigurationTest.java    License: Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
	final Configuration config = new Configuration();
	config.setLong(RestOptions.AWAIT_LEADER_TIMEOUT, 1);
	config.setInteger(RestOptions.RETRY_MAX_ATTEMPTS, 2);
	config.setLong(RestOptions.RETRY_DELAY, 3);
	restClusterClientConfiguration = RestClusterClientConfiguration.fromConfiguration(config);
}
 
Example 28
Source Project: Flink-CEPplus   Source File: RestClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) {
	if (msg instanceof HttpResponse && ((HttpResponse) msg).status().equals(REQUEST_ENTITY_TOO_LARGE)) {
		jsonFuture.completeExceptionally(
			new RestClientException(
				String.format(
					REQUEST_ENTITY_TOO_LARGE + ". Try to raise [%s]",
					RestOptions.CLIENT_MAX_CONTENT_LENGTH.key()),
				((HttpResponse) msg).status()));
	} else if (msg instanceof FullHttpResponse) {
		readRawResponse((FullHttpResponse) msg);
	} else {
		LOG.error("Implementation error: Received a response that wasn't a FullHttpResponse.");
		if (msg instanceof HttpResponse) {
			jsonFuture.completeExceptionally(
				new RestClientException(
					"Implementation error: Received a response that wasn't a FullHttpResponse.",
					((HttpResponse) msg).getStatus()));
		} else {
			jsonFuture.completeExceptionally(
				new RestClientException(
					"Implementation error: Received a response that wasn't a FullHttpResponse.",
					HttpResponseStatus.INTERNAL_SERVER_ERROR));
		}

	}
	ctx.close();
}
 
Example 29
Source Project: Flink-CEPplus   Source File: RestClient.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
	if (cause instanceof TooLongFrameException) {
		jsonFuture.completeExceptionally(new TooLongFrameException(String.format(
			cause.getMessage() + " Try to raise [%s]",
			RestOptions.CLIENT_MAX_CONTENT_LENGTH.key())));
	} else {
		jsonFuture.completeExceptionally(cause);
	}
	ctx.close();
}
 
Example 30
private RestClusterClient<StandaloneClusterId> createRestClusterClient(final int port) throws Exception {
	final Configuration clientConfig = new Configuration(REST_CONFIG);
	clientConfig.setInteger(RestOptions.PORT, port);
	return new RestClusterClient<>(
		clientConfig,
		new RestClient(RestClientConfiguration.fromConfiguration(REST_CONFIG), executor),
		StandaloneClusterId.getInstance(),
		(attempt) -> 0,
		null);
}