-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
59 changed files
with
1,400 additions
and
308 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/CorsConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* | ||
* 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.paimon.web.server.configrue; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource; | ||
import org.springframework.web.filter.CorsFilter; | ||
|
||
/** CorsConfig. */ | ||
@Slf4j | ||
// @Configuration | ||
public class CorsConfig { | ||
|
||
@Bean | ||
public CorsFilter corsFilter() { | ||
CorsConfiguration corsConfiguration = new CorsConfiguration(); | ||
corsConfiguration.setAllowCredentials(true); | ||
corsConfiguration.addAllowedHeader("*"); | ||
corsConfiguration.addAllowedMethod("*"); | ||
corsConfiguration.addExposedHeader("*"); | ||
corsConfiguration.addAllowedOrigin("http://127.0.0.1:5173"); | ||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); | ||
source.registerCorsConfiguration("/**", corsConfiguration); | ||
return new CorsFilter(source); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
paimon-web-server/src/main/java/org/apache/paimon/web/server/configrue/JacksonConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.paimon.web.server.configrue; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAutoDetect; | ||
import com.fasterxml.jackson.annotation.PropertyAccessor; | ||
import com.fasterxml.jackson.databind.DeserializationFeature; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.databind.module.SimpleModule; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder; | ||
|
||
import java.text.SimpleDateFormat; | ||
|
||
/** JacksonConfig. */ | ||
@Configuration | ||
public class JacksonConfig { | ||
@Bean | ||
public ObjectMapper getJacksonObjectMapper(Jackson2ObjectMapperBuilder builder) { | ||
ObjectMapper objectMapper = builder.createXmlMapper(false).build(); | ||
// When the sequence is changed to json, all longs will be changed to strings. | ||
// Because the numeric type in js cannot contain all java long values, precision will be | ||
// lost after more than 16 digits. | ||
SimpleModule simpleModule = new SimpleModule(); | ||
simpleModule.addSerializer( | ||
Long.class, com.fasterxml.jackson.databind.ser.std.ToStringSerializer.instance); | ||
simpleModule.addSerializer( | ||
Long.TYPE, com.fasterxml.jackson.databind.ser.std.ToStringSerializer.instance); | ||
objectMapper.registerModule(simpleModule); | ||
// If there are more attributes during deserialization, no exception will be thrown. | ||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); | ||
// Date format handling. | ||
objectMapper.setDateFormat(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")); | ||
objectMapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY); | ||
return objectMapper; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
...n-web-server/src/main/java/org/apache/paimon/web/server/controller/CatalogController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* 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.paimon.web.server.controller; | ||
|
||
import org.apache.paimon.web.api.catalog.CatalogCreator; | ||
import org.apache.paimon.web.server.data.model.CatalogInfo; | ||
import org.apache.paimon.web.server.data.result.R; | ||
import org.apache.paimon.web.server.data.result.enums.Status; | ||
import org.apache.paimon.web.server.service.CatalogService; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
/** Catalog api controller. */ | ||
@Slf4j | ||
@RestController | ||
@RequestMapping("/api/catalog") | ||
public class CatalogController { | ||
|
||
@Autowired private CatalogService catalogService; | ||
|
||
/** | ||
* Create a filesystem catalog. | ||
* | ||
* @param catalogInfo The catalogInfo for the filesystem catalog. | ||
* @return The created catalog. | ||
*/ | ||
@PostMapping("/createFilesystemCatalog") | ||
public R<Void> createFilesystemCatalog(@RequestBody CatalogInfo catalogInfo) { | ||
if (!catalogService.checkCatalogNameUnique(catalogInfo)) { | ||
return R.failed(Status.CATALOG_NAME_IS_EXIST, catalogInfo.getCatalogName()); | ||
} | ||
|
||
try { | ||
CatalogCreator.createFilesystemCatalog(catalogInfo.getWarehouse()); | ||
return catalogService.save(catalogInfo) ? R.succeed() : R.failed(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return R.failed(Status.CATALOG_CREATE_ERROR); | ||
} | ||
} | ||
|
||
/** | ||
* Create a hive catalog. | ||
* | ||
* @param catalogInfo The information for the hive catalog. | ||
* @return The created catalog. | ||
*/ | ||
@PostMapping("/createHiveCatalog") | ||
public R<Void> createHiveCatalog(@RequestBody CatalogInfo catalogInfo) { | ||
if (!catalogService.checkCatalogNameUnique(catalogInfo)) { | ||
return R.failed(Status.CATALOG_NAME_IS_EXIST, catalogInfo.getCatalogName()); | ||
} | ||
|
||
try { | ||
CatalogCreator.createHiveCatalog( | ||
catalogInfo.getWarehouse(), | ||
catalogInfo.getHiveUri(), | ||
catalogInfo.getHiveConfDir()); | ||
return catalogService.save(catalogInfo) ? R.succeed() : R.failed(); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return R.failed(Status.CATALOG_CREATE_ERROR); | ||
} | ||
} | ||
|
||
/** | ||
* Get all catalog information. | ||
* | ||
* @return The list of all catalogs. | ||
*/ | ||
@GetMapping("/getAllCatalogs") | ||
public R<List<CatalogInfo>> getCatalog() { | ||
List<CatalogInfo> catalogs = catalogService.list(); | ||
return R.succeed(catalogs); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
paimon-web-server/src/main/java/org/apache/paimon/web/server/data/model/CatalogInfo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.paimon.web.server.data.model; | ||
|
||
import com.baomidou.mybatisplus.annotation.TableLogic; | ||
import com.baomidou.mybatisplus.annotation.TableName; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.NoArgsConstructor; | ||
|
||
/** Catalog table model. */ | ||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@EqualsAndHashCode(callSuper = true) | ||
@TableName("catalog") | ||
public class CatalogInfo extends BaseModel { | ||
|
||
private String catalogType; | ||
|
||
private String catalogName; | ||
|
||
private String warehouse; | ||
|
||
private String hiveUri; | ||
|
||
private String hiveConfDir; | ||
|
||
@TableLogic private boolean isDelete; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
paimon-web-server/src/main/java/org/apache/paimon/web/server/mapper/CatalogMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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.paimon.web.server.mapper; | ||
|
||
import org.apache.paimon.web.server.data.model.CatalogInfo; | ||
|
||
import com.baomidou.mybatisplus.core.mapper.BaseMapper; | ||
import org.apache.ibatis.annotations.Mapper; | ||
|
||
/** Catalog table mapper. */ | ||
@Mapper | ||
public interface CatalogMapper extends BaseMapper<CatalogInfo> {} |
Oops, something went wrong.