Added some debug logging for downstream module build cancellations
package com.hubspot.blazar.listener;
+import java.util.Set;
+
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
import com.hubspot.blazar.base.DependencyGraph;
import com.hubspot.blazar.base.ModuleBuild;
import com.hubspot.blazar.base.RepositoryBuild;
@@ -7,12 +15,10 @@ import com.hubspot.blazar.base.visitor.AbstractModuleBuildVisitor;
import com.hubspot.blazar.data.service.ModuleBuildService;
import com.hubspot.blazar.data.service.RepositoryBuildService;
-import javax.inject.Inject;
-import javax.inject.Singleton;
-import java.util.Set;
-
@Singleton
public class DownstreamModuleBuildCanceller extends AbstractModuleBuildVisitor {
+ private static final Logger LOG = LoggerFactory.getLogger(DownstreamModuleBuildCanceller.class);
+
private final RepositoryBuildService repositoryBuildService;
private final ModuleBuildService moduleBuildService;
@@ -25,6 +31,8 @@ public class DownstreamModuleBuildCanceller extends AbstractModuleBuildVisitor {
@Override
protected void visitCancelled(ModuleBuild build) throws Exception {
+ LOG.debug("Module build {} has been cancelled looking for downstream module builds that need to be cancelled",
+ build.getId().get());
cancelDownstreamModuleBuilds(build);
}
@@ -33,14 +41,18 @@ public class DownstreamModuleBuildCanceller extends AbstractModuleBuildVisitor {
cancelDownstreamModuleBuilds(build);
}
- private void cancelDownstreamModuleBuilds(ModuleBuild build) {
- RepositoryBuild repositoryBuild = repositoryBuildService.get(build.getRepoBuildId()).get();
+ private void cancelDownstreamModuleBuilds(ModuleBuild cancelledModuleBuild) {
+ RepositoryBuild repositoryBuild = repositoryBuildService.get(cancelledModuleBuild.getRepoBuildId()).get();
DependencyGraph dependencyGraph = repositoryBuild.getDependencyGraph().get();
- Set<Integer> downstreamModules = dependencyGraph.outgoingVertices(build.getModuleId());
- for (ModuleBuild otherBuild : moduleBuildService.getByRepositoryBuild(build.getRepoBuildId())) {
- if (downstreamModules.contains(otherBuild.getModuleId()) && !otherBuild.getState().isComplete()) {
- moduleBuildService.cancel(otherBuild);
+ Set<Integer> downstreamModules = dependencyGraph.outgoingVertices(cancelledModuleBuild.getModuleId());
+ for (ModuleBuild moduleBuildInRepoBuild : moduleBuildService.getByRepositoryBuild(cancelledModuleBuild.getRepoBuildId())) {
+ LOG.debug("Checking if module build {} is downstream to cancelled module build {} (and has not completed) in order to cancel it.",
+ moduleBuildInRepoBuild, cancelledModuleBuild.getId().get());
+ if (downstreamModules.contains(moduleBuildInRepoBuild.getModuleId()) && !moduleBuildInRepoBuild.getState().isComplete()) {
+ moduleBuildService.cancel(moduleBuildInRepoBuild);
+ LOG.debug("Downstream module build {}->{} was cancelled.", cancelledModuleBuild.getId().get(),
+ moduleBuildInRepoBuild.getId().get());
}
}
}
