Skip to content

Commit 9a8917a

Browse files
committed
v0.1.10 - additional logging
1 parent 5ef454a commit 9a8917a

File tree

2 files changed

+44
-25
lines changed

2 files changed

+44
-25
lines changed

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "HBase",
3-
"version": "0.1.9",
4-
"versionDate": "2019-01-17",
3+
"version": "0.1.10",
4+
"versionDate": "2019-01-18",
55
"author": "hackolade",
66
"engines": {
77
"hackolade": "2.3.2",

reverse_engineering/api.js

+42-23
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ module.exports = {
2222
}, connectionInfo);
2323

2424
if(!clientKrb && options.krb5){
25+
logger.log('info', Object.assign({}, options.krb5, { platform: process.platform }), 'Kerberos options', connectionInfo.hiddenKeys);
26+
2527
kerberosService({ kerberos }).getClient(options.krb5)
2628
.then(client => {
2729
clientKrb = client;
28-
return cb();
30+
return cb();
2931
}, err => cb(err));
3032
} else {
3133
return cb();
@@ -43,30 +45,33 @@ module.exports = {
4345
},
4446

4547
testConnection: function(connectionInfo, logger, cb, app){
48+
logger.clear();
49+
4650
this.connect(connectionInfo, logger, err => {
4751
if(err){
4852
logger.log('error', err, 'Test connection', connectionInfo.hiddenKeys);
4953
return cb(err);
5054
}
5155

52-
getClusterVersion(connectionInfo).then(version => {
56+
getClusterVersion(connectionInfo, logger).then(version => {
5357
return cb();
5458
})
5559
.catch(err => {
56-
logger.log('error', err, 'Test connection', connectionInfo.hiddenKeys);
57-
return cb(err);
60+
return logError(logger, cb)(err, 'Test connection', connectionInfo.hiddenKeys);
5861
});
5962
}, app);
6063
},
6164

6265
getDbCollectionsNames: function(connectionInfo, logger, cb, app) {
66+
logger.clear();
67+
6368
this.connect(connectionInfo, logger, err => {
6469
if(err){
65-
return cb(err);
70+
return logError(logger, cb)(err, 'Connection error', connectionInfo.hiddenKeys);
6671
}
6772
state.connectionInfo = connectionInfo;
6873

69-
getNamespacesList(connectionInfo).then(namespaces => {
74+
getNamespacesList(connectionInfo, logger).then(namespaces => {
7075
async.mapSeries(namespaces, (namespace, callback) => {
7176
getTablesList(connectionInfo, namespace)
7277
.then(res => {
@@ -75,13 +80,17 @@ module.exports = {
7580
return callback(err);
7681
});
7782
}, (err, items) => {
83+
if (err) {
84+
return logError(logger, cb)(err, 'Get tables names error', connectionInfo.hiddenKeys);
85+
}
86+
7887
items = prepareDataItems(namespaces, items);
88+
7989
return cb(err, items);
8090
});
8191
})
8292
.catch(err => {
83-
logger.log('error', err);
84-
return cb(err);
93+
logError(logger, cb)(err, 'Get tables names error', connectionInfo.hiddenKeys);
8594
});
8695
}, app);
8796
},
@@ -159,23 +168,21 @@ module.exports = {
159168
return tableCallback(null, documentsPackage);
160169
})
161170
.catch(err => {
162-
logger.log('error', err);
163-
return tableCallback(err);
171+
return tableCallback(err, []);
164172
});
165173
}, (err, items) => {
166-
if(err){
167-
logger.log('error', err);
168-
} else {
174+
if(!err){
169175
items = items.filter(item => item);
170176
}
171177
return callback(err, items);
172178
});
173179
}
174180
}, (err, res) => {
175-
if(err){
176-
logger.log('error', err);
181+
if (err) {
182+
return logError(logger, cb)(err, 'Get data error', state.connectionInfo.hiddenKeys);
183+
} else {
184+
return cb(err, res, info);
177185
}
178-
return cb(err, res, info);
179186
});
180187
}
181188
};
@@ -187,7 +194,7 @@ function getHostURI(connectionInfo){
187194
}
188195

189196

190-
function getRequestOptions() {
197+
function getRequestOptions(data, logger) {
191198
return new Promise((resolve, reject) => {
192199
let headers = {
193200
'Cache-Control': 'no-cache',
@@ -200,6 +207,10 @@ function getRequestOptions() {
200207
return reject(err);
201208
}
202209

210+
if (logger) {
211+
logger.log('info', { token });
212+
}
213+
203214
headers.Authorization = `Negotiate ${token}`;
204215

205216
resolve({
@@ -216,8 +227,8 @@ function getRequestOptions() {
216227
});
217228
}
218229

219-
function fetchRequest(query, connectionInfo){
220-
return getRequestOptions(connectionInfo)
230+
function fetchRequest(query, connectionInfo, logger){
231+
return getRequestOptions(connectionInfo, logger)
221232
.then((options) => {
222233
return fetch(query, options)
223234
})
@@ -227,10 +238,10 @@ function fetchRequest(query, connectionInfo){
227238
});
228239
}
229240

230-
function getNamespacesList(connectionInfo){
241+
function getNamespacesList(connectionInfo, logger){
231242
let query = `${getHostURI(connectionInfo)}/namespaces`;
232243

233-
return fetchRequest(query, connectionInfo).then(res => {
244+
return fetchRequest(query, connectionInfo, logger).then(res => {
234245
return res.Namespace.filter(item => item !== 'hbase');
235246
});
236247
}
@@ -262,10 +273,10 @@ function getTableSchema(namespace, table, connectionInfo){
262273
});
263274
}
264275

265-
function getClusterVersion(connectionInfo){
276+
function getClusterVersion(connectionInfo, logger){
266277
let query = `${getHostURI(connectionInfo)}/version/cluster`;
267278

268-
return fetchRequest(query, connectionInfo).then(res => {
279+
return fetchRequest(query, connectionInfo, logger).then(res => {
269280
return res;
270281
});
271282
}
@@ -542,3 +553,11 @@ const getRows = (data) => {
542553

543554
return cells;
544555
};
556+
557+
const logError = (logger, cb) => (err, subject, hiddenKeys) => {
558+
logger.log('error', err, subject, hiddenKeys);
559+
560+
setTimeout(() => {
561+
cb(err);
562+
}, 1000);
563+
};

0 commit comments

Comments
 (0)