Java Code Examples for org.apache.flink.runtime.net.SSLUtils#isRestSSLEnabled()

The following examples show how to use org.apache.flink.runtime.net.SSLUtils#isRestSSLEnabled() . 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: RestClientConfiguration.java    From Flink-CEPplus with 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
Source File: RestClientConfiguration.java    From flink with 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 3
Source File: RestClientConfiguration.java    From flink with 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 4
Source File: HighAvailabilityServicesUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Get address of web monitor from configuration.
 *
 * @param configuration Configuration contains those for WebMonitor.
 * @param resolution Whether to try address resolution of the given hostname or not.
 *                   This allows to fail fast in case that the hostname cannot be resolved.
 * @return Address of WebMonitor.
 */
public static String getWebMonitorAddress(
	Configuration configuration,
	HighAvailabilityServicesUtils.AddressResolution resolution) throws UnknownHostException {
	final String address = checkNotNull(configuration.getString(RestOptions.ADDRESS), "%s must be set", RestOptions.ADDRESS.key());

	if (resolution == HighAvailabilityServicesUtils.AddressResolution.TRY_ADDRESS_RESOLUTION) {
		// Fail fast if the hostname cannot be resolved
		//noinspection ResultOfMethodCallIgnored
		InetAddress.getByName(address);
	}

	final int port = configuration.getInteger(RestOptions.PORT);
	final boolean enableSSL = SSLUtils.isRestSSLEnabled(configuration);
	final String protocol = enableSSL ? "https://" : "http://";

	return String.format("%s%s:%s", protocol, address, port);
}
 
Example 5
Source File: RestServerEndpointConfiguration.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Creates and returns a new {@link RestServerEndpointConfiguration} from the given {@link Configuration}.
 *
 * @param config configuration from which the REST server endpoint configuration should be created from
 * @return REST server endpoint configuration
 * @throws ConfigurationException if SSL was configured incorrectly
 */
public static RestServerEndpointConfiguration fromConfiguration(Configuration config) throws ConfigurationException {
	Preconditions.checkNotNull(config);

	final String restAddress = Preconditions.checkNotNull(config.getString(RestOptions.ADDRESS),
		"%s must be set",
		RestOptions.ADDRESS.key());

	final String restBindAddress = config.getString(RestOptions.BIND_ADDRESS);
	final String portRangeDefinition = config.getString(RestOptions.BIND_PORT);

	final SSLHandlerFactory sslHandlerFactory;
	if (SSLUtils.isRestSSLEnabled(config)) {
		try {
			sslHandlerFactory = SSLUtils.createRestServerSSLEngineFactory(config);
		} catch (Exception e) {
			throw new ConfigurationException("Failed to initialize SSLEngineFactory for REST server endpoint.", e);
		}
	} else {
		sslHandlerFactory = null;
	}

	final Path uploadDir = Paths.get(
		config.getString(WebOptions.UPLOAD_DIR,	config.getString(WebOptions.TMP_DIR)),
		"flink-web-upload");

	final int maxContentLength = config.getInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH);

	final Map<String, String> responseHeaders = Collections.singletonMap(
		HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN,
		config.getString(WebOptions.ACCESS_CONTROL_ALLOW_ORIGIN));

	return new RestServerEndpointConfiguration(
		restAddress,
		restBindAddress,
		portRangeDefinition,
		sslHandlerFactory,
		uploadDir,
		maxContentLength,
		responseHeaders);
}
 
Example 6
Source File: HighAvailabilityServicesUtils.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public static HighAvailabilityServices createHighAvailabilityServices(
	Configuration configuration,
	Executor executor,
	AddressResolution addressResolution) throws Exception {

	HighAvailabilityMode highAvailabilityMode = LeaderRetrievalUtils.getRecoveryMode(configuration);

	switch (highAvailabilityMode) {
		case NONE:
			final Tuple2<String, Integer> hostnamePort = getJobManagerAddress(configuration);

			final String jobManagerRpcUrl = AkkaRpcServiceUtils.getRpcUrl(
				hostnamePort.f0,
				hostnamePort.f1,
				JobMaster.JOB_MANAGER_NAME,
				addressResolution,
				configuration);
			final String resourceManagerRpcUrl = AkkaRpcServiceUtils.getRpcUrl(
				hostnamePort.f0,
				hostnamePort.f1,
				ResourceManager.RESOURCE_MANAGER_NAME,
				addressResolution,
				configuration);
			final String dispatcherRpcUrl = AkkaRpcServiceUtils.getRpcUrl(
				hostnamePort.f0,
				hostnamePort.f1,
				Dispatcher.DISPATCHER_NAME,
				addressResolution,
				configuration);

			final String address = checkNotNull(configuration.getString(RestOptions.ADDRESS),
				"%s must be set",
				RestOptions.ADDRESS.key());
			final int port = configuration.getInteger(RestOptions.PORT);
			final boolean enableSSL = SSLUtils.isRestSSLEnabled(configuration);
			final String protocol = enableSSL ? "https://" : "http://";

			return new StandaloneHaServices(
				resourceManagerRpcUrl,
				dispatcherRpcUrl,
				jobManagerRpcUrl,
				String.format("%s%s:%s", protocol, address, port));
		case ZOOKEEPER:
			BlobStoreService blobStoreService = BlobUtils.createBlobStoreFromConfig(configuration);

			return new ZooKeeperHaServices(
				ZooKeeperUtils.startCuratorFramework(configuration),
				executor,
				configuration,
				blobStoreService);

		case FACTORY_CLASS:
			return createCustomHAServices(configuration, executor);

		default:
			throw new Exception("Recovery mode " + highAvailabilityMode + " is not supported.");
	}
}
 
Example 7
Source File: RestServerEndpointConfiguration.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates and returns a new {@link RestServerEndpointConfiguration} from the given {@link Configuration}.
 *
 * @param config configuration from which the REST server endpoint configuration should be created from
 * @return REST server endpoint configuration
 * @throws ConfigurationException if SSL was configured incorrectly
 */
public static RestServerEndpointConfiguration fromConfiguration(Configuration config) throws ConfigurationException {
	Preconditions.checkNotNull(config);

	final String restAddress = Preconditions.checkNotNull(config.getString(RestOptions.ADDRESS),
		"%s must be set",
		RestOptions.ADDRESS.key());

	final String restBindAddress = config.getString(RestOptions.BIND_ADDRESS);
	final String portRangeDefinition = config.getString(RestOptions.BIND_PORT);

	final SSLHandlerFactory sslHandlerFactory;
	if (SSLUtils.isRestSSLEnabled(config)) {
		try {
			sslHandlerFactory = SSLUtils.createRestServerSSLEngineFactory(config);
		} catch (Exception e) {
			throw new ConfigurationException("Failed to initialize SSLEngineFactory for REST server endpoint.", e);
		}
	} else {
		sslHandlerFactory = null;
	}

	final Path uploadDir = Paths.get(
		config.getString(WebOptions.UPLOAD_DIR,	config.getString(WebOptions.TMP_DIR)),
		"flink-web-upload");

	final int maxContentLength = config.getInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH);

	final Map<String, String> responseHeaders = Collections.singletonMap(
		HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN,
		config.getString(WebOptions.ACCESS_CONTROL_ALLOW_ORIGIN));

	return new RestServerEndpointConfiguration(
		restAddress,
		restBindAddress,
		portRangeDefinition,
		sslHandlerFactory,
		uploadDir,
		maxContentLength,
		responseHeaders);
}
 
Example 8
Source File: HighAvailabilityServicesUtils.java    From flink with Apache License 2.0 4 votes vote down vote up
public static HighAvailabilityServices createHighAvailabilityServices(
	Configuration configuration,
	Executor executor,
	AddressResolution addressResolution) throws Exception {

	HighAvailabilityMode highAvailabilityMode = HighAvailabilityMode.fromConfig(configuration);

	switch (highAvailabilityMode) {
		case NONE:
			final Tuple2<String, Integer> hostnamePort = getJobManagerAddress(configuration);

			final String jobManagerRpcUrl = AkkaRpcServiceUtils.getRpcUrl(
				hostnamePort.f0,
				hostnamePort.f1,
				JobMaster.JOB_MANAGER_NAME,
				addressResolution,
				configuration);
			final String resourceManagerRpcUrl = AkkaRpcServiceUtils.getRpcUrl(
				hostnamePort.f0,
				hostnamePort.f1,
				ResourceManager.RESOURCE_MANAGER_NAME,
				addressResolution,
				configuration);
			final String dispatcherRpcUrl = AkkaRpcServiceUtils.getRpcUrl(
				hostnamePort.f0,
				hostnamePort.f1,
				Dispatcher.DISPATCHER_NAME,
				addressResolution,
				configuration);

			final String address = checkNotNull(configuration.getString(RestOptions.ADDRESS),
				"%s must be set",
				RestOptions.ADDRESS.key());
			final int port = configuration.getInteger(RestOptions.PORT);
			final boolean enableSSL = SSLUtils.isRestSSLEnabled(configuration);
			final String protocol = enableSSL ? "https://" : "http://";

			return new StandaloneHaServices(
				resourceManagerRpcUrl,
				dispatcherRpcUrl,
				jobManagerRpcUrl,
				String.format("%s%s:%s", protocol, address, port));
		case ZOOKEEPER:
			BlobStoreService blobStoreService = BlobUtils.createBlobStoreFromConfig(configuration);

			return new ZooKeeperHaServices(
				ZooKeeperUtils.startCuratorFramework(configuration),
				executor,
				configuration,
				blobStoreService);

		case FACTORY_CLASS:
			return createCustomHAServices(configuration, executor);

		default:
			throw new Exception("Recovery mode " + highAvailabilityMode + " is not supported.");
	}
}
 
Example 9
Source File: RestServerEndpointConfiguration.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates and returns a new {@link RestServerEndpointConfiguration} from the given {@link Configuration}.
 *
 * @param config configuration from which the REST server endpoint configuration should be created from
 * @return REST server endpoint configuration
 * @throws ConfigurationException if SSL was configured incorrectly
 */
public static RestServerEndpointConfiguration fromConfiguration(Configuration config) throws ConfigurationException {
	Preconditions.checkNotNull(config);

	final String restAddress = Preconditions.checkNotNull(config.getString(RestOptions.ADDRESS),
		"%s must be set",
		RestOptions.ADDRESS.key());

	final String restBindAddress = config.getString(RestOptions.BIND_ADDRESS);
	final String portRangeDefinition = config.getString(RestOptions.BIND_PORT);

	final SSLHandlerFactory sslHandlerFactory;
	if (SSLUtils.isRestSSLEnabled(config)) {
		try {
			sslHandlerFactory = SSLUtils.createRestServerSSLEngineFactory(config);
		} catch (Exception e) {
			throw new ConfigurationException("Failed to initialize SSLEngineFactory for REST server endpoint.", e);
		}
	} else {
		sslHandlerFactory = null;
	}

	final Path uploadDir = Paths.get(
		config.getString(WebOptions.UPLOAD_DIR,	config.getString(WebOptions.TMP_DIR)),
		"flink-web-upload");

	final int maxContentLength = config.getInteger(RestOptions.SERVER_MAX_CONTENT_LENGTH);

	final Map<String, String> responseHeaders = Collections.singletonMap(
		HttpHeaders.Names.ACCESS_CONTROL_ALLOW_ORIGIN,
		config.getString(WebOptions.ACCESS_CONTROL_ALLOW_ORIGIN));

	return new RestServerEndpointConfiguration(
		restAddress,
		restBindAddress,
		portRangeDefinition,
		sslHandlerFactory,
		uploadDir,
		maxContentLength,
		responseHeaders);
}