<commit_before>package org.csanchez.jenkins.plugins.kubernetes;

import hudson.Extension;
import hudson.model.TaskListener;
import hudson.model.Descriptor;
import hudson.model.Node;
import hudson.slaves.AbstractCloudSlave;
import hudson.slaves.NodeProperty;

import java.io.IOException;
import java.util.Collections;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.jenkinsci.plugins.durabletask.executors.OnceRetentionStrategy;
import org.kohsuke.stapler.DataBoundConstructor;

import com.github.kubernetes.java.client.model.Pod;
import com.google.common.base.MoreObjects;
import com.nirima.jenkins.plugins.docker.DockerTemplate;

/**
 * @author <NAME> <<EMAIL>>
 */
public class KubernetesSlave extends AbstractCloudSlave {

    private static final Logger LOGGER = Logger.getLogger(KubernetesSlave.class.getName());

    private static final long serialVersionUID = -8642936855413034232L;

    private final Pod pod;

    private final KubernetesCloud cloud;

    @DataBoundConstructor
    public KubernetesSlave(Pod pod, DockerTemplate template, String nodeDescription, KubernetesCloud cloud)
            throws Descriptor.FormException, IOException {
        super(pod.getId(), //
                nodeDescription, //
                "/", //
                template.getNumExecutors(), //
                Node.Mode.NORMAL, //
                pod.getLabels().getName(), //
                new KubernetesComputerLauncher(pod, template), //
                new OnceRetentionStrategy(0), //
                Collections.<NodeProperty<Node>> emptyList());

        this.pod = pod;
        this.cloud = cloud;
    }

    @Override
    public KubernetesComputer createComputer() {
        return new KubernetesComputer(this);
    }

    @Override
    protected void _terminate(TaskListener listener) throws IOException, InterruptedException {
        LOGGER.log(Level.INFO, "Terminating Kubernetes instance for slave {0}", name);

        try {
            cloud.connect().deletePod(this.pod.getId());
            LOGGER.log(Level.INFO, "Terminated Kubernetes instance for slave {0}", name);
            toComputer().disconnect(null);
        } catch (Exception e) {<commit_msg>Use the idleTerminationMinutes for the retention strategy<commit_after>package org.csanchez.jenkins.plugins.kubernetes;

import hudson.Extension;
import hudson.model.TaskListener;
import hudson.model.Descriptor;
import hudson.model.Node;
import hudson.slaves.AbstractCloudSlave;
import hudson.slaves.NodeProperty;
import hudson.slaves.RetentionStrategy;

import java.io.IOException;
import java.util.Collections;
import java.util.logging.Level;
import java.util.logging.Logger;

import org.jenkinsci.plugins.durabletask.executors.OnceRetentionStrategy;
import org.kohsuke.stapler.DataBoundConstructor;

import com.github.kubernetes.java.client.model.Pod;
import com.google.common.base.MoreObjects;
import com.google.common.base.Optional;
import com.google.common.primitives.Ints;
import com.nirima.jenkins.plugins.docker.DockerTemplate;

/**
 * @author <NAME> <<EMAIL>>
 */
public class KubernetesSlave extends AbstractCloudSlave {

    private static final Logger LOGGER = Logger.getLogger(KubernetesSlave.class.getName());

    private static final long serialVersionUID = -8642936855413034232L;

    private final Pod pod;

    private final KubernetesCloud cloud;

    @DataBoundConstructor
    public KubernetesSlave(Pod pod, DockerTemplate template, String nodeDescription, KubernetesCloud cloud)
            throws Descriptor.FormException, IOException {
        super(pod.getId(), //
                nodeDescription, //
                "/", //
                template.getNumExecutors(), //
                Node.Mode.NORMAL, //
                pod.getLabels().getName(), //
                new KubernetesComputerLauncher(pod, template), //
                getRetentionStrategy(template), //
                Collections.<NodeProperty<Node>> emptyList());

        this.pod = pod;
        this.cloud = cloud;
    }

    private static RetentionStrategy getRetentionStrategy(DockerTemplate template) {
        return new OnceRetentionStrategy(Optional.fromNullable(Ints.tryParse(template.idleTerminationMinutes)).or(0));
    }

    @Override
    public KubernetesComputer createComputer() {
        return new KubernetesComputer(this);
    }

    @Override
    protected void _terminate(TaskListener listener) throws IOException, InterruptedException {
        LOGGER.log(Level.INFO, "Terminating Kubernetes instance for slave {0}", name);

        try {
            cloud.connect().deletePod(this.pod.getId());
            LOGGER.log(Level.INFO, "Terminated Kubernetes instance for slave {0}", name);
            toComputer().disconnect(null);
        } catch (Exception e) {
{'fraction_non_alphanumeric': 0.09993727785908425, 'fraction_numerical': 0.009199247334309012, 'mean_word_length': 3.2524444444444445, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '19026', 'n_tokens_mistral': 1351, 'n_tokens_neox': 1249, 'n_words': 271}