use of com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO in project databus by linkedin.
the class BootstrapDropSource method getConnection.
/*
* @return a bootstrapDB connection object.
* Note: The connection object is still owned by BootstrapConn. SO dont close it
*/
public Connection getConnection() {
Connection conn = null;
if (_dbDao == null) {
LOG.info("<<<< Creating Bootstrap Connection!! >>>>");
BootstrapConn dbConn = new BootstrapConn();
try {
dbConn.initBootstrapConn(false, _config.getBootstrapDBUsername(), _config.getBootstrapDBPassword(), _config.getBootstrapDBHostname(), _config.getBootstrapDBName());
_dbDao = new BootstrapDBMetaDataDAO(dbConn, _config.getBootstrapDBHostname(), _config.getBootstrapDBUsername(), _config.getBootstrapDBPassword(), _config.getBootstrapDBName(), false);
} catch (Exception e) {
LOG.fatal("Unable to open BootstrapDB Connection !!", e);
throw new RuntimeException("Got exception when getting bootstrap DB Connection.", e);
}
}
try {
conn = _dbDao.getBootstrapConn().getDBConn();
} catch (SQLException e) {
LOG.fatal("Not able to open BootstrapDB Connection !!", e);
throw new RuntimeException("Got exception when getting bootstrap DB Connection.", e);
}
return conn;
}
use of com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO in project databus by linkedin.
the class BootstrapMetadata method main.
/**
*/
public static void main(String[] args) {
int exitStatus = 0;
GnuParser cmdLineParser = new GnuParser();
Options options = new Options();
options.addOption("d", "dbname", true, "database name : [bootstrap]").addOption("s", "dbhost", true, "database hostname: [localhost]").addOption("p", "dbpassword", true, "database password: [bootstrap]").addOption("u", "dbuser", true, "database user: [bootstrap] ").addOption("S", "sources", true, " <srcid,..>|<srcName substring,..,> [all]").addOption("m", "minScnType", true, "type of minScn algorithm: [catchup-forever] catchup-forever|catchup-purged|snapshot. " + "'snapshot': use when snapshot table has been purged and the size of snapshot is not large.Times-out in 5 minutes if query cannot complete. " + "'catchup-purged': use when snapshot table has been purged and a conservative value of minScn is acceptable or when 'snapshot' isn't feasible. " + "'catchup-forever': use when snapshot table has *never* been purged . " + "Note: If a source has been seeded, regardless of the minScnType, the value returned is 0.").addOption("h", "help", false, "help");
// add descriptions used in usage() 'functionName' , 'description-pairs'
String[] functionNames = { "getSources", "get sourceName, sourceId, sourceStatus from bootstrap db", "createMinScnTable", "create metadata required for minScn feature in bootstrap db if none exists", "createAllTables", "create all metadata in bootstrap db if they don't exist", "getMinScn", "[--sources <>] return minScn as seen by bootstrap service for specified sources", "computeMinScn", "[--sources <>] [--minScnType <>] return minScn using one of the algorithms specified. " + "INIT could mean failure to find a minSCN ", "computeAndSetMinScn", "[--sources <>] [--minScnType<>] set minScn using one of the algorithms specified. ", "setMinScn", "[--sources <>] INFINITY|INIT|<scn> set minScn to a desired value. " };
try {
CommandLine cmdLineArgs = cmdLineParser.parse(options, args, false);
if (cmdLineArgs.hasOption('h')) {
usage(options, functionNames);
System.exit(0);
}
String[] fns = cmdLineArgs.getArgs();
if (fns.length < 1) {
usage(options, functionNames);
throw new Exception("Missing argument");
}
String function = fns[0];
String arg1 = (fns.length > 1) ? fns[1] : null;
if (!legitFunction(functionNames, function)) {
usage(options, functionNames);
throw new Exception("Unknown function");
}
String bootstrapHost = cmdLineArgs.getOptionValue("dbhost", DEFAULT_BOOTSTRAP_HOST);
String bootstrapDbName = cmdLineArgs.getOptionValue("dbname", DEFAULT_BOOTSTRAP_DATABASE);
String bootstrapPassword = cmdLineArgs.getOptionValue("dbpassword", DEFAULT_BOOTSTRAP_PASSWORD);
String bootstrapUser = cmdLineArgs.getOptionValue("dbuser", DEFAULT_BOOTSTRAP_USER);
_bsConn = new BootstrapConn();
_bsConn.initBootstrapConn(false, bootstrapUser, bootstrapPassword, bootstrapHost, bootstrapDbName);
_dbao = new BootstrapDBMetaDataDAO(_bsConn, bootstrapHost, bootstrapUser, bootstrapPassword, bootstrapDbName, false);
String minScnType = cmdLineArgs.getOptionValue("minScnType", DEFAULT_MINSCN_TYPE);
if (function.equals("createMinScnTable")) {
createBootstrapMinScn();
return;
} else if (function.equals("createAllTables")) {
_dbao.setupDB();
return;
}
List<SourceStatusInfo> sourceInfoList = _dbao.getSrcStatusInfoFromDB();
if (function.equalsIgnoreCase("getSources")) {
for (SourceStatusInfo s : sourceInfoList) {
StringBuilder sb = new StringBuilder();
sb.append(s.getSrcName()).append('\t').append(s.getSrcId()).append('\t').append(s.getStatus());
System.out.println(sb.toString());
}
} else {
// not getSources()
// expect srcId list; for brevity;
String mySources = cmdLineArgs.getOptionValue("sources");
String[] mySrcList = null;
if (mySources != null) {
mySrcList = mySources.split(",");
}
List<SourceStatusInfo> finalSrcIdList = (mySrcList != null) ? getFinalSrcIdList(sourceInfoList, mySrcList) : sourceInfoList;
if (function.equalsIgnoreCase("getMinScn")) {
// read minScn from minscn table;
createBootstrapMinScn();
for (SourceStatusInfo sInfo : finalSrcIdList) {
long minScn = _dbao.getMinScnOfSnapshots(sInfo.getSrcId());
DBHelper.commit(_bsConn.getDBConn());
if (minScn == Long.MIN_VALUE) {
System.err.println("Error: Cannot get minScn for " + sInfo.getSrcId());
} else {
printScn(minScn, sInfo, '\t');
}
}
} else if (function.equalsIgnoreCase("computeMinScn")) {
// database not affected
for (SourceStatusInfo sInfo : finalSrcIdList) {
long minScn = computeMinScn(minScnType, sInfo.getSrcId());
// commit select;
DBHelper.commit(_bsConn.getDBConn());
if (minScn == Long.MIN_VALUE) {
System.err.println("Error: Cannot get minScn for " + sInfo.getSrcId());
} else {
printScn(minScn, sInfo, '\t');
}
}
} else if (function.equalsIgnoreCase("setMinScn")) {
if (arg1 == null) {
throw new Exception("Missing argument for setMinScn: <scn>, INFINITY or INIT");
}
// setMinScn <scn>
// override existing scn; never fail unless update fails ; show
// warning that you should know what you are doing
createBootstrapMinScn();
long scn;
if (arg1.equalsIgnoreCase("INFINITY")) {
scn = Long.MAX_VALUE;
} else if (arg1.equalsIgnoreCase("INIT")) {
scn = BootstrapDBMetaDataDAO.DEFAULT_WINDOWSCN;
} else {
scn = Long.parseLong(arg1);
}
for (SourceStatusInfo sInfo : finalSrcIdList) {
// calls commit
_dbao.updateMinScnOfSnapshot(sInfo.getSrcId(), scn);
}
} else if (function.equalsIgnoreCase("computeAndSetMinScn")) {
// set scn iff minScn has been initialized; ensure minScn is updated
// safely according to --type
// if seeded; --type is ignored;
createBootstrapMinScn();
for (SourceStatusInfo sInfo : finalSrcIdList) {
long minScn = computeMinScn(minScnType, sInfo.getSrcId());
if (minScn != Long.MIN_VALUE) {
_dbao.updateMinScnOfSnapshot(sInfo.getSrcId(), minScn);
}
DBHelper.commit(_bsConn.getDBConn());
}
}
}
} catch (ParseException e) {
usage(options, functionNames);
exitStatus = 1;
} catch (Exception e) {
System.err.println("Error: " + e);
exitStatus = 1;
} finally {
if (_dbao != null)
_dbao.close();
System.exit(exitStatus);
}
}
use of com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO in project databus by linkedin.
the class TestBootstrap method testBootstrapService.
@Test
public void testBootstrapService() throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException, IOException, BootstrapProcessingException, DatabusException, BootstrapDatabaseTooOldException, BootstrapDBException {
final Logger log = Logger.getLogger("TestBootstrap.testBootstrapService");
EventProcessor processorCallback = new EventProcessor();
BootstrapConfig config = new BootstrapConfig();
BootstrapReadOnlyConfig staticConfig = config.build();
String[] sources = new String[4];
sources[0] = "TestBootstrap.testBootstrapService.event";
sources[1] = "TestBootstrap.testBootstrapService.event1";
sources[2] = "TestBootstrap.testBootstrapService.event2";
sources[3] = "TestBootstrap.testBootstrapService.event3";
// Create the tables for all the sources before starting up the threads
BootstrapConn _bootstrapConn = new BootstrapConn();
final boolean autoCommit = true;
_bootstrapConn.initBootstrapConn(autoCommit, staticConfig.getBootstrapDBUsername(), staticConfig.getBootstrapDBPassword(), staticConfig.getBootstrapDBHostname(), staticConfig.getBootstrapDBName());
BootstrapDBMetaDataDAO dao = new BootstrapDBMetaDataDAO(_bootstrapConn, staticConfig.getBootstrapDBHostname(), staticConfig.getBootstrapDBUsername(), staticConfig.getBootstrapDBPassword(), staticConfig.getBootstrapDBName(), autoCommit);
for (String source : sources) {
SourceStatusInfo srcStatusInfo = dao.getSrcIdStatusFromDB(source, false);
if (srcStatusInfo.getSrcId() >= 0) {
dao.dropSourceInDB(srcStatusInfo.getSrcId());
}
dao.addNewSourceInDB(source, BootstrapProducerStatus.ACTIVE);
}
setBootstrapLoginfoTable(_bootstrapConn, 1, 1);
DatabusBootstrapClient s = new DatabusBootstrapClient(sources);
Checkpoint cp;
while ((cp = s.getNextBatch(10, processorCallback)).getConsumptionMode() != DbusClientMode.ONLINE_CONSUMPTION) {
log.debug(cp);
}
}
use of com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO in project databus by linkedin.
the class BootstrapDBSeeder method getConnection.
/*
* Returns a connection object.
* Note: The connection object is still owned by BootstrapConn. SO dont close it
*/
public Connection getConnection() {
Connection conn = null;
if (_bootstrapDao == null) {
LOG.info("<<<< Creating Bootstrap Connection!! >>>>");
BootstrapConn dbConn = new BootstrapConn();
try {
dbConn.initBootstrapConn(false, java.sql.Connection.TRANSACTION_READ_UNCOMMITTED, _config.getBootstrapDBUsername(), _config.getBootstrapDBPassword(), _config.getBootstrapDBHostname(), _config.getBootstrapDBName());
_bootstrapDao = new BootstrapDBMetaDataDAO(dbConn, _config.getBootstrapDBHostname(), _config.getBootstrapDBUsername(), _config.getBootstrapDBPassword(), _config.getBootstrapDBName(), false);
} catch (Exception e) {
LOG.fatal("Unable to open BootstrapDB Connection !!", e);
throw new RuntimeException("Got exception when getting bootstrap DB Connection.", e);
}
}
try {
conn = _bootstrapDao.getBootstrapConn().getDBConn();
} catch (SQLException e) {
LOG.fatal("Not able to open BootstrapDB Connection !!", e);
throw new RuntimeException("Got exception when getting bootstrap DB Connection.", e);
}
return conn;
}
use of com.linkedin.databus.bootstrap.common.BootstrapDBMetaDataDAO in project databus by linkedin.
the class BootstrapDbControlMain method main.
public static void main(String[] args) throws IOException, DatabusException, InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
Cli cli = new Cli("java " + BootstrapDbControlMain.class.getSimpleName() + " [options]");
cli.processCommandLineArgs(args);
Properties cfgProps = cli.getConfigProps();
BootstrapConfig cfgBuilder = new BootstrapConfig();
ConfigLoader<BootstrapReadOnlyConfig> configLoad = new ConfigLoader<BootstrapReadOnlyConfig>("databus.bootstrap.", cfgBuilder);
configLoad.loadConfig(cfgProps);
BootstrapReadOnlyConfig cfg = cfgBuilder.build();
BootstrapConn conn = new BootstrapConn();
try {
conn.initBootstrapConn(true, cfg.getBootstrapDBUsername(), cfg.getBootstrapDBPassword(), cfg.getBootstrapDBHostname(), cfg.getBootstrapDBName());
BootstrapDBMetaDataDAO dao = new BootstrapDBMetaDataDAO(conn, cfg.getBootstrapDBHostname(), cfg.getBootstrapDBUsername(), cfg.getBootstrapDBPassword(), cfg.getBootstrapDBName(), false);
switch(cli.getAction()) {
case CREATE_LOG_TABLE:
dao.createNewLogTable(cli.getSrcId());
break;
case CREATE_TAB_TABLE:
dao.createNewSrcTable(cli.getSrcId());
break;
default:
throw new RuntimeException("unknown action: " + cli.getAction());
}
} finally {
conn.close();
}
}
Aggregations