public List<SqlDb> getSqlDb( UUID subscriptionId, String serverName, String admin, String adminPassword) throws AzureCmdException { String[] cmd = new String[] { "sql", "db", "list", "--json", "-s", subscriptionId.toString(), serverName, admin, adminPassword }; String json = AzureCommandHelper.getInstance().consoleExec(cmd); CustomJsonSlurper slurper = new CustomJsonSlurper(); List<Map<String, String>> tempRes = (List<Map<String, String>>) slurper.parseText(json); List<SqlDb> res = new ArrayList<SqlDb>(); for (Map<String, String> item : tempRes) { SqlDb sqls = new SqlDb(); sqls.setName(item.get("Name")); sqls.setEdition(item.get("Edition")); res.add(sqls); } return res; }
@Override public void prepare(Map config, TopologyContext context, OutputCollector collector) { if (connectionStr != null && !connectionStr.isEmpty()) { logger.info("prepare - connectionStr = " + connectionStr + ", tableName = " + this.tableName); db = new SqlDb(connectionStr, tableName); db.dropTable(); db.createTable(); } finalCount = 0L; totalCount = 0L; this.collector = collector; }
@Override public void execute(Tuple tuple) { // write the finalCount to SqlDb on each TickTuple. if (isTickTuple(tuple)) { // only emit if finalCount > 0 if (finalCount > 0) { logger.info( "emitting final count" + ", finalCount: " + finalCount + ", totalCount: " + totalCount + ", tuplesToAck: " + tuplesToAck.size() + " at " + System.currentTimeMillis()); if (db != null) { db.insertValue(System.currentTimeMillis(), finalCount); } else { if (enableAck) { this.collector.emit(tuplesToAck, new Values(finalCount)); } else { this.collector.emit(new Values(finalCount)); } } finalCount = 0L; if (enableAck) { for (Tuple tupleToAck : tuplesToAck) { collector.ack(tupleToAck); } tuplesToAck.clear(); } } } else { // Merge finalCount from all PartialCountBolt tasks long incomingPartialCount = tuple.getLong(0); finalCount += incomingPartialCount; totalCount += incomingPartialCount; if (enableAck) { tuplesToAck.add(tuple); } } }
@Override public void cleanup() { db.closeDbConnection(); }