use of hudson.BulkChange in project workflow-cps-plugin by jenkinsci.
the class CpsFlowExecution method notifyListeners.
void notifyListeners(List<FlowNode> nodes, boolean synchronous) {
List<GraphListener> toRun = getListenersToRun();
if (!toRun.isEmpty()) {
Saveable s = Saveable.NOOP;
try {
Queue.Executable exec = owner.getExecutable();
if (exec instanceof Saveable) {
s = (Saveable) exec;
}
} catch (IOException x) {
LOGGER.log(Level.WARNING, "failed to notify listeners of changes to " + nodes + " in " + this, x);
}
BulkChange bc = new BulkChange(s);
try {
for (FlowNode node : nodes) {
for (GraphListener listener : toRun) {
if (listener instanceof GraphListener.Synchronous == synchronous) {
listener.onNewHead(node);
}
}
}
} finally {
if (synchronous) {
// hack to skip save—we are holding a lock
bc.abort();
} else {
try {
bc.commit();
} catch (IOException x) {
LOGGER.log(Level.WARNING, null, x);
}
}
}
}
}
use of hudson.BulkChange in project workflow-job-plugin by jenkinsci.
the class WorkflowJob method setResumeBlocked.
public void setResumeBlocked(boolean resumeBlocked) {
try {
boolean previousState = isResumeBlocked();
if (resumeBlocked != previousState) {
BulkChange bc = new BulkChange(this);
try {
removeProperty(DisableResumeJobProperty.class);
if (resumeBlocked) {
addProperty(new DisableResumeJobProperty());
}
bc.commit();
} finally {
bc.abort();
}
}
} catch (IOException ioe) {
LOGGER.log(Level.WARNING, "Error persisting resume property statue", ioe);
}
}
use of hudson.BulkChange in project workflow-job-plugin by jenkinsci.
the class WorkflowJob method setConcurrentBuild.
public void setConcurrentBuild(boolean b) throws IOException {
concurrentBuild = null;
boolean propertyExists = getProperty(DisableConcurrentBuildsJobProperty.class) != null;
// does not exist, we need to add the property. Yay for flipping boolean values around!
if (propertyExists == b) {
BulkChange bc = new BulkChange(this);
try {
removeProperty(DisableConcurrentBuildsJobProperty.class);
if (!b) {
addProperty(new DisableConcurrentBuildsJobProperty());
}
bc.commit();
} finally {
bc.abort();
}
}
}
use of hudson.BulkChange in project promoted-builds-plugin by jenkinsci.
the class PromotionProcess method fromJson.
/**
* Creates unconnected {@link PromotionProcess} instance from the JSON configuration.
* This is mostly only useful for capturing its configuration in XML format.
* @param req Request
* @param o JSON object with source data
* @throws FormException form submission issue, includes form validation
* @throws IOException {@link PromotionProcess} creation issue
* @return Parsed promotion process
*/
public static PromotionProcess fromJson(StaplerRequest req, JSONObject o) throws FormException, IOException {
String name = o.getString("name");
try {
Jenkins.checkGoodName(name);
} catch (Failure f) {
throw new Descriptor.FormException(f.getMessage(), name);
}
PromotionProcess p = new PromotionProcess(null, name);
BulkChange bc = new BulkChange(p);
try {
// apply configuration. prevent it from trying to save to disk while we do this
p.configure(req, o);
} finally {
bc.abort();
}
return p;
}
use of hudson.BulkChange in project hudson-2.x by hudson.
the class Hudson method doConfigSubmit.
//
//
// actions
//
//
/**
* Accepts submission from the configuration page.
*/
public synchronized void doConfigSubmit(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, FormException {
BulkChange bc = new BulkChange(this);
try {
checkPermission(ADMINISTER);
JSONObject json = req.getSubmittedForm();
// useSecurity = null;
if (json.has("use_security")) {
useSecurity = true;
JSONObject security = json.getJSONObject("use_security");
setSecurityRealm(SecurityRealm.all().newInstanceFromRadioList(security, "realm"));
setAuthorizationStrategy(AuthorizationStrategy.all().newInstanceFromRadioList(security, "authorization"));
if (security.has("markupFormatter")) {
markupFormatter = req.bindJSON(MarkupFormatter.class, security.getJSONObject("markupFormatter"));
} else {
markupFormatter = null;
}
} else {
useSecurity = null;
setSecurityRealm(SecurityRealm.NO_AUTHENTICATION);
authorizationStrategy = AuthorizationStrategy.UNSECURED;
markupFormatter = null;
}
if (json.has("csrf")) {
JSONObject csrf = json.getJSONObject("csrf");
setCrumbIssuer(CrumbIssuer.all().newInstanceFromRadioList(csrf, "issuer"));
} else {
setCrumbIssuer(null);
}
if (json.has("viewsTabBar")) {
viewsTabBar = req.bindJSON(ViewsTabBar.class, json.getJSONObject("viewsTabBar"));
} else {
viewsTabBar = new DefaultViewsTabBar();
}
if (json.has("myViewsTabBar")) {
myViewsTabBar = req.bindJSON(MyViewsTabBar.class, json.getJSONObject("myViewsTabBar"));
} else {
myViewsTabBar = new DefaultMyViewsTabBar();
}
primaryView = json.has("primaryView") ? json.getString("primaryView") : getViews().iterator().next().getViewName();
noUsageStatistics = json.has("usageStatisticsCollected") ? null : true;
{
String v = req.getParameter("slaveAgentPortType");
if (!isUseSecurity() || v == null || v.equals("random")) {
slaveAgentPort = 0;
} else if (v.equals("disable")) {
slaveAgentPort = -1;
} else {
try {
slaveAgentPort = Integer.parseInt(req.getParameter("slaveAgentPort"));
} catch (NumberFormatException e) {
throw new FormException(Messages.Hudson_BadPortNumber(req.getParameter("slaveAgentPort")), "slaveAgentPort");
}
}
// relaunch the agent
if (tcpSlaveAgentListener == null) {
if (slaveAgentPort != -1) {
tcpSlaveAgentListener = new TcpSlaveAgentListener(slaveAgentPort);
}
} else {
if (tcpSlaveAgentListener.configuredPort != slaveAgentPort) {
tcpSlaveAgentListener.shutdown();
tcpSlaveAgentListener = null;
if (slaveAgentPort != -1) {
tcpSlaveAgentListener = new TcpSlaveAgentListener(slaveAgentPort);
}
}
}
}
numExecutors = json.getInt("numExecutors");
if (req.hasParameter("master.mode")) {
mode = Mode.valueOf(req.getParameter("master.mode"));
} else {
mode = Mode.NORMAL;
}
label = json.optString("labelString", "");
quietPeriod = json.getInt("quiet_period");
scmCheckoutRetryCount = json.getInt("retry_count");
systemMessage = Util.nullify(req.getParameter("system_message"));
jdks.clear();
jdks.addAll(req.bindJSONToList(JDK.class, json.get("jdks")));
boolean result = true;
for (Descriptor<?> d : Functions.getSortedDescriptorsForGlobalConfig()) {
result &= configureDescriptor(req, json, d);
}
for (JSONObject o : StructuredForm.toList(json, "plugin")) {
pluginManager.getPlugin(o.getString("name")).getPlugin().configure(req, o);
}
clouds.rebuildHetero(req, json, Cloud.all(), "cloud");
JSONObject np = json.getJSONObject("globalNodeProperties");
if (np != null) {
globalNodeProperties.rebuild(req, np, NodeProperty.for_(this));
}
version = VERSION;
save();
updateComputerList();
if (result) {
// go to the top page
rsp.sendRedirect(req.getContextPath() + '/');
} else {
// back to config
rsp.sendRedirect("configure");
}
} finally {
bc.commit();
}
}
Aggregations