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 a22625c
Show file tree
Hide file tree
Showing 11 changed files with 245 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 int 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 int 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 int 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 int 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());

private JobFinder() {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,136 @@
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 int cacheGetJobsMinutes = 0;

public JobFinderImpersonater() {}

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

Check warning on line 33 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 33 is not covered by tests
final boolean useCache = CacheConfig.get().isCacheGetJobs();

Check warning on line 34 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 34 is not covered by tests
if (useCache && impersonate) {

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

Partially covered line

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

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

Not covered line

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

Check warning on line 38 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 38 is not covered by tests
} catch (final ExecutionException e) {

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
LOGGER.log(Level.SEVERE, "Was unable to getAllParameterizedJobs from cache.", e);

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
return doGetAllParameterizedJobs(impersonate);

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
}
} else if (useCache && !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

Partially covered line

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

Check warning on line 44 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 44 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 50 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 50 is not covered by tests
return doGetAllParameterizedJobs(impersonate);

Check warning on line 51 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 51 is not covered by tests
}

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

Check warning on line 55 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 55 is not covered by tests
}

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

Check warning on line 59 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 59 is not covered by tests
final int configCacheGetJobsMinutes = CacheConfig.get().getCacheGetJobsMinutes();

Check warning on line 60 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 60 is not covered by tests
final boolean shouldReconfigure =

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

Partially covered line

Line 61 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 66 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 66 is only partially covered, 2 branches are missing
LOGGER.log(

Check warning on line 67 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 67 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 79 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 79 is not covered by tests
}

if (configCacheGetJobs) {

Check warning on line 82 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 82 is only partially covered, 2 branches are missing
this.stopCaching();

Check warning on line 83 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 83 is not covered by tests
this.startCaching();

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

Not covered line

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

Check warning on line 87 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 87 is not covered by tests
} catch (final ExecutionException e) {

Check warning on line 88 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 88 is not covered by tests
LOGGER.log(Level.SEVERE, "Was unable to trigger cache", e);

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
}

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
} else {
this.stopCaching();

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
}
this.cacheGetJobs = configCacheGetJobs;

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.cacheGetJobsMinutes = configCacheGetJobsMinutes;

Check warning on line 95 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 95 is not covered by tests
}

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

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

Check warning on line 99 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 99 is not covered by tests
final int cacheRefreshDuration = cacheMinutes > 1 ? cacheMinutes - 1 : cacheMinutes;

Check warning on line 100 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 100 is only partially covered, 2 branches are missing

this.loadingCache =

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

Not covered line

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

Check warning on line 103 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 103 is not covered by tests
.refreshAfterWrite(Duration.ofMinutes(cacheMinutes)) //

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
.build(

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
new CacheLoader<Boolean, List<ParameterizedJob>>() {

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
@Override
public List<ParameterizedJob> load(final Boolean impersonate) throws Exception {
LOGGER.log(Level.FINE, "Loading the cache with impersonate " + impersonate);

Check warning on line 109 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 109 is not covered by tests
return doGetAllParameterizedJobs(impersonate);

Check warning on line 110 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 110 is not covered by tests
}
});
this.scheduledExecutorService = Executors.newSingleThreadScheduledExecutor();

Check warning on line 113 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 113 is not covered by tests
this.scheduledExecutorService.scheduleWithFixedDelay(

Check warning on line 114 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 114 is not covered by tests
() -> {
LOGGER.log(Level.FINE, "Triggering cache refresh");

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
this.loadingCache.asMap().keySet().forEach((key) -> this.loadingCache.refresh(key));

Check warning on line 117 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 117 is not covered by tests
},

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
CACHE_REFRESH_INITIAL_DELAY,
cacheRefreshDuration,
TimeUnit.MINUTES);
}

Check warning on line 122 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 122 is not covered by tests

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

Check warning on line 125 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 125 is only partially covered, 2 branches are missing
this.scheduledExecutorService.shutdown();

Check warning on line 126 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 126 is not covered by tests
}
if (this.loadingCache != null) {

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

Partially covered line

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

Check warning on line 129 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 129 is not covered by tests
}
}

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

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>
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public void before() {
this.allParameterizedJobsByImpersonation = new ArrayList<>();
final JobFinderImpersonater jobFinderImpersonater =
new JobFinderImpersonater() {
@Override
synchronized void reconfigureCachingIfNecessary() {}

@Override
public List<ParameterizedJob> getAllParameterizedJobs(final boolean impersonate) {
JobFinderTest.this.didImpersonate = impersonate;
Expand Down

0 comments on commit a22625c

Please sign in to comment.