Skip to content

Commit d6d37e9

Browse files
cemersozDerekTBrown
authored andcommitted
TERMINAL WERCKS (#145)
* 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 * api changes * fixed api * comments * minor changes * minor fixes * api changes (#126) * 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 * api changes * fixed api * comments * minor changes * minor fixes * method implementations * before merge * removed testing change * fixed typo * fixed prepareLab * removed test methods * fix prepareLab * methods changes * removed swap file * fixed merge * fixes * prepareLab WORKS * further fixes * merge * all works * deleted debug line * fixed minor excess code * minor indentation fix
1 parent 44b9f13 commit d6d37e9

File tree

10 files changed

+275
-123
lines changed

10 files changed

+275
-123
lines changed

client/imports/ui/pages/lab/taskview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@
1818

1919
<!--Terminal View-->
2020
<div class="tuxlab-taskview-terminal">
21-
<terminal [username]='username' [password]='password' [host]='host' domain='domain' ></terminal>
21+
<terminal ></terminal>
2222
</div>
2323
</div>
Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
// Meteor Imports
2-
import { Meteor } from 'meteor/meteor';
3-
import { Mongo } from 'meteor/mongo';
4-
import 'reflect-metadata';
5-
import 'zone.js/dist/zone';
2+
import { Meteor } from 'meteor/meteor';
3+
import { Mongo } from 'meteor/mongo';
4+
import 'reflect-metadata';
5+
import 'zone.js/dist/zone';
66

77
// Angular Imports
8-
import { Component, ViewEncapsulation, provide } from '@angular/core';
9-
import { bootstrap } from 'angular2-meteor-auto-bootstrap';
8+
import { ViewChild, Component, ViewEncapsulation, provide } from '@angular/core';
9+
import { bootstrap } from 'angular2-meteor-auto-bootstrap';
1010

1111
// Angular Material Imports
12-
import { MeteorComponent } from 'angular2-meteor';
12+
import { MeteorComponent } from 'angular2-meteor';
1313
import { OVERLAY_PROVIDERS } from '@angular2-material/core/overlay/overlay';
1414
import { MATERIAL_PROVIDERS, MATERIAL_DIRECTIVES } from 'ng2-material';
1515

16+
import { InjectUser } from 'angular2-meteor-accounts-ui';
17+
1618
// Terminal and Markdown Imports
1719
import { Terminal } from "../../components/wetty/terminal.ts";
1820
import { MarkdownView } from "../../components/markdown/markdown.ts";
@@ -22,8 +24,8 @@
2224

2325
// Meteor method imports
2426
import "../../../lab/methods.ts"
25-
2627
// Define TaskView Component
28+
2729
@Component({
2830
selector: 'tuxlab-taskview',
2931
templateUrl: '/client/imports/ui/pages/lab/taskview.html',
@@ -38,15 +40,31 @@
3840
encapsulation: ViewEncapsulation.None
3941
})
4042

43+
@InjectUser('user')
4144
export default class TaskView extends MeteorComponent {
45+
user: Meteor.User;
46+
public auth : any;
47+
48+
@ViewChild(Terminal) term : Terminal;
49+
4250
labMarkdown = "# Lab 1 Tasks \n ### Task 1 \n Implement **bash** *on your own* ***without*** any help. \n ### Task 2 \n Install *Arch Linux*. \n ### Task 3 \n Type ```sudo rm -rf /*``` into your terminal";
51+
4352
constructor() {
4453
super();
45-
// Create Icon Font
54+
}
4655

56+
ngAfterViewInit(){
57+
var slf = this;
4758
Meteor.call('prepareLab',"1","1", function(err,res){
59+
slf.labMarkdown = "#Sander \n ##are you sure this will work?";
60+
console.log(slf.labMarkdown);
61+
slf.auth = {
62+
username: Meteor.user().profile.nickname,
63+
password: res.sshInfo.pass,
64+
domain: "10.100.1.11"
65+
};
66+
slf.term.openTerminal(slf.auth);
4867
console.log("fired",err,res);
49-
//TODO: @Cem res: {host,pass} initialize terminal
5068
});
5169
}
5270
}

private/settings.env.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1-
{
1+
{
2+
"key_private" : "/etc/ssl/local/host.key",
3+
"key_public" : "/etc/ssl/local/host.key.pub",
4+
"key_ca" : "",
25
"swarm_node_ip" : "10.100.1.10",
36
"swarm_node_port" : "4000",
47
"etcd_node_ip" : "10.100.1.10",
58
"etcd_node_port" : "2379",
69
"etcd_user" : "meteor",
7-
"etcd_pass" : "e6da3f8b45546a76fb6e3e30e3542c65",
10+
"etcd_pass" : "fff86d549374f03f4ba82bfe170b5018",
811
"default_image" : "alpine",
912
"mongo_log_url" : "ds025792.mlab.com:25792/tuxlab",
1013
"mongo_log_collection" : "logs"

server/imports/api/lab.env.js

Lines changed: 45 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ env.prototype.init = function(opts){
111111
//declare final options
112112
var crtOptsf = {
113113
'Image': img,
114-
'Cmd': ['/bin/sh'],
114+
'Cmd': ['./entry.sh'],
115115
'name': this.labVm,
116116
'Hostname': '',
117117
'User': '',
@@ -134,11 +134,11 @@ env.prototype.init = function(opts){
134134

135135
//Check whether environment has been initialized correctly
136136
if(!slf.usr){
137-
TuxLog.log('debug','no env user initialized');
137+
TuxLog.log('warn','no env user initialized');
138138
reject("Internal Error");
139139
}
140140
if(slf.vmList.labVm){
141-
TuxLog.log('labfile_error','trying to init env twice');
141+
TuxLog.log('warn','trying to init env twice');
142142
reject("Internal error");
143143
}
144144

@@ -152,6 +152,7 @@ env.prototype.init = function(opts){
152152

153153
//containerId to be stored in helix
154154
else {
155+
console.log("successfully created container");
155156
var containerId = container.id.substring(0,7);
156157
container.start(strOptsf,function(err,data){
157158

@@ -161,56 +162,54 @@ env.prototype.init = function(opts){
161162
}
162163
else {
163164
var etcd_redrouter = {
164-
docker: containerId,
165-
port: 22,
166-
username: "root",
167-
allowed_auth: ["password"]
168-
}
169-
170-
//etcd directory for helix record
171-
var dir = slf.root_dom.split('.');
172-
dir.reverse().push(slf.usr,'A');
173-
slf.helixKey = dir.join('/');
174-
slf.redRouterKey = '/redrouter/ssh::'+slf.usr;
175-
176-
//set etcd record for redrouter
177-
etcd.set(slf.redRouterKey,etcd_redrouter,function(err,res){
178-
if(err){
179-
TuxLog.log('debug', 'error creating redrotuer etcd record: '+err);
180-
reject("Internal error");
181-
}
182-
else{
183-
//set etcd record for helixdns
184-
slf.docker.getContainer(containerId).inspect(function(err,container){
185-
if(err){
186-
TuxLog.log('warn', 'docker cannot find the container it just created: '+err);
187-
reject("Internal error");
188-
//TODO: get the actual information that we actually want. Perhaps change this entirely
189-
}
190-
else{
191-
192-
//set etcd record for helix
193-
etcd.set(slf.helixKey,container.NetworkSettings,function(err,res){
194-
if(err){
195-
TuxLog.log('warn','error creating helix etcd record: '+err);
196-
reject("Internal error");
197-
}
198-
else{
199-
slf.vmList.labVm = slf.labVm;
200-
resolve();
201-
}
202-
});
203-
}
204-
});
205-
}
165+
docker_container: containerId,
166+
port: 22,
167+
username: "root",
168+
allowed_auth: ["password"]
169+
}
170+
//etcd directory for helix record
171+
var dir = slf.root_dom.split('.');
172+
dir.reverse().push(slf.usr,'A');
173+
slf.helixKey = dir.join('/');
174+
slf.redRouterKey = '/redrouter/SSH::'+slf.usr;
175+
176+
//set etcd record for redrouter
177+
etcd.set(slf.redRouterKey,JSON.stringify(etcd_redrouter),function(err,res){
178+
if(err){
179+
TuxLog.log('debug', 'error creating redrotuer etcd record: '+err);
180+
reject("Internal error");
181+
}
182+
else{
183+
//set etcd record for helixdns
184+
slf.docker.getContainer(containerId).inspect(function(err,container){
185+
if(err){
186+
TuxLog.log('warn', 'docker cannot find the container it just created: '+err);
187+
reject("Internal error");
188+
//TODO: get the actual information that we actually want. Perhaps change this entirely
189+
}
190+
else{
191+
//set etcd record for helix
192+
etcd.set(slf.helixKey,container.NetworkSettings,function(err,res){
193+
if(err){
194+
TuxLog.log('warn','error creating helix etcd record: '+err);
195+
reject("Internal error");
196+
}
197+
else{
198+
slf.vmList.labVm = slf.labVm;
199+
resolve();
200+
}
201+
});
202+
}
206203
});
207204
}
208205
});
209206
}
210207
});
211208
}
212209
});
213-
});
210+
}
211+
});
212+
});
214213
}
215214

216215
/* creates a new container with an image from the options provided,

server/imports/api/lab.session.js

Lines changed: 56 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ session.prototype.init = function(user,labId,callback){
1313
this.env.setUser(user);
1414

1515
// Get Metadata from Database
16-
var lab_data = Collections.labs.findOne({_id: labId}, {fields: {'file' : 0}});
16+
var lab_data = Collections.labs.findOne({_id: labId}, {fields: {'labfile' : 0}});
1717
if(!lab_data || lab_data.length < 0){
1818
callback(new Error("Lab Not Found.", null));
1919
}
@@ -44,72 +44,87 @@ session.prototype.init = function(user,labId,callback){
4444
}
4545
});
4646

47-
48-
SessionCache.add(user,labId,slf,function(err){
47+
48+
slf.start(function(err){
4949
if(err){
5050
callback(err,null);
5151
}
5252
else{
53-
slf.start(function(error){
54-
if(err){
55-
callback(err,null);
56-
}
57-
else{
58-
console.log("moving to env.getPass");
59-
slf.env.getPass(callback);
60-
}
61-
});
53+
console.log("moving to env.getPass");
54+
slf.env.getPass(function(err,res){
55+
if(err){
56+
callback(err,null);
57+
}
58+
else{
59+
slf.lab.pass = res;
60+
callback(null,{taskNo: slf.lab.taskNo,sshPass: res});
61+
}
62+
});
6263
}
6364
});
64-
65-
}
65+
}
6666
else{
6767
// Get LabFile from Cache
6868
var Lab = value;
6969
Lab.taskNo = 0;
7070
slf.lab = Lab;
71-
SessionCache.add(user,labId,slf,function(err){
72-
if(err){
73-
callback(err,null);
74-
}
75-
else{
71+
slf.start(function(err){
72+
if(err){
73+
callback(err,null);
74+
}
75+
else{
7676
console.log("moving to env.getPass");
77-
slf.env.getPass(callback);
78-
}
77+
slf.env.getPass(function(err,res){
78+
if(err){
79+
callback(err,null);
80+
}
81+
else{
82+
//slf.lab.pass = res;
83+
callback(null,{taskNo: slf.lab.taskNo,sshPass: res});
84+
}
85+
});
86+
}
7987
});
8088
}
8189
});
8290
}
8391
}
84-
8592
/* start: runs setup and moves task header to first task
8693
* runs callback(err) on err if there is an error,
8794
* (null) no error
8895
*/
8996
session.prototype.start = function(callback){
9097
var slf = this;
91-
console.log(this.lab);
9298
this.lab.taskNo = 1;
9399
this.lab.setup(this.env)
94-
.then(function(){ slf.lab.tasks(this.env);
95-
console.log("done w setup");
96-
},function(err){
97-
TuxLog.log("warn","error during labfile_setup: "+err);
98-
callback("Internal Service Error")
99-
})
100-
.then(function(){
101-
if(!this.lab.currentTask.next){
102-
TuxLog.log('labfile_error','labfile tasks not properly chained at start');
103-
callback("Internal Service error");
100+
.then(function(){
101+
// slf.lab.tasks(this.env);
102+
callback(null);
103+
},
104+
function(err){
105+
TuxLog.log("warn","error during labfile_setup: "+err);
106+
callback("Internal Service Error")
104107
}
105-
else{
106-
this.lab.currentTask = this.lab.currentTask.next;
107-
this.lab.currentTask.sFn().then(function(){ callback(null); });
108-
}
109-
}, function(){
110-
TuxLog.log("warn","error setting up task1");
111-
callback("Internal Service Error");
112-
});
108+
)
109+
110+
.then(function(){
111+
if(!this.lab.currentTask.next){
112+
TuxLog.log('warn','labfile tasks not properly chained at start');
113+
callback("Internal Service error");
114+
}
115+
else{
116+
this.lab.currentTask = this.lab.currentTask.next;
117+
console.log("no"+slf.lab.taskNo);
118+
this.lab.currentTask.sFn().then(function(){console.log("no"+slf.lab.taskNo)}).then(function(){
119+
console.log("no"+slf.lab.taskNo);
120+
console.log("start");
121+
callback(null); });
122+
}
123+
},
124+
function(){
125+
TuxLog.log("warn","error setting up task1");
126+
callback("Internal Service Error");
127+
});
113128
}
114129

115130
/* next: verifies that task is completed

server/imports/lab/cache.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ var NodeCache = require('node-cache');
6969
session - session object to be stored
7070
callback(success) - returns boolean if success
7171
*/
72-
SessionCache.add = function(userid, labid, session, callback){
72+
SessionCache.add = function(userid, labid, session){
7373
async.series([
7474
function(cb){
7575
SessionCache._NodeCache.set(userid+'#'+labid, session, function(err, success){
@@ -97,10 +97,8 @@ var NodeCache = require('node-cache');
9797
], function(err){
9898
if(err){
9999
TuxLog.log('warn',err);
100-
callback(null);
101100
}
102101
else{
103-
callback(err);
104102
}
105103
});
106104
}

0 commit comments

Comments
 (0)