Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature][scaleph-datasource] upgrade gravitino to 0.5.1 #737

Merged
merged 6 commits into from
Jun 12, 2024
Merged
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
<cola.version>4.3.2</cola.version>
<fury.version>0.4.1</fury.version>
<jgrapht.version>1.5.2</jgrapht.version>
<gravitino.version>0.5.0</gravitino.version>
<gravitino.version>0.5.1</gravitino.version>
</properties>

<dependencyManagement>
Expand Down
2 changes: 0 additions & 2 deletions scaleph-datasource/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,10 @@
<dependency>
<groupId>com.datastrato.gravitino</groupId>
<artifactId>client-java-runtime</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.datastrato.gravitino</groupId>
<artifactId>client-java</artifactId>
<optional>true</optional>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
///*
// * 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 cn.sliew.scaleph.ds.gravitino;
//
//import cn.sliew.scaleph.common.util.NetUtils;
//import com.datastrato.gravitino.client.GravitinoAdminClient;
//import com.datastrato.gravitino.client.GravitinoClient;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.context.properties.EnableConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//
//@Configuration
//@EnableConfigurationProperties(GravitinoProperties.class)
//public class GravitinoConfig {
//
// @Autowired
// private GravitinoProperties properties;
//
// @Bean
// public GravitinoAdminClient gravitinoAdminClient() {
// return GravitinoAdminClient.builder(NetUtils.replaceLocalhost(properties.getUrl()))
// .withSimpleAuth()
// .build();
// }
//
// /**
// * fixme 必须添加 metalakeName
// */
// public GravitinoClient gravitinoClient() {
// return GravitinoClient.builder(NetUtils.replaceLocalhost(properties.getUrl()))
// .withSimpleAuth()
// .build();
// }
//}
/*
* 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 cn.sliew.scaleph.ds.gravitino;

import cn.sliew.scaleph.common.util.NetUtils;
import com.datastrato.gravitino.client.GravitinoAdminClient;
import com.datastrato.gravitino.client.GravitinoClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@EnableConfigurationProperties(GravitinoProperties.class)
public class GravitinoConfig {

@Autowired
private GravitinoProperties properties;

@Bean
public GravitinoAdminClient gravitinoAdminClient() {
return GravitinoAdminClient.builder(NetUtils.replaceLocalhost(properties.getUrl()))
.withSimpleAuth()
.build();
}

/**
* fixme 必须添加 metalakeName
*/
public GravitinoClient gravitinoClient() {
return GravitinoClient.builder(NetUtils.replaceLocalhost(properties.getUrl()))
.withSimpleAuth()
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,118 +1,118 @@
///*
// * 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
// *nch
// * 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 cn.sliew.scaleph.ds.gravitino;
//
//import cn.sliew.milky.common.util.JacksonUtil;
//import cn.sliew.scaleph.common.dict.job.DataSourceType;
//import cn.sliew.scaleph.ds.modal.AbstractDataSource;
//import cn.sliew.scaleph.ds.modal.jdbc.JdbcDataSource;
//import cn.sliew.scaleph.ds.service.DsInfoService;
//import cn.sliew.scaleph.ds.service.dto.DsInfoDTO;
//import com.datastrato.gravitino.Catalog;
//import com.datastrato.gravitino.NameIdentifier;
//import com.datastrato.gravitino.client.GravitinoAdminClient;
//import com.datastrato.gravitino.client.GravitinoMetalake;
//import com.fasterxml.jackson.databind.node.ObjectNode;
//import org.springframework.beans.factory.InitializingBean;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.util.Collections;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//@Component
//public class GravitinoInitializer implements InitializingBean {
//
// @Autowired
// private GravitinoProperties properties;
// @Autowired
// private GravitinoAdminClient adminClient;
// @Autowired
// private DsInfoService dsInfoService;
//
// @Override
// public void afterPropertiesSet() throws Exception {
// initialize();
// }
//
// private void initialize() {
// NameIdentifier nameIdentifier = NameIdentifier.ofMetalake(properties.getMetalake());
//
// // 初始化 metalake
// initMetalake(nameIdentifier);
// // 初始化 catalog
// initDataSource(properties.getMetalake(), DataSourceType.MYSQL);
// initDataSource(properties.getMetalake(), DataSourceType.POSTGRESQL);
// initDataSource(properties.getMetalake(), DataSourceType.HIVE);
// initDataSource(properties.getMetalake(), DataSourceType.ICEBERG);
// initDataSource(properties.getMetalake(), DataSourceType.DORIS);
// initDataSource(properties.getMetalake(), DataSourceType.KAFKA);
// initDataSource(properties.getMetalake(), DataSourceType.HDFS);
// }
//
// private void initMetalake(NameIdentifier nameIdentifier) {
// if (adminClient.metalakeExists(nameIdentifier) == false) {
// adminClient.createMetalake(nameIdentifier, "scaleph created", Collections.emptyMap());
// }
// }
//
// private void initDataSource(String metalakeName, DataSourceType type) {
// List<DsInfoDTO> dsInfoDTOS = dsInfoService.listByType(type);
// for (DsInfoDTO dsInfoDTO : dsInfoDTOS) {
// doInitDataSource(metalakeName, type, dsInfoDTO);
// }
// }
//
// private void doInitDataSource(String metalakeName, DataSourceType type, DsInfoDTO dsInfoDTO) {
// GravitinoMetalake metalake = adminClient.loadMetalake(NameIdentifier.ofMetalake(metalakeName));
// NameIdentifier catalogName = NameIdentifier.ofCatalog(metalakeName, dsInfoDTO.getName());
// if (metalake.catalogExists(catalogName) == false) {
// switch (type) {
// case MYSQL:
// initMySQL(metalake, catalogName, dsInfoDTO);
// break;
// case POSTGRESQL:
// break;
// case HIVE:
// break;
// case ICEBERG:
// break;
// case DORIS:
// break;
// case KAFKA:
// break;
// case HDFS:
// break;
// default:
// }
// }
// }
//
// private void initMySQL(GravitinoMetalake metalake, NameIdentifier catalogName, DsInfoDTO dsInfoDTO) {
// JdbcDataSource dataSource = (JdbcDataSource) AbstractDataSource.fromDsInfo((ObjectNode) JacksonUtil.toJsonNode(dsInfoDTO));
// Map<String, String> properties = new HashMap<>();
// properties.put("jdbc-driver", dataSource.getDriverClassName());
// properties.put("jdbc-url", dataSource.getUrl());
// properties.put("jdbc-user", dataSource.getUser());
// properties.put("jdbc-password", dataSource.getPassword());
// metalake.createCatalog(catalogName, Catalog.Type.RELATIONAL, "jdbc-mysql", dataSource.getRemark(), properties);
// }
//}
/*
* 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
*nch
* 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 cn.sliew.scaleph.ds.gravitino;

import cn.sliew.milky.common.util.JacksonUtil;
import cn.sliew.scaleph.common.dict.job.DataSourceType;
import cn.sliew.scaleph.ds.modal.AbstractDataSource;
import cn.sliew.scaleph.ds.modal.jdbc.JdbcDataSource;
import cn.sliew.scaleph.ds.service.DsInfoService;
import cn.sliew.scaleph.ds.service.dto.DsInfoDTO;
import com.datastrato.gravitino.Catalog;
import com.datastrato.gravitino.NameIdentifier;
import com.datastrato.gravitino.client.GravitinoAdminClient;
import com.datastrato.gravitino.client.GravitinoMetalake;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Component
public class GravitinoInitializer implements InitializingBean {

@Autowired
private GravitinoProperties properties;
@Autowired
private GravitinoAdminClient adminClient;
@Autowired
private DsInfoService dsInfoService;

@Override
public void afterPropertiesSet() throws Exception {
initialize();
}

private void initialize() {
NameIdentifier nameIdentifier = NameIdentifier.ofMetalake(properties.getMetalake());

// 初始化 metalake
initMetalake(nameIdentifier);
// 初始化 catalog
initDataSource(properties.getMetalake(), DataSourceType.MYSQL);
initDataSource(properties.getMetalake(), DataSourceType.POSTGRESQL);
initDataSource(properties.getMetalake(), DataSourceType.HIVE);
initDataSource(properties.getMetalake(), DataSourceType.ICEBERG);
initDataSource(properties.getMetalake(), DataSourceType.DORIS);
initDataSource(properties.getMetalake(), DataSourceType.KAFKA);
initDataSource(properties.getMetalake(), DataSourceType.HDFS);
}

private void initMetalake(NameIdentifier nameIdentifier) {
if (adminClient.metalakeExists(nameIdentifier) == false) {
adminClient.createMetalake(nameIdentifier, "scaleph created", Collections.emptyMap());
}
}

private void initDataSource(String metalakeName, DataSourceType type) {
List<DsInfoDTO> dsInfoDTOS = dsInfoService.listByType(type);
for (DsInfoDTO dsInfoDTO : dsInfoDTOS) {
doInitDataSource(metalakeName, type, dsInfoDTO);
}
}

private void doInitDataSource(String metalakeName, DataSourceType type, DsInfoDTO dsInfoDTO) {
GravitinoMetalake metalake = adminClient.loadMetalake(NameIdentifier.ofMetalake(metalakeName));
NameIdentifier catalogName = NameIdentifier.ofCatalog(metalakeName, dsInfoDTO.getName());
if (metalake.catalogExists(catalogName) == false) {
switch (type) {
case MYSQL:
initMySQL(metalake, catalogName, dsInfoDTO);
break;
case POSTGRESQL:
break;
case HIVE:
break;
case ICEBERG:
break;
case DORIS:
break;
case KAFKA:
break;
case HDFS:
break;
default:
}
}
}

private void initMySQL(GravitinoMetalake metalake, NameIdentifier catalogName, DsInfoDTO dsInfoDTO) {
JdbcDataSource dataSource = (JdbcDataSource) AbstractDataSource.fromDsInfo((ObjectNode) JacksonUtil.toJsonNode(dsInfoDTO));
Map<String, String> properties = new HashMap<>();
properties.put("jdbc-driver", dataSource.getDriverClassName());
properties.put("jdbc-url", dataSource.getUrl());
properties.put("jdbc-user", dataSource.getUser());
properties.put("jdbc-password", dataSource.getPassword());
metalake.createCatalog(catalogName, Catalog.Type.RELATIONAL, "jdbc-mysql", dataSource.getRemark(), properties);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import CassandraForm from "@/pages/Metadata/DataSource/Info/StepForms/Props/Cass
import DorisForm from "@/pages/Metadata/DataSource/Info/StepForms/Props/Doris";
import StarRocksForm from "@/pages/Metadata/DataSource/Info/StepForms/Props/StarRocks";
import MaxComputeForm from "@/pages/Metadata/DataSource/Info/StepForms/Props/MaxCompute";
import GenericForm from "@/pages/Metadata/DataSource/Info/StepForms/Props/Generic";

const DataSourceForm: React.FC = () => {

Expand Down Expand Up @@ -93,7 +94,7 @@ const DataSourceForm: React.FC = () => {
case 'Http':
return <HttpForm/>
default:
return <div>开发中</div>
return <GenericForm/>
}
}
return <div>动态渲染数据源表单失败</div>
Expand Down
Loading
Loading