/** * Retrieves array of simple class names of nodes within a particular flow step. * * @param step step in main flow. * @return list step's graph's vertex names. */ protected String[] getNodeFeatures(BaseFlowStep step) { SimpleDirectedGraph graph = step.getGraph(); Object[] vertices = graph.vertexSet().toArray(); String[] returnedFeatures = new String[vertices.length]; for (int i = 0; i < returnedFeatures.length; i++) { returnedFeatures[i] = vertices[i].getClass().getSimpleName(); } return returnedFeatures; }
/** * Converts the flowStep that generated from cascading to a Map of DAGNode and its name to be used * to build Ambrose Graph. */ public void convert() { // returns a set of the nodes contained in this graph Set vertices = jobsGraph.vertexSet(); // create ambrose nodes for (Object vertex : vertices) { BaseFlowStep step = (BaseFlowStep) vertex; CascadingJob job = new CascadingJob(); job.setFeatures(getNodeFeatures(step)); String name = step.getName(); DAGNode<CascadingJob> node = new DAGNode<CascadingJob>(name, job); dagNamesMap.put(name, node); } // loop again to set the successors for each node after nodes are created for (Object vertex : vertices) { BaseFlowStep step = (BaseFlowStep) vertex; String name = step.getName(); DAGNode<CascadingJob> node = dagNamesMap.get(name); node.setSuccessors(getNodeSuccessors(vertex)); } }
public Set<Process> vertexSet() { return graph.vertexSet(); }
/** * */ @Override public Iterator<Equivalences<T>> iterator() { return dag.vertexSet().iterator(); }
/** * */ @Override public Iterator<Equivalences<T>> iterator() { return dag.vertexSet().iterator(); }
@Deprecated public int vertexSetSize() { return dag.vertexSet().size(); }
@Deprecated public int vertexSetSize() { return dag.vertexSet().size(); }
protected Collection<Resource> getAllResources() { initResourceGraph(); Set<Resource> resources = new HashSet<Resource>(); resources.addAll( resourceGraph.vertexSet() ); return resources; }
/** * Retrieves array of simple class names of nodes within a particular flow step. * * @param step step in main flow. * @return list step's graph's vertex names. */ protected String[] getNodeFeatures(BaseFlowStep step) { SimpleDirectedGraph graph = step.getGraph(); Object[] vertices = graph.vertexSet().toArray(); String[] returnedFeatures = new String[vertices.length]; for (int i = 0; i < returnedFeatures.length; i++) { returnedFeatures[i] = vertices[i].getClass().getSimpleName(); } return returnedFeatures; }
protected Collection<Resource> getResourcesWith( String identifier ) { initResourceGraph(); Set<Resource> resources = new HashSet<Resource>(); for( Resource resource : resourceGraph.vertexSet() ) { if( resource.getIdentifier().equals( identifier ) ) resources.add( resource ); } return resources; }
protected synchronized Set<String> getVertices() { return new HashSet<>(orgGraph.vertexSet()); }
@Override public Map<String, Tap> getSinkTapsMap() { Map<String, Tap> result = new HashMap<>(); Set<Tap> sinkTaps = getSinkTaps(); for( Tap sinkTap : sinkTaps ) { for( Process process : graph.vertexSet() ) { if( !process.getSinkTaps().contains( sinkTap ) ) continue; ElementGraph elementGraph = process.getElementGraph(); for( Scope scope : elementGraph.incomingEdgesOf( sinkTap ) ) result.put( scope.getName(), sinkTap ); } } return result; }
@Override public Map<String, Tap> getSourceTapsMap() { Map<String, Tap> result = new HashMap<>(); Set<Tap> sourceTaps = getSourceTaps(); for( Tap sourceTap : sourceTaps ) { for( Process process : graph.vertexSet() ) { if( !process.getSourceTaps().contains( sourceTap ) ) continue; ElementGraph elementGraph = process.getElementGraph(); for( Scope scope : elementGraph.outgoingEdgesOf( sourceTap ) ) result.put( scope.getName(), sourceTap ); } } return result; }
public static <T> EquivalencesDAGImpl<T> reduce(EquivalencesDAGImpl<T> source, SimpleDirectedGraph <Equivalences<T>,DefaultEdge> target) { ImmutableMap.Builder<T, Equivalences<T>> vertexIndexBuilder = new ImmutableMap.Builder<>(); for (Equivalences<T> tSet : target.vertexSet()) { for (T s : source.getVertex(tSet.getRepresentative())) if (tSet.contains(s)) vertexIndexBuilder.put(s, tSet); } ImmutableMap<T, Equivalences<T>> vertexIndex = vertexIndexBuilder.build(); // create induced edges in the target graph for (Equivalences<T> sSet : source) { Equivalences<T> tSet = vertexIndex.get(sSet.getRepresentative()); for (Equivalences<T> sSetSub : source.getDirectSub(sSet)) { Equivalences<T> tSetSub = vertexIndex.get(sSetSub.getRepresentative()); target.addEdge(tSetSub, tSet); } } return new EquivalencesDAGImpl<>(null, target, vertexIndex, source.vertexIndex); }
public static <T> EquivalencesDAGImpl<T> reduce(EquivalencesDAGImpl<T> source, SimpleDirectedGraph <Equivalences<T>,DefaultEdge> target) { ImmutableMap.Builder<T, Equivalences<T>> vertexIndexBuilder = new ImmutableMap.Builder<>(); for (Equivalences<T> tSet : target.vertexSet()) { for (T s : source.getVertex(tSet.getRepresentative())) if (tSet.contains(s)) vertexIndexBuilder.put(s, tSet); } ImmutableMap<T, Equivalences<T>> vertexIndex = vertexIndexBuilder.build(); // create induced edges in the target graph for (Equivalences<T> sSet : source) { Equivalences<T> tSet = vertexIndex.get(sSet.getRepresentative()); for (Equivalences<T> sSetSub : source.getDirectSub(sSet)) { Equivalences<T> tSetSub = vertexIndex.get(sSetSub.getRepresentative()); target.addEdge(tSetSub, tSet); } } return new EquivalencesDAGImpl<>(null, target, vertexIndex, source.vertexIndex); }
/** * Converts the flowStep that generated from cascading to a Map of DAGNode and its name to be used * to build Ambrose Graph. */ public void convert() { // returns a set of the nodes contained in this graph Set vertices = jobsGraph.vertexSet(); // create ambrose nodes for (Object vertex : vertices) { BaseFlowStep step = (BaseFlowStep) vertex; CascadingJob job = new CascadingJob(); job.setFeatures(getNodeFeatures(step)); String name = step.getName(); DAGNode<CascadingJob> node = new DAGNode<CascadingJob>(name, job); dagNamesMap.put(name, node); } // loop again to set the successors for each node after nodes are created for (Object vertex : vertices) { BaseFlowStep step = (BaseFlowStep) vertex; String name = step.getName(); DAGNode<CascadingJob> node = dagNamesMap.get(name); node.setSuccessors(getNodeSuccessors(vertex)); } }
protected void checkOrgGraph() throws SchemaException { OperationResult result = new OperationResult("temp"); int numberOfOrgsInRepo = repositoryService.countObjects(OrgType.class, null, null, result); info("Checking graph with repo. Orgs in repo: " + numberOfOrgsInRepo + ", orgs in graph: " + orgGraph.vertexSet().size()); assertTrue("# of orgs in repo (" + numberOfOrgsInRepo + ") is different from # of orgs in graph (" + orgGraph.vertexSet().size() + ")", numberOfOrgsInRepo == orgGraph.vertexSet().size()); for (String oid : orgGraph.vertexSet()) { //info("Checking " + oid); OrgType orgType; try { orgType = repositoryService.getObject(OrgType.class, oid, null, result).asObjectable(); } catch (ObjectNotFoundException|SchemaException e) { throw new AssertionError("Couldn't fetch " + oid, e); } assertTrue(orgGraph.vertexSet().contains(orgType.getOid())); Set<String> parentOidsInRepo = new HashSet<>(); for (ObjectReferenceType ort : orgType.getParentOrgRef()) { if (orgGraph.vertexSet().contains(ort.getOid())) { // i.e. the parent does exist parentOidsInRepo.add(ort.getOid()); } } Set<String> parentOidsInGraph = new HashSet<>(); for (DefaultEdge edge : orgGraph.outgoingEdgesOf(oid)) { parentOidsInGraph.add(orgGraph.getEdgeTarget(edge)); } assertEquals("Unexpected parentRefOrg set in " + orgType, parentOidsInGraph, parentOidsInRepo); } info("Graph is OK w.r.t. repo"); }
private void rebuildGraph() { OperationResult result = new OperationResult("dummy"); info("Graph before rebuilding: " + orgGraph.vertexSet().size() + " vertices, " + orgGraph.edgeSet().size() + " edges"); orgGraph.removeAllVertices(new HashSet<>(orgGraph.vertexSet())); List<PrismObject> objects = null; try { objects = (List) repositoryService.searchObjects(OrgType.class, null, null, result); } catch (SchemaException e) { throw new AssertionError(e); } for (PrismObject object : objects) { String oid = object.getOid(); orgGraph.addVertex(oid); } for (PrismObject<ObjectType> object : objects) { for (ObjectReferenceType ort : object.asObjectable().getParentOrgRef()) { if (orgGraph.containsVertex(ort.getOid())) { String oid = object.getOid(); try { orgGraph.addEdge(oid, ort.getOid()); } catch (RuntimeException e) { System.err.println("Couldn't add edge " + oid + " -> " + ort.getOid() + " into the graph"); throw e; } } } } info("Graph after rebuilding: "+orgGraph.vertexSet().size()+" vertices, "+orgGraph.edgeSet().size()+" edges"); }
public DefaultDirectedGraph<T,DefaultEdge> getGraph() { if (graph == null) { graph = new DefaultDirectedGraph<>(DefaultEdge.class); for (Equivalences<T> node : dag.vertexSet()) { for (T v : node) graph.addVertex(v); for (T v : node) { graph.addEdge(v, node.getRepresentative()); graph.addEdge(node.getRepresentative(), v); } } for (DefaultEdge edge : dag.edgeSet()) graph.addEdge(dag.getEdgeSource(edge).getRepresentative(), dag.getEdgeTarget(edge).getRepresentative()); } return graph; }
public DefaultDirectedGraph<T,DefaultEdge> getGraph() { if (graph == null) { graph = new DefaultDirectedGraph<>(DefaultEdge.class); for (Equivalences<T> node : dag.vertexSet()) { for (T v : node) graph.addVertex(v); for (T v : node) { graph.addEdge(v, node.getRepresentative()); graph.addEdge(node.getRepresentative(), v); } } for (DefaultEdge edge : dag.edgeSet()) graph.addEdge(dag.getEdgeSource(edge).getRepresentative(), dag.getEdgeTarget(edge).getRepresentative()); } return graph; }