use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.
the class JdbcDatabaseMetaDataGenerator method getClasses.
VoltTable getClasses() {
VoltTable results = new VoltTable(CLASS_SCHEMA);
for (String classname : m_jarfile.getLoader().getClassNames()) {
try {
Class<?> clazz = m_jarfile.getLoader().loadClass(classname);
boolean isProc = VoltProcedure.class.isAssignableFrom(clazz);
boolean isActive = false;
if (isProc) {
for (Procedure proc : m_database.getProcedures()) {
if (proc.getClassname().equals(clazz.getCanonicalName())) {
isActive = true;
break;
}
}
}
results.addRow(classname, isProc ? 1 : 0, isActive ? 1 : 0);
} catch (Exception e) {
// if we can't load a class from the jarfile, just pretend it doesn't
// exist. Other checks when we actually load the classes should
// ensure that we don't end up in this state.
}
}
return results;
}
use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.
the class ImportManager method discoverConfigsAndLoadBundles.
/**
* Parses importer configs and loads the bundle needed for importer into memory. Updates
* mapping of active importer bundle to the bundle jar needed by the impoter
* @param catalogContext
*/
private void discoverConfigsAndLoadBundles(CatalogContext catalogContext) {
m_configsForProcessor.clear();
for (String configName : m_processorConfig.keySet()) {
ImportConfiguration importConfig = m_processorConfig.get(configName);
Properties properties = importConfig.getmoduleProperties();
String importBundleJar = properties.getProperty(ImportDataProcessor.IMPORT_MODULE);
Preconditions.checkNotNull(importBundleJar, "Import source is undefined or custom import plugin class missing.");
String procedure = properties.getProperty(ImportDataProcessor.IMPORT_PROCEDURE);
//TODO: If processors is a list dont start till all procedures exists.
Procedure catProc = catalogContext.procedures.get(procedure);
if (catProc == null) {
catProc = catalogContext.m_defaultProcs.checkForDefaultProcedure(procedure);
}
if (catProc == null) {
importLog.info("Importer " + configName + " Procedure " + procedure + " is missing will disable this importer until the procedure becomes available.");
continue;
}
if (loadImporterBundle(properties)) {
m_configsForProcessor.put(configName, importConfig);
}
}
if (!m_configsForProcessor.isEmpty()) {
importLog.info("Loaded importer modules: " + m_loadedBundles.keySet() + ", types: " + m_importersByType.keySet());
}
}
use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.
the class TestTwoSitePlans method setUp.
@SuppressWarnings("deprecation")
@Override
public void setUp() throws IOException, InterruptedException {
VoltDB.instance().readBuildInfo("Test");
// compile a catalog
String testDir = BuildDirectoryUtils.getBuildDirectoryPath();
String catalogJar = testDir + File.separator + JAR;
TPCCProjectBuilder pb = new TPCCProjectBuilder();
pb.addDefaultSchema();
pb.addDefaultPartitioning();
pb.addProcedures(MultiSiteSelect.class, InsertNewOrder.class);
pb.compile(catalogJar, 2, 0);
// load a catalog
byte[] bytes = MiscUtils.fileToBytes(new File(catalogJar));
String serializedCatalog = CatalogUtil.getSerializedCatalogStringFromJar(CatalogUtil.loadAndUpgradeCatalogFromJar(bytes, false).getFirst());
// create the catalog (that will be passed to the ClientInterface
catalog = new Catalog();
catalog.execute(serializedCatalog);
// update the catalog with the data from the deployment file
String pathToDeployment = pb.getPathToDeployment();
assertTrue(CatalogUtil.compileDeployment(catalog, pathToDeployment, false) == null);
cluster = catalog.getClusters().get("cluster");
CatalogMap<Procedure> procedures = cluster.getDatabases().get("database").getProcedures();
Procedure insertProc = procedures.get("InsertNewOrder");
assert (insertProc != null);
selectProc = procedures.get("MultiSiteSelect");
assert (selectProc != null);
// Each EE needs its own thread for correct initialization.
final AtomicReference<ExecutionEngine> site1Reference = new AtomicReference<ExecutionEngine>();
final byte[] configBytes = LegacyHashinator.getConfigureBytes(2);
Thread site1Thread = new Thread() {
@Override
public void run() {
site1Reference.set(new ExecutionEngineJNI(cluster.getRelativeIndex(), 1, 0, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, configBytes, 0, 0), false));
}
};
site1Thread.start();
site1Thread.join();
final AtomicReference<ExecutionEngine> site2Reference = new AtomicReference<ExecutionEngine>();
Thread site2Thread = new Thread() {
@Override
public void run() {
site2Reference.set(new ExecutionEngineJNI(cluster.getRelativeIndex(), 2, 1, 0, "", 0, 64 * 1024, 100, new HashinatorConfig(HashinatorType.LEGACY, configBytes, 0, 0), false));
}
};
site2Thread.start();
site2Thread.join();
// create two EEs
ee1 = site1Reference.get();
ee1.loadCatalog(0, catalog.serialize());
ee2 = site2Reference.get();
ee2.loadCatalog(0, catalog.serialize());
// cache some plan fragments
selectStmt = selectProc.getStatements().get("selectAll");
assert (selectStmt != null);
int i = 0;
// this kinda assumes the right order
for (PlanFragment f : selectStmt.getFragments()) {
if (i == 0)
selectTopFrag = f;
else
selectBottomFrag = f;
i++;
}
assert (selectTopFrag != null);
assert (selectBottomFrag != null);
if (selectTopFrag.getHasdependencies() == false) {
PlanFragment temp = selectTopFrag;
selectTopFrag = selectBottomFrag;
selectBottomFrag = temp;
}
// get the insert frag
Statement insertStmt = insertProc.getStatements().get("insert");
assert (insertStmt != null);
for (PlanFragment f : insertStmt.getFragments()) insertFrag = f;
// populate plan cache
ActivePlanRepository.clear();
ActivePlanRepository.addFragmentForTest(CatalogUtil.getUniqueIdForFragment(selectBottomFrag), Encoder.decodeBase64AndDecompressToBytes(selectBottomFrag.getPlannodetree()), selectStmt.getSqltext());
ActivePlanRepository.addFragmentForTest(CatalogUtil.getUniqueIdForFragment(selectTopFrag), Encoder.decodeBase64AndDecompressToBytes(selectTopFrag.getPlannodetree()), selectStmt.getSqltext());
ActivePlanRepository.addFragmentForTest(CatalogUtil.getUniqueIdForFragment(insertFrag), Encoder.decodeBase64AndDecompressToBytes(insertFrag.getPlannodetree()), insertStmt.getSqltext());
// insert some data
ParameterSet params = ParameterSet.fromArrayNoCopy(1L, 1L, 1L);
FastDeserializer fragResult2 = ee2.executePlanFragments(1, new long[] { CatalogUtil.getUniqueIdForFragment(insertFrag) }, null, new ParameterSet[] { params }, null, new String[] { selectStmt.getSqltext() }, null, null, 1, 1, 0, 42, Long.MAX_VALUE, false);
// ignore totalsize field in message
fragResult2.readInt();
VoltTable[] results = TableHelper.convertBackedBufferToTables(fragResult2.buffer(), 1);
assert (results[0].asScalarLong() == 1L);
params = ParameterSet.fromArrayNoCopy(2L, 2L, 2L);
FastDeserializer fragResult1 = ee1.executePlanFragments(1, new long[] { CatalogUtil.getUniqueIdForFragment(insertFrag) }, null, new ParameterSet[] { params }, null, new String[] { selectStmt.getSqltext() }, null, null, 2, 2, 1, 42, Long.MAX_VALUE, false);
// ignore totalsize field in message
fragResult1.readInt();
results = TableHelper.convertBackedBufferToTables(fragResult1.buffer(), 1);
assert (fragResult1.buffer() != fragResult2.buffer());
assert (results[0].asScalarLong() == 1L);
}
use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.
the class TestVoltCompiler method testGoodCreateProcedureWithAllow.
public void testGoodCreateProcedureWithAllow() throws Exception {
Database db = goodDDLAgainstSimpleSchema("create role r1;", "create procedure p1 allow r1 as select * from books;");
Procedure proc = db.getProcedures().get("p1");
assertNotNull(proc);
CatalogMap<GroupRef> groups = proc.getAuthgroups();
assertEquals(1, groups.size());
assertNotNull(groups.get("r1"));
db = goodDDLAgainstSimpleSchema("create role r1;", "create role r2;", "create procedure p1 allow r1, r2 as select * from books;");
proc = db.getProcedures().get("p1");
assertNotNull(proc);
groups = proc.getAuthgroups();
assertEquals(2, groups.size());
assertNotNull(groups.get("r1"));
assertNotNull(groups.get("r2"));
db = goodDDLAgainstSimpleSchema("create role r1;", "create procedure allow r1 from class org.voltdb.compiler.procedures.AddBook;");
proc = db.getProcedures().get("AddBook");
assertNotNull(proc);
groups = proc.getAuthgroups();
assertEquals(1, groups.size());
assertNotNull(groups.get("r1"));
db = goodDDLAgainstSimpleSchema("create role r1;", "create role r2;", "create procedure allow r1,r2 from class org.voltdb.compiler.procedures.AddBook;");
proc = db.getProcedures().get("AddBook");
assertNotNull(proc);
groups = proc.getAuthgroups();
assertEquals(2, groups.size());
assertNotNull(groups.get("r1"));
assertNotNull(groups.get("r2"));
db = goodDDLAgainstSimpleSchema("create role r1;", "create procedure allow r1,r1 from class org.voltdb.compiler.procedures.AddBook;");
proc = db.getProcedures().get("AddBook");
assertNotNull(proc);
groups = proc.getAuthgroups();
assertEquals(1, groups.size());
assertNotNull(groups.get("r1"));
}
use of org.voltdb.catalog.Procedure in project voltdb by VoltDB.
the class TestVoltCompiler method testValidNonAnnotatedProcedureDDL.
public void testValidNonAnnotatedProcedureDDL() throws Exception {
String schema = "create table books" + " (cash integer default 23 not null," + " title varchar(3) default 'foo'," + " PRIMARY KEY(cash));" + "PARTITION TABLE books ON COLUMN cash;" + "create procedure from class org.voltdb.compiler.procedures.NotAnnotatedAddBook;" + "paRtItiOn prOcEdure NotAnnotatedAddBook On taBLe books coLUmN cash ParaMETer 0;";
VoltCompiler compiler = new VoltCompiler(false);
final boolean success = compileDDL(schema, compiler);
assertTrue(success);
String catalogContents = VoltCompilerUtils.readFileFromJarfile(testout_jar, "catalog.txt");
Catalog c2 = new Catalog();
c2.execute(catalogContents);
Database db = c2.getClusters().get("cluster").getDatabases().get("database");
Procedure addBook = db.getProcedures().get("NotAnnotatedAddBook");
assertTrue(addBook.getSinglepartition());
}
Aggregations