Search in sources :

Example 1 with CITriggerThread

use of com.redhat.jenkins.plugins.ci.threads.CITriggerThread in project jms-messaging-plugin by jenkinsci.

the class CIBuildTrigger method startTriggerThreads.

private void startTriggerThreads() {
    if (job == null)
        return;
    if (providerUpdated) {
        log.info("Saving job since messaging provider was migrated...");
        try {
            job.save();
        } catch (IOException e) {
            log.warning("Exception while trying to save job: " + e.getMessage());
        }
    }
    if (job instanceof AbstractProject) {
        AbstractProject<?, ?> aJob = (AbstractProject<?, ?>) job;
        if (aJob.isDisabled()) {
            log.info("Job '" + job.getFullName() + "' is disabled, not subscribing.");
            return;
        }
    }
    try {
        synchronized (locks.computeIfAbsent(job.getFullName(), o -> new ArrayList<>())) {
            if (stopTriggerThreads(job.getFullName()) == null && providers != null) {
                List<CITriggerThread> threads = locks.get(job.getFullName());
                int instance = 1;
                for (ProviderData pd : providers) {
                    JMSMessagingProvider provider = GlobalCIConfiguration.get().getProvider(pd.getName());
                    if (provider == null) {
                        log.log(Level.SEVERE, "Failed to locate JMSMessagingProvider with name " + pd.getName() + ". You must update the job configuration. Trigger not started.");
                        return;
                    }
                    CITriggerThread thread = CITriggerThreadFactory.createCITriggerThread(provider, pd, job.getFullName(), this, instance);
                    log.info("Starting thread (" + thread.getId() + ") for '" + job.getFullName() + "'.");
                    thread.start();
                    threads.add(thread);
                    instance++;
                }
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "Unhandled exception in trigger start.", e);
    }
}
Also used : FedMsgSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.FedMsgSubscriberProviderData) ProviderData(com.redhat.jenkins.plugins.ci.provider.data.ProviderData) ActiveMQSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData) CITriggerThread(com.redhat.jenkins.plugins.ci.threads.CITriggerThread) JMSMessagingProvider(com.redhat.jenkins.plugins.ci.messaging.JMSMessagingProvider) IOException(java.io.IOException) AbstractProject(hudson.model.AbstractProject) IOException(java.io.IOException)

Example 2 with CITriggerThread

use of com.redhat.jenkins.plugins.ci.threads.CITriggerThread in project jms-messaging-plugin by jenkinsci.

the class CIBuildTrigger method stopTriggerThreads.

private List<CITriggerThread> stopTriggerThreads(String fullName, List<CITriggerThread> comparisonThreads) {
    synchronized (locks.computeIfAbsent(fullName, o -> new ArrayList<>())) {
        List<CITriggerThread> threads = locks.get(fullName);
        // If threads are the same we have start/stop sequence, so don't bother stopping.
        if (comparisonThreads != null && threads.size() == comparisonThreads.size()) {
            for (CITriggerThread thread : threads) {
                for (int i = 0; i < comparisonThreads.size(); i++) {
                    if (thread.equals(comparisonThreads.get(i))) {
                        log.info("Already have thread " + thread.getId() + "...");
                        comparisonThreads.remove(i);
                        break;
                    }
                }
            }
            if (comparisonThreads.size() == 0) {
                return threads;
            }
        }
        for (CITriggerThread thread : threads) {
            try {
                log.info("Stopping thread (" + thread.getId() + ") for '" + fullName + "'.");
                thread.shutdown();
            } catch (Exception e) {
                log.log(Level.SEVERE, "Unhandled exception in trigger stop.", e);
            }
        }
        // Just in case.
        threads.clear();
        log.fine("Removed thread lock for '" + fullName + "'.");
    }
    return null;
}
Also used : CITriggerThread(com.redhat.jenkins.plugins.ci.threads.CITriggerThread) IOException(java.io.IOException)

Example 3 with CITriggerThread

use of com.redhat.jenkins.plugins.ci.threads.CITriggerThread in project jms-messaging-plugin by jenkinsci.

the class CIBuildTrigger method getComparisonThreads.

private List<CITriggerThread> getComparisonThreads() {
    if (providers != null && job != null) {
        List<CITriggerThread> threads = new ArrayList<>();
        int instance = 1;
        for (ProviderData pd : providers) {
            JMSMessagingProvider provider = GlobalCIConfiguration.get().getProvider(pd.getName());
            // The thread is never started.
            if (provider == null)
                throw new NullPointerException("No such provider configured for name: '" + pd.getName() + "' on job named '" + job.getFullName() + "'");
            CITriggerThread thread = new CITriggerThread(provider, pd, job.getFullName(), null, instance);
            threads.add(thread);
            instance++;
        }
        return threads;
    }
    return null;
}
Also used : FedMsgSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.FedMsgSubscriberProviderData) ProviderData(com.redhat.jenkins.plugins.ci.provider.data.ProviderData) ActiveMQSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData) CITriggerThread(com.redhat.jenkins.plugins.ci.threads.CITriggerThread) ArrayList(java.util.ArrayList) JMSMessagingProvider(com.redhat.jenkins.plugins.ci.messaging.JMSMessagingProvider)

Aggregations

CITriggerThread (com.redhat.jenkins.plugins.ci.threads.CITriggerThread)3 JMSMessagingProvider (com.redhat.jenkins.plugins.ci.messaging.JMSMessagingProvider)2 ActiveMQSubscriberProviderData (com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData)2 FedMsgSubscriberProviderData (com.redhat.jenkins.plugins.ci.provider.data.FedMsgSubscriberProviderData)2 ProviderData (com.redhat.jenkins.plugins.ci.provider.data.ProviderData)2 IOException (java.io.IOException)2 AbstractProject (hudson.model.AbstractProject)1 ArrayList (java.util.ArrayList)1