Browse Source
* Refactoring zeppelin task plugin with connections managed in connection center --------- Co-authored-by: Eric Gao <ericgao.apache@gmail.com>3.2.1-prepare
chenrj
1 year ago
committed by
GitHub
28 changed files with 723 additions and 64 deletions
@ -0,0 +1,50 @@ |
|||||||
|
<?xml version="1.0" encoding="UTF-8"?> |
||||||
|
<!-- |
||||||
|
~ Licensed to the Apache Software Foundation (ASF) under one or more |
||||||
|
~ contributor license agreements. See the NOTICE file distributed with |
||||||
|
~ this work for additional information regarding copyright ownership. |
||||||
|
~ The ASF licenses this file to You under the Apache License, Version 2.0 |
||||||
|
~ (the "License"); you may not use this file except in compliance with |
||||||
|
~ the License. You may obtain a copy of the License at |
||||||
|
~ |
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0 |
||||||
|
~ |
||||||
|
~ Unless required by applicable law or agreed to in writing, software |
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS, |
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
||||||
|
~ See the License for the specific language governing permissions and |
||||||
|
~ limitations under the License. |
||||||
|
--> |
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> |
||||||
|
<modelVersion>4.0.0</modelVersion> |
||||||
|
<parent> |
||||||
|
<groupId>org.apache.dolphinscheduler</groupId> |
||||||
|
<artifactId>dolphinscheduler-datasource-plugin</artifactId> |
||||||
|
<version>dev-SNAPSHOT</version> |
||||||
|
</parent> |
||||||
|
|
||||||
|
<artifactId>dolphinscheduler-datasource-zeppelin</artifactId> |
||||||
|
<packaging>jar</packaging> |
||||||
|
<name>${project.artifactId}</name> |
||||||
|
|
||||||
|
<dependencies> |
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.dolphinscheduler</groupId> |
||||||
|
<artifactId>dolphinscheduler-spi</artifactId> |
||||||
|
<scope>provided</scope> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.dolphinscheduler</groupId> |
||||||
|
<artifactId>dolphinscheduler-datasource-api</artifactId> |
||||||
|
<version>${project.version}</version> |
||||||
|
</dependency> |
||||||
|
|
||||||
|
<dependency> |
||||||
|
<groupId>org.apache.zeppelin</groupId> |
||||||
|
<artifactId>zeppelin-client</artifactId> |
||||||
|
</dependency> |
||||||
|
</dependencies> |
||||||
|
|
||||||
|
</project> |
@ -0,0 +1,55 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.plugin.datasource.zeppelin; |
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull; |
||||||
|
|
||||||
|
import org.apache.zeppelin.client.ClientConfig; |
||||||
|
import org.apache.zeppelin.client.ZeppelinClient; |
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
@Slf4j |
||||||
|
public class ZeppelinClientWrapper implements AutoCloseable { |
||||||
|
|
||||||
|
private ZeppelinClient zeppelinClient; |
||||||
|
|
||||||
|
public ZeppelinClientWrapper(String restEndpoint) |
||||||
|
throws Exception { |
||||||
|
checkNotNull(restEndpoint); |
||||||
|
ClientConfig clientConfig = new ClientConfig(restEndpoint); |
||||||
|
zeppelinClient = new ZeppelinClient(clientConfig); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean checkConnect(String username, String password) { |
||||||
|
try { |
||||||
|
// If the login fails, an exception will be thrown directly
|
||||||
|
zeppelinClient.login(username, password); |
||||||
|
String version = zeppelinClient.getVersion(); |
||||||
|
log.info("zeppelin client connects to server successfully, version is {}", version); |
||||||
|
return true; |
||||||
|
} catch (Exception e) { |
||||||
|
log.info("zeppelin client failed to connect to the server"); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void close() throws Exception { |
||||||
|
|
||||||
|
} |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.plugin.datasource.zeppelin; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.spi.datasource.AdHocDataSourceClient; |
||||||
|
import org.apache.dolphinscheduler.spi.datasource.BaseConnectionParam; |
||||||
|
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; |
||||||
|
import org.apache.dolphinscheduler.spi.datasource.PooledDataSourceClient; |
||||||
|
import org.apache.dolphinscheduler.spi.enums.DbType; |
||||||
|
|
||||||
|
public class ZeppelinDataSourceChannel implements DataSourceChannel { |
||||||
|
|
||||||
|
@Override |
||||||
|
public AdHocDataSourceClient createAdHocDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { |
||||||
|
throw new UnsupportedOperationException("Zeppelin AdHocDataSourceClient is not supported"); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public PooledDataSourceClient createPooledDataSourceClient(BaseConnectionParam baseConnectionParam, DbType dbType) { |
||||||
|
throw new UnsupportedOperationException("Zeppelin AdHocDataSourceClient is not supported"); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,38 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.plugin.datasource.zeppelin; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannel; |
||||||
|
import org.apache.dolphinscheduler.spi.datasource.DataSourceChannelFactory; |
||||||
|
|
||||||
|
import com.google.auto.service.AutoService; |
||||||
|
|
||||||
|
@AutoService(DataSourceChannelFactory.class) |
||||||
|
public class ZeppelinDataSourceChannelFactory implements DataSourceChannelFactory { |
||||||
|
|
||||||
|
@Override |
||||||
|
public DataSourceChannel create() { |
||||||
|
return new ZeppelinDataSourceChannel(); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getName() { |
||||||
|
return "zeppelin"; |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -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.dolphinscheduler.plugin.datasource.zeppelin; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.plugin.datasource.zeppelin.param.ZeppelinConnectionParam; |
||||||
|
|
||||||
|
import org.apache.zeppelin.client.ClientConfig; |
||||||
|
import org.apache.zeppelin.client.ZeppelinClient; |
||||||
|
|
||||||
|
public class ZeppelinUtils { |
||||||
|
|
||||||
|
private ZeppelinUtils() { |
||||||
|
throw new IllegalStateException("Utility class"); |
||||||
|
} |
||||||
|
|
||||||
|
public static ZeppelinClient getZeppelinClient(ZeppelinConnectionParam connectionParam) throws Exception { |
||||||
|
ClientConfig clientConfig = new ClientConfig(connectionParam.getRestEndpoint()); |
||||||
|
return new ZeppelinClient(clientConfig); |
||||||
|
} |
||||||
|
|
||||||
|
} |
@ -0,0 +1,35 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.plugin.datasource.zeppelin.param; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.spi.datasource.ConnectionParam; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude; |
||||||
|
|
||||||
|
@Data |
||||||
|
@JsonInclude(JsonInclude.Include.NON_NULL) |
||||||
|
public class ZeppelinConnectionParam implements ConnectionParam { |
||||||
|
|
||||||
|
protected String username; |
||||||
|
|
||||||
|
protected String password; |
||||||
|
|
||||||
|
protected String restEndpoint; |
||||||
|
} |
@ -0,0 +1,34 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.plugin.datasource.zeppelin.param; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO; |
||||||
|
import org.apache.dolphinscheduler.spi.enums.DbType; |
||||||
|
|
||||||
|
import lombok.Data; |
||||||
|
|
||||||
|
@Data |
||||||
|
public class ZeppelinDataSourceParamDTO extends BaseDataSourceParamDTO { |
||||||
|
|
||||||
|
protected String restEndpoint; |
||||||
|
|
||||||
|
@Override |
||||||
|
public DbType getType() { |
||||||
|
return DbType.ZEPPELIN; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,131 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.plugin.datasource.zeppelin.param; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.common.utils.JSONUtils; |
||||||
|
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.BaseDataSourceParamDTO; |
||||||
|
import org.apache.dolphinscheduler.plugin.datasource.api.datasource.DataSourceProcessor; |
||||||
|
import org.apache.dolphinscheduler.plugin.datasource.api.utils.PasswordUtils; |
||||||
|
import org.apache.dolphinscheduler.plugin.datasource.zeppelin.ZeppelinClientWrapper; |
||||||
|
import org.apache.dolphinscheduler.spi.datasource.ConnectionParam; |
||||||
|
import org.apache.dolphinscheduler.spi.enums.DbType; |
||||||
|
|
||||||
|
import org.apache.commons.lang3.StringUtils; |
||||||
|
|
||||||
|
import java.sql.Connection; |
||||||
|
import java.text.MessageFormat; |
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j; |
||||||
|
|
||||||
|
import com.google.auto.service.AutoService; |
||||||
|
|
||||||
|
@AutoService(DataSourceProcessor.class) |
||||||
|
@Slf4j |
||||||
|
public class ZeppelinDataSourceProcessor implements DataSourceProcessor { |
||||||
|
|
||||||
|
@Override |
||||||
|
public BaseDataSourceParamDTO castDatasourceParamDTO(String paramJson) { |
||||||
|
return JSONUtils.parseObject(paramJson, ZeppelinDataSourceParamDTO.class); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public void checkDatasourceParam(BaseDataSourceParamDTO datasourceParamDTO) { |
||||||
|
ZeppelinDataSourceParamDTO zeppelinDataSourceParamDTO = (ZeppelinDataSourceParamDTO) datasourceParamDTO; |
||||||
|
if (StringUtils.isEmpty(zeppelinDataSourceParamDTO.getRestEndpoint()) |
||||||
|
|| StringUtils.isEmpty(zeppelinDataSourceParamDTO.getUserName())) { |
||||||
|
throw new IllegalArgumentException("zeppelin datasource param is not valid"); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getDatasourceUniqueId(ConnectionParam connectionParam, DbType dbType) { |
||||||
|
ZeppelinConnectionParam baseConnectionParam = (ZeppelinConnectionParam) connectionParam; |
||||||
|
return MessageFormat.format("{0}@{1}@{2}@{3}", dbType.getDescp(), baseConnectionParam.getRestEndpoint(), |
||||||
|
baseConnectionParam.getUsername(), PasswordUtils.encodePassword(baseConnectionParam.getPassword())); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public BaseDataSourceParamDTO createDatasourceParamDTO(String connectionJson) { |
||||||
|
ZeppelinConnectionParam connectionParams = (ZeppelinConnectionParam) createConnectionParams(connectionJson); |
||||||
|
ZeppelinDataSourceParamDTO zeppelinDataSourceParamDTO = new ZeppelinDataSourceParamDTO(); |
||||||
|
|
||||||
|
zeppelinDataSourceParamDTO.setUserName(connectionParams.getUsername()); |
||||||
|
zeppelinDataSourceParamDTO.setPassword(connectionParams.getPassword()); |
||||||
|
zeppelinDataSourceParamDTO.setRestEndpoint(connectionParams.getRestEndpoint()); |
||||||
|
return zeppelinDataSourceParamDTO; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ZeppelinConnectionParam createConnectionParams(BaseDataSourceParamDTO datasourceParam) { |
||||||
|
ZeppelinDataSourceParamDTO zeppelinDataSourceParam = (ZeppelinDataSourceParamDTO) datasourceParam; |
||||||
|
ZeppelinConnectionParam zeppelinConnectionParam = new ZeppelinConnectionParam(); |
||||||
|
zeppelinConnectionParam.setUsername(zeppelinDataSourceParam.getUserName()); |
||||||
|
zeppelinConnectionParam.setPassword(zeppelinDataSourceParam.getPassword()); |
||||||
|
zeppelinConnectionParam.setRestEndpoint(zeppelinDataSourceParam.getRestEndpoint()); |
||||||
|
|
||||||
|
return zeppelinConnectionParam; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public ConnectionParam createConnectionParams(String connectionJson) { |
||||||
|
return JSONUtils.parseObject(connectionJson, ZeppelinConnectionParam.class); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getDatasourceDriver() { |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getValidationQuery() { |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String getJdbcUrl(ConnectionParam connectionParam) { |
||||||
|
return ""; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Connection getConnection(ConnectionParam connectionParam) { |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public boolean checkDataSourceConnectivity(ConnectionParam connectionParam) { |
||||||
|
ZeppelinConnectionParam baseConnectionParam = (ZeppelinConnectionParam) connectionParam; |
||||||
|
try ( |
||||||
|
ZeppelinClientWrapper zeppelinClientWrapper = |
||||||
|
new ZeppelinClientWrapper(baseConnectionParam.getRestEndpoint())) { |
||||||
|
return zeppelinClientWrapper.checkConnect(baseConnectionParam.username, baseConnectionParam.password); |
||||||
|
} catch (Exception e) { |
||||||
|
log.error("zeppelin client failed to connect to the server", e); |
||||||
|
return false; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public DbType getDbType() { |
||||||
|
return DbType.ZEPPELIN; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public DataSourceProcessor create() { |
||||||
|
return new ZeppelinDataSourceProcessor(); |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,107 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.plugin.datasource.zeppelin; |
||||||
|
|
||||||
|
import org.apache.dolphinscheduler.plugin.datasource.zeppelin.param.ZeppelinConnectionParam; |
||||||
|
import org.apache.dolphinscheduler.plugin.datasource.zeppelin.param.ZeppelinDataSourceParamDTO; |
||||||
|
import org.apache.dolphinscheduler.plugin.datasource.zeppelin.param.ZeppelinDataSourceProcessor; |
||||||
|
import org.apache.dolphinscheduler.spi.enums.DbType; |
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions; |
||||||
|
import org.junit.jupiter.api.BeforeEach; |
||||||
|
import org.junit.jupiter.api.Test; |
||||||
|
import org.junit.jupiter.api.extension.ExtendWith; |
||||||
|
import org.mockito.MockedConstruction; |
||||||
|
import org.mockito.Mockito; |
||||||
|
import org.mockito.junit.jupiter.MockitoExtension; |
||||||
|
|
||||||
|
@ExtendWith(MockitoExtension.class) |
||||||
|
public class ZeppelinDataSourceProcessorTest { |
||||||
|
|
||||||
|
private ZeppelinDataSourceProcessor zeppelinDataSourceProcessor; |
||||||
|
|
||||||
|
private String connectJson = |
||||||
|
"{\"username\":\"lucky\",\"password\":\"123456\",\"restEndpoint\":\"https://dolphinscheduler.com:8080\"}"; |
||||||
|
|
||||||
|
@BeforeEach |
||||||
|
public void init() { |
||||||
|
zeppelinDataSourceProcessor = new ZeppelinDataSourceProcessor(); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void testCheckDatasourceParam() { |
||||||
|
ZeppelinDataSourceParamDTO zeppelinDataSourceParamDTO = new ZeppelinDataSourceParamDTO(); |
||||||
|
Assertions.assertThrows(IllegalArgumentException.class, |
||||||
|
() -> zeppelinDataSourceProcessor.checkDatasourceParam(zeppelinDataSourceParamDTO)); |
||||||
|
zeppelinDataSourceParamDTO.setRestEndpoint("http://dolphinscheduler.com:8080"); |
||||||
|
Assertions.assertThrows(IllegalArgumentException.class, |
||||||
|
() -> zeppelinDataSourceProcessor.checkDatasourceParam(zeppelinDataSourceParamDTO)); |
||||||
|
zeppelinDataSourceParamDTO.setUserName("root"); |
||||||
|
Assertions |
||||||
|
.assertDoesNotThrow(() -> zeppelinDataSourceProcessor.checkDatasourceParam(zeppelinDataSourceParamDTO)); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void testGetDatasourceUniqueId() { |
||||||
|
ZeppelinConnectionParam zeppelinConnectionParam = new ZeppelinConnectionParam(); |
||||||
|
zeppelinConnectionParam.setRestEndpoint("https://dolphinscheduler.com:8080"); |
||||||
|
zeppelinConnectionParam.setUsername("root"); |
||||||
|
zeppelinConnectionParam.setPassword("123456"); |
||||||
|
Assertions.assertEquals("zeppelin@https://dolphinscheduler.com:8080@root@123456", |
||||||
|
zeppelinDataSourceProcessor.getDatasourceUniqueId(zeppelinConnectionParam, DbType.ZEPPELIN)); |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void testCreateDatasourceParamDTO() { |
||||||
|
ZeppelinDataSourceParamDTO zeppelinDataSourceParamDTO = |
||||||
|
(ZeppelinDataSourceParamDTO) zeppelinDataSourceProcessor.createDatasourceParamDTO(connectJson); |
||||||
|
Assertions.assertEquals("lucky", zeppelinDataSourceParamDTO.getUserName()); |
||||||
|
Assertions.assertEquals("123456", zeppelinDataSourceParamDTO.getPassword()); |
||||||
|
Assertions.assertEquals("https://dolphinscheduler.com:8080", zeppelinDataSourceParamDTO.getRestEndpoint()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void testCreateConnectionParams() { |
||||||
|
ZeppelinDataSourceParamDTO zeppelinDataSourceParamDTO = |
||||||
|
(ZeppelinDataSourceParamDTO) zeppelinDataSourceProcessor.createDatasourceParamDTO(connectJson); |
||||||
|
ZeppelinConnectionParam zeppelinConnectionParam = |
||||||
|
zeppelinDataSourceProcessor.createConnectionParams(zeppelinDataSourceParamDTO); |
||||||
|
Assertions.assertEquals("lucky", zeppelinConnectionParam.getUsername()); |
||||||
|
Assertions.assertEquals("123456", zeppelinConnectionParam.getPassword()); |
||||||
|
Assertions.assertEquals("https://dolphinscheduler.com:8080", zeppelinConnectionParam.getRestEndpoint()); |
||||||
|
} |
||||||
|
|
||||||
|
@Test |
||||||
|
void testTestConnection() { |
||||||
|
ZeppelinDataSourceParamDTO zeppelinDataSourceParamDTO = |
||||||
|
(ZeppelinDataSourceParamDTO) zeppelinDataSourceProcessor.createDatasourceParamDTO(connectJson); |
||||||
|
ZeppelinConnectionParam connectionParam = |
||||||
|
zeppelinDataSourceProcessor.createConnectionParams(zeppelinDataSourceParamDTO); |
||||||
|
Assertions.assertFalse(zeppelinDataSourceProcessor.checkDataSourceConnectivity(connectionParam)); |
||||||
|
try ( |
||||||
|
MockedConstruction<ZeppelinClientWrapper> sshClientWrapperMockedConstruction = |
||||||
|
Mockito.mockConstruction(ZeppelinClientWrapper.class, (mock, context) -> { |
||||||
|
Mockito.when( |
||||||
|
mock.checkConnect(connectionParam.getUsername(), connectionParam.getPassword())) |
||||||
|
.thenReturn(true); |
||||||
|
})) { |
||||||
|
Assertions.assertTrue(zeppelinDataSourceProcessor.checkDataSourceConnectivity(connectionParam)); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,46 @@ |
|||||||
|
/* |
||||||
|
* 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.dolphinscheduler.plugin.task.zeppelin; |
||||||
|
|
||||||
|
import java.io.Serializable; |
||||||
|
|
||||||
|
/** |
||||||
|
* master/worker task transport |
||||||
|
*/ |
||||||
|
public class ZeppelinTaskExecutionContext implements Serializable { |
||||||
|
|
||||||
|
/** |
||||||
|
* connectionParams |
||||||
|
*/ |
||||||
|
private String connectionParams; |
||||||
|
|
||||||
|
public String getConnectionParams() { |
||||||
|
return connectionParams; |
||||||
|
} |
||||||
|
|
||||||
|
public void setConnectionParams(String connectionParams) { |
||||||
|
this.connectionParams = connectionParams; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public String toString() { |
||||||
|
return "ZeppelinTaskExecutionContext{" |
||||||
|
+ "connectionParams='" + connectionParams + '\'' |
||||||
|
+ '}'; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue