Skip to content

Commit 09ad63a

Browse files
cemersozDerekTBrown
authored andcommitted
meteo (#120)
* issue 32 fixed * removed swp * fixed nconf issues * issue 82, 84 fixes * fixed #82 * isse #77 * fixed tests * fixed files * fixed tests master * fixed comment * moved validator * removed duplicate file * fixed tests, removed duplicate underscore, publish * changes * fixed methods.ts import * fixed issues w methods * fixes * minor fixes * A Added Session Cache
1 parent 51dfe3a commit 09ad63a

File tree

16 files changed

+360
-174
lines changed

16 files changed

+360
-174
lines changed

client/imports/lab/methods.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Meteor.methods({
22
'prepareLab': function(courseId : String ,labId : Number){
33
return "here";
4-
}
4+
},
5+
'startLab': function(callback : any){},
6+
'nextTask': function(callback : any){},
7+
'endLab': function(callback : any){}
58
});
69

collections/labs.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@ import { Meteor } from 'meteor/meteor';
33

44
import { Roles } from './users.ts';
55

6+
declare var validateLab : any;
7+
declare var _ : any;
8+
9+
10+
var _ = require('underscore');
11+
612
export const labs : any = new Mongo.Collection('labs');
713

814
/**
@@ -95,7 +101,6 @@ labs.allow({
95101
/* LAB VALIDATOR */
96102
if(Meteor.isServer){
97103
var validateLab : any = require('../server/imports/lab/checkLab');
98-
99104
Meteor.startup(function(){
100105
var LabValidator = function(userid, doc, fieldNames?, modifier?, options?){
101106
if (typeof fieldNames === "undefined"){
@@ -138,6 +143,13 @@ labs.allow({
138143
}
139144
});
140145
});
146+
Meteor.publish('user-labs',function(){
147+
this.autorun(function(computation){
148+
let roles = (<any>(Meteor.users.findOne(this.userId))).roles;
149+
let courses = roles.student.map((a) =>{return a[0]});
150+
return (courses.map(function(courseId){return {course: courseId, labs: ((Collections.courses.findOne(courseId)).labs)}}));
151+
});
152+
});
141153
});
142154
}
143155

private/settings.env.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
{
22
"swarm_node_ip": "10.100.1.10",
33
"swarm_node_port": "4000",
4+
5+
"default_image": "alpine",
6+
7+
"mongo_log_collection": "logs",
8+
49
"etcd_node_ip": "192.168.56.102",
510
"etcd_node_port": "2379",
611
"etcd_user": "cem",
7-
"etcd_pass": "ersoz",
8-
"default_image": "alpine",
9-
"mongo_log_url" : "ds025792.mlab.com:25792/tuxlab",
10-
"mongo_log_collection" : "logs"
12+
"etcd_pass": "ersoz"
13+
1114
}

server/imports/api/lab.env.js

Lines changed: 47 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,21 @@
11
// Import Dockerode
22
var dockerode = require('dockerode');
3-
43
// Import other libraries
54
var async = require('async');
65
var underscore = require('underscore');
7-
var etcd = require('node-etcd');
86
var nconf = require('nconf');
97

108
/* constructor
119
* intializes docker, etcd connection
1210
*/
1311
var env = function(){
14-
var etcd_address = nconf.get('etcd_node_ip')+':'+nconf.get('etcd_node_port');
15-
16-
var etcd_auth = {
17-
user: nconf.get('etcd_user'),
18-
password: nconf.get('etcd_pass')
19-
}
2012

2113
var docker_settings = {
2214
host: nconf.get('swarm_node_ip'),
2315
password: nconf.get('swarm_node_port')
2416
}
2517

2618
this.docker = new dockerode(docker_settings);
27-
this.etcd = new etcd(etcd_address,etcd_auth);
2819
this.root_dom = nconf.get("root_domain");
2920

3021
}
@@ -114,7 +105,7 @@ env.prototype.init = function(opts){
114105
var crtOptsf = {Image: img,CMD: ['/bin/sh'], name: this.labVm}
115106

116107
//change final options according to opts input, if there is any
117-
underscore.extend(crtOptsf, crtOpts);
108+
_.extend(crtOptsf, crtOpts);
118109

119110
var slf = this;
120111
return new Promise(function(resolve,reject){
@@ -141,50 +132,51 @@ env.prototype.init = function(opts){
141132
else {
142133
var containerId = container.id.substring(0,7);
143134
container.start(strOpts,function(err,data){
144-
if(err) {
135+
136+
if(err) {
145137
TuxLog.log('debug','container start err: '+err);
146138
reject("Internal error");
147139
}
148140
else {
149-
var etcd_redrouter = {
150-
docker: containerId,
151-
port: 22,
152-
username: "root",
153-
allowed_auth: ["password"]
154-
}
155-
156-
//etcd directory for helix record
157-
var dir = slf.root_dom.split('.');
158-
dir.reverse().push(this.usr,'A');
159-
slf.helixKey = dir.join('/');
160-
161-
slf.redRouterKey = '/redrouter/ssh::'+slf.usr;
162-
163-
//set etcd record for redrouter
164-
etcd.set(slf.redRouterKey,etcd_redrouter,function(err,res){
165-
if(err){
166-
TuxLog.log('debug', 'error creating redrotuer etcd record: '+err);
167-
reject("Internal error");
168-
}
169-
170-
//set etcd record for helixdns
171-
docker.getContainer(containerId).inspect(function(err,container){
172-
if(err){
173-
TuxLog.log('debug', 'docker cannot find the container it just created: '+err);
174-
reject("Internal error");
175-
//TODO: get the actual information that we actually want. Perhaps change this entirely
176-
}
177-
else{
178-
179-
//set etcd record for helix
180-
etcd.set(slf.helixKey,container.NetworkSettings,function(err,res){
181-
if(err){
182-
TuxLog.log('debug','error creating helix etcd record: '+err);
183-
reject("Internal error");
184-
}
185-
else{
186-
slf.vmList.labVm = slf.labVm;
187-
resolve();
141+
var etcd_redrouter = {
142+
docker: containerId,
143+
port: 22,
144+
username: "root",
145+
allowed_auth: ["password"]
146+
}
147+
148+
//etcd directory for helix record
149+
var dir = slf.root_dom.split('.');
150+
dir.reverse().push(this.usr,'A');
151+
slf.helixKey = dir.join('/');
152+
153+
slf.redRouterKey = '/redrouter/ssh::'+slf.usr;
154+
155+
//set etcd record for redrouter
156+
etcd.set(slf.redRouterKey,etcd_redrouter,function(err,res){
157+
if(err){
158+
TuxLog.log('debug', 'error creating redrotuer etcd record: '+err);
159+
reject("Internal error");
160+
}
161+
162+
//set etcd record for helixdns
163+
docker.getContainer(containerId).inspect(function(err,container){
164+
if(err){
165+
TuxLog.log('debug', 'docker cannot find the container it just created: '+err);
166+
reject("Internal error");
167+
//TODO: get the actual information that we actually want. Perhaps change this entirely
168+
}
169+
else{
170+
171+
//set etcd record for helix
172+
etcd.set(slf.helixKey,container.NetworkSettings,function(err,res){
173+
if(err){
174+
TuxLog.log('debug','error creating helix etcd record: '+err);
175+
reject("Internal error");
176+
}
177+
else{
178+
slf.vmList.labVm = slf.labVm;
179+
resolve();
188180
}
189181
});
190182
}
@@ -199,7 +191,6 @@ env.prototype.init = function(opts){
199191
});
200192
}
201193

202-
203194
/* creates a new container with an image from the options provided,
204195
* downloads image if it does not yet exist.
205196
* @param {{},{}} : two options file, dockerodeCreateOptions,dockerodeStartOptions
@@ -228,7 +219,7 @@ env.prototype.createVm = function(opts) {
228219
var crtOptsf = {Image:img,CMD:['/bin/sh']}
229220

230221
//extend the final options with the supplied options
231-
underscore.extend(crtOptsf,crtOpt);
222+
_.extend(crtOptsf,crtOpt);
232223
crtOptsf.name = cName;
233224
//this.vmList.push({name: crtOpt.name,id:cName});
234225
//clone this into slf to use in the promise
@@ -285,8 +276,8 @@ env.prototype.removeVm = function (vmName,opts) {
285276
return function(){
286277
return new Promise(function(resolve,reject){
287278

288-
//check if container initialized
289-
if(!underscore.has(this.vmList,vmName)){
279+
//check if container initialized
280+
if(!_.has(this.vmList,vmName)){
290281
TuxLog.log('labfile_error',"trying to delete non-existing vm");
291282
reject("Internal error");
292283
}
@@ -307,7 +298,7 @@ env.prototype.updateVm = function(vmName, opts) {
307298
var slf = this;
308299
return function(){
309300
return new Promise(function(resolve,reject){
310-
if(!underscore.has(slf.vmList,vmName)){
301+
if(!_.has(slf.vmList,vmName)){
311302
TuxLog.log('labfile_error','trying to update non-existing vm');
312303
reject("Internal error");
313304
}
@@ -330,7 +321,7 @@ env.prototype.shell = function(vmName,command,opts) {
330321
var slf = this;
331322
return function(){
332323
return new Promise(function(resolve,reject){
333-
if(!underscore.has(slf.vmList,vmName)){
324+
if(!_.has(slf.vmList,vmName)){
334325
TuxLog.log('labfile_error','trying to run shell on non-existing vm');
335326
reject("Internal error");
336327
}

server/imports/api/tuxlab.js renamed to server/imports/api/lab.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var fs = require('fs');
2-
var tuxlab = function(){}
2+
var lab = function(){}
33

4-
tuxlab.prototype.init = function(){
4+
lab.prototype.init = function(){
55
var slf = this;
66
var ts = { prnt: slf,
77
next: null,
@@ -15,11 +15,11 @@ tuxlab.prototype.init = function(){
1515
return ts;
1616
}
1717

18-
tuxlab.prototype.currentTask = null;
19-
tuxlab.prototype.taskList = [];
20-
tuxlab.prototype.setup;
21-
tuxlab.prototype.tasks;
22-
tuxlab.prototype.newTask = function(ttl, mdown,sFn, vFn, opt){
18+
lab.prototype.currentTask = null;
19+
lab.prototype.taskList = [];
20+
lab.prototype.setup;
21+
lab.prototype.tasks;
22+
lab.prototype.newTask = function(ttl, mdown,sFn, vFn, opt){
2323
var slf = this;
2424
var ts = { prnt: slf,
2525
setupFn: sFn,
@@ -38,4 +38,4 @@ tuxlab.prototype.newTask = function(ttl, mdown,sFn, vFn, opt){
3838
}
3939
return ts;
4040
}
41-
module.exports = new tuxlab();
41+
module.exports = new lab();

server/imports/api/lab.session.d.t.s

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace lab_exec {
2+
interface labExec{
3+
var env : any;
4+
var tuxlab : any;
5+
function init(user : string, labId : number, callback : any)
6+
function parseTasks() : any
7+
function start(callback : any) : any
8+
function next(callback : any) : any
9+
function end(callback : any) : any
10+
11+
}
12+
function labExec() : any
13+
}

0 commit comments

Comments
 (0)