Java Code Examples for org.apache.flink.runtime.highavailability.HighAvailabilityServicesUtils#AddressResolution

The following examples show how to use org.apache.flink.runtime.highavailability.HighAvailabilityServicesUtils#AddressResolution . 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: AkkaRpcServiceUtils.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param hostname The hostname or address where the target RPC service is listening.
 * @param port The port where the target RPC service is listening.
 * @param endpointName The name of the RPC endpoint.
 * @param addressResolution Whether to try address resolution of the given hostname or not.
 *                          This allows to fail fast in case that the hostname cannot be resolved.
 * @param config The configuration from which to deduce further settings.
 *
 * @return The RPC URL of the specified RPC endpoint.
 */
public static String getRpcUrl(
	String hostname,
	int port,
	String endpointName,
	HighAvailabilityServicesUtils.AddressResolution addressResolution,
	Configuration config) throws UnknownHostException {

	checkNotNull(config, "config is null");

	final boolean sslEnabled = config.getBoolean(AkkaOptions.SSL_ENABLED) &&
			SSLUtils.isInternalSSLEnabled(config);

	return getRpcUrl(
		hostname,
		port,
		endpointName,
		addressResolution,
		sslEnabled ? AkkaProtocol.SSL_TCP : AkkaProtocol.TCP);
}
 
Example 2
Source File: AkkaRpcServiceUtils.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * @param hostname The hostname or address where the target RPC service is listening.
 * @param port The port where the target RPC service is listening.
 * @param endpointName The name of the RPC endpoint.
 * @param addressResolution Whether to try address resolution of the given hostname or not.
 *                          This allows to fail fast in case that the hostname cannot be resolved.
 * @param akkaProtocol True, if security/encryption is enabled, false otherwise.
 *
 * @return The RPC URL of the specified RPC endpoint.
 */
public static String getRpcUrl(
		String hostname,
		int port,
		String endpointName,
		HighAvailabilityServicesUtils.AddressResolution addressResolution,
		AkkaProtocol akkaProtocol) throws UnknownHostException {

	checkNotNull(hostname, "hostname is null");
	checkNotNull(endpointName, "endpointName is null");
	checkArgument(port > 0 && port <= 65535, "port must be in [1, 65535]");

	final String protocolPrefix = akkaProtocol == AkkaProtocol.SSL_TCP ? AKKA_SSL_TCP : AKKA_TCP;

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

	final String hostPort = NetUtils.unresolvedHostAndPortToNormalizedString(hostname, port);

	return String.format("%s://flink@%s/user/%s", protocolPrefix, hostPort, endpointName);
}
 
Example 3
Source File: AkkaRpcServiceUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param hostname The hostname or address where the target RPC service is listening.
 * @param port The port where the target RPC service is listening.
 * @param endpointName The name of the RPC endpoint.
 * @param addressResolution Whether to try address resolution of the given hostname or not.
 *                          This allows to fail fast in case that the hostname cannot be resolved.
 * @param config The configuration from which to deduce further settings.
 *
 * @return The RPC URL of the specified RPC endpoint.
 */
public static String getRpcUrl(
	String hostname,
	int port,
	String endpointName,
	HighAvailabilityServicesUtils.AddressResolution addressResolution,
	Configuration config) throws UnknownHostException {

	checkNotNull(config, "config is null");

	final boolean sslEnabled = config.getBoolean(AkkaOptions.SSL_ENABLED) &&
			SSLUtils.isInternalSSLEnabled(config);

	return getRpcUrl(
		hostname,
		port,
		endpointName,
		addressResolution,
		sslEnabled ? AkkaProtocol.SSL_TCP : AkkaProtocol.TCP);
}
 
Example 4
Source File: AkkaRpcServiceUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * @param hostname The hostname or address where the target RPC service is listening.
 * @param port The port where the target RPC service is listening.
 * @param endpointName The name of the RPC endpoint.
 * @param addressResolution Whether to try address resolution of the given hostname or not.
 *                          This allows to fail fast in case that the hostname cannot be resolved.
 * @param akkaProtocol True, if security/encryption is enabled, false otherwise.
 *
 * @return The RPC URL of the specified RPC endpoint.
 */
public static String getRpcUrl(
		String hostname,
		int port,
		String endpointName,
		HighAvailabilityServicesUtils.AddressResolution addressResolution,
		AkkaProtocol akkaProtocol) throws UnknownHostException {

	checkNotNull(hostname, "hostname is null");
	checkNotNull(endpointName, "endpointName is null");
	checkArgument(port > 0 && port <= 65535, "port must be in [1, 65535]");

	final String protocolPrefix = akkaProtocol == AkkaProtocol.SSL_TCP ? AKKA_SSL_TCP : AKKA_TCP;

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

	final String hostPort = NetUtils.unresolvedHostAndPortToNormalizedString(hostname, port);

	return String.format("%s://flink@%s/user/%s", protocolPrefix, hostPort, endpointName);
}
 
Example 5
Source File: AkkaRpcServiceUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 *
 * @param hostname The hostname or address where the target RPC service is listening.
 * @param port The port where the target RPC service is listening.
 * @param endpointName The name of the RPC endpoint.
 * @param addressResolution Whether to try address resolution of the given hostname or not.
 *                          This allows to fail fast in case that the hostname cannot be resolved.
 * @param config The configuration from which to deduce further settings.
 *
 * @return The RPC URL of the specified RPC endpoint.
 */
public static String getRpcUrl(
	String hostname,
	int port,
	String endpointName,
	HighAvailabilityServicesUtils.AddressResolution addressResolution,
	Configuration config) throws UnknownHostException {

	checkNotNull(config, "config is null");

	final boolean sslEnabled = config.getBoolean(AkkaOptions.SSL_ENABLED) &&
			SSLUtils.isInternalSSLEnabled(config);

	return getRpcUrl(
		hostname,
		port,
		endpointName,
		addressResolution,
		sslEnabled ? AkkaProtocol.SSL_TCP : AkkaProtocol.TCP);
}
 
Example 6
Source File: AkkaRpcServiceUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * @param hostname The hostname or address where the target RPC service is listening.
 * @param port The port where the target RPC service is listening.
 * @param endpointName The name of the RPC endpoint.
 * @param addressResolution Whether to try address resolution of the given hostname or not.
 *                          This allows to fail fast in case that the hostname cannot be resolved.
 * @param akkaProtocol True, if security/encryption is enabled, false otherwise.
 *
 * @return The RPC URL of the specified RPC endpoint.
 */
public static String getRpcUrl(
		String hostname,
		int port,
		String endpointName,
		HighAvailabilityServicesUtils.AddressResolution addressResolution,
		AkkaProtocol akkaProtocol) throws UnknownHostException {

	checkNotNull(hostname, "hostname is null");
	checkNotNull(endpointName, "endpointName is null");
	checkArgument(isValidClientPort(port), "port must be in [1, 65535]");

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

	final String hostPort = NetUtils.unresolvedHostAndPortToNormalizedString(hostname, port);

	return internalRpcUrl(endpointName, Optional.of(new RemoteAddressInformation(hostPort, akkaProtocol)));
}
 
Example 7
Source File: YarnPreConfiguredMasterNonHaServices.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
/**
 * Creates new YarnPreConfiguredMasterHaServices for the given Flink and YARN configuration.
 * This constructor parses the ResourceManager address from the Flink configuration and sets
 * up the HDFS access to store recovery data in the YARN application's working directory.
 *
 * @param config     The Flink configuration of this component / process.
 * @param hadoopConf The Hadoop configuration for the YARN cluster.
 *
 * @throws IOException
 *             Thrown, if the initialization of the Hadoop file system used by YARN fails.
 * @throws IllegalConfigurationException
 *             Thrown, if the Flink configuration does not properly describe the ResourceManager address and port.
 */
public YarnPreConfiguredMasterNonHaServices(
		Configuration config,
		org.apache.hadoop.conf.Configuration hadoopConf,
		HighAvailabilityServicesUtils.AddressResolution addressResolution) throws IOException {

	super(config, hadoopConf);

	// track whether we successfully perform the initialization
	boolean successful = false;

	try {
		// extract the hostname and port of the resource manager
		final String rmHost = config.getString(YarnConfigOptions.APP_MASTER_RPC_ADDRESS);
		final int rmPort = config.getInteger(YarnConfigOptions.APP_MASTER_RPC_PORT);

		if (rmHost == null) {
			throw new IllegalConfigurationException("Config parameter '" +
					YarnConfigOptions.APP_MASTER_RPC_ADDRESS.key() + "' is missing.");
		}
		if (rmPort < 0) {
			throw new IllegalConfigurationException("Config parameter '" +
					YarnConfigOptions.APP_MASTER_RPC_PORT.key() + "' is missing.");
		}
		if (rmPort <= 0 || rmPort >= 65536) {
			throw new IllegalConfigurationException("Invalid value for '" +
					YarnConfigOptions.APP_MASTER_RPC_PORT.key() + "' - port must be in [1, 65535]");
		}

		this.resourceManagerRpcUrl = AkkaRpcServiceUtils.getRpcUrl(
			rmHost,
			rmPort,
			ResourceManager.RESOURCE_MANAGER_NAME,
			addressResolution,
			config);

		this.dispatcherRpcUrl = AkkaRpcServiceUtils.getRpcUrl(
			rmHost,
			rmPort,
			Dispatcher.DISPATCHER_NAME,
			addressResolution,
			config);

		// all well!
		successful = true;
	}
	finally {
		if (!successful) {
			// quietly undo what the parent constructor initialized
			try {
				super.close();
			} catch (Throwable ignored) {}
		}
	}
}
 
Example 8
Source File: YarnPreConfiguredMasterNonHaServices.java    From flink with Apache License 2.0 4 votes vote down vote up
/**
 * Creates new YarnPreConfiguredMasterHaServices for the given Flink and YARN configuration.
 * This constructor parses the ResourceManager address from the Flink configuration and sets
 * up the HDFS access to store recovery data in the YARN application's working directory.
 *
 * @param config     The Flink configuration of this component / process.
 * @param hadoopConf The Hadoop configuration for the YARN cluster.
 *
 * @throws IOException
 *             Thrown, if the initialization of the Hadoop file system used by YARN fails.
 * @throws IllegalConfigurationException
 *             Thrown, if the Flink configuration does not properly describe the ResourceManager address and port.
 */
public YarnPreConfiguredMasterNonHaServices(
		Configuration config,
		org.apache.hadoop.conf.Configuration hadoopConf,
		HighAvailabilityServicesUtils.AddressResolution addressResolution) throws IOException {

	super(config, hadoopConf);

	// track whether we successfully perform the initialization
	boolean successful = false;

	try {
		// extract the hostname and port of the resource manager
		final String rmHost = config.getString(YarnConfigOptions.APP_MASTER_RPC_ADDRESS);
		final int rmPort = config.getInteger(YarnConfigOptions.APP_MASTER_RPC_PORT);

		if (rmHost == null) {
			throw new IllegalConfigurationException("Config parameter '" +
					YarnConfigOptions.APP_MASTER_RPC_ADDRESS.key() + "' is missing.");
		}
		if (rmPort < 0) {
			throw new IllegalConfigurationException("Config parameter '" +
					YarnConfigOptions.APP_MASTER_RPC_PORT.key() + "' is missing.");
		}
		if (rmPort <= 0 || rmPort >= 65536) {
			throw new IllegalConfigurationException("Invalid value for '" +
					YarnConfigOptions.APP_MASTER_RPC_PORT.key() + "' - port must be in [1, 65535]");
		}

		this.resourceManagerRpcUrl = AkkaRpcServiceUtils.getRpcUrl(
			rmHost,
			rmPort,
			ResourceManager.RESOURCE_MANAGER_NAME,
			addressResolution,
			config);

		this.dispatcherRpcUrl = AkkaRpcServiceUtils.getRpcUrl(
			rmHost,
			rmPort,
			Dispatcher.DISPATCHER_NAME,
			addressResolution,
			config);

		// all well!
		successful = true;
	}
	finally {
		if (!successful) {
			// quietly undo what the parent constructor initialized
			try {
				super.close();
			} catch (Throwable ignored) {}
		}
	}
}