Esempio n. 1
0
 @Override
 public List<? extends Object> getAnyRefList(String path) {
   List<Object> l = new ArrayList<Object>();
   List<? extends ConfigValue> list = getList(path);
   for (ConfigValue v : list) {
     l.add(v.unwrapped());
   }
   return l;
 }
Esempio n. 2
0
 @Override
 public boolean hasPath(String pathExpression) {
   Path path = Path.newPath(pathExpression);
   ConfigValue peeked;
   try {
     peeked = object.peekPath(path);
   } catch (ConfigException.NotResolved e) {
     throw ConfigImpl.improveNotResolved(path, e);
   }
   return peeked != null && peeked.valueType() != ConfigValueType.NULL;
 }
Esempio n. 3
0
 @Override
 public Long getNanoseconds(String path) {
   Long ns = null;
   try {
     ns = TimeUnit.MILLISECONDS.toNanos(getLong(path));
   } catch (ConfigException.WrongType e) {
     ConfigValue v = find(path, ConfigValueType.STRING);
     ns = parseDuration((String) v.unwrapped(), v.origin(), path);
   }
   return ns;
 }
Esempio n. 4
0
 private Conf() {
   Config config = ConfigFactory.load("taskCluster");
   // cluster list
   ConfigList list = config.getList("taskCluster.clusterList");
   for (ConfigValue configValue : list) {
     Config config1 = configValue.atPath("cluster").getConfig("cluster");
     clusterMap.put(
         config1.getString("name"),
         config1.getString("ip") + ":" + config1.getString("port") + config1.getString("url"));
   }
 }
Esempio n. 5
0
 @Override
 public Long getBytes(String path) {
   Long size = null;
   try {
     size = getLong(path);
   } catch (ConfigException.WrongType e) {
     ConfigValue v = find(path, ConfigValueType.STRING);
     size = parseBytes((String) v.unwrapped(), v.origin(), path);
   }
   return size;
 }
Esempio n. 6
0
 @Override
 public String toString() {
   StringBuilder sb = new StringBuilder();
   sb.append(valueType().name());
   sb.append("(");
   for (ConfigValue e : value) {
     sb.append(e.toString());
     sb.append(",");
   }
   if (!value.isEmpty()) sb.setLength(sb.length() - 1); // chop comma
   sb.append(")");
   return sb.toString();
 }
Esempio n. 7
0
 private static boolean haveCompatibleTypes(ConfigValue reference, AbstractConfigValue value) {
   if (couldBeNull((AbstractConfigValue) reference) || couldBeNull(value)) {
     // we allow any setting to be null
     return true;
   } else if (reference instanceof AbstractConfigObject) {
     if (value instanceof AbstractConfigObject) {
       return true;
     } else {
       return false;
     }
   } else if (reference instanceof SimpleConfigList) {
     if (value instanceof SimpleConfigList) {
       return true;
     } else {
       return false;
     }
   } else if (reference instanceof ConfigString) {
     // assume a string could be gotten as any non-collection type;
     // allows things like getMilliseconds including domain-specific
     // interpretations of strings
     return true;
   } else if (value instanceof ConfigString) {
     // assume a string could be gotten as any non-collection type
     return true;
   } else {
     if (reference.valueType() == value.valueType()) {
       return true;
     } else {
       return false;
     }
   }
 }
Esempio n. 8
0
  /**
   * Gets the exclusion set for the destination {@link ConfigValue}.
   *
   * @param destinationConfig
   * @return Exclusion Set
   */
  protected Set<String> getExclusionSet(ConfigValue destinationConfig) {
    Set<String> exclusionSet = new HashSet<String>();
    if (mapperConfig.checkIfKeyExists(
        MapperConstants.EXCLUSION_LIST_FIELD_NAME, destinationConfig)) {
      ConfigList exclusionListConfigObject =
          mapperConfig.getValueForKeyAsConfigValue(
              MapperConstants.EXCLUSION_LIST_FIELD_NAME, destinationConfig, ConfigList.class);

      exclusionSet = new HashSet<String>();

      for (ConfigValue configValue : exclusionListConfigObject) {
        if (configValue.unwrapped() != null) {
          exclusionSet.add(configValue.unwrapped().toString());
        }
      }
    }
    return exclusionSet;
  }
Esempio n. 9
0
 private static String getDesc(ConfigValue refValue) {
   if (refValue instanceof AbstractConfigObject) {
     AbstractConfigObject obj = (AbstractConfigObject) refValue;
     if (obj.isEmpty()) return "object";
     else return "object with keys " + obj.keySet();
   } else if (refValue instanceof SimpleConfigList) {
     return "list";
   } else {
     return refValue.valueType().name().toLowerCase();
   }
 }
Esempio n. 10
0
  /**
   * Gets the array of primary keys from the {@code ConfigValue} if exists, otherwise, returns the
   * primary keys of the passed source event.
   *
   * @param sourceEvent
   * @param destinationConfig
   * @return Set of primary key columns
   */
  protected Set<String> getPrimaryKeySet(AbstractEvent sourceEvent, ConfigValue destinationConfig) {
    Set<String> primaryKeySet;
    if (mapperConfig.checkIfKeyExists(
        MapperConstants.DESTINATION_PRIMARY_KEY_LIST, destinationConfig)) {
      ConfigList primaryKeyConfigObject =
          mapperConfig.getValueForKeyAsConfigValue(
              MapperConstants.DESTINATION_PRIMARY_KEY_LIST, destinationConfig, ConfigList.class);

      primaryKeySet = new HashSet<String>();

      for (ConfigValue configValue : primaryKeyConfigObject) {
        if (configValue.unwrapped() != null) {
          primaryKeySet.add(configValue.unwrapped().toString());
        }
      }
    } else {
      primaryKeySet = sourceEvent.getPrimaryKeySet();
    }
    return primaryKeySet;
  }
Esempio n. 11
0
 @Override
 public List<Long> getNanosecondsList(String path) {
   List<Long> l = new ArrayList<Long>();
   List<? extends ConfigValue> list = getList(path);
   for (ConfigValue v : list) {
     if (v.valueType() == ConfigValueType.NUMBER) {
       l.add(TimeUnit.MILLISECONDS.toNanos(((Number) v.unwrapped()).longValue()));
     } else if (v.valueType() == ConfigValueType.STRING) {
       String s = (String) v.unwrapped();
       Long n = parseDuration(s, v.origin(), path);
       l.add(n);
     } else {
       throw new ConfigException.WrongType(
           v.origin(), path, "duration string or number of nanoseconds", v.valueType().name());
     }
   }
   return l;
 }
Esempio n. 12
0
 @Override
 public List<Long> getBytesList(String path) {
   List<Long> l = new ArrayList<Long>();
   List<? extends ConfigValue> list = getList(path);
   for (ConfigValue v : list) {
     if (v.valueType() == ConfigValueType.NUMBER) {
       l.add(((Number) v.unwrapped()).longValue());
     } else if (v.valueType() == ConfigValueType.STRING) {
       String s = (String) v.unwrapped();
       Long n = parseBytes(s, v.origin(), path);
       l.add(n);
     } else {
       throw new ConfigException.WrongType(
           v.origin(), path, "memory size string or number of bytes", v.valueType().name());
     }
   }
   return l;
 }
Esempio n. 13
0
 @Override
 public Object getAnyRef(String path) {
   ConfigValue v = find(path, null);
   return v.unwrapped();
 }
Esempio n. 14
0
 @Override
 public String getString(String path) {
   ConfigValue v = find(path, ConfigValueType.STRING);
   return (String) v.unwrapped();
 }
Esempio n. 15
0
 @Override
 public boolean getBoolean(String path) {
   ConfigValue v = find(path, ConfigValueType.BOOLEAN);
   return (Boolean) v.unwrapped();
 }
Esempio n. 16
0
 public InvalidConfigException(
     final ConfigValue value, final String message, final Throwable cause) {
   super(value.origin().description() + ": " + checkNotNull(message), cause);
 }