From 79ffc04ec7b9b63762013e16756455192482fea1 Mon Sep 17 00:00:00 2001 From: Khotyn Huang Date: Sat, 8 Jul 2023 17:14:02 +0800 Subject: [PATCH] Remove sofa common util stringutil usage (#332) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove unproper usage of StringUtil Using apache common-langs StringUtils instead of sofa-common-util's StringUtil under profile package, sofa-common-utils's StringUtil under profile package is removed from newer sofa-common-util version. * Reformat --------- Co-authored-by: 鲁直 --- .../server/data/providedata/CompressDatumService.java | 4 ++-- .../registry/server/meta/bootstrap/MetaServerBootstrap.java | 3 +-- .../server/meta/remoting/meta/MetaNodeExchange.java | 6 +++--- .../sofa/registry/server/meta/resource/HealthResource.java | 4 ++-- .../server/session/providedata/CompressPushService.java | 3 +-- .../registry/server/shared/util/PersistenceDataParser.java | 4 ++-- .../registry/store/api/elector/AbstractLeaderElector.java | 4 ++-- .../registry/jdbc/convertor/AppRevisionDomainConvertor.java | 4 ++-- 8 files changed, 15 insertions(+), 17 deletions(-) diff --git a/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/providedata/CompressDatumService.java b/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/providedata/CompressDatumService.java index ca7ee27ef..71234afdd 100644 --- a/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/providedata/CompressDatumService.java +++ b/server/server/data/src/main/java/com/alipay/sofa/registry/server/data/providedata/CompressDatumService.java @@ -16,7 +16,6 @@ */ package com.alipay.sofa.registry.server.data.providedata; -import com.alipay.sofa.common.profile.StringUtil; import com.alipay.sofa.registry.common.model.constants.ValueConstants; import com.alipay.sofa.registry.common.model.metaserver.CompressDatumSwitch; import com.alipay.sofa.registry.common.model.metaserver.CompressPushSwitch; @@ -30,6 +29,7 @@ import com.alipay.sofa.registry.server.shared.providedata.AbstractFetchSystemPropertyService; import com.alipay.sofa.registry.server.shared.providedata.SystemDataStorage; import com.alipay.sofa.registry.util.JsonUtils; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; public class CompressDatumService @@ -52,7 +52,7 @@ protected int getSystemPropertyIntervalMillis() { @Override protected boolean doProcess(CompressStorage expect, ProvideData data) { final String switchString = ProvideData.toString(data); - if (StringUtil.isBlank(switchString)) { + if (StringUtils.isBlank(switchString)) { LOGGER.info("Fetch compress datum switch content empty"); return true; } diff --git a/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/bootstrap/MetaServerBootstrap.java b/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/bootstrap/MetaServerBootstrap.java index e71bcf8ca..a08a66f5a 100644 --- a/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/bootstrap/MetaServerBootstrap.java +++ b/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/bootstrap/MetaServerBootstrap.java @@ -16,7 +16,6 @@ */ package com.alipay.sofa.registry.server.meta.bootstrap; -import com.alipay.sofa.common.profile.StringUtil; import com.alipay.sofa.registry.common.model.elector.LeaderInfo; import com.alipay.sofa.registry.common.model.store.URL; import com.alipay.sofa.registry.log.Logger; @@ -178,7 +177,7 @@ public void start() { "[MetaBootstrap] retry connect to meta leader: {}, client:{}", leader.getLeader(), localMetaExchanger.getClient()); - return StringUtil.isNotEmpty(leader.getLeader()) + return StringUtils.isNotEmpty(leader.getLeader()) && localMetaExchanger.getClient() != null; }); diff --git a/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/remoting/meta/MetaNodeExchange.java b/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/remoting/meta/MetaNodeExchange.java index f206d0ff9..828290e71 100644 --- a/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/remoting/meta/MetaNodeExchange.java +++ b/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/remoting/meta/MetaNodeExchange.java @@ -16,7 +16,6 @@ */ package com.alipay.sofa.registry.server.meta.remoting.meta; -import com.alipay.sofa.common.profile.StringUtil; import com.alipay.sofa.registry.common.model.store.URL; import com.alipay.sofa.registry.log.Logger; import com.alipay.sofa.registry.log.LoggerFactory; @@ -33,6 +32,7 @@ import java.util.Collections; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; /** @@ -77,12 +77,12 @@ public int getConnNum() { public Response sendRequest(Object requestBody) throws RequestException { final String newLeader = metaLeaderService.getLeader(); - if (StringUtil.isBlank(newLeader)) { + if (StringUtils.isBlank(newLeader)) { LOGGER.error("[sendRequest] meta leader is empty."); return () -> ResultStatus.FAILED; } - if (!StringUtil.equals(metaLeader, newLeader) || boltExchange.getClient(serverType) == null) { + if (!StringUtils.equals(metaLeader, newLeader) || boltExchange.getClient(serverType) == null) { setLeaderAndConnect(newLeader); } diff --git a/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/resource/HealthResource.java b/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/resource/HealthResource.java index 6211b8bcf..de82afc0a 100644 --- a/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/resource/HealthResource.java +++ b/server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/resource/HealthResource.java @@ -16,7 +16,6 @@ */ package com.alipay.sofa.registry.server.meta.resource; -import com.alipay.sofa.common.profile.StringUtil; import com.alipay.sofa.registry.common.model.CommonResponse; import com.alipay.sofa.registry.metrics.ReporterUtils; import com.alipay.sofa.registry.server.meta.MetaLeaderService; @@ -33,6 +32,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.ResponseBuilder; import javax.ws.rs.core.Response.Status; +import org.apache.commons.lang.StringUtils; import org.springframework.beans.factory.annotation.Autowired; /** @@ -93,7 +93,7 @@ private CommonResponse getHealthCheckResult() { ret = ret && start; sb.append(", remoteMetaRegisterServerStart:").append(start); - boolean leaderNotEmpty = StringUtil.isNotBlank(metaLeaderService.getLeader()); + boolean leaderNotEmpty = StringUtils.isNotBlank(metaLeaderService.getLeader()); ret = ret && leaderNotEmpty; sb.append(", role:").append(metaLeaderService.amILeader() ? "leader" : "follower"); diff --git a/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/providedata/CompressPushService.java b/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/providedata/CompressPushService.java index 16bd50901..a3db649a9 100644 --- a/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/providedata/CompressPushService.java +++ b/server/server/session/src/main/java/com/alipay/sofa/registry/server/session/providedata/CompressPushService.java @@ -16,7 +16,6 @@ */ package com.alipay.sofa.registry.server.session.providedata; -import com.alipay.sofa.common.profile.StringUtil; import com.alipay.sofa.registry.common.model.constants.ValueConstants; import com.alipay.sofa.registry.common.model.metaserver.CompressPushSwitch; import com.alipay.sofa.registry.common.model.metaserver.ProvideData; @@ -55,7 +54,7 @@ protected int getSystemPropertyIntervalMillis() { @Override protected boolean doProcess(CompressStorage expect, ProvideData data) { final String switchString = ProvideData.toString(data); - if (StringUtil.isBlank(switchString)) { + if (StringUtils.isBlank(switchString)) { LOGGER.info("Fetch session push compressed enabled content empty"); return true; } diff --git a/server/server/shared/src/main/java/com/alipay/sofa/registry/server/shared/util/PersistenceDataParser.java b/server/server/shared/src/main/java/com/alipay/sofa/registry/server/shared/util/PersistenceDataParser.java index dc1990561..0d8c50f46 100644 --- a/server/server/shared/src/main/java/com/alipay/sofa/registry/server/shared/util/PersistenceDataParser.java +++ b/server/server/shared/src/main/java/com/alipay/sofa/registry/server/shared/util/PersistenceDataParser.java @@ -16,10 +16,10 @@ */ package com.alipay.sofa.registry.server.shared.util; -import com.alipay.sofa.common.profile.StringUtil; import com.alipay.sofa.registry.common.model.console.PersistenceData; import com.alipay.sofa.registry.store.api.DBResponse; import com.alipay.sofa.registry.store.api.OperationStatus; +import org.apache.commons.lang.StringUtils; /** * @author xiaojian.xj @@ -29,7 +29,7 @@ public class PersistenceDataParser { public static boolean parse2BoolIgnoreCase( PersistenceData persistenceData, boolean defaultValue) { - if (persistenceData == null || StringUtil.isBlank(persistenceData.getData())) { + if (persistenceData == null || StringUtils.isBlank(persistenceData.getData())) { return defaultValue; } return Boolean.parseBoolean(persistenceData.getData()); diff --git a/server/store/api/src/main/java/com/alipay/sofa/registry/store/api/elector/AbstractLeaderElector.java b/server/store/api/src/main/java/com/alipay/sofa/registry/store/api/elector/AbstractLeaderElector.java index 7ec84651c..f246fb7e7 100644 --- a/server/store/api/src/main/java/com/alipay/sofa/registry/store/api/elector/AbstractLeaderElector.java +++ b/server/store/api/src/main/java/com/alipay/sofa/registry/store/api/elector/AbstractLeaderElector.java @@ -16,7 +16,6 @@ */ package com.alipay.sofa.registry.store.api.elector; -import com.alipay.sofa.common.profile.StringUtil; import com.alipay.sofa.registry.log.Logger; import com.alipay.sofa.registry.log.LoggerFactory; import com.alipay.sofa.registry.net.NetUtil; @@ -27,6 +26,7 @@ import java.util.List; import java.util.concurrent.TimeUnit; import javax.annotation.PostConstruct; +import org.apache.commons.lang.StringUtils; /** * @author chen.zhu @@ -144,7 +144,7 @@ public boolean amILeader() { } protected boolean amILeader(String leader) { - return StringUtil.equals(myself(), leader) && leaderNotExpired(); + return StringUtils.equals(myself(), leader) && leaderNotExpired(); } private boolean leaderNotExpired() { diff --git a/server/store/jdbc/src/main/java/com/alipay/sofa/registry/jdbc/convertor/AppRevisionDomainConvertor.java b/server/store/jdbc/src/main/java/com/alipay/sofa/registry/jdbc/convertor/AppRevisionDomainConvertor.java index 2e8619eed..8a6298d57 100644 --- a/server/store/jdbc/src/main/java/com/alipay/sofa/registry/jdbc/convertor/AppRevisionDomainConvertor.java +++ b/server/store/jdbc/src/main/java/com/alipay/sofa/registry/jdbc/convertor/AppRevisionDomainConvertor.java @@ -16,7 +16,6 @@ */ package com.alipay.sofa.registry.jdbc.convertor; -import com.alipay.sofa.common.profile.StringUtil; import com.alipay.sofa.registry.common.model.store.AppRevision; import com.alipay.sofa.registry.core.model.AppRevisionInterface; import com.alipay.sofa.registry.jdbc.domain.AppRevisionDomain; @@ -24,6 +23,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.google.common.annotations.VisibleForTesting; import java.util.*; +import org.apache.commons.lang.StringUtils; import org.springframework.util.CollectionUtils; /** @@ -75,7 +75,7 @@ public static AppRevision convert2Revision(AppRevisionDomain domain) { appRevision.setBaseParams(JsonUtils.read(domain.getBaseParams(), BASE_FORMAT)); String serviceParams = domain.getServiceParamsLarge(); - if (StringUtil.isBlank(serviceParams)) { + if (StringUtils.isBlank(serviceParams)) { serviceParams = domain.getServiceParams(); } appRevision.setInterfaceMap(JsonUtils.read(serviceParams, SERVICE_FORMAT));