[CELEBORN-1617][CIP-11] Support workers tags in FS Config Service

### What changes were proposed in this pull request?

Adding support for reading worker tags in FSConfigService. (Will handle DBConfigService in separate PR). Tags will be part of System level config and  dynamic config file structure with tags is shown below:

```
-  level: SYSTEM
   config:
     celeborn.test.int.only: 100
   tags:
     tag1:
       - 'host1:1111'
       - 'host2:2222'
     tag2:
       - 'host3:3333'
       - 'host4:4444'
```

### Why are the changes needed?

https://cwiki.apache.org/confluence/display/CELEBORN/CIP-11+Supporting+Tags+in+Celeborn

### Does this PR introduce _any_ user-facing change?

- Changes are backward compatible.
- User will be able to pass worker tags from dynamicConfig.yaml file.

### How was this patch tested?
UTs

Closes #2766 from s0nskar/tags_config.

Authored-by: Sanskar Modi <sanskarmodi97@gmail.com>
Signed-off-by: mingji <fengmingxiao.fmx@alibaba-inc.com>
This commit is contained in:
Sanskar Modi 2024-10-09 19:48:50 +08:00 committed by mingji
parent b3bf68edc7
commit 2b2bd6d913
No known key found for this signature in database
GPG Key ID: 6392F71F37356FA0
6 changed files with 193 additions and 5 deletions

View File

@ -19,6 +19,7 @@ package org.apache.celeborn.server.common.service.config;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -41,6 +42,7 @@ public abstract class DynamicConfig {
private static final Logger LOG = LoggerFactory.getLogger(DynamicConfig.class);
protected Map<String, String> configs = new HashMap<>();
protected volatile Quota quota = null;
protected volatile Map<String, Set<String>> tags = null;
public abstract DynamicConfig getParentLevelConfig();
@ -131,6 +133,21 @@ public abstract class DynamicConfig {
return configs;
}
public Map<String, Set<String>> getTags() {
if (tags == null) {
synchronized (DynamicConfig.class) {
if (tags == null) {
tags = currentTags();
}
}
}
return tags;
}
protected Map<String, Set<String>> currentTags() {
return null;
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder("DynamicConfig{");

View File

@ -20,10 +20,7 @@ package org.apache.celeborn.server.common.service.config;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;
import org.apache.commons.lang3.tuple.Pair;
@ -38,6 +35,8 @@ public class FsConfigServiceImpl extends BaseConfigServiceImpl implements Config
private static final String CONF_LEVEL = "level";
private static final String CONF_CONFIG = "config";
private static final String TAGS_CONFIG = "tags";
public FsConfigServiceImpl(CelebornConf celebornConf) throws IOException {
super(celebornConf);
}
@ -51,7 +50,10 @@ public class FsConfigServiceImpl extends BaseConfigServiceImpl implements Config
for (Map<String, Object> configMap : configs) {
if (ConfigLevel.SYSTEM.name().equals(configMap.get(CONF_LEVEL))) {
if (configMap.containsKey(CONF_CONFIG)) {
systemConfigAtomicReference.set(new SystemConfig(celebornConf, getConfigs(configMap)));
systemConfigAtomicReference.get().setConfigs(getConfigs(configMap));
}
if (configMap.containsKey(TAGS_CONFIG)) {
systemConfigAtomicReference.get().setTags(getTags(configMap));
}
} else {
if (configMap.containsKey(CONF_TENANT_ID)) {
@ -88,6 +90,16 @@ public class FsConfigServiceImpl extends BaseConfigServiceImpl implements Config
.collect(Collectors.toMap(Map.Entry::getKey, config -> config.getValue().toString()));
}
private Map<String, Set<String>> getTags(Map<String, Object> configMap) {
Map<String, Object> tagsConfig = (Map<String, Object>) configMap.get(TAGS_CONFIG);
if (tagsConfig == null) return Collections.emptyMap();
return tagsConfig.entrySet().stream()
.filter(tags -> tags.getValue() != null)
.collect(
Collectors.toMap(
Map.Entry::getKey, tags -> new HashSet<>((ArrayList<String>) tags.getValue())));
}
private File getConfigFile(Map<String, String> env) throws IOException {
File configFile =
celebornConf.dynamicConfigStoreFsPath().isEmpty()

View File

@ -20,6 +20,7 @@ package org.apache.celeborn.server.common.service.config;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.apache.celeborn.common.CelebornConf;
import org.apache.celeborn.common.internal.config.ConfigEntry;
@ -63,4 +64,17 @@ public class SystemConfig extends DynamicConfig {
return formatValue;
}
}
public void setConfigs(Map<String, String> configs) {
this.configs = configs;
}
public void setTags(Map<String, Set<String>> tags) {
this.tags = tags;
}
@Override
protected Map<String, Set<String>> currentTags() {
return this.tags;
}
}

View File

@ -23,6 +23,9 @@ import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
@ -307,4 +310,68 @@ public class ConfigServiceSuiteJ {
Assert.assertEquals(gmtTime, clusterInfo.getGmtCreate());
Assert.assertEquals(gmtTime, clusterInfo.getGmtModify());
}
@Test
public void testTags() throws IOException {
CelebornConf celebornConf = new CelebornConf();
String file = getClass().getResource("/dynamicConfig_tags.yaml").getFile();
celebornConf.set(CelebornConf.DYNAMIC_CONFIG_STORE_FS_PATH(), file);
celebornConf.set(CelebornConf.DYNAMIC_CONFIG_REFRESH_INTERVAL(), 5L);
configService = new FsConfigServiceImpl(celebornConf);
verifyTags(configService);
// change -> refresh config
file = getClass().getResource("/dynamicConfig_tags2.yaml").getFile();
celebornConf.set(CelebornConf.DYNAMIC_CONFIG_STORE_FS_PATH(), file);
configService.refreshCache();
verifyModifiedTags(configService);
}
public void verifyTags(ConfigService configService) {
SystemConfig systemConfig = configService.getSystemConfigFromCache();
Map<String, Set<String>> tags = systemConfig.getTags();
Set<String> tag1 = tags.getOrDefault("tag1", new HashSet<>());
Assert.assertEquals(tag1.size(), 2);
Assert.assertTrue(tag1.contains("host1:1111"));
Assert.assertTrue(tag1.contains("host2:2222"));
Set<String> tag2 = tags.getOrDefault("tag2", new HashSet<>());
Assert.assertEquals(tag2.size(), 2);
Assert.assertTrue(tag2.contains("host3:3333"));
Assert.assertTrue(tag2.contains("host4:4444"));
Set<String> tag3 = tags.getOrDefault("tag3", new HashSet<>());
Assert.assertEquals(tag3.size(), 0);
verifyTenantAndUserTagsAsNull(configService);
}
public void verifyModifiedTags(ConfigService configService) {
System.out.println("Tags changed");
SystemConfig systemConfig = configService.getSystemConfigFromCache();
Map<String, Set<String>> tags = systemConfig.getTags();
Set<String> tag1 = tags.getOrDefault("tag1", new HashSet<>());
Assert.assertEquals(tag1.size(), 1);
Assert.assertTrue(tag1.contains("host1:1111"));
Set<String> tag2 = tags.getOrDefault("tag2", new HashSet<>());
Assert.assertEquals(tag2.size(), 0);
Set<String> tag3 = tags.getOrDefault("tag3", new HashSet<>());
Assert.assertEquals(tag3.size(), 1);
Assert.assertTrue(tag3.contains("host5:5555"));
}
public void verifyTenantAndUserTagsAsNull(ConfigService configService) {
TenantConfig tenantConfig = configService.getRawTenantConfigFromCache("tenant_id1");
Assert.assertNull(tenantConfig.getTags());
DynamicConfig userConfig = configService.getTenantUserConfigFromCache("tenant_id1", "Jerry");
Assert.assertNull(userConfig.getTags());
}
}

View File

@ -0,0 +1,45 @@
#
# 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.
#
- level: SYSTEM
config:
celeborn.test.int.only: 100
tags:
tag1:
- 'host1:1111'
- 'host2:2222'
tag2:
- 'host3:3333'
- 'host4:4444'
- tenantId: tenant_id1
level: TENANT
config:
celeborn.test.int.only: 50
# Tags should be null for tenant/user config
tags:
tag1:
- 'host1:1111'
- 'host2:2222'
users:
- name: Jerry
config:
celeborn.test.int.only: 10
# Tags should be null for tenant/user config
tags:
tag1:
- 'host1:1111'
- 'host2:2222'

View File

@ -0,0 +1,33 @@
#
# 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.
#
- level: SYSTEM
config:
celeborn.test.int.only: 100
tags:
tag1:
- 'host1:1111'
tag3:
- 'host5:5555'
- tenantId: tenant_id
level: TENANT
config:
celeborn.test.int.only: 50
users:
- name: tenant1
config:
celeborn.test.int.only: 10