use of co.cask.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.
the class ArtifactHttpHandlerTest method setup.
@BeforeClass
public static void setup() throws IOException {
artifactRepository = getInjector().getInstance(ArtifactRepository.class);
DiscoveryServiceClient discoveryClient = getInjector().getInstance(DiscoveryServiceClient.class);
ServiceDiscovered metadataHttpDiscovered = discoveryClient.discover(Constants.Service.METADATA_SERVICE);
EndpointStrategy endpointStrategy = new RandomEndpointStrategy(metadataHttpDiscovered);
Discoverable discoverable = endpointStrategy.pick(1, TimeUnit.SECONDS);
Assert.assertNotNull(discoverable);
String host = "127.0.0.1";
int port = discoverable.getSocketAddress().getPort();
ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(host).setPort(port).build();
clientConfig = ClientConfig.builder().setConnectionConfig(connectionConfig).build();
metadataClient = new MetadataClient(clientConfig);
}
use of co.cask.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.
the class DefaultSecureStoreServiceTest method waitForService.
private static void waitForService(String service) {
EndpointStrategy endpointStrategy = new RandomEndpointStrategy(discoveryServiceClient.discover(service));
Preconditions.checkNotNull(endpointStrategy.pick(5, TimeUnit.SECONDS), "%s service is not up after 5 seconds", service);
}
use of co.cask.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.
the class AppFabricTestBase method initializeAndStartServices.
protected static void initializeAndStartServices(CConfiguration cConf, @Nullable SConfiguration sConf) throws Exception {
injector = Guice.createInjector(Modules.override(new AppFabricTestModule(cConf, sConf)).with(new AbstractModule() {
@Override
protected void configure() {
// needed because we set Kerberos to true in DefaultNamespaceAdminTest
bind(UGIProvider.class).to(CurrentUGIProvider.class);
}
}));
messagingService = injector.getInstance(MessagingService.class);
if (messagingService instanceof Service) {
((Service) messagingService).startAndWait();
}
txManager = injector.getInstance(TransactionManager.class);
txManager.startAndWait();
dsOpService = injector.getInstance(DatasetOpExecutor.class);
dsOpService.startAndWait();
remoteSysOpService = injector.getInstance(RemoteSystemOperationsService.class);
remoteSysOpService.startAndWait();
datasetService = injector.getInstance(DatasetService.class);
datasetService.startAndWait();
appFabricServer = injector.getInstance(AppFabricServer.class);
appFabricServer.startAndWait();
DiscoveryServiceClient discoveryClient = injector.getInstance(DiscoveryServiceClient.class);
ServiceDiscovered appFabricHttpDiscovered = discoveryClient.discover(Constants.Service.APP_FABRIC_HTTP);
EndpointStrategy endpointStrategy = new RandomEndpointStrategy(appFabricHttpDiscovered);
port = endpointStrategy.pick(1, TimeUnit.SECONDS).getSocketAddress().getPort();
txClient = injector.getInstance(TransactionSystemClient.class);
metricsCollectionService = injector.getInstance(MetricsCollectionService.class);
metricsCollectionService.startAndWait();
metricsService = injector.getInstance(MetricsQueryService.class);
metricsService.startAndWait();
streamService = injector.getInstance(StreamService.class);
streamService.startAndWait();
serviceStore = injector.getInstance(ServiceStore.class);
serviceStore.startAndWait();
metadataService = injector.getInstance(MetadataService.class);
metadataService.startAndWait();
locationFactory = getInjector().getInstance(LocationFactory.class);
streamClient = new StreamClient(getClientConfig(discoveryClient, Constants.Service.STREAMS));
datasetClient = new DatasetClient(getClientConfig(discoveryClient, Constants.Service.DATASET_MANAGER));
createNamespaces();
}
use of co.cask.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.
the class AppFabricTestBase method getClientConfig.
private static ClientConfig getClientConfig(DiscoveryServiceClient discoveryClient, String service) {
EndpointStrategy endpointStrategy = new RandomEndpointStrategy(discoveryClient.discover(service));
Discoverable discoverable = endpointStrategy.pick(1, TimeUnit.SECONDS);
Assert.assertNotNull(discoverable);
int port = discoverable.getSocketAddress().getPort();
ConnectionConfig connectionConfig = ConnectionConfig.builder().setHostname(hostname).setPort(port).build();
return ClientConfig.builder().setConnectionConfig(connectionConfig).build();
}
use of co.cask.cdap.common.discovery.RandomEndpointStrategy in project cdap by caskdata.
the class AppFabricServerTest method testSSL.
@Test
public void testSSL() throws IOException {
CConfiguration cConf = CConfiguration.create();
cConf.setBoolean(Constants.Security.SSL.INTERNAL_ENABLED, true);
cConf.setInt(Constants.AppFabric.SERVER_SSL_PORT, 20443);
SConfiguration sConf = SConfiguration.create();
final Injector injector = AppFabricTestHelper.getInjector(cConf, sConf, new AbstractModule() {
@Override
protected void configure() {
// no overrides
}
});
final DiscoveryServiceClient discoveryServiceClient = injector.getInstance(DiscoveryServiceClient.class);
AppFabricServer appFabricServer = injector.getInstance(AppFabricServer.class);
appFabricServer.startAndWait();
Assert.assertTrue(appFabricServer.isRunning());
Supplier<EndpointStrategy> endpointStrategySupplier = Suppliers.memoize(new Supplier<EndpointStrategy>() {
@Override
public EndpointStrategy get() {
return new RandomEndpointStrategy(discoveryServiceClient.discover(Constants.Service.APP_FABRIC_HTTP));
}
});
Discoverable discoverable = endpointStrategySupplier.get().pick(3, TimeUnit.SECONDS);
Assert.assertNotNull(discoverable);
Assert.assertArrayEquals(Constants.Security.SSL_URI_SCHEME.getBytes(), discoverable.getPayload());
InetSocketAddress addr = discoverable.getSocketAddress();
// Since the server uses a self signed certificate we need a client that trusts all certificates
SSLSocket socket = (SSLSocket) LDAPLoginModule.TrustAllSSLSocketFactory.getDefault().createSocket(addr.getHostName(), addr.getPort());
// in millis
socket.setSoTimeout(5000);
// Would throw exception if the server does not support ssl.
// "javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?"
socket.startHandshake();
appFabricServer.stopAndWait();
}
Aggregations