Search in sources :

Example 6 with BulkChange

use of hudson.BulkChange in project support-core-plugin by jenkinsci.

the class InetAddressContentFilterTest method shouldFilterInetAddresses.

@Issue("JENKINS-21670")
@Test
public void shouldFilterInetAddresses() {
    InetAddressContentFilter filter = InetAddressContentFilter.get();
    // speed up test execution by ignoring new content mappings
    ContentMappings mappings = ContentMappings.get();
    try (BulkChange ignored = new BulkChange(mappings)) {
        qt().forAll(inetAddress()).checkAssert(address -> assertThat(ContentFilter.filter(filter, address)).contains("ip_").doesNotContain(address));
    }
}
Also used : BulkChange(hudson.BulkChange) Issue(org.jvnet.hudson.test.Issue)

Example 7 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) {
                        try {
                            listener.onNewHead(node);
                        } catch (Throwable x) {
                            LOGGER.log(Level.WARNING, null, x);
                        }
                    }
                }
            }
        } 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) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException) GraphListener(org.jenkinsci.plugins.workflow.flow.GraphListener) Queue(hudson.model.Queue) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Example 8 with BulkChange

use of hudson.BulkChange in project configuration-as-code-plugin by jenkinsci.

the class BaseConfigurator method configure.

@NonNull
@Override
public T configure(CNode c, ConfigurationContext context) throws ConfiguratorException {
    final Mapping mapping = (c != null ? c.asMapping() : Mapping.EMPTY);
    final T instance = instance(mapping, context);
    if (instance instanceof Saveable) {
        try (BulkChange bc = new BulkChange((Saveable) instance)) {
            configure(mapping, instance, false, context);
            bc.commit();
        } catch (IOException e) {
            throw new ConfiguratorException("Failed to save " + instance, e);
        }
    } else {
        configure(mapping, instance, false, context);
    }
    return instance;
}
Also used : Saveable(hudson.model.Saveable) BulkChange(hudson.BulkChange) Mapping(io.jenkins.plugins.casc.model.Mapping) IOException(java.io.IOException) NonNull(edu.umd.cs.findbugs.annotations.NonNull)

Example 9 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 10 with BulkChange

use of hudson.BulkChange in project workflow-job-plugin by jenkinsci.

the class WorkflowJob method setResumeBlocked.

@Override
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)

Aggregations

BulkChange (hudson.BulkChange)28 JSONObject (net.sf.json.JSONObject)7 POST (org.kohsuke.stapler.verb.POST)7 IOException (java.io.IOException)6 RequirePOST (org.kohsuke.stapler.interceptor.RequirePOST)5 Test (org.junit.Test)4 CountDownLatch (java.util.concurrent.CountDownLatch)3 NonNull (edu.umd.cs.findbugs.annotations.NonNull)2 FormException (hudson.model.Descriptor.FormException)2 FreeStyleBuild (hudson.model.FreeStyleBuild)2 FreeStyleProject (hudson.model.FreeStyleProject)2 Saveable (hudson.model.Saveable)2 NodeMonitor (hudson.node_monitors.NodeMonitor)2 PipelineTriggersJobProperty (org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty)2 Content (com.cloudbees.jenkins.support.api.Content)1 UnfilteredStringContent (com.cloudbees.jenkins.support.api.UnfilteredStringContent)1 ContentFilter (com.cloudbees.jenkins.support.filter.ContentFilter)1 ContentMappings (com.cloudbees.jenkins.support.filter.ContentMappings)1 FilteredOutputStream (com.cloudbees.jenkins.support.filter.FilteredOutputStream)1 PrefilteredContent (com.cloudbees.jenkins.support.filter.PrefilteredContent)1