<commit_before>//the client needs an agent to connect to so that it may access consul services
//supply a host IP address
var consuler = require('consul-helper')(process.env.HOST_IP); //start a consul client
var nomader = require('nomad-helper');
var fs = require('fs');

module.exports = function (app) {
	//start core and hmi
	app.post('/v1/cores', function (req, res) {
		startWatches();
		createCoreJob().submitJob(process.env.NOMAD_SERVER_IP + ":4646");
		res.sendStatus(200);
	});

	//get a list of HMIs and their branches
	app.get('/v1/hmis', function (req, res) {
		let hmis = {
			hmis: [
				{
					name: "ford",
					branches: ["master", "develop"]
				},
				{
					name: "generic",
					branches: ["master"]
				}
			]
		};
		res.json(hmis);
	});

	//given an HMI, get all valid core branches
	app.get('/v1/cores/:hmiName', function (req, res) {
		//do something with req.params.hmiName
		let branches = {
			branches: [
				"master",
				"develop"
			]
		}
		res.json(branches);
	});

	//given a core branch, get all valid build configurations
	app.get('/v1/builds/:coreBranchName', function (req, res) {
		//do something with req.params.coreBranchName
		let builds = {
			builds: [
				"TIME_TESTER",
				"BUILD_BT_SUPPORT"
			]
		}
		res.json(builds);
	});

	//delete a core passing in an id
	app.delete('/v1/cores/:id', function (req, res) {
		//do something with req.params.id
		res.sendStatus(200);
	});
}

function startWatches () {
	//set up a watch so we know when the core job is actually running
	consuler.watchService("core-master", function (services) {
		//services updated. get information about core and hmi if possible
		for (let i in services) {
			console.log("Core " + i + " TCP Address: " + services[i].Address + ":" + services[i].Tags[0]);
		}

		//submit a corresponding hmi job file that connects with the core service
		if (services.length > 0) {
			var jobService = services[0];
			//this creates an sdl hmi job file suitable for manticore
			createHmiJob(jobService.Address, jobService.Port).submitJob(process.env.NOMAD_SERVER_IP + ":4646");
		}
	});

	//set up a watch so we know when the hmi job is actually running
	consuler.watchService("hmi-master", function (services) {
		//services updated. get information about core and hmi if possible
		for (let i in services) {
			console.log("HMI " + i + " user Address: " + services[i].Address + ":" + services[i].Port);
		}
	});
}

function createHmiJob (address, port) {
	var job = nomader.createJob("hmi");
	job.addGroup("hmi");
	job.addTask("hmi", "hmi-master");
	job.setImage("hmi", "hmi-master", "crokita/discovery-sdl-hmi:master");
	job.addPort("hmi", "hmi-master", true, "user", 8080);
	job.addEnv("hmi", "hmi-master", "HMI_WEBSOCKET_ADDR", address + ":" + port);
	job.addService("hmi", "hmi-master", "${TASKGROUP}-hmi");
	job.setPortLabel("hmi", "hmi-master", "hmi-master", "user");
	return job;
}

function createCoreJob () {
	//this creates an sdl core job file suitable for manticore
	var job = nomader.createJob("core");
	job.addGroup("core");
	job.addTask("core", "core-master");<commit_msg>Fix IP address settings<commit_after>//the client needs an agent to connect to so that it may access consul services
//supply a host IP address
var consuler = require('consul-helper')(process.env.CONSUL_AGENT_IP); //start a consul client
var nomader = require('nomad-helper');
var fs = require('fs');

module.exports = function (app) {
	//start core and hmi
	app.post('/v1/cores', function (req, res) {
		startWatches();
		createCoreJob().submitJob(process.env.NOMAD_AGENT_IP + ":5656");
		res.sendStatus(200);
	});

	//get a list of HMIs and their branches
	app.get('/v1/hmis', function (req, res) {
		let hmis = {
			hmis: [
				{
					name: "ford",
					branches: ["master", "develop"]
				},
				{
					name: "generic",
					branches: ["master"]
				}
			]
		};
		res.json(hmis);
	});

	//given an HMI, get all valid core branches
	app.get('/v1/cores/:hmiName', function (req, res) {
		//do something with req.params.hmiName
		let branches = {
			branches: [
				"master",
				"develop"
			]
		}
		res.json(branches);
	});

	//given a core branch, get all valid build configurations
	app.get('/v1/builds/:coreBranchName', function (req, res) {
		//do something with req.params.coreBranchName
		let builds = {
			builds: [
				"TIME_TESTER",
				"BUILD_BT_SUPPORT"
			]
		}
		res.json(builds);
	});

	//delete a core passing in an id
	app.delete('/v1/cores/:id', function (req, res) {
		//do something with req.params.id
		res.sendStatus(200);
	});
}

function startWatches () {
	//set up a watch so we know when the core job is actually running
	consuler.watchService("core-master", function (services) {
		//services updated. get information about core and hmi if possible
		for (let i in services) {
			console.log("Core " + i + " TCP Address: " + services[i].Address + ":" + services[i].Tags[0]);
		}

		//submit a corresponding hmi job file that connects with the core service
		if (services.length > 0) {
			var jobService = services[0];
			//this creates an sdl hmi job file suitable for manticore
			createHmiJob(jobService.Address, jobService.Port).submitJob(process.env.NOMAD_AGENT_IP + ":5656");
		}
	});

	//set up a watch so we know when the hmi job is actually running
	consuler.watchService("hmi-master", function (services) {
		//services updated. get information about core and hmi if possible
		for (let i in services) {
			console.log("HMI " + i + " user Address: " + services[i].Address + ":" + services[i].Port);
		}
	});
}

function createHmiJob (address, port) {
	var job = nomader.createJob("hmi");
	job.addGroup("hmi");
	job.addTask("hmi", "hmi-master");
	job.setImage("hmi", "hmi-master", "crokita/discovery-sdl-hmi:master");
	job.addPort("hmi", "hmi-master", true, "user", 8080);
	job.addEnv("hmi", "hmi-master", "HMI_WEBSOCKET_ADDR", address + ":" + port);
	job.addService("hmi", "hmi-master", "${TASKGROUP}-hmi");
	job.setPortLabel("hmi", "hmi-master", "hmi-master", "user");
	return job;
}

function createCoreJob () {
	//this creates an sdl core job file suitable for manticore
	var job = nomader.createJob("core");
	job.addGroup("core");
	job.addTask("core", "core-master");
{'fraction_non_alphanumeric': 0.15930345049983877, 'fraction_numerical': 0.00838439213157046, 'mean_word_length': 3.656906906906907, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 5, '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': '4592312', 'n_tokens_mistral': 2377, 'n_tokens_neox': 2152, 'n_words': 588}