Package org.lab41.dendrite.metagraph

Examples of org.lab41.dendrite.metagraph.MetaGraphTx


    @PreAuthorize("hasPermission(#graphId, 'graph', 'admin')")
    @RequestMapping(value = "/graphs/{graphId}", method = RequestMethod.GET)
    @ResponseBody
    public GetGraphResponse getGraph(@PathVariable String graphId) throws NotFound {

        MetaGraphTx tx = metaGraphService.buildTransaction().readOnly().start();

        try {
            GraphMetadata graphMetadata = tx.getGraph(graphId);
            if (graphMetadata == null) {
                throw new NotFound(GraphMetadata.class, graphId);
            }

            // FIXME: Temporary hack to force loading the graph until the UI can handle it occurring asynchronously.
            metaGraphService.getDendriteGraph(graphMetadata.getId());

            return new GetGraphResponse(graphMetadata);
        } finally {
            tx.commit();
        }
    }
View Full Code Here


        return authenticated;
    }

    boolean checkUserForJob(Authentication authentication, Serializable targetId) {
        MetaGraphTx tx = metaGraphService.buildTransaction().start();
        boolean authenticated;

        try {
            JobMetadata jobMetadata = tx.getJob((String) targetId);
            if (jobMetadata == null) {
                return false;
            }

            ProjectMetadata projectMetadata = jobMetadata.getProject();
            if (projectMetadata == null) {
                return false;
            }

            authenticated = checkAuthAgainstUserOfProject(tx, authentication, projectMetadata);
        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

        tx.commit();

        return authenticated;
    }
View Full Code Here

    @PreAuthorize("hasPermission(#graphId, 'graph', 'admin')")
    @RequestMapping(value = "/graphs/{graphId}/random", method = RequestMethod.GET)
    public ResponseEntity<Map<String, Object>> getRandom(@PathVariable String graphId) throws NotFound {

        Map<String, Object> response = new HashMap<>();
        MetaGraphTx tx = metaGraphService.buildTransaction().readOnly().start();

        try {
            GraphMetadata graphMetadata = tx.getGraph(graphId);
            if (graphMetadata == null) {
                throw new NotFound(GraphMetadata.class, graphId);
            }

            DendriteGraph graph = metaGraphService.getDendriteGraph(graphId);

            DendriteGraphTx dendriteGraphTx = graph.buildTransaction().readOnly().start();

            try {
                Map<Object, Object> verticesMap = new HashMap<>();
                Map<Object, Object> edgesMap = new HashMap<>();

                for (Vertex vertex : dendriteGraphTx.query().limit(300).vertices()) {
                    addVertex(verticesMap, vertex);
                }

                for (Edge edge : dendriteGraphTx.query().limit(300).edges()) {
                    addEdge(verticesMap, edgesMap, edge);
                }

                response.put("vertices", new ArrayList<>(verticesMap.values()));
                response.put("edges", new ArrayList<>(edgesMap.values()));
            } finally {
                dendriteGraphTx.commit();
            }

            return new ResponseEntity<>(response, HttpStatus.OK);
        } finally {
            tx.commit();
        }
    }
View Full Code Here

    @PreAuthorize("hasPermission(#graphId, 'graph', 'admin')")
    @RequestMapping(value = "/graphs/{graphId}", method = RequestMethod.DELETE)
    public ResponseEntity<Map<String, Object>> deleteGraph(@PathVariable String graphId) throws NotFound {

        Map<String, Object> response = new HashMap<>();
        MetaGraphTx tx = metaGraphService.newTransaction();

        try {
            GraphMetadata graphMetadata = tx.getGraph(graphId);
            if (graphMetadata == null) {
                throw new NotFound(GraphMetadata.class, graphId);
            }

            try {
                tx.deleteGraph(graphMetadata);
            } catch (Exception e) {
                response.put("status", "error");
                response.put("msg", e.toString());
                tx.rollback();
                return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
            }

            response.put("msg", "deleted");

            return new ResponseEntity<>(response, HttpStatus.OK);
        } finally {
            tx.commit();
        }
    }
View Full Code Here

    @PreAuthorize("hasPermission(#projectId, 'project', 'admin')")
    @RequestMapping(value = "/projects/{projectId}/graphs", method = RequestMethod.GET)
    @ResponseBody
    public GetGraphsResponse getGraphs(@PathVariable String projectId) throws NotFound {

        MetaGraphTx tx = metaGraphService.buildTransaction().readOnly().start();

        try {
            ProjectMetadata projectMetadata = tx.getProject(projectId);
            if (projectMetadata == null) {
                throw new NotFound(ProjectMetadata.class, projectId);
            }

            List<GetGraphResponse> graphs = new ArrayList<>();
            for (GraphMetadata graphMetadata : projectMetadata.getGraphs()) {
                graphs.add(new GetGraphResponse(graphMetadata));
            }

            return new GetGraphsResponse(graphs);
        } finally {
            tx.commit();
        }
    }
View Full Code Here

        if (result.hasErrors()) {
            throw new BindingException(result);
        }

        MetaGraphTx tx = metaGraphService.newTransaction();
        GetGraphResponse getGraphResponse;
        HttpHeaders headers = new HttpHeaders();

        try {
            ProjectMetadata projectMetadata = tx.getProject(projectId);
            if (projectMetadata == null) {
                throw new NotFound(ProjectMetadata.class, projectId);
            }

            GraphMetadata graphMetadata = tx.createGraph(projectMetadata);
            graphMetadata.setProperties(item.getProperties());

            headers.setLocation(builder.path("/graphs/{graphId}").buildAndExpand(projectMetadata.getId()).toUri());

            getGraphResponse = new GetGraphResponse(graphMetadata);
        } catch (Throwable t) {
            tx.rollback();
            throw t;
        }

        tx.commit();

        return new ResponseEntity<>(getGraphResponse, headers, HttpStatus.CREATED);
    }
View Full Code Here

    @PreAuthorize("hasPermission(#projectId, 'project', 'admin')")
    @RequestMapping(value = "/projects/{projectId}/current-graph", method = RequestMethod.GET)
    @ResponseBody
    public GetGraphResponse getCurrentGraph(@PathVariable String projectId) throws NotFound {

        MetaGraphTx tx = metaGraphService.buildTransaction().readOnly().start();

        try {
            ProjectMetadata projectMetadata = tx.getProject(projectId);
            if (projectMetadata == null) {
                throw new NotFound(ProjectMetadata.class, projectId);
            }

            GraphMetadata graphMetadata = projectMetadata.getCurrentGraph();

            // FIXME: Temporary hack to force loading the graph until the UI can handle it occurring asynchronously.
            metaGraphService.getDendriteGraph(graphMetadata.getId());

            return new GetGraphResponse(graphMetadata);
        } finally {
            tx.commit();
        }
    }
View Full Code Here

        try {
            copyIndices(srcGraph, dstGraph);
            copyGraph(srcGraph, dstGraph);

            // Update the branch to point the new graph.
            MetaGraphTx tx = metaGraph.newTransaction();
            try {
                BranchMetadata branchMetadata = tx.getBranch(branchId);
                branchMetadata.setGraph(tx.getGraph(dstGraph.getId()));
                tx.commit();
            } catch (Throwable t) {
                tx.rollback();
                throw t;
            }

            setJobState(jobId, JobMetadata.DONE);
        } catch (Throwable t) {
View Full Code Here

                doneJobs.add(hadoopJobId);

                if (jobMap.containsKey(hadoopJobId)) {
                    setJobState(jobMap.get(hadoopJobId), JobMetadata.DONE);
                } else {
                    MetaGraphTx tx = metaGraph.newTransaction();
                    JobMetadata jobMetadata = tx.getJob(jobId);
                    JobMetadata childJobMetadata = tx.createJob(jobMetadata);
                    childJobMetadata.setName("faunusHadoopJob");
                    childJobMetadata.setState(JobMetadata.DONE);
                    childJobMetadata.setProgress(1.0f);
                    childJobMetadata.setMapreduceJobId(hadoopJobId.toString());
                    tx.commit();

                    jobMap.put(hadoopJobId, childJobMetadata.getId());
                }
            }
        }

        for (Job hadoopJob: failedJobs) {
            JobID hadoopJobId = hadoopJob.getJobID();
            logger.debug("found failed hadoop job:", hadoopJobId.toString());

            if (jobMap.containsKey(hadoopJobId)) {
                setJobState(jobMap.get(hadoopJobId), JobMetadata.ERROR);
            } else {
                MetaGraphTx tx = metaGraph.newTransaction();
                JobMetadata jobMetadata = tx.getJob(jobId);
                JobMetadata childJobMetadata = tx.createJob(jobMetadata);
                childJobMetadata.setName("faunusHadoopJob");
                childJobMetadata.setMapreduceJobId(hadoopJobId.toString());
                childJobMetadata.setState(JobMetadata.ERROR);
                tx.commit();

                jobMap.put(hadoopJobId, childJobMetadata.getId());
            }
        }

        float totalProgress;

        // Don't divide by zero if we don't have any jobs in progress.
        if (jobsInProgress.isEmpty()) {
            totalProgress = 1;
        } else {
            totalProgress = ((float) successfulJobs.size()) / ((float) jobsInProgress.size());
        }

        Job hadoopRunningJob = jobControl.getRunningJob();
        if (hadoopRunningJob != null) {
            JobID hadoopJobId = hadoopRunningJob.getJobID();
            logger.debug("found active hadoop job:", hadoopJobId.toString());

            JobStatus status = hadoopRunningJob.getStatus();
            float progress = 0.25f * (
                    status.getSetupProgress() +
                            status.getMapProgress() +
                            status.getReduceProgress() +
                            status.getCleanupProgress());

            logger.debug("found progress: "
                    + status.getSetupProgress() + " "
                    + status.getMapProgress() + " "
                    + status.getReduceProgress() + " "
                    + status.getCleanupProgress() + " "
                    + progress);

            if (jobMap.containsKey(hadoopJobId)) {
                setJobProgress(jobMap.get(hadoopJobId), progress);
            } else {
                MetaGraphTx tx = metaGraph.newTransaction();
                JobMetadata jobMetadata = tx.getJob(jobId);
                JobMetadata childJobMetadata = tx.createJob(jobMetadata);
                childJobMetadata.setName("faunusHadoopJob");
                childJobMetadata.setProgress(progress);
                childJobMetadata.setState(JobMetadata.RUNNING);
                childJobMetadata.setMapreduceJobId(hadoopJobId.toString());
                tx.commit();

                jobMap.put(hadoopJobId, childJobMetadata.getId());
            }

            JobMetadata.Id jobMetadataId = jobMap.get(hadoopJobId);
View Full Code Here

        MetaGraphTx tx = metaGraphService.buildTransaction().readOnly().start();

        try {
            JobMetadata jobMetadata = tx.getJob(jobId);
            if (jobMetadata == null) {
                throw new NotFound(JobMetadata.class, jobId);
            }

            return new GetJobResponse(jobMetadata);
        } finally {
            tx.commit();
View Full Code Here

TOP

Related Classes of org.lab41.dendrite.metagraph.MetaGraphTx

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.