Search in sources :

Example 1 with IntConfigs

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

the class AutomaticInstanceManagement method adjustConfig.

@VisibleForTesting
void adjustConfig(final String newSpec, String leaderHostname) throws Exception {
    final InstanceConfig currentConfig = exhibitor.getConfigManager().getConfig();
    InstanceConfig newConfig = new InstanceConfig() {

        @Override
        public String getString(StringConfigs config) {
            if (config == StringConfigs.SERVERS_SPEC) {
                return newSpec;
            }
            return currentConfig.getString(config);
        }

        @Override
        public int getInt(IntConfigs config) {
            return currentConfig.getInt(config);
        }
    };
    boolean success;
    if (applyAllAtOnce()) {
        success = exhibitor.getConfigManager().updateConfig(newConfig);
    } else {
        success = exhibitor.getConfigManager().startRollingConfig(newConfig, leaderHostname);
    }
    if (success) {
        clusterState.clear();
    } else {
        exhibitor.getLog().add(ActivityLog.Type.INFO, "Could not initiate Automatic Instance Management config change. Another process is already making a config change.");
    }
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 2 with IntConfigs

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

the class ConfigResource method parseToConfig.

private InstanceConfig parseToConfig(String newConfigJson) throws IOException {
    ObjectMapper mapper = new ObjectMapper();
    final JsonNode tree = mapper.readTree(mapper.getJsonFactory().createJsonParser(newConfigJson));
    String backupExtraValue = "";
    if (tree.get("backupExtra") != null) {
        List<EncodedConfigParser.FieldValue> values = Lists.newArrayList();
        JsonNode backupExtra = tree.get("backupExtra");
        Iterator<String> fieldNames = backupExtra.getFieldNames();
        while (fieldNames.hasNext()) {
            String name = fieldNames.next();
            String value = backupExtra.get(name).getTextValue();
            values.add(new EncodedConfigParser.FieldValue(name, value));
        }
        backupExtraValue = new EncodedConfigParser(values).toEncoded();
    }
    List<EncodedConfigParser.FieldValue> zooCfgValues = Lists.newArrayList();
    JsonNode zooCfgExtra = tree.get("zooCfgExtra");
    Iterator<String> fieldNames = zooCfgExtra.getFieldNames();
    while (fieldNames.hasNext()) {
        String name = fieldNames.next();
        String value = zooCfgExtra.get(name).getTextValue();
        zooCfgValues.add(new EncodedConfigParser.FieldValue(name, value));
    }
    final String zooCfgExtraValue = new EncodedConfigParser(zooCfgValues).toEncoded();
    final String finalBackupExtraValue = backupExtraValue;
    return new InstanceConfig() {

        @Override
        public String getString(StringConfigs config) {
            switch(config) {
                case BACKUP_EXTRA:
                    {
                        return finalBackupExtraValue;
                    }
                case ZOO_CFG_EXTRA:
                    {
                        return zooCfgExtraValue;
                    }
                default:
                    {
                        // NOP
                        break;
                    }
            }
            JsonNode node = tree.get(fixName(config));
            if (node == null) {
                return "";
            }
            return node.asText();
        }

        @Override
        public int getInt(IntConfigs config) {
            JsonNode node = tree.get(fixName(config));
            if (node == null) {
                return 0;
            }
            return node.asInt();
        }
    };
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) EncodedConfigParser(com.netflix.exhibitor.core.config.EncodedConfigParser) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) JsonNode(org.codehaus.jackson.JsonNode) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) ObjectMapper(org.codehaus.jackson.map.ObjectMapper)

Example 3 with IntConfigs

use of com.netflix.exhibitor.core.config.IntConfigs 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 4 with IntConfigs

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

the class TestMonitorRunningInstance method testServerListHasChanged.

@Test
public void testServerListHasChanged() throws Exception {
    InstanceConfig config = new InstanceConfig() {

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

        @Override
        public int getInt(IntConfigs config) {
            return 0;
        }
    };
    Exhibitor mockExhibitor = makeMockExhibitor(config, "foo");
    MonitorRunningInstance monitor = new MonitorRunningInstance(mockExhibitor);
    StateAndLeader stateAndLeader = monitor.getStateAndLeader();
    InstanceState localCurrentInstanceState = new InstanceState(new ServerList(config.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(config));
    InstanceConfig newConfig = new InstanceConfig() {

        @Override
        public String getString(StringConfigs config) {
            switch(config) {
                case SERVERS_SPEC:
                    {
                        // observer added
                        return "S:1:foo,S:2:bar,O:3:snafu";
                    }
            }
            return null;
        }

        @Override
        public int getInt(IntConfigs config) {
            return 0;
        }
    };
    InstanceState instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
    Assert.assertFalse(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
    newConfig = new InstanceConfig() {

        @Override
        public String getString(StringConfigs config) {
            switch(config) {
                case SERVERS_SPEC:
                    {
                        // standard added
                        return "S:1:foo,S:2:bar,S:3:snafu";
                    }
            }
            return null;
        }

        @Override
        public int getInt(IntConfigs config) {
            return 0;
        }
    };
    instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
    Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
    newConfig = new InstanceConfig() {

        @Override
        public String getString(StringConfigs config) {
            switch(config) {
                case SERVERS_SPEC:
                    {
                        // "us" changed to observer
                        return "O:1:foo,S:2:bar";
                    }
            }
            return null;
        }

        @Override
        public int getInt(IntConfigs config) {
            return 0;
        }
    };
    instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
    Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
    newConfig = new InstanceConfig() {

        @Override
        public String getString(StringConfigs config) {
            switch(config) {
                case SERVERS_SPEC:
                    {
                        // not-us changed to observer
                        return "S:1:foo,O:2:bar";
                    }
            }
            return null;
        }

        @Override
        public int getInt(IntConfigs config) {
            return 0;
        }
    };
    instanceState = new InstanceState(new ServerList(newConfig.getString(StringConfigs.SERVERS_SPEC)), stateAndLeader.getState(), new RestartSignificantConfig(newConfig));
    Assert.assertTrue(monitor.serverListHasChanged(instanceState, localCurrentInstanceState));
}
Also used : InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) Exhibitor(com.netflix.exhibitor.core.Exhibitor) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) Test(org.testng.annotations.Test)

Example 5 with IntConfigs

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

the class MockConfigProvider method setConfig.

void setConfig(final IntConfigs type, final int value) {
    final InstanceConfig config = collection.getRootConfig();
    final InstanceConfig newConfig = new InstanceConfig() {

        @Override
        public String getString(StringConfigs configType) {
            return config.getString(configType);
        }

        @Override
        public int getInt(IntConfigs configType) {
            if (configType == type) {
                return value;
            }
            return config.getInt(configType);
        }
    };
    collection = new ConfigCollection() {

        @Override
        public InstanceConfig getConfigForThisInstance(String hostname) {
            return getRootConfig();
        }

        @Override
        public InstanceConfig getRootConfig() {
            return newConfig;
        }

        @Override
        public InstanceConfig getRollingConfig() {
            return null;
        }

        @Override
        public boolean isRolling() {
            return false;
        }

        @Override
        public RollingConfigState getRollingConfigState() {
            return null;
        }
    };
}
Also used : LoadedInstanceConfig(com.netflix.exhibitor.core.config.LoadedInstanceConfig) InstanceConfig(com.netflix.exhibitor.core.config.InstanceConfig) PropertyBasedInstanceConfig(com.netflix.exhibitor.core.config.PropertyBasedInstanceConfig) IntConfigs(com.netflix.exhibitor.core.config.IntConfigs) ConfigCollection(com.netflix.exhibitor.core.config.ConfigCollection) StringConfigs(com.netflix.exhibitor.core.config.StringConfigs) RollingConfigState(com.netflix.exhibitor.core.config.RollingConfigState)

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