Search in sources :

Example 1 with ParseException

use of org.apache.storm.shade.org.json.simple.parser.ParseException in project storm by apache.

the class GeneralTopologyContext method maxTopologyMessageTimeout.

public int maxTopologyMessageTimeout() {
    Integer max = ObjectReader.getInt(topoConf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS));
    for (String spout : getRawTopology().get_spouts().keySet()) {
        ComponentCommon common = getComponentCommon(spout);
        String jsonConf = common.get_json_conf();
        if (jsonConf != null) {
            try {
                Map<String, Object> conf = (Map) JSONValue.parseWithException(jsonConf);
                Object comp = conf.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS);
                max = Math.max(ObjectReader.getInt(comp, max), max);
            } catch (ParseException e) {
                throw new RuntimeException(e);
            }
        }
    }
    return max;
}
Also used : ComponentCommon(org.apache.storm.generated.ComponentCommon) ParseException(org.apache.storm.shade.org.json.simple.parser.ParseException) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with ParseException

use of org.apache.storm.shade.org.json.simple.parser.ParseException in project storm by apache.

the class DependencyPropertiesParser method parseArtifactsProperties.

public Map<String, File> parseArtifactsProperties(String prop) {
    try {
        Map<String, String> parsed = (Map<String, String>) JSONValue.parseWithException(prop);
        Map<String, File> packages = new LinkedHashMap<>(parsed.size());
        for (Map.Entry<String, String> artifactToFilePath : parsed.entrySet()) {
            packages.put(artifactToFilePath.getKey(), new File(artifactToFilePath.getValue()));
        }
        return packages;
    } catch (ParseException e) {
        throw new RuntimeException(e);
    }
}
Also used : ParseException(org.apache.storm.shade.org.json.simple.parser.ParseException) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap)

Example 3 with ParseException

use of org.apache.storm.shade.org.json.simple.parser.ParseException in project storm by apache.

the class ReturnResults method execute.

@Override
public void execute(Tuple input) {
    String result = (String) input.getValue(0);
    String returnInfo = (String) input.getValue(1);
    if (returnInfo != null) {
        Map<String, Object> retMap;
        try {
            retMap = (Map<String, Object>) JSONValue.parseWithException(returnInfo);
        } catch (ParseException e) {
            LOG.error("Parseing returnInfo failed", e);
            collector.fail(input);
            return;
        }
        final String host = (String) retMap.get("host");
        final int port = ObjectReader.getInt(retMap.get("port"));
        String id = (String) retMap.get("id");
        DistributedRPCInvocations.Iface client;
        if (local) {
            client = (DistributedRPCInvocations.Iface) ServiceRegistry.getService(host);
        } else {
            List server = new ArrayList() {

                {
                    add(host);
                    add(port);
                }
            };
            if (!clients.containsKey(server)) {
                try {
                    clients.put(server, new DRPCInvocationsClient(conf, host, port));
                } catch (TTransportException ex) {
                    throw new RuntimeException(ex);
                }
            }
            client = clients.get(server);
        }
        int retryCnt = 0;
        int maxRetries = 3;
        while (retryCnt < maxRetries) {
            retryCnt++;
            try {
                client.result(id, result);
                collector.ack(input);
                break;
            } catch (AuthorizationException aze) {
                LOG.error("Not authorized to return results to DRPC server", aze);
                collector.fail(input);
                throw new RuntimeException(aze);
            } catch (TException tex) {
                if (retryCnt >= maxRetries) {
                    LOG.error("Failed to return results to DRPC server", tex);
                    collector.fail(input);
                }
                reconnectClient((DRPCInvocationsClient) client);
            }
        }
    }
}
Also used : TException(org.apache.storm.thrift.TException) AuthorizationException(org.apache.storm.generated.AuthorizationException) ArrayList(java.util.ArrayList) DistributedRPCInvocations(org.apache.storm.generated.DistributedRPCInvocations) TTransportException(org.apache.storm.thrift.transport.TTransportException) ArrayList(java.util.ArrayList) List(java.util.List) ParseException(org.apache.storm.shade.org.json.simple.parser.ParseException)

Example 4 with ParseException

use of org.apache.storm.shade.org.json.simple.parser.ParseException in project storm by apache.

the class Utils method fromCompressedJsonConf.

public static Map<String, Object> fromCompressedJsonConf(byte[] serialized) {
    try {
        ByteArrayInputStream bis = new ByteArrayInputStream(serialized);
        InputStreamReader in = new InputStreamReader(new GZIPInputStream(bis));
        Object ret = JSONValue.parseWithException(in);
        in.close();
        return (Map<String, Object>) ret;
    } catch (IOException | ParseException e) {
        throw new RuntimeException(e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) ComponentObject(org.apache.storm.generated.ComponentObject) IOException(java.io.IOException) ParseException(org.apache.storm.shade.org.json.simple.parser.ParseException) Map(java.util.Map) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap)

Example 5 with ParseException

use of org.apache.storm.shade.org.json.simple.parser.ParseException in project storm by apache.

the class Utils method readCommandLineOpts.

public static Map<String, Object> readCommandLineOpts() {
    Map<String, Object> ret = new HashMap<>();
    String commandOptions = System.getProperty("storm.options");
    if (commandOptions != null) {
        /*
             Below regex uses negative lookahead to not split in the middle of json objects '{}'
             or json arrays '[]'. This is needed to parse valid json object/arrays passed as options
             via 'storm.cmd' in windows. This is not an issue while using 'storm.py' since it url-encodes
             the options and the below regex just does a split on the commas that separates each option.

             Note:- This regex handles only valid json strings and could produce invalid results
             if the options contain un-encoded invalid json or strings with unmatched '[, ], { or }'. We can
             replace below code with split(",") once 'storm.cmd' is fixed to send url-encoded options.
              */
        String[] configs = commandOptions.split(",(?![^\\[\\]{}]*(]|}))");
        for (String config : configs) {
            config = urlDecodeUtf8(config);
            String[] options = config.split("=", 2);
            if (options.length == 2) {
                Object val = options[1];
                try {
                    val = JSONValue.parseWithException(options[1]);
                } catch (ParseException ignored) {
                // fall back to string, which is already set
                }
                ret.put(options[0], val);
            }
        }
    }
    return ret;
}
Also used : HashMap(java.util.HashMap) ComponentObject(org.apache.storm.generated.ComponentObject) ParseException(org.apache.storm.shade.org.json.simple.parser.ParseException)

Aggregations

ParseException (org.apache.storm.shade.org.json.simple.parser.ParseException)8 ArrayList (java.util.ArrayList)4 List (java.util.List)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 AuthorizationException (org.apache.storm.generated.AuthorizationException)2 ComponentObject (org.apache.storm.generated.ComponentObject)2 DistributedRPCInvocations (org.apache.storm.generated.DistributedRPCInvocations)2 TException (org.apache.storm.thrift.TException)2 TTransportException (org.apache.storm.thrift.transport.TTransportException)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 LinkedHashMap (java.util.LinkedHashMap)1 NavigableMap (java.util.NavigableMap)1 TreeMap (java.util.TreeMap)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 DRPCInvocationsClient (org.apache.storm.drpc.DRPCInvocationsClient)1