org.apache.storm.utils.Utils.parseJson()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(4.1k)|赞(0)|评价(0)|浏览(112)

本文整理了Java中org.apache.storm.utils.Utils.parseJson()方法的一些代码示例,展示了Utils.parseJson()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Utils.parseJson()方法的具体详情如下:
包路径:org.apache.storm.utils.Utils
类名称:Utils
方法名:parseJson

Utils.parseJson介绍

暂无

代码示例

代码示例来源:origin: apache/storm

@Override
  public Object parse(String value) {
    if (value == null) {
      throw new RuntimeException("No arguments found for topology config override!");
    }
    try {
      return Utils.parseJson(value);
    } catch (Exception e) {
      throw new RuntimeException("Error trying to parse topology config override", e);
    }
  }
}

代码示例来源:origin: apache/storm

/**
 * return the current component configuration.
 *
 * @return the current configuration.
 */
@Override
public Map<String, Object> getComponentConfiguration() {
  return parseJson(commons.get(id).get_json_conf());
}

代码示例来源:origin: apache/storm

@SuppressWarnings("unchecked")
@Override
public T addResource(String resourceName, Number resourceValue) {
  Map<String, Object> componentConf = parseJson(commons.get(id).get_json_conf());
  Map<String, Double> resourcesMap = (Map<String, Double>) componentConf.computeIfAbsent(
    Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, (k) -> new HashMap<>());
  resourcesMap.put(resourceName, resourceValue.doubleValue());
  return addConfiguration(Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, resourcesMap);
}

代码示例来源:origin: apache/storm

@Override
public T addResources(Map<String, Double> resources) {
  if (resources != null && !resources.isEmpty()) {
    String currConf = commons.get(id).get_json_conf();
    Map<String, Object> conf = parseJson(currConf);
    Map<String, Double> currentResources =
      (Map<String, Double>) conf.computeIfAbsent(Config.TOPOLOGY_COMPONENT_RESOURCES_MAP, (k) -> new HashMap<>());
    currentResources.putAll(resources);
    commons.get(id).set_json_conf(JSONValue.toJSONString(conf));
  }
  return (T) this;
}

代码示例来源:origin: apache/storm

@SuppressWarnings("unchecked")
@Override
public T addConfigurations(Map<String, Object> conf) {
  if (conf != null) {
    if (conf.containsKey(Config.TOPOLOGY_KRYO_REGISTER)) {
      throw new IllegalArgumentException("Cannot set serializations for a component using fluent API");
    }
    if (!conf.isEmpty()) {
      String currConf = commons.get(id).get_json_conf();
      commons.get(id).set_json_conf(mergeIntoJson(parseJson(currConf), conf));
    }
  }
  return (T) this;
}

代码示例来源:origin: apache/storm

@Override
  public Object parse(String value) {
    if (value == null) {
      throw new RuntimeException("No arguments found for topology resources override!");
    }
    try {
      //This is a bit ugly The JSON we are expecting should be in the form
      // {"component": {"resource": value, ...}, ...}
      // But because value is coming from JSON it is going to be a Number, and we want it to be a Double.
      // So the goal is to go through each entry and update it accordingly
      Map<String, Map<String, Double>> ret = new HashMap<>();
      for (Map.Entry<String, Object> compEntry : Utils.parseJson(value).entrySet()) {
        String comp = compEntry.getKey();
        Map<String, Number> numResources = (Map<String, Number>) compEntry.getValue();
        Map<String, Double> doubleResource = new HashMap<>();
        for (Map.Entry<String, Number> entry : numResources.entrySet()) {
          doubleResource.put(entry.getKey(), entry.getValue().doubleValue());
        }
        ret.put(comp, doubleResource);
      }
      return ret;
    } catch (Exception e) {
      throw new RuntimeException("Error trying to parse resource override", e);
    }
  }
}

代码示例来源:origin: apache/storm

private void updateBlobStore(String topoId, RebalanceOptions rbo, Subject subject)
  throws AuthorizationException, IOException, KeyNotFoundException {
  Map<String, Map<String, Double>> resourceOverrides = rbo.get_topology_resources_overrides();
  if (resourceOverrides != null && !resourceOverrides.isEmpty()) {
    updateTopologyResources(topoId, resourceOverrides, subject);
  }
  String confOverride = rbo.get_topology_conf_overrides();
  if (confOverride != null && !confOverride.isEmpty()) {
    updateTopologyConf(topoId, Utils.parseJson(confOverride), subject);
  }
}

代码示例来源:origin: apache/storm

Map<String, Object> topoConfigOverrides = Utils.parseJson(options.get_topology_conf_overrides());

代码示例来源:origin: apache/storm

o = Utils.parseJson((String)o);
} catch (Exception e) {
  LOG.error("Could not parse json_conf as JSON", e);

相关文章

微信公众号

最新文章

更多

Utils类方法