use of org.apache.drill.exec.server.options.SystemOptionManager in project drill by apache.
the class CodeCompilerTestFactory method getTestCompiler.
public static CodeCompiler getTestCompiler(DrillConfig c) throws Exception {
DrillConfig config = checkNotNull(c);
LogicalPlanPersistence persistence = new LogicalPlanPersistence(config, ClassPathScanner.fromPrescan(config));
LocalPersistentStoreProvider provider = new LocalPersistentStoreProvider(config);
SystemOptionManager systemOptionManager = new SystemOptionManager(persistence, provider);
return new CodeCompiler(config, systemOptionManager.init());
}
use of org.apache.drill.exec.server.options.SystemOptionManager in project drill by apache.
the class ReplaceMethodInvoke method main.
// private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(ReplaceMethodInvoke.class);
public static void main(String[] args) throws Exception {
final String k2 = "org/apache/drill/Pickle.class";
final URL url = Resources.getResource(k2);
final byte[] clazz = Resources.toByteArray(url);
final ClassReader cr = new ClassReader(clazz);
final ClassWriter cw = writer();
final TraceClassVisitor visitor = new TraceClassVisitor(cw, new Textifier(), new PrintWriter(System.out));
final ValueHolderReplacementVisitor v2 = new ValueHolderReplacementVisitor(visitor, true);
//| ClassReader.SKIP_DEBUG);
cr.accept(v2, ClassReader.EXPAND_FRAMES);
final byte[] output = cw.toByteArray();
Files.write(output, new File("/src/scratch/bytes/S.class"));
check(output);
final DrillConfig c = DrillConfig.forClient();
final SystemOptionManager m = new SystemOptionManager(PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(c), new LocalPersistentStoreProvider(c));
m.init();
try (QueryClassLoader ql = new QueryClassLoader(DrillConfig.create(), m)) {
ql.injectByteCode("org.apache.drill.Pickle$OutgoingBatch", output);
Class<?> clz = ql.loadClass("org.apache.drill.Pickle$OutgoingBatch");
clz.getMethod("x").invoke(null);
}
}
use of org.apache.drill.exec.server.options.SystemOptionManager in project drill by apache.
the class PlanningBase method testSqlPlan.
protected void testSqlPlan(String sqlCommands) throws Exception {
final String[] sqlStrings = sqlCommands.split(";");
final LocalPersistentStoreProvider provider = new LocalPersistentStoreProvider(config);
provider.start();
final ScanResult scanResult = ClassPathScanner.fromPrescan(config);
final LogicalPlanPersistence logicalPlanPersistence = new LogicalPlanPersistence(config, scanResult);
final SystemOptionManager systemOptions = new SystemOptionManager(logicalPlanPersistence, provider);
systemOptions.init();
@SuppressWarnings("resource") final UserSession userSession = UserSession.Builder.newBuilder().withOptionManager(systemOptions).build();
final SessionOptionManager sessionOptions = (SessionOptionManager) userSession.getOptions();
final QueryOptionManager queryOptions = new QueryOptionManager(sessionOptions);
final ExecutionControls executionControls = new ExecutionControls(queryOptions, DrillbitEndpoint.getDefaultInstance());
new NonStrictExpectations() {
{
dbContext.getMetrics();
result = new MetricRegistry();
dbContext.getAllocator();
result = allocator;
dbContext.getConfig();
result = config;
dbContext.getOptionManager();
result = systemOptions;
dbContext.getStoreProvider();
result = provider;
dbContext.getClasspathScan();
result = scanResult;
dbContext.getLpPersistence();
result = logicalPlanPersistence;
}
};
final StoragePluginRegistry registry = new StoragePluginRegistryImpl(dbContext);
registry.init();
final FunctionImplementationRegistry functionRegistry = new FunctionImplementationRegistry(config);
final DrillOperatorTable table = new DrillOperatorTable(functionRegistry, systemOptions);
final SchemaPlus root = SimpleCalciteSchema.createRootSchema(false);
registry.getSchemaFactory().registerSchemas(SchemaConfig.newBuilder("foo", context).build(), root);
new NonStrictExpectations() {
{
context.getNewDefaultSchema();
result = root;
context.getLpPersistence();
result = new LogicalPlanPersistence(config, ClassPathScanner.fromPrescan(config));
context.getStorage();
result = registry;
context.getFunctionRegistry();
result = functionRegistry;
context.getSession();
result = UserSession.Builder.newBuilder().setSupportComplexTypes(true).build();
context.getCurrentEndpoint();
result = DrillbitEndpoint.getDefaultInstance();
context.getActiveEndpoints();
result = ImmutableList.of(DrillbitEndpoint.getDefaultInstance());
context.getPlannerSettings();
result = new PlannerSettings(queryOptions, functionRegistry);
context.getOptions();
result = queryOptions;
context.getConfig();
result = config;
context.getDrillOperatorTable();
result = table;
context.getAllocator();
result = allocator;
context.getExecutionControls();
result = executionControls;
dbContext.getLpPersistence();
result = logicalPlanPersistence;
}
};
for (final String sql : sqlStrings) {
if (sql.trim().isEmpty()) {
continue;
}
@SuppressWarnings("unused") final PhysicalPlan p = DrillSqlWorker.getPlan(context, sql);
}
}
use of org.apache.drill.exec.server.options.SystemOptionManager in project drill by apache.
the class DrillRestLoginService method login.
@Override
public UserIdentity login(String username, Object credentials) {
if (!(credentials instanceof String)) {
return null;
}
try {
// Authenticate WebUser locally using UserAuthenticator. If WebServer is started that guarantees the PLAIN
// mechanism is configured and authenticator is also available
final AuthenticatorFactory plainFactory = drillbitContext.getAuthProvider().getAuthenticatorFactory(PlainFactory.SIMPLE_NAME);
final UserAuthenticator userAuthenticator = ((PlainFactory) plainFactory).getAuthenticator();
// Authenticate the user with configured Authenticator
userAuthenticator.authenticate(username, credentials.toString());
logger.debug("WebUser {} is successfully authenticated", username);
final SystemOptionManager sysOptions = drillbitContext.getOptionManager();
final boolean isAdmin = ImpersonationUtil.hasAdminPrivileges(username, sysOptions.getOption(ExecConstants.ADMIN_USERS_KEY).string_val, sysOptions.getOption(ExecConstants.ADMIN_USER_GROUPS_KEY).string_val);
// Create the UserPrincipal corresponding to logged in user.
final Principal userPrincipal = new DrillUserPrincipal(username, isAdmin);
final Subject subject = new Subject();
subject.getPrincipals().add(userPrincipal);
subject.getPrivateCredentials().add(credentials);
if (isAdmin) {
subject.getPrincipals().addAll(DrillUserPrincipal.ADMIN_PRINCIPALS);
return identityService.newUserIdentity(subject, userPrincipal, DrillUserPrincipal.ADMIN_USER_ROLES);
} else {
subject.getPrincipals().addAll(DrillUserPrincipal.NON_ADMIN_PRINCIPALS);
return identityService.newUserIdentity(subject, userPrincipal, DrillUserPrincipal.NON_ADMIN_USER_ROLES);
}
} catch (final Exception e) {
if (e instanceof UserAuthenticationException) {
logger.debug("Authentication failed for WebUser '{}'", username, e);
} else {
logger.error("UnExpected failure occurred for WebUser {} during login.", username, e);
}
return null;
}
}
use of org.apache.drill.exec.server.options.SystemOptionManager in project drill by apache.
the class ExecTest method setupOptionManager.
@BeforeClass
public static void setupOptionManager() throws Exception {
final LocalPersistentStoreProvider provider = new LocalPersistentStoreProvider(c);
provider.start();
optionManager = new SystemOptionManager(PhysicalPlanReaderTestFactory.defaultLogicalPlanPersistence(c), provider);
optionManager.init();
}
Aggregations