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


##########
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:
   Here's the sequence of events:
   
   I ask for a port ":0", to listen on on any IP this machine is on.
   
   It gives me "[::]:PORT"
   
   but [::] is ipv6 unspecified.
   
   In Go, that's explicitly handed as the loopback address.
   
   The fix on my end is to just say the endpoint is one of "localhost:PORT" or 
"[::1]:PORT".
   
   The next failure does happen on Swift side (KV<String, String> isn't 
KV<String,Optional<String>>) which either means prism messed up coders, or the 
swift SDK did, and this is just revealing something due to prism executing a 
single transform.
   
   I need to make prism gracefully mark the job failed on that SDK worker 
failure though. 



-- 
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