github.com/apache/beam/sdks/v2@v2.48.2/java/expansion-service/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 Java SDK expansion service. 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 // - Expansion service port 38 // - Dependencies (for loading SchemaTransforms) 39 // - Config file path. Config file contains: 40 // - Allow-list 41 // - Per-transform dependencies config. 42 var ( 43 id = flag.String("id", "", "Local identifier (required)") 44 port = flag.Int("port", 0, "Port for the expansion service (required)") 45 dependencies_dir = flag.String("dependencies_dir", "", "A directory containing the set of jar files to load transforms from (required)") 46 config_file = flag.String("config_file", "", "Expansion service config YAML file. (required)") 47 ) 48 49 const entrypoint = "org.apache.beam.sdk.expansion.service.ExpansionService" 50 51 func main() { 52 flag.Parse() 53 54 if *id == "" { 55 log.Fatalf("The flag 'id' was not specified") 56 } 57 if *port == 0 { 58 log.Fatalf("The flag 'port' was not specified") 59 } 60 if *dependencies_dir == "" { 61 log.Fatalf("The flag 'dependencies_dir' was not specified") 62 } 63 if *config_file == "" { 64 log.Fatalf("The flag 'config_file' was not specified") 65 } 66 67 log.Printf("Starting the Java expansion service container %v.", *id) 68 69 // Determine all jar files from the dipendencies_dir to be used for the CLASSPATH. 70 files, _ := ioutil.ReadDir(*dependencies_dir) 71 cp := []string{} 72 path, _ := os.Getwd() 73 for _, file := range files { 74 cp = append(cp, filepath.Join(path, *dependencies_dir, file.Name())) 75 } 76 77 args := []string{ 78 // Seting max RAM percentage to a high value since we are running a single JVM within the container. 79 "-XX:MaxRAMPercentage=80.0", 80 // Keep following JVM options in sync with other Java containers released with Beam. 81 "-XX:+UseParallelGC", 82 "-XX:+AlwaysActAsServerClassMachine", 83 "-XX:-OmitStackTraceInFastThrow", 84 "-cp", strings.Join(cp, ":"), 85 } 86 87 args = append(args, entrypoint) 88 args = append(args, strconv.Itoa(*port)) 89 90 if *config_file != "" { 91 args = append(args, fmt.Sprintf("--expansionServiceConfigFile=%s", *config_file)) 92 } 93 94 log.Printf("Executing: java %v", strings.Join(args, " ")) 95 log.Fatalf("Java exited: %v", execx.Execute("java", args...)) 96 }