/** * Creates a Context initialized with configuration stored in Zookeeper. * @param properties Properties to configure the context. * @param zkClient An optional Zookeeper client. */ private Context createContext(Properties properties, Optional<CuratorFramework> zkClient) throws Exception { Context.Builder contextBuilder = new Context.Builder(); Map<String, Object> globals; if (zkClient.isPresent()) { LOG.debug("Zookeeper client present; fetching globals from Zookeeper."); // fetch globals from zookeeper globals = fetchGlobalConfig(zkClient.get()); contextBuilder.with(ZOOKEEPER_CLIENT, () -> zkClient.get()); } else { LOG.debug("No Zookeeper client; initializing empty globals."); // use empty globals to allow a user to '%define' their own globals = new HashMap<>(); } return contextBuilder .with(SHELL_VARIABLES, () -> variables) .with(GLOBAL_CONFIG, () -> globals) .with(STELLAR_CONFIG, () -> getStellarConfig(globals, properties)) .build(); }
client = CuratorFrameworkFactory.newClient(zookeeperUrl, retryPolicy); client.start(); context = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) .build(); MaaSConfig config = ConfigUtil.INSTANCE.read(client, "/metron/maas/config", new MaaSConfig(), MaaSConfig.class); discoverer = new ServiceDiscoverer(client, config.getServiceRoot());
protected Context initializeStellar() { Map<String, Object> cacheConfig = new HashMap<>(); for (String sensorType: this.parserRunner.getSensorTypes()) { SensorParserConfig config = getSensorParserConfig(sensorType); if (config != null) { cacheConfig.putAll(config.getCacheConfig()); } } Cache<CachingStellarProcessor.Key, Object> cache = CachingStellarProcessor.createCache(cacheConfig); Context.Builder builder = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) .with(Context.Capabilities.GLOBAL_CONFIG, () -> getConfigurations().getGlobalConfig()) .with(Context.Capabilities.STELLAR_CONFIG, () -> getConfigurations().getGlobalConfig()) ; if(cache != null) { builder = builder.with(Context.Capabilities.CACHE, () -> cache); } Context stellarContext = builder.build(); StellarFunctions.initialize(stellarContext); return stellarContext; }
@Before public void setup() throws Exception { final MockHTable hbaseTable = (MockHTable) MockHBaseTableProvider.addToCache(hbaseTableName, cf); EnrichmentHelper.INSTANCE.load(hbaseTable, cf, new ArrayList<LookupKV<EnrichmentKey, EnrichmentValue>>() {{ for(int i = 0;i < 5;++i) { add(new LookupKV<>(new EnrichmentKey(ENRICHMENT_TYPE, "indicator" + i) , new EnrichmentValue(ImmutableMap.of("key" + i, "value" + i)) ) ); } }}); context = new Context.Builder() .with( Context.Capabilities.GLOBAL_CONFIG , () -> ImmutableMap.of( SimpleHBaseEnrichmentFunctions.TABLE_PROVIDER_TYPE_CONF , MockHBaseTableProvider.class.getName() ) ) .build(); } public Object run(String rule, Map<String, Object> variables) throws Exception {
public static void setupStellarStatically(CuratorFramework client, Optional<String> globalConfig) { /* In order to validate stellar functions, the function resolver must be initialized. Otherwise, those utilities that require validation cannot validate the stellar expressions necessarily. */ Context.Builder builder = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client); if(globalConfig.isPresent()) { builder = builder .with(Context.Capabilities.GLOBAL_CONFIG, () -> GLOBAL.deserialize(globalConfig.get())) .with(Context.Capabilities.STELLAR_CONFIG, () -> GLOBAL.deserialize(globalConfig.get())); } else { builder = builder .with(Context.Capabilities.STELLAR_CONFIG, () -> new HashMap<>()); } Context stellarContext = builder.build(); StellarFunctions.FUNCTION_RESOLVER().initialize(stellarContext); }
public static void setupStellarStatically(CuratorFramework client, Optional<String> globalConfig) { /* In order to validate stellar functions, the function resolver must be initialized. Otherwise, those utilities that require validation cannot validate the stellar expressions necessarily. */ Context.Builder builder = new Context.Builder().with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) ; if(globalConfig.isPresent()) { builder = builder.with(Context.Capabilities.GLOBAL_CONFIG, () -> GLOBAL.deserialize(globalConfig.get())) .with(Context.Capabilities.STELLAR_CONFIG, () -> GLOBAL.deserialize(globalConfig.get())); } else { builder = builder.with(Context.Capabilities.STELLAR_CONFIG, () -> new HashMap<>()); } Context stellarContext = builder.build(); StellarFunctions.FUNCTION_RESOLVER().initialize(stellarContext); }
@Before public void setup() throws Exception { context = new Context.Builder() .with(Context.Capabilities.GLOBAL_CONFIG, HashMap::new) .build(); // Store the passwords in the local file system FileUtils.writeStringToFile(new File(basicAuthPasswordPath), basicAuthPassword, StandardCharsets.UTF_8); FileUtils.writeStringToFile(new File(proxyBasicAuthPasswordPath), proxyAuthPassword, StandardCharsets.UTF_8); // By default, the mock server expects a GET request with the path set to /get getUri = String.format("http://localhost:%d/get", mockServerRule.getPort()); mockServerClient.when( request() .withMethod("GET") .withPath("/get")) .respond(response() .withBody("{\"get\":\"success\"}")); }
@Before public void setup() throws Exception { // create the cache Map<String, Object> cacheConfig = ImmutableMap.of( CachingStellarProcessor.MAX_CACHE_SIZE_PARAM, 2, CachingStellarProcessor.MAX_TIME_RETAIN_PARAM, 10, CachingStellarProcessor.RECORD_STATS, true ); cache = CachingStellarProcessor.createCache(cacheConfig); contextWithCache = new Context.Builder() .with(Context.Capabilities.CACHE, () -> cache) .build(); // create the object to test processor = new CachingStellarProcessor(); }
@BeforeClass public static void setup() { ConcurrencyContext infrastructure = new ConcurrencyContext(); infrastructure.initialize(5, 100, 10, null, null, false); stellarContext = new Context.Builder() .build(); StellarFunctions.initialize(stellarContext); StellarAdapter adapter = new AccessLoggingStellarAdapter().ofType("ENRICHMENT"); adapter.initializeAdapter(new HashMap<>()); EnrichmentAdapter<CacheKey> dummy = new DummyEnrichmentAdapter(); enrichmentsByType = ImmutableMap.of("stellar", adapter, "dummy", dummy); enricher = new ParallelEnricher(enrichmentsByType, infrastructure, false); }
@Before public void setup() throws Exception { context = new Context.Builder().build(); } @Test
@Test public void testListVarsWithoutVars() { Context context = new Context.Builder() .with(Context.Capabilities.SHELL_VARIABLES, () -> new HashMap<>()) .build(); Object out = run("SHELL_LIST_VARS()", new HashMap<>(), context); Assert.assertEquals(expectedEmptyList, out); } /**
private Context getStellarContext() { Map<String, Object> global = getConfigurations().getGlobalConfig(); return new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> zookeeperClient) .with(Context.Capabilities.GLOBAL_CONFIG, () -> global) .with(Context.Capabilities.STELLAR_CONFIG, () -> global) .build(); }
@Before public void setup() throws Exception { testFolder.create(); context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG , () -> ImmutableMap.of(GeoLiteCityDatabase.GEO_HDFS_FILE, geoHdfsFile.getAbsolutePath()) ) .build(); }
/** * Create the execution context for running Stellar. */ public static Context getContext(Map<String, String> globals) { Context context = new Context.Builder() .with(Context.Capabilities.GLOBAL_CONFIG, () -> globals) .with(Context.Capabilities.STELLAR_CONFIG, () -> globals) .build(); StellarFunctions.initialize(context); return context; } }
protected void initializeStellar() { this.stellarContext = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) .with(Context.Capabilities.GLOBAL_CONFIG, () -> getConfigurations().getGlobalConfig()) .with(Context.Capabilities.STELLAR_CONFIG, () -> getConfigurations().getGlobalConfig()) .build(); StellarFunctions.initialize(stellarContext); this.functionResolver = StellarFunctions.FUNCTION_RESOLVER(); }
protected void initializeStellar() { stellarContext = new Context.Builder() .with(Context.Capabilities.ZOOKEEPER_CLIENT, () -> client) .with(Context.Capabilities.GLOBAL_CONFIG, () -> getConfigurations().getGlobalConfig()) .with(Context.Capabilities.STELLAR_CONFIG, () -> getConfigurations().getGlobalConfig()) .build(); StellarFunctions.initialize(stellarContext); }
@Before public void setup() throws Exception { testFolder.create(); context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> ImmutableMap.of(GeoLiteAsnDatabase.ASN_HDFS_FILE, asnHdfsFile.getAbsolutePath()) ).build(); }
@Test public void testMissingDb() { context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG , () -> ImmutableMap.of(GeoLiteCityDatabase.GEO_HDFS_FILE, "./fakefile.mmdb") ).build(); String stellar = "GEO_GET()"; try { run(stellar, ImmutableMap.of()); } catch (Exception expected) { Assert.assertTrue(expected.getMessage().contains("File fakefile.mmdb does not exist")); } }
@Before public void setup() throws Exception { context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG , () -> ImmutableMap.of(GeoLiteCityDatabase.GEO_HDFS_FILE, geoHdfsFile.getAbsolutePath()) ) .build(); }
@Test public void testMissingDb() { context = new Context.Builder().with(Context.Capabilities.GLOBAL_CONFIG, () -> ImmutableMap.of(GeoLiteAsnDatabase.ASN_HDFS_FILE, "./fakefile.mmdb") ).build(); String stellar = "ASN_GET()"; try { run(stellar, ImmutableMap.of()); } catch (Exception expected) { Assert.assertTrue(expected.getMessage().contains("File fakefile.mmdb does not exist")); } }