Skip to content

Commit

Permalink
feat: add caching feature in global config (refs #272)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasbjerre committed Aug 19, 2023
1 parent ef3289a commit fbad1b6
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 17 deletions.
22 changes: 14 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,20 @@ The token can be supplied as a:

- Request parameter:

`curl -vs http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=abc123 2>&1`
`curl -vs "http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=abc123" 2>&1`
- Token header:

`curl -vs -H "token: abc123" http://localhost:8080/jenkins/generic-webhook-trigger/invoke 2>&1`
`curl -vs -H "token: abc123" "http://localhost:8080/jenkins/generic-webhook-trigger/invoke" 2>&1`
- It will also detect `X-Gitlab-Token`.
- _Authorization_ header of type _Bearer_ :

`curl -vs -H "Authorization: Bearer abc123" http://localhost:8080/jenkins/generic-webhook-trigger/invoke 2>&1`
`curl -vs -H "Authorization: Bearer abc123" "http://localhost:8080/jenkins/generic-webhook-trigger/invoke" 2>&1`

## Cache jobs

When plugin is used in large installations it may need some time to retrieve all configured jobs. This can be cached by enabling it in the global configuration. When enabled, the plugin will cache configured jobs for a configured time. The plugin will automatically refresh the cache so that any calls will use the cached value. This means the effect of any changes to any configured job will be delayed.

The cache will only be used in invocations where a `token` is supplied.

## Trigger exactly one build

Expand Down Expand Up @@ -106,26 +112,26 @@ If you are fiddling with expressions, you may want to checkout:
It's probably easiest to do with `curl`. Given that you have configured a Jenkins job to trigger on Generic Webhook, here are some examples of how to start the jobs.

```bash
curl -vs http://localhost:8080/jenkins/generic-webhook-trigger/invoke 2>&1
curl -vs "http://localhost:8080/jenkins/generic-webhook-trigger/invoke" 2>&1
```

This should start your job, if the job has no `token` configured and no security enabled. If you have security enabled you may need to authenticate:

```bash
curl -vs http://theusername:thepasssword@localhost:8080/jenkins/generic-webhook-trigger/invoke 2>&1
curl -vs "http://theusername:thepasssword@localhost:8080/jenkins/generic-webhook-trigger/invoke" 2>&1
```

If your job has a `token` you don't need to supply other credentials. You can specify the `token` like this:

```bash
curl -vs http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=TOKEN_HERE 2>&1
curl -vs "http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=TOKEN_HERE" 2>&1
```
Please keep in mind, using a token always runs the triggered jobs with SYSTEM privileges.

If you want to trigger with `token` and some post content, `curl` can dot that like this.

```bash
curl -v -H "Content-Type: application/json" -X POST -d '{ "app":{ "name":"some value" }}' http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=TOKEN_HERE
curl -v -H "Content-Type: application/json" -X POST -d '{ "app":{ "name":"some value" }}' "http://localhost:8080/jenkins/generic-webhook-trigger/invoke?token=TOKEN_HERE"
```

## Screenshots
Expand Down Expand Up @@ -372,7 +378,7 @@ pipeline {
It can be triggered with something like:

```bash
curl -X POST -H "Content-Type: application/json" -H "headerWithNumber: nbr123" -H "headerWithString: a b c" -d '{ "before": "1848f12", "after": "5cab1", "ref": "refs/heads/develop" }' -vs http://admin:admin@localhost:8080/jenkins/generic-webhook-trigger/invoke?requestWithNumber=nbr%20123\&requestWithString=a%20string
curl -X POST -H "Content-Type: application/json" -H "headerWithNumber: nbr123" -H "headerWithString: a b c" -d '{ "before": "1848f12", "after": "5cab1", "ref": "refs/heads/develop" }' -vs "http://admin:admin@localhost:8080/jenkins/generic-webhook-trigger/invoke?requestWithNumber=nbr%20123&requestWithString=a%20string"
```

And the job will have this in the log:
Expand Down
10 changes: 7 additions & 3 deletions debug.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/sh
mvn versions:update-properties
mvnDebug -q hpi:run -Djava.util.logging.config.file=logging.properties -Djenkins.version=2.204.1 -Denforcer.skip=true

./mvnw versions:update-properties
MAVEN_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8000,suspend=n" \
./mvnw hpi:run \
-Djava.util.logging.config.file=logging.properties \
-Djenkins.version=2.361.4 \
-Denforcer.skip=true \
-Dhudson.model.ParametersAction.keepUndefinedParameters=true
8 changes: 6 additions & 2 deletions run.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#!/bin/sh
mvn versions:update-properties
mvn hpi:run -Djava.util.logging.config.file=logging.properties -Djenkins.version=2.346.3 -Denforcer.skip=true
./mvnw versions:update-properties
./mvnw hpi:run \
-Djava.util.logging.config.file=logging.properties \
-Djenkins.version=2.361.4 \
-Denforcer.skip=true \
-Dhudson.model.ParametersAction.keepUndefinedParameters=true
57 changes: 57 additions & 0 deletions src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.jenkinsci.plugins.gwt.global;

import hudson.Extension;
import java.io.Serializable;
import java.util.Optional;
import jenkins.model.GlobalConfiguration;
import net.sf.json.JSONObject;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.StaplerRequest;

@Extension
public class CacheConfig extends GlobalConfiguration implements Serializable {

private static final long serialVersionUID = -3077539230674127483L;
private static final Integer DEFAULT_GET_JOBS_CACHE_MINUTES = 15;

public static CacheConfig get() {
return GlobalConfiguration.all().get(CacheConfig.class);

Check warning on line 18 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 18 is not covered by tests
}

private boolean cacheGetJobs;
private Integer cacheGetJobsMinutes;

public CacheConfig(final boolean cacheGetJobs, final Integer cacheGetJobsMinutes) {

Check warning on line 24 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 24 is not covered by tests
this.cacheGetJobs = cacheGetJobs;

Check warning on line 25 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 25 is not covered by tests
this.cacheGetJobsMinutes = cacheGetJobsMinutes;

Check warning on line 26 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 26 is not covered by tests
}

Check warning on line 27 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 27 is not covered by tests

public CacheConfig() {
this.load();
}

@Override
public boolean configure(final StaplerRequest req, final JSONObject json) throws FormException {
req.bindJSON(this, json);

Check warning on line 35 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 35 is not covered by tests
this.save();

Check warning on line 36 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 36 is not covered by tests
return true;

Check warning on line 37 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 37 is not covered by tests
}

@DataBoundSetter
public void setCacheGetJobs(final boolean cacheGetJobs) {
this.cacheGetJobs = cacheGetJobs;

Check warning on line 42 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 42 is not covered by tests
}

Check warning on line 43 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 43 is not covered by tests

public boolean isCacheGetJobs() {
return this.cacheGetJobs;

Check warning on line 46 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 46 is not covered by tests
}

@DataBoundSetter
public void setCacheGetJobsMinutes(final Integer cacheGetJobsMinutes) {
this.cacheGetJobsMinutes = cacheGetJobsMinutes;

Check warning on line 51 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 51 is not covered by tests
}

Check warning on line 52 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 52 is not covered by tests

public Integer getCacheGetJobsMinutes() {
return Optional.ofNullable(this.cacheGetJobsMinutes).orElse(DEFAULT_GET_JOBS_CACHE_MINUTES);

Check warning on line 55 in src/main/java/org/jenkinsci/plugins/gwt/global/CacheConfig.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 55 is not covered by tests
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

public final class JobFinder {

private static Logger LOG = Logger.getLogger(JobFinder.class.getSimpleName());
private static Logger LOG = Logger.getLogger(JobFinder.class.getName());

Check warning on line 25 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinder.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 25 is not covered by tests

private JobFinder() {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,138 @@
package org.jenkinsci.plugins.gwt.jobfinder;

import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import hudson.security.ACL;
import java.time.Duration;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import jenkins.model.Jenkins;
import jenkins.model.ParameterizedJobMixIn.ParameterizedJob;
import org.acegisecurity.context.SecurityContext;
import org.acegisecurity.context.SecurityContextHolder;
import org.jenkinsci.plugins.gwt.global.CacheConfig;

public class JobFinderImpersonater {
public List<ParameterizedJob> getAllParameterizedJobs(boolean impersonate) {
private static final boolean DO_IMPERSONATE = true;
private static Logger LOGGER = Logger.getLogger(JobFinderImpersonater.class.getName());
private static final long CACHE_REFRESH_INITIAL_DELAY = 0;
private ScheduledExecutorService scheduledExecutorService = null;
private LoadingCache<Boolean, List<ParameterizedJob>> loadingCache = null;
private boolean cacheGetJobs = false;
private Integer cacheGetJobsMinutes = 0;

public JobFinderImpersonater() {
this.reconfigureCachingIfNecessary();

Check warning on line 31 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 31 is not covered by tests
}

Check warning on line 32 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 32 is not covered by tests

public List<ParameterizedJob> getAllParameterizedJobs(final boolean impersonate) {
this.reconfigureCachingIfNecessary();

Check warning on line 35 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 35 is not covered by tests
final boolean useCache = CacheConfig.get().isCacheGetJobs();

Check warning on line 36 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 36 is not covered by tests
if (useCache && impersonate) {

Check warning on line 37 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 37 is only partially covered, 4 branches are missing
try {
LOGGER.log(Level.FINE, "Using the cache");

Check warning on line 39 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 39 is not covered by tests
return this.getCachedJobs();

Check warning on line 40 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 40 is not covered by tests
} catch (final ExecutionException e) {

Check warning on line 41 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 41 is not covered by tests
LOGGER.log(Level.SEVERE, "Was unable to getAllParameterizedJobs from cache.", e);

Check warning on line 42 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 42 is not covered by tests
return doGetAllParameterizedJobs(impersonate);

Check warning on line 43 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 43 is not covered by tests
}
} else if (useCache && !impersonate) {

Check warning on line 45 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 45 is only partially covered, 4 branches are missing
LOGGER.log(

Check warning on line 46 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 46 is not covered by tests
Level.INFO,
"Not using the cache because jobs are not retreieved with impersonation SYSTEM. "
+ "SYSTEM is only impersonated when using a token."
+ " If SYSTEM is not impersonated, only jobs available for the currently authenticated user is found.");
}
LOGGER.log(Level.FINE, "Not using the cache");

Check warning on line 52 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 52 is not covered by tests
return doGetAllParameterizedJobs(impersonate);

Check warning on line 53 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 53 is not covered by tests
}

private List<ParameterizedJob> getCachedJobs() throws ExecutionException {
return this.loadingCache.get(DO_IMPERSONATE);

Check warning on line 57 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 57 is not covered by tests
}

private synchronized void reconfigureCachingIfNecessary() {
final boolean configCacheGetJobs = CacheConfig.get().isCacheGetJobs();

Check warning on line 61 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 61 is not covered by tests
final Integer configCacheGetJobsMinutes = CacheConfig.get().getCacheGetJobsMinutes();

Check warning on line 62 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 62 is not covered by tests
final boolean shouldReconfigure =

Check warning on line 63 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 63 is only partially covered, 8 branches are missing
this.scheduledExecutorService == null
|| this.loadingCache == null
|| this.cacheGetJobs != configCacheGetJobs
|| this.cacheGetJobsMinutes != configCacheGetJobsMinutes;
if (shouldReconfigure) {

Check warning on line 68 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 68 is only partially covered, 2 branches are missing
LOGGER.log(

Check warning on line 69 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 69 is not covered by tests
Level.INFO,
"Reconfiguring cache, was (enabled: "
+ this.cacheGetJobs
+ ", minutes: "
+ this.cacheGetJobsMinutes
+ ") changing to (enabled: "
+ configCacheGetJobs
+ ", minutes: "
+ configCacheGetJobsMinutes
+ ")");
} else {
return;

Check warning on line 81 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 81 is not covered by tests
}

if (configCacheGetJobs) {

Check warning on line 84 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 84 is only partially covered, 2 branches are missing
this.stopCaching();

Check warning on line 85 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 85 is not covered by tests
this.startCaching();

Check warning on line 86 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 86 is not covered by tests
try {
// Make a call to add the entry to cache
this.getCachedJobs();

Check warning on line 89 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 89 is not covered by tests
} catch (final ExecutionException e) {

Check warning on line 90 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 90 is not covered by tests
LOGGER.log(Level.SEVERE, "Was unable to trigger cache", e);

Check warning on line 91 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 91 is not covered by tests
}

Check warning on line 92 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 92 is not covered by tests
} else {
this.stopCaching();

Check warning on line 94 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 94 is not covered by tests
}
this.cacheGetJobs = configCacheGetJobs;

Check warning on line 96 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 96 is not covered by tests
this.cacheGetJobsMinutes = configCacheGetJobsMinutes;

Check warning on line 97 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 97 is not covered by tests
}

Check warning on line 98 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 98 is not covered by tests

private void startCaching() {
final int cacheMinutes = CacheConfig.get().getCacheGetJobsMinutes();

Check warning on line 101 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 101 is not covered by tests
final int cacheRefreshDuration = cacheMinutes > 1 ? cacheMinutes - 1 : cacheMinutes;

Check warning on line 102 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 102 is only partially covered, 2 branches are missing

this.loadingCache =

Check warning on line 104 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 104 is not covered by tests
CacheBuilder.newBuilder() //

Check warning on line 105 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 105 is not covered by tests
.refreshAfterWrite(Duration.ofMinutes(cacheMinutes)) //

Check warning on line 106 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 106 is not covered by tests
.build(

Check warning on line 107 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 107 is not covered by tests
new CacheLoader<Boolean, List<ParameterizedJob>>() {

Check warning on line 108 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 108 is not covered by tests
@Override
public List<ParameterizedJob> load(final Boolean impersonate) throws Exception {
LOGGER.log(Level.FINE, "Loading the cache with impersonate " + impersonate);

Check warning on line 111 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 111 is not covered by tests
return doGetAllParameterizedJobs(impersonate);

Check warning on line 112 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 112 is not covered by tests
}
});
this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();

Check warning on line 115 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 115 is not covered by tests
this.scheduledExecutorService.scheduleWithFixedDelay(

Check warning on line 116 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 116 is not covered by tests
() -> {
LOGGER.log(Level.FINE, "Triggering cache refresh");

Check warning on line 118 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 118 is not covered by tests
this.loadingCache.asMap().keySet().forEach((key) -> this.loadingCache.refresh(key));

Check warning on line 119 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 119 is not covered by tests
},

Check warning on line 120 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 120 is not covered by tests
CACHE_REFRESH_INITIAL_DELAY,
cacheRefreshDuration,
TimeUnit.MINUTES);
}

Check warning on line 124 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 124 is not covered by tests

private void stopCaching() {
if (this.scheduledExecutorService != null) {

Check warning on line 127 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 127 is only partially covered, 2 branches are missing
this.scheduledExecutorService.shutdown();

Check warning on line 128 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 128 is not covered by tests
}
if (this.loadingCache != null) {

Check warning on line 130 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 130 is only partially covered, 2 branches are missing
this.loadingCache.invalidateAll();

Check warning on line 131 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 131 is not covered by tests
}
}

Check warning on line 133 in src/main/java/org/jenkinsci/plugins/gwt/jobfinder/JobFinderImpersonater.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 133 is not covered by tests

private static List<ParameterizedJob> doGetAllParameterizedJobs(final boolean impersonate) {
SecurityContext orig = null;
try {
if (impersonate) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core"
xmlns:d="jelly:define"
xmlns:f="/lib/form"
xmlns:l="/lib/layout"
xmlns:st="jelly:stapler"
xmlns:t="/lib/hudson"
xmlns:c="/lib/credentials">

<f:section title="Generic Webhook Trigger Cache">
<f:entry title="Cache Get Jobs" field="cacheGetJobs">
<f:checkbox/>
<f:description>
If checked, the plugin will cache available configured jobs. So that the plugin does not need to retrieve that list when invoked. It will only cache when the <code>token</code>-parameter is supplied.
</f:description>
</f:entry>

<f:entry title="Cache Get Jobs Minutes">
<f:textbox field="cacheGetJobsMinutes"/>
<f:description>
Time, in minutes, to keep the jobs in cache before they are refreshed.
</f:description>
</f:entry>
</f:section>

</j:jelly>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<div>
<p>
This feature is also documented <a href="https://github.com/jenkinsci/generic-webhook-trigger-plugin">here</a>.
</p>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
xmlns:t="/lib/hudson"
xmlns:c="/lib/credentials">

<f:section title="Generic Webhook Trigger">
<f:section title="Generic Webhook Trigger Whitelist">

<f:optionalBlock field="enabled" title="Whitelist enabled" inline="true">
<f:entry title="Whitelisted servers">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<div>
<p>
See <a href="https://github.com/jenkinsci/generic-webhook-trigger-plugin">Generic Webhook Trigger Plugin</a> for details on how to configure and use this plugin.
This feature is also documented <a href="https://github.com/jenkinsci/generic-webhook-trigger-plugin">here</a>.
</p>
</div>

0 comments on commit fbad1b6

Please sign in to comment.