Search in sources :

Example 1 with RemoteData

use of org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData in project incubator-skywalking by apache.

the class RemoteServiceHandlerTestCase method callTest.

@Test
public void callTest() throws DuplicateProviderException, ProviderNotFoundException, IOException {
    final String testWorkerId = "mock-worker";
    ModuleManagerTesting moduleManager = new ModuleManagerTesting();
    ModuleDefineTesting moduleDefine = new ModuleDefineTesting();
    moduleManager.put(CoreModule.NAME, moduleDefine);
    WorkerInstancesService workerInstancesService = new WorkerInstancesService();
    moduleDefine.provider().registerServiceImplementation(IWorkerInstanceGetter.class, workerInstancesService);
    moduleDefine.provider().registerServiceImplementation(IWorkerInstanceSetter.class, workerInstancesService);
    TestWorker worker = new TestWorker(moduleManager);
    workerInstancesService.put(testWorkerId, worker, TestRemoteData.class);
    String serverName = InProcessServerBuilder.generateName();
    MetricsCreator metricsCreator = mock(MetricsCreator.class);
    when(metricsCreator.createCounter(any(), any(), any(), any())).thenReturn(new CounterMetrics() {

        @Override
        public void inc() {
        }

        @Override
        public void inc(double value) {
        }
    });
    when(metricsCreator.createHistogramMetric(any(), any(), any(), any())).thenReturn(new HistogramMetrics() {

        @Override
        public Timer createTimer() {
            return super.createTimer();
        }

        @Override
        public void observe(double value) {
        }
    });
    ModuleDefineTesting telemetryModuleDefine = new ModuleDefineTesting();
    moduleManager.put(TelemetryModule.NAME, telemetryModuleDefine);
    telemetryModuleDefine.provider().registerServiceImplementation(MetricsCreator.class, metricsCreator);
    gRPCCleanup.register(InProcessServerBuilder.forName(serverName).directExecutor().addService(new RemoteServiceHandler(moduleManager)).build().start());
    RemoteServiceGrpc.RemoteServiceStub remoteServiceStub = RemoteServiceGrpc.newStub(gRPCCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build()));
    StreamObserver<RemoteMessage> streamObserver = remoteServiceStub.call(new StreamObserver<Empty>() {

        @Override
        public void onNext(Empty empty) {
        }

        @Override
        public void onError(Throwable throwable) {
        }

        @Override
        public void onCompleted() {
        }
    });
    RemoteMessage.Builder remoteMessage = RemoteMessage.newBuilder();
    remoteMessage.setNextWorkerName(testWorkerId);
    RemoteData.Builder remoteData = RemoteData.newBuilder();
    remoteData.addDataStrings("test1");
    remoteData.addDataStrings("test2");
    remoteData.addDataLongs(10);
    remoteData.addDataLongs(20);
    remoteMessage.setRemoteData(remoteData);
    streamObserver.onNext(remoteMessage.build());
    streamObserver.onCompleted();
}
Also used : RemoteMessage(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteMessage) CounterMetrics(org.apache.skywalking.oap.server.telemetry.api.CounterMetrics) WorkerInstancesService(org.apache.skywalking.oap.server.core.worker.WorkerInstancesService) MetricsCreator(org.apache.skywalking.oap.server.telemetry.api.MetricsCreator) RemoteData(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData) ModuleManagerTesting(org.apache.skywalking.oap.server.testing.module.ModuleManagerTesting) ModuleDefineTesting(org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting) Empty(org.apache.skywalking.oap.server.core.remote.grpc.proto.Empty) RemoteServiceGrpc(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteServiceGrpc) HistogramMetrics(org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics) Test(org.junit.Test)

Example 2 with RemoteData

use of org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData in project incubator-skywalking by apache.

the class RemoteServiceHandler method call.

/**
 * gRPC handler of {@link RemoteServiceGrpc}. Continue the distributed aggregation at the current OAP node.
 */
@Override
public StreamObserver<RemoteMessage> call(StreamObserver<Empty> responseObserver) {
    if (Objects.isNull(workerInstanceGetter)) {
        synchronized (RemoteServiceHandler.class) {
            if (Objects.isNull(workerInstanceGetter)) {
                workerInstanceGetter = moduleDefineHolder.find(CoreModule.NAME).provider().getService(IWorkerInstanceGetter.class);
            }
        }
    }
    return new StreamObserver<RemoteMessage>() {

        @Override
        public void onNext(RemoteMessage message) {
            remoteInCounter.inc();
            HistogramMetrics.Timer timer = remoteInHistogram.createTimer();
            try {
                String nextWorkerName = message.getNextWorkerName();
                RemoteData remoteData = message.getRemoteData();
                try {
                    RemoteHandleWorker handleWorker = workerInstanceGetter.get(nextWorkerName);
                    if (handleWorker != null) {
                        AbstractWorker nextWorker = handleWorker.getWorker();
                        StreamData streamData = handleWorker.getStreamDataClass().newInstance();
                        streamData.deserialize(remoteData);
                        nextWorker.in(streamData);
                    } else {
                        remoteInTargetNotFoundCounter.inc();
                        LOGGER.warn("Work name [{}] not found. Check OAL script, make sure they are same in the whole cluster.", nextWorkerName);
                    }
                } catch (Throwable t) {
                    remoteInErrorCounter.inc();
                    LOGGER.error(t.getMessage(), t);
                }
            } finally {
                timer.finish();
            }
        }

        @Override
        public void onError(Throwable throwable) {
            LOGGER.error(throwable.getMessage(), throwable);
        }

        @Override
        public void onCompleted() {
            responseObserver.onNext(Empty.newBuilder().build());
            responseObserver.onCompleted();
        }
    };
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) RemoteMessage(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteMessage) IWorkerInstanceGetter(org.apache.skywalking.oap.server.core.worker.IWorkerInstanceGetter) AbstractWorker(org.apache.skywalking.oap.server.core.worker.AbstractWorker) StreamData(org.apache.skywalking.oap.server.core.remote.data.StreamData) HistogramMetrics(org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics) RemoteData(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData) RemoteHandleWorker(org.apache.skywalking.oap.server.core.worker.RemoteHandleWorker)

Example 3 with RemoteData

use of org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData in project skywalking by apache.

the class RemoteServiceHandler method call.

/**
 * gRPC handler of {@link RemoteServiceGrpc}. Continue the distributed aggregation at the current OAP node.
 */
@Override
public StreamObserver<RemoteMessage> call(StreamObserver<Empty> responseObserver) {
    if (Objects.isNull(workerInstanceGetter)) {
        synchronized (RemoteServiceHandler.class) {
            if (Objects.isNull(workerInstanceGetter)) {
                workerInstanceGetter = moduleDefineHolder.find(CoreModule.NAME).provider().getService(IWorkerInstanceGetter.class);
            }
        }
    }
    return new StreamObserver<RemoteMessage>() {

        @Override
        public void onNext(RemoteMessage message) {
            remoteInCounter.inc();
            HistogramMetrics.Timer timer = remoteInHistogram.createTimer();
            try {
                String nextWorkerName = message.getNextWorkerName();
                RemoteData remoteData = message.getRemoteData();
                try {
                    RemoteHandleWorker handleWorker = workerInstanceGetter.get(nextWorkerName);
                    if (handleWorker != null) {
                        AbstractWorker nextWorker = handleWorker.getWorker();
                        StreamData streamData = handleWorker.getStreamDataClass().newInstance();
                        streamData.deserialize(remoteData);
                        nextWorker.in(streamData);
                    } else {
                        remoteInTargetNotFoundCounter.inc();
                        LOGGER.warn("Work name [{}] not found. Check OAL script, make sure they are same in the whole cluster.", nextWorkerName);
                    }
                } catch (Throwable t) {
                    remoteInErrorCounter.inc();
                    LOGGER.error(t.getMessage(), t);
                }
            } finally {
                timer.finish();
            }
        }

        @Override
        public void onError(Throwable throwable) {
            LOGGER.error(throwable.getMessage(), throwable);
        }

        @Override
        public void onCompleted() {
            responseObserver.onNext(Empty.newBuilder().build());
            responseObserver.onCompleted();
        }
    };
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) RemoteMessage(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteMessage) IWorkerInstanceGetter(org.apache.skywalking.oap.server.core.worker.IWorkerInstanceGetter) AbstractWorker(org.apache.skywalking.oap.server.core.worker.AbstractWorker) StreamData(org.apache.skywalking.oap.server.core.remote.data.StreamData) HistogramMetrics(org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics) RemoteData(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData) RemoteHandleWorker(org.apache.skywalking.oap.server.core.worker.RemoteHandleWorker)

Example 4 with RemoteData

use of org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData in project skywalking by apache.

the class RemoteServiceHandlerTestCase method callTest.

@Test
public void callTest() throws DuplicateProviderException, ProviderNotFoundException, IOException {
    final String testWorkerId = "mock-worker";
    ModuleManagerTesting moduleManager = new ModuleManagerTesting();
    ModuleDefineTesting moduleDefine = new ModuleDefineTesting();
    moduleManager.put(CoreModule.NAME, moduleDefine);
    WorkerInstancesService workerInstancesService = new WorkerInstancesService();
    moduleDefine.provider().registerServiceImplementation(IWorkerInstanceGetter.class, workerInstancesService);
    moduleDefine.provider().registerServiceImplementation(IWorkerInstanceSetter.class, workerInstancesService);
    TestWorker worker = new TestWorker(moduleManager);
    workerInstancesService.put(testWorkerId, worker, TestRemoteData.class);
    String serverName = InProcessServerBuilder.generateName();
    MetricsCreator metricsCreator = mock(MetricsCreator.class);
    when(metricsCreator.createCounter(any(), any(), any(), any())).thenReturn(new CounterMetrics() {

        @Override
        public void inc() {
        }

        @Override
        public void inc(double value) {
        }
    });
    when(metricsCreator.createHistogramMetric(any(), any(), any(), any())).thenReturn(new HistogramMetrics() {

        @Override
        public Timer createTimer() {
            return super.createTimer();
        }

        @Override
        public void observe(double value) {
        }
    });
    ModuleDefineTesting telemetryModuleDefine = new ModuleDefineTesting();
    moduleManager.put(TelemetryModule.NAME, telemetryModuleDefine);
    telemetryModuleDefine.provider().registerServiceImplementation(MetricsCreator.class, metricsCreator);
    gRPCCleanup.register(InProcessServerBuilder.forName(serverName).directExecutor().addService(new RemoteServiceHandler(moduleManager)).build().start());
    RemoteServiceGrpc.RemoteServiceStub remoteServiceStub = RemoteServiceGrpc.newStub(gRPCCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build()));
    StreamObserver<RemoteMessage> streamObserver = remoteServiceStub.call(new StreamObserver<Empty>() {

        @Override
        public void onNext(Empty empty) {
        }

        @Override
        public void onError(Throwable throwable) {
        }

        @Override
        public void onCompleted() {
        }
    });
    RemoteMessage.Builder remoteMessage = RemoteMessage.newBuilder();
    remoteMessage.setNextWorkerName(testWorkerId);
    RemoteData.Builder remoteData = RemoteData.newBuilder();
    remoteData.addDataStrings("test1");
    remoteData.addDataStrings("test2");
    remoteData.addDataLongs(10);
    remoteData.addDataLongs(20);
    remoteMessage.setRemoteData(remoteData);
    streamObserver.onNext(remoteMessage.build());
    streamObserver.onCompleted();
}
Also used : RemoteMessage(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteMessage) CounterMetrics(org.apache.skywalking.oap.server.telemetry.api.CounterMetrics) WorkerInstancesService(org.apache.skywalking.oap.server.core.worker.WorkerInstancesService) MetricsCreator(org.apache.skywalking.oap.server.telemetry.api.MetricsCreator) RemoteData(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData) ModuleManagerTesting(org.apache.skywalking.oap.server.testing.module.ModuleManagerTesting) ModuleDefineTesting(org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting) Empty(org.apache.skywalking.oap.server.core.remote.grpc.proto.Empty) RemoteServiceGrpc(org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteServiceGrpc) HistogramMetrics(org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics) Test(org.junit.Test)

Aggregations

RemoteData (org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData)4 RemoteMessage (org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteMessage)4 HistogramMetrics (org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics)4 StreamObserver (io.grpc.stub.StreamObserver)2 StreamData (org.apache.skywalking.oap.server.core.remote.data.StreamData)2 Empty (org.apache.skywalking.oap.server.core.remote.grpc.proto.Empty)2 RemoteServiceGrpc (org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteServiceGrpc)2 AbstractWorker (org.apache.skywalking.oap.server.core.worker.AbstractWorker)2 IWorkerInstanceGetter (org.apache.skywalking.oap.server.core.worker.IWorkerInstanceGetter)2 RemoteHandleWorker (org.apache.skywalking.oap.server.core.worker.RemoteHandleWorker)2 WorkerInstancesService (org.apache.skywalking.oap.server.core.worker.WorkerInstancesService)2 CounterMetrics (org.apache.skywalking.oap.server.telemetry.api.CounterMetrics)2 MetricsCreator (org.apache.skywalking.oap.server.telemetry.api.MetricsCreator)2 ModuleDefineTesting (org.apache.skywalking.oap.server.testing.module.ModuleDefineTesting)2 ModuleManagerTesting (org.apache.skywalking.oap.server.testing.module.ModuleManagerTesting)2 Test (org.junit.Test)2