lostluck commented on code in PR #28062: URL: https://github.com/apache/beam/pull/28062#discussion_r1306705926
########## 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: I've successfully installed Swift (5.9 dev snap) on my personal laptop and pulled down the PR locally, and can replicate the behaviour on prism that you were seeing. I should be able to get to the bottom of those problems, and make prism more robust! Hot dang do I love the clarity in the Swift Docs on installing on different OS flavours, and how automated `swift test` is. It failed the first time, and clearly said what else I needed to install (openSSL) to clear it up. We should also add the following to the beam repo's .gitignore, right under the python section. ``` # Ignore files generated by the Swift build process sdks/swift/.build/**/* ``` Building the swift SDK lead to many many files in there. -- 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]
