Search in sources :

Example 6 with JMSMessagingProvider

use of com.redhat.jenkins.plugins.ci.messaging.JMSMessagingProvider 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 7 with JMSMessagingProvider

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

the class CIBuildTrigger method readResolve.

@Override
protected Object readResolve() {
    if (providers == null) {
        log.info("Migrating CIBuildTrigger for job '" + getJobName() + "'.");
        providers = new ArrayList<>();
        if (providerData == null) {
            if (providerName == null) {
                log.info("Provider is null for trigger for job '" + getJobName() + "'.");
                JMSMessagingProvider provider = GlobalCIConfiguration.get().getConfigs().get(0);
                if (provider != null) {
                    providerName = provider.getName();
                    providerUpdated = true;
                    saveJob();
                }
            }
            JMSMessagingProvider provider = GlobalCIConfiguration.get().getProvider(providerName);
            if (provider != null) {
                if (provider instanceof ActiveMqMessagingProvider) {
                    log.info("Creating '" + providerName + "' trigger provider data for job '" + getJobName() + "'.");
                    ActiveMQSubscriberProviderData a = new ActiveMQSubscriberProviderData(providerName);
                    a.setSelector(selector);
                    a.setOverrides(overrides);
                    a.setChecks(checks);
                    providers.add(a);
                    providerUpdated = true;
                    saveJob();
                } else if (provider instanceof FedMsgMessagingProvider) {
                    log.info("Creating '" + providerName + "' trigger provider data for job '" + getJobName() + "'.");
                    FedMsgSubscriberProviderData f = new FedMsgSubscriberProviderData(providerName);
                    f.setOverrides(overrides);
                    f.setChecks(checks);
                    providers.add(f);
                    providerUpdated = true;
                    saveJob();
                }
            } else {
                log.warning("Unable to find provider '" + providerName + "', so unable to upgrade job.");
            }
        } else {
            providers.add(providerData);
            providerUpdated = true;
            saveJob();
        }
    }
    return this;
}
Also used : FedMsgSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.FedMsgSubscriberProviderData) ActiveMqMessagingProvider(com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingProvider) ActiveMQSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData) JMSMessagingProvider(com.redhat.jenkins.plugins.ci.messaging.JMSMessagingProvider) FedMsgMessagingProvider(com.redhat.jenkins.plugins.ci.messaging.FedMsgMessagingProvider)

Example 8 with JMSMessagingProvider

use of com.redhat.jenkins.plugins.ci.messaging.JMSMessagingProvider 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

JMSMessagingProvider (com.redhat.jenkins.plugins.ci.messaging.JMSMessagingProvider)8 ActiveMqMessagingProvider (com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingProvider)5 ActiveMQSubscriberProviderData (com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData)4 DefaultTopicProvider (com.redhat.jenkins.plugins.ci.messaging.topics.DefaultTopicProvider)3 FedMsgSubscriberProviderData (com.redhat.jenkins.plugins.ci.provider.data.FedMsgSubscriberProviderData)3 AbstractProject (hudson.model.AbstractProject)3 Test (org.junit.Test)3 LocalData (org.jvnet.hudson.test.recipes.LocalData)3 UsernameAuthenticationMethod (com.redhat.jenkins.plugins.ci.authentication.activemq.UsernameAuthenticationMethod)2 ProviderData (com.redhat.jenkins.plugins.ci.provider.data.ProviderData)2 CITriggerThread (com.redhat.jenkins.plugins.ci.threads.CITriggerThread)2 FreeStyleProject (hudson.model.FreeStyleProject)2 FedMsgMessagingProvider (com.redhat.jenkins.plugins.ci.messaging.FedMsgMessagingProvider)1 JMSMessagingWorker (com.redhat.jenkins.plugins.ci.messaging.JMSMessagingWorker)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1