org.apache.kafka.common.utils.Exit Java Examples
The following examples show how to use
org.apache.kafka.common.utils.Exit.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShutdownableThread.java From kop with Apache License 2.0 | 6 votes |
@Override public void run() { log.info("{} Starting", logIdent); try { while (isRunning()) { doWork(); } } catch (FatalExitError e) { shutdownInitiated.countDown(); shutdownComplete.countDown(); log.info("{} Stopped", logIdent); Exit.exit(e.statusCode()); } catch (Throwable cause) { if (isRunning()) { log.error("{} Error due to", logIdent, cause); } } finally { shutdownComplete.countDown(); } }
Example #2
Source File: SegmentIndexCLI.java From kafka-backup with Apache License 2.0 | 5 votes |
public static void main(String[] args) throws Exception { /* cli --list --segment-index [file] cli --restore-index --segment [file] // ideas for later cli --show --segment-index [file] --offset [offset] cli --validate --segment-index [file] --segment [file] */ final OptionParser optionParser = new OptionParser(); // Commands optionParser.accepts(CMD_LIST, CMD_LIST_HELP); optionParser.accepts(CMD_RESTORE, CMD_RESTORE_HELP); // Arguments optionParser.accepts(ARG_SEGMENT_INDEX, ARG_SEGMENT_INDEX_HELP) .requiredIf(CMD_LIST) .withRequiredArg().ofType(String.class); optionParser.accepts(ARG_SEGMENT, ARG_SEGMENT_HELP) .requiredIf(CMD_RESTORE) .withRequiredArg().ofType(String.class); OptionSet options; try { options = optionParser.parse(args); if (Stream.of(COMMANDS).filter(options::has).count() != 1) { throw new Exception("Must contain exactly one of " + Arrays.toString(COMMANDS)); } } catch (Exception e) { System.err.println(e.getMessage()); optionParser.printHelpOn(System.err); Exit.exit(-1); return; } if (options.has(CMD_LIST)) { list((String) options.valueOf(ARG_SEGMENT_INDEX)); } else if (options.has(CMD_RESTORE)) { restore((String) options.valueOf(ARG_SEGMENT)); } }
Example #3
Source File: SegmentCLI.java From kafka-backup with Apache License 2.0 | 5 votes |
private static Object instanciateClass(String name) { try { Class formatterClass = Class.forName(name); return formatterClass.getDeclaredConstructor().newInstance(); } catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) { System.err.println("formatter must be a valid class"); Exit.exit(1); // impossible to reach throw new RuntimeException("…"); } }
Example #4
Source File: Mirus.java From mirus with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void main(String[] argv) { Mirus.Args args = new Mirus.Args(); JCommander jCommander = JCommander.newBuilder() .programName(OffsetStatus.class.getSimpleName()) .addObject(args) .build(); try { jCommander.parse(argv); } catch (Exception e) { jCommander.usage(); throw e; } if (args.help) { jCommander.usage(); System.exit(1); } try { Map<String, String> workerProps = !args.workerPropertiesFile.isEmpty() ? Utils.propsToStringMap(Utils.loadProps(args.workerPropertiesFile)) : Collections.emptyMap(); applyOverrides(args.overrides, workerProps); Mirus mirus = new Mirus(); Connect connect = mirus.startConnect(workerProps); // Shutdown will be triggered by Ctrl-C or via HTTP shutdown request connect.awaitStop(); } catch (Throwable t) { log.error("Stopping due to error", t); Exit.exit(2); } }
Example #5
Source File: PartitionIndexCLI.java From kafka-backup with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws Exception { /* cli --list --partition-index [file] cli --restore-index --partition 0 --topic-dir [dir] // ideas for later cli --validate --partition-index [file] --partition 0 --topic-dir [dir] */ final OptionParser optionParser = new OptionParser(); // Commands optionParser.accepts(CMD_LIST); optionParser.accepts(CMD_RESTORE); // Arguments optionParser.accepts(ARG_PARTITION_INDEX) .requiredIf(CMD_LIST) .withRequiredArg().ofType(String.class); optionParser.accepts(ARG_TOPIC_DIR) .requiredIf(CMD_RESTORE) .withRequiredArg().ofType(String.class); optionParser.accepts(ARG_PARTITION) .requiredIf(CMD_RESTORE) .withRequiredArg().ofType(Integer.class); OptionSet options; try { options = optionParser.parse(args); if (Stream.of(COMMANDS).filter(options::has).count() != 1) { throw new Exception("Must contain exactly one of " + Arrays.toString(COMMANDS)); } } catch (Exception e) { System.err.println(e.getMessage()); optionParser.printHelpOn(System.err); Exit.exit(-1); return; } if (options.has(CMD_LIST)) { list((String) options.valueOf(ARG_PARTITION_INDEX)); } else if (options.has(CMD_RESTORE)) { restore((String) options.valueOf(ARG_TOPIC_DIR), (Integer) options.valueOf(ARG_PARTITION)); } else { optionParser.printHelpOn(System.err); } }
Example #6
Source File: Mirus.java From mirus with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * This method is based on the the standard Kafka Connect start logic in {@link * org.apache.kafka.connect.cli.ConnectDistributed#startConnect(Map)}, but with `clientid` prefix * support, to prevent JMX metric names from clashing. Also supports command-line property * overrides (useful for run-time port configuration), and starts the Mirus {@link * HerderStatusMonitor}. */ public Connect startConnect(Map<String, String> workerProps) { log.info("Scanning for plugin classes. This might take a moment ..."); Plugins plugins = new Plugins(workerProps); plugins.compareAndSwapWithDelegatingLoader(); DistributedConfig distributedConfig = configWithClientIdSuffix(workerProps, "herder"); MirusConfig mirusConfig = new MirusConfig(workerProps); String kafkaClusterId = ConnectUtils.lookupKafkaClusterId(distributedConfig); log.debug("Kafka cluster ID: {}", kafkaClusterId); RestServer rest = new RestServer(configWithClientIdSuffix(workerProps, "rest")); rest.initializeServer(); URI advertisedUrl = rest.advertisedUrl(); String workerId = advertisedUrl.getHost() + ":" + advertisedUrl.getPort(); KafkaOffsetBackingStore offsetBackingStore = new KafkaOffsetBackingStore(); offsetBackingStore.configure(configWithClientIdSuffix(workerProps, "offset")); WorkerConfig workerConfigs = configWithClientIdSuffix(workerProps, "worker"); ConnectorClientConfigOverridePolicy connectorClientConfigOverridePolicy = plugins.newPlugin( distributedConfig.getString(WorkerConfig.CONNECTOR_CLIENT_POLICY_CLASS_CONFIG), workerConfigs, ConnectorClientConfigOverridePolicy.class); Worker worker = new Worker( workerId, time, plugins, workerConfigs, offsetBackingStore, connectorClientConfigOverridePolicy); WorkerConfigTransformer configTransformer = worker.configTransformer(); Converter internalValueConverter = worker.getInternalValueConverter(); StatusBackingStore statusBackingStore = new KafkaStatusBackingStore(time, internalValueConverter); statusBackingStore.configure(configWithClientIdSuffix(workerProps, "status")); ConfigBackingStore configBackingStore = new KafkaConfigBackingStore( internalValueConverter, configWithClientIdSuffix(workerProps, "config"), configTransformer); DistributedHerder herder = new DistributedHerder( distributedConfig, time, worker, kafkaClusterId, statusBackingStore, configBackingStore, advertisedUrl.toString(), connectorClientConfigOverridePolicy); // Initialize HerderStatusMonitor boolean autoStartTasks = mirusConfig.getTaskAutoRestart(); boolean autoStartConnectors = mirusConfig.getConnectorAutoRestart(); long pollingCycle = mirusConfig.getTaskStatePollingInterval(); HerderStatusMonitor herderStatusMonitor = new HerderStatusMonitor( herder, workerId, pollingCycle, autoStartTasks, autoStartConnectors); Thread herderStatusMonitorThread = new Thread(herderStatusMonitor); herderStatusMonitorThread.setName("herder-status-monitor"); final Connect connect = new Connect(herder, rest); log.info("Mirus worker initialization took {}ms", time.hiResClockMs() - initStart); try { connect.start(); } catch (Exception e) { log.error("Failed to start Mirus", e); connect.stop(); Exit.exit(3); } herderStatusMonitorThread.start(); return connect; }