diff --git a/dss-apps/dss-apiservice-server/pom.xml b/dss-apps/dss-apiservice-server/pom.xml
new file mode 100644
index 0000000000..97f69346ba
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/pom.xml
@@ -0,0 +1,420 @@
+
+
+
+
+
+ dss
+ com.webank.wedatasphere.dss
+ 1.0.0
+ ../../pom.xml
+
+ 4.0.0
+
+ dss-apiservice-server
+
+
+
+ UTF-8
+ 2.16
+ 2.22.2
+ 2.22.2
+
+
+
+
+ com.webank.wedatasphere.dss
+ dss-common
+ ${dss.version}
+ provided
+
+
+ com.webank.wedatasphere.linkis
+ linkis-module
+ ${linkis.version}
+ provided
+
+
+ asm
+ org.ow2.asm
+
+
+ hk2-api
+ org.glassfish.hk2
+
+
+ jersey-common
+ org.glassfish.jersey.core
+
+
+ linkis-common
+ com.webank.wedatasphere.linkis
+
+
+
+
+ com.alibaba
+ fastjson
+ 1.2.70
+
+
+
+ org.glassfish.jersey.ext
+ jersey-bean-validation
+ ${jersey.version}
+ provided
+
+
+ javax.ws.rs-api
+ javax.ws.rs
+
+
+ hk2-locator
+ org.glassfish.hk2
+
+
+ hk2-api
+ org.glassfish.hk2
+
+
+ hibernate-validator
+ org.hibernate
+
+
+ jersey-server
+ org.glassfish.jersey.core
+
+
+
+
+
+ com.webank.wedatasphere.linkis
+ linkis-bml-client
+ ${linkis.version}
+
+
+ commons-beanutils
+ commons-beanutils
+
+
+ linkis-common
+ com.webank.wedatasphere.linkis
+
+
+ json4s-jackson_2.11
+ org.json4s
+
+
+
+
+ com.webank.wedatasphere.linkis
+ linkis-computation-client
+ ${linkis.version}
+
+
+ commons-beanutils
+ commons-beanutils
+
+
+ linkis-common
+ com.webank.wedatasphere.linkis
+
+
+
+
+ org.postgresql
+ postgresql
+ 42.2.12
+
+
+ com.webank.wedatasphere.linkis
+ linkis-mybatis
+ ${linkis.version}
+ provided
+
+
+ com.webank.wedatasphere.linkis
+ linkis-storage
+ ${linkis.version}
+ provided
+
+
+ linkis-common
+ com.webank.wedatasphere.linkis
+
+
+
+
+ com.webank.wedatasphere.linkis
+ linkis-common
+ ${linkis.version}
+ provided
+
+
+ com.webank.wedatasphere.linkis
+ linkis-rpc
+ ${linkis.version}
+ provided
+
+
+ archaius-core
+ com.netflix.archaius
+
+
+ slf4j-api
+ org.slf4j
+
+
+ spring-cloud-starter
+ org.springframework.cloud
+
+
+ spring-web
+ org.springframework
+
+
+
+
+ com.zaxxer
+ HikariCP
+ 3.4.1
+
+
+ slf4j-api
+ org.slf4j
+
+
+
+
+
+
+
+
+
+
+ hk2-api
+ org.glassfish.hk2
+ 2.4.0-b34
+
+
+
+
+
+
+
+
+ org.modelmapper
+ modelmapper
+ 0.7.5
+
+
+
+ io.jsonwebtoken
+ jjwt
+ 0.6.0
+
+
+ jackson-databind
+ com.fasterxml.jackson.core
+
+
+
+
+
+ org.hamcrest
+ hamcrest-all
+ 1.3
+ test
+
+
+
+
+ com.h2database
+ h2
+ 1.4.196
+ test
+
+
+
+ com.ninja-squad
+ DbSetup
+ 2.1.0
+ test
+
+
+ org.springframework.boot
+ spring-boot-starter-test
+ ${spring.boot.version}
+ test
+
+
+ spring-boot-autoconfigure
+ org.springframework.boot
+
+
+
+
+
+ junit
+ junit
+ 4.12
+ test
+
+
+ org.junit.platform
+ junit-platform-launcher
+ 1.5.2
+ test
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ xstream
+ com.thoughtworks.xstream
+ 1.4.11.1
+
+
+
+
+
+
+
+ maven-surefire-plugin
+ ${maven-surefire-plugin.version}
+
+
+ maven-failsafe-plugin
+ ${maven-failsafe-plugin.version}
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+
+
+
+ net.alchim31.maven
+ scala-maven-plugin
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ 2.3
+ false
+
+
+ make-assembly
+ package
+
+ single
+
+
+
+ src/main/assembly/distribution.xml
+
+
+
+
+
+ false
+ out
+ false
+ false
+
+ src/main/assembly/distribution.xml
+
+
+
+
+
+
+ src/main/java
+
+ **/*.xml
+
+
+
+
+
+
+
+
+
+
+
+
+ ${project.artifactId}-${project.version}
+
+
diff --git a/dss-apps/dss-apiservice-server/src/main/assembly/distribution.xml b/dss-apps/dss-apiservice-server/src/main/assembly/distribution.xml
new file mode 100644
index 0000000000..9882c22ece
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/assembly/distribution.xml
@@ -0,0 +1,44 @@
+
+
+
+ dss-apiService-server
+
+ dir
+
+ true
+ dss-apiservice-server
+
+
+
+
+
+ lib
+ true
+ true
+ false
+ true
+ true
+
+
+
+
+
+
+
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/action/ApiServiceGetAction.scala b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/action/ApiServiceGetAction.scala
new file mode 100644
index 0000000000..62353e7225
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/action/ApiServiceGetAction.scala
@@ -0,0 +1,29 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.action
+
+import com.webank.wedatasphere.linkis.httpclient.request.GetAction
+import com.webank.wedatasphere.linkis.ujes.client.request.UJESJobAction
+
+/**
+ * @author allenlliu
+ * @date 2020/09/14 10:32 AM
+ * @version 2.0.0
+ */
+class ApiServiceGetAction extends GetAction with UJESJobAction {
+ override def suffixURLs: Array[String] = Array("dss","framework","workspace", "getWorkspaceIdByUserName")
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/action/ResultSetDownloadAction.scala b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/action/ResultSetDownloadAction.scala
new file mode 100644
index 0000000000..25c9b75673
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/action/ResultSetDownloadAction.scala
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.action
+
+import com.webank.wedatasphere.linkis.httpclient.request.{DownloadAction, GetAction}
+import com.webank.wedatasphere.linkis.ujes.client.request.UJESJobAction
+
+import scala.tools.nsc.interpreter.InputStream
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ */
+
+class ResultSetDownloadAction extends GetAction with DownloadAction with UJESJobAction {
+
+ private var inputStream: InputStream = _
+
+ override def write(inputStream: InputStream): Unit = this.inputStream = inputStream
+
+ def getInputStream: InputStream = inputStream
+
+ override def suffixURLs: Array[String] = Array("filesystem", "resultsetToExcel")
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/action/ResultWorkspaceIds.scala b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/action/ResultWorkspaceIds.scala
new file mode 100644
index 0000000000..8ae4fa95f8
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/action/ResultWorkspaceIds.scala
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.action
+
+import com.webank.wedatasphere.linkis.httpclient.dws.annotation.DWSHttpMessageResult
+import com.webank.wedatasphere.linkis.httpclient.dws.response.DWSResult
+
+/**
+ * @author allenlliu
+ * @date 2020/09/14 11:44 AM
+ * @version 2.0.0
+ */
+
+@DWSHttpMessageResult("/api/rest_j/v\\d+/dss/framework/workspace/getWorkspaceIdByUserName")
+class ResultWorkspaceIds extends DWSResult{
+ var userWorkspaceIds:String = _
+ def getUserWorkspaceIds:String = this.userWorkspaceIds
+ def setUserWorkspaceIds(userWorkspaceIds:String):Unit = this.userWorkspaceIds = userWorkspaceIds
+}
\ No newline at end of file
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/ApiServiceJob.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/ApiServiceJob.java
new file mode 100644
index 0000000000..95ce75af59
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/ApiServiceJob.java
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.bo;
+
+import com.webank.wedatasphere.linkis.ujes.client.response.JobExecuteResult;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/09/03 07:28 PM
+ */
+public class ApiServiceJob {
+
+ private String submitUser;
+ private String proxyUser;
+ private JobExecuteResult jobExecuteResult;
+ public String getSubmitUser() {
+ return submitUser;
+ }
+
+ public void setSubmitUser(String submitUser) {
+ this.submitUser = submitUser;
+ }
+
+
+
+ public String getProxyUser() {
+ return proxyUser;
+ }
+
+ public void setProxyUser(String proxyUser) {
+ this.proxyUser = proxyUser;
+ }
+ public JobExecuteResult getJobExecuteResult() {
+ return jobExecuteResult;
+ }
+
+ public void setJobExecuteResult(JobExecuteResult jobExecuteResult) {
+ this.jobExecuteResult = jobExecuteResult;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/ApiServiceQuery.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/ApiServiceQuery.java
new file mode 100644
index 0000000000..ff5148bb46
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/ApiServiceQuery.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.bo;
+
+
+/**
+ * query
+ *
+ * @author zhulixin
+ */
+public class ApiServiceQuery {
+
+ /**
+ * 服务名称
+ */
+ private String name;
+
+ /**
+ * 标签
+ */
+ private String tag;
+
+ /**
+ * 状态
+ */
+ private Integer status;
+
+ /**
+ * api创建者
+ */
+ private String creator;
+
+ private int currentPage;
+
+ private int pageSize;
+
+ public int getWorkspaceId() {
+ return workspaceId;
+ }
+
+ public void setWorkspaceId(int workspaceId) {
+ this.workspaceId = workspaceId;
+ }
+
+ private int workspaceId;
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ private String userName;
+
+ public ApiServiceQuery(String userName,String name, String tag, Integer status, String creator) {
+ this.userName= userName;
+ this.name = name;
+ this.tag = tag;
+ this.status = status;
+ this.creator = creator;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getTag() {
+ return tag;
+ }
+
+ public void setTag(String tag) {
+ this.tag = tag;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+
+ public String getCreator() {
+ return creator;
+ }
+
+ public void setCreator(String creator) {
+ this.creator = creator;
+ }
+
+ public int getCurrentPage() {
+ return currentPage;
+ }
+
+ public void setCurrentPage(int currentPage) {
+ this.currentPage = currentPage;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public void setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/ApiServiceToken.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/ApiServiceToken.java
new file mode 100644
index 0000000000..c4b66f9c9c
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/ApiServiceToken.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.bo;
+
+
+
+import java.util.Date;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/11 08:38 PM
+ */
+
+public class ApiServiceToken {
+
+ private String applyUser;
+ private Date applyTime;
+ private Long apiServiceId;
+ private String publisher;
+
+ public String getPublisher() {
+ return publisher;
+ }
+
+ public void setPublisher(String publisher) {
+ this.publisher = publisher;
+ }
+
+ public Long getApiServiceId() {
+ return apiServiceId;
+ }
+
+ public void setApiServiceId(Long apiServiceId) {
+ this.apiServiceId = apiServiceId;
+ }
+
+ public Date getApplyTime() {
+ return applyTime;
+ }
+
+ public void setApplyTime(Date applyTime) {
+ this.applyTime = applyTime;
+ }
+
+ public String getApplyUser() {
+ return applyUser;
+ }
+
+ public void setApplyUser(String applyUser) {
+ this.applyUser = applyUser;
+ }
+
+
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/DirFileTree.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/DirFileTree.java
new file mode 100644
index 0000000000..33b891234d
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/DirFileTree.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.bo;
+
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/09/03 05:29 PM
+ */
+public class DirFileTree {
+
+ private String name;
+ private String path;
+ private HashMap properties;
+ private List children;
+ private Boolean isLeaf = false;
+ private String parentPath;
+
+ public Boolean getIsLeaf() {
+ return isLeaf;
+ }
+
+ public void setIsLeaf(Boolean isLeaf) {
+ this.isLeaf = isLeaf;
+ }
+
+ public String getParentPath() {
+ return parentPath;
+ }
+
+ public void setParentPath(String parentPath) {
+ this.parentPath = parentPath;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public HashMap getProperties() {
+ return properties;
+ }
+
+ public void setProperties(HashMap properties) {
+ this.properties = properties;
+ }
+
+ public List getChildren() {
+ return children;
+ }
+
+ public void setChildren(List children) {
+ this.children = children;
+ }
+}
\ No newline at end of file
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/LinkisExecuteResult.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/LinkisExecuteResult.java
new file mode 100644
index 0000000000..910d4bc9f3
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/LinkisExecuteResult.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.bo;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/13 11:39 AM
+ */
+public class LinkisExecuteResult {
+
+ public LinkisExecuteResult(String taskId,String execId){
+ this.taskId = taskId;
+ this.execId = execId;
+ }
+
+ public String getTaskId() {
+ return taskId;
+ }
+
+ public void setTaskId(String taskId) {
+ this.taskId = taskId;
+ }
+
+ private String taskId;
+
+ public String getExecId() {
+ return execId;
+ }
+
+ public void setExecId(String execId) {
+ this.execId = execId;
+ }
+
+ private String execId;
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/QueryRequest.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/QueryRequest.java
new file mode 100644
index 0000000000..46acb97d90
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/QueryRequest.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.bo;
+
+import java.util.Map;
+
+/**
+ * 接口调用request
+ *
+ * @author lidongzhang
+ */
+public class QueryRequest {
+ /**
+ * 模块名,也是登录用户名、密码
+ */
+ private String moduleName;
+
+ /**
+ * 调用参数
+ */
+ private Map params;
+
+ public Map getParams() {
+ return params;
+ }
+
+ public void setParams(Map params) {
+ this.params = params;
+ }
+
+ public String getModuleName() {
+ return moduleName;
+ }
+
+ public void setModuleName(String moduleName) {
+ this.moduleName = moduleName;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/TokenQuery.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/TokenQuery.java
new file mode 100644
index 0000000000..6cede52470
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/TokenQuery.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.bo;
+
+
+import java.util.Date;
+
+public class TokenQuery {
+ private Long apiId;
+ private String user;
+ private Integer status;
+
+ private String startDate;
+ private String endDate;
+
+ private int currentPage;
+
+ private int pageSize;
+
+ public String getCreator() {
+ return creator;
+ }
+
+ public void setCreator(String creator) {
+ this.creator = creator;
+ }
+
+ private String creator;
+
+
+ public TokenQuery(Long apiId, String user, Integer status) {
+ this.apiId = apiId;
+ this.user = user;
+ this.status = status;
+ }
+
+ public TokenQuery(Long apiId, String user, Integer status, String startDate, String endDate) {
+ this.apiId = apiId;
+ this.user = user;
+ this.status = status;
+ this.startDate = startDate;
+ this.endDate = endDate;
+ }
+
+ public TokenQuery() {
+ }
+
+ public String getStartDate() {
+ return startDate;
+ }
+
+ public void setStartDate(String startDate) {
+ this.startDate = startDate;
+ }
+
+ public String getEndDate() {
+ return endDate;
+ }
+
+ public void setEndDate(String endDate) {
+ this.endDate = endDate;
+ }
+
+ public int getCurrentPage() {
+ return currentPage;
+ }
+
+ public void setCurrentPage(int currentPage) {
+ this.currentPage = currentPage;
+ }
+
+ public int getPageSize() {
+ return pageSize;
+ }
+
+ public void setPageSize(int pageSize) {
+ this.pageSize = pageSize;
+ }
+
+ public Long getApiId() {
+ return apiId;
+ }
+
+ public void setApiId(Long apiId) {
+ this.apiId = apiId;
+ }
+
+ public String getUser() {
+ return user;
+ }
+
+ public void setUser(String user) {
+ this.user = user;
+ }
+
+ public Integer getStatus() {
+ return status;
+ }
+
+ public void setStatus(Integer status) {
+ this.status = status;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/VariableString.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/VariableString.java
new file mode 100644
index 0000000000..21dce95a6e
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/bo/VariableString.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.bo;
+
+/**
+ * VariableString
+ *
+ * @author lidongzhang
+ */
+public class VariableString {
+ private String path;
+
+ public VariableString(String unparsedPath) {
+ this.path = unparsedPath;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/config/ApiServiceConfiguration.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/config/ApiServiceConfiguration.java
new file mode 100644
index 0000000000..feae84b499
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/config/ApiServiceConfiguration.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.config;
+
+import com.webank.wedatasphere.linkis.common.conf.CommonVars;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/12 03:46 PM
+ */
+public class ApiServiceConfiguration {
+ public final static CommonVars LINKIS_AUTHOR_USER_TOKEN = CommonVars.apply("wds.linkis.client.api.service.author.user.token","WS-AUTH");
+ public final static CommonVars LINKIS_ADMIN_USER = CommonVars.apply("wds.linkis.client.api.service.adminuser","ws");
+
+ public final static CommonVars LINKIS_CONNECTION_TIMEOUT = CommonVars.apply("wds.linkis.flow.connection.timeout",30000);
+ public final static CommonVars LINKIS_API_VERSION = CommonVars.apply("wds.linkis.server.version","v1");
+
+ public final static CommonVars API_SERVICE_TOKEN_KEY = CommonVars.apply("wds.dss.api.service.token.key","ApiServiceToken");
+
+
+ public final static CommonVars DSS_API_TOKEN_SECRET_ID = CommonVars.apply("wds.dss.api.service.secret", "DSSSECRETTEST001002");
+
+ public final static CommonVars LINKIS_JOB_REQUEST_STATUS_TIME = CommonVars.apply("wds.linkis.job.status.timeout",3000);
+
+ public final static CommonVars LOG_ARRAY_LEN = CommonVars.apply("wds.linkis.log.array.len",4);
+
+ public final static CommonVars RESULT_PRINT_SIZE = CommonVars.apply("wds.linkis.result.print.size",10);
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ApiCommonConstant.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ApiCommonConstant.java
new file mode 100644
index 0000000000..8c49f7a423
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ApiCommonConstant.java
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.constant;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/20 11:47 AM
+ */
+public class ApiCommonConstant {
+ public static final String DEFAULT_APPROVAL_NO="0001";
+ public static final Integer API_DELETE_STATUS=2;
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ApprovalStatus.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ApprovalStatus.java
new file mode 100644
index 0000000000..102bf71d07
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ApprovalStatus.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.constant;
+
+/**
+ * @author: jinyangrao
+ */
+public enum ApprovalStatus {
+ INIT("init", 0),
+ APPLYING("apply", 1),
+ SUCCESS("success", 2),
+ FAIELD("failed", 3);
+
+ String key;
+ int value;
+
+ ApprovalStatus(String key, int value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public int getValue() {
+ return value;
+ }
+
+ public void setValue(int value) {
+ this.value = value;
+ }
+}
\ No newline at end of file
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ParamType.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ParamType.java
new file mode 100644
index 0000000000..13a7709180
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ParamType.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.constant;
+
+/**
+ * ParamType
+ *
+ * @author lidongzhang
+ */
+public class ParamType {
+ public static final String number = "2";
+
+ public static final String array = "4";
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ParamTypeEnum.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ParamTypeEnum.java
new file mode 100644
index 0000000000..7f20fdbd73
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/ParamTypeEnum.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.constant;
+
+/**
+ * @author chongchuanbing
+ */
+public enum ParamTypeEnum {
+
+ STRING(1, "String"),
+
+ NUMBER(2, "Number"),
+
+ DATE(3, "Date"),
+
+ ARRAY(4, "Array");
+
+ private Integer index;
+ private String name;
+
+ ParamTypeEnum(Integer index, String name) {
+ this.index = index;
+ this.name = name;
+ }
+
+ public static ParamTypeEnum getEnum(Integer index) {
+ if (index == null) {
+ return STRING;
+ }
+ for (ParamTypeEnum statusEnum : values()) {
+ if (statusEnum.getIndex().equals(index)) {
+ return statusEnum;
+ }
+ }
+ return STRING;
+ }
+
+ public Integer getIndex() {
+ return this.index;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/RequireEnum.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/RequireEnum.java
new file mode 100644
index 0000000000..8d0cc3e993
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/RequireEnum.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.constant;
+
+/**
+ * @author chongchuanbing
+ */
+public enum RequireEnum {
+
+ YES(1, "是"),
+
+ NO(0, "否");
+
+ private Integer index;
+ private String name;
+
+ RequireEnum(Integer index, String name) {
+ this.index = index;
+ this.name = name;
+ }
+
+ public static RequireEnum getEnum(Integer index) {
+ if (index == null) {
+ return NO;
+ }
+ for (RequireEnum statusEnum : values()) {
+ if (statusEnum.getIndex().equals(index)) {
+ return statusEnum;
+ }
+ }
+ return NO;
+ }
+
+ public Integer getIndex() {
+ return this.index;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/SQLMetadataInfoCheckStatus.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/SQLMetadataInfoCheckStatus.java
new file mode 100644
index 0000000000..11c7320419
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/SQLMetadataInfoCheckStatus.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.constant;
+
+import com.webank.wedatasphere.dss.apiservice.core.datamap.DataMapStatus;
+
+/**
+ * @author: jinyangrao
+ */
+public enum SQLMetadataInfoCheckStatus {
+ LEGAL(0, "该SQL查询合法"), ILLEGALSQL(1,"不支持无库表信息的SQL查询");
+
+ int index;
+ String desc;
+
+ SQLMetadataInfoCheckStatus(int index, String desc) {
+ this.index = index;
+ this.desc = desc;
+ }
+
+ public String getDescByIndex(int index) {
+ for (SQLMetadataInfoCheckStatus item : values()) {
+ if (item.getIndex() == index) {
+ return item.getDesc();
+ }
+ }
+ return null;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/SaveTokenEnum.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/SaveTokenEnum.java
new file mode 100644
index 0000000000..057dfa5a2c
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/SaveTokenEnum.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.constant;
+
+/**
+ * @author: jinyangrao
+ */
+public enum SaveTokenEnum {
+ SUCCESS(1, "success"), FAILED(2, "failed"), DUPLICATE(3, "duplicate");
+
+ int index;
+ String value;
+ SaveTokenEnum(int index, String value) {
+ this.index = index;
+ this.value = value;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/StatusEnum.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/StatusEnum.java
new file mode 100644
index 0000000000..bb4b8c2656
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/constant/StatusEnum.java
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.constant;
+
+/**
+ * @author chongchuanbing
+ */
+public enum StatusEnum {
+
+ DISABLE(0, "停止"),
+
+ ENABLE(1, "运行中");
+
+ private Integer index;
+ private String name;
+
+ StatusEnum(Integer index, String name) {
+ this.index = index;
+ this.name = name;
+ }
+
+ public static StatusEnum getEnum(Integer index) {
+ if (index == null) {
+ return null;
+ }
+ for (StatusEnum statusEnum : values()) {
+ if (statusEnum.getIndex().equals(index)) {
+ return statusEnum;
+ }
+ }
+ return null;
+ }
+
+ public Integer getIndex() {
+ return this.index;
+ }
+
+ public String getName() {
+ return this.name;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceAccessDao.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceAccessDao.java
new file mode 100644
index 0000000000..11229d44ec
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceAccessDao.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.dao;
+
+import com.webank.wedatasphere.dss.apiservice.core.vo.ApiAccessVo;
+
+/**
+ * @author allenlliu
+ * @date 2020/11/11 10:25
+ */
+public interface ApiServiceAccessDao {
+ void addAccessRecord(ApiAccessVo apiAccessVo);
+
+ ApiAccessVo queryByVersionId(Long versionId);
+
+ ApiAccessVo queryByApiId(Long apiServiceId);
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceApprovalDao.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceApprovalDao.java
new file mode 100644
index 0000000000..3293a159da
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceApprovalDao.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.dao;
+
+
+import com.webank.wedatasphere.dss.apiservice.core.vo.ApprovalVo;
+import org.apache.ibatis.annotations.Param;
+
+/**
+ * @author: jinyangrao
+ * @date: 2020-08-26 18:03:34
+ */
+public interface ApiServiceApprovalDao {
+
+ /**
+ * 新增一条审批单
+ */
+ void insert(ApprovalVo approvalVo);
+
+ /**
+ * 查询审批单
+ * */
+ ApprovalVo queryByApprovalNo(@Param("approvalNo") String approvalNo);
+
+ /**
+ * set status to success
+ * */
+ void setApprovalStatusSuccess(@Param("approvalNo") String approvalNo);
+
+ /**
+ * set status to failed
+ * */
+ void setApprovalStatusFailed(@Param("approvalNo") String approvalNo);
+
+ /**
+ * set status to init
+ * */
+ void setApprovalStatusInit(@Param("approvalNo") String approvalNo);
+
+ /**
+ * set status to applying
+ * */
+ void setApprovalStatusApplying(@Param("approvalNo") String approvalNo);
+
+ /**
+ * update status
+ * */
+ void updateApprovalStatus(@Param("approvalNo") String approvalNo, @Param("status") Integer status);
+
+
+ /**
+ * delete approval
+ * */
+ void deleteApproval(@Param("approvalNo") String approvalNo);
+
+ /**
+ * 通过版本ID查询审批单
+ * */
+ ApprovalVo queryByVersionId(@Param("apiVersionId") Long apiVersionId);
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceDao.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceDao.java
new file mode 100644
index 0000000000..c5f6de7090
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceDao.java
@@ -0,0 +1,83 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.dao;
+
+
+import com.webank.wedatasphere.dss.apiservice.core.bo.ApiServiceQuery;
+import com.webank.wedatasphere.dss.apiservice.core.vo.ApiServiceVo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @author jinyangrao
+ */
+public interface ApiServiceDao {
+
+ /**
+ * Insert
+ */
+ void insert(ApiServiceVo apiServiceVo);
+
+ /**
+ * Update
+ */
+ void update(ApiServiceVo apiServiceVo);
+
+
+ void updateToTarget(ApiServiceVo apiServiceVo);
+
+ /**
+ * query
+ */
+ List query(ApiServiceQuery query);
+
+ /**
+ * query
+ */
+
+ List queryByScriptPath(@Param("scriptPath") String scriptPath);
+
+ /**
+ * query
+ */
+ ApiServiceVo queryByPath(String path);
+
+ /**
+ * query api path count
+ */
+ Integer queryCountByPath(@Param("scriptPath") String scriptPath, @Param("path") String path);
+
+ /**
+ * query api name
+ */
+ Integer queryCountByName(String name);
+
+ Integer enableApi(@Param("id") Long id);
+
+ Integer disableApi(@Param("id") Long id);
+
+ Integer deleteApi(@Param("id") Long id);
+
+ List queryAllTags(@Param("userName")String userName,@Param("workspaceId")Integer workspaceId);
+
+ ApiServiceVo queryById(@Param("id") Long id);
+
+ List queryByWorkspaceId(@Param("workspaceId") Integer workspaceId, @Param("userName") String userName);
+
+ Integer updateApiServiceComment(@Param("id") Long id, @Param("comment") String comment);
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceParamDao.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceParamDao.java
new file mode 100644
index 0000000000..68028347c3
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceParamDao.java
@@ -0,0 +1,61 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.dao;
+
+
+import com.webank.wedatasphere.dss.apiservice.core.vo.ParamVo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * dao
+ *
+ * @author zhulixin
+ */
+public interface ApiServiceParamDao {
+
+ /**
+ * insert
+ *
+ * @param param
+ * @return
+ */
+ int insert(ParamVo param);
+
+ /**
+ * Update
+ *
+ * @param param
+ */
+ void update(ParamVo param);
+
+ /**
+ * query
+ */
+// List queryByConfigIdAndVersion(@Param("configId") Long configId, @Param("version") String version);
+
+ List queryByVersionId(@Param("apiVersionId") Long apiVersionId);
+
+ /**
+ * query a line by id
+ * @param paramId
+ * @return paramVo
+ * */
+ int queryById(@Param("paramId") Long paramId);
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceTokenManagerDao.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceTokenManagerDao.java
new file mode 100644
index 0000000000..eb1ea3d98f
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceTokenManagerDao.java
@@ -0,0 +1,117 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.dao;
+
+import com.webank.wedatasphere.dss.apiservice.core.vo.TokenManagerVo;
+import com.webank.wedatasphere.dss.apiservice.core.bo.TokenQuery;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @author jinyangrao
+ */
+public interface ApiServiceTokenManagerDao {
+
+ /**
+ * insert a token
+ * */
+ void insert(TokenManagerVo tokenManagerVo);
+
+ /**
+ * insert batch token
+ * */
+ void insertList(List tokenManagerVos);
+
+
+ /**
+ * 多条记录需要去重返回最新授权的
+ * @param userName
+ * @return
+ */
+ List queryByApplyUser(String userName);
+
+
+ List queryByApplyUserAndServiceId(@Param("userName") String userName, @Param("serviceId") Long serviceId);
+
+ List queryByApplyUserAndVersionId(@Param("userName") String userName, @Param("apiVersionId") Long apiVersionId);
+
+
+
+ /**
+ * query
+ * */
+ List query(TokenQuery tokenQuery);
+
+ /**
+ * query token by token id
+ * */
+ TokenManagerVo queryTokenById(@Param("id") Long tokenId);
+
+ /**
+ * query token by api service id
+ * */
+ List queryTokenByApiServiceId(@Param("api_id") Long apiServiceId);
+
+ /**
+ * query token avoid submit again
+ * */
+ int queryApprovalNo(@Param("approvalNo") String approvalNo);
+
+ /**
+ * query tokens according to status
+ * */
+ List queryTokenByStatus(@Param("status") Integer status);
+
+ /**
+ * disable token status
+ * */
+ void disableTokenStatus(@Param("id") Long id);
+
+
+ /**
+ * disable token status
+ * */
+ void disableTokenStatusByVersionId(@Param("apiVersionId") Long apiVersionId);
+
+
+ /**
+ * disable token status
+ * */
+ void disableTokenStatusByApiId(@Param("apiId") Long apiId);
+
+ /**
+ * enable token status
+ * */
+ void enableTokenStatus(@Param("id") Long id);
+
+ void enableTokenStatusByVersionId(@Param("apiVersionId") Long apiVersionId);
+
+ void enableTokenStatusByApiId(@Param("apiId") Long apiId);
+
+
+ /**
+ * delete token
+ * */
+ void deleteTokenById(@Param("id") Long tokenId);
+
+ /**
+ * update token status
+ * */
+// void updateTokenStatus(@Param(id) Long tokenId, String status);
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceVersionDao.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceVersionDao.java
new file mode 100644
index 0000000000..eef5041fc7
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/ApiServiceVersionDao.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.dao;
+
+
+import com.webank.wedatasphere.dss.apiservice.core.vo.ApiVersionVo;
+import org.apache.ibatis.annotations.Param;
+
+import java.util.List;
+
+/**
+ * @author jinyangrao
+ */
+public interface ApiServiceVersionDao {
+
+ /**
+ * inster apiversionVo
+ * */
+ void insert(ApiVersionVo apiVersionVo);
+
+ /**
+ * query version
+ * */
+ ApiVersionVo queryApiVersionByVersionId(@Param("id") Long apiVersionId);
+
+ List queryApiVersionByApiServiceId(@Param("api_id") Long apiServiceId);
+
+ /**
+ * update api version
+ * */
+ void updateApiVersionStatusById(@Param("id") Long apiVersionId, @Param("status") int status);
+
+ void updateApiVersionStatus(ApiVersionVo apiVersionVo);
+
+ /**
+ * update all api version status by service id
+ * */
+ void updateAllApiVersionStatusByApiServiceId(@Param("api_id") Long apiServiceId, @Param("status") int status);
+
+ void disableApiVersionStatusByApiId(@Param("api_id") Long apiServiceId);
+
+ /**
+ * delete api version
+ * */
+ void deleteApiVersionById(@Param("id") Long apiVersionId);
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceAccessMapper.xml b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceAccessMapper.xml
new file mode 100644
index 0000000000..ecda53d982
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceAccessMapper.xml
@@ -0,0 +1,66 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `login_user`,`api_name`,`api_id`,`api_version_id`, `api_publisher`, `access_time`, `execute_user`
+
+
+
+ `id`,`login_user`,`api_name`,`api_id`,`api_version_id`, `api_publisher`, `access_time`, `execute_user`
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceApiVersionMapper.xml b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceApiVersionMapper.xml
new file mode 100644
index 0000000000..48460f34b5
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceApiVersionMapper.xml
@@ -0,0 +1,109 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `api_id`,`version`,`bml_resource_id`,`bml_version`,`source`,`creator`,`create_time`,`status`,
+ `metadata_info`, `auth_id`
+
+
+
+ `id`,`api_id`,`version`,`bml_resource_id`,`bml_version`,`source`,`creator`,`create_time`,`status`,
+ `metadata_info`, `auth_id`
+
+
+
+
+
+
+
+
+
+
+
+
+
+ UPDATE `dss_apiservice_api_version`
+ SET `status` = #{status}
+ WHERE id = #{id}
+
+
+
+ UPDATE `dss_apiservice_api_version`
+ SET `status` = 0
+ WHERE
+ api_id = #{api_id}
+
+
+
+ UPDATE `dss_apiservice_api_version`
+ SET `status` = #{status}
+ WHERE id = #{id}
+
+
+
+ UPDATE `dss_apiservice_api_version`
+ SET `status` = #{status}
+ WHERE api_id = #{api_id}
+
+
+
+
+ DELETE FROM
+ `dss_apiservice_api_version`
+ WHERE
+ id = #{id}
+
+
+
+
\ No newline at end of file
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceApprovalMapper.xml b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceApprovalMapper.xml
new file mode 100644
index 0000000000..95861ee906
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceApprovalMapper.xml
@@ -0,0 +1,107 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `api_id`, `api_version_id`, `approval_name`, `apply_user`, `execute_user`, `creator`,
+ `status`, `create_time`, `update_time`, `approval_no`
+
+
+
+ `id`, `api_version_id`, `api_id`, `approval_name`, `apply_user`, `execute_user`, `creator`,
+ `status`, `create_time`, `update_time`, `approval_no`
+
+
+
+
+
+
+
+
+
+
+
+ UPDATE `dss_apiservice_approval`
+ SET `status` = 3
+ WHERE `approval_no` = #{approvalNo}
+
+
+
+ UPDATE `dss_apiservice_approval`
+ SET `status` = 4
+ WHERE `approval_no` = #{approvalNo}
+
+
+
+ UPDATE `dss_apiservice_approval`
+ SET `status` = 1
+ WHERE `approval_no` = #{approvalNo}
+
+
+
+ UPDATE `dss_apiservice_approval`
+ SET `status` = 2
+ WHERE `approval_no` = #{approvalNo}
+
+
+
+ UPDATE `dss_apiservice_approval`
+ SET `status` = #{status}
+ WHERE `approval_no` = #{approvalNo}
+
+
+
+ DELETE FROM
+ `dss_apiservice_approval`
+ WHERE `approval_no` = #{approvalNo}
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceMapper.xml b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceMapper.xml
new file mode 100644
index 0000000000..34d6ab3026
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceMapper.xml
@@ -0,0 +1,297 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `name`,`alias_name`, `path`,`protocol`,`method`,`tag`, `scope`,`description`,`status`,`type`,`run_type`,`create_time`,
+ `modify_time`,`creator`,`modifier`,`script_path`,`workspaceID`,`api_comment`
+
+
+
+ `id`, `alias_name`, `name`,`path`,`protocol`,`method`, `tag`, `scope`,`description`,`status`,`type`,`run_type`,`create_time`,
+ `modify_time`,`creator`,`modifier`,`script_path`,`workspaceID`,`api_comment`
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `id` = #{id}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `id` = #{id}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceParamMapper.xml b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceParamMapper.xml
new file mode 100644
index 0000000000..e1b4490323
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceParamMapper.xml
@@ -0,0 +1,98 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `api_version_id`,`name`,`type`,`required`,`description`, `display_name`, `default_value`, `details`
+
+
+
+ `id`, `api_version_id`, `name`,`type`,`required`,`description`, `display_name`, `default_value`, `details`
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `id` = #{id}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceTokenManagerMapper.xml b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceTokenManagerMapper.xml
new file mode 100644
index 0000000000..1ee6c7399b
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/dao/mapper/ApiServiceTokenManagerMapper.xml
@@ -0,0 +1,245 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ `api_id`,`api_version_id`,`publisher`,`user`,`apply_time`,`duration`,
+ `reason`,`ip_whitelist`,`status`,`caller`,`access_limit`,`token`,`apply_source`
+
+
+
+ `id`, `api_version_id`,`api_id`,`publisher`,`user`,`apply_time`,`duration`,
+ `reason`,`ip_whitelist`,`status`,`caller`,`access_limit`,`token`,`apply_source`
+
+
+
+ `id`, `api_version_id`,`api_id`,`publisher`,`user`,`apply_time`,`duration`,
+ `reason`,`ip_whitelist`,`status`,`caller`,`access_limit`,`apply_source`
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ (#{item.apiId},#{item.apiVersionId}, #{item.publisher}, #{item.user}, #{item.applyTime},
+ #{item.duration}, #{item.reason}, #{item.ipWhitelist}, #{item.status},
+ #{item.caller}, #{item.accessLimit}, #{item.token}, #{item.applySource})
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ UPDATE `dss_apiservice_token_manager`
+ SET `status` = 1
+ WHERE `id` = #{id}
+
+
+
+ UPDATE `dss_apiservice_token_manager`
+ SET `status` = 0
+ WHERE `id` = #{id}
+
+
+
+ UPDATE `dss_apiservice_token_manager`
+ SET `status` = 0
+ WHERE `api_version_id` = #{apiVersionId}
+
+
+
+
+ UPDATE `dss_apiservice_token_manager`
+ SET `status` = 1
+ WHERE `api_version_id` = #{apiVersionId}
+
+
+
+
+
+
+ UPDATE `dss_apiservice_token_manager`
+ SET `status` = 0
+ WHERE `api_id` = #{apiId}
+
+
+
+
+ UPDATE `dss_apiservice_token_manager`
+ SET `status` = 1
+ WHERE `api_id` = #{apiId}
+
+
+
+ DELETE FROM
+ `dss_apiservice_token_manager`
+ WHERE
+ id = #{id}
+
+
+
\ No newline at end of file
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/datamap/DataMapStatus.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/datamap/DataMapStatus.java
new file mode 100644
index 0000000000..f05fd9b53c
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/datamap/DataMapStatus.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.datamap;
+
+import com.webank.wedatasphere.dss.apiservice.core.constant.ParamTypeEnum;
+
+/**
+ * created by cooperyang on 2020/8/27
+ * Description:
+ */
+public enum DataMapStatus {
+ /**
+ * datamap审批单的状态
+ */
+ INITED(1, "inited", "提单成功"),
+ APPROVING(2, "approving", "审批中"),
+ SUCCESS(3, "success", "审批通过"),
+ FAILED(4, "failed", "审批不通过"),
+ REJECT(5, "reject", "审批驳回");
+
+ private DataMapStatus(int index, String value, String desc) {
+ this.index = index;
+ this.value = value;
+ this.desc = desc;
+ }
+
+ private int index;
+ private String value;
+ private String desc;
+
+
+ public static String getDescByIndex(int index) {
+ for (DataMapStatus dataMapStatus : values()) {
+ if (dataMapStatus.getIndex() == index) {
+ return dataMapStatus.desc;
+ }
+ }
+ return INITED.desc;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public void setIndex(int index) {
+ this.index = index;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getDesc() {
+ return desc;
+ }
+
+ public void setDesc(String desc) {
+ this.desc = desc;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/datamap/UUIDGenerator.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/datamap/UUIDGenerator.java
new file mode 100644
index 0000000000..2de875f5b8
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/datamap/UUIDGenerator.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.datamap;
+
+import java.util.UUID;
+
+/**
+ * @author: jinyangrao
+ */
+public class UUIDGenerator {
+
+ /**
+ * 生成唯一标识uuid
+ * */
+ public static String genUUID() {
+ String uuid = UUID.randomUUID().toString();
+ return uuid;
+ }
+}
\ No newline at end of file
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiExecuteException.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiExecuteException.java
new file mode 100644
index 0000000000..9996744cba
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiExecuteException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.exception;
+
+import com.webank.wedatasphere.linkis.common.exception.ErrorException;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/31 02:31 PM
+ */
+public class ApiExecuteException extends ErrorException {
+
+ public ApiExecuteException(int errCode, String desc) {
+ super(errCode, desc);
+ }
+
+ public ApiExecuteException(int errCode, String desc, String ip, int port, String serviceKind) {
+ super(errCode, desc, ip, port, serviceKind);
+ }
+ }
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiServiceQueryException.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiServiceQueryException.java
new file mode 100644
index 0000000000..59b5aebbcb
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiServiceQueryException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.exception;
+
+import com.webank.wedatasphere.linkis.common.exception.ErrorException;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/26 07:51 PM
+ */
+public class ApiServiceQueryException extends ErrorException {
+
+ public ApiServiceQueryException(int errCode, String desc) {
+ super(errCode, desc);
+ }
+
+ public ApiServiceQueryException(int errCode, String desc, String ip, int port, String serviceKind) {
+ super(errCode, desc, ip, port, serviceKind);
+ }
+}
\ No newline at end of file
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiServiceRuntimeException.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiServiceRuntimeException.java
new file mode 100644
index 0000000000..b9b428b890
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiServiceRuntimeException.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.exception;
+
+/**
+ * OneserviceRuntimeException
+ *
+ * @author lidongzhang
+ */
+public class ApiServiceRuntimeException extends RuntimeException {
+
+ public ApiServiceRuntimeException(String message) {
+ super(message);
+ }
+
+ public ApiServiceRuntimeException(String message, Throwable cause) {
+ super(message, cause);
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiServiceTokenException.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiServiceTokenException.java
new file mode 100644
index 0000000000..bb7619bc0a
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/ApiServiceTokenException.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.exception;
+
+import com.webank.wedatasphere.linkis.common.exception.ErrorException;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/14 04:22 PM
+ */
+public class ApiServiceTokenException extends ErrorException {
+
+ public ApiServiceTokenException(int errCode, String desc) {
+ super(errCode, desc);
+ }
+
+ public ApiServiceTokenException(int errCode, String desc, String ip, int port, String serviceKind) {
+ super(errCode, desc, ip, port, serviceKind);
+ }
+ }
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/AssertException.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/AssertException.java
new file mode 100644
index 0000000000..394474b915
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/AssertException.java
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.exception;
+
+/**
+ * AssertException
+ *
+ * @author lidongzhang
+ */
+public class AssertException extends ApiServiceRuntimeException {
+
+ public AssertException(String message) {
+ super(message);
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/BeanValidationExceptionMapper.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/BeanValidationExceptionMapper.java
new file mode 100644
index 0000000000..0f12126c6f
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/exception/BeanValidationExceptionMapper.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.exception;
+
+import com.webank.wedatasphere.linkis.server.Message;
+
+import javax.validation.ConstraintViolationException;
+import javax.validation.ValidationException;
+import javax.ws.rs.core.Response;
+import javax.ws.rs.ext.ExceptionMapper;
+import javax.ws.rs.ext.Provider;
+
+/**
+ * Map bean validation exception to response
+ * @author liaoyt
+ * 2020/02/11
+ */
+@Provider
+public class BeanValidationExceptionMapper implements ExceptionMapper {
+ @Override
+ public Response toResponse(ValidationException exception) {
+ StringBuilder stringBuilder = new StringBuilder();
+ ((ConstraintViolationException)exception)
+ .getConstraintViolations().forEach(constraintViolation -> stringBuilder.append(constraintViolation.getMessage()).append(";"));
+ Message message = Message.error("Bean validation error[实例校验出错], detail:" + stringBuilder.toString());
+ return Message.messageToResponse(message);
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/ApiServiceExecuteJob.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/ApiServiceExecuteJob.java
new file mode 100644
index 0000000000..1b1e3896c1
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/ApiServiceExecuteJob.java
@@ -0,0 +1,64 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.execute;
+
+import com.webank.wedatasphere.linkis.ujes.client.response.JobExecuteResult;
+
+import java.util.Map;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/12 09:01 PM
+ */
+public interface ApiServiceExecuteJob {
+ String getCode();
+
+ void setCode(String code);
+
+ String getEngineType();
+
+ void setEngineType(String engineType);
+
+ String getRunType();
+
+ void setRunType(String runType);
+
+ String getUser();
+
+ void setUser(String user);
+
+ String getJobName();
+
+ Map getParams();
+
+ void setParams(Map params);
+
+ Map getRuntimeParams();
+ void setRuntimeParams(Map runtimeParams);
+
+ JobExecuteResult getJobExecuteResult();
+
+ void setJobExecuteResult(JobExecuteResult jobExecuteResult);
+
+ Map getJobProps();
+
+ void setJobProps(Map jobProps);
+
+ String getScriptPath();
+ void setScriptePath(String path);
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/DefaultApiServiceJob.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/DefaultApiServiceJob.java
new file mode 100644
index 0000000000..6d11d4197b
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/DefaultApiServiceJob.java
@@ -0,0 +1,145 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.execute;
+
+import com.webank.wedatasphere.linkis.ujes.client.request.JobExecuteAction;
+import com.webank.wedatasphere.linkis.ujes.client.response.JobExecuteResult;
+
+import java.util.Map;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/12 09:06 PM
+ */
+public class DefaultApiServiceJob implements ApiServiceExecuteJob {
+ private Map jobProps;
+ private String user;
+ private Map source;
+ private Map variables;
+
+ private Map configuration;
+
+ private String code;
+
+ private String engineType;
+
+ private String runType;
+
+ private Map params;
+
+ private Map runtimeParams;
+
+ private JobExecuteResult jobExecuteResult;
+
+ private String scriptPath;
+
+ @Override
+ public String getCode() {
+ return this.code;
+ }
+
+ @Override
+ public void setCode(String code) {
+ this.code = code;
+ }
+
+ @Override
+ public String getEngineType() {
+ return engineType;
+ }
+
+ @Override
+ public void setEngineType(String engineType) {
+ this.engineType = engineType;
+ }
+
+ @Override
+ public String getRunType() {
+ return runType;
+ }
+
+ @Override
+ public void setRunType(String runType) {
+ this.runType = runType;
+ }
+
+ @Override
+ public String getUser() {
+ return user;
+ }
+
+ @Override
+ public void setUser(String user){
+ this.user =user;
+ }
+
+ @Override
+ public String getJobName() {
+ return null;
+ }
+
+ @Override
+ public Map getParams() {
+ return params;
+ }
+
+ @Override
+ public void setParams(Map params) {
+ this.params = params;
+ }
+
+ @Override
+ public Map getRuntimeParams() {
+ return runtimeParams;
+ }
+
+ @Override
+ public void setRuntimeParams(Map runtimeParams) {
+ this.runtimeParams = runtimeParams;
+ }
+
+ @Override
+ public JobExecuteResult getJobExecuteResult() {
+ return this.jobExecuteResult;
+ }
+
+ @Override
+ public void setJobExecuteResult(JobExecuteResult jobExecuteResult) {
+ this.jobExecuteResult = jobExecuteResult;
+ }
+
+ @Override
+ public Map getJobProps() {
+ return jobProps;
+ }
+
+ @Override
+ public void setJobProps(Map jobProps) {
+ this.jobProps = jobProps;
+ }
+
+ @Override
+ public String getScriptPath() {
+ return scriptPath;
+ }
+
+ @Override
+ public void setScriptePath(String path) {
+ this.scriptPath = path;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/ExecuteCodeHelper.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/ExecuteCodeHelper.java
new file mode 100644
index 0000000000..a8a3d2c743
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/ExecuteCodeHelper.java
@@ -0,0 +1,268 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.execute;
+
+import com.webank.wedatasphere.dss.apiservice.core.action.ApiServiceGetAction;
+import com.webank.wedatasphere.dss.apiservice.core.action.ResultSetDownloadAction;
+import com.webank.wedatasphere.dss.apiservice.core.action.ResultWorkspaceIds;
+import com.webank.wedatasphere.dss.apiservice.core.config.ApiServiceConfiguration;
+import com.webank.wedatasphere.dss.apiservice.core.exception.ApiExecuteException;
+import com.webank.wedatasphere.linkis.common.utils.Utils;
+import com.webank.wedatasphere.linkis.httpclient.response.Result;
+import com.webank.wedatasphere.linkis.ujes.client.UJESClient;
+import com.webank.wedatasphere.linkis.ujes.client.request.ResultSetAction;
+import com.webank.wedatasphere.linkis.ujes.client.request.ResultSetListAction;
+import com.webank.wedatasphere.linkis.ujes.client.response.JobExecuteResult;
+import com.webank.wedatasphere.linkis.ujes.client.response.JobInfoResult;
+import com.webank.wedatasphere.linkis.ujes.client.response.JobLogResult;
+import com.webank.wedatasphere.linkis.ujes.client.response.ResultSetListResult;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * created by cooperyang on 2020/8/26
+ * Description:
+ */
+public class ExecuteCodeHelper {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(ExecuteCodeHelper.class);
+
+ private static final String RELEASE_SCALA_TEMPLATE = "import org.apache.spark.sql.DataFrame\n" +
+ "val sql = %s\n" +
+ "val df = sqlContext.sql(sql)\n" +
+ "show(df)\n";
+
+
+ private static final String SCALA_MARK = "\"\"\"";
+
+ private static final String EXECUTE_SCALA_TEMPLATE = "import org.apache.spark.sql.DataFrame\n" +
+ "val executeCode = %s\n" +
+ "val df = sqlContext.sql(executeCode)\n" +
+ "show(df)\n";
+
+
+
+ public static String packageCodeToRelease(String executeCode){
+ String retStr = String.format(RELEASE_SCALA_TEMPLATE, SCALA_MARK + executeCode + SCALA_MARK);
+ LOGGER.info("release scala code is {}", retStr);
+ return retStr;
+ }
+
+ public static String packageCodeToExecute(String executeCode, String metaDataInfo){
+ String retStr = String.format(EXECUTE_SCALA_TEMPLATE, SCALA_MARK + executeCode + SCALA_MARK);
+ LOGGER.info("execute scala code is {}", retStr);
+ return retStr;
+ }
+
+
+ public static Map getMetaDataInfoByExecute(String user,
+ String executeCode,
+ Map Params,
+ String scriptPath) throws Exception {
+ Map props = new HashMap<>();
+ Map resultMap = new HashMap<>();
+ UJESClient client = LinkisJobSubmit.getClient(props);
+ ApiServiceExecuteJob job = new DefaultApiServiceJob();
+ //sql代码封装成scala执行
+ job.setCode(ExecuteCodeHelper.packageCodeToRelease(executeCode));
+ job.setEngineType("spark");
+ job.setRunType("scala");
+ job.setUser(user);
+ job.setParams(null);
+ job.setRuntimeParams((Map)Params.get("variable"));// pattern注入
+ job.setScriptePath(scriptPath);
+ JobExecuteResult jobExecuteResult = LinkisJobSubmit.execute(job,client, "IDE");
+ job.setJobExecuteResult(jobExecuteResult);
+ try {
+ waitForComplete(job,client);
+ } catch (Exception e) {
+ LOGGER.warn("Failed to execute job", e);
+ String reason = getLog(job,client);
+ LOGGER.error("Reason for failure: " + reason);
+ throw new ApiExecuteException(800024,"获取库表信息失败,执行脚本出错!");
+ }
+ int resultSize = getResultSize(job,client);
+ for(int i =0; i < resultSize; i++){
+ String result = getResult(job, i, ApiServiceConfiguration.RESULT_PRINT_SIZE.getValue().intValue(),client);
+ LOGGER.info("The content of the " + (i + 1) + "th resultset is :"
+ + result);
+ resultMap.put(Integer.toString(i),result);
+
+ }
+
+ LOGGER.info("Finished to execute job");
+ return resultMap;
+ }
+
+
+ public static void waitForComplete(ApiServiceExecuteJob job,UJESClient client) throws Exception {
+ JobInfoResult jobInfo = client.getJobInfo(job.getJobExecuteResult());
+ while (!jobInfo.isCompleted()) {
+ LOGGER.info("Update Progress info:" + getProgress(job,client));
+ LOGGER.info("<----linkis log ---->");
+ Utils.sleepQuietly(ApiServiceConfiguration.LINKIS_JOB_REQUEST_STATUS_TIME.getValue(job.getJobProps()));
+ jobInfo = client.getJobInfo(job.getJobExecuteResult());
+ }
+ if (!jobInfo.isSucceed()) {
+ throw new ApiExecuteException(90101, "Failed to execute Job: " + jobInfo.getTask().get("errDesc").toString());
+ }
+ }
+
+
+ public static void cancel(ApiServiceExecuteJob job,UJESClient client) throws Exception {
+ client.kill(job.getJobExecuteResult());
+ }
+
+
+ public static double getProgress(ApiServiceExecuteJob job,UJESClient client) {
+ return client.progress(job.getJobExecuteResult()).getProgress();
+ }
+
+
+ public static Boolean isCompleted(ApiServiceExecuteJob job,UJESClient client) {
+ return client.getJobInfo(job.getJobExecuteResult()).isCompleted();
+ }
+
+ public static String getResult(ApiServiceExecuteJob job, int index, int maxSize,UJESClient client) {
+ String resultContent = null;
+ JobInfoResult jobInfo = client.getJobInfo(job.getJobExecuteResult());
+ String[] resultSetList = jobInfo.getResultSetList(LinkisJobSubmit.getClient(job.getJobProps()));
+ if (resultSetList != null && resultSetList.length > 0) {
+ Object fileContent = client.resultSet(ResultSetAction.builder()
+ .setPath(resultSetList[index])
+ .setUser(job.getJobExecuteResult().getUser())
+ .setPageSize(maxSize).build()).getFileContent();
+ if (fileContent instanceof ArrayList) {
+ ArrayList> resultSetRow = (ArrayList>) fileContent;
+ resultContent = StringUtils.join(resultSetRow.get(0), "\n");
+ } else {
+ resultContent = fileContent.toString();
+ }
+ }
+ return resultContent;
+ }
+
+
+ public static int getResultSize(ApiServiceExecuteJob job,UJESClient client) {
+ JobInfoResult jobInfo = client.getJobInfo(job.getJobExecuteResult());
+ if (jobInfo.isSucceed()) {
+ String[] resultSetList = jobInfo.getResultSetList(LinkisJobSubmit.getClient(job.getJobProps()));
+ if (resultSetList != null && resultSetList.length > 0) {
+ return resultSetList.length;
+ }
+ }
+ return 0;
+ }
+
+
+ public static String getLog(ApiServiceExecuteJob job, UJESClient client) {
+
+ JobLogResult jobLogResult = client
+ .log(job.getJobExecuteResult(),
+ 0,
+ 50);
+
+ ArrayList logArray = jobLogResult.getLog();
+
+ if (logArray != null && logArray.size()
+ >= ApiServiceConfiguration.LOG_ARRAY_LEN.getValue()
+ && StringUtils.isNotEmpty(logArray.get(3))) {
+ return logArray.get(3);
+ }
+ return null;
+ }
+
+ public static String getResultList(JobExecuteResult executeResult,UJESClient client, String path) {
+ ResultSetListResult resultList = (ResultSetListResult) client.executeUJESJob(ResultSetListAction.builder()
+ .setUser(executeResult.getUser()).setPath(path).build());
+ return resultList.getResponseBody();
+ }
+
+
+
+ public static String getResultContent(String user, String path, int maxSize,UJESClient client) {
+
+ String fileContent = client.resultSet(ResultSetAction.builder()
+ .setPath(path)
+ .setUser(user)
+ .setPageSize(maxSize).build()).getResponseBody();
+
+ return fileContent;
+ }
+
+ public static InputStream downloadResultSet(String user,
+ String path,
+ String charset,
+ String outputFileType,
+ String csvSeperator,
+ String outputFileName,
+ String sheetName,
+ String nullValue,
+ UJESClient client) {
+
+ ResultSetDownloadAction resultSetDownloadAction = new ResultSetDownloadAction();
+ resultSetDownloadAction.setUser(user);
+ resultSetDownloadAction.setParameter("path",path);
+ resultSetDownloadAction.setParameter("charset",charset);
+ resultSetDownloadAction.setParameter("outputFileType",outputFileType);
+ resultSetDownloadAction.setParameter("csvSeperator",csvSeperator);
+ resultSetDownloadAction.setParameter("outputFileName",outputFileName);
+ resultSetDownloadAction.setParameter("sheetName",sheetName);
+ resultSetDownloadAction.setParameter("nullValue",nullValue);
+ client.executeUJESJob(resultSetDownloadAction);
+ return resultSetDownloadAction.getInputStream();
+ }
+
+
+
+
+
+
+
+ public static Map getTaskInfoById(JobExecuteResult jobExecuteResult, UJESClient client) {
+
+ Map taskInfo = (Map)client.getJobInfo(jobExecuteResult).getTask();
+
+ return taskInfo;
+ }
+
+
+
+
+ public static String getUserWorkspaceIds(String userName,UJESClient client){
+ ApiServiceGetAction apiServiceGetAction = new ApiServiceGetAction();
+ apiServiceGetAction.setUser(userName);
+ apiServiceGetAction.setParameter("userName",userName);
+ ResultWorkspaceIds userWorkspaceIds = (ResultWorkspaceIds)client.executeUJESJob(apiServiceGetAction);
+ return userWorkspaceIds.getUserWorkspaceIds();
+
+ }
+
+
+
+
+
+
+
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/LinkisJobSubmit.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/LinkisJobSubmit.java
new file mode 100644
index 0000000000..5c5d4f50c6
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/execute/LinkisJobSubmit.java
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.execute;
+
+import com.webank.wedatasphere.dss.apiservice.core.config.ApiServiceConfiguration;
+import com.webank.wedatasphere.linkis.common.conf.Configuration;
+import com.webank.wedatasphere.linkis.httpclient.dws.authentication.TokenAuthenticationStrategy;
+import com.webank.wedatasphere.linkis.httpclient.dws.config.DWSClientConfig;
+import com.webank.wedatasphere.linkis.httpclient.dws.config.DWSClientConfigBuilder;
+import com.webank.wedatasphere.linkis.ujes.client.UJESClient;
+import com.webank.wedatasphere.linkis.ujes.client.UJESClientImpl;
+import com.webank.wedatasphere.linkis.ujes.client.request.JobExecuteAction;
+import com.webank.wedatasphere.linkis.ujes.client.response.JobExecuteResult;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/12 03:33 PM
+ */
+public class LinkisJobSubmit {
+
+
+
+ public static UJESClient getClient(Map props) {
+
+ UJESClient client = getUJESClient(
+ Configuration.GATEWAY_URL().getValue(props),
+ ApiServiceConfiguration.LINKIS_ADMIN_USER.getValue(props),
+ ApiServiceConfiguration.LINKIS_AUTHOR_USER_TOKEN.getValue(props),
+ props);
+
+ return client;
+ }
+
+
+ public static UJESClient getUJESClient(String url, String user, String token, Map jobProps){
+ return new UJESClientImpl(getClientConfig(url,user,token, jobProps));
+ }
+
+ public static DWSClientConfig getClientConfig(String url, String user, String token, Map jobProps){
+ DWSClientConfig clientConfig = ((DWSClientConfigBuilder) (DWSClientConfigBuilder.newBuilder()
+ .addServerUrl(url)
+ .connectionTimeout(ApiServiceConfiguration.LINKIS_CONNECTION_TIMEOUT.getValue(jobProps))
+ .discoveryEnabled(false).discoveryFrequency(1, TimeUnit.MINUTES)
+ .loadbalancerEnabled(true)
+ .maxConnectionSize(5)
+ .retryEnabled(false).readTimeout(ApiServiceConfiguration.LINKIS_CONNECTION_TIMEOUT.getValue(jobProps))
+ .setAuthenticationStrategy(new TokenAuthenticationStrategy())
+ .setAuthTokenKey(user).setAuthTokenValue(token)))
+ .setDWSVersion(ApiServiceConfiguration.LINKIS_API_VERSION.getValue(jobProps)).build();
+ return clientConfig;
+ }
+
+
+
+ public static JobExecuteResult execute(ApiServiceExecuteJob job,UJESClient client) {
+ Map source = new HashMap<>();
+ source.put("DSS-ApiService",job.getScriptPath());
+ JobExecuteAction.Builder builder = JobExecuteAction.builder().setCreator("IDE")
+ .addExecuteCode(job.getCode())
+ .setEngineTypeStr(job.getEngineType())
+ .setRunTypeStr(job.getRunType())
+ .setUser(job.getUser())
+ .setParams(job.getParams())
+ .setVariableMap(job.getRuntimeParams())
+ .setSource(source);
+ JobExecuteAction jobAction = builder.build();
+ JobExecuteResult res = client.execute(jobAction);
+ return res;
+ }
+ public static JobExecuteResult execute(ApiServiceExecuteJob job,UJESClient client, String creator) {
+ Map source = new HashMap<>();
+ source.put("DSS-ApiService",job.getScriptPath());
+ JobExecuteAction.Builder builder = JobExecuteAction.builder().setCreator(creator)
+ .addExecuteCode(job.getCode())
+ .setEngineTypeStr(job.getEngineType())
+ .setRunTypeStr(job.getRunType())
+ .setUser(job.getUser())
+ .setParams(job.getParams())
+ .setVariableMap(job.getRuntimeParams())
+ .setSource(source);
+ JobExecuteAction jobAction = builder.build();
+ JobExecuteResult res = client.execute(jobAction);
+ return res;
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/jdbc/DatasourceService.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/jdbc/DatasourceService.java
new file mode 100644
index 0000000000..6dc3784aa8
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/jdbc/DatasourceService.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.jdbc;
+
+import com.zaxxer.hikari.HikariConfig;
+import com.zaxxer.hikari.HikariDataSource;
+import org.springframework.context.annotation.Configuration;
+import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
+
+import javax.sql.DataSource;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * DatasourceConfiguration
+ *
+ * @author lidongzhang
+ */
+@Configuration
+public class DatasourceService {
+ private static final Map CLIENT_MAP = new HashMap<>();
+
+
+ private DataSource getDatasource(String url, String username, String password) {
+ HikariConfig hikariConfig = new HikariConfig();
+ hikariConfig.setJdbcUrl(url);
+ hikariConfig.setUsername(username);
+ hikariConfig.setPassword(password);
+ hikariConfig.setMaximumPoolSize(100);
+ hikariConfig.setMinimumIdle(10);
+ return new HikariDataSource(hikariConfig);
+ }
+
+
+ public NamedParameterJdbcTemplate getNamedParameterJdbcTemplate(String url,
+ String username, String password) {
+ String key = genKey(url, username);
+ NamedParameterJdbcTemplate jdbcTemplate = CLIENT_MAP.get(key);
+
+ if (jdbcTemplate == null) {
+ synchronized (this) {
+ jdbcTemplate = CLIENT_MAP.get(key);
+ if (jdbcTemplate == null) {
+ jdbcTemplate = new NamedParameterJdbcTemplate(getDatasource(url, username, password));
+ CLIENT_MAP.put(key, jdbcTemplate);
+ }
+ }
+ }
+
+ return jdbcTemplate;
+ }
+
+ private String genKey(String jdbcUrl, String username) {
+ return String.join("-", jdbcUrl, username);
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/jdbc/JdbcUtil.scala b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/jdbc/JdbcUtil.scala
new file mode 100644
index 0000000000..00ce6a1b85
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/jdbc/JdbcUtil.scala
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.jdbc
+
+import java.util
+
+import com.webank.wedatasphere.linkis.common.exception.WarnException
+import com.webank.wedatasphere.linkis.common.utils.Logging
+//import com.webank.wedatasphere.linkis.datasourcemanager.common.protocol.{DsInfoQueryRequest, DsInfoResponse}
+import com.webank.wedatasphere.linkis.rpc.Sender
+
+object JdbcUtil extends Logging {
+
+// val sender : Sender = Sender.getSender("dsm-server")
+// def getDatasourceInfo(params : util.Map[String, Any]) : (String, String, String) = {
+// val datasourceId = params.get("configuration").asInstanceOf[util.Map[String, Any]]
+// .getOrDefault("datasource", new util.HashMap[String, Any]())
+// .asInstanceOf[util.Map[String, Any]].get("datasourceId")
+// logger.info(s"begin to get datasource info from dsm, datasourceId: ${datasourceId}")
+// if (datasourceId != null) {
+// val ds = sender.ask(DsInfoQueryRequest(String.valueOf(datasourceId), "BDP")) match {
+// case r: DsInfoResponse => r
+// case warn: WarnException => throw warn
+// }
+// logger.info(s"get datasource info result: ${ds}")
+// if (ds.status) {
+// val url = ds.params.get("jdbc.url").asInstanceOf[String]
+// val userName = ds.params.get("jdbc.username").asInstanceOf[String]
+// val password = ds.params.get("jdbc.password").asInstanceOf[String]
+// logger.info(s"get from dsm: url: ${url}, username: ${userName}, password: ${password}")
+// return (url, userName, password)
+// }
+// }
+//
+// ("", "", "")
+// }
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/restful/ApiServiceCoreRestfulApi.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/restful/ApiServiceCoreRestfulApi.java
new file mode 100644
index 0000000000..5816b104a4
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/restful/ApiServiceCoreRestfulApi.java
@@ -0,0 +1,542 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.restful;
+
+import com.webank.wedatasphere.dss.apiservice.core.bo.ApiServiceQuery;
+import com.webank.wedatasphere.dss.apiservice.core.util.ApiUtils;
+import com.webank.wedatasphere.dss.apiservice.core.util.AssertUtil;
+import com.webank.wedatasphere.dss.apiservice.core.vo.*;
+import com.webank.wedatasphere.dss.apiservice.core.service.ApiServiceQueryService;
+import com.webank.wedatasphere.dss.apiservice.core.service.ApiService;
+import com.webank.wedatasphere.linkis.server.Message;
+import com.webank.wedatasphere.linkis.server.security.SecurityFilter;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.jackson.JsonNode;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.validation.ConstraintViolation;
+import javax.validation.ConstraintViolationException;
+import javax.validation.Validator;
+import javax.validation.groups.Default;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.*;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+/**
+ * api service
+ *
+ * @author zhulixin
+ */
+@Path("/dss/apiservice")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@Component
+public class ApiServiceCoreRestfulApi {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ApiServiceCoreRestfulApi.class);
+
+ @Autowired
+ private ApiService apiService;
+
+ @Autowired
+ private ApiServiceQueryService apiServiceQueryService;
+
+ @Autowired
+ private Validator beanValidator;
+
+ private static final Pattern WRITABLE_PATTERN = Pattern.compile("^\\s*(insert|update|delete|drop|alter|create).*", Pattern.CASE_INSENSITIVE | Pattern.DOTALL);
+
+ @POST
+ @Path("/api")
+ public Response insert(ApiServiceVo apiService, @Context HttpServletRequest req) {
+ return ApiUtils.doAndResponse(() -> {
+
+ if (apiService.getWorkspaceId() == null){
+ apiService.setWorkspaceId(180L);
+ }
+
+ if (StringUtils.isBlank(apiService.getAliasName())) {
+ return Message.error("'api service alias name' is missing[缺少中文名]");
+ }
+
+ if (StringUtils.isBlank(apiService.getScriptPath())) {
+ return Message.error("'api service script path' is missing[缺少脚本路径]");
+ }
+ if (StringUtils.isBlank(apiService.getContent())) {
+ return Message.error("'api service script content' is missing[缺少脚本内容]");
+ }
+
+ if (null == apiService.getWorkspaceId()) {
+ return Message.error("'api service workspaceId ' is missing[缺少工作空间ID]");
+ }
+ if (apiService.getContent().contains(";")) {
+ if(!apiService.getContent().toLowerCase().startsWith("use ")) {
+ return Message.error("'api service script content exists semicolon[脚本内容包含分号]");
+ }
+ }
+
+// check data change script
+ if (WRITABLE_PATTERN.matcher(apiService.getContent()).matches()) {
+ return Message.error("'api service script content' only supports query[脚本内容只支持查询语句]");
+ }
+
+ Map metadata = apiService.getMetadata();
+ if (apiService.getScriptPath().endsWith(".jdbc")) {
+ if (MapUtils.isEmpty(metadata)) {
+ return Message.error("'api service metadata' is missing[请选择数据源]");
+ }
+
+ Map configuration = (Map) metadata.get("configuration");
+ if (MapUtils.isEmpty(configuration)) {
+ return Message.error("'api service metadata.configuration' is missing[请选择数据源]");
+ }
+
+ Map datasource = (Map) configuration.get("datasource");
+ if (MapUtils.isEmpty(datasource)) {
+ return Message.error("'api service metadata.configuration.datasource' is missing[请选择数据源]");
+ }
+ }
+
+ String userName = SecurityFilter.getLoginUsername(req);
+ Set> result = beanValidator.validate(apiService, Default.class);
+ if (result.size() > 0) {
+ throw new ConstraintViolationException(result);
+ }
+
+ ApprovalVo approvalVo = apiService.getApprovalVo();
+
+// if (StringUtils.isBlank(approvalVo.getApprovalName())) {
+// return Message.error("'approvalName' is missing[缺少审批单名字]");
+// }
+
+ if (StringUtils.isBlank(approvalVo.getApplyUser())) {
+ return Message.error("'applyUser' is missing[缺少申请用户名字]");
+ }
+
+ apiService.setCreator(userName);
+ apiService.setModifier(userName);
+ this.apiService.save(apiService);
+ return Message.ok().data("insert_id", apiService.getId()).data("approval_no",approvalVo.getApprovalNo());
+ }, "/apiservice/api", "Fail to insert service api[新增服务api失败]");
+ }
+
+ @POST
+ @Path("/create")
+ public Response create(ApiServiceVo apiService, @Context HttpServletRequest req) {
+ return ApiUtils.doAndResponse(() -> {
+
+ if (apiService.getWorkspaceId() == null){
+ apiService.setWorkspaceId(180L);
+ }
+
+ if (StringUtils.isBlank(apiService.getAliasName())) {
+ return Message.error("'api service alias name' is missing[缺少中文名]");
+ }
+
+ if (StringUtils.isBlank(apiService.getScriptPath())) {
+ return Message.error("'api service script path' is missing[缺少脚本路径]");
+ }
+ if (StringUtils.isBlank(apiService.getContent())) {
+ return Message.error("'api service script content' is missing[缺少脚本内容]");
+ }
+
+ if (null == apiService.getWorkspaceId()) {
+ return Message.error("'api service workspaceId ' is missing[缺少工作空间ID]");
+ }
+ if (apiService.getContent().contains(";")) {
+ if(!apiService.getContent().toLowerCase().startsWith("use ")) {
+ return Message.error("'api service script content exists semicolon[脚本内容包含分号]");
+ }
+ }
+
+// check data change script
+ if (WRITABLE_PATTERN.matcher(apiService.getContent()).matches()) {
+ return Message.error("'api service script content' only supports query[脚本内容只支持查询语句]");
+ }
+
+ Map metadata = apiService.getMetadata();
+ if (apiService.getScriptPath().endsWith(".jdbc")) {
+ if (MapUtils.isEmpty(metadata)) {
+ return Message.error("'api service metadata' is missing[请选择数据源]");
+ }
+
+ Map configuration = (Map) metadata.get("configuration");
+ if (MapUtils.isEmpty(configuration)) {
+ return Message.error("'api service metadata.configuration' is missing[请选择数据源]");
+ }
+
+ Map datasource = (Map) configuration.get("datasource");
+ if (MapUtils.isEmpty(datasource)) {
+ return Message.error("'api service metadata.configuration.datasource' is missing[请选择数据源]");
+ }
+ }
+
+ String userName = SecurityFilter.getLoginUsername(req);
+ Set> result = beanValidator.validate(apiService, Default.class);
+ if (result.size() > 0) {
+ throw new ConstraintViolationException(result);
+ }
+
+ ApprovalVo approvalVo = apiService.getApprovalVo();
+
+ if (StringUtils.isBlank(approvalVo.getApprovalName())) {
+ return Message.error("'approvalName' is missing[缺少审批单名字]");
+ }
+
+ if (StringUtils.isBlank(approvalVo.getApplyUser())) {
+ return Message.error("'applyUser' is missing[缺少申请用户名字]");
+ }
+
+ apiService.setCreator(userName);
+ apiService.setModifier(userName);
+ this.apiService.saveByApp(apiService);
+ return Message.ok().data("insert_id", apiService.getId()).data("approval_no",approvalVo.getApprovalNo());
+ }, "/apiservice/api", "Fail to insert service api[新增服务api失败]");
+ }
+
+ @PUT
+ @Path("/api/{api_service_version_id}")
+ public Response update(ApiServiceVo apiService,
+ @PathParam("api_service_version_id") Long apiServiceVersionId,
+ @Context HttpServletRequest req) {
+ return ApiUtils.doAndResponse(() -> {
+
+
+ if (StringUtils.isBlank(apiService.getScriptPath())) {
+ return Message.error("'api service script path' is missing[缺少脚本路径]");
+ }
+ if(apiServiceVersionId !=0) {
+ if (StringUtils.isBlank(apiService.getPath())) {
+ return Message.error("'api service api path' is missing[缺少api路径]");
+ }
+ }
+ if (StringUtils.isBlank(apiService.getContent())) {
+ return Message.error("'api service script content' is missing[缺少脚本内容]");
+ }
+
+ if (null == apiService.getWorkspaceId()) {
+ return Message.error("'api service workspaceId ' is missing[缺少工作空间ID]");
+ }
+
+ if (null == apiService.getTargetServiceId()) {
+ return Message.error("'api service update to target service id ' is missing[缺少更新目标服务ID]");
+ }
+
+ if (apiService.getContent().contains(";")) {
+ return Message.error("'api service script content exists semicolon[脚本内容包含分号]");
+ }
+
+ ApprovalVo approvalVo = apiService.getApprovalVo();
+
+// if (StringUtils.isBlank(approvalVo.getApprovalName())) {
+// return Message.error("'approvalName' is missing[缺少审批单名字]");
+// }
+
+ if (StringUtils.isBlank(approvalVo.getApplyUser())) {
+ return Message.error("'applyUser' is missing[缺少申请用户名字]");
+ }
+// if (StringUtils.isBlank(apiService.getResourceId())) {
+// return Message.error("'api service resourceId' is missing[缺少bml resourceId]");
+// }
+
+// check data change script
+ if (WRITABLE_PATTERN.matcher(apiService.getContent()).matches()) {
+ return Message.error("'api service script content' only supports query[脚本内容只支持查询语句]");
+ }
+
+ Map metadata = apiService.getMetadata();
+ if (apiService.getScriptPath().endsWith(".jdbc")) {
+ if (MapUtils.isEmpty(metadata)) {
+ return Message.error("'api service metadata' is missing[请选择数据源]");
+ }
+
+ Map configuration = (Map) metadata.get("configuration");
+ if (MapUtils.isEmpty(configuration)) {
+ return Message.error("'api service metadata.configuration' is missing[请选择数据源]");
+ }
+
+ Map datasource = (Map) configuration.get("datasource");
+ if (MapUtils.isEmpty(datasource)) {
+ return Message.error("'api service metadata.configuration.datasource' is missing[请选择数据源]");
+ }
+ }
+
+ String userName = SecurityFilter.getLoginUsername(req);
+// Bean validation
+ Set> result = beanValidator.validate(apiService, Default.class);
+ if (result.size() > 0) {
+ throw new ConstraintViolationException(result);
+ }
+ apiService.setLatestVersionId(apiServiceVersionId);
+ apiService.setModifier(userName);
+ apiService.setModifyTime(Calendar.getInstance().getTime());
+ this.apiService.update(apiService);
+ return Message.ok().data("update_id", apiServiceVersionId);
+ }, "/apiservice/api/" + apiServiceVersionId, "Fail to update service api[更新服务api失败]");
+ }
+
+
+
+
+ @GET
+ @Path("/search")
+ public Response query(@QueryParam("name") String name,
+ @QueryParam("tag") String tag,
+ @QueryParam("status") Integer status,
+ @QueryParam("creator") String creator,
+ @QueryParam("workspaceId") Integer workspaceId,
+ @Context HttpServletRequest req) {
+ String userName = SecurityFilter.getLoginUsername(req);
+
+ return ApiUtils.doAndResponse(() -> {
+ if (null == workspaceId) {
+ return Message.error("'api service search workspaceId' is missing[缺少工作空间Id]");
+ }
+ ApiServiceQuery query = new ApiServiceQuery(userName,name, tag, status, creator);
+ query.setWorkspaceId(workspaceId);
+ if(!this.apiService.checkUserWorkspace(userName,workspaceId) ){
+ return Message.error("'api service search workspaceId' is wrong[该用户不属于该工作空间Id]");
+ }
+ List queryList = apiService.query(query);
+ return Message.ok().data("query_list", queryList);
+ }, "/apiservice/search", "Fail to query page of service api[查询服务api失败]");
+ }
+
+
+ @GET
+ @Path("/getUserServices")
+ public Response getUserServices(@QueryParam("workspaceId") Integer workspaceId,
+ @Context HttpServletRequest req){
+ String userName = SecurityFilter.getLoginUsername(req);
+ return ApiUtils.doAndResponse(() -> {
+ if(!this.apiService.checkUserWorkspace(userName,workspaceId) ){
+ return Message.error("'api service getUserServices workspaceId' is wrong[该用户不属于该工作空间Id]");
+ }
+ List apiServiceList = apiService.queryByWorkspaceId(workspaceId,userName);
+ return Message.ok().data("query_list", apiServiceList);
+ }, "/apiservice/getUserServices", "Fail to query page of user service api[查询用户服务api列表失败]");
+ }
+
+
+
+ @GET
+ @Path("/tags")
+ public Response query( @Context HttpServletRequest req,@QueryParam("workspaceId") Integer workspaceId) {
+ String userName = SecurityFilter.getLoginUsername(req);
+ return ApiUtils.doAndResponse(() -> {
+
+ List tags= apiService.queryAllTags(userName,workspaceId);
+ return Message.ok().data("tags", tags);
+ }, "/apiservice/tags", "Fail to query page of service tag[查询服务tag失败]");
+ }
+
+
+
+
+ @GET
+ @Path("/query")
+ public Response queryByScriptPath(@QueryParam("scriptPath") String scriptPath,
+ @Context HttpServletRequest req) {
+ return ApiUtils.doAndResponse(() -> {
+ String userName = SecurityFilter.getLoginUsername(req);
+ if (StringUtils.isBlank(scriptPath)) {
+ return Message.error("'api service scriptPath' is missing[缺少脚本路径]");
+ }
+ ApiServiceVo apiServiceVo = apiService.queryByScriptPath(scriptPath);
+ if(null != apiServiceVo) {
+ if (!this.apiService.checkUserWorkspace(userName, apiServiceVo.getWorkspaceId().intValue())) {
+ return Message.error("'api service query workspaceId' is wrong[该用户不属于该工作空间Id]");
+ }
+
+ if (apiServiceVo.getCreator().equals(userName)) {
+ return Message.ok().data("result", apiServiceVo);
+ } else {
+ return Message.error("'api service belong to others' [该脚本路径数据服务不属于当前用户]");
+ }
+ }else {
+ return Message.ok().data("result", apiServiceVo);
+ }
+ }, "/apiservice/query", "Fail to query page of service api[查询服务api失败]");
+ }
+
+ @GET
+ @Path("/queryById")
+ public Response queryById(@QueryParam("id") Long id,
+ @Context HttpServletRequest req) {
+ String userName = SecurityFilter.getLoginUsername(req);
+ return ApiUtils.doAndResponse(() -> {
+ if (id==null) {
+ return Message.error("'api service id' is missing[缺少服务ID]");
+ }
+ ApiServiceVo apiServiceVo = apiService.queryById(id,userName);
+ AssertUtil.notNull(apiServiceVo,"未找到数据服务,有可能已经被删除");
+ if(!this.apiService.checkUserWorkspace(userName,apiServiceVo.getWorkspaceId().intValue()) ){
+ return Message.error("'api service queryById for workspaceId' is wrong[该用户不属于该工作空间Id]");
+ }
+ return Message.ok().data("result", apiServiceVo);
+ }, "/apiservice/queryById", "Fail to query page of service api[查询服务api失败]");
+ }
+
+ @GET
+ @Path("/checkPath")
+ public Response checkPath(@QueryParam("scriptPath") String scriptPath, @QueryParam("path") String path) {
+ //需要跨用户查询
+ return ApiUtils.doAndResponse(() -> {
+ if (StringUtils.isBlank(scriptPath)) {
+ return Message.error("'api service scriptPath' is missing[缺少api脚本路径]");
+ }
+ if (StringUtils.isBlank(path)) {
+ return Message.error("'api service path' is missing[缺少api路径]");
+ }
+ Integer apiCount = apiService.queryCountByPath(scriptPath, path);
+ return Message.ok().data("result", 0 > Integer.valueOf(0).compareTo(apiCount));
+ }, "/apiservice/checkPath", "Fail to check path of service api[校验服务api路径失败]");
+ }
+
+ @GET
+ @Path("/checkName")
+ public Response checkName(@QueryParam("name") String name) {
+ //需要跨用户查询
+ return ApiUtils.doAndResponse(() -> {
+ if (StringUtils.isBlank(name)) {
+ return Message.error("'api service name' is missing[缺少api名称]");
+ }
+ Integer count = apiService.queryCountByName(name);
+ return Message.ok().data("result", count > 0);
+ }, "/apiservice/checkName", "Fail to check name of service api[校验服务api名称失败]");
+ }
+
+ @GET
+ @Path("/apiDisable")
+ public Response apiDisable(@QueryParam("id") Long id,
+ @Context HttpServletRequest req) {
+ return ApiUtils.doAndResponse(() -> {
+ String userName = SecurityFilter.getLoginUsername(req);
+ if (null == id) {
+ return Message.error("'api service api id' is missing[缺少api id]");
+ }
+ boolean resultFlag = apiService.disableApi(id,userName);
+ return Message.ok().data("result", resultFlag);
+ }, "/apiservice/apiDisable", "Fail to disable api[禁用api失败]");
+ }
+
+ @GET
+ @Path("/apiEnable")
+ public Response apiEnable(@QueryParam("id") Long id,
+ @Context HttpServletRequest req) {
+ return ApiUtils.doAndResponse(() -> {
+ String userName = SecurityFilter.getLoginUsername(req);
+ if (null == id) {
+ return Message.error("'api service api id' is missing[缺少api id]");
+ }
+ boolean resultFlag = apiService.enableApi(id,userName);
+ return Message.ok().data("result", resultFlag);
+ }, "/apiservice/apiEnable", "Fail to enable api[启用api失败]");
+ }
+
+ @GET
+ @Path("/apiDelete")
+ public Response apiDelete(@QueryParam("id") Long id,
+ @Context HttpServletRequest req) {
+ //目前暂时不实际删除数据,只做不可见和不可用。
+ return ApiUtils.doAndResponse(() -> {
+ String userName = SecurityFilter.getLoginUsername(req);
+ if (null == id) {
+ return Message.error("'api service api id' is missing[缺少api id]");
+ }
+ boolean resultFlag = apiService.deleteApi(id,userName);
+ return Message.ok().data("result", resultFlag);
+ }, "/apiservice/apiDelete", "Fail to delete api[删除api失败]");
+ }
+
+ @POST
+ @Path("/apiCommentUpdate")
+ public Response apiCommentUpdate(@Context HttpServletRequest req, JsonNode json) {
+ //目前暂时不实际删除数据,只做不可见和不可用。
+ Long id = json.get("id").getLongValue();
+ String comment=json.get("comment").getTextValue();
+ return ApiUtils.doAndResponse(() -> {
+ String userName = SecurityFilter.getLoginUsername(req);
+ if (null == id) {
+ return Message.error("'api service api id' is missing[缺少api id]");
+ }
+ boolean resultFlag = apiService.updateComment(id,comment,userName);
+ return Message.ok().data("result", resultFlag);
+ }, "/apiservice/apiDelete", "Fail to delete api[删除api失败]");
+ }
+
+
+ @GET
+ @Path("/apiParamQuery")
+ public Response apiParamQuery(@QueryParam("scriptPath") String scriptPath,
+ @QueryParam("versionId") Long versionId,
+ @Context HttpServletRequest req) {
+ return ApiUtils.doAndResponse(() -> {
+ String userName = SecurityFilter.getLoginUsername(req);
+ if (StringUtils.isEmpty(scriptPath)) {
+ return Message.error("'api service api scriptPath' is missing[缺少api scriptPath]");
+ }
+ if (null == versionId) {
+ return Message.error("'api service api version' is missing[缺少api 版本号]");
+ }
+ List queryParamVoList = apiServiceQueryService.queryParamList(scriptPath, versionId);
+ return Message.ok().data("result", queryParamVoList);
+ }, "/apiservice/apiParamQuery", "Fail to query api info[查询api信息失败]");
+ }
+
+ @GET
+ @Path("/apiVersionQuery")
+ public Response apiVersionQuery(@QueryParam("serviceId") Long serviceId,
+ @Context HttpServletRequest req) {
+ return ApiUtils.doAndResponse(() -> {
+ String userName = SecurityFilter.getLoginUsername(req);
+ if (null == serviceId) {
+ return Message.error("'api service api serviceId' is missing[缺少api serviceId]");
+ }
+ List apiVersionVoList = apiServiceQueryService.queryApiVersionById(serviceId)
+ .stream().filter(apiVersionVo -> apiVersionVo.getCreator().equals(userName))
+ .collect(Collectors.toList());
+ return Message.ok().data("result", apiVersionVoList);
+ }, "/apiservice/apiVersionQuery", "Fail to query api version[查询api版本失败]");
+ }
+
+ @GET
+ @Path("/apiContentQuery")
+ public Response apiContentQuery(@QueryParam("versionId") Long versionId,
+ @Context HttpServletRequest req) {
+ String userName = SecurityFilter.getLoginUsername(req);
+ return ApiUtils.doAndResponse(() -> {
+ if (null== versionId) {
+ return Message.error("'api service api versionId' is missing[缺少api versionId]");
+ }
+ ApiServiceVo apiServiceVo = apiServiceQueryService.queryByVersionId(userName,versionId);
+ if(!this.apiService.checkUserWorkspace(userName,apiServiceVo.getWorkspaceId().intValue()) ){
+ return Message.error("'api service apiContentQuery for workspaceId' is wrong[该用户不属于该工作空间Id]");
+ }
+ return Message.ok().data("result", apiServiceVo);
+ }, "/apiservice/apiContentQuery", "Fail to query api Content[查询api版本内容失败]");
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/restful/ApiServiceExecuteRestfulApi.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/restful/ApiServiceExecuteRestfulApi.java
new file mode 100644
index 0000000000..1b023dab07
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/restful/ApiServiceExecuteRestfulApi.java
@@ -0,0 +1,319 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.restful;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JavaType;
+import com.webank.wedatasphere.dss.apiservice.core.bo.*;
+import com.webank.wedatasphere.dss.apiservice.core.config.ApiServiceConfiguration;
+import com.webank.wedatasphere.dss.apiservice.core.exception.ApiServiceQueryException;
+import com.webank.wedatasphere.dss.apiservice.core.execute.ExecuteCodeHelper;
+import com.webank.wedatasphere.dss.apiservice.core.execute.LinkisJobSubmit;
+import com.webank.wedatasphere.dss.apiservice.core.service.ApiServiceQueryService;
+import com.webank.wedatasphere.dss.apiservice.core.token.JwtManager;
+import com.webank.wedatasphere.dss.apiservice.core.util.ApiUtils;
+import com.webank.wedatasphere.dss.apiservice.core.util.AssertUtil;
+import com.webank.wedatasphere.dss.apiservice.core.vo.*;
+import com.webank.wedatasphere.linkis.server.BDPJettyServerHelper;
+import com.webank.wedatasphere.linkis.server.Message;
+import com.webank.wedatasphere.linkis.server.security.SecurityFilter;
+import com.webank.wedatasphere.linkis.ujes.client.UJESClient;
+import com.webank.wedatasphere.linkis.ujes.client.response.JobExecuteResult;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.io.IOUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+import org.springframework.util.StringUtils;
+import org.springframework.web.bind.annotation.RequestBody;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author: jinyangrao
+ * @date: 2020-08-26 18:03:34
+ */
+
+@Path("/dss/apiservice")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@Component
+public class ApiServiceExecuteRestfulApi {
+ public static final String XLSX_RESPONSE_CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
+
+ private static final Logger logger = LoggerFactory.getLogger(ApiServiceExecuteRestfulApi.class);
+ @Autowired
+ private ApiServiceQueryService queryService;
+
+
+ private static final String SYS_COLUMN_PREFIX = "_";
+
+ private static final String requestBodyDemo = "{\"moduleName\":\"aladdin-demo\",\"params\":{\"param1\": \"value1\"}}";
+
+
+
+ @POST
+ @Path("/execute/{path:.*}")
+ public Response post(@PathParam("path") VariableString path, @RequestBody QueryRequest queryRequest,
+ @Context HttpServletRequest req) {
+ String userName = SecurityFilter.getLoginUsername(req);
+ return getResponse(userName,path.getPath(), queryRequest, HttpMethod.POST);
+ }
+
+ @GET
+ @Path("/execute/{path:.*}")
+ public Response get(@PathParam("path") VariableString path,
+ @Context HttpServletRequest req) throws JsonProcessingException {
+ String userName = SecurityFilter.getLoginUsername(req);
+
+ QueryRequest queryRequest = new QueryRequest();
+
+
+ // 如果requestBody为空,尝试从url中获取参数
+ if (MapUtils.isEmpty(queryRequest.getParams())) {
+ String paramSuffix = "params.";
+ Enumeration parameterNames = req.getParameterNames();
+ Map params = new HashMap<>();
+ while (parameterNames.hasMoreElements()) {
+ String name = parameterNames.nextElement();
+ if (name.startsWith(paramSuffix)) {
+ params.put(name.substring(paramSuffix.length()), req.getParameter(name));
+ }
+ }
+ queryRequest.setParams(params);
+ }
+ String paramsJsonStr = req.getParameter("params");
+ JavaType javaType = BDPJettyServerHelper.jacksonJson().getTypeFactory().constructParametricType(Map.class,String.class,Object.class);
+ Map parmas = BDPJettyServerHelper.jacksonJson().readValue(paramsJsonStr, javaType);
+ queryRequest.setParams(parmas);
+
+ if (StringUtils.isEmpty(queryRequest.getModuleName())) {
+ queryRequest.setModuleName(req.getParameter("moduleName"));
+ }
+
+ return getResponse(userName,path.getPath(), queryRequest, HttpMethod.GET);
+ }
+
+ @PUT
+ @Path("/execute/{path:.*}")
+ public Response put(@PathParam("path") VariableString path, @RequestBody QueryRequest queryRequest,
+ @Context HttpServletRequest req) {
+ String userName = SecurityFilter.getLoginUsername(req);
+ return getResponse(userName,path.getPath(), queryRequest, HttpMethod.PUT);
+ }
+
+ @DELETE
+ @Path("/execute/{path:.*}")
+ public Response delete(@PathParam("path") VariableString path, @RequestBody QueryRequest queryRequest,
+ @Context HttpServletRequest req) {
+ String userName = SecurityFilter.getLoginUsername(req);
+ return getResponse(userName,path.getPath(), queryRequest, HttpMethod.DELETE);
+ }
+
+ private void validParam(QueryRequest queryRequest) {
+ AssertUtil.notNull(queryRequest, "请求体不能为空,正确的格式:" + requestBodyDemo);
+ AssertUtil.notEmpty(queryRequest.getModuleName(), "moduleName不能为空,正确的格式:" + requestBodyDemo);
+ AssertUtil.notNull(queryRequest.getParams().get(ApiServiceConfiguration.API_SERVICE_TOKEN_KEY.getValue()),"请求token不能为空");
+ }
+
+ @GET
+ @Path("/getDirFileTrees")
+ public void getDirFileTrees(@Context HttpServletRequest req, @Context HttpServletResponse resp,
+ @QueryParam("path") String path,
+ @QueryParam("taskId") String taskId) throws IOException, ApiServiceQueryException {
+ String userName = SecurityFilter.getLoginUsername(req);
+ if (StringUtils.isEmpty(path)) {
+ throw new ApiServiceQueryException(80004, path);
+ }
+ String dirFileTree="";
+ ApiServiceJob apiServiceJob = queryService.getJobByTaskId(taskId);
+ if(null != apiServiceJob && userName.equals(apiServiceJob.getSubmitUser())) {
+ JobExecuteResult jobExecuteResult = new JobExecuteResult();
+ jobExecuteResult.setTaskID(taskId);
+ jobExecuteResult.setUser(apiServiceJob.getProxyUser());
+ Map props = new HashMap<>();
+ UJESClient client = LinkisJobSubmit.getClient(props);
+
+
+ dirFileTree = ExecuteCodeHelper.getResultList(jobExecuteResult, client, path);
+ }else{
+ dirFileTree="当前用户不存在运行的TaskId: "+taskId;
+ }
+ resp.getWriter().println(dirFileTree);
+ resp.getWriter().flush();
+ }
+
+
+ @GET
+ @Path("/openFile")
+ public void openFile(@Context HttpServletRequest req,
+ @QueryParam("path") String path,
+ @QueryParam("taskId") String taskId,
+ @DefaultValue("1") @QueryParam("page") Integer page,
+ @DefaultValue("5000") @QueryParam("pageSize") Integer pageSize,
+ @DefaultValue("utf-8") @QueryParam("charset") String charset,
+ @Context HttpServletResponse resp) throws IOException, ApiServiceQueryException {
+ String userName = SecurityFilter.getLoginUsername(req);
+ if (StringUtils.isEmpty(path)) {
+ throw new ApiServiceQueryException(80004, path);
+ }
+ if(StringUtils.isEmpty(taskId)){
+ throw new ApiServiceQueryException(80005, "taskId is null");
+ }
+ String fileContent="";
+ ApiServiceJob apiServiceJob = queryService.getJobByTaskId(taskId);
+ if(null != apiServiceJob && userName.equals(apiServiceJob.getSubmitUser())) {
+ Map props = new HashMap<>();
+ UJESClient client = LinkisJobSubmit.getClient(props);
+ fileContent = ExecuteCodeHelper.getResultContent(apiServiceJob.getProxyUser(), path, pageSize, client);
+ }else{
+ fileContent="当前用户不存在运行的TaskId: "+taskId;
+ }
+ resp.getWriter().println(fileContent);
+ resp.getWriter().flush();
+ }
+
+ @GET
+ @Path("resultsetToExcel")
+ public void resultsetToExcel(
+ @Context HttpServletRequest req,
+ @Context HttpServletResponse resp,
+ @QueryParam("path") String path,
+ @QueryParam("taskId") String taskId,
+ @DefaultValue("utf-8") @QueryParam("charset") String charset,
+ @DefaultValue("csv") @QueryParam("outputFileType") String outputFileType,
+ @DefaultValue(",") @QueryParam("csvSeperator") String csvSeperator,
+ @DefaultValue("downloadResultset") @QueryParam("outputFileName") String outputFileName,
+ @DefaultValue("result") @QueryParam("sheetName") String sheetName,
+ @DefaultValue("NULL") @QueryParam("nullValue") String nullValue) throws ApiServiceQueryException, IOException {
+
+ resp.addHeader("Content-Disposition", "attachment;filename="
+ + new String(outputFileName.getBytes("UTF-8"), "ISO8859-1") + "." + outputFileType);
+ resp.setCharacterEncoding(charset);
+
+ switch (outputFileType) {
+ case "csv":
+ resp.addHeader("Content-Type", "text/plain");
+ break;
+ case "xlsx":
+ resp.addHeader("Content-Type", XLSX_RESPONSE_CONTENT_TYPE);
+ break;
+ default:
+ new ApiServiceQueryException(80015,"不支持的下载类型");
+
+ }
+
+ String userName = SecurityFilter.getLoginUsername(req);
+ if (StringUtils.isEmpty(path)) {
+ throw new ApiServiceQueryException(80005, path);
+ }
+ InputStream inputStream;
+ ApiServiceJob apiServiceJob = queryService.getJobByTaskId(taskId);
+ if(null != apiServiceJob && userName.equals(apiServiceJob.getSubmitUser())) {
+ Map props = new HashMap<>();
+ UJESClient client = LinkisJobSubmit.getClient(props);
+ inputStream = ExecuteCodeHelper.downloadResultSet(apiServiceJob.getProxyUser(),
+ path,
+ charset,
+ outputFileType,
+ csvSeperator,
+ outputFileName,
+ sheetName,
+ nullValue,
+ client);
+ } else{
+ resp.getWriter().println("当前用户不存在运行的TaskId: "+taskId);
+ resp.getWriter().flush();
+ return;
+ }
+ try {
+ IOUtils.copy(inputStream, resp.getOutputStream());
+ resp.getOutputStream().flush();
+ } finally {
+ IOUtils.closeQuietly(inputStream);
+ }
+ }
+
+ @GET
+ @Path("/{id}/get")
+ public Response getTaskByID(@Context HttpServletRequest req, @PathParam("id") Long taskId) {
+ String username = SecurityFilter.getLoginUsername(req);
+ ApiServiceJob apiServiceJob = queryService.getJobByTaskId(taskId.toString());
+ if (null != apiServiceJob && username.equals(apiServiceJob.getSubmitUser())) {
+ Map props = new HashMap<>();
+ UJESClient client = LinkisJobSubmit.getClient(props);
+ JobExecuteResult jobExecuteResult = apiServiceJob.getJobExecuteResult();
+ jobExecuteResult.setUser(apiServiceJob.getProxyUser());
+ Map vo = ExecuteCodeHelper.getTaskInfoById(jobExecuteResult, client);
+ return Message.messageToResponse(Message.ok().data("task", vo));
+ } else {
+ return Message.messageToResponse(Message.ok().data("task", null));
+ }
+ }
+
+ private Response getResponse(String user,String path, QueryRequest queryRequest, String httpMethod) {
+ return ApiUtils.doAndResponse(() -> {
+
+ validParam(queryRequest);
+ String token = queryRequest.getParams().get(ApiServiceConfiguration.API_SERVICE_TOKEN_KEY.getValue()).toString();
+
+ MessageVo messageVo = null;
+ ApiServiceToken tokenDetail = null;
+ boolean isParseRight = true;
+ try {
+ tokenDetail = JwtManager.parseToken(token);
+ }catch (Exception e) {
+ isParseRight = false;
+ messageVo = new MessageVo().setData("token解析错误,该token无效!");
+ }
+ if(false == isParseRight) {
+ return messageVo;
+ }
+
+ if(tokenDetail.getApplyUser().equals(user)) {
+
+ LinkisExecuteResult query = queryService.query("/" + path,
+ queryRequest.getParams() == null ? new HashMap<>() : queryRequest.getParams(),
+ queryRequest.getModuleName(), httpMethod,tokenDetail,user);
+ if(null == query) {
+ messageVo = new MessageVo().setMessage("用户任务执行出错,用户参数错误!").setStatus(1);
+ return messageVo;
+ }
+
+ HashMap queryRes = new HashMap<>();
+ queryRes.put("taskId",query.getTaskId());
+ queryRes.put("execId",query.getExecId());
+ messageVo = new MessageVo().setData(queryRes);
+ }else {
+ messageVo = new MessageVo().setData("Token is not correct");
+ }
+
+ return messageVo;
+ });
+ }
+}
\ No newline at end of file
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/restful/ApiServiceTokenRestfulApi.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/restful/ApiServiceTokenRestfulApi.java
new file mode 100644
index 0000000000..f25dd436c8
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/restful/ApiServiceTokenRestfulApi.java
@@ -0,0 +1,136 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.restful;
+
+import com.github.pagehelper.PageInfo;
+import com.webank.wedatasphere.dss.apiservice.core.constant.SaveTokenEnum;
+import com.webank.wedatasphere.dss.apiservice.core.datamap.DataMapStatus;
+import com.webank.wedatasphere.dss.apiservice.core.service.ApprovalService;
+import com.webank.wedatasphere.dss.apiservice.core.token.TokenAuth;
+import com.webank.wedatasphere.dss.apiservice.core.service.TokenQueryService;
+import com.webank.wedatasphere.dss.apiservice.core.util.ApiUtils;
+import com.webank.wedatasphere.dss.apiservice.core.util.DateUtil;
+import com.webank.wedatasphere.dss.apiservice.core.vo.ApprovalVo;
+import com.webank.wedatasphere.dss.apiservice.core.vo.TokenManagerVo;
+import com.webank.wedatasphere.dss.apiservice.core.bo.TokenQuery;
+import com.webank.wedatasphere.linkis.server.Message;
+import com.webank.wedatasphere.linkis.server.security.SecurityFilter;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.*;
+import javax.ws.rs.core.Context;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.List;
+
+/**
+ * @author allenlliu
+ * @version 2.0.0
+ * @date 2020/08/17 05:37 PM
+ */
+
+@Path("/dss/apiservice")
+@Consumes(MediaType.APPLICATION_JSON)
+@Produces(MediaType.APPLICATION_JSON)
+@Component
+public class ApiServiceTokenRestfulApi {
+ private static final Logger LOG = LoggerFactory.getLogger(ApiServiceTokenRestfulApi.class);
+
+ @Autowired
+ TokenQueryService tokenQueryService;
+
+ @Autowired
+ ApprovalService approvalService;
+
+ @Autowired
+ TokenAuth tokenAuth;
+
+
+ @GET
+ @Path("/tokenQuery")
+ public Response apiServiceTokenQuery(@QueryParam("apiId") Long apiId,
+ @QueryParam("user") String user,
+ @QueryParam("status") Integer status,
+ @QueryParam("startDate") String startDateStr,
+ @QueryParam("endDate") String endDateStr,
+ @QueryParam("currentPage") Integer currentPage,
+ @QueryParam("pageSize") Integer pageSize,
+ @Context HttpServletRequest req) {
+ String userName = SecurityFilter.getLoginUsername(req);
+ return ApiUtils.doAndResponse(() -> {
+
+ TokenQuery query = null;
+
+ if(StringUtils.isBlank(startDateStr) || StringUtils.isBlank(endDateStr)) {
+ query = new TokenQuery(apiId, user, status);
+ } else {
+ Long startDateSecond = Long.parseLong(startDateStr);
+ Long endDateSeconed = Long.parseLong(endDateStr);
+ String startDate = DateUtil.format(new Date(startDateSecond), DateUtil.FORMAT_LONG);
+ Date endDateReal = new Date(endDateSeconed);
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(endDateReal);
+ cal.add(Calendar.DATE, 1);
+ Date realDate = cal.getTime();
+ String endDate = DateUtil.format(realDate, DateUtil.FORMAT_LONG);
+
+ query = new TokenQuery(apiId, user, status, startDate, endDate);
+
+ }
+ query.setCreator(userName);
+ query.setCurrentPage(null != currentPage ? currentPage : 1);
+ query.setPageSize(null != pageSize ? pageSize : 10);
+ PageInfo tokenList = tokenQueryService.query(query);
+ return Message.ok().data("queryList", tokenList.getList()).data("total", tokenList.getTotal());
+ }, "/apiservice/tokenQuery", "Fail to query page of token[查询token信息失败]");
+ }
+
+
+ @GET
+ @Path("/approvalRefresh")
+ public Response refresh(@QueryParam("approvalNo") String approvalNo,
+ @Context HttpServletRequest req) {
+ String userName = SecurityFilter.getLoginUsername(req);
+ return ApiUtils.doAndResponse(() ->{
+
+ ApprovalVo approvalVo = approvalService.refreshStatus(approvalNo);
+ if(approvalVo.getCreator().equals(userName) == false){
+ return Message.error("'api service user check failed' [用户检查失败!]");
+ }
+ if(null == approvalVo) {
+ return Message.error("'api service approvalNo' is missing[未查询到对应的审批单号]");
+ }
+ if(approvalVo.getStatus().equals(DataMapStatus.SUCCESS.getIndex())) {
+ List tokenManagerVoList = tokenAuth.genTokenRecord(approvalVo);
+
+ SaveTokenEnum res = tokenAuth.saveTokensToDb(tokenManagerVoList, approvalNo);
+ if(SaveTokenEnum.FAILED == res) {
+ return Message.error("'token auth process occur error' [token认证过程出现错误]");
+ }
+ }
+ String approvalStatusDesc = DataMapStatus.getDescByIndex(approvalVo.getStatus());
+ return Message.ok().data("approvalStatus", approvalStatusDesc);
+ }, "/apiservice/approvalRefresh/", "提交审批单查询出错");
+ }
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/ApiService.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/ApiService.java
new file mode 100644
index 0000000000..28b6ebb8ae
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/ApiService.java
@@ -0,0 +1,100 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.service;
+
+import com.webank.wedatasphere.dss.apiservice.core.bo.ApiServiceQuery;
+import com.webank.wedatasphere.dss.apiservice.core.exception.ApiServiceQueryException;
+import com.webank.wedatasphere.dss.apiservice.core.vo.*;
+
+import java.util.List;
+
+/**
+ * @author zhulixin
+ */
+public interface ApiService {
+
+ /**
+ * Save
+ *
+ * @param oneService oneService info
+ */
+ void save(ApiServiceVo oneService) throws Exception;
+
+
+
+ void saveByApp(ApiServiceVo apiService) throws Exception;
+
+ /**
+ * Update
+ *
+ * @param oneService oneService info
+ */
+ void update(ApiServiceVo oneService) throws Exception;
+
+ /**
+ * query
+ *
+ * @param apiServiceQuery
+ * @return
+ */
+ List query(ApiServiceQuery apiServiceQuery) throws ApiServiceQueryException;
+
+ List queryByWorkspaceId(Integer workspaceId, String userName);
+
+ List queryAllTags(String userName,Integer workspaceId);
+
+
+ /**
+ * query
+ *
+ * @param scriptPath
+ * @return
+ */
+ ApiServiceVo queryByScriptPath(String scriptPath);
+
+ Integer queryCountByPath(String scriptPath, String path);
+
+ Integer queryCountByName(String name);
+
+ /**
+ * enable api
+ * @param id api record id
+ * @return
+ */
+ Boolean enableApi(Long id,String userName);
+
+ /**
+ * disable api
+ * @param id api record id
+ * @return
+ */
+ Boolean disableApi(Long id,String userName);
+
+ Boolean deleteApi(Long id,String userName);
+
+ Boolean updateComment(Long id,String comment,String userName);
+
+ ApiServiceVo queryById(Long id,String userName);
+
+ ApiVersionVo getMaxVersion(long serviceId);
+
+ boolean checkUserWorkspace(String userName,Integer workspaceId);
+
+// List genDataMapApplyContentDatas(ApiServiceVo apiServiceVo, ApiVersionVo apiVersionVo, String metaDtaInfo);
+
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/ApiServiceQueryService.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/ApiServiceQueryService.java
new file mode 100644
index 0000000000..310cba28f7
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/ApiServiceQueryService.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.service;
+
+import com.webank.wedatasphere.dss.apiservice.core.bo.ApiServiceJob;
+import com.webank.wedatasphere.dss.apiservice.core.bo.ApiServiceToken;
+import com.webank.wedatasphere.dss.apiservice.core.bo.LinkisExecuteResult;
+import com.webank.wedatasphere.dss.apiservice.core.exception.ApiServiceQueryException;
+import com.webank.wedatasphere.dss.apiservice.core.vo.*;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * 接口调用service
+ *
+ * @author lidongzhang
+ */
+public interface ApiServiceQueryService {
+ /**
+ * 执行查询
+ *
+ * @param path path
+ * @param params params
+ * @param moduleName moduleName
+ * @param httpMethod httpMethod
+ * @return 查询接口
+ */
+ LinkisExecuteResult query(String path, Map params, String moduleName, String httpMethod, ApiServiceToken tokenDetail, String loginUser);
+
+ List queryParamList(String scriptPath, Long versionId);
+
+ /**
+ * 查询api 版本信息
+ *
+ * @param serviceId
+ * @return
+ */
+ List queryApiVersionById(Long serviceId);
+
+ ApiServiceVo queryByVersionId(String userName,Long versionId) throws ApiServiceQueryException;
+
+ ApiServiceJob getJobByTaskId(String taskId);
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/ApprovalService.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/ApprovalService.java
new file mode 100644
index 0000000000..248228ea46
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/ApprovalService.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.service;
+
+import com.webank.wedatasphere.dss.apiservice.core.vo.ApprovalVo;
+
+/**
+ * @author: jinyangrao
+ */
+public interface ApprovalService {
+
+ /**
+ * 根据审批单号,查询对应数据
+ * */
+ ApprovalVo query(String approvalNo);
+
+ /**
+ * 查询DataMap,依据DataMap审批结果更新审批单状态
+ * */
+ ApprovalVo refreshStatus(String approvalNo) throws Exception;
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/TokenQueryService.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/TokenQueryService.java
new file mode 100644
index 0000000000..58e0a30143
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/TokenQueryService.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.service;
+
+import com.github.pagehelper.PageInfo;
+import com.webank.wedatasphere.dss.apiservice.core.vo.TokenManagerVo;
+import com.webank.wedatasphere.dss.apiservice.core.bo.TokenQuery;
+
+
+public interface TokenQueryService {
+
+ /**
+ * 查询
+ * */
+ PageInfo query(TokenQuery tokenQuery);
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/impl/ApiServiceImpl.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/impl/ApiServiceImpl.java
new file mode 100644
index 0000000000..7d17636025
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/impl/ApiServiceImpl.java
@@ -0,0 +1,664 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.service.impl;
+
+import com.google.common.base.Splitter;
+import com.webank.wedatasphere.dss.apiservice.core.bo.ApiServiceQuery;
+import com.webank.wedatasphere.dss.apiservice.core.bo.ApiServiceToken;
+import com.webank.wedatasphere.dss.apiservice.core.constant.ApiCommonConstant;
+import com.webank.wedatasphere.dss.apiservice.core.constant.SQLMetadataInfoCheckStatus;
+import com.webank.wedatasphere.dss.apiservice.core.constant.SaveTokenEnum;
+import com.webank.wedatasphere.dss.apiservice.core.dao.*;
+import com.webank.wedatasphere.dss.apiservice.core.datamap.DataMapStatus;
+import com.webank.wedatasphere.dss.apiservice.core.datamap.UUIDGenerator;
+import com.webank.wedatasphere.dss.apiservice.core.exception.ApiServiceQueryException;
+import com.webank.wedatasphere.dss.apiservice.core.exception.ApiServiceTokenException;
+import com.webank.wedatasphere.dss.apiservice.core.execute.ExecuteCodeHelper;
+import com.webank.wedatasphere.dss.apiservice.core.execute.LinkisJobSubmit;
+import com.webank.wedatasphere.dss.apiservice.core.token.JwtManager;
+import com.webank.wedatasphere.dss.apiservice.core.token.TokenAuth;
+import com.webank.wedatasphere.dss.apiservice.core.vo.*;
+import com.webank.wedatasphere.dss.apiservice.core.service.ApiService;
+import com.webank.wedatasphere.linkis.bml.client.BmlClient;
+import com.webank.wedatasphere.linkis.bml.client.BmlClientFactory;
+import com.webank.wedatasphere.linkis.bml.protocol.BmlUpdateResponse;
+import com.webank.wedatasphere.linkis.bml.protocol.BmlUploadResponse;
+import com.webank.wedatasphere.linkis.common.exception.ErrorException;
+import com.webank.wedatasphere.linkis.common.io.FsPath;
+import com.webank.wedatasphere.linkis.storage.script.ScriptFsWriter;
+import com.webank.wedatasphere.linkis.storage.script.ScriptMetaData;
+import com.webank.wedatasphere.linkis.storage.script.ScriptRecord;
+import com.webank.wedatasphere.linkis.storage.script.Variable;
+import com.webank.wedatasphere.linkis.storage.script.VariableParser;
+import com.webank.wedatasphere.linkis.storage.script.writer.StorageScriptFsWriter;
+import com.webank.wedatasphere.linkis.ujes.client.UJESClient;
+import org.apache.commons.lang.StringUtils;
+import org.apache.http.Consts;
+import org.apache.ibatis.annotations.Param;
+import org.mortbay.log.Log;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import javax.annotation.PostConstruct;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.*;
+import java.util.stream.Collectors;
+
+/**
+ * service impl
+ *
+ * @author zhulixin
+ */
+@Service
+public class ApiServiceImpl implements ApiService {
+
+ private static final Logger LOG = LoggerFactory.getLogger(ApiServiceImpl.class);
+
+
+ @Autowired
+ private ApiServiceDao apiServiceDao;
+
+ @Autowired
+ private ApiServiceParamDao apiServiceParamDao;
+
+ @Autowired
+ private ApiServiceVersionDao apiServiceVersionDao;
+
+ @Autowired
+ private ApiServiceTokenManagerDao apiServiceTokenManagerDao;
+
+ @Autowired
+ TokenAuth tokenAuth;
+
+ @Autowired
+ ApiServiceApprovalDao apiServiceApprovalDao;
+
+
+ /**
+ * Bml client
+ */
+ private BmlClient client;
+
+ private UJESClient ujesClient;
+
+ @PostConstruct
+ public void buildClient() {
+ LOG.info("build client start ======");
+ client = BmlClientFactory.createBmlClient();
+ Map props = new HashMap<>();
+ ujesClient = LinkisJobSubmit.getClient(props);
+ LOG.info("build client end =======");
+ }
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void save(ApiServiceVo apiService) throws Exception {
+ String user = apiService.getCreator();
+ String resourceId = null;
+ try {
+ // check script path if already created
+ String scriptPath = apiService.getScriptPath();
+
+ // upload to bml
+ Map uploadResult = uploadBml(user, scriptPath,
+ apiService.getMetadata(), apiService.getContent());
+
+ // insert linkis_oneservice_config
+ String version = uploadResult.get("version");
+ resourceId = uploadResult.get("resourceId");
+ apiServiceDao.insert(apiService);
+
+ //insert into version
+ ApiVersionVo apiVersionVo = new ApiVersionVo();
+ apiVersionVo.setApiId(apiService.getId());
+ apiVersionVo.setBmlResourceId(resourceId);
+ apiVersionVo.setBmlVersion(version);
+ apiVersionVo.setVersion(version);
+ apiVersionVo.setCreator(user);
+ apiVersionVo.setCreateTime(Calendar.getInstance().getTime());
+ apiVersionVo.setSource(apiService.getScriptPath());
+ //1为正常 0为禁用
+ apiVersionVo.setStatus(1);
+
+
+ //生成审批记录,必须使用发布用户执行sql
+ sendApprovalToDM(user,apiService,apiVersionVo);
+ //顺序不能改变,版本信息依赖审批单信息
+ //todo update by query
+ apiVersionVo.setMetadataInfo("default");
+ apiServiceVersionDao.insert(apiVersionVo);
+
+ addApprovalToDB(apiService,apiVersionVo.getId(),apiVersionVo.getAuthId());
+
+ // insert linkis_oneservice_params
+ List params = apiService.getParams();
+ if (params != null && !params.isEmpty()) {
+ for (ParamVo param : params) {
+ param.setApiVersionId(apiVersionVo.getId());
+ apiServiceParamDao.insert(param);
+ }
+ }
+
+ //insert a token record for self
+ genTokenForPublisher(apiService,apiVersionVo.getId());
+ } catch (Exception e) {
+ LOG.error("one service insert error", e);
+ if (StringUtils.isNotBlank(resourceId)) {
+// removeBml(user, resourceId);
+ }
+ if (e.getCause() instanceof ErrorException) {
+ throw (ErrorException) e.getCause();
+ }
+ throw e;
+ }
+ }
+
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void saveByApp(ApiServiceVo apiService) throws Exception {
+ String user = apiService.getCreator();
+ String resourceId = null;
+ try {
+ // check script path if already created
+ String scriptPath = apiService.getScriptPath();
+
+ // upload to bml
+ Map uploadResult = uploadBml(user, scriptPath,
+ apiService.getMetadata(), apiService.getContent());
+
+ // insert linkis_oneservice_config
+ String version = uploadResult.get("version");
+ resourceId = uploadResult.get("resourceId");
+ apiServiceDao.insert(apiService);
+
+ //insert into version
+ ApiVersionVo apiVersionVo = new ApiVersionVo();
+ apiVersionVo.setApiId(apiService.getId());
+ apiVersionVo.setBmlResourceId(resourceId);
+ apiVersionVo.setBmlVersion(version);
+ apiVersionVo.setVersion(version);
+ apiVersionVo.setCreator(user);
+ apiVersionVo.setCreateTime(Calendar.getInstance().getTime());
+ apiVersionVo.setSource(apiService.getScriptPath());
+ //1为正常 0为禁用
+ apiVersionVo.setStatus(1);
+
+
+ //生成审批记录,必须使用发布用户执行sql
+// checkApprovalFromDM(user,apiService,apiVersionVo);
+ //顺序不能改变,版本信息依赖审批单信息
+ apiServiceVersionDao.insert(apiVersionVo);
+
+ addApprovalToDB(apiService,apiVersionVo.getId(),apiVersionVo.getAuthId());
+
+ // insert linkis_oneservice_params
+ List params = apiService.getParams();
+ if (params != null && !params.isEmpty()) {
+ for (ParamVo param : params) {
+ param.setApiVersionId(apiVersionVo.getId());
+ apiServiceParamDao.insert(param);
+ }
+ }
+
+ //insert a token record for self
+ genTokenForPublisher(apiService,apiVersionVo.getId());
+ } catch (Exception e) {
+ LOG.error("one service insert error", e);
+ if (StringUtils.isNotBlank(resourceId)) {
+// removeBml(user, resourceId);
+ }
+ if (e.getCause() instanceof ErrorException) {
+ throw (ErrorException) e.getCause();
+ }
+ throw e;
+ }
+ }
+
+
+
+
+
+ @Override
+ @Transactional(rollbackFor = Exception.class)
+ public void update(ApiServiceVo apiService) throws Exception {
+ try {
+ if(null!=apiService.getTargetServiceId()) {
+ ApiVersionVo maxTargetApiVersionVo = getMaxVersion(apiService.getTargetServiceId());
+ if(!checkUserWorkspace(apiService.getModifier(),apiService.getWorkspaceId().intValue())){
+ throw new ApiServiceQueryException(800035,"Only can update the api service by owner workspace! ");
+ }
+ if(maxTargetApiVersionVo.getCreator().equals(apiService.getModifier())) {
+ Map updateResult = updateBml(apiService.getModifier(), maxTargetApiVersionVo.getBmlResourceId(),
+ apiService.getScriptPath(), apiService.getMetadata(), apiService.getContent());
+ apiService.setCreator(maxTargetApiVersionVo.getCreator());
+ apiService.setId(maxTargetApiVersionVo.getApiId());
+ apiServiceDao.updateToTarget(apiService);
+ Log.info("Update to other Api Service, ID: " + apiService.getTargetServiceId() + ",resourceId:" + maxTargetApiVersionVo.getBmlResourceId());
+
+
+ String version = updateResult.get("version");
+ String resourceId = updateResult.get("resourceId");
+
+
+ //update api version
+ //insert into version
+ ApiVersionVo apiServiceVersionVo = new ApiVersionVo();
+ apiServiceVersionVo.setApiId(apiService.getId());
+ apiServiceVersionVo.setBmlResourceId(resourceId);
+ apiServiceVersionVo.setBmlVersion(version);
+ apiServiceVersionVo.setVersion(version);
+ apiServiceVersionVo.setCreator(apiService.getModifier());
+ apiServiceVersionVo.setCreateTime(Calendar.getInstance().getTime());
+ apiServiceVersionVo.setSource(apiService.getScriptPath());
+ //0默认已禁用 1为正常
+ apiServiceVersionVo.setStatus(1);
+ //生成审批记录
+ sendApprovalToDM(apiService.getModifier(), apiService, apiServiceVersionVo);
+ //todo update by query
+ apiServiceVersionVo.setMetadataInfo("null");
+ //顺序不能改变,版本信息依赖审批单信息
+ apiServiceVersionDao.insert(apiServiceVersionVo);
+
+ //改变历史版本状态
+ apiServiceVersionDao.updateApiVersionStatusById(maxTargetApiVersionVo.getId(), 0);
+
+ //改变历史Token状态
+ apiServiceTokenManagerDao.disableTokenStatusByVersionId(maxTargetApiVersionVo.getId());
+ // insert params
+ List params = apiService.getParams();
+ if (params != null && !params.isEmpty()) {
+ for (ParamVo param : params) {
+ param.setApiVersionId(apiServiceVersionVo.getId());
+ apiServiceParamDao.insert(param);
+ }
+ }
+
+ addApprovalToDB(apiService, apiServiceVersionVo.getId(), apiServiceVersionVo.getAuthId());
+
+ //insert a token record for self
+ genTokenForPublisher(apiService, apiServiceVersionVo.getId());
+ }else {
+ throw new ApiServiceQueryException(800036,"Only can update the api service by owner! ");
+ }
+ }else {
+ throw new ApiServiceQueryException(800037,"Target service id can not be null for update");
+ }
+
+ } catch (Exception e) {
+ LOG.error("api service update error", e);
+ if (e.getCause() instanceof ErrorException) {
+ throw (ErrorException) e.getCause();
+ }
+ throw e;
+ }
+ }
+
+ @Override
+ public List query(ApiServiceQuery apiServiceQuery) throws ApiServiceQueryException {
+ //todo 查询需要优化,量小时不影响效率
+ List queryList = apiServiceDao.query(apiServiceQuery);
+
+ //add auth check
+ List userTokenManagerVos = apiServiceTokenManagerDao.queryByApplyUser(apiServiceQuery.getUserName());
+
+ List authQueryList = queryList.stream().filter(apiServiceVo -> {
+ TokenManagerVo findUserTokenManagerVo = userTokenManagerVos.stream().filter(userTokenManagerVo ->
+ userTokenManagerVo.getApiId().equals(apiServiceVo.getId())
+ && userTokenManagerVo.getUser().equals(apiServiceQuery.getUserName())
+ ).findAny().orElse(null);
+ if (null != findUserTokenManagerVo) {
+ //检查token状态为有效的
+ if(findUserTokenManagerVo.getStatus().equals(1) || findUserTokenManagerVo.getPublisher().equals(apiServiceVo.getCreator())) {
+ return true;
+ }else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }).collect(Collectors.toList());
+
+ // query param
+ if (authQueryList != null && !authQueryList.isEmpty()) {
+ for (ApiServiceVo apiServiceVo : authQueryList) {
+ ApiVersionVo maxApiVersionVo = getMaxVersion(apiServiceVo.getId());
+ if(null == maxApiVersionVo){
+ throw new ApiServiceQueryException(800032,"数据服务API版本记录为空"+apiServiceVo.getName());
+ }
+ apiServiceVo.setParams(apiServiceParamDao.queryByVersionId(maxApiVersionVo.getId()));
+ apiServiceVo.setLatestVersionId(maxApiVersionVo.getId());
+ }
+ }
+
+ return authQueryList;
+ }
+
+ @Override
+ public List queryByWorkspaceId(Integer workspaceId, String userName){
+ List result = apiServiceDao.queryByWorkspaceId(workspaceId,userName);
+ result.stream().forEach(apiServiceVo -> {
+ ApiVersionVo apiVersionVo = getMaxVersion(apiServiceVo.getId());
+ ApprovalVo approvalVo =apiServiceApprovalDao.queryByVersionId(apiVersionVo.getId());
+ apiServiceVo.setApprovalVo(approvalVo);
+ });
+ return result;
+ }
+
+
+ @Override
+ public ApiServiceVo queryById(Long id,String userName) {
+ ApiServiceVo apiServiceVo = apiServiceDao.queryById(id);
+ ApiVersionVo maxApiVersionVo = getMaxVersion(apiServiceVo.getId());
+ List userTokenManagerVos = apiServiceTokenManagerDao.queryByApplyUserAndVersionId(userName,maxApiVersionVo.getId());
+ if(userTokenManagerVos.size()>0) {
+ // query param
+ if (apiServiceVo != null) {
+ apiServiceVo.setParams(apiServiceParamDao.queryByVersionId(maxApiVersionVo.getId()));
+ apiServiceVo.setUserToken(userTokenManagerVos.get(0).getToken());
+ apiServiceVo.setLatestVersionId(maxApiVersionVo.getId());
+ apiServiceVo.setApprovalVo(apiServiceApprovalDao.queryByVersionId(maxApiVersionVo.getId()));
+ }
+ }else {
+ return null;
+ }
+ return apiServiceVo;
+ }
+
+
+ @Override
+ public List queryAllTags(String userName,Integer workspaceId) {
+ //todo 会有历史版本的tag
+ List tags = apiServiceDao.queryAllTags(userName,workspaceId);
+ List tagList=
+ tags.stream().filter(tag->!StringUtils.isEmpty(tag)).map(tag -> Splitter.on(",").splitToList(tag)).flatMap(List::stream).distinct()
+ .collect(Collectors.toList());
+ return tagList;
+ }
+
+
+ @Override
+ public ApiServiceVo queryByScriptPath(@Param("scriptPath") String scriptPath) {
+ List apiServiceList = apiServiceDao.queryByScriptPath(scriptPath);
+ ApiServiceVo latestApiService = apiServiceList.stream().max(Comparator.comparing(ApiServiceVo::getModifyTime)).orElse(null);
+ if(null == latestApiService){
+ return null;
+ }
+ List apiVersionVos =apiServiceVersionDao.queryApiVersionByApiServiceId(latestApiService.getId());
+ ApiVersionVo maxVersion =apiVersionVos.stream().max(Comparator.comparing(ApiVersionVo::getVersion)).orElse(null);
+ // query param
+ if (latestApiService != null && null != maxVersion ) {
+ latestApiService.setParams(apiServiceParamDao.queryByVersionId(maxVersion.getId()));
+ latestApiService.setLatestVersionId(maxVersion.getId());
+ }
+ return latestApiService;
+ }
+
+
+
+
+
+
+ @Override
+ public Integer queryCountByPath(String scriptPath, String path) {
+ return apiServiceDao.queryCountByPath(scriptPath, path);
+ }
+
+ @Override
+ public Integer queryCountByName(String name) {
+ return apiServiceDao.queryCountByName(name);
+ }
+
+ @Override
+ public Boolean enableApi(Long id,String userName) {
+ ApiServiceVo apiServiceVo = apiServiceDao.queryById(id);
+ if(!checkUserWorkspace(userName,apiServiceVo.getWorkspaceId().intValue())){
+ LOG.error("api service check workspace error");
+ return false;
+ }
+ if(apiServiceVo.getCreator().equals(userName)) {
+
+ Integer updateCount = apiServiceDao.enableApi(id);
+ List targetApiVersionList = apiServiceVersionDao.queryApiVersionByApiServiceId(id);
+ ApiVersionVo maxTargetApiVersionVo = targetApiVersionList.stream().max(Comparator.comparing(ApiVersionVo::getVersion)).orElse(null);
+
+ apiServiceTokenManagerDao.enableTokenStatusByVersionId(maxTargetApiVersionVo.getId());
+ apiServiceVersionDao.updateApiVersionStatusById(maxTargetApiVersionVo.getId(), 1);
+ return updateCount > 0;
+ }else {
+ return false;
+ }
+ }
+
+ @Override
+ public Boolean disableApi(Long id,String userName) {
+ ApiServiceVo apiServiceVo = apiServiceDao.queryById(id);
+ if(!checkUserWorkspace(userName,apiServiceVo.getWorkspaceId().intValue())){
+ LOG.error("api service check workspace error");
+ return false;
+ }
+ if(apiServiceVo.getCreator().equals(userName)) {
+ Integer updateCount = apiServiceDao.disableApi(id);
+ apiServiceTokenManagerDao.disableTokenStatusByApiId(id);
+ apiServiceVersionDao.updateAllApiVersionStatusByApiServiceId(id, 0);
+ return updateCount > 0;
+ }else {
+ return false;
+ }
+ }
+
+
+ @Override
+ public Boolean deleteApi(Long id,String userName) {
+ ApiServiceVo apiServiceVo = apiServiceDao.queryById(id);
+ if(!checkUserWorkspace(userName,apiServiceVo.getWorkspaceId().intValue())){
+ LOG.error("api service check workspace error");
+ return false;
+ }
+ if(apiServiceVo.getCreator().equals(userName)) {
+ Integer updateCount = apiServiceDao.deleteApi(id);
+ apiServiceTokenManagerDao.disableTokenStatusByApiId(id);
+ apiServiceVersionDao.updateAllApiVersionStatusByApiServiceId(id, 0);
+ return updateCount > 0;
+ }else {
+ return false;
+ }
+ }
+
+ @Override
+ public Boolean updateComment(Long id, String comment, String userName) {
+ ApiServiceVo apiServiceVo = apiServiceDao.queryById(id);
+ if(!checkUserWorkspace(userName,apiServiceVo.getWorkspaceId().intValue())){
+ LOG.error("api service check workspace error");
+ return false;
+ }
+ if(apiServiceVo.getCreator().equals(userName)) {
+ Integer updateCount = apiServiceDao.updateApiServiceComment(id,comment);
+ return updateCount > 0;
+ }else {
+ return false;
+ }
+ }
+
+ private Map uploadBml(String userName, String scriptPath, Map metadata, String scriptContent) {
+ try {
+ ScriptFsWriter writer = StorageScriptFsWriter.getScriptFsWriter(new FsPath(scriptPath), Consts.UTF_8.toString(), null);
+ List variableList=null;
+ if(metadata.entrySet().size() >0) {
+ Variable[] v = VariableParser.getVariables(metadata);
+ variableList = Arrays.stream(v).filter(var -> !StringUtils.isEmpty(var.value())).collect(Collectors.toList());
+
+ }
+ if(variableList!=null) {
+ writer.addMetaData(new ScriptMetaData(variableList.toArray(new Variable[0])));
+ }else {
+ writer.addMetaData(null);
+ }
+ writer.addRecord(new ScriptRecord(scriptContent));
+ InputStream inputStream = writer.getInputStream();
+ // 新增文件
+ BmlUploadResponse resource = client.uploadResource(userName, scriptPath, inputStream);
+ if (!resource.isSuccess()) {
+ throw new IOException("upload bml error");
+ }
+ Map result = new HashMap<>();
+ result.put("resourceId", resource.resourceId());
+ result.put("version", resource.version());
+ return result;
+ } catch (IOException e) {
+ LOG.error("upload bml error", e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ private Map updateBml(String userName, String resourceId, String scriptPath, Map metadata, String scriptContent) {
+ try {
+ ScriptFsWriter writer = StorageScriptFsWriter.getScriptFsWriter(new FsPath(scriptPath), Consts.UTF_8.toString(), null);
+ Variable[] v = VariableParser.getVariables(metadata);
+ List variableList = Arrays.stream(v).filter(var -> !StringUtils.isEmpty(var.value())).collect(Collectors.toList());
+ writer.addMetaData(new ScriptMetaData(variableList.toArray(new Variable[0])));
+ writer.addRecord(new ScriptRecord(scriptContent));
+ InputStream inputStream = writer.getInputStream();
+
+ // 更新文件
+ BmlUpdateResponse resource = client.updateResource(userName, resourceId, "", inputStream);
+ if (!resource.isSuccess()) {
+ throw new IOException("update bml error");
+ }
+ Map result = new HashMap<>();
+ result.put("resourceId", resource.resourceId());
+ result.put("version", resource.version());
+ return result;
+ } catch (IOException e) {
+ LOG.error("update bml error", e);
+ throw new RuntimeException(e);
+ }
+ }
+
+ private void removeBml(String userName, String resourceId) {
+ try {
+ LOG.info("delete bml resource: userName: " + userName + ", resourceId: " + resourceId);
+ client.deleteResource(userName, resourceId);
+ } catch (Exception e) {
+ LOG.error("remove bml error", e);
+ }
+ }
+
+
+ public SQLMetadataInfoCheckStatus sendApprovalToDM(String user, ApiServiceVo apiService, ApiVersionVo apiVersionVo) throws Exception {
+ // 需要把发布者的SQL脚本内容,解析出对应的metadata库表信息
+
+// ApprovalVo approvalVo = apiService.getApprovalVo();
+ String approvalNo = UUIDGenerator.genUUID();
+ apiVersionVo.setAuthId(approvalNo);
+ return SQLMetadataInfoCheckStatus.LEGAL;
+ }
+
+
+ public void addApprovalToDB(ApiServiceVo apiService,Long apiVersionId,String approvalNumber){
+
+ ApprovalVo approvalVo = apiService.getApprovalVo();
+ // 需要插入审批单记录
+ approvalVo.setApiId(apiService.getId());
+ approvalVo.setApiVersionId(apiVersionId);
+ approvalVo.setApprovalNo(approvalNumber);
+
+ approvalVo.setCreator(apiService.getCreator());
+
+ approvalVo.setStatus(DataMapStatus.INITED.getIndex());
+ approvalVo.setCreateTime(new Date());
+ approvalVo.setUpdateTime(new Date());
+ if(StringUtils.isEmpty(approvalVo.getApprovalName())){
+ approvalVo.setApprovalName("default");
+ }
+ if(StringUtils.isEmpty(approvalVo.getExecuteUser())) {
+ approvalVo.setExecuteUser(approvalVo.getCreator());
+ }
+ apiServiceApprovalDao.insert(approvalVo);
+
+ }
+
+ public void genTokenForPublisher(ApiServiceVo apiService,Long apiVersionId) throws ApiServiceTokenException {
+
+ List tokenManagerVoList = genTokenForAccessApi(apiService,apiVersionId);
+ SaveTokenEnum res = tokenAuth.saveTokensToDb(tokenManagerVoList, ApiCommonConstant.DEFAULT_APPROVAL_NO);
+ }
+
+ /**
+ * 为申请用户和自己生成访问token
+ * @param apiService
+ * @param apiVersionId
+ * @return
+ */
+ private List genTokenForAccessApi(ApiServiceVo apiService,Long apiVersionId){
+ List tokenManagerVoList = new ArrayList<>();
+ List userNamesTmp = Arrays.asList(apiService.getApprovalVo().getApplyUser().split(","));
+ List userNames = new ArrayList<>(userNamesTmp);
+ userNames.add(apiService.getCreator());
+ userNames.stream().forEach(userName ->{
+ TokenManagerVo tokenManagerVo = new TokenManagerVo();
+ tokenManagerVo.setApiId(apiService.getId());
+ tokenManagerVo.setApiVersionId(apiVersionId);
+ tokenManagerVo.setApplyTime(Calendar.getInstance().getTime());
+ tokenManagerVo.setDuration(365L);
+ tokenManagerVo.setReason("create api service");
+ tokenManagerVo.setStatus(1);
+ tokenManagerVo.setIpWhitelist("");
+ tokenManagerVo.setCaller("scriptis");
+ tokenManagerVo.setUser(userName);
+ tokenManagerVo.setPublisher(apiService.getCreator());
+
+ ApiServiceToken apiServiceToken = new ApiServiceToken();
+ apiServiceToken.setApplyUser(userName);
+ apiServiceToken.setPublisher(apiService.getCreator());
+ apiServiceToken.setApplyTime(tokenManagerVo.getApplyTime());
+ apiServiceToken.setApiServiceId(tokenManagerVo.getApiId());
+
+ tokenManagerVo.setToken(JwtManager.createToken(userName,apiServiceToken,tokenManagerVo.getDuration()));
+ //审批单号使用默认的,自己给自己授权
+ tokenManagerVo.setApplySource(ApiCommonConstant.DEFAULT_APPROVAL_NO);
+ tokenManagerVoList.add(tokenManagerVo);
+ });
+
+ return tokenManagerVoList;
+ }
+
+
+ @Override
+ public ApiVersionVo getMaxVersion(long serviceId){
+ List apiVersionVoList = apiServiceVersionDao.queryApiVersionByApiServiceId(serviceId);
+ ApiVersionVo maxApiVersionVo = apiVersionVoList.stream().max(Comparator.comparing(ApiVersionVo::getVersion)).orElse(null);
+ return maxApiVersionVo;
+ }
+
+ @Override
+ public boolean checkUserWorkspace(String userName,Integer workspaceId){
+ //todo cache user workspaceIds
+ return true;
+// String workspaceIds = ExecuteCodeHelper.getUserWorkspaceIds(userName,ujesClient);
+// if(Arrays.stream(workspaceIds.split(",")).map(Integer::valueOf).collect(Collectors.toList()).contains(workspaceId)){
+// return true;
+// }else {
+// return false;
+// }
+
+ }
+
+}
diff --git a/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/impl/ApiServiceQueryServiceImpl.java b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/impl/ApiServiceQueryServiceImpl.java
new file mode 100644
index 0000000000..2da0401a6f
--- /dev/null
+++ b/dss-apps/dss-apiservice-server/src/main/java/com/webank/wedatasphere/dss/apiservice/core/service/impl/ApiServiceQueryServiceImpl.java
@@ -0,0 +1,559 @@
+/*
+ * Copyright 2019 WeBank
+ * Licensed 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 com.webank.wedatasphere.dss.apiservice.core.service.impl;
+
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.RemovalCause;
+import com.webank.wedatasphere.dss.apiservice.core.bo.ApiServiceJob;
+import com.webank.wedatasphere.dss.apiservice.core.bo.ApiServiceToken;
+import com.webank.wedatasphere.dss.apiservice.core.bo.LinkisExecuteResult;
+import com.webank.wedatasphere.dss.apiservice.core.config.ApiServiceConfiguration;
+import com.webank.wedatasphere.dss.apiservice.core.constant.ParamType;
+import com.webank.wedatasphere.dss.apiservice.core.constant.ParamTypeEnum;
+import com.webank.wedatasphere.dss.apiservice.core.constant.RequireEnum;
+import com.webank.wedatasphere.dss.apiservice.core.dao.*;
+import com.webank.wedatasphere.dss.apiservice.core.exception.ApiExecuteException;
+import com.webank.wedatasphere.dss.apiservice.core.exception.ApiServiceQueryException;
+import com.webank.wedatasphere.dss.apiservice.core.execute.ApiServiceExecuteJob;
+import com.webank.wedatasphere.dss.apiservice.core.execute.DefaultApiServiceJob;
+import com.webank.wedatasphere.dss.apiservice.core.execute.ExecuteCodeHelper;
+import com.webank.wedatasphere.dss.apiservice.core.execute.LinkisJobSubmit;
+import com.webank.wedatasphere.dss.apiservice.core.jdbc.DatasourceService;
+import com.webank.wedatasphere.dss.apiservice.core.service.ApiService;
+import com.webank.wedatasphere.dss.apiservice.core.util.DateUtil;
+import com.webank.wedatasphere.dss.apiservice.core.util.SQLCheckUtil;
+import com.webank.wedatasphere.dss.apiservice.core.vo.*;
+//import com.webank.wedatasphere.dss.oneservice.core.jdbc.JdbcUtil;
+import com.webank.wedatasphere.dss.apiservice.core.exception.ApiServiceRuntimeException;
+import com.webank.wedatasphere.dss.apiservice.core.service.ApiServiceQueryService;
+import com.webank.wedatasphere.dss.apiservice.core.util.AssertUtil;
+import com.webank.wedatasphere.dss.apiservice.core.util.ModelMapperUtil;
+//import com.webank.wedatasphere.dss.oneservice.core.vo.*;
+import com.webank.wedatasphere.dss.apiservice.core.vo.ApiServiceVo;
+import com.webank.wedatasphere.linkis.bml.client.BmlClient;
+import com.webank.wedatasphere.linkis.bml.client.BmlClientFactory;
+import com.webank.wedatasphere.linkis.bml.protocol.BmlDownloadResponse;
+import com.webank.wedatasphere.linkis.common.io.FsPath;
+import com.webank.wedatasphere.linkis.storage.source.FileSource;
+import com.webank.wedatasphere.linkis.storage.source.FileSource$;
+import com.webank.wedatasphere.linkis.ujes.client.UJESClient;
+import com.webank.wedatasphere.linkis.ujes.client.response.JobExecuteResult;
+import org.apache.commons.collections4.MapUtils;
+import org.apache.commons.lang.StringUtils;
+import org.apache.commons.math3.util.Pair;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.RowMapper;
+import org.springframework.jdbc.support.JdbcUtils;
+import org.springframework.stereotype.Service;
+import org.springframework.util.LinkedCaseInsensitiveMap;
+import scala.Tuple3;
+
+import javax.annotation.PostConstruct;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.ResultSet;
+import java.sql.ResultSetMetaData;
+import java.sql.SQLException;
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import static java.util.stream.Collectors.toMap;
+
+/**
+ * 接口调用service
+ *
+ * @author lidongzhang
+ */
+@Service
+public class ApiServiceQueryServiceImpl implements ApiServiceQueryService {
+ private static final Logger LOG = LoggerFactory.getLogger(ApiServiceQueryServiceImpl.class);
+
+
+ Map runJobs = new HashMap<>();
+
+ /**
+ * key:resourceId+version
+ * value:bml
+ */
+ private static Cache>> bmlCache = CacheBuilder.newBuilder()
+ .expireAfterWrite(6, TimeUnit.HOURS)
+ .maximumSize(10000)
+ .removalListener((notification) -> {
+ if (notification.getCause() == RemovalCause.SIZE) {
+ LOG.warn("bml缓存容量不足,移除key:" + notification.getKey());
+ }
+ })
+ .build();
+
+ /**
+ * key:resourceId+version
+ * value:configParam
+ */
+ private static Cache> configParamCache = CacheBuilder.newBuilder()
+ .expireAfterWrite(6, TimeUnit.HOURS)
+ .maximumSize(10000)
+ .removalListener((notification) -> {
+ if (notification.getCause() == RemovalCause.SIZE) {
+ LOG.warn("configParamCache缓存容量不足,移除key:" + notification.getKey());
+ }
+ })
+ .build();
+
+ /**
+ * key:datasourceMap
+ * value:jdbc连接信息
+ */
+ private static Cache