|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.inlong.manager.pojo.node.hive; |
| 19 | + |
| 20 | +import com.fasterxml.jackson.databind.DeserializationFeature; |
| 21 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 22 | +import io.swagger.annotations.ApiModel; |
| 23 | +import io.swagger.annotations.ApiModelProperty; |
| 24 | +import lombok.AllArgsConstructor; |
| 25 | +import lombok.Builder; |
| 26 | +import lombok.Data; |
| 27 | +import lombok.NoArgsConstructor; |
| 28 | +import org.apache.inlong.manager.common.enums.ErrorCodeEnum; |
| 29 | +import org.apache.inlong.manager.common.exceptions.BusinessException; |
| 30 | +import org.slf4j.Logger; |
| 31 | +import org.slf4j.LoggerFactory; |
| 32 | + |
| 33 | +import javax.validation.constraints.NotNull; |
| 34 | + |
| 35 | +/** |
| 36 | + * Hive data node info |
| 37 | + */ |
| 38 | +@Data |
| 39 | +@Builder |
| 40 | +@NoArgsConstructor |
| 41 | +@AllArgsConstructor |
| 42 | +@ApiModel("Hive data node info") |
| 43 | +public class HiveDataNodeDTO { |
| 44 | + |
| 45 | + private static final Logger LOGGER = LoggerFactory.getLogger(HiveDataNodeDTO.class); |
| 46 | + |
| 47 | + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); // thread safe |
| 48 | + |
| 49 | + @ApiModelProperty("Hive JDBC URL, such as jdbc:hive2://${ip}:${port}") |
| 50 | + private String jdbcUrl; |
| 51 | + |
| 52 | + @ApiModelProperty("Version for Hive, such as: 3.2.1") |
| 53 | + private String hiveVersion; |
| 54 | + |
| 55 | + @ApiModelProperty("Config directory of Hive on HDFS, needed by sort in light mode, must include hive-site.xml") |
| 56 | + private String hiveConfDir; |
| 57 | + |
| 58 | + @ApiModelProperty("HDFS default FS, such as: hdfs://127.0.0.1:9000") |
| 59 | + private String hdfsPath; |
| 60 | + |
| 61 | + @ApiModelProperty("Hive warehouse path, such as: /user/hive/warehouse/") |
| 62 | + private String warehouse; |
| 63 | + |
| 64 | + @ApiModelProperty("User and group information for writing data to HDFS") |
| 65 | + private String hdfsUgi; |
| 66 | + |
| 67 | + /** |
| 68 | + * Get the dto instance from the request |
| 69 | + */ |
| 70 | + public static HiveDataNodeDTO getFromRequest(HiveDataNodeRequest request) throws Exception { |
| 71 | + return HiveDataNodeDTO.builder() |
| 72 | + .jdbcUrl(request.getJdbcUrl()) |
| 73 | + .hiveVersion(request.getHiveVersion()) |
| 74 | + .hiveConfDir(request.getHiveConfDir()) |
| 75 | + .hdfsPath(request.getHdfsPath()) |
| 76 | + .warehouse(request.getWarehouse()) |
| 77 | + .hdfsUgi(request.getHdfsUgi()) |
| 78 | + .build(); |
| 79 | + } |
| 80 | + |
| 81 | + /** |
| 82 | + * Get the dto instance from the JSON string. |
| 83 | + */ |
| 84 | + public static HiveDataNodeDTO getFromJson(@NotNull String extParams) { |
| 85 | + try { |
| 86 | + OBJECT_MAPPER.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); |
| 87 | + return OBJECT_MAPPER.readValue(extParams, HiveDataNodeDTO.class); |
| 88 | + } catch (Exception e) { |
| 89 | + LOGGER.error("Failed to extract additional parameters for hive data node: ", e); |
| 90 | + throw new BusinessException(ErrorCodeEnum.GROUP_INFO_INCORRECT.getMessage()); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | +} |
0 commit comments