Java Code Examples for com.typesafe.config.Config#isEmpty()

The following examples show how to use com.typesafe.config.Config#isEmpty() . 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: EventTimeHistoryPlanner.java    From envelope with Apache License 2.0 6 votes vote down vote up
private TimeModel getTimeModel(Config timeModelConfig, List<String> fieldNames, boolean configure) {
  TimeModel timeModel;

  if (!timeModelConfig.isEmpty()) {
    timeModel = ComponentFactory.create(TimeModel.class, timeModelConfig, configure);
  }
  else {
    timeModel = new LongMillisTimeModel();
  }

  if (configure) {
    timeModel.configureFieldNames(fieldNames);
  }

  return timeModel;
}
 
Example 2
Source File: BitemporalHistoryPlanner.java    From envelope with Apache License 2.0 6 votes vote down vote up
private TimeModel getTimeModel(Config timeModelConfig, List<String> fieldNames, boolean configure) {
  TimeModel timeModel;

  if (!timeModelConfig.isEmpty()) {
    timeModel = ComponentFactory.create(TimeModel.class, timeModelConfig, configure);
  }
  else {
    timeModel = new LongMillisTimeModel();
  }

  if (configure) {
    timeModel.configureFieldNames(fieldNames);
  }

  return timeModel;
}
 
Example 3
Source File: EventTimeUpsertPlanner.java    From envelope with Apache License 2.0 6 votes vote down vote up
private TimeModel getTimeModel(Config timeModelConfig, List<String> fieldNames, boolean configure) {
  TimeModel timeModel;

  if (!timeModelConfig.isEmpty()) {
    timeModel = ComponentFactory.create(TimeModel.class, timeModelConfig, configure);
  }
  else {
    timeModel = new LongMillisTimeModel();
  }

  if (configure) {
    timeModel.configureFieldNames(fieldNames);
  }

  return timeModel;
}
 
Example 4
Source File: JobExecutionPlan.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * A method to add any additional configurations to a JobSpec which need to be passed to the {@link SpecExecutor}.
 * This enables {@link org.apache.gobblin.metrics.GobblinTrackingEvent}s
 * to be emitted from each Gobblin job orchestrated by Gobblin-as-a-Service, which will then be used for tracking the
 * execution status of the job.
 * @param jobSpec representing a fully resolved {@link JobSpec}.
 */
private static void addAdditionalConfig(JobSpec jobSpec, Config sysConfig) {
  if (!(sysConfig.hasPath(ConfigurationKeys.SPECEXECUTOR_CONFIGS_PREFIX_KEY)
      && !Strings.isNullOrEmpty(ConfigUtils.getString(sysConfig, ConfigurationKeys.SPECEXECUTOR_CONFIGS_PREFIX_KEY, ""))
      && sysConfig.hasPath(sysConfig.getString(ConfigurationKeys.SPECEXECUTOR_CONFIGS_PREFIX_KEY)))) {
    return;
  }

  String additionalConfigsPrefix = sysConfig.getString(ConfigurationKeys.SPECEXECUTOR_CONFIGS_PREFIX_KEY);

  Config config = jobSpec.getConfig().withFallback(ConfigUtils.getConfigOrEmpty(sysConfig, additionalConfigsPrefix));

  if (!config.isEmpty()) {
    jobSpec.setConfig(config);
  }
}
 
Example 5
Source File: JobExecutionPlan.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * A method to add tracking event configurations to a JobSpec.
 * This enables {@link org.apache.gobblin.metrics.GobblinTrackingEvent}s
 * to be emitted from each Gobblin job orchestrated by Gobblin-as-a-Service, which will then be used for tracking the
 * execution status of the job.
 * @param jobSpec representing a fully resolved {@link JobSpec}.
 */
private static void addTrackingEventConfig(JobSpec jobSpec, Config sysConfig) {
  Config reportingConfig = ConfigUtils.getConfig(sysConfig, ConfigurationKeys.METRICS_REPORTING_CONFIGURATIONS_PREFIX, ConfigFactory.empty());
  if (!reportingConfig.isEmpty()) {
    Config jobConfig = jobSpec.getConfig().withFallback(reportingConfig.atPath(ConfigurationKeys.METRICS_REPORTING_CONFIGURATIONS_PREFIX));
    boolean isSchemaRegistryEnabled = ConfigUtils.getBoolean(sysConfig, ConfigurationKeys.METRICS_REPORTING_KAFKA_USE_SCHEMA_REGISTRY, false);
    if (isSchemaRegistryEnabled) {
      String schemaRegistryUrl = ConfigUtils.getString(sysConfig, KafkaSchemaRegistry.KAFKA_SCHEMA_REGISTRY_URL, "");
      if (!Strings.isNullOrEmpty(schemaRegistryUrl)) {
        jobConfig = jobConfig.withValue(KafkaSchemaRegistry.KAFKA_SCHEMA_REGISTRY_URL, ConfigValueFactory.fromAnyRef(schemaRegistryUrl));
      }
      String schemaOverrideNamespace = ConfigUtils
          .getString(sysConfig, KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_OVERRIDE_NAMESPACE, "");
      if (!Strings.isNullOrEmpty(schemaOverrideNamespace)) {
        jobConfig = jobConfig.withValue(KafkaSchemaRegistryConfigurationKeys.KAFKA_SCHEMA_REGISTRY_OVERRIDE_NAMESPACE,
            ConfigValueFactory.fromAnyRef(schemaOverrideNamespace));
      }
    }
    jobSpec.setConfig(jobConfig);
  }
}
 
Example 6
Source File: SecureJobTemplate.java    From incubator-gobblin with Apache License 2.0 6 votes vote down vote up
/**
 * Filter the user config to only preserve the keys allowed by a secure template.
 */
static Config filterUserConfig(SecureJobTemplate template, Config userConfig, Logger logger) {
	if (!template.isSecure()) {
		return userConfig;
	}
	Config survivingConfig = ConfigFactory.empty();
	for (String key : template.overridableProperties()) {
		if (userConfig.hasPath(key)) {
			survivingConfig = survivingConfig.withValue(key, userConfig.getValue(key));
			userConfig = userConfig.withoutPath(key);
		}
	}

	if (!userConfig.isEmpty()) {
		logger.warn(String.format("Secure template %s ignored the following keys because they are not overridable: %s",
				template.getUri().toString(),
				userConfig.entrySet().stream().map(Map.Entry::getKey).collect(Collectors.joining(", "))));
	}

	return survivingConfig;
}
 
Example 7
Source File: ConfigUtil.java    From sunbird-lms-service with MIT License 4 votes vote down vote up
public static Config getConfigFromJsonString(String jsonString, String configType) {
  ProjectLogger.log("ConfigUtil: getConfigFromJsonString called", LoggerEnum.DEBUG.name());

  if (null == jsonString || StringUtils.isBlank(jsonString)) {
    ProjectLogger.log(
        "ConfigUtil:getConfigFromJsonString: Empty string", LoggerEnum.ERROR.name());
    ProjectCommonException.throwServerErrorException(
        ResponseCode.errorConfigLoadEmptyString,
        ProjectUtil.formatMessage(
            ResponseCode.errorConfigLoadEmptyString.getErrorMessage(), configType));
  }

  Config jsonConfig = null;
  try {
    jsonConfig = ConfigFactory.parseString(jsonString);
  } catch (Exception e) {
    ProjectLogger.log(
        "ConfigUtil:getConfigFromJsonString: Exception occurred during parse with error message = "
            + e.getMessage(),
        LoggerEnum.ERROR.name());
    ProjectCommonException.throwServerErrorException(
        ResponseCode.errorConfigLoadParseString,
        ProjectUtil.formatMessage(
            ResponseCode.errorConfigLoadParseString.getErrorMessage(), configType));
  }

  if (null == jsonConfig || jsonConfig.isEmpty()) {
    ProjectLogger.log(
        "ConfigUtil:getConfigFromJsonString: Empty configuration", LoggerEnum.ERROR.name());
    ProjectCommonException.throwServerErrorException(
        ResponseCode.errorConfigLoadEmptyConfig,
        ProjectUtil.formatMessage(
            ResponseCode.errorConfigLoadEmptyConfig.getErrorMessage(), configType));
  }

  ProjectLogger.log(
      "ConfigUtil:getConfigFromJsonString: Successfully constructed type safe configuration",
      LoggerEnum.DEBUG.name());

  return jsonConfig;
}