lukecwik commented on code in PR #23165:
URL: https://github.com/apache/beam/pull/23165#discussion_r978796531


##########
sdks/java/container/agent/src/main/java/org/apache/beam/agent/OpenModuleAgent.java:
##########
@@ -0,0 +1,58 @@
+/*
+ * 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.
+ */
+package org.apache.beam.agent;
+
+import java.lang.instrument.Instrumentation;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+public class OpenModuleAgent {
+  public static void premain(String argument, Instrumentation instrumentation) 
{
+    Set<Module> automaticModules = new HashSet<>();
+    Set<Module> modulesToOpen = new HashSet<>();
+    ModuleLayer.boot()
+        .modules()
+        .forEach(
+            module -> {
+              if (module.getDescriptor().isAutomatic()) {
+                automaticModules.add(module);
+              } else if (!module.getDescriptor().isOpen()) {
+                modulesToOpen.add(module);
+              }
+            });
+
+    if (!automaticModules.isEmpty()) {
+      for (Module module : modulesToOpen) {
+        Map<String, Set<Module>> addOpens = new HashMap<>();
+        for (String pkg : module.getPackages()) {
+          addOpens.put(pkg, automaticModules);
+        }
+        instrumentation.redefineModule(

Review Comment:
   can we limit this only to jamm?



##########
sdks/java/container/common.gradle:
##########
@@ -86,6 +89,16 @@ task skipPullLicenses(type: Exec) {
     args "-c", "mkdir -p build/target/go-licenses build/target/options 
build/target/third_party_licenses && touch 
build/target/third_party_licenses/skip"
 }
 
+task validateJavaHome {
+    if (JavaVersion.VERSION_1_8.compareTo(JavaVersion.current()) >= 0 && 
imageJavaVersion == "17" || imageJavaVersion == "11") {

Review Comment:
   nit:
   ```suggestion
       if (JavaVersion.VERSION_1_8.compareTo(JavaVersion.current()) >= 0 && 
imageJavaVersion == "11" || imageJavaVersion == "17") {
   ```



##########
release/src/main/scripts/build_release_candidate.sh:
##########
@@ -135,6 +140,12 @@ if [[ -z "$USER_GITHUB_ID" ]] ; then
   exit 1
 fi
 
+if [[ -z "$JAVA11_HOME" ]] ; then
+  echo 'Please provide Java 11 home'

Review Comment:
   ```suggestion
     echo 'Please provide Java 11 home. Required to build 
sdks/java/container/agent for Java 11+ containers.'
   ```



##########
sdks/java/container/common.gradle:
##########
@@ -48,6 +48,9 @@ task copyDockerfileDependencies(type: Copy) {
     from configurations.dockerDependency
     rename 'slf4j-api.*', 'slf4j-api.jar'
     rename 'slf4j-jdk14.*', 'slf4j-jdk14.jar'
+    if (imageJavaVersion == "17" || imageJavaVersion == "11") {

Review Comment:
   ```suggestion
       if (imageJavaVersion == "11" || imageJavaVersion == "17") {
   ```



##########
sdks/java/container/agent/build.gradle:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+plugins {
+    id 'org.apache.beam.module'
+}
+applyJavaNature(
+        exportJavadoc: false,

Review Comment:
   nit: spacing



##########
sdks/java/container/Dockerfile:
##########
@@ -31,7 +31,8 @@ ADD target/beam-sdks-java-io-kafka.jar /opt/apache/beam/jars/
 ADD target/kafka-clients.jar /opt/apache/beam/jars/
 
 # Required to use jamm as a javaagent to get accurate object size measuring
-ADD target/jamm.jar /opt/apache/beam/jars/
+# COPY fails if file is not found, so use a wildcard for open-module-agent.jar

Review Comment:
   ```suggestion
   # COPY fails if file is not found, so use a wildcard for 
open-module-agent.jar since it is only included in Java 9+ containers
   ```



##########
sdks/java/container/agent/build.gradle:
##########
@@ -0,0 +1,82 @@
+/*
+ * 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.
+ */
+
+plugins {
+    id 'org.apache.beam.module'
+}
+applyJavaNature(
+        exportJavadoc: false,
+        publish: false
+)
+
+description = "Apache Beam :: SDKs :: Java :: Container :: Agent"
+
+jar {
+    manifest {
+        attributes("Agent-Class": "org.apache.beam.agent.OpenModuleAgent",
+                "Can-Redefine-Classes": true,
+                "Can-Retransform-Classes": true,
+                "Premain-Class": "org.apache.beam.agent.OpenModuleAgent")
+    }
+}
+
+if (project.hasProperty('java11Home')) {
+    javaVersion = "1.11"
+    def java11Home = project.findProperty('java11Home')
+    project.tasks.withType(JavaCompile) {
+        options.fork = true
+        options.forkOptions.javaHome = java11Home as File
+        options.compilerArgs += ['-Xlint:-path']
+    }
+} else if (project.hasProperty('java17Home')) {
+    javaVersion = "1.17"
+    def java17Home = project.findProperty("java17Home")
+    project.tasks.withType(JavaCompile) {

Review Comment:
   Is there a way to share this logic with BeamModulePlugin.groovy?



##########
website/www/site/content/en/contribute/release-guide.md:
##########
@@ -499,7 +499,7 @@ Consider adding known issues there for minor issues instead 
of accepting cherry
 * There are no open pull requests to release branch;
 * Originating branch has the version information updated to the new version;
 * Nightly snapshot is in progress (do revisit it continually);
-* Set `JAVA_HOME` to JDK 8 (Example: `export 
JAVA_HOME=/example/path/to/java/jdk8`).
+* Set `JAVA_HOME` to JDK 8 (Example: `export 
JAVA_HOME=/example/path/to/java/jdk8`). You'll also need Java 11+ installed.

Review Comment:
   ```suggestion
   * Set `JAVA_HOME` to JDK 8 (Example: `export 
JAVA_HOME=/example/path/to/java/jdk8`).
   * Have Java 11 installed.
   ```



##########
sdks/java/container/common.gradle:
##########
@@ -86,6 +89,16 @@ task skipPullLicenses(type: Exec) {
     args "-c", "mkdir -p build/target/go-licenses build/target/options 
build/target/third_party_licenses && touch 
build/target/third_party_licenses/skip"
 }
 
+task validateJavaHome {
+    if (JavaVersion.VERSION_1_8.compareTo(JavaVersion.current()) >= 0 && 
imageJavaVersion == "17" || imageJavaVersion == "11") {

Review Comment:
   Why the 1.8 check?



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