use of io.cdap.cdap.common.conf.SConfiguration in project cdap by caskdata.
the class TaskWorkerMetricsTest method beforeTest.
@Before
public void beforeTest() {
CConfiguration cConf = createCConf();
SConfiguration sConf = SConfiguration.create();
published = new ArrayList<>();
AggregatedMetricsCollectionService mockMetricsCollector = new AggregatedMetricsCollectionService(1000L) {
@Override
protected void publish(Iterator<MetricValues> metrics) {
Iterators.addAll(published, metrics);
}
};
mockMetricsCollector.startAndWait();
taskWorkerService = new TaskWorkerService(cConf, sConf, new InMemoryDiscoveryService(), (namespaceId, retryStrategy) -> null, mockMetricsCollector);
taskWorkerStateFuture = TaskWorkerTestUtil.getServiceCompletionFuture(taskWorkerService);
// start the service
taskWorkerService.startAndWait();
InetSocketAddress addr = taskWorkerService.getBindAddress();
this.uri = URI.create(String.format("http://%s:%s", addr.getHostName(), addr.getPort()));
}
use of io.cdap.cdap.common.conf.SConfiguration in project cdap by caskdata.
the class TaskWorkerServiceTest method testRestartAfterMultipleExecutions.
@Test
public void testRestartAfterMultipleExecutions() throws IOException {
CConfiguration cConf = createCConf();
SConfiguration sConf = createSConf();
cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_REQUEST_COUNT, 2);
cConf.setInt(Constants.TaskWorker.CONTAINER_KILL_AFTER_DURATION_SECOND, 0);
TaskWorkerService taskWorkerService = new TaskWorkerService(cConf, sConf, new InMemoryDiscoveryService(), (namespaceId, retryStrategy) -> null, new NoOpMetricsCollectionService());
serviceCompletionFuture = TaskWorkerTestUtil.getServiceCompletionFuture(taskWorkerService);
// start the service
taskWorkerService.startAndWait();
InetSocketAddress addr = taskWorkerService.getBindAddress();
URI uri = URI.create(String.format("http://%s:%s", addr.getHostName(), addr.getPort()));
// Post valid request
String want = "100";
RunnableTaskRequest req = RunnableTaskRequest.getBuilder(TestRunnableClass.class.getName()).withParam(want).build();
String reqBody = GSON.toJson(req);
HttpResponse response = HttpRequests.execute(HttpRequest.post(uri.resolve("/v3Internal/worker/run").toURL()).withBody(reqBody).build(), new DefaultHttpRequestConfig(false));
response = HttpRequests.execute(HttpRequest.post(uri.resolve("/v3Internal/worker/run").toURL()).withBody(reqBody).build(), new DefaultHttpRequestConfig(false));
TaskWorkerTestUtil.waitForServiceCompletion(serviceCompletionFuture);
Assert.assertEquals(Service.State.TERMINATED, taskWorkerService.state());
}
use of io.cdap.cdap.common.conf.SConfiguration in project cdap by caskdata.
the class RouterResource method before.
@Override
protected void before() {
CConfiguration cConf = CConfiguration.create();
Injector injector = Guice.createInjector(new CoreSecurityRuntimeModule().getStandaloneModules(), new ExternalAuthenticationModule(), new InMemoryDiscoveryModule(), new AppFabricTestModule(cConf));
DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
TokenValidator mockValidator = new MockTokenValidator("failme");
UserIdentityExtractor extractor = new MockAccessTokenIdentityExtractor(mockValidator);
SConfiguration sConf = injector.getInstance(SConfiguration.class);
cConf.set(Constants.Router.ADDRESS, hostname);
cConf.setInt(Constants.Router.ROUTER_PORT, 0);
for (Map.Entry<String, String> entry : additionalConfig.entrySet()) {
cConf.set(entry.getKey(), entry.getValue());
}
router = new NettyRouter(cConf, sConf, InetAddresses.forString(hostname), new RouterServiceLookup(cConf, (DiscoveryServiceClient) discoveryService, new RouterPathLookup()), mockValidator, extractor, discoveryServiceClient);
router.startAndWait();
}
use of io.cdap.cdap.common.conf.SConfiguration in project cdap by caskdata.
the class AuditLogTest method init.
@BeforeClass
public static void init() throws Exception {
// Configure a log appender programmatically for the audit log
TestLogAppender.addAppender(Constants.Router.AUDIT_LOGGER_NAME);
((ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Constants.Router.AUDIT_LOGGER_NAME)).setLevel(Level.TRACE);
CConfiguration cConf = CConfiguration.create();
SConfiguration sConf = SConfiguration.create();
cConf.set(Constants.Router.ADDRESS, InetAddress.getLoopbackAddress().getHostAddress());
cConf.setInt(Constants.Router.ROUTER_PORT, 0);
cConf.setBoolean(Constants.Router.ROUTER_AUDIT_LOG_ENABLED, true);
InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
RouterServiceLookup serviceLookup = new RouterServiceLookup(cConf, discoveryService, new RouterPathLookup());
TokenValidator successValidator = new SuccessTokenValidator();
router = new NettyRouter(cConf, sConf, InetAddress.getLoopbackAddress(), serviceLookup, successValidator, new MockAccessTokenIdentityExtractor(successValidator), discoveryService);
router.startAndWait();
httpService = NettyHttpService.builder("test").setHttpHandlers(new TestHandler()).build();
httpService.start();
cancelDiscovery = discoveryService.register(new Discoverable(Constants.Service.APP_FABRIC_HTTP, httpService.getBindAddress()));
int port = router.getBoundAddress().orElseThrow(IllegalStateException::new).getPort();
baseURI = URI.create(String.format("http://%s:%d", cConf.get(Constants.Router.ADDRESS), port));
}
use of io.cdap.cdap.common.conf.SConfiguration in project cdap by caskdata.
the class PreviewRunnerTwillRunnable method createInjector.
@VisibleForTesting
static Injector createInjector(CConfiguration cConf, Configuration hConf, PreviewRequestPollerInfo pollerInfo) {
List<Module> modules = new ArrayList<>();
byte[] pollerInfoBytes = Bytes.toBytes(new Gson().toJson(pollerInfo));
SConfiguration sConf = SConfiguration.create();
modules.add(new ConfigModule(cConf, hConf, sConf));
modules.add(RemoteAuthenticatorModules.getDefaultModule());
modules.add(new PreviewConfigModule(cConf, hConf, sConf));
modules.add(new IOModule());
modules.add(new MetricsClientRuntimeModule().getDistributedModules());
// If MasterEnvironment is not available, assuming it is the old hadoop stack with ZK, Kafka
MasterEnvironment masterEnv = MasterEnvironments.getMasterEnvironment();
if (masterEnv == null) {
modules.add(new ZKClientModule());
modules.add(new ZKDiscoveryModule());
modules.add(new KafkaClientModule());
modules.add(new KafkaLogAppenderModule());
} else {
modules.add(new AbstractModule() {
@Override
protected void configure() {
bind(DiscoveryService.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceSupplier()));
bind(DiscoveryServiceClient.class).toProvider(new SupplierProviderBridge<>(masterEnv.getDiscoveryServiceClientSupplier()));
}
});
modules.add(new RemoteLogAppenderModule());
}
modules.add(new PreviewRunnerManagerModule().getDistributedModules());
modules.add(new DataSetServiceModules().getStandaloneModules());
modules.add(new DataSetsModules().getStandaloneModules());
modules.add(new AppFabricServiceRuntimeModule(cConf).getStandaloneModules());
modules.add(new ProgramRunnerRuntimeModule().getStandaloneModules());
modules.add(new MetricsStoreModule());
modules.add(new MessagingClientModule());
modules.add(new AuditModule());
modules.add(new SecureStoreClientModule());
modules.add(new MetadataReaderWriterModules().getStandaloneModules());
modules.add(new DFSLocationModule());
modules.add(new MetadataServiceModule());
modules.add(new CoreSecurityRuntimeModule().getInMemoryModules());
modules.add(new AuthenticationContextModules().getMasterWorkerModule());
modules.add(new AuthorizationModule());
modules.add(new AuthorizationEnforcementModule().getNoOpModules());
modules.add(Modules.override(new DataFabricModules("master").getDistributedModules()).with(new AbstractModule() {
@Override
protected void configure() {
// Bind transaction system to a constant one, basically no transaction, with every write become
// visible immediately.
// TODO: Ideally we shouldn't need this at all. However, it is needed now to satisfy dependencies
bind(TransactionSystemClientService.class).to(DelegatingTransactionSystemClientService.class);
bind(TransactionSystemClient.class).to(ConstantTransactionSystemClient.class);
bind(ExploreClient.class).to(UnsupportedExploreClient.class);
bind(PreviewRequestPollerInfoProvider.class).toInstance(() -> pollerInfoBytes);
}
}));
return Guice.createInjector(modules);
}
Aggregations