/*
* Copyright (c) 2014 Spotify AB.
*
* 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 com.spotify.helios.master;
import com.spotify.helios.servicescommon.ServiceParser;
import java.net.InetSocketAddress;
import net.sourceforge.argparse4j.inf.Argument;
import net.sourceforge.argparse4j.inf.ArgumentParser;
import net.sourceforge.argparse4j.inf.ArgumentParserException;
import net.sourceforge.argparse4j.inf.Namespace;
/**
* Parses command-line arguments to produce the {@link MasterConfig}.
*/
public class MasterParser extends ServiceParser {
private final MasterConfig masterConfig;
private Argument httpArg;
private Argument adminArg;
public MasterParser(final String... args) throws ArgumentParserException {
super("helios-master", "Spotify Helios Master", args);
final Namespace options = getNamespace();
final InetSocketAddress httpAddress = parseSocketAddress(options.getString(httpArg.getDest()));
final MasterConfig config = new MasterConfig()
.setZooKeeperConnectString(getZooKeeperConnectString())
.setZooKeeperSessionTimeoutMillis(getZooKeeperSessionTimeoutMillis())
.setZooKeeperConnectionTimeoutMillis(getZooKeeperConnectionTimeoutMillis())
.setZooKeeperNamespace(getZooKeeperNamespace())
.setZooKeeperClusterId(getZooKeeperClusterId())
.setDomain(getDomain())
.setName(getName())
.setStatsdHostPort(getStatsdHostPort())
.setRiemannHostPort(getRiemannHostPort())
.setInhibitMetrics(getInhibitMetrics())
.setSentryDsn(getSentryDsn())
.setServiceRegistryAddress(getServiceRegistryAddress())
.setServiceRegistrarPlugin(getServiceRegistrarPlugin())
.setAdminPort(options.getInt(adminArg.getDest()))
.setHttpEndpoint(httpAddress);
this.masterConfig = config;
}
@Override
protected void addArgs(final ArgumentParser parser) {
httpArg = parser.addArgument("--http")
.setDefault("http://0.0.0.0:5801")
.help("http endpoint");
adminArg = parser.addArgument("--admin")
.type(Integer.class)
.setDefault(5802)
.help("admin http port");
}
public MasterConfig getMasterConfig() {
return masterConfig;
}
}