public synchronized Collection provision()

in src/main/java/com/amazon/jenkins/ec2fleet/EC2FleetCloud.java [339:383]


    public synchronized Collection<NodeProvisioner.PlannedNode> provision(final Label label, final int excessWorkload) {
        info("excessWorkload %s", excessWorkload);

        if (stats == null) {
            info("No first update, skip provision");
            return Collections.emptyList();
        }

        final int cap = stats.getNumDesired() + toAdd;

        if (cap >= getMaxSize()) {
            info("max %s reached, no more provision", getMaxSize());
            return Collections.emptyList();
        }

        if (!"active".equals(stats.getState())) {
            info("fleet in %s not active state", stats.getState());
            return Collections.emptyList();
        }

        // if the planned node has 0 executors configured force it to 1 so we end up doing an unweighted check
        final int numExecutors1 = this.numExecutors == 0 ? 1 : this.numExecutors;

        // Calculate the ceiling, without having to work with doubles from Math.ceil
        // https://stackoverflow.com/a/21830188/877024
        final int weightedExcessWorkload = (excessWorkload + numExecutors1 - 1) / numExecutors1;
        int targetCapacity = Math.min(cap + weightedExcessWorkload, getMaxSize());

        int toProvision = targetCapacity - cap;
        info("to provision = %s", toProvision);

        if (toProvision < 1) return Collections.emptyList();

        toAdd += toProvision;

        final List<NodeProvisioner.PlannedNode> resultList = new ArrayList<>();
        for (int f = 0; f < toProvision; ++f) {
            // todo make name unique per fleet
            final NodeProvisioner.PlannedNode plannedNode = new NodeProvisioner.PlannedNode(
                    "FleetNode-" + f, SettableFuture.<Node>create(), this.numExecutors);
            resultList.add(plannedNode);
            plannedNodesCache.add(plannedNode);
        }
        return resultList;
    }