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

chore(hubble): Enhance code style in hubble #592

Merged
merged 13 commits into from
Mar 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static void initEnv() {

@Override
protected SpringApplicationBuilder configure(
SpringApplicationBuilder builder) {
SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public final class Constant {
public static final String CONFIG_FILE = "hugegraph-hubble.properties";

public static final String CONTROLLER_PACKAGE =
"org.apache.hugegraph.controller";
"org.apache.hugegraph.controller";

public static final String COOKIE_USER = "user";
public static final String API_V1_1 = "/api/v1.1/";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
package org.apache.hugegraph.common;

public interface Mergeable {

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.File;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.exception.ExternalException;
import org.apache.hugegraph.options.HubbleOptions;
import org.slf4j.Logger;
Expand All @@ -29,8 +30,6 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import org.apache.hugegraph.common.Constant;

@Configuration
public class HubbleConfig {

Expand All @@ -44,7 +43,7 @@ public HugeConfig hugeConfig() {
String[] args = this.arguments.getSourceArgs();
if (args.length > 1) {
throw new ExternalException(
"HugeGraphHubble accept up to one param as config file");
"HugeGraphHubble accept up to one param as config file");
} else if (args.length == 0) {
args = new String[]{Constant.CONFIG_FILE};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@
import java.io.IOException;
import java.util.Map;

import org.apache.hugegraph.common.Response;
import org.apache.hugegraph.structure.graph.Edge;
import org.apache.hugegraph.structure.graph.Vertex;
import org.springframework.boot.jackson.JsonComponent;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.json.Jackson2ObjectMapperBuilder;

import org.apache.hugegraph.common.Response;
import org.apache.hugegraph.structure.graph.Edge;
import org.apache.hugegraph.structure.graph.Vertex;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand Down Expand Up @@ -98,15 +98,15 @@ public void serialize(Edge edge, JsonGenerator generator,

private static void writeIdField(String fieldName, Object id,
JsonGenerator generator)
throws IOException {
throws IOException {
// Serialize id to string
generator.writeStringField(fieldName, id.toString());
}

private static void writePropertiesField(Map<String, Object> properties,
JsonGenerator generator,
SerializerProvider provider)
throws IOException {
throws IOException {
// Start write properties
generator.writeFieldName("properties");
generator.writeStartObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.handler.MessageSourceHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.handler.MessageSourceHandler;

@RestController
@RequestMapping("about")
// TODO: delete the class or keep it?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@

import java.util.List;

import org.springframework.util.StringUtils;

import org.apache.hugegraph.common.Identifiable;
import org.apache.hugegraph.common.Mergeable;
import org.apache.hugegraph.util.EntityUtil;
import org.apache.hugegraph.util.Ex;
import org.springframework.util.StringUtils;

public abstract class BaseController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.common.Response;
import org.apache.hugegraph.config.HugeConfig;
Expand All @@ -48,6 +37,17 @@
import org.apache.hugegraph.util.Ex;
import org.apache.hugegraph.util.HubbleUtil;
import org.apache.hugegraph.util.HugeClientUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;

import lombok.extern.log4j.Log4j2;
Expand Down Expand Up @@ -201,14 +201,14 @@ private void checkAddressSecurity(GraphConnection newEntity) {
log.debug("The host: {}, ip: {}", address.getHostName(), ip);

List<String> ipWhiteList = this.config.get(
HubbleOptions.CONNECTION_IP_WHITE_LIST);
HubbleOptions.CONNECTION_IP_WHITE_LIST);
if (!ipWhiteList.contains("*")) {
Ex.check(ipWhiteList.contains(host) || ipWhiteList.contains(ip),
"graph-connection.host.unauthorized");
}

List<Integer> portWhiteList = this.config.get(
HubbleOptions.CONNECTION_PORT_WHITE_LIST);
HubbleOptions.CONNECTION_PORT_WHITE_LIST);
if (!portWhiteList.contains(-1)) {
Ex.check(portWhiteList.contains(port),
"graph-connection.port.unauthorized");
Expand All @@ -226,8 +226,8 @@ private void checkEntityUnique(GraphConnection newEntity,
Ex.check(!oldEntity.getName().equals(newEntity.getName()),
"graph-connection.exist.name", oldEntity.getName());
Ex.check(!(oldEntity.getGraph().equals(newEntity.getGraph()) &&
oldEntity.getHost().equals(newEntity.getHost()) &&
oldEntity.getPort().equals(newEntity.getPort())),
oldEntity.getHost().equals(newEntity.getHost()) &&
oldEntity.getPort().equals(newEntity.getPort())),
"graph-connection.exist.graph-host-port",
oldEntity.getGraph(), oldEntity.getHost(),
oldEntity.getPort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,16 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.entity.UserInfo;
import org.apache.hugegraph.service.UserInfoService;
import org.apache.hugegraph.util.E;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.entity.UserInfo;
import org.apache.hugegraph.service.UserInfoService;
import org.apache.hugegraph.util.E;

@RestController
@RequestMapping(Constant.API_VERSION + "setting")
public class SettingController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@

package org.apache.hugegraph.controller.algorithm;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.entity.algorithm.ShortestPath;
import org.apache.hugegraph.entity.query.GremlinResult;
import org.apache.hugegraph.service.algorithm.OltpAlgoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
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 org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.entity.algorithm.ShortestPath;
import org.apache.hugegraph.entity.query.GremlinResult;
import org.apache.hugegraph.service.algorithm.OltpAlgoService;

import lombok.extern.log4j.Log4j2;

@Log4j2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,6 @@
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriUtils;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.controller.BaseController;
import org.apache.hugegraph.entity.graph.EdgeEntity;
Expand All @@ -45,6 +36,14 @@
import org.apache.hugegraph.structure.graph.Edge;
import org.apache.hugegraph.structure.graph.Vertex;
import org.apache.hugegraph.util.Ex;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.util.UriUtils;

@RestController
@RequestMapping(Constant.API_VERSION + "graph-connections/{connId}/graph")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@
import java.util.Set;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.controller.BaseController;
import org.apache.hugegraph.entity.enums.JobStatus;
Expand All @@ -54,6 +42,18 @@
import org.apache.hugegraph.util.CollectionUtil;
import org.apache.hugegraph.util.Ex;
import org.apache.hugegraph.util.HubbleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.metadata.IPage;

import lombok.extern.log4j.Log4j2;
Expand Down Expand Up @@ -195,7 +195,7 @@ public FileMapping deleteVertexMapping(@PathVariable("id") int id,
boolean removed = mapping.getVertexMappings().remove(vertexMapping);
if (!removed) {
throw new ExternalException(
"load.file-mapping.vertex-mapping.not-exist.id", vmid);
"load.file-mapping.vertex-mapping.not-exist.id", vmid);
}
this.service.update(mapping);
return mapping;
Expand Down Expand Up @@ -252,7 +252,7 @@ public FileMapping deleteEdgeMapping(@PathVariable("id") int id,
boolean removed = mapping.getEdgeMappings().remove(edgeMapping);
if (!removed) {
throw new ExternalException(
"load.file-mapping.edge-mapping.not-exist.id", emid);
"load.file-mapping.edge-mapping.not-exist.id", emid);
}
this.service.update(mapping);
return mapping;
Expand Down Expand Up @@ -305,15 +305,15 @@ private void checkVertexMappingValid(int connId, VertexMapping vertexMapping,
vl.getPrimaryKeys().size(),
"load.file-mapping.vertex.id-fields-should-same-size-pks");
Ex.check(!CollectionUtils.containsAny(
vertexMapping.fieldMappingToMap().values(),
vl.getPrimaryKeys()),
vertexMapping.fieldMappingToMap().values(),
vl.getPrimaryKeys()),
"load.file-mapping.vertex.mapping-fields-cannot-contains-pk");
} else {
Ex.check(vertexMapping.getIdFields().size() == 1,
"load.file-mapping.vertex.id-fields-should-only-one");
}
Ex.check(CollectionUtil.allUnique(
vertexMapping.fieldMappingToMap().values()),
vertexMapping.fieldMappingToMap().values()),
"load.file-mapping.mapping-fields-should-no-duplicate");
this.checkMappingValid(vertexMapping, fileMapping);
}
Expand Down Expand Up @@ -341,7 +341,7 @@ private void checkEdgeMappingValid(int connId, EdgeMapping edgeMapping,
"load.file-mapping.edge.target-fields-should-in-column-names",
edgeMapping.getTargetFields(), columnNames);
Ex.check(CollectionUtil.allUnique(
edgeMapping.fieldMappingToMap().values()),
edgeMapping.fieldMappingToMap().values()),
"load.file-mapping.mapping-fields-should-no-duplicate");
this.checkMappingValid(edgeMapping, fileMapping);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,6 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import org.apache.hugegraph.common.Constant;
import org.apache.hugegraph.config.HugeConfig;
import org.apache.hugegraph.entity.enums.FileMappingStatus;
Expand All @@ -59,6 +48,16 @@
import org.apache.hugegraph.util.Ex;
import org.apache.hugegraph.util.FileUtil;
import org.apache.hugegraph.util.HubbleUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import lombok.extern.log4j.Log4j2;

Expand Down Expand Up @@ -259,13 +258,13 @@ private void checkFileValid(int connId, int jobId, JobManager jobEntity,

String format = FilenameUtils.getExtension(fileName);
List<String> formatWhiteList = this.config.get(
HubbleOptions.UPLOAD_FILE_FORMAT_LIST);
HubbleOptions.UPLOAD_FILE_FORMAT_LIST);
Ex.check(formatWhiteList.contains(format),
"load.upload.file.format.unsupported");

long fileSize = file.getSize();
long singleFileSizeLimit = this.config.get(
HubbleOptions.UPLOAD_SINGLE_FILE_SIZE_LIMIT);
HubbleOptions.UPLOAD_SINGLE_FILE_SIZE_LIMIT);
Ex.check(fileSize <= singleFileSizeLimit,
"load.upload.file.exceed-single-size",
FileUtils.byteCountToDisplaySize(singleFileSizeLimit));
Expand All @@ -277,7 +276,7 @@ private void checkFileValid(int connId, int jobId, JobManager jobEntity,
"load.upload.file.existed", fileName);

long totalFileSizeLimit = this.config.get(
HubbleOptions.UPLOAD_TOTAL_FILE_SIZE_LIMIT);
HubbleOptions.UPLOAD_TOTAL_FILE_SIZE_LIMIT);
List<FileMapping> fileMappings = this.service.listAll();
long currentTotalSize = fileMappings.stream()
.map(FileMapping::getTotalSize)
Expand Down
Loading
Loading