github.com/apache/beam/sdks/v2@v2.48.2/java/transform-service/controller-container/boot.go (about) 1 // Licensed to the Apache Software Foundation (ASF) under one or more 2 // contributor license agreements. See the NOTICE file distributed with 3 // this work for additional information regarding copyright ownership. 4 // The ASF licenses this file to You under the Apache License, Version 2.0 5 // (the "License"); you may not use this file except in compliance with 6 // the License. You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 16 // Boot code for the transform service controller. 17 // Contract: 18 // https://github.com/apache/beam/blob/master/model/job-management/src/main/proto/org/apache/beam/model/job_management/v1/beam_expansion_api.proto 19 // https://github.com/apache/beam/blob/master/model/job-management/src/main/proto/org/apache/beam/model/job_management/v1/beam_artifact_api.proto 20 package main 21 22 import ( 23 // "context" 24 "flag" 25 "fmt" 26 "io/ioutil" 27 "log" 28 "os" 29 "path/filepath" 30 "strconv" 31 "strings" 32 33 "github.com/apache/beam/sdks/v2/go/pkg/beam/util/execx" 34 ) 35 36 // Args: 37 // - Transform service port 38 // - Config file path. Config file contains: 39 // - A list of expansion services 40 var ( 41 port = flag.Int("port", 0, "Port for the expansion service (required)") 42 config_file = flag.String("config_file", "", "Transform service config YAML file. (required)") 43 ) 44 45 const entrypoint = "org.apache.beam.sdk.transformservice.Controller" 46 47 func main() { 48 flag.Parse() 49 50 if *port == 0 { 51 log.Fatalf("The flag 'port' was not specified") 52 } 53 54 if *config_file == "" { 55 log.Fatalf("The flag 'config_file' was not specified") 56 } 57 58 log.Printf("Starting the transform service controller container") 59 60 // Determine all jar files from the 'jars' to be used for the CLASSPATH. 61 files, _ := ioutil.ReadDir("jars") 62 cp := []string{} 63 path, _ := os.Getwd() 64 for _, file := range files { 65 cp = append(cp, filepath.Join(path, "jars", file.Name())) 66 } 67 68 args := []string{ 69 // Seting max RAM percentage to a high value since we are running a single JVM within the container. 70 "-XX:MaxRAMPercentage=80.0", 71 // Keep following JVM options in sync with other Java containers released with Beam. 72 "-XX:+UseParallelGC", 73 "-XX:+AlwaysActAsServerClassMachine", 74 "-XX:-OmitStackTraceInFastThrow", 75 "-cp", strings.Join(cp, ":"), 76 } 77 78 args = append(args, entrypoint) 79 80 if *port != 0 { 81 args = append(args, fmt.Sprintf("--port=%s", strconv.Itoa(*port))) 82 } 83 if *config_file != "" { 84 args = append(args, fmt.Sprintf("--transformServiceConfigFile=%s", *config_file)) 85 } 86 87 log.Printf("Executing: java %v", strings.Join(args, " ")) 88 log.Fatalf("Java exited: %v", execx.Execute("java", args...)) 89 }