All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.plugins.slave_squatter.NodePropertyImpl Maven / Gradle / Ivy

Go to download

This plugin enables administrators to reserve executors to be used outside Hudson

The newest version!
/*
 * The MIT License
 *
 * Copyright (c) 2010, InfraDNA, Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */
package hudson.plugins.slave_squatter;

import hudson.Extension;
import hudson.model.Computer;
import hudson.model.Node;
import hudson.model.Saveable;
import hudson.slaves.NodeProperty;
import hudson.slaves.NodePropertyDescriptor;
import hudson.util.DescribableList;
import org.kohsuke.stapler.DataBoundConstructor;

import java.io.IOException;
import java.util.List;

import static hudson.Util.*;

/**
 * Records {@link SlaveSquatter}s for the node.
 *
 * @author Kohsuke Kawaguchi
 */
public class NodePropertyImpl extends NodeProperty {
    private final DescribableList squatters =
            new DescribableList(Saveable.NOOP);

    @DataBoundConstructor
    public NodePropertyImpl(List squatters) throws IOException {
        this.squatters.replaceBy(fixNull(squatters));
    }

    public DescribableList getSquatters() {
        return squatters;
    }

    public int sizeOfReservation(Computer c, long timestamp) {
        int r=0;
        for (SlaveSquatter s : squatters)
            r += s.sizeOfReservation(c, timestamp);
        return r;
    }

    public long timeOfNextChange(Computer c, long timestamp) {
        long t = Long.MAX_VALUE;
        for (SlaveSquatter s : squatters)
            t = Math.min(t,s.timeOfNextChange(c, timestamp));
        return t;
    }

    @Extension
    public static class DescriptorImpl extends NodePropertyDescriptor {
        @Override
        public String getDisplayName() {
            return "External Slave Reservation";
        }

        public List getSquatterDescriptors() {
            return SlaveSquatterDescriptor.all();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy