-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[JENKINS-45892] IllegalStateException at hudson.XmlFile.replaceIfNotA… #257
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
435efcc
[JENKINS-45892] IllegalStateException at hudson.XmlFile.replaceIfNotA…
carlossg d55cfce
[JENKINS-45892] Run should be transient in actions
carlossg 02b946d
Remove duplication
carlossg 86a15bc
Fix warning: finally block does not complete normally
carlossg 01d2767
Merge branch 'master' into JENKINS-45892
carlossg f49f8ef
[JENKINS-45892] Use the correct classes when looking for actions
carlossg 7728d9a
Lower the logging level
carlossg 4782429
Refactor PodTemplateAction and NamespaceAction
carlossg 70e8346
Refactor PodTemplateAction and NamespaceAction
carlossg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
...in/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/AbstractInvisibleRunAction2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2017, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package org.csanchez.jenkins.plugins.kubernetes.pipeline; | ||
|
||
import java.io.IOException; | ||
import java.util.Stack; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
import hudson.BulkChange; | ||
import hudson.model.InvisibleAction; | ||
import hudson.model.Run; | ||
import jenkins.model.RunAction2; | ||
|
||
/** | ||
* @author Carlos Sanchez | ||
* @since 1.1.1 | ||
* | ||
*/ | ||
public abstract class AbstractInvisibleRunAction2 extends InvisibleAction implements RunAction2 { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(AbstractInvisibleRunAction2.class.getName()); | ||
|
||
protected final Stack<String> stack = new Stack<>(); | ||
|
||
private transient Run<?, ?> run; | ||
|
||
public AbstractInvisibleRunAction2(Run<?, ?> run) { | ||
setRun(run); | ||
} | ||
|
||
protected abstract AbstractInvisibleRunAction2 createAction(Run<?, ?> run); | ||
|
||
public Run<?, ?> getRun() { | ||
return run; | ||
} | ||
|
||
protected void setRun(Run<?, ?> run) { | ||
this.run = run; | ||
} | ||
|
||
public void push(String item) throws IOException { | ||
if (run == null) { | ||
LOGGER.warning("run is null, cannot push"); | ||
return; | ||
} | ||
synchronized (run) { | ||
BulkChange bc = new BulkChange(run); | ||
try { | ||
AbstractInvisibleRunAction2 action = run.getAction(this.getClass()); | ||
if (action == null) { | ||
action = createAction(run); | ||
run.addAction(action); | ||
} | ||
LOGGER.log(Level.FINEST, "Pushing item {0} to action {1} in run {2}", | ||
new Object[] { item, action, run }); | ||
action.stack.push(item); | ||
bc.commit(); | ||
} finally { | ||
bc.abort(); | ||
} | ||
} | ||
} | ||
|
||
public String pop() throws IOException { | ||
if (run == null) { | ||
LOGGER.warning("run is null, cannot pop"); | ||
return null; | ||
} | ||
synchronized (getRun()) { | ||
BulkChange bc = new BulkChange(getRun()); | ||
try { | ||
AbstractInvisibleRunAction2 action = getRun().getAction(this.getClass()); | ||
if (action == null) { | ||
action = createAction(getRun()); | ||
getRun().addAction(action); | ||
} | ||
String item = action.stack.pop(); | ||
LOGGER.log(Level.FINEST, "Popped item {0} from action {1} in run {2}", | ||
new Object[] { item, action, run }); | ||
bc.commit(); | ||
return item; | ||
} finally { | ||
bc.abort(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void onAttached(Run<?, ?> r) { | ||
setRun(r); | ||
} | ||
|
||
@Override | ||
public void onLoad(Run<?, ?> r) { | ||
setRun(r); | ||
} | ||
|
||
} |
75 changes: 12 additions & 63 deletions
75
src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/NamespaceAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 12 additions & 61 deletions
73
src/main/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/PodTemplateAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
As I understand
RunAction2
, this is not necessary, asonAttached(Run)
will be called as soon as it is attached to aRun
instance.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.
it's used in the tests https://github.com/jenkinsci/kubernetes-plugin/blob/master/src/test/java/org/csanchez/jenkins/plugins/kubernetes/pipeline/KubernetesPipelineTest.java#L209