-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add/link api #13
Add/link api #13
Changes from 34 commits
08e1c60
8b4d408
45949d0
340f1f6
ab09b7b
b679941
dabf58a
588f608
6317a9d
36dfcd0
020d9a8
377fb5b
93e09bf
9d23272
ac456d0
9647134
ad3a08f
a6f20f7
656b441
ef261ff
8c863b7
39b060d
fb2636e
f6ab838
39eb252
4b616fe
efaa604
73b3d98
e5088f2
f2ca8f5
074784b
c4c0e22
c0c0955
f86a7c2
96cda19
2976264
1919690
f5e2f4e
2d4b220
5d0b45a
93f360f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
"regenerator": true, | ||
"moduleName": "babel-runtime" | ||
} | ||
] | ||
], | ||
["transform-export-extensions"] | ||
] | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
/** | ||
* Created by Chyroc on 17/1/11. | ||
*/ | ||
import { linkType } from './index' | ||
|
||
export function setCreateLinkRequestBody (linkConfig) { | ||
if (linkConfig['linkType'] === linkType.mysql) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. use two separate functions for mysql and hdfs |
||
const fetchSize = linkConfig['fetchSize'] || 1000 | ||
const identifierEnclose = linkConfig['identifierEnclose'] || '`' | ||
const port = linkConfig['port'] || 3306 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest you keep these default values in another file called constants.js.. and import it in this file |
||
const connectorName = 'generic-jdbc-connector' | ||
const jdbcDriver = 'com.mysql.jdbc.Driver' | ||
const connectionString = `jdbc:mysql://${linkConfig.host}:${port}/${linkConfig.databaseName}` | ||
return { | ||
'links': [ | ||
{ | ||
'id': -1, | ||
'name': linkConfig['linkName'], | ||
'connector-name': connectorName, | ||
'enabled': true, | ||
'creation-date': Date.now(), | ||
'creation-user': null, | ||
'update-user': null, | ||
'update-date': Date.now(), | ||
'link-config-values': { | ||
'configs': [ | ||
{ | ||
'validators': [], | ||
'inputs': [ | ||
{ | ||
'size': 128, | ||
'editable': 'ANY', | ||
'validators': [], | ||
'name': 'linkConfig.jdbcDriver', | ||
'id': 67, | ||
'sensitive': false, | ||
'overrides': '', | ||
'type': 'STRING', | ||
'value': jdbcDriver | ||
}, { | ||
'size': 2000, | ||
'editable': 'ANY', | ||
'validators': [], | ||
'name': 'linkConfig.connectionString', | ||
'id': 68, | ||
'sensitive': false, | ||
'overrides': '', | ||
'type': 'STRING', | ||
'value': encodeURIComponent(connectionString) | ||
}, { | ||
'size': 40, | ||
'editable': 'ANY', | ||
'validators': [], | ||
'name': 'linkConfig.username', | ||
'id': 69, | ||
'sensitive': false, | ||
'overrides': '', | ||
'type': 'STRING', | ||
'value': linkConfig['username'] | ||
}, { | ||
'size': 40, | ||
'editable': 'ANY', | ||
'validators': [], | ||
'name': 'linkConfig.password', | ||
'id': 70, | ||
'sensitive': true, | ||
'overrides': '', | ||
'type': 'STRING', | ||
'value': linkConfig['password'] | ||
}, { | ||
'editable': 'ANY', | ||
'validators': [], | ||
'name': 'linkConfig.fetchSize', | ||
'id': 71, | ||
'sensitive': false, | ||
'overrides': '', | ||
'type': 'INTEGER', | ||
'value': `${fetchSize}` | ||
}, { | ||
'editable': 'ANY', | ||
'validators': [], | ||
'name': 'linkConfig.jdbcProperties', | ||
'id': 72, | ||
'sensitive': false, | ||
'overrides': '', | ||
'type': 'MAP', | ||
'sensitive-pattern': '' | ||
} | ||
], | ||
'name': 'linkConfig', | ||
'id': 17, | ||
'type': 'LINK' | ||
}, | ||
{ | ||
'validators': [], | ||
'inputs': [ | ||
{ | ||
'size': 5, | ||
'editable': 'ANY', | ||
'validators': [], | ||
'name': 'dialect.identifierEnclose', | ||
'id': 73, | ||
'sensitive': false, | ||
'overrides': '', | ||
'type': 'STRING', | ||
'value': encodeURIComponent(identifierEnclose) | ||
} | ||
], | ||
'name': 'dialect', | ||
'id': 18, | ||
'type': 'LINK' | ||
} | ||
], | ||
'validators': [] | ||
} | ||
} | ||
] | ||
} | ||
} else if (linkConfig['linkType'] === linkType.hdfs) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tear up this into two smaller functions |
||
const connectorName = 'hdfs-connector' | ||
const createHdfsLinkBody = { | ||
'links': [{ | ||
'id': -1, | ||
'name': linkConfig['linkName'], | ||
'connector-name': connectorName, | ||
'enabled': true, | ||
'creation-date': Date.now(), | ||
'creation-user': null, | ||
'update-user': null, | ||
'update-date': Date.now(), | ||
'link-config-values': { | ||
'configs': [ | ||
{ | ||
'validators': [], | ||
'inputs': [ | ||
{ | ||
'size': 255, | ||
'editable': 'ANY', | ||
'validators': [], | ||
'name': 'linkConfig.uri', | ||
'id': 52, | ||
'sensitive': false, | ||
'overrides': '', | ||
'type': 'STRING', | ||
'value': encodeURIComponent(linkConfig['uri']) | ||
}, { | ||
'size': 255, | ||
'editable': 'ANY', | ||
'validators': [], | ||
'name': 'linkConfig.confDir', | ||
'id': 53, | ||
'sensitive': false, | ||
'overrides': '', | ||
'type': 'STRING' | ||
}, { | ||
'editable': 'ANY', | ||
'validators': [], | ||
'name': 'linkConfig.configOverrides', | ||
'id': 54, | ||
'sensitive': false, | ||
'overrides': '', | ||
'type': 'MAP', | ||
// 'value': {'key': 'value'}, TODO | ||
'sensitive-pattern': '' | ||
} | ||
], | ||
'name': 'linkConfig', | ||
'id': 13, | ||
'type': 'LINK' | ||
} | ||
], | ||
'validators': [] | ||
} | ||
}] | ||
} | ||
if (linkConfig['hadoopConfDir']) { | ||
createHdfsLinkBody['links'][0]['link-config-values']['configs'][0]['inputs'][1]['value'] = encodeURIComponent(linkConfig['hadoopConfDir']) | ||
} | ||
return createHdfsLinkBody | ||
} else { | ||
throw new Error('linkType must be mysql or hdfs') | ||
} | ||
} | ||
|
||
export function setUpdateLinkRequestBody (linkConfig) { | ||
return setCreateLinkRequestBody(linkConfig) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
/* eslint-env mocha */ | ||
|
||
import { expect } from 'chai' | ||
import _ from 'lodash' | ||
import { sqoopClient } from './index' | ||
|
||
suite('connector', () => { | ||
test('getConnectorAll', async () => { | ||
const data = await sqoopClient.getConnectorAll() | ||
expect(data['connectors'].length).to.equal(7) | ||
expect(data.connectors.length).to.equal(7) | ||
}) | ||
|
||
test('getConnectorByConnectorName', async () => { | ||
const connectorName = 'generic-jdbc-connector' | ||
const data = await sqoopClient.getConnectorByConnectorName(connectorName) | ||
expect(data['connectors'][0]['name']).to.equal('generic-jdbc-connector') | ||
expect(_.get(data, 'connectors[0].name')).to.equal('generic-jdbc-connector') | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you need to look at
Promise.all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
also if you explicitly return
Promise
then you do not need to useasync
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async
是为了getLinkAll
,不是后面那些delete