Search in sources :

Example 6 with GraphConnection

use of com.baidu.hugegraph.entity.GraphConnection in project incubator-hugegraph-toolchain by apache.

the class LoadTaskController method start.

@PostMapping("start")
public List<LoadTask> start(@PathVariable("connId") int connId, @PathVariable("jobId") int jobId, @RequestParam("file_mapping_ids") List<Integer> fileIds) {
    GraphConnection connection = this.connService.get(connId);
    if (connection == null) {
        throw new ExternalException("graph-connection.not-exist.id", connId);
    }
    JobManager jobEntity = this.jobService.get(jobId);
    Ex.check(jobEntity != null, "job-manager.not-exist.id", jobId);
    Ex.check(jobEntity.getJobStatus() == JobStatus.SETTING, "load.task.start.no-permission");
    boolean existError = false;
    try {
        List<LoadTask> tasks = new ArrayList<>();
        for (Integer fileId : fileIds) {
            FileMapping fileMapping = this.fmService.get(fileId);
            if (fileMapping == null) {
                throw new ExternalException("file-mapping.not-exist.id", fileId);
            }
            tasks.add(this.service.start(connection, fileMapping));
        }
        return tasks;
    } catch (Exception e) {
        existError = true;
        throw e;
    } finally {
        if (existError) {
            jobEntity.setJobStatus(JobStatus.FAILED);
        } else {
            jobEntity.setJobStatus(JobStatus.LOADING);
        }
        jobEntity.setUpdateTime(HubbleUtil.nowDate());
        this.jobService.update(jobEntity);
    }
}
Also used : LoadTask(com.baidu.hugegraph.entity.load.LoadTask) FileMapping(com.baidu.hugegraph.entity.load.FileMapping) GraphConnection(com.baidu.hugegraph.entity.GraphConnection) ArrayList(java.util.ArrayList) JobManager(com.baidu.hugegraph.entity.load.JobManager) ExternalException(com.baidu.hugegraph.exception.ExternalException) ExternalException(com.baidu.hugegraph.exception.ExternalException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 7 with GraphConnection

use of com.baidu.hugegraph.entity.GraphConnection in project incubator-hugegraph-toolchain by apache.

the class LoadTaskController method pause.

@PostMapping("pause")
public LoadTask pause(@PathVariable("connId") int connId, @PathVariable("jobId") int jobId, @RequestParam("task_id") int taskId) {
    GraphConnection connection = this.connService.get(connId);
    if (connection == null) {
        throw new ExternalException("graph-connection.not-exist.id", connId);
    }
    JobManager jobEntity = this.jobService.get(jobId);
    Ex.check(jobEntity != null, "job-manager.not-exist.id", jobId);
    Ex.check(jobEntity.getJobStatus() == JobStatus.LOADING, "load.task.pause.no-permission");
    try {
        return this.service.pause(taskId);
    } finally {
        jobEntity.setJobStatus(JobStatus.LOADING);
        jobEntity.setUpdateTime(HubbleUtil.nowDate());
        this.jobService.update(jobEntity);
    }
}
Also used : GraphConnection(com.baidu.hugegraph.entity.GraphConnection) JobManager(com.baidu.hugegraph.entity.load.JobManager) ExternalException(com.baidu.hugegraph.exception.ExternalException) PostMapping(org.springframework.web.bind.annotation.PostMapping)

Example 8 with GraphConnection

use of com.baidu.hugegraph.entity.GraphConnection in project incubator-hugegraph-toolchain by apache.

the class GraphConnectionController method checkEntityUnique.

private void checkEntityUnique(GraphConnection newEntity, boolean creating) {
    List<GraphConnection> oldEntities = this.connService.listAll();
    for (GraphConnection oldEntity : oldEntities) {
        // NOTE: create should check all, update check others
        if (!creating && oldEntity.getId().equals(newEntity.getId())) {
            continue;
        }
        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())), "graph-connection.exist.graph-host-port", oldEntity.getGraph(), oldEntity.getHost(), oldEntity.getPort());
    }
}
Also used : GraphConnection(com.baidu.hugegraph.entity.GraphConnection)

Example 9 with GraphConnection

use of com.baidu.hugegraph.entity.GraphConnection in project incubator-hugegraph-toolchain by apache.

the class GraphConnectionController method update.

@PutMapping("{id}")
public GraphConnection update(@PathVariable("id") int id, @RequestBody GraphConnection newEntity) {
    this.checkIdSameAsBody(id, newEntity);
    this.checkParamsValid(newEntity, false);
    this.checkAddressSecurity(newEntity);
    // Check exist connection with this id
    GraphConnection oldEntity = this.connService.get(id);
    if (oldEntity == null) {
        throw new ExternalException("graph-connection.not-exist.id", id);
    }
    GraphConnection entity = this.mergeEntity(oldEntity, newEntity);
    // Make sure the updated connection doesn't conflict with exists
    this.checkEntityUnique(entity, false);
    this.sslService.configSSL(this.config, entity);
    HugeClient client = HugeClientUtil.tryConnect(entity);
    this.connService.update(entity);
    this.poolService.put(entity, client);
    return entity;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) GraphConnection(com.baidu.hugegraph.entity.GraphConnection) ExternalException(com.baidu.hugegraph.exception.ExternalException) PutMapping(org.springframework.web.bind.annotation.PutMapping)

Example 10 with GraphConnection

use of com.baidu.hugegraph.entity.GraphConnection in project incubator-hugegraph-toolchain by apache.

the class GraphConnectionController method delete.

@DeleteMapping("{id}")
public GraphConnection delete(@PathVariable("id") int id) {
    GraphConnection oldEntity = this.connService.get(id);
    if (oldEntity == null) {
        throw new ExternalException("graph-connection.not-exist.id", id);
    }
    this.connService.remove(id);
    this.poolService.remove(oldEntity);
    return oldEntity;
}
Also used : GraphConnection(com.baidu.hugegraph.entity.GraphConnection) ExternalException(com.baidu.hugegraph.exception.ExternalException) DeleteMapping(org.springframework.web.bind.annotation.DeleteMapping)

Aggregations

GraphConnection (com.baidu.hugegraph.entity.GraphConnection)11 ExternalException (com.baidu.hugegraph.exception.ExternalException)9 JobManager (com.baidu.hugegraph.entity.load.JobManager)5 PostMapping (org.springframework.web.bind.annotation.PostMapping)5 HugeClient (com.baidu.hugegraph.driver.HugeClient)3 FileMapping (com.baidu.hugegraph.entity.load.FileMapping)1 LoadTask (com.baidu.hugegraph.entity.load.LoadTask)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Test (org.junit.Test)1 DeleteMapping (org.springframework.web.bind.annotation.DeleteMapping)1 GetMapping (org.springframework.web.bind.annotation.GetMapping)1 PutMapping (org.springframework.web.bind.annotation.PutMapping)1