Exemplo n.º 1
0
var listContainers = function(args) {
  insight.track('container', 'list');

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  var table = new cliTable({chars: tableChars, style: tableStyle,
                            head: ['Name', 'Type', 'Id'], colWidths: [20, 20, 50]});


  var sr = fetchContainerSysRev(args);
  if (!sr) { return; }

  sdk.listContainers(sr.sys, sr.revision, function(err, containers) {
    if (err) {
      return quit(err);
    }

    _.each(containers, function(container) {
      var name = container.name || '-';
      var type = container.type ||  '-';
      var id = container.id || '-';
      table.push([name, type, id]);
    });
    console.log(table.toString());
    quit();
  });
};
Exemplo n.º 2
0
function logServer(args) {
  insight.track('server', 'logs');
  var logDir = nscaleRoot + '/log';
  var logfile = args[2] || 'kernel.log';
  var logProcess = exec('tail -n 100 -f ' + logDir + '/' + logfile);
  logProcess.stdout.pipe(process.stdout);
}
Exemplo n.º 3
0
var previewRevision = function(args) {
  insight.track('revision', 'preview');

  fetchSys(3, args);
  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.previewRevision(args._[0], args._[1], args._[2], function(err, operations) {
    if (err) {
      return quit(err);
    }

    console.log();
    var table = new cliTable({chars: tableChars, style: tableStyle, head: ['Command', 'Id'], colWidths: [30, 50]});
    console.log('execution plan: ');
    _.each(operations.plan, function(element) {
      table.push([element.cmd, element.id]);
    });
    console.log(table.toString());
    console.log();

    var opsTable = new cliTable({chars: tableChars, style: tableStyle, head: ['Host', 'Command'], colWidths: [20, 150]});
    console.log('operations: ');

    _.each(operations.ops, function(operation) {
      opsTable.push([operation.host || '', operation.cmd || '']);
    });
    console.log(opsTable.toString());
    console.log();
    quit();
  });
};
Exemplo n.º 4
0
var linkSystem = function(args) {
  insight.track('system', 'link');

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.linkSystem(args._[0] || '.', process.cwd(), function(err) {
    quit(err);
  });
};
Exemplo n.º 5
0
insight.trackEvent = function(eventName) {
  if (!insight.optOut){
    switch (eventName) {
      case "init":
        insight.track('bloc', 'init');
        break;
      case "register":
        insight.track('bloc', 'register');
        break;
      case "genkey":
        insight.track('bloc', 'genkey');
        break;
      case "compile":
        insight.track('bloc', 'compile');
        break;
      case "upload":
        insight.track('bloc', 'upload');
        break;
      case "start":
        insight.track('bloc', 'start');
        break;
      case "version":
        insight.track('bloc', 'version');
        break;
      default:
        break;
    }
  }
}
Exemplo n.º 6
0
var compileSystem = function(args) {
  insight.track('system', 'compile');

  fetchSys(1, args);
  var message = args.m || args.message || 'system compile';

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.compileSystem(args._[0], message, quit);
};
Exemplo n.º 7
0
var unlinkSystem = function(args) {
  insight.track('system', 'unlink');

  fetchSys(1, args);
  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.unlinkSystem(args._[0], function(err) {
    quit(err);
  });
};
 insight.trackWithEvent = (category, action) => {
     insight.track(category, action);
     insight.trackEvent({
         category,
         action,
         label: `${category} ${action}`,
         value: 1
     });
 };
Exemplo n.º 9
0
  socket.on('start', function () {
    if (!KitIoT.token.getId()) {
      KitIoT.logout();

    } else {
      KitIoT.start();
      insight.track('socket', 'start');
    }
  });
Exemplo n.º 10
0
function quit(err) {
  if (err) {
    insight.track('error', err.message);
  }

  // because of analytics tracking
  // we need to wait ~100ms for it to complete
  setTimeout(_quit.bind(null, err), 100);
}
Exemplo n.º 11
0
function stopServer() {
  insight.track('server', 'stop');
  console.log('nscale servers stopping..');

  var servers = [
    'nscale-kernel'
  ];

  serverController.stop(servers, quit);
}
Exemplo n.º 12
0
var deployRevision = function(args) {
  insight.track('revision', 'deploy');

  fetchSys(3, args);

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.deployRevision(args._[0], args._[1], args._[2], function(err) {
    if (err) {
      return quit(err);
    }
    quit();
  });
};
Exemplo n.º 13
0
var markRevisionDeployed = function(args) {
  insight.track('revision', 'mark');

  fetchSys(2, args);

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.markRevision(args._[0], args._[1], function(err, result) {
    if (err) {
      return quit(err);
    }

    console.log(JSON.stringify(result, null, 2));
    quit();
  });
};
Exemplo n.º 14
0
var getRevision = function(args) {
  insight.track('revision', 'get');

  fetchSys(3, args);

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.getRevision(args._[0], args._[1], args._[2], function(err, revisions) {
    if (err) {
      return quit(err);
    }

    console.log(JSON.stringify(revisions, null, 2));
    quit();
  });
};
Exemplo n.º 15
0
var analyzeSystem = function(args) {
  insight.track('system', 'analyze');

  fetchSys(2, args);

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.analyzeSystem(args._[0], args._[1], function(err, result) {
    if (err) {
      return quit(err);
    }

    console.log(JSON.stringify(result, null, 2));
    quit();
  });
};
Exemplo n.º 16
0
var getDeployed = function(args) {
  insight.track('system', 'current');

  sdk.ioHandlers(stdoutHandler, stderrHandler);

  fetchSys(2, args);

  sdk.getDeployed(args._[0], args._[1], function(err, system) {
    if (err) {
      return quit(err);
    }

    console.log(JSON.stringify(system, null, 2));
    quit();
  });
};
Exemplo n.º 17
0
var stopSystem = function(args) {
  insight.track('system', 'stop');

  fetchSys(2, args);
  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.stopSystem(args._[0], args._[1], function(err) {
    if (err) {
      return quit(err);
    }

    console.log();
    console.log('Stop completed, run \'system check\' to confirm');
    console.log();
    quit();
  });
};
Exemplo n.º 18
0
function login() {
  insight.track('login');

  sdk.login('', '', function(err, result) {
    if (result && result.user && result.user.token) {
      cfg.setToken(result.user.token);
      console.log('done');
    }
    else if (result && result.err) {
      console.log();
      console.log('error: ' + JSON.stringify(result.err));
      console.log();
    }
    quit();
  });
}
Exemplo n.º 19
0
var buildAllContainers = function(args) {
  insight.track('container', 'buildall');

  var sys;
  var revision;
  var localSys = currentSys();
  var target;

  if (args._.length === 0) {
    sys = localSys;
    revision = 'latest';
    target = 'alltargets';
  } else if (args._.length === 1) {
    if (!localSys || args._[0] === localSys) {
      sys = args._[0];
      revision = 'latest';
    } else {
      sys = localSys;
      revision = args._[0];
    }
    target = 'alltargets';
  } else if (args._.length === 2) {
    if (!localSys || args._[0] === localSys) {
      sys = args._[0];
      revision = args._[1];
      target = 'alltargets';
    } else {
      sys = localSys;
      revision = args._[0];
      target = args._[1];
    }
  } else {
    sys = args._[0];
    revision = args._[1];
    target = args._[2];
  }

  if (!sys) {
    console.error('please specify a system');
    quit();
    return;
  }

  sdk.ioHandlers(stdoutHandler, stderrHandler);

  sdk.buildAllContainers(sys, revision, target, quit);
};
Exemplo n.º 20
0
var listSystems = function() {
  insight.track('system', 'list');

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  var table = new cliTable({chars: tableChars, style: tableStyle,
                            head: ['Name', 'Id'], colWidths: [30, 50]});
  sdk.listSystems(function(err, systems) {
    if (err) {
      return quit(err);
    }

    _.each(systems, function(system) {
      table.push([system.name, system.id]);
    });
    console.log(table.toString());
    quit();
  });
};
Exemplo n.º 21
0
var useSystem = function(args) {
  insight.track('system', 'use');

  var port = args._[1];
  var config;

  if (!port) {
    port = 3223;
  }
  if (args._[0]) {
    cfg.use(args._[0], port);
  }
  else {
    config = cfg.getConfig();
    console.log('using: ' + config.host + ' ' + config.port);
  }
  quit();
};
Exemplo n.º 22
0
var commitSystem = function(args) {
  var commitMsg = '';
  var first = true;
  insight.track('system', 'commit');

  fetchSys(1, args);
  var message = args.m || args.message;

  if (!message) {
    tmp.file(function(err, path) {
      fs.writeFileSync(path, '\n# Please enter the commit message for your changes. Lines starting\n# with "#" will be ignored, and an empty message aborts the commit.', 'utf8');
      editor(path, function() {
        message = fs.readFileSync(path, 'utf8');
        _.each(message.split('\n'), function(line) {
          if (line.charAt(0) !== '#') {
            if (!first) {
              commitMsg += '\n';
            }
            first = false;
            commitMsg += line;
          }
        });
        commitMsg = commitMsg.replace(/\n/g, ' ');
        if (commitMsg.length > 3) {
          commitMsg = '\'' + commitMsg + '\'';
          sdk.ioHandlers(stdoutHandler, stderrHandler);
          sdk.commitSystem(args._[0], commitMsg, function(err) {
            quit(err);
          });
        }
        else {
          console.log('aborted!');
          quit();
        }
      });
    });
  }
  else {
    sdk.ioHandlers(stdoutHandler, stderrHandler);
    sdk.commitSystem(args._[0], message, function(err) {
      quit(err);
    });
  }
};
Exemplo n.º 23
0
function serverStatus() {
  insight.track('server', 'status');

  var servers = [
    'nscale-kernel'
  ];

  function onNextServer(server, cb) {
    serverController.serverStatus(server, function(err, status) {
      if (err) { cb(err); }
      console.log(server, status);
      if (!status.running && status.listening) {
        console.log('Another service is running on the ' + server.replace('nscale-', '') + ' port - please check', nscaleRoot + '/config/config.json\n');
      }
      cb(null);
    });
  }

  async.eachSeries(servers, onNextServer, quit);
}
Exemplo n.º 24
0
KitIoT.io.on('connection', function (socket) {
  KitIoT.connect();
  insight.track('socket', 'connection');

  //Start sending/saving data
  socket.on('start', function () {
    if (!KitIoT.token.getId()) {
      KitIoT.logout();

    } else {
      KitIoT.start();
      insight.track('socket', 'start');
    }
  });

  //Stop sending/saving data
  socket.on('stop', function () {
    KitIoT.clearLoop(KitIoT.loop);
    insight.track('socket', 'stop');
  });
});
Exemplo n.º 25
0
var infoSystem = function(args) {
  insight.track('system', 'info');

  fetchSys(2, args);

  var table = new cliTable({chars: tableChars, style: tableStyle,
                            head: ['Name', 'Type', 'Parent', 'Info'], colWidths: [20, 20, 20, 50]});

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.infoSystem(args._[0], args._[1], function(err, info) {
    if (err) {
      return quit(err);
    }

    _.each(info, function(inf) {
      table.push([inf.name, inf.type, inf.parent, inf.info]);
    });
    console.log(table.toString());
    quit();
  });
};
Exemplo n.º 26
0
var checkSystem = function(args) {
  insight.track('system', 'check');

  fetchSys(2, args);
  sdk.ioHandlers(stdoutHandler, stderrHandler);
  sdk.checkSystem(args._[0], args._[1], function(err, operations) {
    if (err) {
      return quit(err);
    }

    console.log();

    if (operations.plan.length > 0) {
      console.log('Deviation from deployed revision detected!');
      console.log('Remedial action plan as follows:');
      console.log();
      var table = new cliTable({chars: tableChars, style: tableStyle, head: ['Command', 'Id'], colWidths: [30, 50]});
      console.log('execution plan: ');
      _.each(operations.plan, function(element) {
        table.push([element.cmd, element.id]);
      });
      console.log(table.toString());
      console.log();

      var opsTable = new cliTable({chars: tableChars, style: tableStyle, head: ['Host', 'Command'], colWidths: [20, 150]});
      console.log('operations: ');
      _.each(operations.ops, function(operation) {
        opsTable.push([operation.host || '', operation.cmd || '']);
      });
      console.log(opsTable.toString());
      console.log();
      console.log('run \'system fix\' to execute');
    }
    else {
      console.log('Looking good! No deviation detected');
    }
    console.log();
    quit();
  });
};
Exemplo n.º 27
0
var listRevisions = function(args) {
  insight.track('revision', 'list');

  fetchSys(1, args);

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  var table = new cliTable({chars: tableChars, style: tableStyle,
                            head: ['revision', 'deployed', 'who', 'time', 'description'],
                            colWidths: [20, 12, 40, 25, 50]});

  sdk.listRevisions(args._[0], function(err, revisions) {
    if (err) {
      return quit(err);
    }

    _.each(revisions, function(revision){
      table.push([revision.id, revision.deployedTo || '', revision.author, revision.date, revision.message.trim()]);
    });
    console.log(table.toString());
    quit();
  });
};
Exemplo n.º 28
0
var listTimeline = function(args) {
  insight.track('timeline', 'list');

  sdk.ioHandlers(stdoutHandler, stderrHandler);
  var table = new cliTable({chars: tableChars,
                            style: tableStyle,
                            head: ['Timestamp', 'User', 'Action', 'Details'],
                            colWidths: [40, 20, 20, 60]});

  fetchSys(1, args);

  sdk.timeline(args._[0], function(err, timeline) {
    if (err) {
      return quit(err);
    }

    _.each(timeline.entries.reverse(), function(entry){
      table.push(['' + entry.ts, entry.user.name, entry.type, entry.details]);
    });
    console.log(table.toString());
    quit();
  });
};
Exemplo n.º 29
0
var createSystem = function() {
  insight.track('system', 'create');
  sdk.ioHandlers(stdoutHandler, stderrHandler);
  inquirer.prompt([{
    type: 'input',
    name: 'name',
    message: 'What is the system name?',
    validate: validateDockerName
  }, {
    type: 'input',
    name: 'namespace',
    message: 'What is the system namespace?',
    default: function(values) {
      return values.name;
    },
    validate: validateDockerName
  }, {
    type: 'confirm',
    name: 'confirm',
    message: function(values) {
      return 'Confirm creating system "' + values.name + '" with namespace "' + values.namespace + '"?';
    },
    default: true
  }], function(results) {
    if (!results.confirm) {
      console.log(chalk.red('aborted'));
    }

    sdk.createSystem(results.name, results.namespace, process.cwd(), function(err, system) {
      if (!err && system && !system.id) {
        err = new Error('No system id was returned');
      }

      quit(err);
    });
  });
};
Exemplo n.º 30
0
 socket.on('stop', function () {
   KitIoT.clearLoop(KitIoT.loop);
   insight.track('socket', 'stop');
 });