[ 
https://issues.apache.org/jira/browse/STORM-72?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13848746#comment-13848746
 ] 

caofangkun commented on STORM-72:
---------------------------------

StormSubmitter.java  or Utils.readCommandLineOpts() shoud also do the number 
check:

https://github.com/nathanmarz/storm/blob/master/storm-core/src/jvm/backtype/storm/StormSubmitter.java#L78
https://github.com/nathanmarz/storm/blob/master/storm-core/src/jvm/backtype/storm/utils/Utils.java#L157

{code:title=StormSubmitter.java|borderStyle=solid}
storm-core/src/jvm/backtype/storm/StormSubmitter.java
@@ -9,6 +9,7 @@
  import java.util.Map;
  import org.slf4j.Logger;
  import org.slf4j.LoggerFactory;
 +import org.apache.commons.lang.math.NumberUtils;
  import org.apache.thrift7.TException;
  import org.json.simple.JSONValue;
  
 @@ -59,6 +60,12 @@ public static void submitTopology(String name, Map 
stormConf, StormTopology topo
          }
          stormConf = new HashMap(stormConf);
          stormConf.putAll(Utils.readCommandLineOpts());
     +  for (Object confName : stormConf.keySet()) {
     +    String confValue = String.valueOf(stormConf.get(confName));
     +    if (NumberUtils.isNumber(confValue)) {
     +      stormConf.put(confName, NumberUtils.createNumber(confValue));
     +    }
     +  }
          Map conf = Utils.readStormConfig();
          conf.putAll(stormConf);
          try {
{code}

> Storm Conf convert value to int fail
> ------------------------------------
>
>                 Key: STORM-72
>                 URL: https://issues.apache.org/jira/browse/STORM-72
>             Project: Apache Storm (Incubating)
>          Issue Type: Improvement
>            Reporter: James Xu
>            Priority: Minor
>
> https://github.com/nathanmarz/storm/issues/588
>  ./storm jar my.jar my.MainClass args1=argsValue1 ... -c 
> nimbus.thirft.port=7777
> so my stormConf will include a hash entry['nimbus.thirft.port']='7777'
> but the method of util convert Object to int has a bug:
> https://github.com/nathanmarz/storm/blob/master/storm-core/src/jvm/backtype/storm/utils/Utils.java#L270
>     public static Integer getInt(Object o) {
>         if(o instanceof Long) {
>             return ((Long) o ).intValue();
>         } else if (o instanceof Integer) {
>             return (Integer) o;
>         } else if (o instanceof Short) {
>             return ((Short) o).intValue();
>         } else {
>             throw new IllegalArgumentException("Don't know how to convert " + 
> o + " + to int");
>         }
>     }
> call from
> https://github.com/nathanmarz/storm/blob/master/storm-core/src/jvm/backtype/storm/utils/NimbusClient.java#L18
>     public static NimbusClient getConfiguredClient(Map conf) {
>         try {
>             String nimbusHost = (String) conf.get(Config.NIMBUS_HOST);
>             int nimbusPort = 
> Utils.getInt(conf.get(Config.NIMBUS_THRIFT_PORT));
>             return new NimbusClient(conf, nimbusHost, nimbusPort);
>         } catch (TTransportException ex) {
>             throw new RuntimeException(ex);
>         }
>     }
> my mind add code:
>        else if (o instanceof String) {
>             return Integer.valueOf((String) o);
>         }
>     public static Integer getInt(Object o) {
>         if(o instanceof Long) {
>             return ((Long) o ).intValue();
>         } else if (o instanceof Integer) {
>             return (Integer) o;
>         } else if (o instanceof Short) {
>             return ((Short) o).intValue();
>         } else if (o instanceof String) {
>             return Integer.valueOf((String) o);
>         } else {
>             throw new IllegalArgumentException("Don't know how to convert " + 
> o + " + to int");
>         }
>     }



--
This message was sent by Atlassian JIRA
(v6.1.4#6159)

Reply via email to