Search in sources :

Example 11 with ConfigTable

use of org.apache.skywalking.oap.server.configuration.api.ConfigTable in project skywalking by apache.

the class ZookeeperConfigWatcherRegister method readConfig.

@Override
public Optional<ConfigTable> readConfig(Set<String> keys) {
    ConfigTable table = new ConfigTable();
    keys.forEach(s -> {
        ChildData data = this.childrenCache.getCurrentData(this.prefix + s);
        String itemValue = null;
        if (data != null && data.getData() != null) {
            itemValue = new String(data.getData(), StandardCharsets.UTF_8);
        }
        table.add(new ConfigTable.ConfigItem(s, itemValue));
    });
    return Optional.of(table);
}
Also used : ChildData(org.apache.curator.framework.recipes.cache.ChildData) GroupConfigTable(org.apache.skywalking.oap.server.configuration.api.GroupConfigTable) ConfigTable(org.apache.skywalking.oap.server.configuration.api.ConfigTable)

Example 12 with ConfigTable

use of org.apache.skywalking.oap.server.configuration.api.ConfigTable in project skywalking by apache.

the class GRPCConfigWatcherRegister method readConfig.

@Override
public Optional<ConfigTable> readConfig(Set<String> keys) {
    ConfigTable table = new ConfigTable();
    try {
        ConfigurationRequest.Builder builder = ConfigurationRequest.newBuilder().setClusterName(settings.getClusterName());
        if (uuid != null) {
            builder.setUuid(uuid);
        }
        ConfigurationResponse response = stub.call(builder.build());
        String responseUuid = response.getUuid();
        if (Objects.equals(uuid, responseUuid)) {
            // If UUID matched, the config table is expected as empty.
            return Optional.empty();
        }
        response.getConfigTableList().forEach(config -> {
            final String name = config.getName();
            if (keys.contains(name)) {
                table.add(new ConfigTable.ConfigItem(name, config.getValue()));
            }
        });
        this.uuid = responseUuid;
    } catch (Exception e) {
        log.error("Remote config center [{}] is not available.", settings, e);
    }
    return Optional.of(table);
}
Also used : GroupConfigurationResponse(org.apache.skywalking.oap.server.configuration.service.GroupConfigurationResponse) ConfigurationResponse(org.apache.skywalking.oap.server.configuration.service.ConfigurationResponse) ConfigurationRequest(org.apache.skywalking.oap.server.configuration.service.ConfigurationRequest) ConfigTable(org.apache.skywalking.oap.server.configuration.api.ConfigTable) GroupConfigTable(org.apache.skywalking.oap.server.configuration.api.GroupConfigTable)

Example 13 with ConfigTable

use of org.apache.skywalking.oap.server.configuration.api.ConfigTable in project skywalking by apache.

the class EtcdConfigWatcherRegister method readConfig.

@Override
public Optional<ConfigTable> readConfig(final Set<String> keys) {
    ConfigTable table = new ConfigTable();
    keys.forEach(e -> {
        try {
            GetResponse response = client.get(ByteSequence.from(e, Charset.defaultCharset())).get();
            if (0 == response.getCount()) {
                table.add(new ConfigTable.ConfigItem(e, null));
            } else {
                response.getKvs().forEach(kv -> table.add(new ConfigTable.ConfigItem(kv.getKey().toString(Charset.defaultCharset()), kv.getValue().toString(Charset.defaultCharset()))));
            }
        } catch (Exception exp) {
            throw new EtcdConfigException("Failed to read configuration", exp);
        }
    });
    return Optional.of(table);
}
Also used : GroupConfigTable(org.apache.skywalking.oap.server.configuration.api.GroupConfigTable) ConfigTable(org.apache.skywalking.oap.server.configuration.api.ConfigTable) GetResponse(io.etcd.jetcd.kv.GetResponse)

Example 14 with ConfigTable

use of org.apache.skywalking.oap.server.configuration.api.ConfigTable in project skywalking by apache.

the class ConfigmapConfigWatcherRegisterTest method readConfigWhenConfigMapDataIsNull.

@Test
public void readConfigWhenConfigMapDataIsNull() throws Exception {
    Map<String, String> configMapData = new HashMap<>();
    PowerMockito.doReturn(configMapData).when(informer).configMapData();
    Optional<ConfigTable> optionalConfigTable = register.readConfig(new HashSet<String>() {

        {
            add("key1");
        }
    });
    Assert.assertTrue(optionalConfigTable.isPresent());
    ConfigTable configTable = optionalConfigTable.get();
    Assert.assertEquals(configTable.getItems().size(), 1);
    Assert.assertEquals(configTable.getItems().get(0).getName(), "key1");
    Assert.assertNull(configTable.getItems().get(0).getValue());
}
Also used : HashMap(java.util.HashMap) GroupConfigTable(org.apache.skywalking.oap.server.configuration.api.GroupConfigTable) ConfigTable(org.apache.skywalking.oap.server.configuration.api.ConfigTable) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 15 with ConfigTable

use of org.apache.skywalking.oap.server.configuration.api.ConfigTable in project skywalking by apache.

the class ConfigmapConfigWatcherRegisterTest method readConfigWhenInformerWork.

@Test
public void readConfigWhenInformerWork() throws Exception {
    Map<String, String> configMapData = this.readMockConfigMapData();
    PowerMockito.doReturn(configMapData).when(informer).configMapData();
    Optional<ConfigTable> optionalConfigTable = register.readConfig(new HashSet<String>() {

        {
            add("agent-analyzer.default.slowDBAccessThreshold");
            add("alarm.default.alarm-settings");
            add("core.default.apdexThreshold");
            add("agent-analyzer.default.uninstrumentedGateways");
        }
    });
    Assert.assertTrue(optionalConfigTable.isPresent());
    ConfigTable configTable = optionalConfigTable.get();
    List<String> list = configTable.getItems().stream().map(ConfigTable.ConfigItem::getValue).filter(Objects::nonNull).collect(Collectors.toList());
    Assert.assertEquals(list.size(), 4);
}
Also used : GroupConfigTable(org.apache.skywalking.oap.server.configuration.api.GroupConfigTable) ConfigTable(org.apache.skywalking.oap.server.configuration.api.ConfigTable) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ConfigTable (org.apache.skywalking.oap.server.configuration.api.ConfigTable)26 GroupConfigTable (org.apache.skywalking.oap.server.configuration.api.GroupConfigTable)22 Test (org.junit.Test)10 ChildData (org.apache.curator.framework.recipes.cache.ChildData)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 HashMap (java.util.HashMap)4 ConfigService (com.alibaba.nacos.api.config.ConfigService)2 GetResponse (io.etcd.jetcd.kv.GetResponse)2 Map (java.util.Map)2 Optional (java.util.Optional)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 PathChildrenCache (org.apache.curator.framework.recipes.cache.PathChildrenCache)2 ConfigurationRequest (org.apache.skywalking.oap.server.configuration.service.ConfigurationRequest)2 ConfigurationResponse (org.apache.skywalking.oap.server.configuration.service.ConfigurationResponse)2 GroupConfigurationResponse (org.apache.skywalking.oap.server.configuration.service.GroupConfigurationResponse)2 ZookeeperServerSettings (org.apache.skywalking.oap.server.configuration.zookeeper.ZookeeperServerSettings)2