From commits-return-16708-archive-asf-public=cust-asf.ponee.io@pulsar.apache.org Mon Oct 29 20:47:09 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 4013D180677 for ; Mon, 29 Oct 2018 20:47:09 +0100 (CET) Received: (qmail 15235 invoked by uid 500); 29 Oct 2018 19:47:08 -0000 Mailing-List: contact commits-help@pulsar.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@pulsar.apache.org Delivered-To: mailing list commits@pulsar.apache.org Received: (qmail 15223 invoked by uid 99); 29 Oct 2018 19:47:08 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 29 Oct 2018 19:47:08 +0000 From: GitBox To: commits@pulsar.apache.org Subject: [GitHub] sijie commented on a change in pull request #2883: Add healthcheck for broker Message-ID: <154084242775.19695.10768790024509802533.gitbox@gitbox.apache.org> Date: Mon, 29 Oct 2018 19:47:07 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit sijie commented on a change in pull request #2883: Add healthcheck for broker URL: https://github.com/apache/pulsar/pull/2883#discussion_r229072513 ########## File path: pulsar-broker/src/main/java/org/apache/pulsar/PulsarHealthcheck.java ########## @@ -0,0 +1,204 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.pulsar; + +import com.beust.jcommander.JCommander; +import com.beust.jcommander.Parameter; + +import com.fasterxml.jackson.databind.ObjectMapper; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.file.Paths; + +import java.util.Map; +import java.util.HashMap; + +import java.util.Properties; +import java.util.UUID; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import org.apache.commons.lang3.StringUtils; + +import org.apache.pulsar.client.admin.PulsarAdmin; +import org.apache.pulsar.client.admin.PulsarAdminBuilder; +import org.apache.pulsar.client.api.ClientBuilder; +import org.apache.pulsar.client.api.Consumer; +import org.apache.pulsar.client.api.Message; +import org.apache.pulsar.client.api.Producer; +import org.apache.pulsar.client.api.PulsarClient; +import org.apache.pulsar.client.api.Schema; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +public class PulsarHealthcheck { + private static final Logger log = LoggerFactory.getLogger(PulsarHealthcheck.class); + + private static class HealthcheckArguments { + @Parameter(names = {"-c", "--clientConf"}, description = "Configuration file for healthcheck") + private String healthcheckConf = Paths.get("").toAbsolutePath().normalize().toString() + "/conf/client.conf"; + + @Parameter(names = {"-t", "--timeout"}, description = "Max number of seconds to wait for the healthcheck") + private int timeoutSeconds = 10; + + @Parameter(names = {"-h", "--help"}, description = "Show this help message") + private boolean help = false; + } + + private static class Healthcheck implements Callable { + private final Properties properties; + + Healthcheck(Properties properties) { + this.properties = properties; + } + + @Override + public Void call() throws Exception { + log.info("Running healthcheck"); + try (PulsarAdmin admin = propsToAdminBuilder(properties).build()) { + String topic = String.format("persistent://%s/healthcheck", + admin.brokers().getInternalConfigurationData().getHeartbeatNamespace()); Review comment: but we need to handle the case if people rollback broker without tearing down the health check, no? from writing code perspective, we have to keep these things in mind, because you can assume people who running this code will follow exactly the same scenario you are thinking of. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services