Skip to content

Commit 9aea2c6

Browse files
authored
chore:调整日志打印 (#72)
1 parent 9171592 commit 9aea2c6

File tree

4 files changed

+50
-18
lines changed

4 files changed

+50
-18
lines changed

conf/sync-registry.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
"source": {
77
"name": "nacos",
88
"type": "nacos",
9+
"user": "nacos",
10+
"password": "nacos",
911
"addresses": [
1012
"127.0.0.1:8848"
1113
]
@@ -51,12 +53,12 @@
5153
},
5254
"match": [
5355
{
54-
"namespace": "atom-ns1",
55-
"service": "nacos.test.3"
56+
"namespace": "Polaris",
57+
"service": "polaris.checker"
5658
},
5759
{
58-
"namespace": "atom-ns1",
59-
"service": "nacos.test.4"
60+
"namespace": "default",
61+
"service": "EchoServer"
6062
}
6163
]
6264
}

polaris-sync-config-plugins/config-nacos/src/main/java/cn/polarismesh/polaris/sync/config/plugins/nacos/NacosConfigCenter.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,6 @@ public void updateGroups(Collection<ConfigGroup> groups) {
237237
}
238238
namespaceIds.add(group.getNamespace());
239239
}
240-
LOG.info("[Nacos][Config] wait create nacos ns : {}", namespaceIds);
241240
if (namespaceIds.isEmpty()) {
242241
return;
243242
}
@@ -253,6 +252,11 @@ public void updateGroups(Collection<ConfigGroup> groups) {
253252
return;
254253
}
255254
}
255+
if (!authResponse.isGlobalAdmin()) {
256+
LOG.warn("[Nacos][Config] current user is not nacos global admin, ignore create nacos namespace, {}",
257+
endpoint.getAuthorization());
258+
return;
259+
}
256260
//2. 查询命名空间是否已经创建
257261
List<NacosNamespace> nacosNamespaces = new ArrayList<>();
258262
ResponseProto.DiscoverResponse discoverResponse = NacosRestUtils

polaris-sync-extension/src/main/java/cn/polarismesh/polaris/sync/extension/InitRequest.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
1-
package cn.polarismesh.polaris.sync.extension;
1+
/*
2+
* Tencent is pleased to support the open source community by making Polaris available.
3+
*
4+
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
5+
*
6+
* Licensed under the BSD 3-Clause License (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* https://opensource.org/licenses/BSD-3-Clause
11+
*
12+
* Unless required by applicable law or agreed to in writing, software distributed
13+
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
14+
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations under the License.
16+
*/
217

3-
import cn.polarismesh.polaris.sync.registry.pb.RegistryProto;
18+
package cn.polarismesh.polaris.sync.extension;
419

520
/**
621
* @author <a href="mailto:[email protected]">liaochuntao</a>

polaris-sync-registry-plugins/registry-nacos/src/main/java/cn/polarismesh/polaris/sync/registry/plugins/nacos/NacosRegistryCenter.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@
1919

2020
import cn.polarismesh.polaris.sync.common.rest.HostAndPort;
2121
import cn.polarismesh.polaris.sync.common.rest.RestOperator;
22+
import cn.polarismesh.polaris.sync.common.utils.CommonUtils;
23+
import cn.polarismesh.polaris.sync.common.utils.DefaultValues;
2224
import cn.polarismesh.polaris.sync.extension.Health;
2325
import cn.polarismesh.polaris.sync.extension.ResourceEndpoint;
2426
import cn.polarismesh.polaris.sync.extension.ResourceType;
2527
import cn.polarismesh.polaris.sync.extension.registry.RegistryCenter;
2628
import cn.polarismesh.polaris.sync.extension.registry.RegistryInitRequest;
2729
import cn.polarismesh.polaris.sync.extension.registry.Service;
2830
import cn.polarismesh.polaris.sync.extension.registry.WatchEvent;
29-
import cn.polarismesh.polaris.sync.common.utils.CommonUtils;
30-
import cn.polarismesh.polaris.sync.common.utils.DefaultValues;
3131
import cn.polarismesh.polaris.sync.extension.utils.ResponseUtils;
3232
import cn.polarismesh.polaris.sync.extension.utils.StatusCodes;
3333
import cn.polarismesh.polaris.sync.model.pb.ModelProto;
@@ -51,7 +51,6 @@
5151
import com.tencent.polaris.client.pb.ServiceProto;
5252
import com.tencent.polaris.client.pb.ServiceProto.Instance.Builder;
5353
import com.tencent.polaris.client.pb.ServiceProto.Namespace;
54-
5554
import java.lang.reflect.Field;
5655
import java.util.ArrayList;
5756
import java.util.Collection;
@@ -276,7 +275,8 @@ public DiscoverResponse listInstances(Service service, ModelProto.Group group) {
276275
return builder.build();
277276
}
278277

279-
private List<ServiceProto.Instance> convertNacosInstances(Service service, List<Instance> instances, ModelProto.Group group) {
278+
private List<ServiceProto.Instance> convertNacosInstances(Service service, List<Instance> instances,
279+
ModelProto.Group group) {
280280
Map<String, String> filters = (null == group ? null : group.getMetadataMap());
281281
List<ServiceProto.Instance> polarisInstances = new ArrayList<>();
282282
for (Instance instance : instances) {
@@ -394,6 +394,11 @@ public void updateServices(Collection<Service> services) {
394394
return;
395395
}
396396
}
397+
if (!authResponse.isGlobalAdmin()) {
398+
LOG.warn("[Nacos][Registry] current user is not nacos global admin, ignore create nacos namespace, {}",
399+
registryEndpoint.getAuthorization());
400+
return;
401+
}
397402
//2. 查询命名空间是否已经创建
398403
List<NacosNamespace> nacosNamespaces = new ArrayList<>();
399404
DiscoverResponse discoverResponse = NacosRestUtils
@@ -420,7 +425,8 @@ public void updateGroups(Service service, Collection<ModelProto.Group> groups) {
420425
}
421426

422427
@Override
423-
public void updateInstances(Service service, ModelProto.Group group, Collection<ServiceProto.Instance> srcInstances) {
428+
public void updateInstances(Service service, ModelProto.Group group,
429+
Collection<ServiceProto.Instance> srcInstances) {
424430
ResourceEndpoint registryEndpoint = registryInitRequest.getResourceEndpoint();
425431
List<Instance> allInstances = queryNacosInstances(service, registryEndpoint.getName());
426432
if (null == allInstances) {
@@ -458,7 +464,8 @@ public void updateInstances(Service service, ModelProto.Group group, Collection<
458464
hasExistsInstances = true;
459465
//比较是否存在不一致
460466
if (!instanceEquals(srcInstance, destInstance)) {
461-
targetsToUpdate.put(srcAddress, toNacosInstancePendingSync(srcInstance, destInstance.getInstanceId()));
467+
targetsToUpdate.put(srcAddress,
468+
toNacosInstancePendingSync(srcInstance, destInstance.getInstanceId()));
462469
}
463470
targetsExists.put(srcAddress, toNacosInstancePendingSync(srcInstance, destInstance.getInstanceId()));
464471
}
@@ -485,7 +492,8 @@ public void updateInstances(Service service, ModelProto.Group group, Collection<
485492
//1. 有1-N个实例需要删除
486493
//2. 存在新增+存量
487494
if (!targetsToDelete.isEmpty()) {
488-
LOG.info("[Nacos] targets pending to delete are {}, group {}", targetsToDelete.keySet(), group.getName());
495+
LOG.info("[Nacos] targets pending to delete are {}, group {}", targetsToDelete.keySet(),
496+
group.getName());
489497
deregisterInstance("delete", namingService, service.getService(), targetsToDelete.values().iterator()
490498
.next());
491499
targetDeleteCount += targetsToDelete.size();
@@ -505,7 +513,7 @@ public void updateInstances(Service service, ModelProto.Group group, Collection<
505513
}
506514
registerInstances("create", namingService, service.getService(), instances);
507515
targetAddCount += targetsToCreate.size();
508-
} else{
516+
} else {
509517
if (deleted) {
510518
//前面已经删除了,则把存量重新注册一遍
511519
List<Instance> instances = new ArrayList<>(targetsExists.values());
@@ -515,7 +523,8 @@ public void updateInstances(Service service, ModelProto.Group group, Collection<
515523
} else if (!targetsToUpdate.isEmpty()) {
516524
//前面已经删除了,则把存量重新注册一遍
517525
List<Instance> instances = new ArrayList<>(targetsToUpdate.values());
518-
LOG.info("[Nacos] targets pending to update are {}, group {}", targetsToUpdate.keySet(), group.getName());
526+
LOG.info("[Nacos] targets pending to update are {}, group {}", targetsToUpdate.keySet(),
527+
group.getName());
519528
registerInstances("update", namingService, service.getService(), instances);
520529
targetPatchCount += targetsToUpdate.size();
521530
}
@@ -533,8 +542,10 @@ private void registerInstances(String operation, NamingService namingService,
533542
} catch (NacosException e) {
534543
if (StringUtils.contains(e.getMessage(), "RequestHandler Not Found")) {
535544
Field field = ReflectionUtils.findField(NacosNamingService.class, "clientProxy");
536-
NamingClientProxyDelegate proxy = (NamingClientProxyDelegate) ReflectionUtils.getField(field, namingService);
537-
NamingClientProxy httpProxy = (NamingClientProxy) ReflectionUtils.getField(ReflectionUtils.findField(NamingClientProxyDelegate.class, "httpClientProxy"), proxy);
545+
NamingClientProxyDelegate proxy = (NamingClientProxyDelegate) ReflectionUtils.getField(field,
546+
namingService);
547+
NamingClientProxy httpProxy = (NamingClientProxy) ReflectionUtils.getField(
548+
ReflectionUtils.findField(NamingClientProxyDelegate.class, "httpClientProxy"), proxy);
538549
for (Instance instance : instances) {
539550
try {
540551
httpProxy.registerService(values[1], values[0], instance);

0 commit comments

Comments
 (0)