Java 类hudson.model.Node 实例源码

项目:envinject-api-plugin    文件:EnvVarsResolver.java   
@Nonnull
public static Map<String, String> getPollingEnvVars(@Nonnull Job<?, ?> job, @CheckForNull Node node) throws EnvInjectException {

    final Run<?, ?> lastBuild = job.getLastBuild();
    if (lastBuild != null) {
        if (EnvInjectPluginHelper.isEnvInjectPluginInstalled()) {
            return getEnVars(lastBuild);
        }
    }

    if (node == null) {
        return getFallBackMasterNode(job);
    }
    if (node.getRootPath() == null) {
        return getFallBackMasterNode(job);
    }

    return getDefaultEnvVarsJob(job, node);
}
项目:envinject-api-plugin    文件:EnvVarsResolver.java   
@Nonnull
public static Map<String, String> getEnVars(@Nonnull Run<?, ?> run) throws EnvInjectException {
    Action envInjectAction = EnvInjectActionRetriever.getEnvInjectAction(run);
    if (envInjectAction != null) {
        try {
            Method method = envInjectAction.getClass().getMethod("getEnvMap");
            return (Map<String, String>) method.invoke(envInjectAction);
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | ClassCastException e) {
            throw new EnvInjectException(e);
        }
    }

    // Retrieve node used for this build
    Node builtOn = (run instanceof AbstractBuild) ? ((AbstractBuild)run).getBuiltOn() : null;

    // Check if node is always on. Otherwise, gather master env vars
    if (builtOn == null) {
        return getFallBackMasterNode(run.getParent());
    }
    if (builtOn.getRootPath() == null) {
        return getFallBackMasterNode(run.getParent());
    }

    // Get envVars from the node of the last build
    return getDefaultEnvVarsJob(run.getParent(), builtOn);
}
项目:external-workspace-manager-plugin    文件:ExwsExecution.java   
/**
 * Finds the {@link NodeProperty} for the external workspace definition.
 *
 * @param node the current node
 * @return the node property for the external workspace manager
 * @throws IOException if node property was not found
 */
@Nonnull
private static ExternalWorkspaceProperty findNodeProperty(Node node) throws IOException {
    DescribableList<NodeProperty<?>, NodePropertyDescriptor> nodeProperties = node.getNodeProperties();

    ExternalWorkspaceProperty exwsNodeProperty = null;
    for (NodeProperty<?> nodeProperty : nodeProperties) {
        if (nodeProperty instanceof ExternalWorkspaceProperty) {
            exwsNodeProperty = (ExternalWorkspaceProperty) nodeProperty;
            break;
        }
    }

    if (exwsNodeProperty == null) {
        String message = format("There is no External Workspace config defined in Node '%s' config", node.getDisplayName());
        throw new AbortException(message);
    }

    return exwsNodeProperty;
}
项目:external-workspace-manager-plugin    文件:ConfigMigrationTest.java   
@LocalData
@Test
public void localRootPathToNodeMountPoint() throws Exception {

    // The node configuration version 1.0.0 contains a localRootPath field.
    // This tests that future versions load this field as nodeMountPoint,
    // in other words it tests NodeDisk.readResolve()

    Computer computer = jr.getInstance().getComputer("node1");
    Node node = computer.getNode();
    DescribableList<NodeProperty<?>,NodePropertyDescriptor> props = node.getNodeProperties();
    ExternalWorkspaceProperty exwsProp = props.get(ExternalWorkspaceProperty.class);

    List<NodeDiskPool> diskPools = exwsProp.getNodeDiskPools();
    assertThat(diskPools.size(), is(1));

    NodeDiskPool diskPool = diskPools.get(0);
    assertThat(diskPool.getDiskPoolRefId(), is ("dp1"));

    List<NodeDisk> disks = diskPool.getNodeDisks();
    assertThat(disks.size(), is(1));

    NodeDisk disk = disks.get(0);
    assertThat(disk.getDiskRefId(), is("d1"));
    assertThat(disk.getNodeMountPoint(), is("/tmp/dp1/d1"));
}
项目:ec2-spot-jenkins-plugin    文件:EC2FleetCloud.java   
private synchronized void removeNode(String instanceId) {
    final Jenkins jenkins=Jenkins.getInstance();
    //noinspection SynchronizationOnLocalVariableOrMethodParameter
    synchronized (jenkins) {
        // If this node is dying, remove it from Jenkins
        final Node n = jenkins.getNode(instanceId);
        if (n != null) {
            try {
                jenkins.removeNode(n);
            } catch(final Exception ex) {
                LOGGER.log(Level.WARNING, "Error removing node " + instanceId);
                throw new IllegalStateException(ex);
            }
        }
    }
}
项目:appscansource-scanner    文件:AppScanSourceExecutor.java   
public static void execute(Run<?, ?> run, FilePath ws, Launcher launcher, String installation, Node node, TaskListener listener, EnvVars envVars, String cliScriptContent) throws IOException, InterruptedException{
    String exe = AppScanSourceInstallation.getExecutable(installation, AppScanSourceCommand.AppScanSourceCLI, node, listener, envVars);

    //Create a temp file with our script commands
    FilePath tempFile = ws.createTextTempFile("temp_cli_script_", ".txt", cliScriptContent);

    //Build the command line commands with necessary parameters
    JenkinsExecutor runner = new JenkinsExecutor(run, ws, launcher, listener);
    AppScanSourceInvocation invocation = new AppScanSourceInvocation(exe, run, ws, listener); 
    invocation.addScriptFile(tempFile);

    //Execute command line
    if (!invocation.execute(runner)) {
           throw new AbortException("AppScan Source execution failed");
       }            
    //Delete the temp file after we use it
    tempFile.delete();
}
项目:jenkins-parallels    文件:ParallelsDesktopConnectorSlaveComputer.java   
public Node createSlaveOnVM(ParallelsDesktopVM vm) throws Exception
{
    String vmId = vm.getVmid();
    String slaveName = vm.getSlaveName();
    LOGGER.log(Level.SEVERE, "Starting slave '" + slaveName+ "'");
    LOGGER.log(Level.SEVERE, "Starting virtual machine '" + vmId + "'");
    RunVmCallable command = new RunVmCallable("start", vmId);
    try
    {
        forceGetChannel().call(command);
        LOGGER.log(Level.SEVERE, "Waiting for IP...");
        String ip = getVmIPAddress(vmId);
        LOGGER.log(Level.SEVERE, "Got IP address for VM " + vmId + ": " + ip);
        vm.setLauncherIP(ip);
    }
    catch (Exception ex)
    {
        LOGGER.log(Level.SEVERE, ex.toString());
    }
    return new ParallelsDesktopVMSlave(vm, this);
}
项目:distributed-test-job    文件:NodeUtils.java   
/**
 * Used to get all available {@link Nodes}s in the {@link Label} that are
 * not the Master node.
 * 
 * @param build
 *            the current build
 * @param set
 *            the {@link Label} assigned to the {@link DTJob}.
 * @return a {@link Set} of all available nodes
 * @throws Exception
 * @since 1.0
 */
public static Set<Node> getAllAvailableNodes(AbstractBuild<?, ?> build)
        throws Exception {
    Set<Node> nodes = new HashSet<Node>();
    checkNodes(build);
    for (Node node : getAssignedNodes(build)) {
        if (node.toComputer().isOnline()) {
            if (node.equals(build.getBuiltOn())) {
                nodes.add(node);
            } else {
                if (node.toComputer().isIdle()) {
                    nodes.add(node);
                }
            }
        }
    }

    if (nodes.size() < 2) {
        throw PrintMessages.throwNotEnoughSlaves(nodes.size());
    }
    return nodes;
}
项目:distributed-test-job    文件:NodeUtils.java   
/**
 * Used define additional environment variable for a particular {@link Node}
 * .
 * 
 * @param node
 *            the {@link Node}
 * @param build
 *            the current build
 * @return a new Entry of a node and it's additional environment variables
 * @throws IOException
 * @throws Exception
 * @since 1.0
 */
public static GenericEntry<Node, EnvVars> createEnvVarsForNode(Node node,
        AbstractBuild<?, ?> build, String listFile) throws IOException,
        Exception {
    if (node != null) {
        String nodeTestEnv = ((DTBuild) build).getTestJob()
                .getSlaveTestEnv();
        String projectName = ((DTBuild) build).getTestJob()
                .getDisplayName();
        EnvVars additionalEnvironment = new EnvVars();
        additionalEnvironment.put("$TEST_ENV", nodeTestEnv + "/");
        additionalEnvironment.put("$TEST_LIST", projectName + "/"
                + listFile);
        additionalEnvironment.put("$TARGET_SCRIPT", projectName + "/"
                + FilePathUtils.getPathToTargetScript(build).getName());
        additionalEnvironment.put("$TEST_WS", FilePathUtils
                .getPathToRootProjectWorkspaceOnNode(node, build)
                .getRemote()
                + "/");
        return new GenericEntry<Node, EnvVars>(node, additionalEnvironment);
    } else {
        return null;
    }
}
项目:ec2-plugin    文件:SlaveTemplateTest.java   
public void testUnixConfigRoundTrip() throws Exception {
    String ami = "ami1";
    String description = "foo ami";

    EC2Tag tag1 = new EC2Tag( "name1", "value1" );
    EC2Tag tag2 = new EC2Tag( "name2", "value2" );
    List<EC2Tag> tags = new ArrayList<EC2Tag>();
    tags.add( tag1 );
    tags.add( tag2 );

    SlaveTemplate orig = new SlaveTemplate(ami, EC2AbstractSlave.TEST_ZONE, null, "default", "foo", InstanceType.M1Large, "ttt", Node.Mode.NORMAL, description, "bar", "bbb", "aaa", "10", "rrr", new UnixData("sudo", "22"), "-Xmx1g", false, "subnet 456", tags, null, false, null, "", true, false, "", false, "");

    List<SlaveTemplate> templates = new ArrayList<SlaveTemplate>();
    templates.add(orig);

    AmazonEC2Cloud ac = new AmazonEC2Cloud("us-east-1", false, "abc", "def", "us-east-1", "ghi", "3", templates);
    hudson.clouds.add(ac);

    submit(createWebClient().goTo("configure").getFormByName("config"));
    SlaveTemplate received = ((EC2Cloud)hudson.clouds.iterator().next()).getTemplate(description);
    assertEqualBeans(orig, received, "amiType");
}
项目:distributed-test-job    文件:PrintMessages.java   
/**
 * Used to print a success message indicating that the test case suite
 * generation and the copying of relevant files was successful.
 * 
 * @param printStream
 *            the print stream
 * @param pair
 *            containing the {@link Node} and it's assigned test cases
 * @param path
 *            the path to the remote location where files have been copied
 * @since 1.0
 */
public static void printPreBuildInfoSuccess(PrintStream printStream,
        Entry<Node, List<String>> pair, String path) {
    printStream
            .printf("[PREBUILD-INFO] The test case list for %s Slave Node was successfully generated!%n",
                    pair.getKey().getDisplayName());
    printStream.printf(
            "%-15s The %slist.lst contains %d test cases in total.%n", " ",
            pair.getKey().getDisplayName(), pair.getValue().size());
    printStream
            .printf("%-15s The test cases specified in %slist.lst were successfully copied.%n",
                    " ", pair.getKey().getDisplayName());
    printStream
            .printf("[PREBUILD-INFO]%n Copying list, target script and test cases files ->%n [TO] %s%n",
                    pair.getKey().getDisplayName() + " -> " + path);
}
项目:distributed-test-job    文件:DTBuilder.java   
/**
 * Used to execute/start a remote process that initializes the testing
 * process.
 * 
 * @param build
 *            the current build
 * @param listener
 *            the build's listener
 * @param entry
 *            containing the {@link Node} and its {@link EnvVars}
 * @return the started process
 * @throws InterruptedException
 * @throws IOException
 * @since 1.0
 */
private Proc executeTest(AbstractBuild<?, ?> build, BuildListener listener,
        Entry<Node, EnvVars> entry) throws InterruptedException,
        IOException {
    final EnvVars vars = NodeUtils.getEnvironment(entry.getKey(),
            entry.getValue());
    final Node node = entry.getKey();

    // Get testing environment on the specific node
    FilePath testEnv = FilePathUtils.getPathToTestEnvOnNode(node, build);

    // Create a remote launcher
    RemoteLauncher remoteLaucher = new RemoteLauncher(listener,
            node.getChannel(), true);

    // Create process starter
    ProcStarter starter = remoteLaucher.launch()
            .cmds(buildShellCmds(vars, node, build)).stdout(listener)
            .stderr(listener.getLogger()).pwd(testEnv.getParent());

    // Launch the process
    Proc proc = remoteLaucher.launch(starter);

    return proc;
}
项目:zaproxy-plugin    文件:ZAProxy.java   
/**
 * Return the ZAProxy program name with separator prefix (\zap.bat or /zap.sh) depending of the build node and the OS.
 * 
 * @param build
 * @return the ZAProxy program name with separator prefix (\zap.bat or /zap.sh)
 * @throws IOException
 * @throws InterruptedException
 */
private String getZAPProgramNameWithSeparator(AbstractBuild<?, ?> build) throws IOException, InterruptedException {
    Node node = build.getBuiltOn();
    String zapProgramName = "";

    // Append zap program following Master/Slave and Windows/Unix
    if( "".equals(node.getNodeName())) { // Master
        if( File.pathSeparatorChar == ':' ) { // UNIX
            zapProgramName = "/" + ZAP_PROG_NAME_SH;
        } else { // Windows (pathSeparatorChar == ';')
            zapProgramName = "\\" + ZAP_PROG_NAME_BAT;
        }
    } 
    else { // Slave
        if( "Unix".equals(((SlaveComputer)node.toComputer()).getOSDescription()) ) {
            zapProgramName = "/" + ZAP_PROG_NAME_SH;
        } else {
            zapProgramName = "\\" + ZAP_PROG_NAME_BAT;
        }
    }
    return zapProgramName;
}
项目:yet-another-docker-plugin    文件:AbstractCloud.java   
/**
 * Multiple templates may have the same label.
 *
 * @return Templates matched to requested label assuming slave Mode
 */
@Nonnull
public List<DockerSlaveTemplate> getTemplates(Label label) {
    List<DockerSlaveTemplate> dockerSlaveTemplates = new ArrayList<>();

    for (DockerSlaveTemplate t : templates) {
        if (isNull(label) && t.getMode() == Node.Mode.NORMAL) {
            dockerSlaveTemplates.add(t);
        }

        if (nonNull(label) && label.matches(t.getLabelSet())) {
            dockerSlaveTemplates.add(t);
        }
    }

    return dockerSlaveTemplates;
}
项目:yet-another-docker-plugin    文件:DockerSimpleBuildWrapper.java   
@Override
public void tearDown(Run<?, ?> run, FilePath workspace, Launcher launcher, TaskListener listener)
        throws IOException, InterruptedException {
    LOG.info("Shutting down slave");
    listener.getLogger().println("Shutting down slave '" + slaveName + "'.");
    final Node slaveNode = Jenkins.getInstance().getNode(slaveName);
    if (isNull(slaveNode)) {
        throw new IllegalStateException("Can't get node " + slaveName);
    }
    final DockerSlaveSingle node = (DockerSlaveSingle) slaveNode;
    try {
        node.terminate();
    } catch (Throwable e) {
        LOG.error("Can't terminate node", e);
        CloudStatistics.ProvisioningListener.get().onFailure(node.getId(), e);
    }

}
项目:yet-another-docker-plugin    文件:DockerSlaveTemplate.java   
/**
 * Initializes data structure that we don't persist.
 */
@SuppressWarnings("unused")
public Object readResolve() {
    if (configVersion < 1) {
        if (isNull(nodeProperties)) nodeProperties = new ArrayList<>();
        nodeProperties.add(new DockerNodeProperty("DOCKER_CONTAINER_ID", "JENKINS_CLOUD_ID", "DOCKER_HOST"));
        configVersion = 1;
    }

    // real @Nonnull
    if (mode == null) {
        mode = Node.Mode.NORMAL;
    }

    if (retentionStrategy == null) {
        retentionStrategy = new DockerOnceRetentionStrategy(10);
    }

    try {
        labelSet = Label.parse(getLabelString()); // fails sometimes under debugger
    } catch (Throwable t) {
        LOG.error("Can't parse labels: {}", t);
    }

    return this;
}
项目:ec2-plugin    文件:SlaveTemplateTest.java   
public void testWindowsConfigRoundTrip() throws Exception {
    String ami = "ami1";
    String description = "foo ami";

    EC2Tag tag1 = new EC2Tag( "name1", "value1" );
    EC2Tag tag2 = new EC2Tag( "name2", "value2" );
    List<EC2Tag> tags = new ArrayList<EC2Tag>();
    tags.add( tag1 );
    tags.add( tag2 );

    SlaveTemplate orig = new SlaveTemplate(ami, EC2AbstractSlave.TEST_ZONE, null, "default", "foo", InstanceType.M1Large, "ttt", Node.Mode.NORMAL, description, "bar", "bbb", "aaa", "10", "rrr", new WindowsData("password", false, ""), "-Xmx1g", false, "subnet 456", tags, null, false, null, "", true, false, "", false, "");

    List<SlaveTemplate> templates = new ArrayList<SlaveTemplate>();
    templates.add(orig);

    AmazonEC2Cloud ac = new AmazonEC2Cloud("us-east-1", false, "abc", "def", "us-east-1", "ghi", "3", templates);
    hudson.clouds.add(ac);

    submit(createWebClient().goTo("configure").getFormByName("config"));
    SlaveTemplate received = ((EC2Cloud)hudson.clouds.iterator().next()).getTemplate(description);
    assertEqualBeans(orig, received, "amiType");
}
项目:ec2-plugin    文件:EC2OndemandSlave.java   
@Override
public Node newInstance(StaplerRequest req, JSONObject formData) throws FormException {
    EC2OndemandSlave ec2AbstractSlave = (EC2OndemandSlave) super.newInstance(req, formData);

    if (!ec2AbstractSlave.isAlive(true)) {
        LOGGER.info("EC2 instance terminated externally: " + ec2AbstractSlave.getInstanceId());
        try {
            Hudson.getInstance().removeNode(ec2AbstractSlave);
        } catch (IOException ioe) {
            LOGGER.log(Level.WARNING, "Attempt to reconfigure EC2 instance which has been externally terminated: " + ec2AbstractSlave.getInstanceId(), ioe);
        }

        return null;
    }

    return ec2AbstractSlave;
}
项目:ec2-plugin    文件:EC2SlaveMonitor.java   
@Override
protected void execute(TaskListener listener) throws IOException, InterruptedException {
    for (Node node : Hudson.getInstance().getNodes()) {
        if (node instanceof EC2AbstractSlave) {
            final EC2AbstractSlave ec2Slave = (EC2AbstractSlave) node;
            try {
                if (!ec2Slave.isAlive(true)) {
                    LOGGER.info("EC2 instance is dead: " + ec2Slave.getInstanceId());
                    ec2Slave.terminate();
                }
            } catch (AmazonClientException e) {
                LOGGER.info("EC2 instance is dead and failed to terminate: " + ec2Slave.getInstanceId());
                removeNode(ec2Slave);
            }
        }
    }
}
项目:ec2-plugin    文件:SlaveTemplateTest.java   
public void testConfigRoundtrip() throws Exception {
       String ami = "ami1";
String description = "foo ami";

       EC2Tag tag1 = new EC2Tag( "name1", "value1" );
       EC2Tag tag2 = new EC2Tag( "name2", "value2" );
       List<EC2Tag> tags = new ArrayList<EC2Tag>();
       tags.add( tag1 );
       tags.add( tag2 );

    SlaveTemplate orig = new SlaveTemplate(ami, EC2AbstractSlave.TEST_ZONE, null, "default", "foo", InstanceType.M1Large, "ttt", Node.Mode.NORMAL, description, "bar", "bbb", "aaa", "10", "fff", null, "-Xmx1g", false, "subnet 456", tags, null, false, null, "", true, false, "", false, "");

       List<SlaveTemplate> templates = new ArrayList<SlaveTemplate>();
       templates.add(orig);

       AmazonEC2Cloud ac = new AmazonEC2Cloud("us-east-1", false, "abc", "def", "us-east-1", "ghi", "3", templates);
       hudson.clouds.add(ac);

       submit(createWebClient().goTo("configure").getFormByName("config"));
       SlaveTemplate received = ((EC2Cloud)hudson.clouds.iterator().next()).getTemplate(description);
       assertEqualBeans(orig, received, "ami,zone,description,remoteFS,type,jvmopts,stopOnTerminate,securityGroups,subnetId,usePrivateDnsName,useEphemeralDevices,useDedicatedTenancy");
   }
项目:ec2-plugin    文件:SlaveTemplateTest.java   
public void testConfigRoundtripWithPrivateDns() throws Exception {
       String ami = "ami1";
String description = "foo ami";

       EC2Tag tag1 = new EC2Tag( "name1", "value1" );
       EC2Tag tag2 = new EC2Tag( "name2", "value2" );
       List<EC2Tag> tags = new ArrayList<EC2Tag>();
       tags.add( tag1 );
       tags.add( tag2 );

       SlaveTemplate orig = new SlaveTemplate(ami, EC2AbstractSlave.TEST_ZONE, null, "default", "foo", InstanceType.M1Large, "ttt", Node.Mode.NORMAL, description, "bar", "bbb", "aaa", "10",  "fff", null, "-Xmx1g", false, "subnet 456", tags, null, true, null, "", false, false, "", false, "");

       List<SlaveTemplate> templates = new ArrayList<SlaveTemplate>();
       templates.add(orig);

       AmazonEC2Cloud ac = new AmazonEC2Cloud("us-east-1", false, "abc", "def", "us-east-1", "ghi", "3", templates);
       hudson.clouds.add(ac);

       submit(createWebClient().goTo("configure").getFormByName("config"));
       SlaveTemplate received = ((EC2Cloud)hudson.clouds.iterator().next()).getTemplate(description);
       assertEqualBeans(orig, received, "ami,zone,description,remoteFS,type,jvmopts,stopOnTerminate,securityGroups,subnetId,tags,usePrivateDnsName");
   }
项目:ec2-plugin    文件:SlaveTemplateTest.java   
/**
 * Tests to make sure the slave created has been configured properly.
 * Also tests to make sure the spot max bid price has been set properly.
 * @throws Exception - Exception that can be thrown by the Jenkins test harness
 */
public void testConfigWithSpotBidPrice() throws Exception {
    String ami = "ami1";
    String description = "foo ami";

    EC2Tag tag1 = new EC2Tag( "name1", "value1" );
    EC2Tag tag2 = new EC2Tag( "name2", "value2" );
    List<EC2Tag> tags = new ArrayList<EC2Tag>();
    tags.add( tag1 );
    tags.add( tag2 );

    SpotConfiguration spotConfig = new SpotConfiguration(".05", SpotInstanceType.OneTime.toString());

    SlaveTemplate orig = new SlaveTemplate(ami, EC2AbstractSlave.TEST_ZONE, spotConfig, "default", "foo", InstanceType.M1Large, "ttt", Node.Mode.NORMAL, "foo ami", "bar", "bbb", "aaa", "10", "fff", null, "-Xmx1g", false, "subnet 456", tags, null, true, null, "", false, false, "", false, "");
    List<SlaveTemplate> templates = new ArrayList<SlaveTemplate>();
    templates.add(orig);

    AmazonEC2Cloud ac = new AmazonEC2Cloud("us-east-1", false, "abc", "def", "us-east-1", "ghi", "3", templates);
    hudson.clouds.add(ac);

    submit(createWebClient().goTo("configure").getFormByName("config"));
    SlaveTemplate received = ((EC2Cloud)hudson.clouds.iterator().next()).getTemplate(description);
    assertEqualBeans(orig, received, "ami,zone,spotConfig,description,remoteFS,type,jvmopts,stopOnTerminate,securityGroups,subnetId,tags,usePrivateDnsName");
}
项目:ec2-plugin    文件:SlaveTemplateTest.java   
/**
 * Test to make sure the IAM Role is set properly.
 *
 * @throws Exception
 */
public void testConfigRoundtripIamRole() throws Exception {
    String ami = "ami1";
    String description = "foo ami";

    EC2Tag tag1 = new EC2Tag( "name1", "value1" );
    EC2Tag tag2 = new EC2Tag( "name2", "value2" );
    List<EC2Tag> tags = new ArrayList<EC2Tag>();
    tags.add( tag1 );
    tags.add( tag2 );

    SlaveTemplate orig = new SlaveTemplate(ami, EC2AbstractSlave.TEST_ZONE, null, "default", "foo", InstanceType.M1Large, "ttt", Node.Mode.NORMAL, description, "bar", "bbb", "aaa", "10", "fff", null, "-Xmx1g", false, "subnet 456", tags, null, false, null, "iamInstanceProfile", false, false, "", false, "");

    List<SlaveTemplate> templates = new ArrayList<SlaveTemplate>();
    templates.add(orig);

    AmazonEC2Cloud ac = new AmazonEC2Cloud("us-east-1", false, "abc", "def", "us-east-1", "ghi", "3", templates);
    hudson.clouds.add(ac);

    submit(createWebClient().goTo("configure").getFormByName("config"));
    SlaveTemplate received = ((EC2Cloud)hudson.clouds.iterator().next()).getTemplate(description);
    assertEqualBeans(orig, received, "ami,zone,description,remoteFS,type,jvmopts,stopOnTerminate,securityGroups,subnetId,usePrivateDnsName,iamInstanceProfile");
}
项目:envinject-api-plugin    文件:EnvVarsResolver.java   
@Nonnull
private static Map<String, String> getFallBackMasterNode(@Nonnull Job<?, ?> job) throws EnvInjectException {
    final Node masterNode = getMasterNode();
    if (masterNode == null) {
        return gatherEnvVarsMaster(job);
    }
    return getDefaultEnvVarsJob(job, masterNode);
}
项目:envinject-api-plugin    文件:EnvVarsResolver.java   
@CheckForNull
private static Node getMasterNode() {
    final Jenkins jenkins  = Jenkins.getInstance();
    if (jenkins == null) {
        return null;
    }
    Computer computer = jenkins.toComputer();
    if (computer == null) {
        return null; //Master can have no executors
    }
    return computer.getNode();
}
项目:envinject-api-plugin    文件:EnvVarsResolver.java   
@Nonnull
private static Map<String, String> getDefaultEnvVarsJob(@Nonnull Job<?, ?> job, @Nonnull Node node) throws EnvInjectException {
    // TODO: wat
    assert node.getRootPath() != null;
    //--- Same code for master or a slave node
    Map<String, String> result = gatherEnvVarsMaster(job);
    result.putAll(gatherEnvVarsNode(job, node));
    result.putAll(gatherEnvVarsNodeProperties(node));
    return result;
}
项目:envinject-api-plugin    文件:EnvVarsResolver.java   
@Nonnull
private static Map<String, String> gatherEnvVarsNode(@Nonnull Job<?, ?> job, @Nonnull Node node) throws EnvInjectException {

    final FilePath rootPath = node.getRootPath();
    if (rootPath == null) {
        //TODO: better than the original NPE. But maybe it's preferable to have more intelligent handling
        throw new EnvInjectException("Cannot retrieve Environment variables from the offline node");
    }

    try {
        Map<String, String> envVars = new EnvVars(rootPath.act(new MasterToSlaveCallable<Map<String, String>, EnvInjectException>() {
            private static final long serialVersionUID = 1L;

            @Override
            public Map<String, String> call() throws EnvInjectException {
                return EnvVars.masterEnvVars;
            }
        }));

        envVars.put("NODE_NAME", node.getNodeName());
        envVars.put("NODE_LABELS", Util.join(node.getAssignedLabels(), " "));

        if (job instanceof AbstractProject) {
            FilePath wFilePath = ((AbstractProject)job).getSomeWorkspace();
            if (wFilePath != null) {
                envVars.put("WORKSPACE", wFilePath.getRemote());
            }
        }

        return envVars;

    } catch (IOException | InterruptedException ioe) {
        throw new EnvInjectException(ioe);
    }
}
项目:ec2-spot-jenkins-plugin    文件:EC2FleetCloud.java   
@Override public synchronized Collection<NodeProvisioner.PlannedNode> provision(
        final Label label, final int excessWorkload) {


    final FleetStateStats stats=updateStatus();
    final int maxAllowed = this.getMaxSize();

    if (stats.getNumDesired() >= maxAllowed || !"active".equals(stats.getState()))
        return Collections.emptyList();

    int targetCapacity = stats.getNumDesired() + excessWorkload;

    if (targetCapacity > maxAllowed)
        targetCapacity = maxAllowed;

    int toProvision = targetCapacity - stats.getNumDesired();

    LOGGER.log(Level.INFO, "Provisioning nodes. Excess workload: " + Integer.toString(excessWorkload) + ", Provisioning: " + Integer.toString(toProvision));

    final ModifySpotFleetRequestRequest request=new ModifySpotFleetRequestRequest();
    request.setSpotFleetRequestId(fleet);
    request.setTargetCapacity(targetCapacity);

    final AmazonEC2 ec2=connect(credentialsId, region);
    ec2.modifySpotFleetRequest(request);

    final List<NodeProvisioner.PlannedNode> resultList =
            new ArrayList<NodeProvisioner.PlannedNode>();
    for(int f=0;f<toProvision; ++f)
    {
        final SettableFuture<Node> futureNode=SettableFuture.create();
        final NodeProvisioner.PlannedNode plannedNode=
                new NodeProvisioner.PlannedNode("FleetNode-"+f, futureNode, 1);
        resultList.add(plannedNode);
        this.plannedNodes.add(plannedNode);
    }
    return resultList;
}
项目:ec2-spot-jenkins-plugin    文件:IdleRetentionStrategy.java   
@Override public long check(final SlaveComputer c) {
    // Ensure that the EC2FleetCloud cannot be mutated from under us while
    // we're doing this check
    synchronized(parent) {
        // Ensure nobody provisions onto this node until we've done
        // checking
        boolean shouldAcceptTasks = c.isAcceptingTasks();
        c.setAcceptingTasks(false);
        try {
            if (isIdleForTooLong(c)) {
                // Find instance ID
                Node compNode = c.getNode();
                if (compNode == null) {
                    return 0;
                }

                final String nodeId = compNode.getNodeName();
                if (parent.terminateInstance(nodeId)) {
                    // Instance successfully terminated, so no longer accept tasks
                    shouldAcceptTasks = false;
                }
            } else {
                if (c.isOffline() && !c.isConnecting() && c.isLaunchSupported())
                    c.tryReconnect();
            }
        } finally {
            c.setAcceptingTasks(shouldAcceptTasks);
        }
    }

    return 1;
}
项目:cloud-stats-plugin    文件:CloudStatistics.java   
@Override @Restricted(DoNotUse.class)
public void onComplete(NodeProvisioner.PlannedNode plannedNode, Node node) {
    ProvisioningActivity.Id id = getIdFor(plannedNode);
    if (id != null) {
        onComplete(id, node);
    }
}
项目:cloud-stats-plugin    文件:CloudStatistics.java   
/**
 * Inform plugin provisioning has completed. This is only needed when provisioned outside {@link NodeProvisioner}.
 *
 * The method should be called before the node is added to Jenkins.
 */
public @CheckForNull ProvisioningActivity onComplete(@Nonnull ProvisioningActivity.Id id, @Nonnull Node node) {
    ProvisioningActivity activity = stats.getActivityFor(id);
    if (activity != null) {
        activity.rename(node.getDisplayName());
        stats.persist();
    }
    return activity;
}
项目:cloud-stats-plugin    文件:CloudStatisticsTest.java   
@Before
public void before() throws Exception {
    // Pretend we are out of slaves
    j.jenkins.setNumExecutors(0);
    j.jenkins.setNodes(Collections.<Node>emptyList());

    // Do not provision when not expected
    ExtensionList<NodeProvisioner.NodeProvisionerInvoker> extensionList = j.jenkins.getExtensionList(NodeProvisioner.NodeProvisionerInvoker.class);
    provisionerInvoker = extensionList.get(0);
}
项目:hyper-slaves-plugin    文件:ProvisionQueueListener.java   
private Node prepareExecutorFor(final AbstractProject job) throws Descriptor.FormException, IOException, InterruptedException {
    LOGGER.info("Creating a Container slave to host " + job.toString() + "#" + job.getNextBuildNumber());

    // Immediately create a slave for this item
    // Real provisioning will happen later
    String slaveName = "Container for " + job.getName() + "#" + job.getNextBuildNumber();
    String description = "Container slave for building " + job.getFullName();
    HyperSlaves plugin = HyperSlaves.get();
    return new HyperSlave(slaveName, description, null, plugin.createStandardJobProvisionerFactory(job));
}
项目:hyper-slaves-plugin    文件:ProvisionQueueListener.java   
/**
 * If item is canceled, remove the executor we created for it.
 */
@Override
public void onLeft(Queue.LeftItem item) {
    if (item.isCancelled()) {
        HyperSlaveAssignmentAction action = item.getAction(HyperSlaveAssignmentAction.class);
        if (action == null) return;
        Node slave = action.getAssignedNodeName();
        if (slave == null) return;
        try {
            Jenkins.getActiveInstance().removeNode(slave);
        } catch (Exception e) {
            LOGGER.log(Level.SEVERE, "Failure to remove One-Shot Slave", e);
        }
    }
}
项目:appscansource-scanner    文件:AppScanSourceInstallation.java   
public static String getExecutable(String name, AppScanSourceCommand command, Node node, TaskListener listener, EnvVars env) throws IOException, InterruptedException {
    if (name != null) {
        Jenkins j = Jenkins.getInstance();
        if (j != null) {
            for (AppScanSourceInstallation tool : j.getDescriptorByType(DescriptorImpl.class).getInstallations()) {
                if (tool.getName().equals(name)) {
                    if (node != null) {
                        tool = tool.forNode(node, listener);
                    }
                    if (env != null) {
                        tool = tool.forEnvironment(env);
                    }
                    String home = Util.fixEmpty(tool.getHome());
                    if (home != null) {
                        if (node != null) {
                            FilePath homePath = node.createPath(home);
                            if (homePath != null) {
                                return homePath.child(command.getName()).getRemote();
                            }
                        }
                        return home + "/" + command.getName();
                    }
                }
            }
        }
    }
    return command.getName();
}
项目:pipeline-maven-plugin    文件:WithMavenStepExecution.java   
/**
 * Setup the selected JDK. If none is provided nothing is done.
 */
private void setupJDK() throws AbortException, IOException, InterruptedException {
    String jdkInstallationName = step.getJdk();
    if (StringUtils.isEmpty(jdkInstallationName)) {
        console.println("[withMaven] use JDK installation provided by the build agent");
        return;
    }

    if (withContainer) {
        // see #detectWithContainer()
        LOGGER.log(Level.FINE, "Ignoring JDK installation parameter: {0}", jdkInstallationName);
        console.println("WARNING: \"withMaven(){...}\" step running within \"docker.image().inside{...}\"," +
                " tool installations are not available see https://issues.jenkins-ci.org/browse/JENKINS-36159. " +
                "You have specified a JDK installation \"" + jdkInstallationName + "\", which will be ignored.");
        return;
    }

    console.println("[withMaven] use JDK installation " + jdkInstallationName);

    JDK jdk = Jenkins.getActiveInstance().getJDK(jdkInstallationName);
    if (jdk == null) {
        throw new AbortException("Could not find the JDK installation: " + jdkInstallationName + ". Make sure it is configured on the Global Tool Configuration page");
    }
    Node node = getComputer().getNode();
    if (node == null) {
        throw new AbortException("Could not obtain the Node for the computer: " + getComputer().getName());
    }
    jdk = jdk.forNode(node, listener).forEnvironment(env);
    jdk.buildEnvVars(envOverride);

}
项目:pipeline-maven-plugin    文件:WithMavenStepTest.java   
@Before
public void setup() throws Exception {
    super.setup();

    JavaGitContainer slaveContainer = slaveRule.get();

    DumbSlave agent = new DumbSlave("remote", "", "/home/test/slave", "1", Node.Mode.NORMAL, "",
            new SSHLauncher(slaveContainer.ipBound(22), slaveContainer.port(22), "test", "test", "", ""),
            RetentionStrategy.INSTANCE, Collections.<NodeProperty<?>>emptyList());
    jenkinsRule.jenkins.addNode(agent);
}
项目:jenkins-parallels    文件:ParallelsDesktopCloud.java   
@Override
public Collection<NodeProvisioner.PlannedNode> provision(Label label, int excessWorkload)
{
    LOGGER.log(Level.SEVERE, "Going to provision " + excessWorkload + " executors");
    Collection<NodeProvisioner.PlannedNode> result = new ArrayList<NodeProvisioner.PlannedNode>();
    final ParallelsDesktopConnectorSlaveComputer connector = getConnector();
    for (int i = 0; (i < vms.size()) && (excessWorkload > 0); i++)
    {
        final ParallelsDesktopVM vm = vms.get(i);
        if (vm.isProvisioned())
            continue;
        if (!label.matches(Label.parse(vm.getLabels())))
            continue;
        final String vmId = vm.getVmid();
        final String slaveName = name + " " + vmId;
        vm.setSlaveName(slaveName);
        vm.setProvisioned(true);
        --excessWorkload;
        result.add(new NodeProvisioner.PlannedNode(slaveName,
            Computer.threadPoolForRemoting.submit(new Callable<Node>()
            {
                @Override
                public Node call() throws Exception
                {
                    connector.checkVmExists(vmId);
                    return connector.createSlaveOnVM(vm);
                }
            }), 1));
    }
    return result;
}
项目:ansible-plugin    文件:AnsibleInstallation.java   
public static String getExecutable(String name, AnsibleCommand command, Node node, TaskListener listener, EnvVars env) throws IOException, InterruptedException {
    if (name != null) {
        Jenkins j = Jenkins.getInstance();
        if (j != null) {
            for (AnsibleInstallation tool : j.getDescriptorByType(DescriptorImpl.class).getInstallations()) {
                if (tool.getName().equals(name)) {
                    if (node != null) {
                        tool = tool.forNode(node, listener);
                    }
                    if (env != null) {
                        tool = tool.forEnvironment(env);
                    }
                    String home = Util.fixEmpty(tool.getHome());
                    if (home != null) {
                        if (node != null) {
                            FilePath homePath = node.createPath(home);
                            if (homePath != null) {
                                return homePath.child(command.getName()).getRemote();
                            }
                        }
                        return home + "/" + command.getName();
                    }
                }
            }
        }
    }
    return command.getName();
}
项目:ansible-plugin    文件:AnsiblePlaybookBuilder.java   
public void perform(@Nonnull Run<?, ?> run, @Nonnull Node node, @Nonnull FilePath ws, @Nonnull Launcher launcher, @Nonnull TaskListener listener, EnvVars envVars)
        throws InterruptedException, IOException
{
    try {
        CLIRunner runner = new CLIRunner(run, ws, launcher, listener);
        String exe = AnsibleInstallation.getExecutable(ansibleName, AnsibleCommand.ANSIBLE_PLAYBOOK, node, listener, envVars);
        AnsiblePlaybookInvocation invocation = new AnsiblePlaybookInvocation(exe, run, ws, listener);
        invocation.setPlaybook(playbook);
        invocation.setInventory(inventory);
        invocation.setLimit(limit);
        invocation.setTags(tags);
        invocation.setSkippedTags(skippedTags);
        invocation.setStartTask(startAtTask);
        invocation.setSudo(sudo, sudoUser);
        invocation.setForks(forks);
        invocation.setCredentials(StringUtils.isNotBlank(credentialsId) ?
            CredentialsProvider.findCredentialById(credentialsId, StandardUsernameCredentials.class, run) : null,
            copyCredentialsInWorkspace);
        invocation.setAdditionalParameters(additionalParameters);
        invocation.setHostKeyCheck(hostKeyChecking);
        invocation.setUnbufferedOutput(unbufferedOutput);
        invocation.setColorizedOutput(colorizedOutput);
        if (!invocation.execute(runner)) {
            throw new AbortException("Ansible playbook execution failed");
        }
    } catch (IOException ioe) {
        Util.displayIOException(ioe, listener);
        ioe.printStackTrace(listener.fatalError(hudson.tasks.Messages.CommandInterpreter_CommandFailed()));
        throw ioe;
    } catch (AnsibleInvocationException aie) {
        listener.fatalError(aie.getMessage());
        throw new AbortException(aie.getMessage());
    }
}