<commit_before>import {Instance} from "./instance";
import {InstanceManager} from "./instanceManager";

import child_process = require("child_process");
const exec = child_process.exec;
let waitForSshd;

class SudoDockerContainersInstanceManager implements InstanceManager {
  getNewInstance(next){
    const newInstance = JSON.parse(JSON.stringify(this.currentInstance));
    this.currentInstance.port++;
    newInstance.containerName = "m2Port" + newInstance.port;
    exec(this.constructDockerRunCommand(this.resources, newInstance),
      (function(error) {
        if (error) {
          const containerAlreadyStarted =
                error.message.match(/Conflict. The name/) ||
                error.message.match(/Conflict. The container name/);
          if (containerAlreadyStarted) {
            this.getNewInstance(next);
          } else {
            console.error("Error starting the docker container: " +
                  error.message);
            throw error;
          }
        } else {
          this.waitForSshd(next, newInstance);
        }
      }).bind(this));
  }

removeInstance(instance: Instance) {
    console.log("Removing container: " + instance.containerName);
    const removeDockerContainer = "sudo docker rm -f " + instance.containerName;
    exec(removeDockerContainer, function(error) {
      if (error) {
        console.error("Error removing container " +
            instance.containerName + " with error:" + error);
      }
    });
  }
updateLastActiveTime(){}
resources: any;
options: any;
currentInstance: any;

constructor(resources: any, options: any, currentInstance: Instance) {
  this.resources = resources;
  this.options = options;
  this.currentInstance = currentInstance;
}
c;

constructDockerRunCommand(resources, newInstance: Instance) {
    let dockerRunCmd = "sudo docker run -d";
    dockerRunCmd += " -c " + resources.cpuShares;
    dockerRunCmd += " -m " + resources.memory + "m";
    dockerRunCmd += " --name " + newInstance.containerName;
    dockerRunCmd += " -p " + newInstance.port + ":22 ";
    dockerRunCmd += this.options.containerType + " " + this.options.sshdCmd;
    return dockerRunCmd;
  }
waitForSshd(next, instance: Instance) {
    const dockerRunningProcesses = "sudo docker exec " + instance.containerName +
        " ps aux";
    const filterForSshd = "grep \"" + this.options.sshdCmd + "\"";
    const excludeGrep = "grep -v grep";

    exec(dockerRunningProcesses + " | " + filterForSshd + " | " + excludeGrep,
      function(error, stdout, stderr) {<commit_msg>Remove weird c<commit_after>import {Instance} from "./instance";
import {InstanceManager} from "./instanceManager";

import child_process = require("child_process");
const exec = child_process.exec;
let waitForSshd;

class SudoDockerContainersInstanceManager implements InstanceManager {
  getNewInstance(next){
    const newInstance = JSON.parse(JSON.stringify(this.currentInstance));
    this.currentInstance.port++;
    newInstance.containerName = "m2Port" + newInstance.port;
    exec(this.constructDockerRunCommand(this.resources, newInstance),
      (function(error) {
        if (error) {
          const containerAlreadyStarted =
                error.message.match(/Conflict. The name/) ||
                error.message.match(/Conflict. The container name/);
          if (containerAlreadyStarted) {
            this.getNewInstance(next);
          } else {
            console.error("Error starting the docker container: " +
                  error.message);
            throw error;
          }
        } else {
          this.waitForSshd(next, newInstance);
        }
      }).bind(this));
  }

removeInstance(instance: Instance) {
    console.log("Removing container: " + instance.containerName);
    const removeDockerContainer = "sudo docker rm -f " + instance.containerName;
    exec(removeDockerContainer, function(error) {
      if (error) {
        console.error("Error removing container " +
            instance.containerName + " with error:" + error);
      }
    });
  }
updateLastActiveTime(){}
resources: any;
options: any;
currentInstance: any;

constructor(resources: any, options: any, currentInstance: Instance) {
  this.resources = resources;
  this.options = options;
  this.currentInstance = currentInstance;
}

constructDockerRunCommand(resources, newInstance: Instance) {
    let dockerRunCmd = "sudo docker run -d";
    dockerRunCmd += " -c " + resources.cpuShares;
    dockerRunCmd += " -m " + resources.memory + "m";
    dockerRunCmd += " --name " + newInstance.containerName;
    dockerRunCmd += " -p " + newInstance.port + ":22 ";
    dockerRunCmd += this.options.containerType + " " + this.options.sshdCmd;
    return dockerRunCmd;
  }
waitForSshd(next, instance: Instance) {
    const dockerRunningProcesses = "sudo docker exec " + instance.containerName +
        " ps aux";
    const filterForSshd = "grep \"" + this.options.sshdCmd + "\"";
    const excludeGrep = "grep -v grep";

    exec(dockerRunningProcesses + " | " + filterForSshd + " | " + excludeGrep,
      function(error, stdout, stderr) {
{'fraction_non_alphanumeric': 0.12087264150943396, 'fraction_numerical': 0.0011792452830188679, 'mean_word_length': 3.117313915857605, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '3722688', 'n_tokens_mistral': 1484, 'n_tokens_neox': 1437, 'n_words': 311}