Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<groupId>org.hibernate.validator</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.1.2.Final</version>
</dependency>

<!--bml client-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,42 @@ public Message getDataSourceListByTypes(
},
"Fail to get all types of data source[获取数据源列表失败]");
}

@ApiOperation(
value = "getPublishedDataSourceByType",
notes = "get published data source by type and proxy user",
response = Message.class)
@ApiImplicitParams({
@ApiImplicitParam(name = "dataSourceType", required = true, dataType = "String"),
@ApiImplicitParam(name = "proxyUser", required = true, dataType = "String")
})
@RequestMapping(value = "/published/type", method = RequestMethod.GET)
public Message getPublishedDataSourceByType(
@RequestParam("dataSourceType") String dataSourceType,
@RequestParam("proxyUser") String proxyUser,
HttpServletRequest request) {
return RestfulApiHelper.doAndResponse(
() -> {
String userName =
ModuleUserUtils.getOperationUser(request, "getPublishedDataSourceByType");
DataSource dataSource =
dataSourceInfoService.getPublishedDataSourceByType(dataSourceType, proxyUser);
if (dataSource == null) {
return Message.error(
"No published data source found for type: "
+ dataSourceType
+ " and proxy user: "
+ proxyUser);
}
if (!AuthContext.hasPermission(dataSource, userName)) {
return Message.error("Don't have query permission for data source [没有数据源的查询权限]");
}
dataSource.setConnectParams(null);
dataSource.setParameter(null);
return Message.ok().data("info", dataSource);
},
"Fail to get published data source[获取已发布数据源信息失败]");
}
/**
* Inner method to insert data source
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,4 +290,13 @@ DataSource getDataSourceInfoForConnect(String dataSourceName, String envId)
* @return
*/
boolean existDataSourceEnv(String dataSourceEnvName);

/**
* Get published data source by type and proxy user
*
* @param dataSourceType data source type
* @param proxyUser proxy user
* @return data source entity
*/
DataSource getPublishedDataSourceByType(String dataSourceType, String proxyUser);
}
Original file line number Diff line number Diff line change
Expand Up @@ -739,4 +739,29 @@ private void mergeVersionParams(DataSource dataSource, Long version) {
}
}
}

@Override
public DataSource getPublishedDataSourceByType(String dataSourceType, String proxyUser) {
try {
// 1. 查询数据源列表
List<DataSource> dataSourceList =
dataSourceDao.selectDatasourcesByType(dataSourceType, proxyUser);
if (CollectionUtils.isEmpty(dataSourceList)) {
LOG.debug("No datasource found for type:{} and owner:{}", dataSourceType, proxyUser);
return null;
}
// 2. 筛选符合条件的已发布数据源
return dataSourceList.stream()
.filter(
dataSource ->
(dataSource.getPublishedVersionId() != null) && (!dataSource.isExpire()))
.sorted(Comparator.comparing(DataSource::getCreateTime, Comparator.reverseOrder()))
.findFirst()
.orElse(null);
} catch (Exception e) {
LOG.error(
"Get published datasource failed, type:{}, proxyUser:{}", dataSourceType, proxyUser, e);
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public enum DatasourceClientErrorCodeSummary implements LinkisErrorCode {
IP_NEEDED(31000, "ip is needed(ip为空)!"),
PORT_NEEDED(31000, "port is needed(port为空)!"),
OWNER_NEEDED(31000, "owner is needed(owner为空)!"),
DATASOURCE_TYPE_NEEDED(31000, "dataSourceType is needed(dataSourceType为空)!"),
PROXY_USER_NEEDED(31000, "proxyUser is needed(proxyUser为空)!"),
DATASOURCE_NEEDED(31000, "datasourceTypeName is needed(datasourceTypeName为空)!"),
CANNOT_SOURCE(
31000, "Cannot encode the name of data source:{0} for request(无法对请求的数据源名称进行编码:{0})"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ trait DataSourceRemoteClient extends RemoteClient {
): UpdateDataSourceParameterResult

def getKeyDefinitionsByType(action: GetKeyTypeDatasourceAction): GetKeyTypeDatasourceResult

def getPublishedDataSourceByType(
action: GetPublishedDataSourceByTypeAction
): GetPublishedDataSourceByTypeResult

}
Original file line number Diff line number Diff line change
Expand Up @@ -151,4 +151,9 @@ class LinkisDataSourceRemoteClient(clientConfig: DWSClientConfig, clientName: St
action: GetKeyTypeDatasourceAction
): GetKeyTypeDatasourceResult = execute(action).asInstanceOf[GetKeyTypeDatasourceResult]

override def getPublishedDataSourceByType(
action: GetPublishedDataSourceByTypeAction
): GetPublishedDataSourceByTypeResult =
execute(action).asInstanceOf[GetPublishedDataSourceByTypeResult]

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.linkis.datasource.client.request

import org.apache.linkis.datasource.client.config.DatasourceClientConfig.DATA_SOURCE_SERVICE_MODULE
import org.apache.linkis.datasource.client.errorcode.DatasourceClientErrorCodeSummary._
import org.apache.linkis.datasource.client.exception.DataSourceClientBuilderException
import org.apache.linkis.httpclient.request.GetAction

class GetPublishedDataSourceByTypeAction extends GetAction with DataSourceAction {
private var dataSourceType: String = _
private var proxyUser: String = _

override def suffixURLs: Array[String] =
Array(DATA_SOURCE_SERVICE_MODULE.getValue, "published", "type")

override def setUser(user: String): Unit = this.user = user

override def getUser: String = this.user

private var user: String = _

}

object GetPublishedDataSourceByTypeAction {
def builder(): Builder = new Builder

class Builder private[GetPublishedDataSourceByTypeAction] () {
private var dataSourceType: String = _
private var proxyUser: String = _
private var system: String = _
private var user: String = _

def setUser(user: String): Builder = {
this.user = user
this
}

def setDataSourceType(dataSourceType: String): Builder = {
this.dataSourceType = dataSourceType
this
}

def setProxyUser(proxyUser: String): Builder = {
this.proxyUser = proxyUser
this
}

def setSystem(system: String): Builder = {
this.system = system
this
}

def build(): GetPublishedDataSourceByTypeAction = {
if (dataSourceType == null) {
throw new DataSourceClientBuilderException(DATASOURCE_TYPE_NEEDED.getErrorDesc)
}
if (proxyUser == null) {
throw new DataSourceClientBuilderException(PROXY_USER_NEEDED.getErrorDesc)
}
if (system == null) throw new DataSourceClientBuilderException(SYSTEM_NEEDED.getErrorDesc)
if (user == null) throw new DataSourceClientBuilderException(USER_NEEDED.getErrorDesc)

val action = new GetPublishedDataSourceByTypeAction
action.dataSourceType = this.dataSourceType
action.proxyUser = this.proxyUser
action.setParameter("dataSourceType", dataSourceType)
action.setParameter("proxyUser", proxyUser)
action.setParameter("system", system)
action.setUser(user)
action
}

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.linkis.datasource.client.response

import org.apache.linkis.datasourcemanager.common.domain.DataSource
import org.apache.linkis.httpclient.dws.DWSHttpClient
import org.apache.linkis.httpclient.dws.annotation.DWSHttpMessageResult
import org.apache.linkis.httpclient.dws.response.DWSResult

import scala.beans.BeanProperty

@DWSHttpMessageResult("/api/rest_j/v\\d+/data-source-manager/published/type")
class GetPublishedDataSourceByTypeResult extends DWSResult {
@BeanProperty var info: java.util.Map[String, Any] = _

def getDataSource: DataSource = {
val str = DWSHttpClient.jacksonJson.writeValueAsString(info)
DWSHttpClient.jacksonJson.readValue(str, classOf[DataSource])
}

}