Java Code Examples for org.apache.flink.configuration.Configuration#containsKey()

The following examples show how to use org.apache.flink.configuration.Configuration#containsKey() . 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: BootstrapTools.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
* Sets the value of a new config key to the value of a deprecated config key. Taking into
* account the changed prefix.
* @param config Config to write
* @param deprecatedPrefix Old prefix of key
* @param designatedPrefix New prefix of key
*/
public static void substituteDeprecatedConfigPrefix(
		Configuration config,
		String deprecatedPrefix,
		String designatedPrefix) {

	// set the designated key only if it is not set already
	final int prefixLen = deprecatedPrefix.length();

	Configuration replacement = new Configuration();

	for (String key : config.keySet()) {
		if (key.startsWith(deprecatedPrefix)) {
			String newKey = designatedPrefix + key.substring(prefixLen);
			if (!config.containsKey(newKey)) {
				replacement.setString(newKey, config.getString(key, null));
			}
		}
	}

	config.addAll(replacement);
}
 
Example 2
Source File: BootstrapTools.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
* Sets the value of a new config key to the value of a deprecated config key. Taking into
* account the changed prefix.
* @param config Config to write
* @param deprecatedPrefix Old prefix of key
* @param designatedPrefix New prefix of key
*/
public static void substituteDeprecatedConfigPrefix(
		Configuration config,
		String deprecatedPrefix,
		String designatedPrefix) {

	// set the designated key only if it is not set already
	final int prefixLen = deprecatedPrefix.length();

	Configuration replacement = new Configuration();

	for (String key : config.keySet()) {
		if (key.startsWith(deprecatedPrefix)) {
			String newKey = designatedPrefix + key.substring(prefixLen);
			if (!config.containsKey(newKey)) {
				replacement.setString(newKey, config.getString(key, null));
			}
		}
	}

	config.addAll(replacement);
}
 
Example 3
Source File: BootstrapTools.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
* Sets the value of a new config key to the value of a deprecated config key. Taking into
* account the changed prefix.
* @param config Config to write
* @param deprecatedPrefix Old prefix of key
* @param designatedPrefix New prefix of key
*/
public static void substituteDeprecatedConfigPrefix(
		Configuration config,
		String deprecatedPrefix,
		String designatedPrefix) {

	// set the designated key only if it is not set already
	final int prefixLen = deprecatedPrefix.length();

	Configuration replacement = new Configuration();

	for (String key : config.keySet()) {
		if (key.startsWith(deprecatedPrefix)) {
			String newKey = designatedPrefix + key.substring(prefixLen);
			if (!config.containsKey(newKey)) {
				replacement.setString(newKey, config.getString(key, null));
			}
		}
	}

	config.addAll(replacement);
}
 
Example 4
Source File: StsParamValidateUtil.java    From alibaba-flink-connectors with Apache License 2.0 5 votes vote down vote up
public static String stsValidate(String accessId, String accessKey, String localErrorMsg, Configuration properties) {
	String stsRoleArn = properties.getString(BlinkOptions.STS.STS_ROLE_ARN);
	String stsAccessId = properties.getString(BlinkOptions.STS.STS_ACCESS_ID);
	String stsAccessKey = properties.getString(BlinkOptions.STS.STS_ACCESS_KEY);
	String stsUid = properties.getString(BlinkOptions.STS.STS_UID);
	if (BlinkStringUtil.isNotEmpty(accessId, accessKey) || BlinkStringUtil.isNotEmpty(stsRoleArn, stsAccessId, stsAccessKey, stsUid)){
		return null;
	} else if (properties.containsKey(BlinkOptions.STS.STS_ROLE_ARN.key())){
		throw new NotEnoughParamsException(String.format("Lack necessary arguments: {0}", BlinkOptions.STS.STS_PARAMS_HELP_MSG));
	} else {
		throw new NotEnoughParamsException(localErrorMsg);
	}
}
 
Example 5
Source File: BootstrapTools.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
/**
* Sets the value of a new config key to the value of a deprecated config key.
* @param config Config to write
* @param deprecated The old config key
* @param designated The new config key
*/
public static void substituteDeprecatedConfigKey(Configuration config, String deprecated, String designated) {
	// set the designated key only if it is not set already
	if (!config.containsKey(designated)) {
		final String valueForDeprecated = config.getString(deprecated, null);
		if (valueForDeprecated != null) {
			config.setString(designated, valueForDeprecated);
		}
	}
}
 
Example 6
Source File: BootstrapTools.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
* Sets the value of a new config key to the value of a deprecated config key.
* @param config Config to write
* @param deprecated The old config key
* @param designated The new config key
*/
public static void substituteDeprecatedConfigKey(Configuration config, String deprecated, String designated) {
	// set the designated key only if it is not set already
	if (!config.containsKey(designated)) {
		final String valueForDeprecated = config.getString(deprecated, null);
		if (valueForDeprecated != null) {
			config.setString(designated, valueForDeprecated);
		}
	}
}
 
Example 7
Source File: FlinkExecutionEnvironments.java    From beam with Apache License 2.0 5 votes vote down vote up
private static void setManagedMemoryByFraction(final Configuration config) {
  if (!config.containsKey("taskmanager.memory.managed.size")) {
    float managedMemoryFraction = config.getFloat(TaskManagerOptions.MANAGED_MEMORY_FRACTION);
    long freeHeapMemory = EnvironmentInformation.getSizeOfFreeHeapMemoryWithDefrag();
    long managedMemorySize = (long) (freeHeapMemory * managedMemoryFraction);
    config.setString("taskmanager.memory.managed.size", String.valueOf(managedMemorySize));
  }
}
 
Example 8
Source File: AbstractStatelessFunctionOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
private Map<String, String> buildJobOptions(Configuration config) {
	Map<String, String> jobOptions = new HashMap<>();
	if (config.containsKey("table.exec.timezone")) {
		jobOptions.put("table.exec.timezone", config.getString("table.exec.timezone", null));
	}
	return jobOptions;
}
 
Example 9
Source File: AbstractPythonStatelessFunctionFlatMap.java    From flink with Apache License 2.0 5 votes vote down vote up
private Map<String, String> buildJobOptions(Configuration config) {
	Map<String, String> jobOptions = new HashMap<>();
	if (config.containsKey("table.exec.timezone")) {
		jobOptions.put("table.exec.timezone", config.getString("table.exec.timezone", null));
	}
	return jobOptions;
}
 
Example 10
Source File: BootstrapTools.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
* Sets the value of a new config key to the value of a deprecated config key.
* @param config Config to write
* @param deprecated The old config key
* @param designated The new config key
*/
public static void substituteDeprecatedConfigKey(Configuration config, String deprecated, String designated) {
	// set the designated key only if it is not set already
	if (!config.containsKey(designated)) {
		final String valueForDeprecated = config.getString(deprecated, null);
		if (valueForDeprecated != null) {
			config.setString(designated, valueForDeprecated);
		}
	}
}
 
Example 11
Source File: StsServiceRequest.java    From alibaba-flink-connectors with Apache License 2.0 4 votes vote down vote up
public static AssumeRoleResponse assumeRoleWithServiceIdentity(
			final String streamAccessId, final String streamAccessKey,
			final String roleArn, final String roleSessionName,
			final String assumeRoleFor,
			Configuration properties) throws Exception {
		//decode
		String decodeKey = DecodeUtil.decrypt(streamAccessKey, StsConstants.STS_SECRET_KEY);

		String regionId = properties.getString(BlinkOptions.STS.STS_REGION_ID);

		// 创建一个 Aliyun Acs Client, 用于发起 OpenAPI 请求
		IClientProfile profile = DefaultProfile.getProfile(
				regionId, streamAccessId, decodeKey);
		DefaultAcsClient client = new DefaultAcsClient(profile);

		// endPoints format:   endPointName#regionId#product#domain,endPointName1#regionId1#product1#domain1
		if (properties.containsKey(INNER_STS_ENDPOINT) && properties.getString(INNER_STS_ENDPOINT, null) != null){
			String endPoints = properties.toMap().get(INNER_STS_ENDPOINT);
			if (!endPoints.isEmpty()) {
				String[] endPointItem = endPoints.split(",");
				for (String item : endPointItem) {
					String[] partItems = item.split("#");
					if (null != partItems && partItems.length == 4) {
						DefaultProfile.addEndpoint(partItems[0], partItems[1], partItems[2], partItems[3]);
					}
				}
			}
		}

		// 创建一个 AssumeRoleRequest 并设置请求参数
		final AssumeRoleRequest request = new AssumeRoleRequest();
		request.setMethod(MethodType.POST);

		request.setProtocol(PROTOCOL_TYPE);
		request.setDurationSeconds(DURATION);
		request.setRoleArn(roleArn);
		request.setRoleSessionName(roleSessionName);
//		request.setAssumeRoleFor(assumeRoleFor);
		X509TrustAll.ignoreSSLCertificate();
		// 发起请求,并得到response
		final AssumeRoleResponse response = client.getAcsResponse(request);

		return response;
	}