byronellis commented on code in PR #28062:
URL: https://github.com/apache/beam/pull/28062#discussion_r1306741820


##########
sdks/swift/Sources/ApacheBeam/Runners/PortableRunner.swift:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import Logging
+import GRPC
+import NIOCore
+
+public struct PortableRunner : PipelineRunner {
+    let loopback:Bool
+    let log: Logging.Logger
+    let host: String
+    let port: Int
+    
+    public init(host:String="localhost",port:Int=8073,loopback:Bool=false) {
+        self.loopback = loopback
+        self.log = .init(label: "PortableRunner")
+        self.host = host
+        self.port = port
+    }
+    
+    public func run(_ context: PipelineContext) async throws {
+        var proto = context.proto
+        if loopback {
+            //If we are in loopback mode we want to replace the default 
environment
+            //with an external environment that points to our local worker 
server
+            let worker = try WorkerServer(context.collections,context.pardoFns)
+            log.info("Running in LOOPBACK mode with a worker server at 
\(worker.endpoint).")
+            proto.components.environments[context.defaultEnvironmentId] = try 
.with {
+                try Environment.external(worker.endpoint).populate(&$0)
+            }
+        }
+        log.info("\(proto)")
+        log.info("Connecting to Portable Runner at \(host):\(port).")
+        let group = PlatformSupport.makeEventLoopGroup(loopCount: 1)
+        let channel = try GRPCChannelPool.with(target: .host(host, port: port),
+                                           transportSecurity: .plaintext, 
eventLoopGroup: group)
+        let client = 
Org_Apache_Beam_Model_JobManagement_V1_JobServiceAsyncClient(channel: channel)
+        let prepared = try await client.prepare(.with {
+            $0.pipeline = proto
+        })
+        let job = try await client.run(.with {
+            $0.preparationID = prepared.preparationID
+        })
+        log.info("Submitted job \(job.jobID)")
+        var done = false
+        while !done {
+            let status = try await client.getState(.with {

Review Comment:
   Interesting. The worker code is connecting to Prism on the port specified so 
that doesn't appear to be a problem, though it's a bit hard due to the 
"backwards" nature of the control plane connection. And, yes, the Swift 
toolchain is surprisingly pleasant to use. With the plugin system we should 
also be able to add some nice quality-of-life Beam features to SPM as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to