use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.
the class ByteStreamClientFactory method withScope.
/**
* Creates a new instance of ByteStreamClientFactory.
*
* @param scope The scope string.
* @param config Configuration for the client.
* @return Instance of ByteStreamClientFactory implementation.
*/
static ByteStreamClientFactory withScope(String scope, ClientConfig config) {
val connectionFactory = new SocketConnectionFactoryImpl(config);
ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(config).build(), connectionFactory.getInternalExecutor());
val connectionPool = new ConnectionPoolImpl(config, Preconditions.checkNotNull(connectionFactory));
val inputStreamFactory = new SegmentInputStreamFactoryImpl(controller, connectionPool);
val outputStreamFactory = new SegmentOutputStreamFactoryImpl(controller, connectionPool);
val metaStreamFactory = new SegmentMetadataClientFactoryImpl(controller, connectionPool);
return new ByteStreamClientImpl(scope, controller, connectionPool, inputStreamFactory, outputStreamFactory, metaStreamFactory);
}
use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.
the class SynchronizerClientFactory method withScope.
/**
* Creates a new instance of Client Factory.
*
* @param scope The scope string.
* @param config Configuration for the client.
* @return Instance of ClientFactory implementation.
*/
static SynchronizerClientFactory withScope(String scope, ClientConfig config) {
// Change the max number of number of allowed connections to the segment store to 1.
val updatedConfig = config.toBuilder().maxConnectionsPerSegmentStore(1).enableTlsToSegmentStore(config.isEnableTlsToSegmentStore()).enableTlsToController(config.isEnableTlsToController()).build();
val connectionFactory = new SocketConnectionFactoryImpl(updatedConfig, 1);
return new ClientFactoryImpl(scope, new ControllerImpl(ControllerImplConfig.builder().clientConfig(updatedConfig).build(), connectionFactory.getInternalExecutor()), updatedConfig, connectionFactory);
}
use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.
the class StreamMetadataTasksTest method setup.
@Before
public void setup() throws Exception {
zkServer = new TestingServerStarter().start();
zkServer.start();
zkClient = CuratorFrameworkFactory.newClient(zkServer.getConnectString(), new ExponentialBackoffRetry(200, 10, 5000));
zkClient.start();
StreamMetrics.initialize();
TransactionMetrics.initialize();
StreamMetadataStore streamStore = getStore();
// create a partial mock.
streamStorePartialMock = spy(streamStore);
ImmutableMap<BucketStore.ServiceType, Integer> map = ImmutableMap.of(BucketStore.ServiceType.RetentionService, 1, BucketStore.ServiceType.WatermarkingService, 1);
bucketStore = StreamStoreFactory.createInMemoryBucketStore(map);
kvtStore = spy(getKvtStore());
TaskMetadataStore taskMetadataStore = TaskStoreFactory.createZKStore(zkClient, executor);
SegmentHelper segmentHelperMock = SegmentHelperMock.getSegmentHelperMock();
connectionFactory = new SocketConnectionFactoryImpl(ClientConfig.builder().build());
EventHelper helper = EventHelperMock.getEventHelperMock(executor, "host", ((AbstractStreamMetadataStore) streamStore).getHostTaskIndex());
streamMetadataTasks = spy(new StreamMetadataTasks(streamStorePartialMock, bucketStore, taskMetadataStore, segmentHelperMock, executor, "host", new GrpcAuthHelper(authEnabled, "key", 300), helper));
EventHelper helperMock = EventHelperMock.getEventHelperMock(executor, "host", ((AbstractStreamMetadataStore) streamStore).getHostTaskIndex());
kvtMetadataTasks = spy(new TableMetadataTasks(kvtStore, segmentHelperMock, executor, executor, "host", GrpcAuthHelper.getDisabledAuthHelper(), helperMock));
streamTransactionMetadataTasks = new StreamTransactionMetadataTasks(streamStorePartialMock, segmentHelperMock, executor, "host", new GrpcAuthHelper(authEnabled, "key", 300));
this.streamRequestHandler = new StreamRequestHandler(new AutoScaleTask(streamMetadataTasks, streamStorePartialMock, executor), new ScaleOperationTask(streamMetadataTasks, streamStorePartialMock, executor), new UpdateStreamTask(streamMetadataTasks, streamStorePartialMock, bucketStore, executor), new SealStreamTask(streamMetadataTasks, streamTransactionMetadataTasks, streamStorePartialMock, executor), new DeleteStreamTask(streamMetadataTasks, streamStorePartialMock, bucketStore, executor), new TruncateStreamTask(streamMetadataTasks, streamStorePartialMock, executor), new CreateReaderGroupTask(streamMetadataTasks, streamStorePartialMock, executor), new DeleteReaderGroupTask(streamMetadataTasks, streamStorePartialMock, executor), new UpdateReaderGroupTask(streamMetadataTasks, streamStore, executor), streamStorePartialMock, new DeleteScopeTask(streamMetadataTasks, streamStore, kvtStore, kvtMetadataTasks, executor), executor);
consumer = new ControllerService(kvtStore, kvtMetadataTasks, streamStorePartialMock, bucketStore, streamMetadataTasks, streamTransactionMetadataTasks, segmentHelperMock, executor, null, requestTracker);
commitWriter = new EventStreamWriterMock<>();
abortWriter = new EventStreamWriterMock<>();
streamTransactionMetadataTasks.initializeStreamWriters(commitWriter, abortWriter);
final ScalingPolicy policy1 = ScalingPolicy.fixed(2);
final StreamConfiguration configuration1 = StreamConfiguration.builder().scalingPolicy(policy1).build();
streamStorePartialMock.createScope(SCOPE, null, executor).join();
// stream1
long start = System.currentTimeMillis();
streamStorePartialMock.createStream(SCOPE, stream1, configuration1, start, null, executor).get();
streamStorePartialMock.setState(SCOPE, stream1, State.ACTIVE, null, executor).get();
AbstractMap.SimpleEntry<Double, Double> segment1 = new AbstractMap.SimpleEntry<>(0.5, 0.75);
AbstractMap.SimpleEntry<Double, Double> segment2 = new AbstractMap.SimpleEntry<>(0.75, 1.0);
List<Long> sealedSegments = Collections.singletonList(1L);
VersionedMetadata<EpochTransitionRecord> response = streamStorePartialMock.submitScale(SCOPE, stream1, sealedSegments, Arrays.asList(segment1, segment2), start + 20, null, null, executor).get();
VersionedMetadata<State> state = streamStorePartialMock.getVersionedState(SCOPE, stream1, null, executor).join();
state = streamStorePartialMock.updateVersionedState(SCOPE, stream1, State.SCALING, state, null, executor).join();
streamStorePartialMock.startScale(SCOPE, stream1, false, response, state, null, executor).join();
streamStorePartialMock.scaleCreateNewEpochs(SCOPE, stream1, response, null, executor).get();
streamStorePartialMock.scaleSegmentsSealed(SCOPE, stream1, sealedSegments.stream().collect(Collectors.toMap(x -> x, x -> 0L)), response, null, executor).get();
streamStorePartialMock.completeScale(SCOPE, stream1, response, null, executor).join();
streamStorePartialMock.updateVersionedState(SCOPE, stream1, State.ACTIVE, state, null, executor).get();
// stream2
streamStorePartialMock.createStream(SCOPE, stream2, configuration1, System.currentTimeMillis(), null, executor).get();
streamStorePartialMock.setState(SCOPE, stream1, State.ACTIVE, null, executor).get();
streamStorePartialMock.createStream(SCOPE, stream3, configuration1, System.currentTimeMillis(), null, executor).get();
streamStorePartialMock.setState(SCOPE, stream1, State.ACTIVE, null, executor).get();
}
use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.
the class PravegaTest method simpleTest.
/**
* Invoke the simpleTest, ensure we are able to produce events.
* The test fails incase of exceptions while writing to the stream.
*/
@Test
public void simpleTest() {
Service conService = Utils.createPravegaControllerService(null);
List<URI> ctlURIs = conService.getServiceDetails();
URI controllerUri = ctlURIs.get(0);
log.info("Invoking create stream with Controller URI: {}", controllerUri);
@Cleanup ConnectionFactory connectionFactory = new SocketConnectionFactoryImpl(Utils.buildClientConfig(controllerUri));
@Cleanup ControllerImpl controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(Utils.buildClientConfig(controllerUri)).build(), connectionFactory.getInternalExecutor());
assertTrue(controller.createScope(STREAM_SCOPE).join());
assertTrue(controller.createStream(STREAM_SCOPE, STREAM_NAME, config).join());
@Cleanup EventStreamClientFactory clientFactory = EventStreamClientFactory.withScope(STREAM_SCOPE, Utils.buildClientConfig(controllerUri));
log.info("Invoking Writer test with Controller URI: {}", controllerUri);
@Cleanup EventStreamWriter<Serializable> writer = clientFactory.createEventWriter(STREAM_NAME, new JavaSerializer<>(), EventWriterConfig.builder().build());
for (int i = 0; i < NUM_EVENTS; i++) {
String event = "Publish " + i + "\n";
log.debug("Producing event: {} ", event);
// any exceptions while writing the event will fail the test.
writer.writeEvent("", event);
writer.flush();
}
log.info("Invoking Reader test.");
ReaderGroupManager groupManager = ReaderGroupManager.withScope(STREAM_SCOPE, Utils.buildClientConfig(controllerUri));
groupManager.createReaderGroup(READER_GROUP, ReaderGroupConfig.builder().stream(Stream.of(STREAM_SCOPE, STREAM_NAME)).build());
@Cleanup EventStreamReader<String> reader = clientFactory.createReader(UUID.randomUUID().toString(), READER_GROUP, new JavaSerializer<>(), ReaderConfig.builder().build());
int readCount = 0;
EventRead<String> event = null;
do {
event = reader.readNextEvent(10_000);
log.debug("Read event: {}.", event.getEvent());
if (event.getEvent() != null) {
readCount++;
}
// try reading until all the written events are read, else the test will timeout.
} while ((event.getEvent() != null || event.isCheckpoint()) && readCount < NUM_EVENTS);
assertEquals("Read count should be equal to write count", NUM_EVENTS, readCount);
}
use of io.pravega.client.connection.impl.SocketConnectionFactoryImpl in project pravega by pravega.
the class BookieFailoverTest method setup.
@Before
public void setup() {
// Get zk details to verify if controller, SSS are running
Service zkService = Utils.createZookeeperService();
List<URI> zkUris = zkService.getServiceDetails();
log.debug("Zookeeper service details: {}", zkUris);
// get the zk ip details and pass it to host, controller
URI zkUri = zkUris.get(0);
// Verify bookie is running
bookkeeperService = Utils.createBookkeeperService(zkUri);
List<URI> bkUris = bookkeeperService.getServiceDetails();
log.debug("Bookkeeper service details: {}", bkUris);
// Verify controller is running.
controllerInstance = Utils.createPravegaControllerService(zkUri);
assertTrue(controllerInstance.isRunning());
List<URI> conURIs = controllerInstance.getServiceDetails();
log.info("Pravega Controller service instance details: {}", conURIs);
// Fetch all the RPC endpoints and construct the client URIs.
final List<String> uris = conURIs.stream().filter(ISGRPC).map(URI::getAuthority).collect(Collectors.toList());
controllerURIDirect = URI.create((Utils.TLS_AND_AUTH_ENABLED ? TLS : TCP) + String.join(",", uris));
log.info("Controller Service direct URI: {}", controllerURIDirect);
// Verify segment store is running.
segmentStoreInstance = Utils.createPravegaSegmentStoreService(zkUri, controllerURIDirect);
assertTrue(segmentStoreInstance.isRunning());
log.info("Pravega Segmentstore service instance details: {}", segmentStoreInstance.getServiceDetails());
executorService = ExecutorServiceHelpers.newScheduledThreadPool(NUM_READERS + NUM_WRITERS + 1, "BookieFailoverTest-main");
controllerExecutorService = ExecutorServiceHelpers.newScheduledThreadPool(2, "BookieFailoverTest-controller");
// get Controller Uri
controller = new ControllerImpl(ControllerImplConfig.builder().clientConfig(Utils.buildClientConfig(controllerURIDirect)).maxBackoffMillis(5000).build(), controllerExecutorService);
testState = new TestState(false);
// read and write count variables
testState.writersListComplete.add(0, testState.writersComplete);
streamManager = new StreamManagerImpl(Utils.buildClientConfig(controllerURIDirect));
createScopeAndStream(SCOPE, STREAM, config, streamManager);
log.info("Scope passed to client factory {}", SCOPE);
clientFactory = new ClientFactoryImpl(SCOPE, controller, new SocketConnectionFactoryImpl(Utils.buildClientConfig(controllerURIDirect)));
readerGroupManager = ReaderGroupManager.withScope(SCOPE, Utils.buildClientConfig(controllerURIDirect));
}
Aggregations