/** * Performs the given operation on the store. * If the operation does not have a view then the graph view is used. * * @param operation the operation to be executed. * @param user the user executing the operation. * @throws OperationException if an operation fails */ public void execute(final Operation operation, final User user) throws OperationException { execute(new GraphRequest<>(operation, user)); }
/** * Performs the given operation on the store. * If the operation does not have a view then the graph view is used. * The context will be cloned and a new jobId will be created. * * @param operation the operation to be executed. * @param context the user context for the execution of the operation * @throws OperationException if an operation fails */ public void execute(final Operation operation, final Context context) throws OperationException { execute(new GraphRequest<>(operation, context)); }
/** * Performs the given output operation on the store. * If the operation does not have a view then the graph view is used. * * @param operation the output operation to be executed. * @param user the user executing the operation. * @param <O> the operation chain output type. * @return the operation result. * @throws OperationException if an operation fails */ public <O> O execute(final Output<O> operation, final User user) throws OperationException { return execute(new GraphRequest<>(operation, user)).getResult(); }
/** * Performs the given output operation on the store. * If the operation does not have a view then the graph view is used. * The context will be cloned and a new jobId will be created. * * @param operation the output operation to be executed. * @param context the user context for the execution of the operation. * @param <O> the operation chain output type. * @return the operation result. * @throws OperationException if an operation fails */ public <O> O execute(final Output<O> operation, final Context context) throws OperationException { return execute(new GraphRequest<>(operation, context)).getResult(); }
private void waitUntilJobHashFinished(final User user, final Graph graph, final JobDetail initialJobDetail) throws OperationException { JobDetail jobDetail = initialJobDetail; while (JobStatus.RUNNING.equals(jobDetail.getStatus())) { jobDetail = graph.execute(new GetJobDetails.Builder() .jobId(jobDetail.getJobId()) .build(), user); try { Thread.sleep(100); } catch (final InterruptedException e) { throw new RuntimeException(e); } } }
@Override @SuppressWarnings("unchecked") public void add(final String key, final Iterable<?> elements) throws OperationException { if (null == elements) { return; } graph.execute(new AddElements.Builder() .input((Iterable<Element>) elements) .build(), context.getUser()); }
private void waitUntilJobHashFinished(final User user, final Graph graph, final JobDetail initialJobDetail) throws OperationException { JobDetail jobDetail = initialJobDetail; while (JobStatus.RUNNING.equals(jobDetail.getStatus())) { jobDetail = graph.execute(new GetJobDetails.Builder() .jobId(jobDetail.getJobId()) .build(), user); try { Thread.sleep(100); } catch (InterruptedException e) { throw new RuntimeException(e); } } } }
protected void runExampleNoResult(final Operation<?, Void> operation) { log("#### " + getMethodNameAsSentence(1) + "\n"); printJava(JavaSourceUtil.getRawJavaSnippet(getClass(), "example/example-graph", " " + getMethodName(1) + "() {", String.format("---%n"), "// ----")); printAsJson(operation); printOperationClass(operation); try { getGraph().execute(operation, new User("user01")); } catch (OperationException e) { throw new RuntimeException(e); } log(METHOD_DIVIDER); }
protected void runExampleNoResult(final Operation operation, final String description) { log("#### " + getMethodNameAsSentence(1) + "\n"); if (StringUtils.isNotBlank(description)) { log(description + "\n"); } printMethodJavaSnippet(); printAsJson(operation); try { getGraph().execute(operation, new User("user01")); } catch (final OperationException e) { throw new RuntimeException(e); } log(METHOD_DIVIDER); }
@Override public O doOperation(final OP operation, final Context context, final Store store) throws OperationException { final Collection<Graph> graphs = ((FederatedStore) store).getGraphs(context.getUser(), operation.getOption(KEY_OPERATION_OPTIONS_GRAPH_IDS)); final List<O> results = new ArrayList<>(graphs.size()); for (final Graph graph : graphs) { final OP updatedOp = FederatedStoreUtil.updateOperationForGraph(operation, graph); if (null != updatedOp) { O execute = null; try { execute = graph.execute(updatedOp, context); } catch (final Exception e) { if (!Boolean.valueOf(getSkipFailedFederatedStoreExecute(updatedOp))) { throw new OperationException(FederatedStoreUtil.createOperationErrorMsg(operation, graph.getGraphId(), e), e); } } if (null != execute) { results.add(execute); } } } try { return mergeResults(results, operation, context, store); } catch (final Exception e) { throw new OperationException(e); } }
protected <RESULT_TYPE> RESULT_TYPE runExample(final OperationChain<RESULT_TYPE> operationChain) { log("#### " + getMethodNameAsSentence(1) + "\n"); printGraph(); printJava(JavaSourceUtil.getRawJavaSnippet(getClass(), "example/example-graph", " " + getMethodName(1) + "() {", String.format("---%n"), "// ----")); printAsJson(operationChain); final RESULT_TYPE result; try { result = getGraph().execute( operationChain, new User("user01")); } catch (OperationException e) { throw new RuntimeException(e); } logResult(result); log(METHOD_DIVIDER); return result; }
@Override public CloseableIterable<O_ITEM> doOperation(final FederatedOperationChain<I, O_ITEM> operation, final Context context, final Store store) throws OperationException { final Collection<Graph> graphs = ((FederatedStore) store).getGraphs(context.getUser(), operation.getOption(KEY_OPERATION_OPTIONS_GRAPH_IDS)); final List<Object> results = new ArrayList<>(graphs.size()); for (final Graph graph : graphs) { final OperationChain opChain = operation.getOperationChain(); OperationHandlerUtil.updateOperationInput(opChain, operation.getInput()); final OperationChain updatedOp = FederatedStoreUtil.updateOperationForGraph(opChain, graph); if (null != updatedOp) { Object result = null; try { result = graph.execute(updatedOp, context); } catch (final Exception e) { if (!Boolean.valueOf(updatedOp.getOption(KEY_SKIP_FAILED_FEDERATED_STORE_EXECUTE))) { throw new OperationException(FederatedStoreUtil.createOperationErrorMsg(operation, graph.getGraphId(), e), e); } } if (null != result) { results.add(result); } } } return mergeResults(results, operation, context, store); }
protected <RESULT_TYPE> RESULT_TYPE runExample(final Operation<?, RESULT_TYPE> operation) { log("#### " + getMethodNameAsSentence(1) + "\n"); printGraph(); printJava(JavaSourceUtil.getRawJavaSnippet(getClass(), "example/example-graph", " " + getMethodName(1) + "() {", String.format("---%n"), "// ----")); printAsJson(operation); printOperationClass(operation); final RESULT_TYPE results; try { results = getGraph().execute( operation, new User("user01")); } catch (OperationException e) { throw new RuntimeException(e); } logResult(results); log(METHOD_DIVIDER); return results; }
public Object doOperation(final Operation operation, final Context context, final Store store) throws OperationException { final Collection<Graph> graphs = ((FederatedStore) store).getGraphs(context.getUser(), operation.getOption(KEY_OPERATION_OPTIONS_GRAPH_IDS)); for (final Graph graph : graphs) { final Operation updatedOp = FederatedStoreUtil.updateOperationForGraph(operation, graph); if (null != updatedOp) { try { graph.execute(updatedOp, context); } catch (final Exception e) { if (!Boolean.valueOf(getSkipFailedFederatedStoreExecute(updatedOp))) { throw new OperationException(FederatedStoreUtil.createOperationErrorMsg(operation, graph.getGraphId(), e), e); } } } } return null; } }
protected <RESULT_TYPE> RESULT_TYPE runExample( final Output<RESULT_TYPE> operation, final String description) { log("#### " + getMethodNameAsSentence(1) + "\n"); if (StringUtils.isNotBlank(description)) { log(description + "\n"); } printGraph(); printMethodJavaSnippet(); printAsJson(operation); final RESULT_TYPE results; try { results = getGraph().execute( operation, new User("user01")); } catch (final OperationException e) { throw new RuntimeException(e); } logResult(results); log(METHOD_DIVIDER); return results; }
protected <RESULT_TYPE> RESULT_TYPE runExample( final OperationChain<RESULT_TYPE> operationChain, final String description) { log("#### " + getMethodNameAsSentence(1) + "\n"); if (StringUtils.isNotBlank(description)) { log(description); } printGraph(); printMethodJavaSnippet(); printAsJson(operationChain); final RESULT_TYPE result; try { result = getGraph().execute( operationChain, new User("user01")); } catch (final OperationException e) { throw new RuntimeException(e); } logResult(result); log(METHOD_DIVIDER); return result; }
@Override public void runExamples() { try { final OperationChain<JobDetail> opChain = new OperationChain.Builder() .first(new GetAllEdges()) .then(new ExportToGafferResultCache()) .then(new GetJobDetails()) .build(); final JobDetail jobDetails = getGraph().execute(opChain, new User("user01")); jobId = jobDetails.getJobId(); } catch (final OperationException e) { throw new RuntimeException(e); } getJobResults(); }
public void load(final Supplier<Reader> readerSupplier) throws OperationException, IOException { final SuppliedIterable<CSVRecord> csvIterable = new SuppliedIterable<>(() -> { try { return new CSVParser(readerSupplier.get(), CSVFormat.DEFAULT.withFirstRecordAsHeader()); } catch (final IOException e) { throw new RuntimeException("Unable to load csv data", e); } }); try { final OperationChain<Void> populateChain = new OperationChain.Builder() .first(new GenerateElements.Builder<CSVRecord>() .input(csvIterable) .generator(new RoadTrafficCsvElementGenerator()) .build()) .then(new AddElements.Builder() .skipInvalidElements(false) .build()) .build(); this.graph.execute(populateChain, this.user); } finally { CloseableUtil.close(csvIterable); } }
@Override public void runExamples() { try { final OperationChain<JobDetail> opChain = new OperationChain.Builder() .first(new GetAllElements()) .then(new ExportToGafferResultCache<>()) .then(new DiscardOutput()) .then(new GetJobDetails()) .build(); final JobDetail jobDetails = getGraph().execute(opChain, new User("user01")); jobId = jobDetails.getJobId(); } catch (final OperationException e) { throw new RuntimeException(e); } getJobResults(); }
@Override public CloseableIterable<?> get(final String key) throws OperationException { final GetElements getEdges = new GetElements.Builder() .input(new EdgeSeed(jobId, key, true)) .view(new View.Builder() .edge("result", new ViewElementDefinition.Builder() .preAggregationFilter(new ElementFilter.Builder() .select("opAuths") .execute(new AreIn(userOpAuths)) .build()) .build()) .build()) .build(); final CloseableIterable<? extends Element> edges = resultCache.execute(getEdges, context); if (null == edges) { return new WrappedCloseableIterable<>(); } return new TransformJsonResult(edges); }