use of org.apache.drill.common.scanner.persistence.ScanResult in project drill by apache.
the class BuildTimeScan method loadExcept.
/**
* loads all the prescanned resources from classpath
* (except for the target location in case it already exists)
* @return the result of the previous scan
*/
private static ScanResult loadExcept(URL ignored) {
Set<URL> preScanned = ClassPathScanner.forResource(REGISTRY_FILE, false);
ScanResult result = null;
for (URL u : preScanned) {
if (ignored != null && u.toString().startsWith(ignored.toString())) {
continue;
}
try (InputStream reflections = u.openStream()) {
ScanResult ref = reader.readValue(reflections);
if (result == null) {
result = ref;
} else {
result = result.merge(ref);
}
} catch (IOException e) {
throw new DrillRuntimeException("can't read function registry at " + u, e);
}
}
if (result != null) {
if (logger.isInfoEnabled()) {
StringBuilder sb = new StringBuilder();
sb.append(format("Loaded prescanned packages %s from locations:\n", result.getScannedPackages()));
for (URL u : preScanned) {
sb.append('\t');
sb.append(u.toExternalForm());
sb.append('\n');
}
}
logger.info(format("Loaded prescanned packages %s from locations %s", result.getScannedPackages(), preScanned));
return result;
} else {
return ClassPathScanner.emptyResult();
}
}
use of org.apache.drill.common.scanner.persistence.ScanResult in project drill by apache.
the class BuildTimeScan method main.
/**
* to generate the prescan file during build
* @param args the root path for the classes where {@link BuildTimeScan#REGISTRY_FILE} is generated
* @throws Exception
*/
public static void main(String[] args) throws Exception {
if (args.length != 1) {
throw new IllegalArgumentException("Usage: java {cp} " + BuildTimeScan.class.getName() + " path/to/scan");
}
String basePath = args[0];
logger.info("Scanning: {}", basePath);
File registryFile = new File(basePath, REGISTRY_FILE);
File dir = registryFile.getParentFile();
if ((!dir.exists() && !dir.mkdirs()) || !dir.isDirectory()) {
throw new IllegalArgumentException("could not create dir " + dir.getAbsolutePath());
}
DrillConfig config = DrillConfig.create();
// normalize
if (!basePath.endsWith("/")) {
basePath = basePath + "/";
}
if (!basePath.startsWith("/")) {
basePath = "/" + basePath;
}
URL url = new URL("file:" + basePath);
Set<URL> markedPaths = ClassPathScanner.getMarkedPaths(ConfigConstants.DRILL_JAR_MARKER_FILE_RESOURCE_PATHNAME);
if (!markedPaths.contains(url)) {
throw new IllegalArgumentException(url + " not in " + markedPaths);
}
List<String> packagePrefixes = ClassPathScanner.getPackagePrefixes(config);
List<String> baseClasses = ClassPathScanner.getScannedBaseClasses(config);
List<String> scannedAnnotations = ClassPathScanner.getScannedAnnotations(config);
ScanResult preScanned = loadExcept(url);
ScanResult scan = ClassPathScanner.scan(asList(url), packagePrefixes, baseClasses, scannedAnnotations, preScanned);
save(scan, registryFile);
}
use of org.apache.drill.common.scanner.persistence.ScanResult in project drill by apache.
the class ZKACLProviderFactory method findACLProvider.
public static ZKACLProviderDelegate findACLProvider(DrillConfig config, ZKACLContextProvider contextProvider, BootStrapContext context) throws DrillbitStartupException {
if (!config.hasPath(ZK_ACL_PROVIDER)) {
throw new DrillbitStartupException(String.format("BOOT option '%s' is missing in config.", ZK_ACL_PROVIDER));
}
final String aclProviderName = config.getString(ZK_ACL_PROVIDER);
if (Strings.isNullOrEmpty(aclProviderName)) {
throw new DrillbitStartupException(String.format("Invalid value '%s' for BOOT option '%s'", aclProviderName, ZK_ACL_PROVIDER));
}
ScanResult scan = context.getClasspathScan();
final Collection<Class<? extends ZKACLProvider>> aclProviderImpls = scan.getImplementations(ZKACLProvider.class);
logger.debug("Found ZkACLProvider implementations: {}", aclProviderImpls);
for (Class<? extends ZKACLProvider> clazz : aclProviderImpls) {
final ZKACLProviderTemplate template = clazz.getAnnotation(ZKACLProviderTemplate.class);
if (template == null) {
logger.warn("{} doesn't have {} annotation. Skipping.", clazz.getCanonicalName(), ZKACLProviderTemplate.class);
continue;
}
if (template.type().equalsIgnoreCase(aclProviderName)) {
Constructor<?> validConstructor = null;
Class constructorArgumentClass = ZKACLContextProvider.class;
for (Constructor<?> c : clazz.getConstructors()) {
Class<?>[] params = c.getParameterTypes();
if (params.length == 1 && params[0] == constructorArgumentClass) {
validConstructor = c;
break;
}
}
if (validConstructor == null) {
logger.warn("Skipping ZKACLProvider implementation class '{}' since it doesn't " + "implement a constructor [{}({})]", clazz.getCanonicalName(), clazz.getName(), constructorArgumentClass.getName());
continue;
}
try {
final ZKACLProvider aclProvider = (ZKACLProvider) validConstructor.newInstance(contextProvider);
return new ZKACLProviderDelegate(aclProvider);
} catch (ReflectiveOperationException e) {
throw new DrillbitStartupException(String.format("Failed to create and initialize the ZKACLProvider class '%s'", clazz.getCanonicalName()), e);
}
}
}
String errMsg = String.format("Failed to find the implementation of '%s' for type '%s'", ZKACLProvider.class.getCanonicalName(), aclProviderName);
logger.error(errMsg);
throw new DrillbitStartupException(errMsg);
}
use of org.apache.drill.common.scanner.persistence.ScanResult in project drill by apache.
the class Drillbit method start.
@VisibleForTesting
public static Drillbit start(final DrillConfig config, final CaseInsensitiveMap<OptionDefinition> validators, final RemoteServiceSet remoteServiceSet) throws DrillbitStartupException {
logger.debug("Starting new Drillbit.");
// TODO: allow passing as a parameter
ScanResult classpathScan = ClassPathScanner.fromPrescan(config);
Drillbit bit;
try {
bit = new Drillbit(config, validators, remoteServiceSet, classpathScan);
} catch (final Exception ex) {
if (ex instanceof DrillbitStartupException) {
throw (DrillbitStartupException) ex;
} else {
throw new DrillbitStartupException("Failure while initializing values in Drillbit.", ex);
}
}
try {
bit.run();
} catch (final Exception e) {
logger.error("Failure during initial startup of Drillbit.", e);
bit.close();
throw new DrillbitStartupException("Failure during initial startup of Drillbit.", e);
}
logger.debug("Started new Drillbit.");
return bit;
}
use of org.apache.drill.common.scanner.persistence.ScanResult in project drill by apache.
the class TestBitBitKerberos method successEncryption.
@Test
public void successEncryption() throws Exception {
final WorkerBee bee = mock(WorkerBee.class);
final WorkEventBus workBus = mock(WorkEventBus.class);
newConfig = new DrillConfig(DrillConfig.create(cloneDefaultTestConfigProperties()).withValue(ExecConstants.AUTHENTICATION_MECHANISMS, ConfigValueFactory.fromIterable(Lists.newArrayList("kerberos"))).withValue(ExecConstants.BIT_AUTHENTICATION_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.BIT_AUTHENTICATION_MECHANISM, ConfigValueFactory.fromAnyRef("kerberos")).withValue(ExecConstants.BIT_ENCRYPTION_SASL_ENABLED, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.USE_LOGIN_PRINCIPAL, ConfigValueFactory.fromAnyRef(true)).withValue(ExecConstants.SERVICE_PRINCIPAL, ConfigValueFactory.fromAnyRef(krbHelper.SERVER_PRINCIPAL)).withValue(ExecConstants.SERVICE_KEYTAB_LOCATION, ConfigValueFactory.fromAnyRef(krbHelper.serverKeytab.toString())));
final ScanResult result = ClassPathScanner.fromPrescan(newConfig);
final BootStrapContext c2 = new BootStrapContext(newConfig, SystemOptionManager.createDefaultOptionDefinitions(), result);
final FragmentManager manager = setupFragmentContextAndManager(c2.getAllocator());
when(workBus.getFragmentManager(Mockito.<FragmentHandle>any())).thenReturn(manager);
final DataConnectionConfig config = new DataConnectionConfig(c2.getAllocator(), c2, new DataServerRequestHandler(workBus, bee));
final DataServer server = new DataServer(config);
port = server.bind(port, true);
DrillbitEndpoint ep = DrillbitEndpoint.newBuilder().setAddress("localhost").setDataPort(port).build();
final DataConnectionManager connectionManager = new DataConnectionManager(ep, config);
final DataTunnel tunnel = new DataTunnel(connectionManager);
AtomicLong max = new AtomicLong(0);
try {
for (int i = 0; i < 40; i++) {
long t1 = System.currentTimeMillis();
tunnel.sendRecordBatch(new TimingOutcome(max), new FragmentWritableBatch(false, QueryId.getDefaultInstance(), 1, 1, 1, 1, getRandomBatch(c2.getAllocator(), 5000)));
}
assertTrue(max.get() > 2700);
Thread.sleep(5000);
} finally {
server.close();
connectionManager.close();
c2.close();
}
}
Aggregations