-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Deploy Environment Weights #13069
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: jetty-12.1.x
Are you sure you want to change the base?
Deploy Environment Weights #13069
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't really like the approach of setting weights everywhere.
I'd prefer a centralized approach. Just have a setter on the scanner that takes a list of environment names and the weight is the index of the env name in that list. We can have a default list with our known environments and it will be an error if an unknown env name needs to be sorted
…stom weight option alone.
…ploy-environment-weights
I reverted the XML and Test case changes.
I'm good up to the "and it will be an error if an unknown env name needs to be sorted" bit. This allows for new environments, which your proposal doesn't allow. We are down from 24 files changed, to 4 now in this PR. |
private final Server server; | ||
private final FilenameFilter filenameFilter; | ||
private final List<Path> monitoredDirs = new CopyOnWriteArrayList<>(); | ||
private final ContextHandlerFactory contextHandlerFactory; | ||
private final Map<String, PathsApp> trackedApps = new HashMap<>(); | ||
private final Map<String, Attributes> environmentAttributesMap = new HashMap<>(); | ||
private Set<String> trackedEnvironments = new TreeSet<>(String.CASE_INSENSITIVE_ORDER); | ||
private List<TrackedEnv> trackedEnvironments = new ArrayList<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it final
.
@@ -301,20 +272,56 @@ void addScannerListener(Scanner.Listener listener) | |||
scanner.addListener(listener); | |||
} | |||
|
|||
protected int getDefaultWeight(String name) | |||
{ | |||
URL url = getClass().getResource("environment-weights.properties"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this will work if DeploymentScanner
is subclassed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A properties file is too hard to change and it still makes weights in the "API". We don't need weights, we just need an order. If somebody defines a new environment, then setting a new order is easier than inventing a weight that is robust to future changes.
@@ -301,20 +272,56 @@ void addScannerListener(Scanner.Listener listener) | |||
scanner.addListener(listener); | |||
} | |||
|
|||
protected int getDefaultWeight(String name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this method.
We should just have configureEnvironment(String, int)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Read Greg's review, he didn't like this approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, I don't like the current one.
We decided to shy away from "default" environments, so the core
environment was not created upfront, etc. so why now we should have upfront weights?
The weights are not everywhere, they are just in 1 method of DeploymentScanner
.
Only Jetty XML code should call that method, so a custom corp-deploy
module should just be aware of Jetty's xyz-deploy
modules, if they are used simultaneously with corp-deploy
.
Otherwise, there are no Jetty xyz-deploy
modules in use, we don't load our environment-weights.properties
that we don't use, and there only will be corp-deploy
and spring-corp-deploy
, with the weights they decide to use.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A prior commit did this
See the revert at 00f95a7 for how it looked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't like this approach either. I don't like the concept of weights being seen externally at all, as it is just an abstraction that we don't need to both the user with. I think we should just have:
void setEnvironmentOrder(List<String> environmentNames);
List<String> getEnvironmentOrder();
With the default value being ["core", "static", "ee8", "ee9", "ee10", "ee11"]
.
If internally we turn that into weights, then fine, but no weights should be in any public API.
* (Example usage: {@code static} is 100, {@code core} is 200, {@code ee8} is 1008, {@code ee11} is 1011) | ||
* @return the deployment configuration for the {@link Environment}. | ||
*/ | ||
public EnvironmentConfig configureEnvironment(String name, int weight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just have this method and delete configureEnvironment(String name)
.
Rename this to trackEnvironment()
maybe?
The XML files will pass in the weight and there will be no need for the environment-weights.properties
file.
This method is only called by tests or XML files.
|
||
trackedEnvironments.add(new TrackedEnv(name, weight)); | ||
} | ||
|
||
public void setDefaultEnvironmentName(String name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method should be removed there is no concept of default, if not determined by the environments that are enabled.
.toList(); | ||
} | ||
|
||
protected void addTrackedEnvironment(String name, int weight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make it private or package.
@@ -346,12 +353,29 @@ public String getDefaultEnvironmentName() | |||
if (defaultEnvironmentName == null) | |||
{ | |||
return trackedEnvironments.stream() | |||
.min(ENVIRONMENT_COMPARATOR) | |||
.max(Comparator.comparing(TrackedEnv::weight)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Method getDefaultEnvironmentName()
should be private.
DeploymentScanner deploymentScanner = new DeploymentScanner(new Server()); | ||
for (Map.Entry<String, Integer> entry : input.entrySet()) | ||
{ | ||
deploymentScanner.addTrackedEnvironment(entry.getKey(), entry.getValue()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be:
deploymentScanner.addTrackedEnvironment(entry.getKey(), entry.getValue()); | |
deploymentScanner.configureEnvironment(entry.getKey(), entry.getValue()); |
@@ -1684,4 +1721,8 @@ else if (ret != PathsApp.State.REMOVED) | |||
return ret != null ? ret : PathsApp.State.UNCHANGED; | |||
} | |||
} | |||
|
|||
record TrackedEnv(String name, int weight) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TrackedEnv -> TrackedEnvironment
public void testDefaultWeights() | ||
{ | ||
DeploymentScanner deploymentScanner = new DeploymentScanner(new Server()); | ||
assertThat(deploymentScanner.getDefaultWeight("core"), is(200)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is too much magic here.
Where the 200 come from?
I would expect this test to call configureEnvironment("core", 200)
before the asserts, so it's clear where the 200 comes from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like weights being in the API at all. Just have an order list.
@@ -301,20 +272,56 @@ void addScannerListener(Scanner.Listener listener) | |||
scanner.addListener(listener); | |||
} | |||
|
|||
protected int getDefaultWeight(String name) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still don't like this approach either. I don't like the concept of weights being seen externally at all, as it is just an abstraction that we don't need to both the user with. I think we should just have:
void setEnvironmentOrder(List<String> environmentNames);
List<String> getEnvironmentOrder();
With the default value being ["core", "static", "ee8", "ee9", "ee10", "ee11"]
.
If internally we turn that into weights, then fine, but no weights should be in any public API.
@@ -301,20 +272,56 @@ void addScannerListener(Scanner.Listener listener) | |||
scanner.addListener(listener); | |||
} | |||
|
|||
protected int getDefaultWeight(String name) | |||
{ | |||
URL url = getClass().getResource("environment-weights.properties"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A properties file is too hard to change and it still makes weights in the "API". We don't need weights, we just need an order. If somebody defines a new environment, then setting a new order is easier than inventing a weight that is robust to future changes.
@gregw I don't see how the "order list" would work in case of custom environments. With weights in the APIs, users will be exposed to the fact that there is an order, while calling Furthermore, we would have to remember to update that list for every new EE version, while with weights, we just need to copy We don't bother users with weights, just implementers of new deployment environments, which should be rare. |
Enhancement to handle Default Environment sorting via weights assigned to the Environment when the environment is configured with the DeploymentScanner.