Skip to content

Commit

Permalink
Merge pull request #1544 from hanbingleixue/develop
Browse files Browse the repository at this point in the history
Fix the issue of configuration modification failure
  • Loading branch information
Sherlockhan authored Jun 25, 2024
2 parents 559aa7b + d3576f8 commit 170d85e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,14 @@ public boolean publishConfig(String key, Map<String, String> labels, String cont

@Override
public boolean publishConfig(String key, String group, String content) {
return this.publishConfig(key, LabelGroupUtils.resolveGroupLabels(group), content, true);
final Optional<String> keyIdOptional = this.getKeyId(key, group);
if (keyIdOptional.isPresent()) {
return this.doUpdateConfig(keyIdOptional.get(), content, true);
}

// If not exists, then publish
final Map<String, String> labels = LabelGroupUtils.resolveGroupLabels(group);
return this.publishConfig(key, labels, content, true);
}

/**
Expand Down Expand Up @@ -255,7 +262,7 @@ public boolean removeConfig(String key, String group) {
return false;
}
final HttpResult httpResult = this.httpClient.doDelete(buildKeyIdUrl(keyIdOptional.get()));
return httpResult.getCode() == HttpStatus.SC_OK;
return httpResult.getCode() == HttpStatus.SC_NO_CONTENT;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,7 @@ public boolean removeGroupListener(String group, DynamicConfigListener listener)
* @return publish result
*/
public boolean publishConfig(String key, String group, String content) {
final Optional<String> keyIdOptional = this.kieClient.getKeyId(key, group);
if (!keyIdOptional.isPresent()) {
// If not exists, then publish
final Map<String, String> labels = LabelGroupUtils.resolveGroupLabels(group);
return kieClient.publishConfig(key, labels, content, true);
} else {
return kieClient.doUpdateConfig(keyIdOptional.get(), content, true);
}
return kieClient.publishConfig(key, group, content);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,12 @@ private Map<String, List<String>> fuzzyGetConfigListByGroupAndKey(String key, St
if (!child.contains(nodeName)) {
continue;
}
String childPath = parentNodePath + child;
String childPath;
if (parentNodePath.endsWith(String.valueOf(ZK_PATH_SEPARATOR))) {
childPath = parentNodePath + child;
} else {
childPath = parentNodePath + ZK_PATH_SEPARATOR + child;
}
List<String> subChild = this.zkClient.getChildren(childPath, false);
if (subChild == null || subChild.isEmpty()) {
continue;
Expand Down
28 changes: 28 additions & 0 deletions sermant-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<aspectjweaver.version>1.8.4</aspectjweaver.version>
<tomcat-embed.version>9.0.86</tomcat-embed.version>
<spring-framework.version>5.3.33</spring-framework.version>
<nacos-client-version>2.2.1</nacos-client-version>
<webapp.path>${project.basedir}/src/main/webapp/frontend</webapp.path>
</properties>

Expand Down Expand Up @@ -250,8 +251,35 @@
<dependency>
<groupId>io.sermant</groupId>
<artifactId>sermant-agentcore-implement</artifactId>
<exclusions>
<exclusion>
<groupId>io.envoyproxy.controlplane</groupId>
<artifactId>api</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
</exclusion>
<exclusion>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
</exclusion>
<exclusion>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
</exclusion>
</exclusions>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.alibaba.nacos</groupId>
<artifactId>nacos-client</artifactId>
<version>${nacos-client-version}</version>
</dependency>
</dependencies>

<profiles>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ private ConfigClient getConfigClient(String namespace) {
return configClient;
}
ConfigClient client = CONFIG_CLIENT_MAP.get(namespace);
if (client == null || !client.isConnect()) {
if (client == null) {
return createNacosClient(namespace);
}
return client;
Expand Down Expand Up @@ -326,7 +326,7 @@ public void reConnection() {
}
if (ConfigCenterType.NACOS.name().equals(dynamicConfig.getDynamicConfigType()) && !configClient.isConnect()) {
for (Map.Entry<String, ConfigClient> entry : CONFIG_CLIENT_MAP.entrySet()) {
getConfigClient(entry.getKey());
createNacosClient(entry.getKey());
}
}
}
Expand Down

0 comments on commit 170d85e

Please sign in to comment.