Search in sources :

Example 11 with ExternalException

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);
}
Also used : ExternalException(com.baidu.hugegraph.exception.ExternalException) File(java.io.File) ExternalException(com.baidu.hugegraph.exception.ExternalException) Bean(org.springframework.context.annotation.Bean)

Example 12 with ExternalException

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");
    }
}
Also used : UnknownHostException(java.net.UnknownHostException) ExternalException(com.baidu.hugegraph.exception.ExternalException) InetAddress(java.net.InetAddress)

Example 13 with ExternalException

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;
}
Also used : FileMapping(com.baidu.hugegraph.entity.load.FileMapping) FileSetting(com.baidu.hugegraph.entity.load.FileSetting) ExternalException(com.baidu.hugegraph.exception.ExternalException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 14 with ExternalException

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;
}
Also used : FileMapping(com.baidu.hugegraph.entity.load.FileMapping) ExternalException(com.baidu.hugegraph.exception.ExternalException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 15 with ExternalException

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();
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) FileMapping(com.baidu.hugegraph.entity.load.FileMapping) ArrayList(java.util.ArrayList) JobManager(com.baidu.hugegraph.entity.load.JobManager) ExternalException(com.baidu.hugegraph.exception.ExternalException) JobManagerReasonResult(com.baidu.hugegraph.entity.load.JobManagerReasonResult) GetMapping(org.springframework.web.bind.annotation.GetMapping)

Aggregations

ExternalException (com.baidu.hugegraph.exception.ExternalException)42 HugeClient (com.baidu.hugegraph.driver.HugeClient)14 FileMapping (com.baidu.hugegraph.entity.load.FileMapping)11 ServerException (com.baidu.hugegraph.exception.ServerException)11 GraphConnection (com.baidu.hugegraph.entity.GraphConnection)9 JobManager (com.baidu.hugegraph.entity.load.JobManager)9 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)9 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)8 PostMapping (org.springframework.web.bind.annotation.PostMapping)8 LoadTask (com.baidu.hugegraph.entity.load.LoadTask)5 VertexLabel (com.baidu.hugegraph.structure.schema.VertexLabel)5 PutMapping (org.springframework.web.bind.annotation.PutMapping)5 EdgeLabel (com.baidu.hugegraph.structure.schema.EdgeLabel)4 PropertyKey (com.baidu.hugegraph.structure.schema.PropertyKey)4 InternalException (com.baidu.hugegraph.exception.InternalException)3 GetMapping (org.springframework.web.bind.annotation.GetMapping)3 EdgeMapping (com.baidu.hugegraph.entity.load.EdgeMapping)2 VertexMapping (com.baidu.hugegraph.entity.load.VertexMapping)2 GremlinCollection (com.baidu.hugegraph.entity.query.GremlinCollection)2 ClientException (com.baidu.hugegraph.rest.ClientException)2