hudson.model.queue.CauseOfBlockage Java Examples

The following examples show how to use hudson.model.queue.CauseOfBlockage. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PipelineNodeUtil.java    From blueocean-plugin with MIT License 6 votes vote down vote up
/**
 *  Gives cause of block for declarative style plugin where agent (node block) is declared inside a stage.
 *  <pre>
 *    pipeline {
 *      agent none
 *      stages {
 *          stage ('first') {
 *              agent {
 *                  label 'first'
 *              }
 *              steps{
 *                  sh 'echo "from first"'
 *              }
 *          }
 *      }
 *    }
 *  </pre>
 *
 * @param stage stage's {@link FlowNode}
 * @param nodeBlock agent or node block's {@link FlowNode}
 * @return cause of block if present, nul otherwise
 */
public static @CheckForNull String getCauseOfBlockage(@Nonnull FlowNode stage, @Nullable FlowNode nodeBlock) {
    if(nodeBlock != null){
        //Check and see if this node block is inside this stage
        for(FlowNode p:nodeBlock.getParents()){
            if(p.equals(stage)){
                Queue.Item item = QueueItemAction.getQueueItem(nodeBlock);
                if (item != null) {
                    CauseOfBlockage causeOfBlockage = item.getCauseOfBlockage();
                    String cause = null;
                    if (causeOfBlockage != null) {
                        cause = causeOfBlockage.getShortDescription();
                        if (cause == null) {
                            causeOfBlockage = item.task.getCauseOfBlockage();
                            if(causeOfBlockage != null) {
                                return causeOfBlockage.getShortDescription();
                            }
                        }
                    }
                    return cause;
                }
            }
        }
    }
    return null;
}
 
Example #2
Source File: DockerSwarmAgent.java    From docker-swarm-plugin with MIT License 5 votes vote down vote up
@Override
public CauseOfBlockage canTake(final Queue.BuildableItem item) {
    final Label l = item.getAssignedLabel();
    if (l != null && this.name.equals(l.getName())) {
        return null;
    }
    return super.canTake(item);
}
 
Example #3
Source File: DockerSlave.java    From yet-another-docker-plugin with MIT License 5 votes vote down vote up
@Override
public CauseOfBlockage canTake(Queue.BuildableItem item) {
    // hack for some core issue
    if (item.task instanceof Queue.FlyweightTask) {
        return new FlyweightCauseOfBlockage();
    }
    return super.canTake(item);
}
 
Example #4
Source File: PipelineNodeUtilTest.java    From blueocean-plugin with MIT License 4 votes vote down vote up
/**
 * This test tests all code paths of getCauseOfBlockage.
 * @throws Exception
 */
@Test
public void getCauseOfBlockage() throws Exception {
    CauseOfBlockage blockage = mock(CauseOfBlockage.class);
    CauseOfBlockage taskBlockage = mock(CauseOfBlockage.class);

    FlowNode stage = mock(FlowNode.class);
    FlowNode nodeBlock = mock(FlowNode.class);
    Queue.Item item = mock(Queue.Item.class);
    mockStatic(QueueItemAction.class);
    String cause = null;

    cause = PipelineNodeUtil.getCauseOfBlockage(stage, null);
    assertNull(cause);

    when(nodeBlock.getParents()).thenReturn(ImmutableList.of());
    cause = PipelineNodeUtil.getCauseOfBlockage(stage, null);
    assertNull(cause);

    when(nodeBlock.getParents()).thenReturn(ImmutableList.of(stage));
    when(QueueItemAction.getQueueItem(nodeBlock)).thenReturn(null);
    cause = PipelineNodeUtil.getCauseOfBlockage(stage, null);
    assertNull(cause);

    when(QueueItemAction.getQueueItem(nodeBlock)).thenReturn(item);
    when(item.getCauseOfBlockage()).thenReturn(null);
    cause = PipelineNodeUtil.getCauseOfBlockage(stage, null);
    assertNull(cause);

    when(blockage.getShortDescription()).thenReturn("test");
    when(item.getCauseOfBlockage()).thenReturn(blockage);
    cause = PipelineNodeUtil.getCauseOfBlockage(stage, nodeBlock);
    assertEquals("test", cause);

    when(blockage.getShortDescription()).thenReturn(null);
    cause = PipelineNodeUtil.getCauseOfBlockage(stage, null);
    assertNull(cause);

    when(taskBlockage.getShortDescription()).thenReturn("test1");
    Whitebox.setInternalState(item,"task", mock(Queue.Task.class));
    when(item.task.getCauseOfBlockage()).thenReturn(taskBlockage);
    cause = PipelineNodeUtil.getCauseOfBlockage(stage, nodeBlock);
    assertEquals("test1", cause);
}
 
Example #5
Source File: NoDelayProvisionerStrategyTest.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public CauseOfBlockage canProvision(Cloud cloud, Label label, int numExecutors) {
    return delegate.canProvision(cloud, label, numExecutors);
}
 
Example #6
Source File: ECSProvisioningStrategy.java    From amazon-ecs-plugin with MIT License 4 votes vote down vote up
/**
 * Takes a provisioning decision for a single label. Determines how many ECS tasks to start based solely on
 * queue length and how many agents are in the process of connecting.
 */
@Nonnull
@Override
public NodeProvisioner.StrategyDecision apply(@Nonnull NodeProvisioner.StrategyState state) {
    LOGGER.log(Level.FINE, "Received {0}", new Object[]{state});
    LoadStatistics.LoadStatisticsSnapshot snap = state.getSnapshot();
    Label label = state.getLabel();

    int excessWorkload = snap.getQueueLength() - snap.getAvailableExecutors() - snap.getConnectingExecutors();

    CLOUD:
    for (Cloud c : Jenkins.get().clouds) {
        if (excessWorkload <= 0) {
            break;  // enough agents allocated
        }

        // Make sure this cloud actually can provision for this label.
        if (!c.canProvision(label)) {
            continue;
        }

        for (CloudProvisioningListener cl : CloudProvisioningListener.all()) {
            CauseOfBlockage causeOfBlockage = cl.canProvision(c, label, excessWorkload);
            if (causeOfBlockage != null) {
                continue CLOUD;
            }
        }

        Collection<NodeProvisioner.PlannedNode> additionalCapacities = c.provision(label, excessWorkload);

        // compat with what the default NodeProvisioner.Strategy does
        fireOnStarted(c, label, additionalCapacities);

        for (NodeProvisioner.PlannedNode ac : additionalCapacities) {
            excessWorkload -= ac.numExecutors;
            LOGGER.log(Level.FINE, "Started provisioning {0} from {1} with {2,number,integer} "
                            + "executors. Remaining excess workload: {3,number,#.###}",
                    new Object[]{ac.displayName, c.name, ac.numExecutors, excessWorkload});
        }
        state.recordPendingLaunches(additionalCapacities);
    }
    // we took action, only pass on to other strategies if our action was insufficient
    return excessWorkload > 0 ? NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES : NodeProvisioner.StrategyDecision.PROVISIONING_COMPLETED;
}