Skip to content

Commit

Permalink
notifications and Build bundles.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yasar icli committed Apr 7, 2016
1 parent c237d06 commit 84b04f8
Show file tree
Hide file tree
Showing 27 changed files with 289 additions and 112 deletions.
6 changes: 5 additions & 1 deletion .meteor/packages
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ iron:router
aldeed:autoform
cfs:standard-packages
cfs:filesystem
cfs:autoform
less
adriancbo:chalk
zimme:active-route
Expand Down Expand Up @@ -66,3 +65,8 @@ momentjs:moment
templates:tabs
yasaricli:slugify
ongoworks:security
yogiben:autoform-file
juliancwirko:s-alert
juliancwirko:s-alert-slide
cfs:power-queue
froatsnook:sleep
9 changes: 7 additions & 2 deletions .meteor/versions
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ caching-compiler@1.0.3
caching-html-compiler@1.0.5
callback-hook@1.0.7
cfs:access-point@0.1.49
cfs:autoform@2.2.1
cfs:base-package@0.0.30
cfs:collection@0.5.5
cfs:collection-filters@0.2.4
Expand All @@ -40,6 +39,7 @@ cfs:reactive-property@0.0.4
cfs:standard-packages@0.5.9
cfs:storage-adapter@0.2.3
cfs:tempstore@0.1.5
cfs:ui@0.1.3
cfs:upload-http@0.0.20
cfs:worker@0.1.4
check@1.1.3
Expand All @@ -64,6 +64,7 @@ fastclick@1.0.10
fileer:size@0.0.2
flot:flot@0.8.3
fortawesome:fontawesome@4.5.0
froatsnook:sleep@1.2.0
geojson-utils@1.0.7
hitchcott:method-hooks@1.1.0
hot-code-push@1.0.3
Expand All @@ -85,6 +86,8 @@ jparker:crypto-core@0.1.0
jparker:crypto-md5@0.1.1
jparker:gravatar@0.4.1
jquery@1.11.7
juliancwirko:s-alert@3.1.4
juliancwirko:s-alert-slide@3.1.3
kevohagan:sweetalert@1.0.0
lai:collection-extensions@0.2.1_1
launch-screen@1.0.10
Expand Down Expand Up @@ -117,6 +120,8 @@ momentjs:moment@2.12.0
mongo@1.1.6
mongo-id@1.0.3
mongo-livedata@1.0.11
mpowaga:jquery-fileupload@9.11.2
mpowaga:jquery-ui-widget@1.11.4
natestrauser:animate-css@3.5.1
npm-bcrypt@0.7.8_2
npm-mongo@1.4.42
Expand All @@ -130,7 +135,6 @@ pmteor:underscore-helpers@0.0.1
pmteor:whirl@0.0.1
promise@0.6.6
raix:eventemitter@0.1.3
raix:ui-dropped-event@0.0.7
raix:ui-progress-circle@0.0.3
random@1.0.8
rate-limit@1.0.3
Expand Down Expand Up @@ -167,6 +171,7 @@ utilities:avatar@0.9.2
webapp@1.2.7
webapp-hashing@1.0.8
yasaricli:slugify@0.0.7
yogiben:autoform-file@0.4.2
zimme:active-route@2.3.2
zimme:collection-behaviours@1.1.3
zimme:collection-timestampable@1.0.9
1 change: 1 addition & 0 deletions client/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</head>

<template name="layout">
{{ > notifications }}
<div class="wrapper">
<header class="topnavbar-wrapper">
<nav role="navigation" class="navbar topnavbar">
Expand Down
8 changes: 7 additions & 1 deletion i18n/en.i18n.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"all": "All",
"create": "Create",
"update": "Update",
"build": "Build",
"stop-and-update": "Stop Application And Update",
"change-password": "Change Password",
"log-out": "Log Out",
Expand Down Expand Up @@ -47,5 +48,10 @@
"no-logs": "No Logs",
"not-find-logs": "Could not find any logs.",
"monitoring": "Monitoring",
"logs": "Logs"
"logs": "Logs",
"build-started": "<b>%s</b> is to build application started.",
"build-completed": "<b>%s</b> build is completed.",
"started-application": "<b>%s</b> application started successfully.",
"stopped-application": "<b>%s</b> stopped successfully.",
"errored-application": "<b>%s</b> application is errored."
}
30 changes: 19 additions & 11 deletions imports/api/applications/applications.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { Dev } from 'meteor/pmteor:dev';
import Users from '../users/users.js';
import { Logs } from '../logs/logs.js';
import { Bundles } from '../bundles/bundles.js';
import { Notifications } from '../notifications/notifications.js';

import { STATUS_ALLOWED_VALUES, NODE_ENV_ALLOWED_VALUES, DEFAULT_NODE_ENV,
STATUS_MAPPER } from './utils.js';
Expand Down Expand Up @@ -50,7 +51,6 @@ Applications.attachSchema(new SimpleSchema({
'env.MAIL_URL': { type: String, optional: true },
'env.PORT': { type: Number, optional: true },
'env.DISABLE_WEBSOCKETS': { type: Number, optional: true },
'env.MONGO_OPLOG_URL': { type: String, optional: true },

// RUNNING APPLICATION ENV VARIABLE
'env.NODE_ENV': {
Expand All @@ -64,8 +64,10 @@ Applications.attachSchema(new SimpleSchema({
label: 'Bundle',
autoform: {
afFieldInput: {
type: "cfs-file",
collection: "bundles"
type: 'fileUpload',
collection: 'bundles',
label: 'Choose application bundle file',
removeFileBtnTemplate: 'bundleRemoveFileBtn'
}
}
}
Expand Down Expand Up @@ -100,6 +102,16 @@ Applications.helpers({
});
},

notifications(callback) {
return Notifications.find({
applicationId: this._id
}, callback);
},

notification({ type, message }) {
return Notifications.insert({ applicationId: this._id, type, message });
},

bundle() {
return Bundles.findOne(this.bundleId);
},
Expand All @@ -108,14 +120,6 @@ Applications.helpers({
return Dev.isDevelopmentReturned(`http://localhost:${this.env.PORT}`, this.env.ROOT_URL);
},

setStatus(statusCode) {
return Applications.update(this._id, {
$set: {
status: STATUS_ALLOWED_VALUES[statusCode]
}
});
},

isStop() {
return _.isEqual(this.status, STATUS_MAPPER.STOP);
},
Expand All @@ -130,5 +134,9 @@ Applications.helpers({

isReady() {
return _.isEqual(this.status, STATUS_MAPPER.READY);
},

isProgress() {
return _.isEqual(this.status, STATUS_MAPPER.PROGRESS);
}
});
82 changes: 75 additions & 7 deletions imports/api/applications/server/helpers.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { TAPi18n } from 'meteor/tap:i18n';
import { _ } from 'meteor/underscore';

import Users from '../../users/users.js';
import { Applications } from '../applications.js';
import { BUNDLE_DIR } from '../../bundles/utils.js';
import { BUNDLE_DIR, SYNC_EXEC_OPTIONS } from '../../bundles/utils.js';

// NPM PACKAGES
import pm2 from 'pm2';
import freeport from 'freeport';
import { cd, find, rm, exec, test } from 'shelljs';

Applications.helpers({
dir() {
Expand All @@ -27,9 +29,6 @@ Applications.helpers({
start() {
const self = this;

// RUNNING UPDATE
self.setStatus(1);

/*
* Listening port and connect production process manager. if connected
* process manager and started application then change application status
Expand Down Expand Up @@ -68,6 +67,11 @@ Applications.helpers({
});
}

self.notification({
type: 'success',
message: TAPi18n.__('started-application', self.name)
});

// DISCONNECT
pm2.disconnect();
}));
Expand All @@ -78,12 +82,76 @@ Applications.helpers({

stop() {
const self = this;
pm2.connect((connect_err) => {
pm2.stop(self.bundleId, (stop_err) => {
pm2.connect(Meteor.bindEnvironment(() => {
pm2.stop(self.bundleId, Meteor.bindEnvironment(() => {

self.notification({
type: 'success',
message: TAPi18n.__('stopped-application', self.name)
});

// DISCONNECT
pm2.disconnect();
});
}))
}));
},

// ##### --------- REBUILDING FIBERS -------------- #######
build() {

this.notification({
type: 'info',
message: TAPi18n.__('build-started', this.name)
});

// async sleep statements
Meteor.sleep(1000);

cd(`${this.dir()}/programs/server`);

// GO NPM PACKAGES
cd('npm');

// BINARY NPM MODULES
const bindingFiles = find('.').filter((file) => {
return file.match(/\.gyp$/);
});

bindingFiles.forEach((file) => {
const dir = file.replace('/binding.gyp', '');

// GO TO BINDING FILE DIR
cd(dir);

// REMOVE BEFORE MODULES
rm('-rf', 'node_modules');

// INSTALL MODULES
exec('npm install', SYNC_EXEC_OPTIONS);

// AND REBUILD BINDINGS PACKAGES.
exec('node-gyp rebuild', SYNC_EXEC_OPTIONS);

// PREV DIR
cd('-');
});

// PROGRAMS SERVER DIR
cd('..');

// support for 0.9
if (test('-e', 'package.json')) {

exec('npm install', SYNC_EXEC_OPTIONS);
} else {

// support for older versions
exec('npm install fibers bcrypt', SYNC_EXEC_OPTIONS);
}

this.notification({
type: 'success',
message: TAPi18n.__('build-completed', this.name)
});
},

Expand Down
6 changes: 5 additions & 1 deletion imports/api/applications/server/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { _ } from 'meteor/underscore';
import Users from '../../users/users.js';
import { Logs } from '../../logs/logs.js';
import { Applications } from '../applications.js';
import { Notifications } from '../../notifications/notifications.js';

import { BUNDLE_DIR } from '../../bundles/utils.js';

Expand All @@ -23,7 +24,10 @@ Applications.before.insert((userId, doc) => {
Applications.after.remove((userId, doc) => {

// Applications all logs removed.
Logs.remove({ applicationId: doc._id });
Logs.remove({ 'process.name': doc.bundleId });

// Notifications removed
Notifications.remove({ applicationId: doc._id });

// CONNECT AND DELETE APPLICATION
pm2.connect((connect_err) => {
Expand Down
15 changes: 14 additions & 1 deletion imports/api/applications/server/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,20 @@ const stopApplication = new ValidatedMethod({
}
});

const buildApplication = new ValidatedMethod({
name: 'application.build',
mixins: [ hasApplicationMixin ],

run({ _id }) {
const application = Applications.findOne(_id);

// BULD APPLICATION
application.build();
}
});

export {
stopApplication,
startApplication
startApplication,
buildApplication
}
25 changes: 25 additions & 0 deletions imports/api/applications/server/publications.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Meteor } from 'meteor/meteor';
// COLLECTIONS
import Users from '../../users/users.js';
import { Applications } from '../applications.js';
import { Notifications } from '../../notifications/notifications.js';
import { Logs } from '../../logs/logs.js';

Meteor.publishComposite('applications', function() {
Expand Down Expand Up @@ -41,6 +42,18 @@ Meteor.publishComposite('applications', function() {
}
});
}
},

// Notifications
{
find(application) {
return Notifications.find({
applicationId: application._id,
createdAt: {
$gt: new Date() // Publish current Date after .
}
});
}
}
]
}
Expand Down Expand Up @@ -80,6 +93,18 @@ Meteor.publishComposite('application', function(_id) {
}
});
}
},

// Notifications
{
find(application) {
return Notifications.find({
applicationId: application._id,
createdAt: {
$gt: new Date() // Publish current Date after .
}
});
}
}
]
}
Expand Down
5 changes: 3 additions & 2 deletions imports/api/applications/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const NODE_ENV_ALLOWED_VALUES = ['PMTEOR'];
const [ DEFAULT_NODE_ENV ] = NODE_ENV_ALLOWED_VALUES;

// ALLOW STATUS LIST
const STATUS_ALLOWED_VALUES = ['STOP', 'EXIT', 'ONLINE', 'READY', 'ERRORED', 'RESTART', 'RESTART OVERLIMIT'];
const STATUS_ALLOWED_VALUES = ['STOP', 'EXIT', 'ONLINE', 'READY', 'ERRORED', 'RESTART', 'RESTART OVERLIMIT', 'PROGRESS'];

// MAPPER STATUS LIST
const STATUS_MAPPER = {
Expand All @@ -17,7 +17,8 @@ const STATUS_MAPPER = {
ONLINE: STATUS_ALLOWED_VALUES[2],
READY: STATUS_ALLOWED_VALUES[3],
ERRORED: STATUS_ALLOWED_VALUES[4],
RESTART: STATUS_ALLOWED_VALUES[2]
RESTART: STATUS_ALLOWED_VALUES[2],
PROGRESS: STATUS_ALLOWED_VALUES[7]
}

const hasApplicationMixin = (options) => {
Expand Down
Loading

0 comments on commit 84b04f8

Please sign in to comment.