use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.
the class HubbleConfig method hugeConfig.
@Bean
public HugeConfig hugeConfig() {
String[] args = this.arguments.getSourceArgs();
if (args.length > 1) {
throw new ExternalException("HugeGraphHubble accept up to one param as config file");
} else if (args.length == 0) {
args = new String[] { Constant.CONFIG_FILE };
}
// Register hubble config options
OptionSpace.register(Constant.MODULE_NAME, HubbleOptions.instance());
String conf = args[0];
try {
String path = HubbleConfig.class.getClassLoader().getResource(conf).getPath();
File file = new File(path);
if (file.exists() && file.isFile()) {
conf = path;
}
} catch (Exception ignored) {
}
return new HugeConfig(conf);
}
use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.
the class GraphConnectionController method checkAddressSecurity.
private void checkAddressSecurity(GraphConnection newEntity) {
String host = newEntity.getHost();
Integer port = newEntity.getPort();
InetAddress address;
try {
address = InetAddress.getByName(host);
} catch (UnknownHostException e) {
throw new ExternalException("graph-connection.host.unresolved");
}
String ip = address.getHostAddress();
log.debug("The host: {}, ip: {}", address.getHostName(), ip);
List<String> ipWhiteList = this.config.get(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);
if (!portWhiteList.contains(-1)) {
Ex.check(portWhiteList.contains(port), "graph-connection.port.unauthorized");
}
}
use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.
the class FileMappingController method fileSetting.
@PostMapping("{id}/file-setting")
public FileMapping fileSetting(@PathVariable("id") int id, @RequestBody FileSetting newEntity) {
Ex.check(!StringUtils.isEmpty(newEntity.getDelimiter()), "load.file-mapping.file-setting.delimiter-cannot-be-empty");
Ex.check(!StringUtils.isEmpty(newEntity.getCharset()), "load.file-mapping.file-setting.charset-cannot-be-empty");
Ex.check(!StringUtils.isEmpty(newEntity.getDateFormat()), "load.file-mapping.file-setting.dateformat-cannot-be-empty");
Ex.check(!StringUtils.isEmpty(newEntity.getTimeZone()), "load.file-mapping.file-setting.timezone-cannot-be-empty");
Ex.check(!StringUtils.isEmpty(newEntity.getSkippedLine()), "load.file-mapping.file-setting.skippedline-cannot-be-empty");
FileMapping mapping = this.service.get(id);
if (mapping == null) {
throw new ExternalException("load.file-mapping.not-exist.id", id);
}
// Change format to TEXT if needed
newEntity.changeFormatIfNeeded();
FileSetting oldEntity = mapping.getFileSetting();
FileSetting entity = this.mergeEntity(oldEntity, newEntity);
mapping.setFileSetting(entity);
// Read column names and values then fill it
this.service.extractColumns(mapping);
this.service.update(mapping);
return mapping;
}
use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.
the class FileMappingController method addEdgeMapping.
@PostMapping("{id}/edge-mappings")
public FileMapping addEdgeMapping(@PathVariable("connId") int connId, @PathVariable("id") int id, @RequestBody EdgeMapping newEntity) {
FileMapping mapping = this.service.get(id);
if (mapping == null) {
throw new ExternalException("load.file-mapping.not-exist.id", id);
}
this.checkEdgeMappingValid(connId, newEntity, mapping);
newEntity.setId(HubbleUtil.generateSimpleId());
mapping.getEdgeMappings().add(newEntity);
this.service.update(mapping);
return mapping;
}
use of com.baidu.hugegraph.exception.ExternalException in project incubator-hugegraph-toolchain by apache.
the class JobManagerController method reason.
@GetMapping("{id}/reason")
public Response reason(@PathVariable("connId") int connId, @PathVariable("id") int id) {
JobManager job = this.service.get(id);
if (job == null) {
throw new ExternalException("job.manager.not-exist.id", id);
}
List<LoadTask> tasks = this.taskService.batchTasks(job.getId());
List<JobManagerReasonResult> reasonResults = new ArrayList<>();
tasks.forEach(task -> {
JobManagerReasonResult reasonResult = new JobManagerReasonResult();
int fileId = task.getFileId();
String reason = "";
if (task.getStatus() == LoadStatus.FAILED) {
FileMapping mapping = this.fmService.get(fileId);
reason = this.taskService.readLoadFailedReason(mapping);
}
reasonResult.setTaskId(task.getJobId());
reasonResult.setFileId(task.getFileId());
reasonResult.setFileName(task.getFileName());
reasonResult.setReason(reason);
reasonResults.add(reasonResult);
});
return Response.builder().status(Constant.STATUS_OK).data(reasonResults).build();
}
Aggregations