Skip to content

Commit 3327753

Browse files
committed
Merge branch 'develop'
2 parents ca69290 + 64e212c commit 3327753

File tree

13 files changed

+319
-263
lines changed

13 files changed

+319
-263
lines changed

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
FROM node:6.2
22

3-
ADD src /usr/src/app/src
4-
ADD package.json /usr/src/app/
3+
COPY src /usr/src/app/src
4+
COPY package.json /usr/src/app/
55

66
WORKDIR /usr/src/app
77

@@ -11,4 +11,4 @@ RUN mkdir logs
1111
RUN npm install
1212

1313
EXPOSE 9090
14-
CMD ["forever", "src/main/server.js"]
14+
CMD ["node", "src/main/server.js"]

docker-compose.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
msg-node-nodejs:
22
image: msg-node-rethink:latest
3+
# For Easy Development of the msg-node load this volume
34
# volumes:
45
# - /path/to/msg-node/repository:/usr/src/app
56
ports:
67
- "9090:9090"
78
environment:
8-
- url=localhost
9-
- port=9090
10-
- domainRegistryUrl=http://localhost:4567
9+
- url=localhost # url:domain of CSP where the Messaging Node would be deployed
10+
- port=9090 # port:port of Messaging Node would be deployed
11+
- domainRegistryUrl=http://localhost:4567/ # url:domain of CSP where the registry-domain would be deployed
12+
- globalRegistryUrl=http://130.149.22.133:5002/ # url:domain of CSP where the Global Registry would be deployed
1113
- logLevel=INFO
1214
# - logDir=/usr/src/app/logs
1315
# - useSSL=1

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"chai": "^3.3.0",
3535
"expect.js": "^0.3.1",
3636
"gulp": "^3.9.0",
37+
"log4js": "^0.6.27",
3738
"gulp-bump": "^1.0.0",
3839
"gulp-if": "^2.0.0",
3940
"gulp-insert": "^0.5.0",
@@ -52,7 +53,9 @@
5253
"socket.io-client": "^1.3.7",
5354
"vinyl-buffer": "^1.0.0",
5455
"vinyl-source-stream": "^1.1.0",
55-
"watchify": "^3.4.0"
56+
"watchify": "^3.4.0",
57+
"dev-registry-domain": "github:rethink-project/dev-registry-domain",
58+
"runtime-core": "github:rethink-project/dev-runtime-core#develop"
5659
},
5760
"jspm": {
5861
"directories": {
@@ -66,6 +69,7 @@
6669
}
6770
},
6871
"directories": {
72+
"doc": "docs",
6973
"test": "test"
7074
},
7175
"dependencies": {
@@ -99,6 +103,8 @@
99103
"uuid": "^2.0.1",
100104
"vinyl-buffer": "^1.0.0",
101105
"vinyl-source-stream": "^1.1.0",
102-
"watchify": "^3.6.1"
106+
"watchify": "^3.6.1",
107+
"dev-registry-domain": "github:rethink-project/dev-registry-domain",
108+
"runtime-core": "github:rethink-project/dev-runtime-core#develop"
103109
}
104110
}

src/main/MsgNode.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ let MessageBus = require('./components/MessageBus');
4545
let SessionManager = require('./components/SessionManager');
4646

4747
let AddressAllocationManager = require('./components/rethink/AddressAllocationManager');
48-
let RegistryManager = require('./components/rethink/RegistryManager');
48+
let DomainRegistryManager = require('./components/rethink/DomainRegistryManager');
49+
let GlobalRegistryManager = require('./components/rethink/GlobalRegistryManager');
4950
let SubscriptionManager = require('./components/rethink/SubscriptionManager');
5051
let ObjectAllocationManager = require('./components/rethink/ObjectAllocationManager');
5152

@@ -58,9 +59,7 @@ class MsgNode {
5859
*/
5960
constructor(config) {
6061
let _this = this;
61-
6262
this.config = config;
63-
6463
this.config.domainRegistryUrl = this.config.domainRegistryUrl.replace(/\/$/, '') + '/';
6564

6665
// define logger configuration
@@ -89,8 +88,9 @@ class MsgNode {
8988
this.app.get('/live', (req, res) => {
9089
res.send({
9190
status:'up',
92-
domain : this.config.url,
91+
domain: this.config.url,
9392
domainRegistry: this.config.domainRegistryUrl,
93+
globalRegistry: this.config.globalRegistryUrl,
9494
time: (new Date()).toISOString(),
9595
connected: Object.keys(this.io.sockets.sockets).length
9696
});
@@ -122,8 +122,10 @@ class MsgNode {
122122
this.registry.registerComponent(olm);
123123
let syncm = new SubscriptionManager('domain://msg-node.' + this.registry.getDomain() + '/sm', this.registry);
124124
this.registry.registerComponent(syncm);
125-
let rm = new RegistryManager('domain://registry.' + this.registry.getDomain(), this.registry);
125+
let rm = new DomainRegistryManager('domain://registry.' + this.registry.getDomain() + '/', this.registry);
126126
this.registry.registerComponent(rm);
127+
let glbm = new GlobalRegistryManager(this.registry.getDomain().globalRegistryUrl, this.registry);
128+
this.registry.registerComponent(glbm);
127129

128130
this.io.on('connection', this.onConnection.bind(this));
129131

@@ -135,13 +137,13 @@ class MsgNode {
135137

136138
//socket.id : socket.io id
137139
//socket.handshake.sessionID : express shared sessionId
138-
this.logger.info('[C->S] new client connection', socket.id);
140+
this.logger.info('[C->S] new client connection : ', socket.id);
139141

140142
// socket.join(socket.id);
141143
let client = new Client(this.registry, socket);
142144

143145
socket.on('message', function(data) {
144-
_this.logger.info('[C->S] new event', data);
146+
_this.logger.info('[C->S] new event : ', data);
145147
try {
146148
client.processMessage(new Message(data));
147149
} catch (e) {
@@ -150,21 +152,21 @@ class MsgNode {
150152
});
151153

152154
socket.on('disconnect', function() {
153-
_this.logger.info('[C->S] client disconnect', socket.id);
155+
_this.logger.info('[C->S] client disconnect: ', socket.id);
154156

155157
client.disconnect();
156158
});
157159

158160
socket.on('error', function(e) {
159-
_this.logger.info('[C->S] socket error', socket.id, e);
161+
_this.logger.info('[C->S] socket error : ', socket.id, e);
160162
});
161163

162164
// test ws route
163165
socket.on('echo', function(msg, callback) {
164-
_this.logger.info('[C->S] receive echo');
166+
_this.logger.info('[C->S] receive echo : ');
165167
callback = callback || function() {};
166168

167-
_this.logger.info('[S->C] test ping back');
169+
_this.logger.info('[S->C] test ping back :');
168170
socket.emit('echo', msg);
169171
callback(null, 'Done.');
170172
});

src/main/components/Client.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,15 @@ class Client {
5757
}
5858

5959
reply(msg) {
60-
this.logger.info('[S->C] emit msg', msg.getJson(), 'to', this.getUid());
60+
this.logger.info('[S->C] emit msg : \n ', msg.getJson(), '\t to', this.getUid());
6161
this.socket.emit('message', msg.getJson());
6262
}
6363

64+
replyDomain(msg) {
65+
this.logger.info('[S->C] Forward reply from domain registry emit msg : \n ', msg, '\n to : \n', msg.to);
66+
this.socket.emit('message', msg);
67+
}
68+
6469
disconnect() {
6570
this.socket.disconnect();
6671
}

src/main/components/ClientMessage.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@ class ClientMessage {
5252
dispatch() {
5353
let comp = this.registry.getComponent(this.msg.getTo());
5454
if (comp) {
55-
this.logger.info('[ClientMessage] dispatch msg to internal', comp.getName());
55+
this.logger.info('[ClientMessage] dispatch msg to internal:', comp.getName());
5656
try {
5757
comp.handle(this);
5858
} catch (e) {
5959
this.replyError(comp.getName(), e);
6060
}
6161
} else {
62-
this.logger.info('[ClientMessage] forward msg to', this.msg.getTo());
62+
this.logger.info('[ClientMessage] forward msg to :', this.msg.getTo());
6363
this.registry.getComponent('MessageBus').publish(this.msg.getTo(), this.msg.msg);
6464
}
6565
}
@@ -69,6 +69,11 @@ class ClientMessage {
6969
this.client.reply(msg);
7070
}
7171

72+
replyDomain(msg) {
73+
// msg.setType('response');
74+
this.client.replyDomain(msg);
75+
}
76+
7277
replyok(from) {
7378
let reply = new Message();
7479
reply.setId(this.msg.getId());

src/main/components/MessageBus.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
/**
23
* Copyright 2016 PT Inovação e Sistemas SA
34
* Copyright 2016 INESC-ID

src/main/components/Registry.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ class Registry {
5858
}
5959

6060
registerComponent(component) {
61+
this.logger.info(this.components[component.getName()]);
6162
this.components[component.getName()] = component;
6263
}
6364

6465
getComponent(name) {
6566
this.logger.info('getComponent(name):', name);
6667
if (name in this.components) {
67-
this.logger.info('this.components', this.components);
68+
// this.logger.info('this.components', this.components);
6869
return this.components[name];
6970
}
7071

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/**
2+
* Copyright 2016 PT Inovação e Sistemas SA
3+
* Copyright 2016 INESC-ID
4+
* Copyright 2016 QUOBIS NETWORKS SL
5+
* Copyright 2016 FRAUNHOFER-GESELLSCHAFT ZUR FOERDERUNG DER ANGEWANDTEN FORSCHUNG E.V
6+
* Copyright 2016 ORANGE SA
7+
* Copyright 2016 Deutsche Telekom AG
8+
* Copyright 2016 Apizee
9+
* Copyright 2016 TECHNISCHE UNIVERSITAT BERLIN
10+
*
11+
* Licensed under the Apache License, Version 2.0 (the "License");
12+
* you may not use this file except in compliance with the License.
13+
* You may obtain a copy of the License at
14+
*
15+
* http://www.apache.org/licenses/LICENSE-2.0
16+
*
17+
* Unless required by applicable law or agreed to in writing, software
18+
* distributed under the License is distributed on an "AS IS" BASIS,
19+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20+
* See the License for the specific language governing permissions and
21+
* limitations under the License.
22+
**/
23+
24+
'use strict';
25+
let Message = require('./../Message');
26+
27+
const RegistryDomainConnector = require('dev-registry-domain/connector');
28+
29+
class DomainRegistryManager {
30+
31+
constructor(name, registry) {
32+
this.name = name;
33+
this.registry = registry;
34+
this.registryConnector = new RegistryDomainConnector(this.registry.getConfig().domainRegistryUrl);
35+
this.logger = this.registry.getLogger();
36+
37+
}
38+
39+
getName() {
40+
return this.name;
41+
}
42+
43+
handle(clientMessage) {
44+
let msg = clientMessage.getMessage();
45+
this.logger.info('[RegistryManager]: [', this.getName(), ']: handle registry message :\n', msg.msg);
46+
47+
switch (msg.msg.type.toLowerCase()) {
48+
case 'create':
49+
case 'read':
50+
case 'delete':
51+
case 'update':
52+
try {
53+
this.registryConnector.processMessage(msg.msg, (res) => {
54+
this.logger.info('[', this.getName(), '] Reply from domain registry :\n ', res);
55+
this.logger.debug(' this.registryConnector : ', this.registryConnector);
56+
let reply = new Message();
57+
reply = {
58+
id: msg.msg.id,
59+
type: 'response',
60+
from:msg.msg.to,
61+
to: msg.msg.from,
62+
body: res
63+
};
64+
clientMessage.replyDomain(reply);
65+
});
66+
} catch (e) {
67+
this.logger.error('[', this.getName(), ']: Error while processing message:\n', e);
68+
}
69+
70+
break;
71+
default:
72+
clientMessage.replyError(this.getName(), 'Unrecognized type :"' + msg.getType() + '"');
73+
}
74+
}
75+
}
76+
module.exports = DomainRegistryManager;

0 commit comments

Comments
 (0)