Search in sources :

Example 26 with Node

use of org.flyte.api.v1.Node in project flytekit-java by flyteorg.

the class SdkWorkflowBuilderTest method testConditionalWorkflowIdl.

@Test
void testConditionalWorkflowIdl() {
    SdkWorkflowBuilder builder = new SdkWorkflowBuilder();
    new ConditionalWorkflow().expand(builder);
    Node caseNode = Node.builder().id("neq").taskNode(TaskNode.builder().referenceId(PartialTaskIdentifier.builder().name("org.flyte.flytekit.SdkWorkflowBuilderTest$MultiplicationTask").build()).build()).inputs(asList(Binding.builder().var_("a").binding(BindingData.ofOutputReference(OutputReference.builder().var("in").nodeId(Node.START_NODE_ID).build())).build(), Binding.builder().var_("b").binding(BindingData.ofScalar(Scalar.ofPrimitive(Primitive.ofIntegerValue(2L)))).build())).upstreamNodeIds(emptyList()).build();
    IfElseBlock ifElse = IfElseBlock.builder().case_(IfBlock.builder().condition(BooleanExpression.ofComparison(ComparisonExpression.builder().leftValue(Operand.ofVar("$0")).rightValue(Operand.ofPrimitive(Primitive.ofIntegerValue(2L))).operator(ComparisonExpression.Operator.NEQ).build())).thenNode(caseNode).build()).error(NodeError.builder().message("No cases matched").failedNodeId("square").build()).other(emptyList()).build();
    Node expectedNode = Node.builder().id("square").branchNode(BranchNode.builder().ifElse(ifElse).build()).inputs(singletonList(Binding.builder().var_("$0").binding(BindingData.ofOutputReference(OutputReference.builder().var("in").nodeId(Node.START_NODE_ID).build())).build())).upstreamNodeIds(emptyList()).build();
    WorkflowTemplate expected = WorkflowTemplate.builder().metadata(WorkflowMetadata.builder().build()).interface_(expectedInterface()).outputs(expectedOutputs()).nodes(singletonList(expectedNode)).build();
    assertEquals(expected, builder.toIdlTemplate());
}
Also used : IfElseBlock(org.flyte.api.v1.IfElseBlock) WorkflowTemplate(org.flyte.api.v1.WorkflowTemplate) TaskNode(org.flyte.api.v1.TaskNode) BranchNode(org.flyte.api.v1.BranchNode) Node(org.flyte.api.v1.Node) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with Node

use of org.flyte.api.v1.Node in project flytekit-java by flyteorg.

the class SdkTestingExecutor method execute.

public Result execute() {
    TestingSdkWorkflowBuilder builder = new TestingSdkWorkflowBuilder(fixedInputMap(), fixedInputTypeMap());
    workflow().expand(builder);
    WorkflowTemplate workflowTemplate = builder.toIdlTemplate();
    for (Node node : workflowTemplate.nodes()) {
        TaskNode taskNode = node.taskNode();
        if (taskNode != null) {
            String taskName = taskNode.referenceId().name();
            checkArgument(fixedTaskMap().containsKey(taskName), "Can't execute remote task [%s], " + "use SdkTestingExecutor#withTaskOutput or SdkTestingExecutor#withTask", taskName);
        }
    }
    Map<String, Literal> outputLiteralMap = LocalEngine.compileAndExecute(workflowTemplate, unmodifiableMap(fixedTaskMap()), emptyMap(), fixedInputMap());
    Map<String, LiteralType> outputLiteralTypeMap = workflowTemplate.interface_().outputs().entrySet().stream().collect(toMap(Map.Entry::getKey, x -> x.getValue().literalType()));
    return Result.create(outputLiteralMap, outputLiteralTypeMap);
}
Also used : TaskNode(org.flyte.api.v1.TaskNode) SdkRunnableTask(org.flyte.flytekit.SdkRunnableTask) HashMap(java.util.HashMap) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Collectors.toMap(java.util.stream.Collectors.toMap) WorkflowTemplate(org.flyte.api.v1.WorkflowTemplate) SdkType(org.flyte.flytekit.SdkType) Duration(java.time.Duration) Map(java.util.Map) Preconditions.checkArgument(org.flyte.flytekit.testing.Preconditions.checkArgument) Collections.emptyMap(java.util.Collections.emptyMap) Node(org.flyte.api.v1.Node) LiteralType(org.flyte.api.v1.LiteralType) Literal(org.flyte.api.v1.Literal) ServiceLoader(java.util.ServiceLoader) Variable(org.flyte.api.v1.Variable) Instant(java.time.Instant) SdkWorkflow(org.flyte.flytekit.SdkWorkflow) Var(com.google.errorprone.annotations.Var) List(java.util.List) SdkRemoteTask(org.flyte.flytekit.SdkRemoteTask) AutoValue(com.google.auto.value.AutoValue) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap) LocalEngine(org.flyte.localengine.LocalEngine) TaskNode(org.flyte.api.v1.TaskNode) WorkflowTemplate(org.flyte.api.v1.WorkflowTemplate) TaskNode(org.flyte.api.v1.TaskNode) Node(org.flyte.api.v1.Node) Literal(org.flyte.api.v1.Literal) LiteralType(org.flyte.api.v1.LiteralType) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap) Collections.unmodifiableMap(java.util.Collections.unmodifiableMap)

Example 28 with Node

use of org.flyte.api.v1.Node in project flytekit-java by flyteorg.

the class SdkWorkflowWithSdkRemoteLaunchPlanTest method applyShouldReturnASdkWorkflowNode.

@Test
void applyShouldReturnASdkWorkflowNode() {
    SdkWorkflowBuilder builder = new SdkWorkflowBuilder();
    new WorkflowExample().expand(builder);
    Node expectedNode = Node.builder().id("some-node-id").workflowNode(WorkflowNode.builder().reference(WorkflowNode.Reference.ofLaunchPlanRef(PartialLaunchPlanIdentifier.builder().domain("dev").project("project-a").name("SomeLaunchPlan").version("version").build())).build()).upstreamNodeIds(Collections.emptyList()).inputs(Arrays.asList(Binding.builder().var_("a").binding(BindingData.ofOutputReference(OutputReference.builder().nodeId("start-node").var("a").build())).build(), Binding.builder().var_("b").binding(BindingData.ofOutputReference(OutputReference.builder().nodeId("start-node").var("b").build())).build())).build();
    WorkflowTemplate expected = WorkflowTemplate.builder().metadata(WorkflowMetadata.builder().build()).interface_(expectedInterface()).outputs(expectedOutputs()).nodes(singletonList(expectedNode)).build();
    assertEquals(expected, builder.toIdlTemplate());
}
Also used : WorkflowTemplate(org.flyte.api.v1.WorkflowTemplate) Node(org.flyte.api.v1.Node) WorkflowNode(org.flyte.api.v1.WorkflowNode) Test(org.junit.jupiter.api.Test)

Example 29 with Node

use of org.flyte.api.v1.Node in project OSMWrangle by SLIPO-EU.

the class OsmPbfParser method process.

/**
 * Processes an OSM element (node, way, or relation).
 * @param entityContainer  Container of an OSM node, way, or relation.
 */
@Override
public void process(EntityContainer entityContainer) {
    // Will become true only if a tag related to user-specified filters is found for the current OSM element
    keepIndexed = false;
    if ((!scanWays) && (!scanRelations) && (entityContainer instanceof NodeContainer)) {
        // Create a new OSM node object and populate it with the appropriate values
        // Mark position of the parser
        inNode = true;
        inWay = false;
        inRelation = false;
        numNodes++;
        Node myNode = ((NodeContainer) entityContainer).getEntity();
        nodeTmp = new OSMNode();
        nodeTmp.setID("" + myNode.getId());
        // Collect tags associated with this OSM element
        for (Tag myTag : myNode.getTags()) {
            nodeTmp.setTagKeyValue(myTag.getKey(), myChecker.removeIllegalChars(myTag.getValue()));
            if ((tags == null) || (tags.contains(myTag.getKey()))) {
                // CAUTION! Filter out any OSM elements not related to tags specified by the user
                // In case of no tags specified for filtering, index all nodes
                keepIndexed = true;
            }
        }
        // Create geometry object with original WGS84 coordinates
        Geometry geom = geometryFactory.createPoint(new Coordinate(myNode.getLongitude(), myNode.getLatitude()));
        nodeTmp.setGeometry(geom);
        // Convert entity
        if (keepIndexed) {
            if (keepUnnamed)
                myConverter.parse(recBuilder.createOSMRecord(nodeTmp), classification, reproject, targetSRID);
            else if (nodeTmp.getTagKeyValue().containsKey("name")) {
                // CAUTION! Only named entities will be transformed
                myConverter.parse(recBuilder.createOSMRecord(nodeTmp), classification, reproject, targetSRID);
                numNamedEntities++;
            }
        }
        if (recBuilder.nodeIndex.containsKey(nodeTmp.getID()))
            // Keep a dictionary of node geometries, only if referenced by OSM ways
            recBuilder.nodeIndex.put(nodeTmp.getID(), nodeTmp.getGeometry());
        nodeTmp = null;
    } else if ((!scanRelations) && (entityContainer instanceof WayContainer)) {
        // Create a new OSM way object and populate it with the appropriate values
        Way myWay = ((WayContainer) entityContainer).getEntity();
        for (Tag myTag : myWay.getTags()) {
            if ((tags == null) || (tags.contains(myTag.getKey()))) {
                // CAUTION! Filter out any OSM elements not related to tags specified by the user
                // In case of no tags specified for filtering, index all ways
                keepIndexed = true;
                break;
            }
        }
        if (scanWays) {
            // Either this OSM way is filtered or referenced by a relation, so its nodes should be kept in the index
            if ((keepIndexed) || (recBuilder.wayIndex.containsKey("" + myWay.getId()))) {
                for (WayNode entry : myWay.getWayNodes()) {
                    // ...initially with NULL geometry, to be replaced once nodes will be parsed
                    recBuilder.nodeIndex.put("" + entry.getNodeId(), null);
                }
            }
        } else {
            if (inNode)
                System.out.println("\nFinished parsing OSM nodes.");
            // Mark position of the parser
            inNode = false;
            inWay = true;
            inRelation = false;
            numWays++;
            // Skip parsing if this way is filtered out or not referenced by other relations
            if ((!keepIndexed) && (!recBuilder.wayIndex.containsKey("" + myWay.getId())))
                return;
            wayTmp = new OSMWay();
            wayTmp.setID("" + myWay.getId());
            // Collect tags associated with this OSM element
            for (Tag myTag : myWay.getTags()) {
                wayTmp.setTagKeyValue(myTag.getKey(), myChecker.removeIllegalChars(myTag.getValue()));
            }
            for (WayNode entry : myWay.getWayNodes()) {
                if (recBuilder.nodeIndex.containsKey("" + entry.getNodeId())) {
                    // get the geometry of the node with ID=entry
                    Geometry geometry = recBuilder.nodeIndex.get("" + entry.getNodeId());
                    // add the node geometry in this way
                    wayTmp.addNodeGeometry(geometry);
                } else
                    System.out.println("Missing node " + entry.getNodeId() + " in referencing way " + wayTmp.getID());
            }
            Geometry geom = geometryFactory.buildGeometry(wayTmp.getNodeGeometries());
            // These nodes must be more than 3, because JTS does not allow construction of a linear ring with less than 3 points
            if ((closedRings2Polygons) && (wayTmp.getNodeGeometries().size() > 3) && wayTmp.getNodeGeometries().get(0).equals(wayTmp.getNodeGeometries().get(wayTmp.getNodeGeometries().size() - 1))) {
                // Always construct a polygon when a linear ring is detected
                LinearRing linear = geometryFactory.createLinearRing(geom.getCoordinates());
                Polygon poly = new Polygon(linear, null, geometryFactory);
                wayTmp.setGeometry(poly);
            /**
             ***********************************************
             *		               //OPTION NOT USED: Construct a linear ring geometry when this feature is either a barrier or a road
             *		               if (!((wayTmp.getTagKeyValue().containsKey("barrier")) || wayTmp.getTagKeyValue().containsKey("highway"))){
             *		            	   //this is not a barrier nor a road, so construct a polygon geometry
             *
             *		            	   LinearRing linear = geometryFactory.createLinearRing(geom.getCoordinates());
             *		            	   Polygon poly = new Polygon(linear, null, geometryFactory);
             *		            	   wayTmp.setGeometry(poly);
             *		               }
             *		               else {    //it is either a barrier or a road, so construct a linear ring geometry
             *		                  LinearRing linear = geometryFactory.createLinearRing(geom.getCoordinates());
             *		                  wayTmp.setGeometry(linear);
             *		               }
             *************************************************
             */
            } else if (wayTmp.getNodeGeometries().size() > 1) {
                // it is an open geometry with more than one nodes, make it linestring
                LineString lineString = geometryFactory.createLineString(geom.getCoordinates());
                wayTmp.setGeometry(lineString);
            } else {
                // we assume that any other geometries are points
                // some ways happen to have only one point. Construct a Point.
                Point point = geometryFactory.createPoint(geom.getCoordinate());
                wayTmp.setGeometry(point);
            }
            // Convert this entity
            if (keepIndexed) {
                if (keepUnnamed)
                    myConverter.parse(recBuilder.createOSMRecord(wayTmp), classification, reproject, targetSRID);
                else if (wayTmp.getTagKeyValue().containsKey("name")) {
                    // CAUTION! Only named entities will be transformed
                    myConverter.parse(recBuilder.createOSMRecord(wayTmp), classification, reproject, targetSRID);
                    numNamedEntities++;
                }
            }
            if (recBuilder.wayIndex.containsKey(wayTmp.getID()))
                // Keep a dictionary of way geometries, only for those referenced by OSM relations
                recBuilder.wayIndex.put(wayTmp.getID(), wayTmp.getGeometry());
            wayTmp = null;
        }
    } else if ((!scanWays) && (entityContainer instanceof RelationContainer)) {
        // Create a new OSM relation object and populate it with the appropriate values
        Relation myRelation = ((RelationContainer) entityContainer).getEntity();
        for (Tag myTag : myRelation.getTags()) {
            if ((tags == null) || (tags.contains(myTag.getKey()))) {
                // CAUTION! Filter out any OSM elements not related to tags specified by the user
                // In case of no tags specified for filtering, index all nodes
                keepIndexed = true;
                break;
            }
        }
        if (scanRelations) {
            // Either only filtered relations will be indexed or those referenced by other relations
            if ((keepIndexed) || (recBuilder.relationIndex.containsKey("" + myRelation.getId()))) {
                for (RelationMember m : myRelation.getMembers()) {
                    if (m.getMemberType().name().equalsIgnoreCase("node"))
                        // This node is referenced by a relation; keep it in the index, and its geometry will be filled in when parsing the nodes
                        recBuilder.nodeIndex.put("" + m.getMemberId(), null);
                    else if (m.getMemberType().name().equalsIgnoreCase("way"))
                        // This way is referenced by a relation; keep it in the index, and its geometry will be filled in when parsing the ways
                        recBuilder.wayIndex.put("" + m.getMemberId(), null);
                    else if (m.getMemberType().name().equalsIgnoreCase("relation")) {
                        // This relation is referenced by another relation; keep it in the index, and its geometry will be filled in when parsing the relations
                        recBuilder.relationIndex.put("" + m.getMemberId(), null);
                        // Relations need to be scanned once more, as they reference other relations
                        rescanRelations = true;
                    }
                }
            }
        } else {
            if (inWay)
                System.out.println("\nFinished parsing OSM ways.");
            // Mark position of the parser
            inNode = false;
            inWay = false;
            inRelation = true;
            numRelations++;
            // Skip parsing if this relation is filtered out or not referenced by others
            if ((!keepIndexed) && (!recBuilder.relationIndex.containsKey("" + myRelation.getId())))
                return;
            relationTmp = new OSMRelation();
            relationTmp.setID("" + myRelation.getId());
            // Collect tags associated with this OSM element
            for (Tag myTag : myRelation.getTags()) {
                relationTmp.setTagKeyValue(myTag.getKey(), myChecker.removeIllegalChars(myTag.getValue()));
            }
            // System.out.println("Relation " + myRelation.getId() + " Number of members: " +  myRelation.getMembers().size());
            for (RelationMember m : myRelation.getMembers()) relationTmp.addMemberReference("" + m.getMemberId(), m.getMemberType().name(), m.getMemberRole());
            OSMRecord rec = recBuilder.createOSMRecord(relationTmp);
            if (// No records created for incomplete relations during the first pass
            rec != null) {
                // Convert entity
                if (keepIndexed) {
                    if (keepUnnamed)
                        myConverter.parse(rec, classification, reproject, targetSRID);
                    else if (relationTmp.getTagKeyValue().containsKey("name")) {
                        // CAUTION! Only named entities will be transformed
                        myConverter.parse(rec, classification, reproject, targetSRID);
                        numNamedEntities++;
                    }
                }
                if (recBuilder.relationIndex.containsKey(relationTmp.getID()))
                    // Keep a dictionary of relation geometries, only for those referenced by other OSM relations
                    recBuilder.relationIndex.put(relationTmp.getID(), rec.getGeometry());
            }
            relationTmp = null;
        }
    }
}
Also used : WayContainer(org.openstreetmap.osmosis.core.container.v0_6.WayContainer) OSMWay(eu.smartdatalake.athenarc.osmwrangle.osm.OSMWay) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) OSMRelation(eu.smartdatalake.athenarc.osmwrangle.osm.OSMRelation) WayNode(org.openstreetmap.osmosis.core.domain.v0_6.WayNode) Node(org.openstreetmap.osmosis.core.domain.v0_6.Node) OSMNode(eu.smartdatalake.athenarc.osmwrangle.osm.OSMNode) NodeContainer(org.openstreetmap.osmosis.core.container.v0_6.NodeContainer) Point(org.locationtech.jts.geom.Point) OSMWay(eu.smartdatalake.athenarc.osmwrangle.osm.OSMWay) Way(org.openstreetmap.osmosis.core.domain.v0_6.Way) Geometry(org.locationtech.jts.geom.Geometry) OSMRecord(eu.smartdatalake.athenarc.osmwrangle.osm.OSMRecord) RelationContainer(org.openstreetmap.osmosis.core.container.v0_6.RelationContainer) Relation(org.openstreetmap.osmosis.core.domain.v0_6.Relation) OSMRelation(eu.smartdatalake.athenarc.osmwrangle.osm.OSMRelation) RelationMember(org.openstreetmap.osmosis.core.domain.v0_6.RelationMember) Coordinate(org.locationtech.jts.geom.Coordinate) LineString(org.locationtech.jts.geom.LineString) OSMNode(eu.smartdatalake.athenarc.osmwrangle.osm.OSMNode) Tag(org.openstreetmap.osmosis.core.domain.v0_6.Tag) LinearRing(org.locationtech.jts.geom.LinearRing) Polygon(org.locationtech.jts.geom.Polygon)

Example 30 with Node

use of org.flyte.api.v1.Node in project JavaProgrames by srv-shivam.

the class ReverseKNodes method add.

public void add(int data) {
    Node newNode = new Node(data);
    if (head == null) {
        head = newNode;
        tail = newNode;
        ++length;
    } else {
        tail.next = newNode;
        tail = newNode;
        ++length;
    }
}
Also used : Node(dsa450List.PracticeLinkedList2.Node)

Aggregations

Test (org.junit.jupiter.api.Test)20 Node (org.flyte.api.v1.Node)15 TaskNode (org.flyte.api.v1.TaskNode)11 WorkflowTemplate (org.flyte.api.v1.WorkflowTemplate)11 Test (org.junit.Test)10 ArrayList (java.util.ArrayList)9 Node (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Node)9 Node (org.openhab.binding.mqtt.homie.internal.homie300.Node)9 Node (org.openstreetmap.osmosis.core.domain.v0_6.Node)9 List (java.util.List)7 Way (org.openstreetmap.osmosis.core.domain.v0_6.Way)7 WayNode (org.openstreetmap.osmosis.core.domain.v0_6.WayNode)7 NodeAttributes (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.NodeAttributes)6 BranchNode (org.flyte.api.v1.BranchNode)6 WorkflowNode (org.flyte.api.v1.WorkflowNode)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 NodeAttributes (org.openhab.binding.mqtt.homie.internal.homie300.NodeAttributes)6 Map (java.util.Map)5 Property (org.eclipse.smarthome.binding.mqtt.generic.internal.convention.homie300.Property)5 Node (dataStructure.JunkCourse.ch04.Node)4