Java Code Examples for com.datatorrent.stram.plan.logical.LogicalPlanConfiguration#STREAM_PREFIX

The following examples show how to use com.datatorrent.stram.plan.logical.LogicalPlanConfiguration#STREAM_PREFIX . 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: LogicalPlanSerializer.java    From Bats with Apache License 2.0 4 votes vote down vote up
public static PropertiesConfiguration convertToProperties(LogicalPlan dag)
{
  PropertiesConfiguration props = new PropertiesConfiguration();
  Collection<OperatorMeta> allOperators = dag.getAllOperators();

  for (OperatorMeta operatorMeta : allOperators) {
    String operatorKey = LogicalPlanConfiguration.OPERATOR_PREFIX + operatorMeta.getName();
    Operator operator = operatorMeta.getOperator();
    props.setProperty(operatorKey + "." + LogicalPlanConfiguration.OPERATOR_CLASSNAME, operator.getClass().getName());
    BeanMap operatorProperties = LogicalPlanConfiguration.getObjectProperties(operator);
    @SuppressWarnings("rawtypes")
    Iterator entryIterator = operatorProperties.entryIterator();
    while (entryIterator.hasNext()) {
      try {
        @SuppressWarnings("unchecked")
        Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryIterator.next();
        if (!entry.getKey().equals("class") && !entry.getKey().equals("name") && entry.getValue() != null) {
          props.setProperty(operatorKey + "." + entry.getKey(), entry.getValue());
        }
      } catch (Exception ex) {
        LOG.warn("Error trying to get a property of operator {}", operatorMeta.getName(), ex);
      }
    }
  }
  Collection<StreamMeta> allStreams = dag.getAllStreams();

  for (StreamMeta streamMeta : allStreams) {
    String streamKey = LogicalPlanConfiguration.STREAM_PREFIX + streamMeta.getName();
    OutputPortMeta source = streamMeta.getSource();
    Collection<InputPortMeta> sinks = streamMeta.getSinks();
    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SOURCE, source.getOperatorMeta().getName() + "." + source.getPortName());
    String sinksValue = "";
    for (InputPortMeta sink : sinks) {
      if (!sinksValue.isEmpty()) {
        sinksValue += ",";
      }
      sinksValue += sink.getOperatorMeta().getName() + "." + sink.getPortName();
    }
    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SINKS, sinksValue);
    if (streamMeta.getLocality() != null) {
      props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_LOCALITY, streamMeta.getLocality().name());
    }
  }

  // TBD: Attributes

  return props;
}
 
Example 2
Source File: LogicalPlanSerializer.java    From Bats with Apache License 2.0 4 votes vote down vote up
public static PropertiesConfiguration convertToProperties(JSONObject json) throws JSONException
{
  PropertiesConfiguration props = new PropertiesConfiguration();
  JSONArray allOperators = json.getJSONArray("operators");
  JSONArray allStreams = json.getJSONArray("streams");

  for (int j = 0; j < allOperators.length(); j++) {
    JSONObject operatorDetail = allOperators.getJSONObject(j);
    String operatorName = operatorDetail.getString("name");
    String operatorKey = LogicalPlanConfiguration.OPERATOR_PREFIX + operatorName;
    props.setProperty(operatorKey + ".classname", operatorDetail.getString("class"));
    JSONObject properties = operatorDetail.optJSONObject("properties");
    if (properties != null) {
      Iterator<String> iter2 = properties.keys();
      while (iter2.hasNext()) {
        String propertyName = iter2.next();
        if (!propertyName.equals("name") && !propertyName.equals("class") && properties.opt(propertyName) != null) {
          JSONArray list = properties.optJSONArray(propertyName);
          String value = "";
          if (list != null) {
            for (int i = 0; i < list.length(); i++) {
              if (i != 0) {
                value += ",";
              }
              value += list.get(i).toString();
            }
            props.setProperty(operatorKey + "." + propertyName, value);
          } else {
            props.setProperty(operatorKey + "." + propertyName, properties.get(propertyName));
          }
        }
      }
    }
  }

  for (int j = 0; j < allStreams.length(); j++) {
    JSONObject streamDetail = allStreams.getJSONObject(j);
    String streamName = streamDetail.getString("name");
    String streamKey = LogicalPlanConfiguration.STREAM_PREFIX + streamName;
    JSONObject sourceDetail = streamDetail.getJSONObject("source");
    JSONArray sinksList = streamDetail.getJSONArray("sinks");

    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SOURCE, sourceDetail.getString("operatorName") + "." + sourceDetail.getString("portName"));
    String sinksValue = "";
    for (int i = 0; i < sinksList.length(); i++) {
      if (!sinksValue.isEmpty()) {
        sinksValue += ",";
      }
      sinksValue += sinksList.getJSONObject(i).getString("operatorName") + "." + sinksList.getJSONObject(i).getString("portName");
    }
    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SINKS, sinksValue);
    String locality = streamDetail.optString("locality", null);
    if (locality != null) {
      props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_LOCALITY, Locality.valueOf(locality));
    }
  }

  // TBD: Attributes

  return props;
}
 
Example 3
Source File: LogicalPlanSerializer.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
public static PropertiesConfiguration convertToProperties(LogicalPlan dag)
{
  PropertiesConfiguration props = new PropertiesConfiguration();
  Collection<OperatorMeta> allOperators = dag.getAllOperators();

  for (OperatorMeta operatorMeta : allOperators) {
    String operatorKey = LogicalPlanConfiguration.OPERATOR_PREFIX + operatorMeta.getName();
    Operator operator = operatorMeta.getOperator();
    props.setProperty(operatorKey + "." + LogicalPlanConfiguration.OPERATOR_CLASSNAME, operator.getClass().getName());
    BeanMap operatorProperties = LogicalPlanConfiguration.getObjectProperties(operator);
    @SuppressWarnings("rawtypes")
    Iterator entryIterator = operatorProperties.entryIterator();
    while (entryIterator.hasNext()) {
      try {
        @SuppressWarnings("unchecked")
        Map.Entry<String, Object> entry = (Map.Entry<String, Object>)entryIterator.next();
        if (!entry.getKey().equals("class") && !entry.getKey().equals("name") && entry.getValue() != null) {
          props.setProperty(operatorKey + "." + entry.getKey(), entry.getValue());
        }
      } catch (Exception ex) {
        LOG.warn("Error trying to get a property of operator {}", operatorMeta.getName(), ex);
      }
    }
  }
  Collection<StreamMeta> allStreams = dag.getAllStreams();

  for (StreamMeta streamMeta : allStreams) {
    String streamKey = LogicalPlanConfiguration.STREAM_PREFIX + streamMeta.getName();
    OutputPortMeta source = streamMeta.getSource();
    Collection<InputPortMeta> sinks = streamMeta.getSinks();
    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SOURCE, source.getOperatorMeta().getName() + "." + source.getPortName());
    String sinksValue = "";
    for (InputPortMeta sink : sinks) {
      if (!sinksValue.isEmpty()) {
        sinksValue += ",";
      }
      sinksValue += sink.getOperatorMeta().getName() + "." + sink.getPortName();
    }
    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SINKS, sinksValue);
    if (streamMeta.getLocality() != null) {
      props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_LOCALITY, streamMeta.getLocality().name());
    }
  }

  // TBD: Attributes

  return props;
}
 
Example 4
Source File: LogicalPlanSerializer.java    From attic-apex-core with Apache License 2.0 4 votes vote down vote up
public static PropertiesConfiguration convertToProperties(JSONObject json) throws JSONException
{
  PropertiesConfiguration props = new PropertiesConfiguration();
  JSONArray allOperators = json.getJSONArray("operators");
  JSONArray allStreams = json.getJSONArray("streams");

  for (int j = 0; j < allOperators.length(); j++) {
    JSONObject operatorDetail = allOperators.getJSONObject(j);
    String operatorName = operatorDetail.getString("name");
    String operatorKey = LogicalPlanConfiguration.OPERATOR_PREFIX + operatorName;
    props.setProperty(operatorKey + ".classname", operatorDetail.getString("class"));
    JSONObject properties = operatorDetail.optJSONObject("properties");
    if (properties != null) {
      Iterator<String> iter2 = properties.keys();
      while (iter2.hasNext()) {
        String propertyName = iter2.next();
        if (!propertyName.equals("name") && !propertyName.equals("class") && properties.opt(propertyName) != null) {
          JSONArray list = properties.optJSONArray(propertyName);
          String value = "";
          if (list != null) {
            for (int i = 0; i < list.length(); i++) {
              if (i != 0) {
                value += ",";
              }
              value += list.get(i).toString();
            }
            props.setProperty(operatorKey + "." + propertyName, value);
          } else {
            props.setProperty(operatorKey + "." + propertyName, properties.get(propertyName));
          }
        }
      }
    }
  }

  for (int j = 0; j < allStreams.length(); j++) {
    JSONObject streamDetail = allStreams.getJSONObject(j);
    String streamName = streamDetail.getString("name");
    String streamKey = LogicalPlanConfiguration.STREAM_PREFIX + streamName;
    JSONObject sourceDetail = streamDetail.getJSONObject("source");
    JSONArray sinksList = streamDetail.getJSONArray("sinks");

    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SOURCE, sourceDetail.getString("operatorName") + "." + sourceDetail.getString("portName"));
    String sinksValue = "";
    for (int i = 0; i < sinksList.length(); i++) {
      if (!sinksValue.isEmpty()) {
        sinksValue += ",";
      }
      sinksValue += sinksList.getJSONObject(i).getString("operatorName") + "." + sinksList.getJSONObject(i).getString("portName");
    }
    props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_SINKS, sinksValue);
    String locality = streamDetail.optString("locality", null);
    if (locality != null) {
      props.setProperty(streamKey + "." + LogicalPlanConfiguration.STREAM_LOCALITY, Locality.valueOf(locality));
    }
  }

  // TBD: Attributes

  return props;
}