This is an automated email from the ASF dual-hosted git repository.
peacewong pushed a commit to branch dev-1.3.2
in repository https://gitbox.apache.org/repos/asf/incubator-linkis.git
The following commit(s) were added to refs/heads/dev-1.3.2 by this push:
new 50733c4f1 [Feature][Module Name] Add Tenant label filling and ip
address interception (#3723)
50733c4f1 is described below
commit 50733c4f1084fe716323766b6966df86ee0152c9
Author: huangKai-2323 <[email protected]>
AuthorDate: Mon Nov 14 14:18:35 2022 +0800
[Feature][Module Name] Add Tenant label filling and ip address interception
(#3723)
---
docs/info-1.1.7.md | 5 +
.../org/apache/linkis/ujes/client/UJESClient.scala | 4 +
.../linkis/ujes/client/request/EmsListAction.scala | 71 ++++++++
.../ujes/client/response/EmsListResult.scala | 26 ++-
.../common/protocol/conf/TenantConf.scala | 22 +--
.../common/protocol/conf/UserCreatorIPConf.scala | 22 +--
.../entrance/conf/EntranceSpringConfiguration.java | 18 +-
.../entrance/exception/EntranceErrorCode.java | 4 +-
.../entrance/conf/EntranceConfiguration.scala | 3 +
.../exception/SetTenantLabelException.scala | 23 +--
.../exception/UserCreatorIPCheckException.scala | 23 +--
.../impl/SetTenantLabelInterceptor.scala | 29 ++-
.../interceptor/impl/TenantLabelSetUtils.scala | 110 ++++++++++++
.../impl/UserCreatorIPCheckInterceptor.scala | 42 +++++
.../interceptor/impl/UserCreatorIPCheckUtils.scala | 109 ++++++++++++
.../package/conf/linkis-cg-entrance.properties | 3 +-
linkis-dist/package/db/linkis_ddl.sql | 34 ++++
.../db/upgrade/1.3.1_schema/mysql/linkis_ddl.sql | 3 +-
.../db/upgrade/1.3.2_schema/mysql/linkis_ddl.sql | 49 +++++
.../linkis-configuration/pom.xml | 16 +-
.../UserIpMapper.java} | 27 ++-
.../UserTenantMapper.java} | 30 ++--
.../linkis/configuration/dao/impl/UserIpMapper.xml | 91 ++++++++++
.../configuration/dao/impl/UserTenantMapper.xml | 92 ++++++++++
.../linkis/configuration/entity/TenantVo.java | 143 +++++++++++++++
.../linkis/configuration/entity/UserIpVo.java | 143 +++++++++++++++
.../restful/api/TenantConfigrationRestfulApi.java | 198 +++++++++++++++++++++
.../restful/api/UserIpConfigrationRestfulApi.java | 192 ++++++++++++++++++++
.../TenantConfigService.java} | 30 ++--
.../TenantService.java} | 23 +--
.../UserIpConfigService.java} | 29 +--
.../UserIpService.java} | 23 +--
.../service/impl/TenantConfigServiceImpl.java | 180 +++++++++++++++++++
.../service/impl/TenantServiceImpl.java | 54 ++++++
.../service/impl/UserIpConfigServiceImpl.java | 157 ++++++++++++++++
.../service/impl/UserIpServiceImpl.java | 53 ++++++
...gurationConfiguration.java => CommonUtils.java} | 27 ++-
.../util/ConfigurationConfiguration.java | 6 +
.../linkis/configuration/util/HttpsUtil.java | 114 ++++++++++++
.../linkis/configuration/constant/Constants.scala | 49 +++++
40 files changed, 2051 insertions(+), 226 deletions(-)
diff --git a/docs/info-1.1.7.md b/docs/info-1.1.7.md
new file mode 100644
index 000000000..58f01d4c1
--- /dev/null
+++ b/docs/info-1.1.7.md
@@ -0,0 +1,5 @@
+## 参数变化
+
+| 模块名(服务名)| 类型 | 参数名 | 默认值
| 描述 |
+| ----------- | ----- |
-------------------------------------------------------- | ---------------- |
------------------------------------------------------- |
+|cg-entrance | 新增 |
wds.linkis.entrance.user.creator.ip.interceptor.switch=false |
false|是否开启ip地址拦截|
diff --git
a/linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/UJESClient.scala
b/linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/UJESClient.scala
index b0be00d14..f7241144b 100644
---
a/linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/UJESClient.scala
+++
b/linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/UJESClient.scala
@@ -129,6 +129,10 @@ abstract class UJESClient extends Closeable {
executeUJESJob(getPartitionStatisticInfoAction).asInstanceOf[GetPartitionStatisticInfoResult]
}
+ def listECM(emsListAction: EmsListAction): EmsListResult = {
+ executeUJESJob(emsListAction).asInstanceOf[EmsListResult]
+ }
+
}
object UJESClient {
diff --git
a/linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/request/EmsListAction.scala
b/linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/request/EmsListAction.scala
new file mode 100644
index 000000000..b4f1b4f2b
--- /dev/null
+++
b/linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/request/EmsListAction.scala
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.ujes.client.request
+
+import org.apache.linkis.httpclient.request.GetAction
+
+import org.apache.commons.lang3.StringUtils
+
+class EmsListAction extends GetAction with UJESJobAction {
+
+ override def suffixURLs: Array[String] = Array("linkisManager", "listAllEMs")
+
+}
+
+object EmsListAction {
+ def newBuilder(): Builder = new Builder
+
+ class Builder private[EmsListAction] () {
+ private var user: String = _
+ private var instance: String = _
+ private var nodeHealthy: String = _
+ private var owner: String = _
+
+ def setInstance(instance: String): Builder = {
+ this.instance = instance
+ this
+ }
+
+ def setNodeHealthy(nodeHealthy: String): Builder = {
+ this.nodeHealthy = nodeHealthy
+ this
+ }
+
+ def setOwner(owner: String): Builder = {
+ this.owner = owner
+ this
+ }
+
+ def setUser(user: String): Builder = {
+ this.user = user
+ this
+ }
+
+ def build(): EmsListAction = {
+ val emsListAction = new EmsListAction
+ if (StringUtils.isNotBlank(instance))
emsListAction.setParameter("instance", instance)
+ if (StringUtils.isNotBlank(nodeHealthy))
+ emsListAction.setParameter("nodeHealthy", nodeHealthy)
+ if (StringUtils.isNotBlank(owner)) emsListAction.setParameter("owner",
owner)
+ if (StringUtils.isNotBlank(user)) emsListAction.setUser(user)
+ emsListAction
+ }
+
+ }
+
+}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/response/EmsListResult.scala
similarity index 53%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/response/EmsListResult.scala
index 515d8320d..fcc6925cd 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-computation-governance/linkis-client/linkis-computation-client/src/main/scala/org/apache/linkis/ujes/client/response/EmsListResult.scala
@@ -15,24 +15,22 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.ujes.client.response
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.httpclient.dws.annotation.DWSHttpMessageResult
+import org.apache.linkis.httpclient.dws.response.DWSResult
-import java.util.ArrayList;
+import java.util
-public class ConfigurationConfiguration {
+import scala.beans.BeanProperty
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
+@DWSHttpMessageResult("/api/rest_j/v\\d+/linkisManager/listAllEMs")
+class EmsListResult extends DWSResult {
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
+ @BeanProperty
+ var tasks: util.ArrayList[util.Map[String, Object]] = _
+
+ @BeanProperty
+ var totalPage: Int = _
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/protocol/conf/TenantConf.scala
similarity index 53%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/protocol/conf/TenantConf.scala
index 515d8320d..e8d129453 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/protocol/conf/TenantConf.scala
@@ -15,24 +15,12 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.governance.common.protocol.conf
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.protocol.message.RequestProtocol
-import java.util.ArrayList;
+trait TenantConf extends RequestProtocol
-public class ConfigurationConfiguration {
+case class TenantRequest(user: String, creator: String) extends TenantConf
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
-
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
-
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
-}
+case class TenantResponse(user: String, creator: String, tenant: String)
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/protocol/conf/UserCreatorIPConf.scala
similarity index 53%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/protocol/conf/UserCreatorIPConf.scala
index 515d8320d..fbeafd219 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-computation-governance/linkis-computation-governance-common/src/main/scala/org/apache/linkis/governance/common/protocol/conf/UserCreatorIPConf.scala
@@ -15,24 +15,12 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.governance.common.protocol.conf
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.protocol.message.RequestProtocol
-import java.util.ArrayList;
+trait UserCreatorIPConf extends RequestProtocol
-public class ConfigurationConfiguration {
+case class UserIpRequest(user: String, creator: String) extends
UserCreatorIPConf
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
-
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
-
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
-}
+case class UserIpResponse(user: String, creator: String, ip: String)
diff --git
a/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/conf/EntranceSpringConfiguration.java
b/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/conf/EntranceSpringConfiguration.java
index 795b57038..0bf27a68b 100644
---
a/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/conf/EntranceSpringConfiguration.java
+++
b/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/conf/EntranceSpringConfiguration.java
@@ -27,19 +27,7 @@ import
org.apache.linkis.entrance.event.EntranceEventListenerBus;
import org.apache.linkis.entrance.execute.impl.EntranceExecutorManagerImpl;
import org.apache.linkis.entrance.interceptor.EntranceInterceptor;
import org.apache.linkis.entrance.interceptor.OnceJobInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.CSEntranceInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.CommentInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.CompatibleInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.LabelCheckInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.LogPathCreateInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.ParserVarLabelInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.SQLCodeCheckInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.SQLLimitEntranceInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.ScalaCodeInterceptor;
-import
org.apache.linkis.entrance.interceptor.impl.ShellDangerousGrammerInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.SparkCodeCheckInterceptor;
-import
org.apache.linkis.entrance.interceptor.impl.StorePathEntranceInterceptor;
-import org.apache.linkis.entrance.interceptor.impl.VarSubstitutionInterceptor;
+import org.apache.linkis.entrance.interceptor.impl.*;
import org.apache.linkis.entrance.log.CacheLogManager;
import org.apache.linkis.entrance.log.ErrorCodeListener;
import org.apache.linkis.entrance.log.ErrorCodeManager;
@@ -161,7 +149,9 @@ public class EntranceSpringConfiguration {
new StorePathEntranceInterceptor(),
new ScalaCodeInterceptor(),
new SQLLimitEntranceInterceptor(),
- new CommentInterceptor()
+ new CommentInterceptor(),
+ new SetTenantLabelInterceptor(),
+ new UserCreatorIPCheckInterceptor()
};
}
diff --git
a/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/exception/EntranceErrorCode.java
b/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/exception/EntranceErrorCode.java
index ce481acac..065f436e0 100644
---
a/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/exception/EntranceErrorCode.java
+++
b/linkis-computation-governance/linkis-entrance/src/main/java/org/apache/linkis/entrance/exception/EntranceErrorCode.java
@@ -30,7 +30,9 @@ public enum EntranceErrorCode {
GROUP_NOT_FOUND(20014, "group not found"),
EXECUTION_CODE_ISNULL(20015, "execute code is null, nothing will be
execute!(执行代码为空,没有任何代码会被执行)"),
JOB_UPDATE_FAILED(20016, "job update failed"),
- VARIABLE_NULL_EXCEPTION(20017, "variable is null");
+ VARIABLE_NULL_EXCEPTION(20017, "variable is null"),
+ USER_NULL_EXCEPTION(20018, "User information not obtained"),
+ USER_IP_EXCEPTION(20019, "User IP address is not configured");
private int errCode;
private String desc;
diff --git
a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/conf/EntranceConfiguration.scala
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/conf/EntranceConfiguration.scala
index 9bba3b2ae..89f9d48b2 100644
---
a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/conf/EntranceConfiguration.scala
+++
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/conf/EntranceConfiguration.scala
@@ -222,4 +222,7 @@ object EntranceConfiguration {
val CLIENT_MONITOR_CREATOR =
CommonVars("wds.linkis.entrance.client.monitor.creator", "LINKISCLI")
+ val CREATOR_IP_SWITCH =
+ CommonVars("wds.linkis.entrance.user.creator.ip.interceptor.switch", false)
+
}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/exception/SetTenantLabelException.scala
similarity index 53%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/exception/SetTenantLabelException.scala
index 515d8320d..6614a3d7c 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/exception/SetTenantLabelException.scala
@@ -15,24 +15,9 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.entrance.interceptor.exception
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.common.exception.ErrorException
-import java.util.ArrayList;
-
-public class ConfigurationConfiguration {
-
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
-
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
-
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
-}
+case class SetTenantLabelException(errCode: Int, errDesc: String)
+ extends ErrorException(errCode, errDesc) {}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/exception/UserCreatorIPCheckException.scala
similarity index 53%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/exception/UserCreatorIPCheckException.scala
index 515d8320d..030dc4dc9 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/exception/UserCreatorIPCheckException.scala
@@ -15,24 +15,9 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.entrance.interceptor.exception
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.common.exception.ErrorException
-import java.util.ArrayList;
-
-public class ConfigurationConfiguration {
-
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
-
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
-
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
-}
+case class UserCreatorIPCheckException(errCode: Int, errDesc: String)
+ extends ErrorException(errCode, errDesc) {}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/SetTenantLabelInterceptor.scala
similarity index 52%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/SetTenantLabelInterceptor.scala
index 515d8320d..bc0dd2d02 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/SetTenantLabelInterceptor.scala
@@ -15,24 +15,23 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.entrance.interceptor.impl
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.common.utils.Logging
+import org.apache.linkis.entrance.interceptor.EntranceInterceptor
+import org.apache.linkis.governance.common.entity.job.JobRequest
-import java.util.ArrayList;
+import java.{lang, util}
-public class ConfigurationConfiguration {
+class SetTenantLabelInterceptor extends EntranceInterceptor with Logging {
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
-
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
-
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
+ /**
+ * The apply function supplements the information of the incoming parameter
task, making the
+ * content of the task more complete. Supplementary information includes:
This Interceptor is
+ * mainly used to intercept userCreator and IP
+ */
+ override def apply(jobRequest: JobRequest, logAppender: lang.StringBuilder):
JobRequest = {
+ TenantLabelSetUtils.checkTenantLabel(jobRequest, logAppender)
}
+
}
diff --git
a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/TenantLabelSetUtils.scala
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/TenantLabelSetUtils.scala
new file mode 100644
index 000000000..20f1e61a7
--- /dev/null
+++
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/TenantLabelSetUtils.scala
@@ -0,0 +1,110 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.entrance.interceptor.impl
+
+import org.apache.linkis.common.conf.Configuration
+import org.apache.linkis.common.log.LogUtils
+import org.apache.linkis.common.utils.{Logging, Utils}
+import org.apache.linkis.entrance.conf.EntranceConfiguration
+import org.apache.linkis.entrance.exception.EntranceErrorCode
+import org.apache.linkis.entrance.interceptor.exception.SetTenantLabelException
+import org.apache.linkis.governance.common.entity.job.JobRequest
+import org.apache.linkis.governance.common.protocol.conf.{TenantRequest,
TenantResponse}
+import
org.apache.linkis.manager.label.builder.factory.LabelBuilderFactoryContext
+import org.apache.linkis.manager.label.constant.LabelKeyConstant
+import org.apache.linkis.manager.label.entity.TenantLabel
+import org.apache.linkis.manager.label.utils.LabelUtil
+import org.apache.linkis.rpc.Sender
+
+import org.apache.commons.lang3.StringUtils
+
+import java.{lang, util}
+import java.util.concurrent.TimeUnit
+
+import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache}
+
+object TenantLabelSetUtils extends Logging {
+
+ private val userCreatorTenantCache: LoadingCache[String, String] =
CacheBuilder
+ .newBuilder()
+ .maximumSize(1000)
+
.expireAfterWrite(EntranceConfiguration.USER_PARALLEL_REFLESH_TIME.getValue,
TimeUnit.MINUTES)
+ .build(new CacheLoader[String, String]() {
+
+ override def load(userCreatorLabel: String): String = {
+ Utils.tryAndWarn {
+ val sender: Sender = Sender
+
.getSender(Configuration.CLOUD_CONSOLE_CONFIGURATION_SPRING_APPLICATION_NAME.getValue)
+ val user = userCreatorLabel.split("-")(0)
+ val creator = userCreatorLabel.split("-")(1)
+ logger.info(s"load tenant data user $user creator $creator data")
+ sender.ask(TenantRequest(user, creator)) match {
+ case tenantResponse: TenantResponse => tenantResponse.tenant
+ case _ =>
+ logger.warn(s"TenantCache user $user creator $creator data
loading failed")
+ ""
+ }
+ }
+ }
+
+ })
+
+ def checkTenantLabel(jobRequest: JobRequest, logAppender:
lang.StringBuilder): JobRequest = {
+ jobRequest match {
+ case requestPersistTask: JobRequest =>
+ val labels = requestPersistTask.getLabels
+ // Determine whether the tenant exists. If it exists, it will be
released; if it does not exist, it will be backfilled
+ logger.debug("check labels contains tenant :{} ", labels)
+ if (!labels.contains(LabelKeyConstant.TENANT_KEY)) {
+ // Get user information
+ val userName = jobRequest.getSubmitUser
+ // Error reported when user information is not obtained
+ if (StringUtils.isBlank(userName)) {
+ throw SetTenantLabelException(
+ EntranceErrorCode.USER_NULL_EXCEPTION.getErrCode,
+ EntranceErrorCode.USER_NULL_EXCEPTION.getDesc
+ )
+ }
+ // Get the tenant in the cache through user creator
+ var tenant = ""
+ tenant = userCreatorTenantCache.get(
+ LabelUtil.getUserCreatorLabel(labels).getStringValue.toLowerCase()
+ )
+ if (StringUtils.isBlank(tenant)) {
+ tenant = userCreatorTenantCache.get(
+ "*-" +
LabelUtil.getUserCreatorLabel(jobRequest.getLabels).getCreator.toLowerCase()
+ )
+ }
+ logger.info("get cache tenant:" + tenant + ",jobRequest:" +
jobRequest.getId)
+ // Add cached data if it is not empty
+ if (StringUtils.isNotBlank(tenant)) {
+ val tenantLabel = LabelBuilderFactoryContext.getLabelBuilderFactory
+ .createLabel[TenantLabel](LabelKeyConstant.TENANT_KEY)
+ tenantLabel.setTenant(tenant)
+ labels.add(tenantLabel)
+ logAppender.append(
+ LogUtils.generateInfo(s"Your task should be to set tenant label
$tenant") + "\n"
+ )
+ }
+ }
+ case _ =>
+ }
+ jobRequest
+ }
+
+}
diff --git
a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/UserCreatorIPCheckInterceptor.scala
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/UserCreatorIPCheckInterceptor.scala
new file mode 100644
index 000000000..ee534fcc8
--- /dev/null
+++
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/UserCreatorIPCheckInterceptor.scala
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.entrance.interceptor.impl
+
+import org.apache.linkis.entrance.conf.EntranceConfiguration
+import org.apache.linkis.entrance.interceptor.EntranceInterceptor
+import org.apache.linkis.governance.common.entity.job.JobRequest
+
+import java.lang
+
+class UserCreatorIPCheckInterceptor extends EntranceInterceptor {
+
+ /**
+ * The apply function supplements the information of the incoming parameter
task, making the
+ * content of the task more complete. Additional information includes
Function is a supplement to
+ * the information of the passed in parameter task, making the content of
this task more complete.
+ * Additional information includes: user IP address restrictions
+ */
+ override def apply(jobRequest: JobRequest, logAppender: lang.StringBuilder):
JobRequest = {
+ if (EntranceConfiguration.CREATOR_IP_SWITCH.getValue) {
+ UserCreatorIPCheckUtils.checkUserIp(jobRequest, logAppender)
+ } else {
+ jobRequest
+ }
+ }
+
+}
diff --git
a/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/UserCreatorIPCheckUtils.scala
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/UserCreatorIPCheckUtils.scala
new file mode 100644
index 000000000..ee7fe6d96
--- /dev/null
+++
b/linkis-computation-governance/linkis-entrance/src/main/scala/org/apache/linkis/entrance/interceptor/impl/UserCreatorIPCheckUtils.scala
@@ -0,0 +1,109 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.entrance.interceptor.impl
+
+import org.apache.linkis.common.conf.Configuration
+import org.apache.linkis.common.utils.{Logging, Utils}
+import org.apache.linkis.entrance.conf.EntranceConfiguration
+import org.apache.linkis.entrance.exception.EntranceErrorCode
+import
org.apache.linkis.entrance.interceptor.exception.UserCreatorIPCheckException
+import org.apache.linkis.governance.common.entity.job.JobRequest
+import org.apache.linkis.governance.common.protocol.conf.{UserIpRequest,
UserIpResponse}
+import org.apache.linkis.manager.label.utils.LabelUtil
+import org.apache.linkis.protocol.constants.TaskConstant
+import org.apache.linkis.rpc.Sender
+
+import org.apache.commons.lang3.StringUtils
+
+import java.lang
+import java.util.concurrent.TimeUnit
+
+import com.google.common.cache.{CacheBuilder, CacheLoader, LoadingCache}
+
+object UserCreatorIPCheckUtils extends Logging {
+
+ private val configCache: LoadingCache[String, String] = CacheBuilder
+ .newBuilder()
+ .maximumSize(1000)
+
.expireAfterWrite(EntranceConfiguration.USER_PARALLEL_REFLESH_TIME.getValue,
TimeUnit.MINUTES)
+ .build(new CacheLoader[String, String]() {
+
+ override def load(userCreatorLabel: String): String = {
+ Utils.tryAndWarn {
+ val sender: Sender = Sender
+
.getSender(Configuration.CLOUD_CONSOLE_CONFIGURATION_SPRING_APPLICATION_NAME.getValue)
+ val user = userCreatorLabel.split("-")(0)
+ val creator = userCreatorLabel.split("-")(1)
+ sender.ask(UserIpRequest(user, creator)) match {
+ case useripResponse: UserIpResponse => useripResponse.ip
+ case _ =>
+ logger.warn(s"UserIpCache user $user creator $creator data
loading failed")
+ ""
+ }
+ }
+ }
+
+ })
+
+ def checkUserIp(jobRequest: JobRequest, logAppender: lang.StringBuilder):
JobRequest = {
+ // Get IP address
+ val jobIp = jobRequest.getSource.get(TaskConstant.REQUEST_IP)
+ logger.debug(s"start to checkTenantLabel $jobIp")
+ if (StringUtils.isNotBlank(jobIp)) {
+ jobRequest match {
+ case jobRequest: JobRequest =>
+ // The user information is obtained, and an error is reported if the
user information is not obtained
+ if (StringUtils.isBlank(jobRequest.getSubmitUser)) {
+ throw UserCreatorIPCheckException(
+ EntranceErrorCode.USER_NULL_EXCEPTION.getErrCode,
+ EntranceErrorCode.USER_NULL_EXCEPTION.getDesc
+ )
+ }
+ // Obtain the IP address in the cache through user creator
+ var cacheIp = ""
+ cacheIp = configCache.get(
+
LabelUtil.getUserCreatorLabel(jobRequest.getLabels).getStringValue.toLowerCase()
+ )
+ if (StringUtils.isBlank(cacheIp)) {
+ cacheIp = configCache.get(
+ "*-" +
LabelUtil.getUserCreatorLabel(jobRequest.getLabels).getCreator.toLowerCase()
+ )
+ }
+ logger.info("get cache cacheIp:" + cacheIp + ",jobRequest:" +
jobRequest.getId)
+ // Judge if the cached data is not empty
+ if (StringUtils.isNotBlank(cacheIp)) {
+ if (!cacheIp.equals("*") && (!cacheIp.contains(jobIp))) {
+ logger.warn(
+ " User IP blocking failed cacheIp :{} ,jobRequest:{}
,requestIp:{}",
+ cacheIp,
+ jobRequest.getId,
+ jobIp
+ )
+ throw UserCreatorIPCheckException(
+ EntranceErrorCode.USER_IP_EXCEPTION.getErrCode,
+ EntranceErrorCode.USER_IP_EXCEPTION.getDesc
+ )
+ }
+ }
+ case _ =>
+ }
+ }
+ jobRequest
+ }
+
+}
diff --git a/linkis-dist/package/conf/linkis-cg-entrance.properties
b/linkis-dist/package/conf/linkis-cg-entrance.properties
index f2d136f6e..faeeb2059 100644
--- a/linkis-dist/package/conf/linkis-cg-entrance.properties
+++ b/linkis-dist/package/conf/linkis-cg-entrance.properties
@@ -30,4 +30,5 @@
wds.linkis.server.user.restful.uri.pass.auth=/actuator/prometheus,/api/rest_j/v1
##Spring
-spring.server.port=9104
\ No newline at end of file
+spring.server.port=9104
+wds.linkis.entrance.user.creator.ip.interceptor.switch=false
\ No newline at end of file
diff --git a/linkis-dist/package/db/linkis_ddl.sql
b/linkis-dist/package/db/linkis_ddl.sql
index 745927645..b7f082174 100644
--- a/linkis-dist/package/db/linkis_ddl.sql
+++ b/linkis-dist/package/db/linkis_ddl.sql
@@ -955,3 +955,37 @@ UNIQUE KEY `token_name` (`token_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
+
+-- ----------------------------
+-- Table structure for linkis_cg_tenant_label_config
+-- ----------------------------
+DROP TABLE IF EXISTS `linkis_cg_tenant_label_config`;
+CREATE TABLE `linkis_cg_tenant_label_config` (
+ `id` int(20) NOT NULL AUTO_INCREMENT,
+ `user` varchar(50) COLLATE utf8_bin NOT NULL,
+ `creator` varchar(50) COLLATE utf8_bin NOT NULL,
+ `tenant_value` varchar(128) COLLATE utf8_bin NOT NULL,
+ `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `desc` varchar(100) COLLATE utf8_bin NOT NULL,
+ `bussiness_user` varchar(50) COLLATE utf8_bin NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `user_creator` (`user`,`creator`)
+) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+
+-- ----------------------------
+-- Table structure for linkis_cg_user_ip_config
+-- ----------------------------
+DROP TABLE IF EXISTS `linkis_cg_user_ip_config`;
+CREATE TABLE `linkis_cg_user_ip_config` (
+ `id` int(20) NOT NULL AUTO_INCREMENT,
+ `user` varchar(50) COLLATE utf8_bin NOT NULL,
+ `creator` varchar(50) COLLATE utf8_bin NOT NULL,
+ `ip_list` text COLLATE utf8_bin NOT NULL,
+ `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `desc` varchar(100) COLLATE utf8_bin NOT NULL,
+ `bussiness_user` varchar(50) COLLATE utf8_bin NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `user_creator` (`user`,`creator`)
+) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
\ No newline at end of file
diff --git a/linkis-dist/package/db/upgrade/1.3.1_schema/mysql/linkis_ddl.sql
b/linkis-dist/package/db/upgrade/1.3.1_schema/mysql/linkis_ddl.sql
index a42b1b55a..70c0b1238 100644
--- a/linkis-dist/package/db/upgrade/1.3.1_schema/mysql/linkis_ddl.sql
+++ b/linkis-dist/package/db/upgrade/1.3.1_schema/mysql/linkis_ddl.sql
@@ -44,4 +44,5 @@ CREATE TABLE `linkis_cg_manager_lock` (
`update_time` datetime DEFAULT CURRENT_TIMESTAMP,
`create_time` datetime DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
-) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
\ No newline at end of file
+) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+
diff --git a/linkis-dist/package/db/upgrade/1.3.2_schema/mysql/linkis_ddl.sql
b/linkis-dist/package/db/upgrade/1.3.2_schema/mysql/linkis_ddl.sql
new file mode 100644
index 000000000..fa32d4e5a
--- /dev/null
+++ b/linkis-dist/package/db/upgrade/1.3.2_schema/mysql/linkis_ddl.sql
@@ -0,0 +1,49 @@
+/*
+ * 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.
+*/
+
+-- ----------------------------
+-- CREATE TABLE linkis_cg_tenant_label_config
+-- ----------------------------
+CREATE TABLE `linkis_cg_tenant_label_config` (
+ `id` int(20) NOT NULL AUTO_INCREMENT,
+ `user` varchar(50) COLLATE utf8_bin NOT NULL,
+ `creator` varchar(50) COLLATE utf8_bin NOT NULL,
+ `tenant_value` varchar(128) COLLATE utf8_bin NOT NULL,
+ `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `desc` varchar(100) COLLATE utf8_bin NOT NULL,
+ `bussiness_user` varchar(50) COLLATE utf8_bin NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `user_creator` (`user`,`creator`)
+) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_bin;
+
+
+-- ----------------------------
+-- CREATE TABLE linkis_cg_user_ip_config
+-- ----------------------------
+CREATE TABLE `linkis_cg_user_ip_config` (
+ `id` int(20) NOT NULL AUTO_INCREMENT,
+ `user` varchar(50) COLLATE utf8_bin NOT NULL,
+ `creator` varchar(50) COLLATE utf8_bin NOT NULL,
+ `ip_list` text COLLATE utf8_bin NOT NULL,
+ `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
+ `desc` varchar(100) COLLATE utf8_bin NOT NULL,
+ `bussiness_user` varchar(50) COLLATE utf8_bin NOT NULL,
+ PRIMARY KEY (`id`),
+ UNIQUE KEY `user_creator` (`user`,`creator`)
+) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_bin
\ No newline at end of file
diff --git a/linkis-public-enhancements/linkis-configuration/pom.xml
b/linkis-public-enhancements/linkis-configuration/pom.xml
index f9a51ae51..d55d0b4f3 100644
--- a/linkis-public-enhancements/linkis-configuration/pom.xml
+++ b/linkis-public-enhancements/linkis-configuration/pom.xml
@@ -44,7 +44,21 @@
<artifactId>linkis-manager-common</artifactId>
<version>${project.version}</version>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.linkis</groupId>
+ <artifactId>linkis-httpclient</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.linkis</groupId>
+ <artifactId>linkis-gateway-httpclient-support</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.linkis</groupId>
+ <artifactId>linkis-computation-client</artifactId>
+ <version>${project.version}</version>
+ </dependency>
</dependencies>
<build>
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/UserIpMapper.java
similarity index 53%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/UserIpMapper.java
index 515d8320d..fb6bf44fb 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/UserIpMapper.java
@@ -15,24 +15,23 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.configuration.dao;
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.configuration.entity.UserIpVo;
-import java.util.ArrayList;
+import org.apache.ibatis.annotations.Param;
-public class ConfigurationConfiguration {
+import java.util.List;
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
+public interface UserIpMapper {
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
+ List<UserIpVo> queryUserIPList(@Param("user") String user, @Param("creator")
String creator);
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
+ void deleteUserIP(Integer id);
+
+ void updateUserIP(UserIpVo userIpVo);
+
+ void createUserIP(UserIpVo userIpVo);
+
+ UserIpVo queryUserIP(@Param("user") String user, @Param("creator") String
creator);
}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/UserTenantMapper.java
similarity index 53%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/UserTenantMapper.java
index 515d8320d..c141738ce 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/UserTenantMapper.java
@@ -15,24 +15,26 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.configuration.dao;
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.configuration.entity.TenantVo;
-import java.util.ArrayList;
+import org.apache.ibatis.annotations.Param;
-public class ConfigurationConfiguration {
+import java.util.List;
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
+public interface UserTenantMapper {
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
+ List<TenantVo> queryTenantList(
+ @Param("user") String user,
+ @Param("creator") String creator,
+ @Param("tenant_value") String tenant);
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
+ void deleteTenant(@Param("id") Integer id);
+
+ void updateTenant(TenantVo tenantVo);
+
+ void createTenant(TenantVo tenantVo);
+
+ TenantVo queryTenant(@Param("user") String user, @Param("creator") String
creator);
}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/impl/UserIpMapper.xml
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/impl/UserIpMapper.xml
new file mode 100644
index 000000000..62f36291b
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/impl/UserIpMapper.xml
@@ -0,0 +1,91 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+
+<mapper namespace="org.apache.linkis.configuration.dao.UserIpMapper">
+
+ <resultMap id="UserIpMap"
type="org.apache.linkis.configuration.entity.UserIpVo">
+ <id column="id" property="id" jdbcType="INTEGER"/>
+ <result column="user" property="user" jdbcType="VARCHAR"/>
+ <result column="creator" property="creator" jdbcType="VARCHAR"/>
+ <result column="ip_list" property="ipList" jdbcType="VARCHAR"/>
+ <result column="create_time" property="createTime"
jdbcType="TIMESTAMP"/>
+ <result column="update_time" property="updateTime"
jdbcType="TIMESTAMP"/>
+ <result column="desc" property="desc" jdbcType="VARCHAR"/>
+ <result column="bussiness_user" property="bussinessUser"
jdbcType="VARCHAR"/>
+ </resultMap>
+
+ <sql id="UserIp_Column_List">
+ id,`user`,creator,ip_list,create_time,update_time,`desc`,bussiness_user
+ </sql>
+
+ <sql id="UserIp_insert_Column_List">
+ `user`,creator,ip_list,create_time,update_time,`desc`,bussiness_user
+ </sql>
+
+ <insert id="createUserIP"
parameterType="org.apache.linkis.configuration.entity.UserIpVo">
+ INSERT INTO `linkis_cg_user_ip_config`(<include
refid="UserIp_insert_Column_List"/>)
+ VALUES (
+ #{user},
+ #{creator},
+ #{ipList},
+ #{createTime},
+ #{updateTime},
+ #{desc},
+ #{bussinessUser}
+ )
+ </insert>
+
+ <select id="queryUserIPList" resultMap="UserIpMap">
+ select <include refid="UserIp_Column_List"/>
+ from linkis_cg_user_ip_config
+ <where>
+ <if test="user != null">`user` = #{user}</if>
+ <if test="creator != null">and `creator` = #{creator}</if>
+ </where>
+ </select>
+
+ <delete id="deleteUserIP">
+ DELETE FROM linkis_cg_user_ip_config
+ WHERE id = #{id}
+ </delete>
+
+ <update id="updateUserIP"
parameterType="org.apache.linkis.configuration.entity.UserIpVo">
+ UPDATE linkis_cg_user_ip_config
+ <trim prefix="set" suffixOverrides=",">
+ <if test="user != null">user = #{user},</if>
+ <if test="creator != null">creator = #{creator},</if>
+ <if test="ipList != null">ip_list = #{ipList},</if>
+ <if test="createTime != null">create_time = #{createTime},</if>
+ <if test="updateTime != null">update_time = #{updateTime},</if>
+ <if test="desc != null">`desc` = #{desc},</if>
+ <if test="bussinessUser != null">bussiness_user =
#{bussinessUser}</if>
+ </trim>
+ WHERE id = #{id}
+ </update>
+
+ <select id="queryUserIP"
resultType="org.apache.linkis.configuration.entity.UserIpVo">
+ select <include refid="UserIp_Column_List"/>
+ from linkis_cg_user_ip_config
+ <where>
+ <if test="user != null">`user` = #{user}</if>
+ <if test="creator != null">and `creator` = #{creator}</if>
+ </where>
+ </select>
+</mapper>
\ No newline at end of file
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/impl/UserTenantMapper.xml
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/impl/UserTenantMapper.xml
new file mode 100644
index 000000000..1d031f730
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/dao/impl/UserTenantMapper.xml
@@ -0,0 +1,92 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
+
+<mapper namespace="org.apache.linkis.configuration.dao.UserTenantMapper">
+
+ <resultMap id="TenantMap"
type="org.apache.linkis.configuration.entity.TenantVo">
+ <id column="id" property="id" jdbcType="INTEGER"/>
+ <result column="user" property="user" jdbcType="VARCHAR"/>
+ <result column="creator" property="creator" jdbcType="VARCHAR"/>
+ <result column="tenant_value" property="tenantValue"
jdbcType="VARCHAR"/>
+ <result column="create_time" property="createTime"
jdbcType="TIMESTAMP"/>
+ <result column="update_time" property="updateTime"
jdbcType="TIMESTAMP"/>
+ <result column="desc" property="desc" jdbcType="VARCHAR"/>
+ <result column="bussiness_user" property="bussinessUser"
jdbcType="VARCHAR"/>
+ </resultMap>
+
+ <sql id="Tenant_Column_List">
+
id,user,creator,tenant_value,create_time,update_time,`desc`,bussiness_user
+ </sql>
+
+ <sql id="Tenant_insert_Column_List">
+
`user`,creator,tenant_value,create_time,update_time,`desc`,bussiness_user
+ </sql>
+
+ <insert id="createTenant"
parameterType="org.apache.linkis.configuration.entity.TenantVo">
+ INSERT INTO linkis_cg_tenant_label_config(<include
refid="Tenant_insert_Column_List"/>) VALUES (
+ #{user},
+ #{creator},
+ #{tenantValue},
+ #{createTime},
+ #{updateTime},
+ #{desc},
+ #{bussinessUser}
+ )
+ </insert>
+
+ <select id="queryTenantList" resultMap="TenantMap">
+ select <include refid="Tenant_Column_List"/>
+ from linkis_cg_tenant_label_config
+ <where>
+ <if test="user != null">`user` = #{user}</if>
+ <if test="creator != null">and `creator` = #{creator}</if>
+ <if test="tenant_value != null">and `tenant_value` =
#{tenant_value}</if>
+ </where>
+ </select>
+
+ <delete id="deleteTenant">
+ DELETE FROM linkis_cg_tenant_label_config
+ WHERE id = #{id}
+ </delete>
+
+ <update id="updateTenant"
parameterType="org.apache.linkis.configuration.entity.TenantVo">
+ UPDATE linkis_cg_tenant_label_config
+ <trim prefix="set" suffixOverrides=",">
+ <if test="user != null ">user = #{user},</if>
+ <if test="creator != null">creator = #{creator},</if>
+ <if test="tenantValue != null">tenant_value = #{tenantValue},</if>
+ <if test="createTime != null">create_time = #{createTime},</if>
+ <if test="updateTime != null">update_time = #{updateTime},</if>
+ <if test="desc != null">`desc` = #{desc},</if>
+ <if test="bussinessUser != null">bussiness_user =
#{bussinessUser}</if>
+ </trim>
+ WHERE id = #{id}
+ </update>
+
+
+ <select id="queryTenant" resultMap="TenantMap">
+ select <include refid="Tenant_Column_List"/>
+ from linkis_cg_tenant_label_config
+ <where>
+ <if test="user != null">`user` = #{user}</if>
+ <if test="creator != null">and `creator` = #{creator}</if>
+ </where>
+ </select>
+</mapper>
\ No newline at end of file
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/TenantVo.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/TenantVo.java
new file mode 100644
index 000000000..c2399ff9b
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/TenantVo.java
@@ -0,0 +1,143 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.configuration.entity;
+
+import java.util.Date;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel
+public class TenantVo {
+
+ @ApiModelProperty("id")
+ private String id;
+
+ @ApiModelProperty("user")
+ private String user;
+
+ @ApiModelProperty("creator")
+ private String creator;
+
+ @ApiModelProperty("tenantValue")
+ private String tenantValue;
+
+ @ApiModelProperty("createTime")
+ private Date createTime;
+
+ @ApiModelProperty("updateTime")
+ private Date updateTime;
+
+ @ApiModelProperty("desc")
+ private String desc;
+
+ @ApiModelProperty("bussinessUser")
+ private String bussinessUser;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getCreator() {
+ return creator;
+ }
+
+ public void setCreator(String creator) {
+ this.creator = creator;
+ }
+
+ public String getTenantValue() {
+ return tenantValue;
+ }
+
+ public void setTenantValue(String tenantValue) {
+ this.tenantValue = tenantValue;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public Date getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(Date updateTime) {
+ this.updateTime = updateTime;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ public void setDesc(String desc) {
+ this.desc = desc;
+ }
+
+ public String getBussinessUser() {
+ return bussinessUser;
+ }
+
+ public void setBussinessUser(String bussinessUser) {
+ this.bussinessUser = bussinessUser;
+ }
+
+ @Override
+ public String toString() {
+ return "TenantVo{"
+ + "id='"
+ + id
+ + '\''
+ + ", user='"
+ + user
+ + '\''
+ + ", creator='"
+ + creator
+ + '\''
+ + ", tenantValue='"
+ + tenantValue
+ + '\''
+ + ", createTime="
+ + createTime
+ + ", updateTime="
+ + updateTime
+ + ", desc='"
+ + desc
+ + '\''
+ + ", bussinessUser='"
+ + bussinessUser
+ + '\''
+ + '}';
+ }
+}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/UserIpVo.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/UserIpVo.java
new file mode 100644
index 000000000..05ec8046f
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/entity/UserIpVo.java
@@ -0,0 +1,143 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.configuration.entity;
+
+import java.util.Date;
+
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+
+@ApiModel
+public class UserIpVo {
+
+ @ApiModelProperty("id")
+ private String id;
+
+ @ApiModelProperty("user")
+ private String user;
+
+ @ApiModelProperty("creator")
+ private String creator;
+
+ @ApiModelProperty("ipList")
+ private String ipList;
+
+ @ApiModelProperty("createTime")
+ private Date createTime;
+
+ @ApiModelProperty("updateTime")
+ private Date updateTime;
+
+ @ApiModelProperty("desc")
+ private String desc;
+
+ @ApiModelProperty("bussinessUser")
+ private String bussinessUser;
+
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public String getCreator() {
+ return creator;
+ }
+
+ public void setCreator(String creator) {
+ this.creator = creator;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ public void setDesc(String desc) {
+ this.desc = desc;
+ }
+
+ public String getBussinessUser() {
+ return bussinessUser;
+ }
+
+ public void setBussinessUser(String bussinessUser) {
+ this.bussinessUser = bussinessUser;
+ }
+
+ public Date getCreateTime() {
+ return createTime;
+ }
+
+ public void setCreateTime(Date createTime) {
+ this.createTime = createTime;
+ }
+
+ public Date getUpdateTime() {
+ return updateTime;
+ }
+
+ public void setUpdateTime(Date updateTime) {
+ this.updateTime = updateTime;
+ }
+
+ public String getIpList() {
+ return ipList;
+ }
+
+ public void setIpList(String ips) {
+ this.ipList = ips;
+ }
+
+ @Override
+ public String toString() {
+ return "UserIpVo{"
+ + "id='"
+ + id
+ + '\''
+ + ", user='"
+ + user
+ + '\''
+ + ", creator='"
+ + creator
+ + '\''
+ + ", ipList='"
+ + ipList
+ + '\''
+ + ", createTime="
+ + createTime
+ + ", updateTime="
+ + updateTime
+ + ", desc='"
+ + desc
+ + '\''
+ + ", bussinessUser='"
+ + bussinessUser
+ + '\''
+ + '}';
+ }
+}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/TenantConfigrationRestfulApi.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/TenantConfigrationRestfulApi.java
new file mode 100644
index 000000000..748675253
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/TenantConfigrationRestfulApi.java
@@ -0,0 +1,198 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.configuration.restful.api;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang.StringUtils;
+import org.apache.linkis.common.conf.Configuration;
+import org.apache.linkis.configuration.entity.TenantVo;
+import org.apache.linkis.configuration.exception.ConfigurationException;
+import org.apache.linkis.configuration.service.TenantConfigService;
+import org.apache.linkis.governance.common.constant.job.JobRequestConstants;
+import org.apache.linkis.server.Message;
+import org.apache.linkis.server.utils.ModuleUserUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DuplicateKeyException;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.List;
+import java.util.Map;
+
+@Api
+@RestController
+@RequestMapping(path = "/configuration/tenant-mapping")
+public class TenantConfigrationRestfulApi {
+
+ private static final Logger logger =
LoggerFactory.getLogger(TenantConfigrationRestfulApi.class);
+
+ @Autowired
+ private TenantConfigService tenantConfigService;
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", dataType =
"HttpServletRequest", name = "req", value = ""),
+ @ApiImplicitParam(paramType = "body", dataType = "TenantVo", name
= "tenantVo", value = "tenantVo")
+ })
+ @ApiOperation(value = "create-tenant", notes = "create tenant", httpMethod
= "POST", response = Message.class)
+ @RequestMapping(path = "/create-tenant", method = RequestMethod.POST)
+ public Message createTenant(HttpServletRequest req, @RequestBody TenantVo
tenantVo) {
+ try {
+ String userName = ModuleUserUtils.getOperationUser(req, "execute
createTenant");
+ if (!Configuration.isAdmin(userName)) {
+ return Message.error("Failed to create-tenant,msg: only
administrators can configure");
+ }
+ parameterVerification(tenantVo);
+ tenantConfigService.createTenant(tenantVo);
+ } catch (DuplicateKeyException e) {
+ return Message.error("Failed to create-tenant,msg:create
user-creator is existed");
+ } catch (ConfigurationException e) {
+ return Message.error("Failed to update-tenant,msg:" +
e.getMessage());
+ }
+ return Message.ok();
+ }
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", dataType =
"HttpServletRequest", name = "req", value = ""),
+ @ApiImplicitParam(paramType = "body", dataType = "TenantVo", name
= "tenantVo", value = "tenantVo")
+ })
+ @ApiOperation(value = "update-tenant", notes = "update tenant", httpMethod
= "POST", response = Message.class)
+ @RequestMapping(path = "/update-tenant", method = RequestMethod.POST)
+ public Message updateTenant(HttpServletRequest req, @RequestBody TenantVo
tenantVo) {
+ try {
+ String userName = ModuleUserUtils.getOperationUser(req, "execute
updateTenant");
+ if (!Configuration.isAdmin(userName)) {
+ return Message.error("Failed to update-tenant,msg: only
administrators can configure");
+ }
+ parameterVerification(tenantVo);
+ tenantConfigService.updateTenant(tenantVo);
+ } catch (ConfigurationException e) {
+ return Message.error("Failed to update-tenant,msg:" +
e.getMessage());
+ }
+ return Message.ok();
+ }
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", dataType =
"HttpServletRequest", name = "req", value = ""),
+ @ApiImplicitParam(paramType = "query", dataType = "int", name =
"id", value = "id")
+ })
+ @ApiOperation(value = "delete-tenant", notes = "delete tenant", httpMethod
= "GET", response = Message.class)
+ @RequestMapping(path = "/delete-tenant", method = RequestMethod.GET)
+ public Message deleteTenant(HttpServletRequest req,
+ @RequestParam(value = "id") Integer id) {
+ try {
+ String userName = ModuleUserUtils.getOperationUser(req, "execute
deleteTenant,id: " + id);
+ if (!Configuration.isAdmin(userName)) {
+ return Message.error("Failed to delete-tenant,msg: only
administrators can configure");
+ }
+ tenantConfigService.deleteTenant(id);
+ } catch (ConfigurationException e) {
+ return Message.error("Failed to delete-tenant,msg:" +
e.getMessage());
+ }
+ return Message.ok();
+ }
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", dataType =
"HttpServletRequest", name = "req", value = ""),
+ @ApiImplicitParam(paramType = "query", dataType = "string", name =
"user", value = "user"),
+ @ApiImplicitParam(paramType = "query", dataType = "string", name =
"creator", value = "creator"),
+ @ApiImplicitParam(paramType = "query", dataType = "string", name =
"tenantValue", value = "tenantValue")
+ })
+ @ApiOperation(value = "query-tenant-list", notes = "query tenant list",
httpMethod = "GET", response = Message.class)
+ @RequestMapping(path = "/query-tenant-list", method = RequestMethod.GET)
+ public Message queryTenantList(HttpServletRequest req,
+ @RequestParam(value = "user", required =
false) String user,
+ @RequestParam(value = "creator", required =
false) String creator,
+ @RequestParam(value = "tenantValue",
required = false) String tenantValue,
+ @RequestParam(value = "pageNow", required =
false) Integer pageNow,
+ @RequestParam(value = "pageSize", required
= false) Integer pageSize) {
+ String userName = ModuleUserUtils.getOperationUser(req, "execute
queryTenantList");
+ if (!Configuration.isAdmin(userName)) {
+ return Message.error("Failed to query-tenant-list,msg: only
administrators can configure");
+ }
+ if (StringUtils.isBlank(user)) user = null;
+ if (StringUtils.isBlank(creator)) creator = null;
+ if (StringUtils.isBlank(tenantValue)) tenantValue = null;
+ if (null == pageNow) pageNow = 1;
+ if (null == pageSize) pageSize = 20;
+ Map<String,Object> resultMap =
tenantConfigService.queryTenantList(user, creator, tenantValue, pageNow,
pageSize);
+ return Message.ok().data("tenantList",resultMap.get("tenantList"))
+
.data(JobRequestConstants.TOTAL_PAGE(),resultMap.get(JobRequestConstants.TOTAL_PAGE()));
+ }
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", dataType =
"HttpServletRequest", name = "req", value = ""),
+ @ApiImplicitParam(paramType = "query", dataType = "string", name =
"user", value = "user"),
+ @ApiImplicitParam(paramType = "query", dataType = "string", name =
"creator", value = "creator"),
+ @ApiImplicitParam(paramType = "query", dataType = "string", name =
"tenantValue", value = "tenantValue")
+ })
+ @ApiOperation(value = "check-user-creator", notes = "check user creator",
httpMethod = "GET", response = Message.class)
+ @RequestMapping(path = "/check-user-creator", method = RequestMethod.GET)
+ public Message checkUserCreator(HttpServletRequest req,
+ @RequestParam(value = "user", required =
false) String user,
+ @RequestParam(value = "creator", required
= false) String creator,
+ @RequestParam(value = "tenantValue",
required = false) String tenantValue) {
+ Boolean result = false;
+ try {
+ // Parameter verification
+ if (StringUtils.isBlank(creator)) {
+ throw new ConfigurationException("Application Name can't be
empty ");
+ }
+ if (StringUtils.isBlank(user)) {
+ throw new ConfigurationException("User Name can't be empty ");
+ }
+ if (creator.equals("*")) {
+ throw new ConfigurationException("Application Name can't be
'*' ");
+ }
+ String userName = ModuleUserUtils.getOperationUser(req,
"checkUserCreator");
+ if (!Configuration.isAdmin(userName)) {
+ return Message.error("Failed to check-user-creator,msg: only
administrators can configure");
+ }
+ result = tenantConfigService.checkUserCteator(user, creator,
tenantValue);
+ } catch (ConfigurationException e) {
+ return Message.error("Failed to check-user-creator,msg:" +
e.getMessage());
+ }
+ return Message.ok().data("exist", result);
+ }
+
+ private void parameterVerification(TenantVo tenantVo) throws
ConfigurationException {
+ // Parameter verification
+ if (StringUtils.isBlank(tenantVo.getCreator())) {
+ throw new ConfigurationException("Application name can't be empty
");
+ }
+ if (StringUtils.isBlank(tenantVo.getUser())) {
+ throw new ConfigurationException("User name can't be empty ");
+ }
+ if (StringUtils.isBlank(tenantVo.getBussinessUser())) {
+ throw new ConfigurationException("Creat user can't be empty ");
+ }
+ if (StringUtils.isBlank(tenantVo.getDesc())) {
+ throw new ConfigurationException("Description can't be empty ");
+ }
+ if (StringUtils.isBlank(tenantVo.getTenantValue())) {
+ throw new ConfigurationException("Tenant tag can't be empty ");
+ }
+ if
(tenantConfigService.checkUserCteator(tenantVo.getUser(),tenantVo.getCreator(),null)){
+ throw new ConfigurationException("User-creat is existed");
+ }
+ }
+}
\ No newline at end of file
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/UserIpConfigrationRestfulApi.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/UserIpConfigrationRestfulApi.java
new file mode 100644
index 000000000..b4c40d88c
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/restful/api/UserIpConfigrationRestfulApi.java
@@ -0,0 +1,192 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.configuration.restful.api;
+
+import io.swagger.annotations.Api;
+import io.swagger.annotations.ApiImplicitParam;
+import io.swagger.annotations.ApiImplicitParams;
+import io.swagger.annotations.ApiOperation;
+import org.apache.commons.lang.StringUtils;
+import org.apache.linkis.common.conf.Configuration;
+import org.apache.linkis.configuration.entity.UserIpVo;
+import org.apache.linkis.configuration.exception.ConfigurationException;
+import org.apache.linkis.configuration.service.UserIpConfigService;
+import org.apache.linkis.governance.common.constant.job.JobRequestConstants;
+import org.apache.linkis.server.Message;
+import org.apache.linkis.server.utils.ModuleUserUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.dao.DuplicateKeyException;
+import org.springframework.web.bind.annotation.*;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Map;
+
+@Api
+@RestController
+@RequestMapping(path = "/configuration/user-ip-mapping")
+public class UserIpConfigrationRestfulApi {
+
+ private static final Logger logger =
LoggerFactory.getLogger(UserIpConfigrationRestfulApi.class);
+
+ @Autowired
+ private UserIpConfigService userIpConfigService;
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", dataType =
"HttpServletRequest", name = "req", value = ""),
+ @ApiImplicitParam(paramType = "body", dataType = "UserIpVo", name
= "userIpVo", value = "userIpVo")
+ })
+ @ApiOperation(value = "create-user-ip", notes = "create user ip",
httpMethod = "POST")
+ @RequestMapping(path = "/create-user-ip", method = RequestMethod.POST)
+ public Message createUserIp(HttpServletRequest req, @RequestBody UserIpVo
userIpVo) {
+ try {
+ String userName = ModuleUserUtils.getOperationUser(req, "execute
createUserIP");
+ if (!Configuration.isAdmin(userName)) {
+ return Message.error("Failed to create-user-ip,msg: only
administrators can configure");
+ }
+ parameterVerification(userIpVo);
+ userIpConfigService.createUserIP(userIpVo);
+ } catch (DuplicateKeyException e) {
+ return Message.error("Failed to create-user-ip,msg:create
user-creator is existed");
+ } catch (ConfigurationException e) {
+ return Message.error("Failed to create-user-ip,msg:" +
e.getMessage());
+ }
+ return Message.ok();
+ }
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", dataType =
"HttpServletRequest", name = "req", value = ""),
+ @ApiImplicitParam(paramType = "body", dataType = "UserIpVo", name
= "UserIpVo", value = "UserIpVo")
+ })
+ @ApiOperation(value = "update-user-ip", notes = "update user ip",
httpMethod = "POST")
+ @RequestMapping(path = "/update-user-ip", method = RequestMethod.POST)
+ public Message updateUserIp(HttpServletRequest req, @RequestBody UserIpVo
userIpVo) {
+ try {
+ String userName = ModuleUserUtils.getOperationUser(req, "execute
updateUserIP");
+ if (!Configuration.isAdmin(userName)) {
+ return Message.error("Failed to update-user-ip,msg: only
administrators can configure ");
+ }
+ parameterVerification(userIpVo);
+ userIpConfigService.updateUserIP(userIpVo);
+ } catch (ConfigurationException e) {
+ return Message.error("Failed to update-user-ip,msg:" +
e.getMessage());
+ }
+ return Message.ok();
+ }
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", dataType =
"HttpServletRequest", name = "req", value = ""),
+ @ApiImplicitParam(paramType = "query", dataType = "int", name =
"id", value = "id")
+ })
+ @ApiOperation(value = "delete-user-ip", notes = "delete user ip",
httpMethod = "GET")
+ @RequestMapping(path = "/delete-user-ip", method = RequestMethod.GET)
+ public Message deleteUserIp(HttpServletRequest req,
+ @RequestParam(value = "id") Integer id) {
+ try {
+ String userName = ModuleUserUtils.getOperationUser(req, "execute
deleteUserIp,id: " + id);
+ if (!Configuration.isAdmin(userName)) {
+ return Message.error("Failed to delete-user-ip,msg: only
administrators can configure");
+ }
+ userIpConfigService.deleteUserIP(id);
+ } catch (ConfigurationException e) {
+ return Message.error("Failed to check-user-creator,msg:" +
e.getMessage());
+ }
+ return Message.ok();
+ }
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", dataType =
"HttpServletRequest", name = "req", value = ""),
+ @ApiImplicitParam(paramType = "query", dataType = "string", name =
"user", value = "user"),
+ @ApiImplicitParam(paramType = "query", dataType = "string", name =
"creator", value = "creator")
+ })
+ @ApiOperation(value = "query-user-ip-list", notes = "query user ip list",
httpMethod = "GET")
+ @RequestMapping(path = "/query-user-ip-list", method = RequestMethod.GET)
+ public Message queryUserIpList(HttpServletRequest req,
+ @RequestParam(value = "user") String user,
+ @RequestParam(value = "creator") String
creator,
+ @RequestParam(value = "pageNow") Integer
pageNow,
+ @RequestParam(value = "pageSize") Integer
pageSize) {
+ String userName = ModuleUserUtils.getOperationUser(req,
"queryUserIPList");
+ if (!Configuration.isAdmin(userName)) {
+ return Message.error("Failed to query-user-ip-list,msg: only
administrators can configure");
+ }
+ if (StringUtils.isBlank(user)) user = null;
+ if (StringUtils.isBlank(creator)) creator = null;
+ if (null == pageNow) pageNow = 1;
+ if (null == pageSize) pageSize = 20;
+ Map<String, Object> resultMap =
userIpConfigService.queryUserIPList(user, creator, pageNow, pageSize);
+ return Message.ok().data("userIpList", resultMap.get("userIpList"))
+ .data(JobRequestConstants.TOTAL_PAGE(),
resultMap.get(JobRequestConstants.TOTAL_PAGE()));
+ }
+
+ @ApiImplicitParams({
+ @ApiImplicitParam(paramType = "query", dataType =
"HttpServletRequest", name = "req", value = ""),
+ @ApiImplicitParam(paramType = "query", dataType = "string", name =
"user", value = "user"),
+ @ApiImplicitParam(paramType = "query", dataType = "string", name =
"creator", value = "creator")
+ })
+ @ApiOperation(value = "check-user-creator", notes = " check user creator",
httpMethod = "GET")
+ @RequestMapping(path = "/check-user-creator", method = RequestMethod.GET)
+ public Message checkUserCreator(HttpServletRequest req,
+ @RequestParam(value = "user") String user,
+ @RequestParam(value = "creator") String
creator) {
+ Boolean result = false;
+ try {
+ String userName = ModuleUserUtils.getOperationUser(req,
"checkUserCreator");
+ if (!Configuration.isAdmin(userName)) {
+ return Message.error("Failed to check-user-creator,msg: only
administrators can configure");
+ }
+ // Parameter verification
+ if (StringUtils.isBlank(creator)) {
+ throw new ConfigurationException("Application Name couldn't be
empty ");
+ }
+ if (StringUtils.isBlank(user)) {
+ throw new ConfigurationException("User Name couldn't be empty
");
+ }
+ if (creator.equals("*")) {
+ throw new ConfigurationException("Application Name couldn't be
'*' ");
+ }
+ result = userIpConfigService.checkUserCteator(user, creator);
+ } catch (ConfigurationException e) {
+ return Message.error("Failed to check-user-creator,msg:" +
e.getMessage());
+ }
+ return Message.ok().data("exist", result);
+ }
+
+ private void parameterVerification(UserIpVo userIpVo) throws
ConfigurationException {
+ // Parameter verification
+ if (StringUtils.isBlank(userIpVo.getCreator())) {
+ throw new ConfigurationException("Application Name couldn't be
empty ");
+ }
+ if (StringUtils.isBlank(userIpVo.getUser())) {
+ throw new ConfigurationException("User Name couldn't be empty ");
+ }
+ if (StringUtils.isBlank(userIpVo.getBussinessUser())) {
+ throw new ConfigurationException("Creat User couldn't be empty ");
+ }
+ if (StringUtils.isBlank(userIpVo.getIpList())) {
+ throw new ConfigurationException("Ip List couldn't be empty ");
+ }
+ if (StringUtils.isBlank(userIpVo.getDesc())) {
+ throw new ConfigurationException("Description couldn't be empty ");
+ }
+ if (userIpConfigService.checkUserCteator(userIpVo.getUser(),
userIpVo.getCreator())) {
+ throw new ConfigurationException("User-creat is existed");
+ }
+ }
+}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/TenantConfigService.java
similarity index 52%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/TenantConfigService.java
index 515d8320d..3e6ba85a8 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/TenantConfigService.java
@@ -15,24 +15,26 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.configuration.service;
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.configuration.entity.TenantVo;
+import org.apache.linkis.configuration.exception.ConfigurationException;
-import java.util.ArrayList;
+import java.util.Map;
-public class ConfigurationConfiguration {
+public interface TenantConfigService {
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
+ Map<String, Object> queryTenantList(
+ String user, String creator, String tenantValue, Integer pageNow,
Integer pageSize);
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
+ void deleteTenant(Integer id) throws ConfigurationException;
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
+ void updateTenant(TenantVo tenantVo) throws ConfigurationException;
+
+ void createTenant(TenantVo tenantVo) throws ConfigurationException;
+
+ Boolean checkUserCteator(String user, String creator, String tenantValue)
+ throws ConfigurationException;
+
+ TenantVo queryTenant(String user, String creator);
}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/TenantService.java
similarity index 53%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/TenantService.java
index 515d8320d..df8892345 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/TenantService.java
@@ -15,24 +15,13 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.configuration.service;
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.governance.common.protocol.conf.TenantRequest;
+import org.apache.linkis.governance.common.protocol.conf.TenantResponse;
+import org.apache.linkis.rpc.Sender;
-import java.util.ArrayList;
+public interface TenantService {
-public class ConfigurationConfiguration {
-
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
-
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
-
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
+ TenantResponse getTenantData(TenantRequest request, Sender sender);
}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/UserIpConfigService.java
similarity index 53%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/UserIpConfigService.java
index 515d8320d..18b163a25 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/UserIpConfigService.java
@@ -15,24 +15,25 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.configuration.service;
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.configuration.entity.UserIpVo;
+import org.apache.linkis.configuration.exception.ConfigurationException;
-import java.util.ArrayList;
+import java.util.Map;
-public class ConfigurationConfiguration {
+public interface UserIpConfigService {
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
+ void createUserIP(UserIpVo userIpVo) throws ConfigurationException;
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
+ void updateUserIP(UserIpVo userIpVo) throws ConfigurationException;
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
+ void deleteUserIP(Integer id) throws ConfigurationException;
+
+ Map<String, Object> queryUserIPList(
+ String user, String creator, Integer pageNow, Integer pageSize);
+
+ Boolean checkUserCteator(String user, String creator);
+
+ UserIpVo queryUserIP(String user, String creator);
}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/UserIpService.java
similarity index 53%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/UserIpService.java
index 515d8320d..c025e3f73 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/UserIpService.java
@@ -15,24 +15,13 @@
* limitations under the License.
*/
-package org.apache.linkis.configuration.util;
+package org.apache.linkis.configuration.service;
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
+import org.apache.linkis.governance.common.protocol.conf.UserIpRequest;
+import org.apache.linkis.governance.common.protocol.conf.UserIpResponse;
+import org.apache.linkis.rpc.Sender;
-import java.util.ArrayList;
+public interface UserIpService {
-public class ConfigurationConfiguration {
-
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
-
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
-
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
- }
+ UserIpResponse getUserIpData(UserIpRequest request, Sender sender);
}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantConfigServiceImpl.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantConfigServiceImpl.java
new file mode 100644
index 000000000..932c10e48
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantConfigServiceImpl.java
@@ -0,0 +1,180 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.configuration.service.impl;
+
+import org.apache.linkis.configuration.dao.UserTenantMapper;
+import org.apache.linkis.configuration.entity.TenantVo;
+import org.apache.linkis.configuration.exception.ConfigurationException;
+import org.apache.linkis.configuration.service.TenantConfigService;
+import org.apache.linkis.configuration.util.HttpsUtil;
+import org.apache.linkis.governance.common.constant.job.JobRequestConstants;
+
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.StringUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.io.IOException;
+import java.util.*;
+import java.util.concurrent.atomic.AtomicReference;
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Service
+public class TenantConfigServiceImpl implements TenantConfigService {
+
+ private static final Logger logger =
LoggerFactory.getLogger(TenantConfigServiceImpl.class);
+
+ @Autowired private UserTenantMapper userTenantMapper;
+
+ /**
+ * * Querying the tenant configuration table
+ *
+ * @param user
+ * @param creator
+ * @param tenantValue
+ * @param pageNow
+ * @param pageSize
+ * @return List<TenantVo>
+ */
+ @Override
+ public Map<String, Object> queryTenantList(
+ String user, String creator, String tenantValue, Integer pageNow,
Integer pageSize) {
+ Map<String, Object> result = new HashMap<>(2);
+ List<TenantVo> tenantVos = null;
+ PageHelper.startPage(pageNow, pageSize);
+ try {
+ tenantVos = userTenantMapper.queryTenantList(user, creator, tenantValue);
+ } finally {
+ PageHelper.clearPage();
+ }
+ PageInfo<TenantVo> pageInfo = new PageInfo<>(tenantVos);
+ result.put("tenantList", tenantVos);
+ result.put(JobRequestConstants.TOTAL_PAGE(), pageInfo.getTotal());
+ return result;
+ }
+
+ /**
+ * Delete tenant By ID
+ *
+ * @param id
+ */
+ @Override
+ public void deleteTenant(Integer id) throws ConfigurationException {
+ logger.info("deleteUserIP : id:{}", id);
+ if (StringUtils.isBlank(id.toString())) {
+ throw new ConfigurationException("id can't be empty ");
+ }
+ userTenantMapper.deleteTenant(id);
+ }
+
+ /**
+ * Update tenant
+ *
+ * @param tenantVo
+ */
+ @Override
+ public void updateTenant(TenantVo tenantVo) throws ConfigurationException {
+ if (StringUtils.isBlank(tenantVo.getId())) {
+ throw new ConfigurationException("id can't be empty ");
+ }
+ dataProcessing(tenantVo);
+ TenantVo tenantVoLowerCase = toLowerCase(tenantVo);
+ tenantVoLowerCase.setUpdateTime(new Date());
+ logger.info("updateTenant : {}", tenantVoLowerCase);
+ userTenantMapper.updateTenant(tenantVoLowerCase);
+ }
+
+ /**
+ * Insert tenant
+ *
+ * @param tenantVo
+ */
+ @Override
+ public void createTenant(TenantVo tenantVo) throws ConfigurationException {
+ dataProcessing(tenantVo);
+ TenantVo tenantVoLowerCase = toLowerCase(tenantVo);
+ tenantVoLowerCase.setUpdateTime(new Date());
+ tenantVoLowerCase.setCreateTime(new Date());
+ logger.info("updateTenant : {}", tenantVoLowerCase);
+ userTenantMapper.createTenant(tenantVo);
+ }
+
+ private void dataProcessing(TenantVo tenantVo) throws ConfigurationException
{
+ AtomicReference<Boolean> tenantResult = new AtomicReference<>(false);
+ // Obtain the tenant information of the ECM list
+ Map<String, Object> resultmap = null;
+ try {
+ resultmap = HttpsUtil.sendHttp(null, null);
+ logger.info("ResourceMonitor response {}:", resultmap);
+ } catch (IOException e) {
+ logger.warn("failed to get ecmResource data");
+ }
+ Map<String, List<Map<String, Object>>> data = MapUtils.getMap(resultmap,
"data");
+ List<Map<String, Object>> emNodeVoList = data.get("EMs");
+ emNodeVoList.forEach(
+ ecmInfo -> {
+ List<Map<String, Object>> labels = (List<Map<String, Object>>)
ecmInfo.get("labels");
+ labels.stream()
+ .filter(labelmap -> labelmap.containsKey("tenant"))
+ .forEach(
+ map -> {
+ String tenant = map.get("tenant").toString().toLowerCase();
+ if (tenant.equals(tenantVo.getTenantValue())) {
+ tenantResult.set(true);
+ }
+ });
+ });
+ // Compare the value of ecm tenant
+ if (!tenantResult.get())
+ throw new ConfigurationException("The ECM with the corresponding label
was not found");
+ // The beginning of tenantValue needs to contain creator
+ String creator = tenantVo.getCreator().toLowerCase();
+ String tenantValue = tenantVo.getTenantValue().toLowerCase().split("_")[0];
+ if (!creator.equals(tenantValue))
+ throw new ConfigurationException("tenantValue should contain creator
first");
+ }
+
+ @Override
+ public Boolean checkUserCteator(String user, String creator, String
tenantValue)
+ throws ConfigurationException {
+ boolean result = true;
+ Map<String, Object> resultMap =
+ queryTenantList(user.toLowerCase(), creator.toLowerCase(), null, null,
null);
+ Object tenantList =
resultMap.getOrDefault(JobRequestConstants.TOTAL_PAGE(), 0);
+ int total = Integer.parseInt(tenantList.toString());
+ if (total == 0) result = false;
+ return result;
+ }
+
+ @Override
+ public TenantVo queryTenant(String user, String creator) {
+ return userTenantMapper.queryTenant(user, creator);
+ }
+
+ public TenantVo toLowerCase(TenantVo tenantVo) {
+ tenantVo.setTenantValue(tenantVo.getTenantValue().toLowerCase());
+ tenantVo.setCreator(tenantVo.getCreator().toLowerCase());
+ tenantVo.setUser(tenantVo.getUser().toLowerCase());
+ return tenantVo;
+ }
+}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantServiceImpl.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantServiceImpl.java
new file mode 100644
index 000000000..25d272c12
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/TenantServiceImpl.java
@@ -0,0 +1,54 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.configuration.service.impl;
+
+import org.apache.linkis.configuration.entity.TenantVo;
+import org.apache.linkis.configuration.service.TenantConfigService;
+import org.apache.linkis.configuration.service.TenantService;
+import org.apache.linkis.governance.common.protocol.conf.TenantRequest;
+import org.apache.linkis.governance.common.protocol.conf.TenantResponse;
+import org.apache.linkis.rpc.Sender;
+import org.apache.linkis.rpc.message.annotation.Receiver;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Service
+public class TenantServiceImpl implements TenantService {
+
+ private static final Logger logger =
LoggerFactory.getLogger(TenantService.class);
+
+ @Autowired private TenantConfigService tenantConfigService;
+
+ @Receiver
+ @Override
+ public TenantResponse getTenantData(TenantRequest request, Sender sender) {
+ TenantVo tenantVo = tenantConfigService.queryTenant(request.user(),
request.creator());
+ if (null == tenantVo) {
+ logger.warn(
+ "TenantCache user {} creator {} data loading failed",
request.user(), request.creator());
+ return new TenantResponse(request.user(), request.creator(), "");
+ } else {
+ return new TenantResponse(
+ tenantVo.getUser(), tenantVo.getCreator(),
tenantVo.getTenantValue());
+ }
+ }
+}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpConfigServiceImpl.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpConfigServiceImpl.java
new file mode 100644
index 000000000..7e41b0ee8
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpConfigServiceImpl.java
@@ -0,0 +1,157 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.configuration.service.impl;
+
+import org.apache.linkis.configuration.dao.UserIpMapper;
+import org.apache.linkis.configuration.entity.UserIpVo;
+import org.apache.linkis.configuration.exception.ConfigurationException;
+import org.apache.linkis.configuration.service.UserIpConfigService;
+import org.apache.linkis.configuration.util.CommonUtils;
+import org.apache.linkis.governance.common.constant.job.JobRequestConstants;
+
+import org.apache.commons.lang.StringUtils;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.*;
+
+import com.github.pagehelper.PageHelper;
+import com.github.pagehelper.PageInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Service
+public class UserIpConfigServiceImpl implements UserIpConfigService {
+
+ private static final Logger logger =
LoggerFactory.getLogger(UserIpConfigServiceImpl.class);
+
+ @Autowired private UserIpMapper userIpMapper;
+
+ /**
+ * * createUserIP
+ *
+ * @param userIpVo
+ * @return
+ */
+ @Override
+ public void createUserIP(UserIpVo userIpVo) throws ConfigurationException {
+ dataProcessing(userIpVo);
+ UserIpVo userIpVoLowerCase = toLowerCase(userIpVo);
+ userIpVoLowerCase.setCreateTime(new Date());
+ userIpVoLowerCase.setUpdateTime(new Date());
+ userIpMapper.createUserIP(userIpVoLowerCase);
+ }
+
+ /**
+ * updateUserIP
+ *
+ * @param userIpVo
+ */
+ @Override
+ public void updateUserIP(UserIpVo userIpVo) throws ConfigurationException {
+ if (StringUtils.isBlank(userIpVo.getId())) {
+ throw new ConfigurationException("id couldn't be empty ");
+ }
+ dataProcessing(userIpVo);
+ UserIpVo userIpVoLowerCase = toLowerCase(userIpVo);
+ userIpVoLowerCase.setUpdateTime(new Date());
+ logger.info("updateUserIP : {}", userIpVoLowerCase);
+ userIpMapper.updateUserIP(userIpVoLowerCase);
+ }
+
+ /**
+ * deleteUserIP
+ *
+ * @param id
+ */
+ @Override
+ @Transactional(rollbackFor = Throwable.class)
+ public void deleteUserIP(Integer id) throws ConfigurationException {
+ logger.info("deleteUserIP : id:{}", id);
+ if (StringUtils.isBlank(id.toString())) {
+ throw new ConfigurationException("id couldn't be empty ");
+ }
+ userIpMapper.deleteUserIP(id);
+ }
+
+ /**
+ * Query IP Collection
+ *
+ * @return List<UserIpVo>
+ * @param user
+ * @param creator
+ * @param pageNow
+ * @param pageSize
+ */
+ @Override
+ public Map<String, Object> queryUserIPList(
+ String user, String creator, Integer pageNow, Integer pageSize) {
+ Map<String, Object> result = new HashMap<>(2);
+ List<UserIpVo> userIpVos = null;
+ PageHelper.startPage(pageNow, pageSize);
+ try {
+ userIpVos = userIpMapper.queryUserIPList(user, creator);
+ } finally {
+ PageHelper.clearPage();
+ }
+ PageInfo<UserIpVo> pageInfo = new PageInfo<>(userIpVos);
+ result.put("userIpList", userIpVos);
+ result.put(JobRequestConstants.TOTAL_PAGE(), pageInfo.getTotal());
+ return result;
+ }
+
+ private void dataProcessing(UserIpVo userIpVo) throws ConfigurationException
{
+ // Ip rule verification
+ String ipList = userIpVo.getIpList();
+ if (!ipList.equals("*")) {
+ String[] split = ipList.split(",");
+ StringJoiner joiner = new StringJoiner(",");
+ Arrays.stream(split)
+ .distinct()
+ .filter(ipStr -> !CommonUtils.ipCheck(ipStr))
+ .forEach(joiner::add);
+ if (StringUtils.isNotBlank(joiner.toString())) {
+ throw new ConfigurationException(joiner + ",Illegal IP address ");
+ }
+ }
+ }
+
+ @Override
+ public Boolean checkUserCteator(String user, String creator) {
+ boolean result = true;
+ Map<String, Object> resultMap =
+ queryUserIPList(user.toLowerCase(), creator.toLowerCase(), null, null);
+ Object userIpList =
resultMap.getOrDefault(JobRequestConstants.TOTAL_PAGE(), 0);
+ int total = Integer.parseInt(userIpList.toString());
+ if (total == 0) result = false;
+ return result;
+ }
+
+ @Override
+ public UserIpVo queryUserIP(String user, String creator) {
+ return userIpMapper.queryUserIP(user, creator);
+ }
+
+ private UserIpVo toLowerCase(UserIpVo userIpVo) {
+ userIpVo.setCreator(userIpVo.getCreator().toLowerCase());
+ userIpVo.setUser(userIpVo.getUser().toLowerCase());
+ return userIpVo;
+ }
+}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpServiceImpl.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpServiceImpl.java
new file mode 100644
index 000000000..40128cc5b
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/service/impl/UserIpServiceImpl.java
@@ -0,0 +1,53 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.configuration.service.impl;
+
+import org.apache.linkis.configuration.entity.UserIpVo;
+import org.apache.linkis.configuration.service.UserIpConfigService;
+import org.apache.linkis.configuration.service.UserIpService;
+import org.apache.linkis.governance.common.protocol.conf.UserIpRequest;
+import org.apache.linkis.governance.common.protocol.conf.UserIpResponse;
+import org.apache.linkis.rpc.Sender;
+import org.apache.linkis.rpc.message.annotation.Receiver;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Service
+public class UserIpServiceImpl implements UserIpService {
+
+ private static final Logger logger =
LoggerFactory.getLogger(UserIpService.class);
+
+ @Autowired private UserIpConfigService userIpConfigService;
+
+ @Receiver
+ @Override
+ public UserIpResponse getUserIpData(UserIpRequest request, Sender sender) {
+ UserIpVo userIpVo = userIpConfigService.queryUserIP(request.user(),
request.creator());
+ if (null == userIpVo) {
+ logger.warn(
+ "UserIpCache user {} creator {} data loading failed",
request.user(), request.creator());
+ return new UserIpResponse(request.user(), request.creator(), "");
+ } else {
+ return new UserIpResponse(userIpVo.getUser(), userIpVo.getCreator(),
userIpVo.getIpList());
+ }
+ }
+}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/CommonUtils.java
similarity index 56%
copy from
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
copy to
linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/CommonUtils.java
index 515d8320d..ed80f09a0 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/CommonUtils.java
@@ -17,22 +17,15 @@
package org.apache.linkis.configuration.util;
-import org.apache.linkis.common.conf.CommonVars$;
-import org.apache.linkis.manager.label.entity.Label;
-import org.apache.linkis.manager.label.entity.engine.EngineTypeLabel;
-import org.apache.linkis.manager.label.entity.engine.UserCreatorLabel;
-
-import java.util.ArrayList;
-
-public class ConfigurationConfiguration {
-
- public static final ArrayList<Label> PERMIT_LABEL_TYPE = new ArrayList<>();
-
- public static final String COPYKEYTOKEN =
- CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
-
- static {
- PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
- PERMIT_LABEL_TYPE.add(new EngineTypeLabel());
+public class CommonUtils {
+ public static boolean ipCheck(String str) {
+ if (str != null && !str.isEmpty()) {
+ String pattern = ConfigurationConfiguration.IPCHECK;
+ if (str.matches(pattern)) {
+ return true;
+ }
+ return false;
+ }
+ return false;
}
}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
index 515d8320d..b69f20cdb 100644
---
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/ConfigurationConfiguration.java
@@ -30,6 +30,12 @@ public class ConfigurationConfiguration {
public static final String COPYKEYTOKEN =
CommonVars$.MODULE$.apply("wds.linkis.configuration.copykey.token",
"e8724-e").getValue();
+ public static final String IPCHECK =
+ CommonVars$.MODULE$
+ .apply(
+ "linkis.configuration.ipcheck.pattern",
+
"^(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}$")
+ .getValue();
static {
PERMIT_LABEL_TYPE.add(new UserCreatorLabel());
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/HttpsUtil.java
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/HttpsUtil.java
new file mode 100644
index 000000000..57fd7035d
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/java/org/apache/linkis/configuration/util/HttpsUtil.java
@@ -0,0 +1,114 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.configuration.util;
+
+import org.apache.linkis.common.conf.Configuration;
+import org.apache.linkis.configuration.constant.Constants;
+import
org.apache.linkis.httpclient.dws.authentication.TokenAuthenticationStrategy;
+import org.apache.linkis.httpclient.dws.config.DWSClientConfig;
+import org.apache.linkis.httpclient.dws.config.DWSClientConfigBuilder;
+import org.apache.linkis.ujes.client.UJESClientImpl;
+import org.apache.linkis.ujes.client.request.EmsListAction;
+import org.apache.linkis.ujes.client.response.EmsListResult;
+
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HttpsUtil {
+
+ private static final Logger logger =
LoggerFactory.getLogger(HttpsUtil.class);
+
+ public static DWSClientConfig dwsClientConfig = createClientConfig(null,
null);
+
+ public static UJESClientImpl client = new UJESClientImpl(dwsClientConfig);
+
+ public static Map<String, Object> sendHttp(String url, Map<String, Object>
properties)
+ throws IOException {
+ if (null == dwsClientConfig) {
+ dwsClientConfig = createClientConfig(url, properties);
+ }
+ if (null == client) {
+ client = new UJESClientImpl(dwsClientConfig);
+ }
+ EmsListAction build = EmsListAction.newBuilder().setUser("hadoop").build();
+ EmsListResult result = client.listECM(build);
+ return result.getResultMap();
+ }
+
+ private static DWSClientConfig createClientConfig(String url, Map<String,
Object> properties) {
+ String realUrl = "";
+ if (StringUtils.isBlank(url)) {
+ realUrl = Configuration.getGateWayURL();
+ } else {
+ realUrl = url;
+ }
+ Map<String, Object> parms = new HashMap<>();
+ if (MapUtils.isNotEmpty(properties)) {
+ parms = properties;
+ }
+ int maxConnection =
+ (int)
+ parms.getOrDefault(
+ Constants.CONNECTION_MAX_SIZE_SHORT_NAME(),
+ Constants.CONNECTION_MAX_SIZE().getValue());
+ int connectTimeout =
+ (int)
+ parms.getOrDefault(
+ Constants.CONNECTION_TIMEOUT_SHORT_NAME(),
+ Constants.CONNECTION_TIMEOUT().getValue());
+ int readTimeout =
+ (int)
+ parms.getOrDefault(
+ Constants.CONNECTION_READ_TIMEOUT_SHORT_NAME(),
+ Constants.CONNECTION_READ_TIMEOUT().getValue());
+ String tokenKey =
+ (String)
+ parms.getOrDefault(
+ Constants.AUTH_TOKEN_KEY_SHORT_NAME(),
Constants.AUTH_TOKEN_KEY().getValue());
+ String tokenValue =
+ (String)
+ parms.getOrDefault(
+ Constants.AUTH_TOKEN_VALUE_SHORT_NAME(),
Constants.AUTH_TOKEN_VALUE().getValue());
+
+ DWSClientConfig clientConfig =
+ ((DWSClientConfigBuilder)
+ (DWSClientConfigBuilder.newBuilder()
+ .addServerUrl(realUrl)
+ .connectionTimeout(connectTimeout)
+ .discoveryEnabled(false)
+ .discoveryFrequency(1, TimeUnit.MINUTES)
+ .loadbalancerEnabled(false)
+ .maxConnectionSize(maxConnection)
+ .retryEnabled(false)
+ .readTimeout(readTimeout)
+ .setAuthenticationStrategy(new
TokenAuthenticationStrategy())
+ .setAuthTokenKey(tokenKey)
+ .setAuthTokenValue(tokenValue)))
+ .setDWSVersion("v1")
+ .build();
+ return clientConfig;
+ }
+}
diff --git
a/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/constant/Constants.scala
b/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/constant/Constants.scala
new file mode 100644
index 000000000..5e61cc018
--- /dev/null
+++
b/linkis-public-enhancements/linkis-configuration/src/main/scala/org/apache/linkis/configuration/constant/Constants.scala
@@ -0,0 +1,49 @@
+/*
+ * 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.
+ */
+
+package org.apache.linkis.configuration.constant
+
+import org.apache.linkis.common.conf.CommonVars
+
+object Constants {
+
+ val LINKIS_API_VERSION: CommonVars[String] =
+ CommonVars[String]("linkis.configuration.linkisclient.api.version", "v1")
+
+ val AUTH_TOKEN_KEY: CommonVars[String] =
+ CommonVars[String]("linkis.configuration.linkisclient.auth.token.key",
"Validation-Code")
+
+ val AUTH_TOKEN_VALUE: CommonVars[String] =
+ CommonVars[String]("linkis.configuration.linkisclient.auth.token.value",
"BML-AUTH")
+
+ val CONNECTION_MAX_SIZE: CommonVars[Int] =
+ CommonVars[Int]("linkis.configuration.linkisclient.connection.max.size",
10)
+
+ val CONNECTION_TIMEOUT: CommonVars[Int] =
+ CommonVars[Int]("linkis.configuration.linkisclient.connection.timeout", 5
* 60 * 1000)
+
+ val CONNECTION_READ_TIMEOUT: CommonVars[Int] =
+
CommonVars[Int]("linkis.configuration.linkisclient.connection.read.timeout", 10
* 60 * 1000)
+
+ val AUTH_TOKEN_KEY_SHORT_NAME = "tokenKey"
+ val AUTH_TOKEN_VALUE_SHORT_NAME = "tokenValue"
+ val CONNECTION_MAX_SIZE_SHORT_NAME = "maxConnection"
+ val CONNECTION_TIMEOUT_SHORT_NAME = "connectTimeout"
+ val CONNECTION_READ_TIMEOUT_SHORT_NAME = "readTimeout"
+ val CLIENT_NAME_SHORT_NAME = "clientName"
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]