/** * Constructor with a {@link NoopMetricsContext}. This constructor should only be used in unit-testing. */ @VisibleForTesting ConcurrentMessageWriter(StoreRequestWriter<?> messagesWriter) { this(messagesWriter, new NoopMetricsContext()); }
/** * Constructor with a {@link NoopMetricsContext}. This constructor should only be used in unit-testing. */ @VisibleForTesting ConcurrentMessageWriter(StoreRequestWriter<?> messagesWriter) { this(messagesWriter, new NoopMetricsContext()); }
@Override public MetricsContext childContext(Map<String, String> tags) { return new NoopMetricsContext(ImmutableMap.<String, String>builder().putAll(this.tags).putAll(tags).build()); }
@Override public void start() { super.start(); if (context instanceof AppenderContext) { this.metricsContext = ((AppenderContext) context).getMetricsContext(); } else if (Boolean.TRUE.equals(context.getObject(Constants.Logging.PIPELINE_VALIDATION))) { // It is performing pipeline validation this.metricsContext = new NoopMetricsContext(); } else { throw new IllegalStateException("Expected logger context instance of " + AppenderContext.class.getName() + " but get " + context.getClass().getName()); } }
@Override public void start() { super.start(); if (context instanceof AppenderContext) { this.metricsContext = ((AppenderContext) context).getMetricsContext(); } else if (Boolean.TRUE.equals(context.getObject(Constants.Logging.PIPELINE_VALIDATION))) { // It is performing pipeline validation this.metricsContext = new NoopMetricsContext(); } else { throw new IllegalStateException("Expected logger context instance of " + AppenderContext.class.getName() + " but get " + context.getClass().getName()); } }
/** * Validates the given set of user service handlers. * * @param handlers set of service handlers to validate. * @param <T> type of the handler * @throws IllegalArgumentException if any of the service handler is not valid */ public <T> void validateHttpHandler(Iterable<T> handlers) { List<HttpHandler> httpHandlers = new ArrayList<>(); NoopMetricsContext metricsContext = new NoopMetricsContext(); for (T handler : handlers) { try { @SuppressWarnings("unchecked") TypeToken<T> type = (TypeToken<T>) TypeToken.of(handler.getClass()); httpHandlers.add(createHttpHandler(type, new VerificationDelegateContext<>(handler), metricsContext)); } catch (Exception e) { throw new IllegalArgumentException("Invalid http handler class " + handler.getClass().getName()); } } try { // Constructs a NettyHttpService, to verify that the handlers passed in by the user are valid. NettyHttpService.builder("service-configurer") .setHttpHandlers(httpHandlers) .build(); } catch (Exception e) { throw new IllegalArgumentException("Invalid http handler", e); } }
/** * Validates the given set of user service handlers. * * @param handlers set of service handlers to validate. * @param <T> type of the handler * @throws IllegalArgumentException if any of the service handler is not valid */ public <T> void validateHttpHandler(Iterable<T> handlers) { List<HttpHandler> httpHandlers = new ArrayList<>(); NoopMetricsContext metricsContext = new NoopMetricsContext(); for (T handler : handlers) { try { @SuppressWarnings("unchecked") TypeToken<T> type = (TypeToken<T>) TypeToken.of(handler.getClass()); httpHandlers.add(createHttpHandler(type, new VerificationDelegateContext<>(handler), metricsContext)); } catch (Exception e) { throw new IllegalArgumentException("Invalid http handler class " + handler.getClass().getName()); } } try { // Constructs a NettyHttpService, to verify that the handlers passed in by the user are valid. NettyHttpService.builder("service-configurer") .setHttpHandlers(httpHandlers) .build(); } catch (Exception e) { throw new IllegalArgumentException("Invalid http handler", e); } }
/** * Creates a {@link MetricsContext} for metrics emission of the program represented by this context. * * @param programRunId the {@link ProgramRunId} of the current execution * @param metricsService the underlying service for metrics publishing; or {@code null} to suppress metrics publishing * @param metricsTags a set of extra tags to be used for creating the {@link MetricsContext} * @return a {@link MetricsContext} for emitting metrics for the current program context. */ private MetricsContext createProgramMetrics(ProgramRunId programRunId, @Nullable MetricsCollectionService metricsService, Map<String, String> metricsTags) { Map<String, String> tags = Maps.newHashMap(metricsTags); tags.put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()); tags.put(Constants.Metrics.Tag.APP, programRunId.getApplication()); tags.put(ProgramTypeMetricTag.getTagName(programRunId.getType()), programRunId.getProgram()); tags.put(Constants.Metrics.Tag.RUN_ID, programRunId.getRun()); return metricsService == null ? new NoopMetricsContext(tags) : metricsService.getContext(tags); }
/** * Creates a {@link MetricsContext} for metrics emission of the program represented by this context. * * @param programRunId the {@link ProgramRunId} of the current execution * @param metricsService the underlying service for metrics publishing; or {@code null} to suppress metrics publishing * @param metricsTags a set of extra tags to be used for creating the {@link MetricsContext} * @return a {@link MetricsContext} for emitting metrics for the current program context. */ private MetricsContext createProgramMetrics(ProgramRunId programRunId, @Nullable MetricsCollectionService metricsService, Map<String, String> metricsTags) { Map<String, String> tags = Maps.newHashMap(metricsTags); tags.put(Constants.Metrics.Tag.NAMESPACE, programRunId.getNamespace()); tags.put(Constants.Metrics.Tag.APP, programRunId.getApplication()); tags.put(ProgramTypeMetricTag.getTagName(programRunId.getType()), programRunId.getProgram()); tags.put(Constants.Metrics.Tag.RUN_ID, programRunId.getRun()); return metricsService == null ? new NoopMetricsContext(tags) : metricsService.getContext(tags); }
return new MyHttpHandler(); }, new NoopMetricsContext()); return new NoAnnotationHandler(); }, new NoopMetricsContext());
return new MyHttpHandler(); }, new NoopMetricsContext());
return new FileHandler(outputDir); }, new NoopMetricsContext());
@Test public void testContentConsumer() throws Exception { HttpHandlerFactory factory = new HttpHandlerFactory("/content", TransactionControl.IMPLICIT); // Create the file upload handler and starts a netty server with it final File outputDir = TEMP_FOLDER.newFolder(); HttpHandler httpHandler = factory.createHttpHandler( TypeToken.of(FileHandler.class), new AbstractDelegatorContext<FileHandler>() { @Override protected FileHandler createHandler() { return new FileHandler(outputDir); } }, new NoopMetricsContext()); // Creates a Netty http server with 1K request buffer NettyHttpService service = NettyHttpService.builder("test-content-consumer") .setHttpHandlers(httpHandler) .setHttpChunkLimit(1024) .build(); service.start(); try { InetSocketAddress bindAddress = service.getBindAddress(); testUpload(outputDir, bindAddress, ""); testUpload(outputDir, bindAddress, "-no-tx"); } finally { service.stop(); } }