io.continual.services.messaging.impl.kafka.tools.KafkaClusterReporter Maven / Gradle / Ivy
The newest version!
package io.continual.services.messaging.impl.kafka.tools;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Map;
import org.apache.kafka.clients.admin.AdminClient;
import org.apache.kafka.clients.admin.KafkaAdminClient;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.continual.builder.Builder;
import io.continual.builder.Builder.BuildFailure;
import io.continual.notify.ContinualNotifier;
import io.continual.services.messaging.impl.kafka.tools.KafkaClusterStatus.Group;
import io.continual.services.messaging.impl.kafka.tools.KafkaClusterStatus.KafkaClusterStatusException;
import io.continual.services.messaging.impl.kafka.tools.KafkaClusterStatus.Topic;
import io.continual.util.console.CmdLineParser;
import io.continual.util.console.CmdLinePrefs;
import io.continual.util.console.ConfiguredConsole;
import io.continual.util.console.ConsoleProgram;
import io.continual.util.data.StringUtils;
import io.continual.util.data.exprEval.EnvDataSource;
import io.continual.util.data.exprEval.ExprDataSourceStack;
import io.continual.util.data.exprEval.ExpressionEvaluator;
import io.continual.util.data.exprEval.SpecialFnsDataSource;
import io.continual.util.data.json.CommentedJsonTokener;
import io.continual.util.data.json.JsonSerialized;
import io.continual.util.data.json.JsonVisitor;
import io.continual.util.data.json.JsonVisitor.ItemRenderer;
import io.continual.util.naming.Name;
import io.continual.util.naming.Path;
import io.continual.util.nv.NvReadable;
import io.continual.util.nv.NvReadable.InvalidSettingValueException;
import io.continual.util.nv.NvReadable.MissingReqdSettingException;
public class KafkaClusterReporter extends ConsoleProgram
{
public interface KafkaClusterReport extends JsonSerialized
{
Map getTopics ();
Map getGroups ();
@Override
default JSONObject toJson ()
{
return new JSONObject ()
.put ( "topics", JsonVisitor.mapOfJsonToObject ( getTopics () ) )
.put ( "groups", JsonVisitor.mapOfJsonToObject ( getGroups () ) )
;
}
}
public interface ReportSender extends Closeable
{
void send ( KafkaClusterReport report );
}
@Override
protected KafkaClusterReporter setupOptions ( CmdLineParser p )
{
super.setupOptions ( p );
p.registerOptionWithValue ( ConfiguredConsole.kConfigFile, ConfiguredConsole.kConfigFileChar, null, null );
return this;
}
@Override
protected Looper init ( NvReadable p, CmdLinePrefs clp ) throws MissingReqdSettingException, InvalidSettingValueException, StartupFailureException
{
final String configFile = p.get ( ConfiguredConsole.kConfigFile );
if ( StringUtils.isEmpty ( configFile ) ) throw new MissingReqdSettingException ( ConfiguredConsole.kConfigFile );
try
{
final JSONObject config = loadConfig ( configFile );
// setup kafka admin client
final JSONObject kafkaConfig = config.getJSONObject ( "kafka" );
final Map configMap = JsonVisitor.objectToMap ( kafkaConfig, new ItemRenderer
© 2015 - 2024 Weber Informatics LLC | Privacy Policy