Java Code Examples for hudson.model.LoadStatistics#LoadStatisticsSnapshot

The following examples show how to use hudson.model.LoadStatistics#LoadStatisticsSnapshot . 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: NoDelayProvisionStrategy.java    From ec2-spot-jenkins-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public NodeProvisioner.StrategyDecision apply(final NodeProvisioner.StrategyState strategyState) {
    final Label label = strategyState.getLabel();

    final LoadStatistics.LoadStatisticsSnapshot snapshot = strategyState.getSnapshot();
    final int availableCapacity =
            snapshot.getAvailableExecutors()   // live executors
                    + snapshot.getConnectingExecutors()  // executors present but not yet connected
                    + strategyState.getPlannedCapacitySnapshot()     // capacity added by previous strategies from previous rounds
                    + strategyState.getAdditionalPlannedCapacity();  // capacity added by previous strategies _this round_

    int currentDemand = snapshot.getQueueLength() - availableCapacity;
    LOGGER.log(Level.INFO, "Available capacity={0}, currentDemand={1}",
            new Object[]{availableCapacity, currentDemand});

    for (final Cloud cloud : getClouds()) {
        if (currentDemand < 1) break;

        if (!(cloud instanceof EC2FleetCloud)) continue;
        if (!cloud.canProvision(label)) continue;

        final EC2FleetCloud ec2 = (EC2FleetCloud) cloud;
        if (!ec2.isNoDelayProvision()) continue;

        final Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(label, currentDemand);
        currentDemand -= plannedNodes.size();
        LOGGER.log(Level.FINE, "Planned {0} new nodes", plannedNodes.size());
        strategyState.recordPendingLaunches(plannedNodes);
        LOGGER.log(Level.FINE, "After provisioning, available capacity={0}, currentDemand={1}",
                new Object[]{availableCapacity, currentDemand});
    }

    if (currentDemand < 1) {
        LOGGER.log(Level.FINE, "Provisioning completed");
        return NodeProvisioner.StrategyDecision.PROVISIONING_COMPLETED;
    } else {
        LOGGER.log(Level.FINE, "Provisioning not complete, consulting remaining strategies");
        return NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES;
    }
}
 
Example 2
Source File: FastNodeProvisionerStrategy.java    From docker-plugin with MIT License 5 votes vote down vote up
private StrategyDecision applyFoCloud(@Nonnull NodeProvisioner.StrategyState state, DockerCloud cloud) {

        final Label label = state.getLabel();

        if (!cloud.canProvision(label)) {
            return CONSULT_REMAINING_STRATEGIES;
        }

        LoadStatistics.LoadStatisticsSnapshot snapshot = state.getSnapshot();
        LOGGER.log(FINEST, "Available executors={0}, connecting={1}, planned={2}",
                new Object[]{snapshot.getAvailableExecutors(), snapshot.getConnectingExecutors(), state.getPlannedCapacitySnapshot()});
        int availableCapacity =
              snapshot.getAvailableExecutors()
            + snapshot.getConnectingExecutors()
            + state.getPlannedCapacitySnapshot();

        int currentDemand = snapshot.getQueueLength();
        LOGGER.log(FINE, "Available capacity={0}, currentDemand={1}",
                new Object[]{availableCapacity, currentDemand});

        if (availableCapacity < currentDemand) {
            Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(label, currentDemand - availableCapacity);
            LOGGER.log(FINE, "Planned {0} new nodes", plannedNodes.size());
            state.recordPendingLaunches(plannedNodes);
            availableCapacity += plannedNodes.size();
            LOGGER.log(FINE, "After provisioning, available capacity={0}, currentDemand={1}",
                    new Object[]{availableCapacity, currentDemand});
        }

        if (availableCapacity >= currentDemand) {
            LOGGER.log(FINE, "Provisioning completed");
            return PROVISIONING_COMPLETED;
        }
        LOGGER.log(FINE, "Provisioning not complete, consulting remaining strategies");
        return CONSULT_REMAINING_STRATEGIES;
    }
 
Example 3
Source File: NoDelayProvisionerStrategy.java    From kubernetes-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public NodeProvisioner.StrategyDecision apply(NodeProvisioner.StrategyState strategyState) {
    if (DISABLE_NODELAY_PROVISING) {
        LOGGER.log(Level.FINE, "Provisioning not complete, NoDelayProvisionerStrategy is disabled");
        return NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES;
    }

    final Label label = strategyState.getLabel();

    LoadStatistics.LoadStatisticsSnapshot snapshot = strategyState.getSnapshot();
    int availableCapacity =
            snapshot.getAvailableExecutors()   // live executors
                    + snapshot.getConnectingExecutors()  // executors present but not yet connected
                    + strategyState.getPlannedCapacitySnapshot()     // capacity added by previous strategies from previous rounds
                    + strategyState.getAdditionalPlannedCapacity();  // capacity added by previous strategies _this round_
    int currentDemand = snapshot.getQueueLength();
    LOGGER.log(Level.FINE, "Available capacity={0}, currentDemand={1}",
            new Object[]{availableCapacity, currentDemand});
    if (availableCapacity < currentDemand) {
        List<Cloud> jenkinsClouds = new ArrayList<>(Jenkins.get().clouds);
        Collections.shuffle(jenkinsClouds);
        for (Cloud cloud : jenkinsClouds) {
            int workloadToProvision = currentDemand - availableCapacity;
            if (!(cloud instanceof KubernetesCloud)) continue;
            if (!cloud.canProvision(label)) continue;
            for (CloudProvisioningListener cl : CloudProvisioningListener.all()) {
                if (cl.canProvision(cloud, strategyState.getLabel(), workloadToProvision) != null) {
                    continue;
                }
            }
            Collection<NodeProvisioner.PlannedNode> plannedNodes = cloud.provision(label, workloadToProvision);
            LOGGER.log(Level.FINE, "Planned {0} new nodes", plannedNodes.size());
            fireOnStarted(cloud, strategyState.getLabel(), plannedNodes);
            strategyState.recordPendingLaunches(plannedNodes);
            availableCapacity += plannedNodes.size();
            LOGGER.log(Level.FINE, "After provisioning, available capacity={0}, currentDemand={1}", new Object[]{availableCapacity, currentDemand});
            break;
        }
    }
    if (availableCapacity >= currentDemand) {
        LOGGER.log(Level.FINE, "Provisioning completed");
        return NodeProvisioner.StrategyDecision.PROVISIONING_COMPLETED;
    } else {
        LOGGER.log(Level.FINE, "Provisioning not complete, consulting remaining strategies");
        return NodeProvisioner.StrategyDecision.CONSULT_REMAINING_STRATEGIES;
    }
}
 
Example 4
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;
}