Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
possibly avoids duplicate build entries in the skip list by indexing off of build name vs. obj
synchronizes on the flush method since it possible can get called by multiple folks
  • Loading branch information
gabemontero committed Mar 12, 2019
1 parent 2ba43b4 commit 17433d4
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/main/java/io/fabric8/jenkins/openshiftsync/BuildWatcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import jenkins.security.NotReallyRoleSensitiveCallable;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jetty.util.ConcurrentHashSet;
import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.jenkinsci.plugins.workflow.job.WorkflowRun;

Expand All @@ -40,6 +39,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -66,17 +66,17 @@ public class BuildWatcher extends BaseWatcher {
private static final Logger logger = Logger.getLogger(BuildWatcher.class
.getName());

// the fabric8 classes like Build have equal/hashcode annotations that
// should allow
// us to index via the objects themselves;
// now that listing interval is 5 minutes (used to be 10 seconds), we have
// seen
// timing windows where if the build watch events come before build config
// watch events
// when both are created in a simultaneous fashion, there is an up to 5
// minute delay
// before the job run gets kicked off
private static final ConcurrentHashSet<Build> buildsWithNoBCList = new ConcurrentHashSet<>();
// started seeing duplicate builds getting kicked off so quit depending on
// so moved off of concurrent hash set to concurrent hash map using
// namepace/name key
private static final ConcurrentHashMap<String,Build> buildsWithNoBCList = new ConcurrentHashMap<String,Build>();

@SuppressFBWarnings("EI_EXPOSE_REP2")
public BuildWatcher(String[] namespaces) {
Expand Down Expand Up @@ -355,7 +355,7 @@ private static void addBuildToNoBCList(Build build) {
if (!OpenShiftUtils.isPipelineStrategyBuild(build))
return;
try {
buildsWithNoBCList.add(build);
buildsWithNoBCList.put(build.getMetadata().getNamespace()+build.getMetadata().getName(), build);
} catch (ConcurrentModificationException | IllegalArgumentException |
UnsupportedOperationException | NullPointerException e) {
logger.log(Level.WARNING,"Failed to add item " +
Expand All @@ -364,14 +364,14 @@ private static void addBuildToNoBCList(Build build) {
}

private static void removeBuildFromNoBCList(Build build) {
buildsWithNoBCList.remove(build);
buildsWithNoBCList.remove(build.getMetadata().getNamespace()+build.getMetadata().getName());
}

// trigger any builds whose watch events arrived before the
// corresponding build config watch events
public static void flushBuildsWithNoBCList() {
public synchronized static void flushBuildsWithNoBCList() {
boolean anyRemoveFailures = false;
for (Build build : buildsWithNoBCList) {
for (Build build : buildsWithNoBCList.values()) {
WorkflowJob job = getJobFromBuild(build);
if (job != null) {
try {
Expand Down

0 comments on commit 17433d4

Please sign in to comment.