This is an automated email from the ASF dual-hosted git repository.
rzo1 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/storm.git
The following commit(s) were added to refs/heads/master by this push:
new 838f6b8d89 Fail the build when storm-client or storm-server imports
relocated packages directly (#9286)
838f6b8d89 is described below
commit 838f6b8d896f1448bbdb9451af81b5a556aa6319
Author: 龙骑士k <[email protected]>
AuthorDate: Mon Nov 23 18:31:54 2026 +0000
Fail the build when storm-client or storm-server imports relocated packages
directly (#9286)
* Fail the build when storm-client or storm-server imports relocated
packages directly
Closes issue 7641
## What is the purpose of the change
storm-client and storm-server now fail validate when their main code
imports one of the relocated packages of storm-shaded-deps. Such an import
still compiles if another dependency brings in the original jar, so the module
silently depends on an unshaded copy. Six imports already did this:
- storm-client Utils used org.apache.commons.io.IOUtils, which reaches
storm-client through commons-compress.
- storm-server EquivalenceUtils, SchedulerConfigCache, WorkerTokenManager,
CgroupManager and Slot used com.google.common, which reaches storm-server only
through the optional auto-service dependency.
They now use the shaded classes, like the other imports in the same modules.
Each module gets its own checkstyle execution with an IllegalImport rule,
so the shared storm_checkstyle.xml stays unchanged for other modules. A comment
next to the relocations in storm-shaded-deps/pom.xml asks to update both lists
together.
The two lists differ:
- storm-client bans all relocated packages.
- commons-io, commons-lang3, commons-collections4, json-smart and snakeyaml
are direct dependencies of storm-server, so their relocated packages are
allowed there.
- storm-server bans com.google.common and com.google.thirdparty, the
com.google packages in the shaded jar, so com.google.auto.service stays allowed.
Other modules are not checked, because storm-core, storm-webapp and the
external modules declare some of the relocated packages themselves. Test code
is not checked, because tests use curator-test, which is not shaded. The check
covers import statements only, not fully qualified class names in code.
## How was the change tested
Without the fixes, storm-client reports the IOUtils import and storm-server
reports the five com.google.common imports, and nothing else. A temporary class
in storm-server that imports one class from each relocated package fails on the
15 banned packages and passes on the allowed ones and on auto-service. The
build with the examples and externals profiles passes validate in every module.
UtilsTest passes in storm-client. SlotTest, WorkerTokenTest,
EquivalenceUtilsTest, TestCgroups, Te [...]
## AI Disclosure
Human-led contribution. Grok Bot, working for dragonknightk, assisted with
this change, including the code, tests, and description. All submitted content
was reviewed by a human before submission.
Signed-off-by: dragonknightk
<[email protected]>
* Define the check-unshaded-imports execution once in the root pom
Closes issue 7641
## What is the purpose of the change
storm-client and storm-server now fail validate when their main code
imports one of the relocated packages of storm-shaded-deps. Such an import
still compiles if another dependency brings in the original jar, so the module
silently depends on an unshaded copy. Six imports already did this:
- storm-client Utils used org.apache.commons.io.IOUtils, which reaches
storm-client through commons-compress.
- storm-server EquivalenceUtils, SchedulerConfigCache, WorkerTokenManager,
CgroupManager and Slot used com.google.common, which reaches storm-server only
through the optional auto-service dependency.
They now use the shaded classes, like the other imports in the same modules.
The root pom defines the check-unshaded-imports checkstyle execution once,
in pluginManagement, with an IllegalImport rule that reads the
unshaded.illegalPkgs property. The shared storm_checkstyle.xml stays unchanged.
The execution is bound to the phase in the unshaded.check.phase property, which
defaults to none. storm-client and storm-server set it to validate and set
their own unshaded.illegalPkgs. A comment next to the relocations in
storm-shaded-deps/pom.xml points to these two p [...]
The two lists differ:
- storm-client bans all relocated packages.
- commons-io, commons-lang3, commons-collections4, json-smart and snakeyaml
are direct dependencies of storm-server, so their relocated packages are
allowed there.
- storm-server bans com.google.common and com.google.thirdparty, the
com.google packages in the shaded jar, so com.google.auto.service stays allowed.
Both lists ban org.apache.curator, so new Curator code in the main code of
storm-client and storm-server has to use the shaded package. This fits the
ongoing Curator decoupling.
Other modules are not checked, because storm-core, storm-webapp and the
external modules declare some of the relocated packages themselves. They
inherit the execution with phase none, so it never runs there. Test code is not
checked, because tests use curator-test, which is not shaded. The check covers
import statements only, not fully qualified class names in code.
## How was the change tested
Without the fixes, storm-client reports the IOUtils import and storm-server
reports the five com.google.common imports, and nothing else. A temporary class
in storm-server that imports one class from each relocated package fails on the
15 banned packages and passes on the allowed ones and on auto-service.
Temporary imports of the first, the last and two other banned packages fail
validate in storm-client and in storm-server. The effective pom of storm-client
and storm-server binds che [...]
## AI Disclosure
Human-led contribution. Grok Bot, working for dragonknightk, assisted with
this change, including the code, tests, and description. All submitted content
was reviewed by a human before submission.
Signed-off-by: dragonknightk
<[email protected]>
---------
Signed-off-by: dragonknightk
<[email protected]>
---
pom.xml | 28 ++++++++++++++++++++++
storm-client/pom.xml | 10 ++++++++
.../src/jvm/org/apache/storm/utils/Utils.java | 2 +-
storm-server/pom.xml | 10 ++++++++
.../storm/container/cgroup/CgroupManager.java | 2 +-
.../org/apache/storm/daemon/supervisor/Slot.java | 2 +-
.../scheduler/utils/SchedulerConfigCache.java | 2 +-
.../auth/workertoken/WorkerTokenManager.java | 2 +-
.../org/apache/storm/utils/EquivalenceUtils.java | 2 +-
storm-shaded-deps/pom.xml | 2 ++
10 files changed, 56 insertions(+), 6 deletions(-)
diff --git a/pom.xml b/pom.xml
index 3bc674f8e4..a07423cd9c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -78,6 +78,8 @@
also update the storm_checkstyle.xml file to be based on the
google_checks.xml from the version
of checkstyle you are choosing. -->
<checkstyle.version>14.3.0</checkstyle.version>
+ <!-- check-unshaded-imports runs only in modules that set this to
validate and set unshaded.illegalPkgs. -->
+ <unshaded.check.phase>none</unshaded.check.phase>
<maven.javadoc.failOnError>false</maven.javadoc.failOnError>
<maven.javadoc.failOnWarnings>false</maven.javadoc.failOnWarnings>
@@ -1297,6 +1299,32 @@
<goal>check</goal>
</goals>
</execution>
+ <execution>
+ <!-- Fail the build if main code imports one of
the relocated packages of storm-shaded-deps.
+ Each module that enables it lists the banned
packages in unshaded.illegalPkgs. -->
+ <id>check-unshaded-imports</id>
+ <phase>${unshaded.check.phase}</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ <configuration>
+ <checkstyleRules>
+ <module name="Checker">
+ <module name="TreeWalker">
+ <module name="IllegalImport">
+ <property name="illegalPkgs"
value="${unshaded.illegalPkgs}"/>
+ </module>
+ </module>
+ </module>
+ </checkstyleRules>
+ <failOnViolation>true</failOnViolation>
+ <violationSeverity>error</violationSeverity>
+
<logViolationsToConsole>true</logViolationsToConsole>
+ <consoleOutput>true</consoleOutput>
+
<outputFile>target/checkstyle-unshaded-imports.xml</outputFile>
+
<cacheFile>target/checkstyle-unshaded-imports-cachefile</cacheFile>
+ </configuration>
+ </execution>
</executions>
</plugin>
<plugin>
diff --git a/storm-client/pom.xml b/storm-client/pom.xml
index fcb0035c9b..a4d19b3e5c 100644
--- a/storm-client/pom.xml
+++ b/storm-client/pom.xml
@@ -33,6 +33,16 @@
<packaging>jar</packaging>
<description>The client side (including worker) of Storm
implementations.</description>
+ <properties>
+ <!-- Relocated packages of storm-shaded-deps that main code must not
import (check-unshaded-imports in the root pom). -->
+ <unshaded.check.phase>validate</unshaded.check.phase>
+ <unshaded.illegalPkgs>org.apache.thrift, com.google,
org.apache.curator,
+ org.apache.zookeeper, org.apache.jute, org.apache.commons.io,
org.apache.commons.lang3,
+ org.apache.commons.collections4, org.jctools, org.yaml.snakeyaml,
org.jboss.netty,
+ io.netty, org.jgrapht, org.apache.commons.codec, net.minidev.json,
net.minidev.asm,
+ org.objectweb.asm, org.xerial.snappy,
uk.org.lidalia.sysoutslf4j</unshaded.illegalPkgs>
+ </properties>
+
<dependencies>
<!-- logging -->
diff --git a/storm-client/src/jvm/org/apache/storm/utils/Utils.java
b/storm-client/src/jvm/org/apache/storm/utils/Utils.java
index a4ec9e4f51..476691cb4e 100644
--- a/storm-client/src/jvm/org/apache/storm/utils/Utils.java
+++ b/storm-client/src/jvm/org/apache/storm/utils/Utils.java
@@ -79,7 +79,6 @@ import java.util.zip.ZipFile;
import javax.security.auth.Subject;
import
org.apache.commons.compress.compressors.zstandard.ZstdCompressorInputStream;
import
org.apache.commons.compress.compressors.zstandard.ZstdCompressorOutputStream;
-import org.apache.commons.io.IOUtils;
import org.apache.storm.Config;
import org.apache.storm.blobstore.BlobStore;
import org.apache.storm.blobstore.ClientBlobStore;
@@ -104,6 +103,7 @@ import
org.apache.storm.shade.com.google.common.collect.Maps;
import org.apache.storm.shade.net.minidev.json.JSONValue;
import org.apache.storm.shade.net.minidev.json.parser.ParseException;
import org.apache.storm.shade.org.apache.commons.io.FileUtils;
+import org.apache.storm.shade.org.apache.commons.io.IOUtils;
import org.apache.storm.shade.org.apache.commons.io.input.BoundedInputStream;
import
org.apache.storm.shade.org.apache.commons.io.input.ClassLoaderObjectInputStream;
import org.apache.storm.shade.org.apache.commons.lang3.StringUtils;
diff --git a/storm-server/pom.xml b/storm-server/pom.xml
index e8ab2a6b48..4e84470eb6 100644
--- a/storm-server/pom.xml
+++ b/storm-server/pom.xml
@@ -32,6 +32,16 @@
<name>Storm Server</name>
<properties>
<storm-server.test.introspection.argLine>--add-opens
java.base/java.lang=ALL-UNNAMED</storm-server.test.introspection.argLine>
+ <!-- Relocated packages of storm-shaded-deps that main code must not
import (check-unshaded-imports in the root pom).
+ Relocated packages that storm-server declares as dependencies are
allowed: commons-io,
+ commons-lang3, commons-collections4, json-smart
(net.minidev.json) and snakeyaml.
+ com.google is narrowed to com.google.common and
com.google.thirdparty, the packages in
+ the shaded jar, so the auto-service annotation stays allowed. -->
+ <unshaded.check.phase>validate</unshaded.check.phase>
+ <unshaded.illegalPkgs>org.apache.thrift, com.google.common,
+ com.google.thirdparty, org.apache.curator, org.apache.zookeeper,
org.apache.jute,
+ org.jctools, org.jboss.netty, io.netty, org.jgrapht,
org.apache.commons.codec,
+ net.minidev.asm, org.objectweb.asm, org.xerial.snappy,
uk.org.lidalia.sysoutslf4j</unshaded.illegalPkgs>
</properties>
<dependencies>
diff --git
a/storm-server/src/main/java/org/apache/storm/container/cgroup/CgroupManager.java
b/storm-server/src/main/java/org/apache/storm/container/cgroup/CgroupManager.java
index 4a89751a1f..2a410e9bfd 100644
---
a/storm-server/src/main/java/org/apache/storm/container/cgroup/CgroupManager.java
+++
b/storm-server/src/main/java/org/apache/storm/container/cgroup/CgroupManager.java
@@ -12,7 +12,6 @@
package org.apache.storm.container.cgroup;
-import com.google.common.annotations.VisibleForTesting;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -36,6 +35,7 @@ import org.apache.storm.container.cgroup.core.CpusetCore;
import org.apache.storm.container.cgroup.core.MemoryCore;
import org.apache.storm.daemon.supervisor.ClientSupervisorUtils;
import org.apache.storm.daemon.supervisor.ExitCodeCallback;
+import org.apache.storm.shade.com.google.common.annotations.VisibleForTesting;
import org.apache.storm.utils.ObjectReader;
import org.apache.storm.utils.ServerUtils;
import org.slf4j.Logger;
diff --git
a/storm-server/src/main/java/org/apache/storm/daemon/supervisor/Slot.java
b/storm-server/src/main/java/org/apache/storm/daemon/supervisor/Slot.java
index 27b8d7cc61..0c094bbcc2 100644
--- a/storm-server/src/main/java/org/apache/storm/daemon/supervisor/Slot.java
+++ b/storm-server/src/main/java/org/apache/storm/daemon/supervisor/Slot.java
@@ -12,7 +12,6 @@
package org.apache.storm.daemon.supervisor;
-import com.google.common.annotations.VisibleForTesting;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
@@ -42,6 +41,7 @@ import org.apache.storm.localizer.GoodToGo;
import org.apache.storm.localizer.LocallyCachedBlob;
import org.apache.storm.metricstore.WorkerMetricsProcessor;
import org.apache.storm.scheduler.ISupervisor;
+import org.apache.storm.shade.com.google.common.annotations.VisibleForTesting;
import org.apache.storm.utils.EnumUtil;
import org.apache.storm.utils.EquivalenceUtils;
import org.apache.storm.utils.LocalState;
diff --git
a/storm-server/src/main/java/org/apache/storm/scheduler/utils/SchedulerConfigCache.java
b/storm-server/src/main/java/org/apache/storm/scheduler/utils/SchedulerConfigCache.java
index e85bb9f7e9..71b660c290 100644
---
a/storm-server/src/main/java/org/apache/storm/scheduler/utils/SchedulerConfigCache.java
+++
b/storm-server/src/main/java/org/apache/storm/scheduler/utils/SchedulerConfigCache.java
@@ -12,12 +12,12 @@
package org.apache.storm.scheduler.utils;
-import com.google.common.base.Preconditions;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.storm.DaemonConfig;
import org.apache.storm.StormTimer;
+import org.apache.storm.shade.com.google.common.base.Preconditions;
import org.apache.storm.utils.ObjectReader;
import org.apache.storm.utils.Time;
import org.apache.storm.utils.Utils;
diff --git
a/storm-server/src/main/java/org/apache/storm/security/auth/workertoken/WorkerTokenManager.java
b/storm-server/src/main/java/org/apache/storm/security/auth/workertoken/WorkerTokenManager.java
index 1490328660..b8403277af 100644
---
a/storm-server/src/main/java/org/apache/storm/security/auth/workertoken/WorkerTokenManager.java
+++
b/storm-server/src/main/java/org/apache/storm/security/auth/workertoken/WorkerTokenManager.java
@@ -18,7 +18,6 @@
package org.apache.storm.security.auth.workertoken;
-import com.google.common.annotations.VisibleForTesting;
import java.nio.ByteBuffer;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
@@ -33,6 +32,7 @@ import org.apache.storm.generated.WorkerToken;
import org.apache.storm.generated.WorkerTokenInfo;
import org.apache.storm.generated.WorkerTokenServiceType;
import org.apache.storm.security.auth.ClientAuthUtils;
+import org.apache.storm.shade.com.google.common.annotations.VisibleForTesting;
import org.apache.storm.utils.ObjectReader;
import org.apache.storm.utils.Time;
import org.slf4j.Logger;
diff --git
a/storm-server/src/main/java/org/apache/storm/utils/EquivalenceUtils.java
b/storm-server/src/main/java/org/apache/storm/utils/EquivalenceUtils.java
index 66be019e55..044545f2af 100644
--- a/storm-server/src/main/java/org/apache/storm/utils/EquivalenceUtils.java
+++ b/storm-server/src/main/java/org/apache/storm/utils/EquivalenceUtils.java
@@ -18,7 +18,6 @@
package org.apache.storm.utils;
-import com.google.common.annotations.VisibleForTesting;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@@ -26,6 +25,7 @@ import java.util.Set;
import org.apache.storm.generated.ExecutorInfo;
import org.apache.storm.generated.LocalAssignment;
import org.apache.storm.generated.WorkerResources;
+import org.apache.storm.shade.com.google.common.annotations.VisibleForTesting;
public class EquivalenceUtils {
diff --git a/storm-shaded-deps/pom.xml b/storm-shaded-deps/pom.xml
index 2a7eeb354c..71547c728a 100644
--- a/storm-shaded-deps/pom.xml
+++ b/storm-shaded-deps/pom.xml
@@ -249,6 +249,8 @@
<include>uk.org.lidalia:sysout-over-slf4j</include>
</includes>
</artifactSet>
+ <!-- The unshaded.illegalPkgs properties in
storm-client/pom.xml and storm-server/pom.xml ban imports of these
+ relocated packages (check-unshaded-imports). Update
both when adding a relocated package. -->
<relocations>
<relocation>
<pattern>org.apache.thrift</pattern>