Search in sources :

Example 1 with BulkChange

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);
                }
            }
        }
    }
}
Also used : Saveable(hudson.model.Saveable) BulkChange(hudson.BulkChange) IOException(java.io.IOException) GraphListener(org.jenkinsci.plugins.workflow.flow.GraphListener) Queue(hudson.model.Queue) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Example 2 with BulkChange

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);
    }
}
Also used : DisableResumeJobProperty(org.jenkinsci.plugins.workflow.job.properties.DisableResumeJobProperty) BulkChange(hudson.BulkChange) IOException(java.io.IOException)

Example 3 with BulkChange

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();
        }
    }
}
Also used : DisableConcurrentBuildsJobProperty(org.jenkinsci.plugins.workflow.job.properties.DisableConcurrentBuildsJobProperty) BulkChange(hudson.BulkChange)

Example 4 with BulkChange

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;
}
Also used : FormException(hudson.model.Descriptor.FormException) BuildStepDescriptor(hudson.tasks.BuildStepDescriptor) Descriptor(hudson.model.Descriptor) BulkChange(hudson.BulkChange) Failure(hudson.model.Failure)

Example 5 with BulkChange

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();
    }
}
Also used : DefaultMyViewsTabBar(hudson.views.DefaultMyViewsTabBar) MyViewsTabBar(hudson.views.MyViewsTabBar) BulkChange(hudson.BulkChange) DefaultViewsTabBar(hudson.views.DefaultViewsTabBar) DefaultMyViewsTabBar(hudson.views.DefaultMyViewsTabBar) ViewsTabBar(hudson.views.ViewsTabBar) MyViewsTabBar(hudson.views.MyViewsTabBar) DefaultMyViewsTabBar(hudson.views.DefaultMyViewsTabBar) FormException(hudson.model.Descriptor.FormException) TcpSlaveAgentListener(hudson.TcpSlaveAgentListener) JSONObject(net.sf.json.JSONObject) RawHtmlMarkupFormatter(hudson.markup.RawHtmlMarkupFormatter) MarkupFormatter(hudson.markup.MarkupFormatter) DefaultViewsTabBar(hudson.views.DefaultViewsTabBar)

Aggregations

BulkChange (hudson.BulkChange)10 JSONObject (net.sf.json.JSONObject)3 FormException (hudson.model.Descriptor.FormException)2 IOException (java.io.IOException)2 PipelineTriggersJobProperty (org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty)2 TcpSlaveAgentListener (hudson.TcpSlaveAgentListener)1 MarkupFormatter (hudson.markup.MarkupFormatter)1 RawHtmlMarkupFormatter (hudson.markup.RawHtmlMarkupFormatter)1 Descriptor (hudson.model.Descriptor)1 Failure (hudson.model.Failure)1 Queue (hudson.model.Queue)1 Saveable (hudson.model.Saveable)1 NodeMonitor (hudson.node_monitors.NodeMonitor)1 DumbSlave (hudson.slaves.DumbSlave)1 BuildStepDescriptor (hudson.tasks.BuildStepDescriptor)1 SCMTrigger (hudson.triggers.SCMTrigger)1 Trigger (hudson.triggers.Trigger)1 DefaultMyViewsTabBar (hudson.views.DefaultMyViewsTabBar)1 DefaultViewsTabBar (hudson.views.DefaultViewsTabBar)1 MyViewsTabBar (hudson.views.MyViewsTabBar)1