Clover icon

Jenkins Monitor 0.1.4-SNAPSHOT_jdk19

  1. Project Clover database So. Apr. 23 2023 11:22:19 UTC
  2. Package com.github.funthomas424242.jenkinsmonitor.jenkins

File JenkinsRESTClient.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
36% of files have more coverage

Code metrics

0
18
2
1
74
43
3
0,17
9
2
1,5

Classes

Class Line # Actions
JenkinsRESTClient 35 18 3
0.770%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    package com.github.funthomas424242.jenkinsmonitor.jenkins;
2   
3    /*-
4    * #%L
5    * Jenkins Monitor
6    * %%
7    * Copyright (C) 2019 PIUG
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10    * it under the terms of the GNU Lesser General Public License as
11    * published by the Free Software Foundation, either version 3 of the
12    * License, or (at your option) any later version.
13    *
14    * This program is distributed in the hope that it will be useful,
15    * but WITHOUT ANY WARRANTY; without even the implied warranty of
16    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17    * GNU General Lesser Public License for more details.
18    *
19    * You should have received a copy of the GNU General Lesser Public
20    * License along with this program. If not, see
21    * <http://www.gnu.org/licenses/lgpl-3.0.html>.
22    * #L%
23    */
24   
25    import java.util.concurrent.ExecutionException;
26    import java.util.concurrent.Executors;
27    import java.util.concurrent.Future;
28    import java.util.concurrent.ThreadPoolExecutor;
29    import java.util.concurrent.TimeUnit;
30    import java.util.concurrent.TimeoutException;
31    import org.slf4j.Logger;
32    import org.slf4j.LoggerFactory;
33   
34   
 
35    public class JenkinsRESTClient {
36   
37    protected static final Logger LOG = LoggerFactory.getLogger(JenkinsRESTClient.class);
38   
 
39  1 toggle public void ladeJobsStatus(final AbstractJobBeschreibungen<JobStatusBeschreibung> jobStatusBeschreibungen, final JobBeschreibungen jobBeschreibungen) {
40  1 LOG.debug("Frage Jobstatus ab");
41  1 final ThreadPoolExecutor executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(10);
42  1 AbstractJobBeschreibung.sortedStreamOf(jobBeschreibungen)
43    .parallel()
44    .map(beschreibung -> {
45  1 final JobAbfrage jobAbfrage
46    = new JobAbfrage(beschreibung.getJobAbfragedaten(), beschreibung.getJobOrderId());
47  1 final Future<JobStatusBeschreibung> jobAbfrageFuture = executor.submit(jobAbfrage);
48  1 return new JobAbfrageFutureWrapper(jobAbfrage, jobAbfrageFuture);
49    })
50    .map(jobAbfrageFutureWrapper -> {
51  1 final Future<JobStatusBeschreibung> future = jobAbfrageFutureWrapper.getJobAbfrageFuture();
52  1 JobStatusBeschreibung jobStatusBeschreibung;
53  1 try {
54  1 jobStatusBeschreibung = future.get(5, TimeUnit.SECONDS);
55    } catch (InterruptedException | TimeoutException | ExecutionException ex) { // NOSONAR java:S2142
56  0 LOG.warn("Read Future Result goes wrong with exception: \n {}", ex.toString());
57  0 jobStatusBeschreibung =getJobStatusOTHER(jobAbfrageFutureWrapper);
58  0 future.cancel(true);
59    }
60  1 LOG.debug("JobStatus geladen: {} : {} at {} ", jobStatusBeschreibung.getJobName(), jobStatusBeschreibung.getJobStatus(), jobStatusBeschreibung.getJobUrl().toExternalForm());
61  1 return jobStatusBeschreibung;
62    })
63    .forEach(jobStatusBeschreibung -> jobStatusBeschreibungen.put(jobStatusBeschreibung.getPrimaryKey(), jobStatusBeschreibung));
64  1 executor.shutdown();
65    }
66   
 
67  0 toggle private static JobStatusBeschreibung getJobStatusOTHER( final JobAbfrageFutureWrapper jobAbfrageFutureWrapper) {
68  0 final JobAbfrage jobAbfrage = jobAbfrageFutureWrapper.getJobAbfrage();
69  0 return new JobStatusBeschreibung("Connection Timeout" + jobAbfrage.getAbfrageUrl().toExternalForm(), JobStatus.OTHER, jobAbfrage.getAbfrageUrl(), jobAbfrage.getJobOrderId());
70    }
71    }
72   
73   
74