Search in sources :

Example 6 with StringConfigs

use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.

the class TestMonitorRunningInstance method testTempDownInstance.

@Test
public void testTempDownInstance() throws Exception {
    final AtomicInteger checkMs = new AtomicInteger(10000);
    InstanceConfig config = new InstanceConfig() {

        @Override
        public String getString(StringConfigs config) {
            switch(config) {
                case SERVERS_SPEC:
                    {
                        return "1:foo,2:bar";
                    }
                case ZOOKEEPER_DATA_DIRECTORY:
                case ZOOKEEPER_INSTALL_DIRECTORY:
                    {
                        return "/";
                    }
            }
            return null;
        }

        @Override
        public int getInt(IntConfigs config) {
            switch(config) {
                case CHECK_MS:
                    {
                        return checkMs.get();
                    }
            }
            return 0;
        }
    };
    Exhibitor mockExhibitor = makeMockExhibitor(config, "foo");
    final Semaphore semaphore = new Semaphore(0);
    MonitorRunningInstance monitor = new MonitorRunningInstance(mockExhibitor) {

        @Override
        protected void restartZooKeeper(InstanceState currentInstanceState) throws Exception {
            semaphore.release();
        }
    };
    monitor.doWork();
    Assert.assertTrue(semaphore.tryAcquire(10, TimeUnit.SECONDS));
    monitor.doWork();
    // no instance state change, should not try restart
    Assert.assertFalse(semaphore.tryAcquire(3, TimeUnit.SECONDS));
    checkMs.set(1);
    // should do restart now as 10 times checkMs has elapsed
    monitor.doWork();
    Assert.assertTrue(semaphore.tryAcquire(10, TimeUnit.SECONDS));
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Exhibitor(com.netflix.exhibitor.core.Exhibitor) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) Semaphore(java.util.concurrent.Semaphore) Test(org.testng.annotations.Test)

Example 7 with StringConfigs

use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.

the class ConfigResource method getSystemState.

@Path("get-state")
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getSystemState(@Context Request request) throws Exception {
    InstanceConfig config = context.getExhibitor().getConfigManager().getConfig();
    String response = new FourLetterWord(FourLetterWord.Word.RUOK, config, context.getExhibitor().getConnectionTimeOutMs()).getResponse();
    ServerList serverList = new ServerList(config.getString(StringConfigs.SERVERS_SPEC));
    ServerSpec us = UsState.findUs(context.getExhibitor(), serverList.getSpecs());
    ObjectNode mainNode = JsonNodeFactory.instance.objectNode();
    ObjectNode configNode = JsonNodeFactory.instance.objectNode();
    ObjectNode controlPanelNode = JsonNodeFactory.instance.objectNode();
    mainNode.put("version", context.getExhibitor().getVersion());
    mainNode.put("running", "imok".equals(response));
    mainNode.put("backupActive", context.getExhibitor().getBackupManager().isActive());
    mainNode.put("standaloneMode", context.getExhibitor().getConfigManager().isStandaloneMode());
    mainNode.put("extraHeadingText", context.getExhibitor().getExtraHeadingText());
    mainNode.put("nodeMutationsAllowed", context.getExhibitor().nodeMutationsAllowed());
    configNode.put("rollInProgress", context.getExhibitor().getConfigManager().isRolling());
    configNode.put("rollStatus", context.getExhibitor().getConfigManager().getRollingConfigState().getRollingStatus());
    configNode.put("rollPercentDone", context.getExhibitor().getConfigManager().getRollingConfigState().getRollingPercentDone());
    configNode.put("hostname", context.getExhibitor().getThisJVMHostname());
    configNode.put("serverId", (us != null) ? us.getServerId() : -1);
    for (StringConfigs c : StringConfigs.values()) {
        configNode.put(fixName(c), config.getString(c));
    }
    for (IntConfigs c : IntConfigs.values()) {
        String fixedName = fixName(c);
        int value = config.getInt(c);
        configNode.put(fixedName, value);
    }
    EncodedConfigParser zooCfgParser = new EncodedConfigParser(config.getString(StringConfigs.ZOO_CFG_EXTRA));
    ObjectNode zooCfgNode = JsonNodeFactory.instance.objectNode();
    for (EncodedConfigParser.FieldValue fv : zooCfgParser.getFieldValues()) {
        zooCfgNode.put(fv.getField(), fv.getValue());
    }
    configNode.put("zooCfgExtra", zooCfgNode);
    if (context.getExhibitor().getBackupManager().isActive()) {
        ObjectNode backupExtraNode = JsonNodeFactory.instance.objectNode();
        EncodedConfigParser parser = context.getExhibitor().getBackupManager().getBackupConfigParser();
        List<BackupConfigSpec> configs = context.getExhibitor().getBackupManager().getConfigSpecs();
        for (BackupConfigSpec c : configs) {
            String value = parser.getValue(c.getKey());
            backupExtraNode.put(c.getKey(), (value != null) ? value : "");
        }
        configNode.put("backupExtra", backupExtraNode);
    }
    configNode.put("controlPanel", controlPanelNode);
    mainNode.put("config", configNode);
    String json = JsonUtil.writeValueAsString(mainNode);
    EntityTag tag = new EntityTag(Hashing.sha1().hashString(json, Charsets.UTF_8).toString());
    Response.ResponseBuilder builder = request.evaluatePreconditions(tag);
    if (builder == null) {
        builder = Response.ok(json).tag(tag);
    }
    return builder.build();
}
Also used : ServerSpec(com.netflix.exhibitor.core.state.ServerSpec) ObjectNode(org.codehaus.jackson.node.ObjectNode) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) Response(javax.ws.rs.core.Response) InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) EncodedConfigParser(com.netflix.exhibitor.core.config.EncodedConfigParser) FourLetterWord(com.netflix.exhibitor.core.state.FourLetterWord) BackupConfigSpec(com.netflix.exhibitor.core.backup.BackupConfigSpec) ServerList(com.netflix.exhibitor.core.state.ServerList) EntityTag(javax.ws.rs.core.EntityTag) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 8 with StringConfigs

use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.

the class ExhibitorCLI method printHelp.

public void printHelp() {
    ManifestVersion manifestVersion = new ManifestVersion();
    System.out.println("Exhibitor " + manifestVersion.getVersion());
    HelpFormatter formatter = new HelpFormatter() {

        @Override
        public void printUsage(PrintWriter pw, int width, String cmdLineSyntax) {
        }

        @Override
        public void printUsage(PrintWriter pw, int width, String app, Options options) {
        }
    };
    formatter.printHelp("ExhibitorMain", generalOptions);
    for (OptionSection section : sections) {
        formatter.printHelp(" ", "\n== " + section.sectionName + " ==", section.options, null);
    }
    System.out.println();
    System.out.println("== Default Property Names ==");
    for (StringConfigs config : StringConfigs.values()) {
        System.out.println("\t" + PropertyBasedInstanceConfig.toName(config, ""));
    }
    for (IntConfigs config : IntConfigs.values()) {
        System.out.println("\t" + PropertyBasedInstanceConfig.toName(config, ""));
    }
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Options(org.apache.commons.cli.Options) ManifestVersion(com.netflix.exhibitor.core.state.ManifestVersion) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) PrintWriter(java.io.PrintWriter)

Example 9 with StringConfigs

use of com.netflix.exhibitor.core.config.StringConfigs in project exhibitor by soabase.

the class ExhibitorCreator method addInitialConfigFile.

private void addInitialConfigFile(CommandLine commandLine, Properties properties) throws IOException {
    Properties defaultProperties = new Properties();
    String defaultConfigFile = commandLine.getOptionValue(INITIAL_CONFIG_FILE);
    if (defaultConfigFile == null) {
        return;
    }
    InputStream in = new BufferedInputStream(new FileInputStream(defaultConfigFile));
    try {
        defaultProperties.load(in);
    } finally {
        CloseableUtils.closeQuietly(in);
    }
    Set<String> propertyNames = Sets.newHashSet();
    for (StringConfigs config : StringConfigs.values()) {
        propertyNames.add(PropertyBasedInstanceConfig.toName(config, ""));
    }
    for (IntConfigs config : IntConfigs.values()) {
        propertyNames.add(PropertyBasedInstanceConfig.toName(config, ""));
    }
    for (String name : defaultProperties.stringPropertyNames()) {
        if (propertyNames.contains(name)) {
            String value = defaultProperties.getProperty(name);
            properties.setProperty(PropertyBasedInstanceConfig.ROOT_PROPERTY_PREFIX + name, value);
        } else {
            log.warn("Ignoring unknown config: " + name);
        }
    }
}
Also used : BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) DefaultProperties(com.netflix.exhibitor.core.config.DefaultProperties) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Aggregations

IntConfigs (com.netflix.exhibitor.core.config.IntConfigs)9 StringConfigs (com.netflix.exhibitor.core.config.StringConfigs)9 InstanceConfig (com.netflix.exhibitor.core.config.InstanceConfig)7 Exhibitor (com.netflix.exhibitor.core.Exhibitor)2 ConfigCollection (com.netflix.exhibitor.core.config.ConfigCollection)2 EncodedConfigParser (com.netflix.exhibitor.core.config.EncodedConfigParser)2 LoadedInstanceConfig (com.netflix.exhibitor.core.config.LoadedInstanceConfig)2 PropertyBasedInstanceConfig (com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig)2 RollingConfigState (com.netflix.exhibitor.core.config.RollingConfigState)2 Test (org.testng.annotations.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 BackupConfigSpec (com.netflix.exhibitor.core.backup.BackupConfigSpec)1 DefaultProperties (com.netflix.exhibitor.core.config.DefaultProperties)1 FourLetterWord (com.netflix.exhibitor.core.state.FourLetterWord)1 ManifestVersion (com.netflix.exhibitor.core.state.ManifestVersion)1 ServerList (com.netflix.exhibitor.core.state.ServerList)1 ServerSpec (com.netflix.exhibitor.core.state.ServerSpec)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1