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;
}
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);
}
}
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);
}
}
}
}
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);
}
}
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;
}
Aggregations