-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.js
153 lines (124 loc) · 4.27 KB
/
setup.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
const http = require('http');
const https = require('https');
const fs = require('fs');
function makeHttpRequest(options, data = undefined) {
if (options.headers === undefined) {
options.headers = {
'Accept': '*/*'
};
}
if (options.method === 'POST' && data != undefined) {
const jsonData = JSON.stringify(data);
console.log(jsonData);
options.headers['Content-Type'] = 'application/json';
options.headers['Content-Length'] = Buffer.byteLength(jsonData);
}
return new Promise((resolve, reject) => {
const protocolModule = options.port === 443 ? https : http;
const req = protocolModule.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
resolve({
statusCode: res.statusCode,
headers: res.headers,
body: responseData
});
});
});
req.on('error', (error) => {
reject(error);
});
if (options.method === 'POST' && data) {
req.write(JSON.stringify(data));
}
req.end();
});
};
async function addModule(descriptor) {
console.log(`Adding module ${descriptor.id}: ${descriptor.name}`);
try {
const response = await makeHttpRequest({
hostname: 'localhost',
port: 9130,
path: '/_/proxy/modules',
method: 'POST'
}, descriptor);
return response.statusCode === 201 ? response.body : response;
} catch (error) {
console.error('Error:', error.message);
}
};
async function deployModule(descriptor, nodeId) {
console.log(`Deploying module ${descriptor.id}: ${descriptor.name}`);
try {
const response = await makeHttpRequest({
hostname: 'localhost',
port: 9130,
path: '/_/discovery/modules',
method: 'POST'
}, {
srvcId: descriptor.id,
nodeId
});
return response.statusCode === 201 ? response.body : response;
} catch (error) {
console.error('Error:', error.message);
}
};
async function enableModule(descriptor, tenant) {
console.log(`${tenant} enabling module ${descriptor.id}: ${descriptor.name}`);
try {
const response = await makeHttpRequest({
hostname: 'localhost',
port: 9130,
path: `/_/proxy/tenants/${tenant}/modules`,
method: 'POST'
}, { id: descriptor.id });
return response.statusCode === 201 ? response.body : response;
} catch (error) {
console.error('Error:', error.message);
}
};
function readModuleDescriptor(path) {
console.log(`Reading module descriptor at ${path}`);
return new Promise((resolve, reject) => {
fs.readFile(path, 'utf8', (err, data) => {
if (err) {
reject(err);
}
resolve(JSON.parse(data));
});
});
}
async function main() {
// run from fw-cli with mod-camunda and mod-workflow target available and images built
// get the tenant
const tenant = 'diku';
// get the nodeId
const nodeId = '10.0.2.15';
const modWorkflowDescriptorPath = './mod-workflow/target/ModuleDescriptor.json';
const modCamundaDescriptorPath = './mod-camunda/target/ModuleDescriptor.json';
if (!fs.existsSync(modWorkflowDescriptorPath)) {
console.error(`mod-workflow module descriptor is required! ${modWorkflowDescriptorPath} not found`);
}
if (!fs.existsSync(modCamundaDescriptorPath)) {
console.error(`mod-camunda module descriptor is required! ${modCamundaDescriptorPath} not found`);
}
const modWorkflowDescriptor = await readModuleDescriptor(modWorkflowDescriptorPath);
const modCamundaDescriptor = await readModuleDescriptor(modCamundaDescriptorPath);
console.log('watch okapi logs\n: docker logs okapi -n 100 -f');
console.log(await addModule(modWorkflowDescriptor));
console.log(await addModule(modCamundaDescriptor));
console.log(await deployModule(modWorkflowDescriptor, nodeId));
console.log('watch mod workflow logs\n: docker container ls | grep workflow');
console.log(': docker logs <container id> -n 100 -f');
console.log(await deployModule(modCamundaDescriptor, nodeId));
console.log('watch mod camunda logs\n: docker container ls | grep camunda');
console.log(': docker logs <container id> -n 100 -f');
console.log(await enableModule(modWorkflowDescriptor, tenant));
console.log(await enableModule(modCamundaDescriptor, tenant));
}
main();