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());
}
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);
}
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());
}
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;
}
}
}
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;
}
}
Aggregations