Reduce too strict check in ONS Client create process
diff --git a/ons-core/ons-auth4client/src/main/java/org/apache/rocketmq/ons/api/impl/authority/SessionCredentials.java b/ons-core/ons-auth4client/src/main/java/org/apache/rocketmq/ons/api/impl/authority/SessionCredentials.java
index fdbac11..854c093 100644
--- a/ons-core/ons-auth4client/src/main/java/org/apache/rocketmq/ons/api/impl/authority/SessionCredentials.java
+++ b/ons-core/ons-auth4client/src/main/java/org/apache/rocketmq/ons/api/impl/authority/SessionCredentials.java
@@ -46,7 +46,7 @@
     private String securityToken;
     private String signature;
     private String signatureMethod;
-    private ONSChannel onsChannel = ONSChannel.ALIYUN;
+    private ONSChannel onsChannel = ONSChannel.CLOUD;
 
     public SessionCredentials() {
         String keyContent = null;
diff --git a/ons-core/ons-client/src/main/java/org/apache/rocketmq/ons/api/impl/rocketmq/ONSClientAbstract.java b/ons-core/ons-client/src/main/java/org/apache/rocketmq/ons/api/impl/rocketmq/ONSClientAbstract.java
index 2cc4d9c..74735e6 100644
--- a/ons-core/ons-client/src/main/java/org/apache/rocketmq/ons/api/impl/rocketmq/ONSClientAbstract.java
+++ b/ons-core/ons-client/src/main/java/org/apache/rocketmq/ons/api/impl/rocketmq/ONSClientAbstract.java
@@ -23,23 +23,20 @@
 import java.util.concurrent.ThreadFactory;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
-
 import javax.annotation.Generated;
-
-import org.apache.rocketmq.ons.open.trace.core.dispatch.AsyncDispatcher;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.rocketmq.client.exception.MQClientException;
 import org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl;
 import org.apache.rocketmq.common.UtilAll;
 import org.apache.rocketmq.common.namesrv.TopAddressing;
 import org.apache.rocketmq.logging.InternalLogger;
-
 import org.apache.rocketmq.ons.api.Admin;
 import org.apache.rocketmq.ons.api.PropertyKeyConst;
 import org.apache.rocketmq.ons.api.exception.ONSClientException;
 import org.apache.rocketmq.ons.api.impl.authority.SessionCredentials;
 import org.apache.rocketmq.ons.api.impl.util.ClientLoggerUtil;
 import org.apache.rocketmq.ons.api.impl.util.NameAddrUtils;
-import org.apache.commons.lang3.StringUtils;
+import org.apache.rocketmq.ons.open.trace.core.dispatch.AsyncDispatcher;
 
 import static org.apache.rocketmq.common.UtilAll.getPid;
 
@@ -54,7 +51,7 @@
     protected static final long WSADDR_INTERNAL_TIMEOUTMILLS =
         Long.parseLong(System.getProperty("com.aliyun.openservices.ons.addr.internal.timeoutmills", "3000"));
     protected static final long WSADDR_INTERNET_TIMEOUTMILLS =
-            Long.parseLong(System.getProperty("com.aliyun.openservices.ons.addr.internet.timeoutmills", "5000"));
+        Long.parseLong(System.getProperty("com.aliyun.openservices.ons.addr.internet.timeoutmills", "5000"));
     private final static InternalLogger LOGGER = ClientLoggerUtil.getClientLogger();
     protected final Properties properties;
     protected final SessionCredentials sessionCredentials = new SessionCredentials();
@@ -75,11 +72,13 @@
     public ONSClientAbstract(Properties properties) {
         this.properties = properties;
         this.sessionCredentials.updateContent(properties);
-        if (null == this.sessionCredentials.getAccessKey() || "".equals(this.sessionCredentials.getAccessKey())) {
+        if (this.sessionCredentials.getOnsChannel().equals(ONSChannel.ALIYUN) &&
+            (null == this.sessionCredentials.getAccessKey() || "".equals(this.sessionCredentials.getAccessKey()))) {
             throw new ONSClientException("please set access key");
         }
 
-        if (null == this.sessionCredentials.getSecretKey() || "".equals(this.sessionCredentials.getSecretKey())) {
+        if (this.sessionCredentials.getOnsChannel().equals(ONSChannel.ALIYUN) &&
+            (null == this.sessionCredentials.getSecretKey() || "".equals(this.sessionCredentials.getSecretKey()))) {
             throw new ONSClientException("please set secret key");
         }
 
@@ -87,12 +86,13 @@
             throw new ONSClientException("please set ons channel");
         }
 
-
-
         this.nameServerAddr = getNameSrvAddrFromProperties();
         if (nameServerAddr != null) {
             return;
         }
+        if (nameServerAddr == null && !this.sessionCredentials.getOnsChannel().equals(ONSChannel.ALIYUN)) {
+            return;
+        }
         this.nameServerAddr = fetchNameServerAddr();
         if (null == nameServerAddr) {
             throw new ONSClientException(FAQ.errorMessage("Can not find name server, May be your network problem.", FAQ.FIND_NS_FAILED));
@@ -131,7 +131,6 @@
     private String fetchNameServerAddr() {
         String nsAddrs;
 
-
         {
             String property = this.properties.getProperty(PropertyKeyConst.ONSAddr);
             if (property != null) {
@@ -145,7 +144,6 @@
             }
         }
 
-
         {
             TopAddressing top = new TopAddressing(WSADDR_INTERNAL);
             nsAddrs = top.fetchNSAddr(false, WSADDR_INTERNAL_TIMEOUTMILLS);
@@ -155,7 +153,6 @@
             }
         }
 
-
         {
             TopAddressing top = new TopAddressing(WSADDR_INTERNET);
             nsAddrs = top.fetchNSAddr(false, WSADDR_INTERNET_TIMEOUTMILLS);
@@ -172,16 +169,21 @@
     }
 
     protected String buildIntanceName() {
-        return Integer.toString(UtilAll.getPid())
-            + "#" + this.nameServerAddr.hashCode()
-            + "#" + this.sessionCredentials.getAccessKey().hashCode()
-            + "#" + System.nanoTime();
+        StringBuilder stringBuilder = new StringBuilder();
+        stringBuilder.append(Integer.toString(UtilAll.getPid())).append("#");
+        if (this.nameServerAddr != null) {
+            stringBuilder.append(this.nameServerAddr.hashCode()).append("#");
+        }
+        if (this.sessionCredentials.getAccessKey() != null) {
+            stringBuilder.append(this.sessionCredentials.getAccessKey().hashCode()).append("#");
+        }
+        stringBuilder.append(System.nanoTime());
+        return stringBuilder.toString();
     }
 
     protected String getNamespace() {
         String namespace = null;
 
-
         {
             String nameserverAddr = this.properties.getProperty(PropertyKeyConst.NAMESRV_ADDR);
             if (StringUtils.isNotEmpty(nameserverAddr)) {
@@ -192,7 +194,6 @@
             }
         }
 
-
         {
             String namespaceFromProperty = this.properties.getProperty(PropertyKeyConst.INSTANCE_ID, null);
             if (StringUtils.isNotEmpty(namespaceFromProperty)) {
@@ -236,13 +237,15 @@
 
     @Override
     public void updateCredential(Properties credentialProperties) {
-        if (null == credentialProperties.getProperty(SessionCredentials.AccessKey)
-                || "".equals(credentialProperties.getProperty(SessionCredentials.AccessKey))) {
+        if (this.sessionCredentials.getOnsChannel().equals(ONSChannel.ALIYUN) &&
+            (null == credentialProperties.getProperty(SessionCredentials.AccessKey)
+                || "".equals(credentialProperties.getProperty(SessionCredentials.AccessKey)))) {
             throw new ONSClientException("update credential failed. please set access key.");
         }
 
-        if (null == credentialProperties.getProperty(SessionCredentials.SecretKey)
-                || "".equals(credentialProperties.getProperty(SessionCredentials.SecretKey))) {
+        if (this.sessionCredentials.getOnsChannel().equals(ONSChannel.ALIYUN) &&
+            (null == credentialProperties.getProperty(SessionCredentials.SecretKey)
+                || "".equals(credentialProperties.getProperty(SessionCredentials.SecretKey)))) {
             throw new ONSClientException("update credential failed. please set secret key");
         }
         this.sessionCredentials.updateContent(credentialProperties);