use of org.apache.storm.jdbc.common.JdbcClient in project storm by apache.
the class AbstractUserTopology method execute.
public void execute(String[] args) throws Exception {
if (args.length != 4 && args.length != 5) {
System.out.println("Usage: " + this.getClass().getSimpleName() + " <dataSourceClassName> <dataSource.url> " + "<user> <password> [topology name]");
System.exit(-1);
}
Map map = Maps.newHashMap();
//com.mysql.jdbc.jdbc2.optional.MysqlDataSource
map.put("dataSourceClassName", args[0]);
//jdbc:mysql://localhost/test
map.put("dataSource.url", args[1]);
//root
map.put("dataSource.user", args[2]);
if (args.length == 4) {
//password
map.put("dataSource.password", args[3]);
}
Config config = new Config();
config.put(JDBC_CONF, map);
ConnectionProvider connectionProvider = new HikariCPConnectionProvider(map);
connectionProvider.prepare();
int queryTimeoutSecs = 60;
JdbcClient jdbcClient = new JdbcClient(connectionProvider, queryTimeoutSecs);
for (String sql : setupSqls) {
jdbcClient.executeSql(sql);
}
this.userSpout = new UserSpout();
this.jdbcMapper = new SimpleJdbcMapper(TABLE_NAME, connectionProvider);
connectionProvider.cleanup();
Fields outputFields = new Fields("user_id", "user_name", "dept_name", "create_date");
List<Column> queryParamColumns = Lists.newArrayList(new Column("user_id", Types.INTEGER));
this.jdbcLookupMapper = new SimpleJdbcLookupMapper(outputFields, queryParamColumns);
this.connectionProvider = new HikariCPConnectionProvider(map);
if (args.length == 4) {
try (LocalCluster cluster = new LocalCluster();
LocalTopology topo = cluster.submitTopology("test", config, getTopology())) {
Thread.sleep(30000);
}
System.exit(0);
} else {
StormSubmitter.submitTopology(args[4], config, getTopology());
}
}
use of org.apache.storm.jdbc.common.JdbcClient in project storm by apache.
the class JdbcState method prepare.
protected void prepare() {
options.connectionProvider.prepare();
if (StringUtils.isBlank(options.insertQuery) && StringUtils.isBlank(options.tableName) && StringUtils.isBlank(options.selectQuery)) {
throw new IllegalArgumentException("If you are trying to insert into DB you must supply either insertQuery or tableName." + "If you are attempting to user a query state you must supply a select query.");
}
if (options.queryTimeoutSecs == null) {
options.queryTimeoutSecs = Integer.parseInt(map.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS).toString());
}
this.jdbcClient = new JdbcClient(options.connectionProvider, options.queryTimeoutSecs);
}
use of org.apache.storm.jdbc.common.JdbcClient in project storm by apache.
the class AbstractJdbcBolt method prepare.
@Override
public void prepare(Map map, TopologyContext topologyContext, OutputCollector collector) {
this.collector = collector;
connectionProvider.prepare();
if (queryTimeoutSecs == null) {
queryTimeoutSecs = Integer.parseInt(map.get(Config.TOPOLOGY_MESSAGE_TIMEOUT_SECS).toString());
}
this.jdbcClient = new JdbcClient(connectionProvider, queryTimeoutSecs);
}
Aggregations