Search in sources :

Example 1 with StreamClient

use of co.cask.cdap.client.StreamClient 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();
}
Also used : StreamService(co.cask.cdap.data.stream.service.StreamService) DiscoveryServiceClient(org.apache.twill.discovery.DiscoveryServiceClient) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) AppFabricServer(co.cask.cdap.internal.app.services.AppFabricServer) MetricsCollectionService(co.cask.cdap.api.metrics.MetricsCollectionService) MetadataService(co.cask.cdap.metadata.MetadataService) Service(com.google.common.util.concurrent.Service) MessagingService(co.cask.cdap.messaging.MessagingService) MetricsQueryService(co.cask.cdap.metrics.query.MetricsQueryService) StreamService(co.cask.cdap.data.stream.service.StreamService) RemoteSystemOperationsService(co.cask.cdap.gateway.handlers.meta.RemoteSystemOperationsService) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DatasetService(co.cask.cdap.data2.datafabric.dataset.service.DatasetService) DatasetOpExecutor(co.cask.cdap.data2.datafabric.dataset.service.executor.DatasetOpExecutor) RemoteSystemOperationsService(co.cask.cdap.gateway.handlers.meta.RemoteSystemOperationsService) ServiceDiscovered(org.apache.twill.discovery.ServiceDiscovered) MetadataService(co.cask.cdap.metadata.MetadataService) AbstractModule(com.google.inject.AbstractModule) MessagingService(co.cask.cdap.messaging.MessagingService) LocationFactory(org.apache.twill.filesystem.LocationFactory) TransactionSystemClient(org.apache.tephra.TransactionSystemClient) DatasetClient(co.cask.cdap.client.DatasetClient) ServiceStore(co.cask.cdap.app.store.ServiceStore) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy) EndpointStrategy(co.cask.cdap.common.discovery.EndpointStrategy) StreamClient(co.cask.cdap.client.StreamClient) TransactionManager(org.apache.tephra.TransactionManager) CurrentUGIProvider(co.cask.cdap.security.impersonation.CurrentUGIProvider) AppFabricTestModule(co.cask.cdap.internal.guice.AppFabricTestModule) RandomEndpointStrategy(co.cask.cdap.common.discovery.RandomEndpointStrategy)

Example 2 with StreamClient

use of co.cask.cdap.client.StreamClient in project cdap-ingest by caskdata.

the class PollingListenerImpl method getStreamWriterForPipe.

/**
 * create StreamWriter for pipe
 *
 * @param pipeConf the pipe configuration
 * @return the pipe's streamWriter
 * @throws java.io.IOException streamWriter creation failed
 */
private StreamWriter getStreamWriterForPipe(PipeConfiguration pipeConf) throws IOException {
    StreamClient client = pipeConf.getSinkConfiguration().getStreamClient();
    String streamName = pipeConf.getSinkConfiguration().getStreamName();
    try {
        client.create(streamName);
        StreamWriter writer = client.createWriter(streamName);
        return writer;
    } catch (IOException e) {
        throw new IOException(String.format("Cannot create/get client stream by name: %s: %s", streamName, e));
    }
}
Also used : StreamClient(co.cask.cdap.client.StreamClient) StreamWriter(co.cask.cdap.client.StreamWriter) IOException(java.io.IOException)

Example 3 with StreamClient

use of co.cask.cdap.client.StreamClient in project cdap-ingest by caskdata.

the class CdapFlumeIT method createStream.

private void createStream() throws Exception {
    RestStreamClient.Builder builder = RestStreamClient.builder(streamReader.getCdapHost(), streamReader.getCdapPort()).ssl(streamReader.getSsl());
    if (streamReader.getAuthClientPropertiesPath() != null) {
        AuthenticationClient authClient = streamReader.createAuthClient();
        builder.authClient(authClient);
    }
    StreamClient streamClient = builder.build();
    streamClient.create(streamName);
}
Also used : StreamClient(co.cask.cdap.client.StreamClient) RestStreamClient(co.cask.cdap.client.rest.RestStreamClient) RestStreamClient(co.cask.cdap.client.rest.RestStreamClient) AuthenticationClient(co.cask.cdap.security.authentication.client.AuthenticationClient)

Example 4 with StreamClient

use of co.cask.cdap.client.StreamClient in project cdap by caskdata.

the class GenerateClientUsageExample method streamClient.

public void streamClient() throws Exception {
    // Construct the client used to interact with CDAP
    StreamClient streamClient = new StreamClient(clientConfig);
    // Fetch the stream list
    List streams = streamClient.list(NamespaceId.DEFAULT);
    // Create a stream, using the Purchase example
    StreamId streamId = NamespaceId.DEFAULT.stream("purchases");
    streamClient.create(streamId);
    // Fetch a stream's properties
    StreamProperties config = streamClient.getConfig(streamId);
    // Send events to a stream
    streamClient.sendEvent(streamId, "Tom bought 5 apples for $10");
    // Read all events from a stream (results in events)
    List<StreamEvent> events = Lists.newArrayList();
    streamClient.getEvents(streamId, 0, Long.MAX_VALUE, Integer.MAX_VALUE, events);
    // Read first 5 events from a stream (results in events)
    events = Lists.newArrayList();
    streamClient.getEvents(streamId, 0, Long.MAX_VALUE, 5, events);
    // Read 2nd and 3rd events from a stream, after first calling getEvents
    long startTime = events.get(1).getTimestamp();
    long endTime = events.get(2).getTimestamp() + 1;
    events.clear();
    streamClient.getEvents(streamId, startTime, endTime, Integer.MAX_VALUE, events);
    // Write asynchronously to a stream
    streamId = NamespaceId.DEFAULT.stream("testAsync");
    events = Lists.newArrayList();
    streamClient.create(streamId);
    // Send 10 async writes
    int msgCount = 10;
    for (int i = 0; i < msgCount; i++) {
        streamClient.asyncSendEvent(streamId, "Testing " + i);
    }
    // Read them back; need to read it multiple times as the writes happen asynchronously
    while (events.size() != msgCount) {
        events.clear();
        streamClient.getEvents(streamId, 0, Long.MAX_VALUE, msgCount, events);
    }
    // Check that there are no more events
    events.clear();
    while (events.isEmpty()) {
        events.clear();
        streamClient.getEvents(streamId, 0, Long.MAX_VALUE, msgCount, events);
    }
// End write asynchronously
}
Also used : StreamId(co.cask.cdap.proto.id.StreamId) StreamClient(co.cask.cdap.client.StreamClient) StreamEvent(co.cask.cdap.api.flow.flowlet.StreamEvent) StreamProperties(co.cask.cdap.proto.StreamProperties) List(java.util.List)

Example 5 with StreamClient

use of co.cask.cdap.client.StreamClient in project cdap-ingest by caskdata.

the class FileTailerIT method mockMetricsProcessor.

private void mockMetricsProcessor(PipeManager manager) throws IOException, NoSuchMethodException, InvocationTargetException, IllegalAccessException, NoSuchFieldException {
    List<Pipe> pipeList = new ArrayList<Pipe>();
    StreamClient client = null;
    StreamWriter writer = null;
    try {
        Method method1 = manager.getClass().getDeclaredMethod("getPipeConfigs");
        method1.setAccessible(true);
        List<PipeConfiguration> pipeConfList = (List<PipeConfiguration>) method1.invoke(manager);
        for (PipeConfiguration pipeConf : pipeConfList) {
            FileTailerQueue queue = new FileTailerQueue(pipeConf.getQueueSize());
            client = pipeConf.getSinkConfiguration().getStreamClient();
            String streamName = pipeConf.getSinkConfiguration().getStreamName();
            Method method2 = manager.getClass().getDeclaredMethod("getStreamWriterForPipe", StreamClient.class, String.class);
            method2.setAccessible(true);
            writer = (StreamWriter) method2.invoke(manager, client, streamName);
            FileTailerStateProcessor stateProcessor = new FileTailerStateProcessorImpl(pipeConf.getDaemonDir(), pipeConf.getStateFile());
            FileTailerMetricsProcessor metricsProcessor = new FileTailerMetricsProcessor(pipeConf.getDaemonDir(), pipeConf.getStatisticsFile(), pipeConf.getStatisticsSleepInterval(), pipeConf.getPipeName(), pipeConf.getSourceConfiguration().getFileName()) {

                @Override
                public void onReadEventMetric(int eventSize) {
                    super.onReadEventMetric(eventSize);
                    read.incrementAndGet();
                }

                @Override
                public void onIngestEventMetric(int latency) {
                    super.onIngestEventMetric(latency);
                    ingest.incrementAndGet();
                }
            };
            pipeList.add(new Pipe(new LogTailer(pipeConf, queue, stateProcessor, metricsProcessor, null), new FileTailerSink(queue, writer, SinkStrategy.LOADBALANCE, stateProcessor, metricsProcessor, null, pipeConf.getSinkConfiguration().getPackSize()), metricsProcessor));
            client = null;
            writer = null;
        }
        Field field = manager.getClass().getDeclaredField("serviceManager");
        field.setAccessible(true);
        Field modifiersField = Field.class.getDeclaredField("modifiers");
        modifiersField.setAccessible(true);
        modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL);
        field.set(manager, new ServiceManager(pipeList));
    } finally {
        if (client != null) {
            client.close();
        }
        if (writer != null) {
            writer.close();
        }
    }
}
Also used : StreamWriter(co.cask.cdap.client.StreamWriter) ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) FileTailerStateProcessor(co.cask.cdap.filetailer.state.FileTailerStateProcessor) FileTailerMetricsProcessor(co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor) Field(java.lang.reflect.Field) FileTailerStateProcessorImpl(co.cask.cdap.filetailer.state.FileTailerStateProcessorImpl) PipeConfiguration(co.cask.cdap.filetailer.config.PipeConfiguration) FileTailerQueue(co.cask.cdap.filetailer.queue.FileTailerQueue) StreamClient(co.cask.cdap.client.StreamClient) LogTailer(co.cask.cdap.filetailer.tailer.LogTailer) FileTailerSink(co.cask.cdap.filetailer.sink.FileTailerSink) ServiceManager(com.google.common.util.concurrent.ServiceManager) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

StreamClient (co.cask.cdap.client.StreamClient)6 StreamWriter (co.cask.cdap.client.StreamWriter)3 PipeConfiguration (co.cask.cdap.filetailer.config.PipeConfiguration)2 FileTailerMetricsProcessor (co.cask.cdap.filetailer.metrics.FileTailerMetricsProcessor)2 FileTailerQueue (co.cask.cdap.filetailer.queue.FileTailerQueue)2 FileTailerSink (co.cask.cdap.filetailer.sink.FileTailerSink)2 FileTailerStateProcessor (co.cask.cdap.filetailer.state.FileTailerStateProcessor)2 FileTailerStateProcessorImpl (co.cask.cdap.filetailer.state.FileTailerStateProcessorImpl)2 LogTailer (co.cask.cdap.filetailer.tailer.LogTailer)2 ServiceManager (com.google.common.util.concurrent.ServiceManager)2 List (java.util.List)2 StreamEvent (co.cask.cdap.api.flow.flowlet.StreamEvent)1 MetricsCollectionService (co.cask.cdap.api.metrics.MetricsCollectionService)1 ServiceStore (co.cask.cdap.app.store.ServiceStore)1 DatasetClient (co.cask.cdap.client.DatasetClient)1 RestStreamClient (co.cask.cdap.client.rest.RestStreamClient)1 EndpointStrategy (co.cask.cdap.common.discovery.EndpointStrategy)1 RandomEndpointStrategy (co.cask.cdap.common.discovery.RandomEndpointStrategy)1 StreamService (co.cask.cdap.data.stream.service.StreamService)1 DatasetService (co.cask.cdap.data2.datafabric.dataset.service.DatasetService)1