-
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 33 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"] | ||
] | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,18 @@ | |
* Created by Chyroc on 17/1/10. | ||
*/ | ||
|
||
import { sendGetRequest } from './utils/sendRequest' | ||
import { sendGetRequest, senPostRequest, senPutRequest, senDeleteRequest } from './sendRequest' | ||
import { setCreateLinkRequestBody, setUpdateLinkRequestBody } from './setLinkOptions' | ||
|
||
import url from 'url' | ||
import path from 'path' | ||
import querystring from 'querystring' | ||
|
||
export const version = 'v1' | ||
const versionUri = 'version' | ||
const driverUri = 'v1/driver' | ||
const connectorUri = 'v1/connector' | ||
const driverUri = `${version}/driver` | ||
const connectorUri = `${version}/connector` | ||
const linkUri = `${version}/link` | ||
|
||
export class Hasoop { | ||
constructor (config) { | ||
|
@@ -39,16 +42,19 @@ export class Hasoop { | |
return url.format(urlObj) | ||
} | ||
|
||
// version | ||
getVersion () { | ||
const url = this.formatUrl([versionUri]) | ||
return sendGetRequest(url) | ||
} | ||
|
||
// driver | ||
getDriver () { | ||
const url = this.formatUrl([driverUri], 'all') | ||
return sendGetRequest(url) | ||
} | ||
|
||
// connector | ||
getConnectorAll () { | ||
const url = this.formatUrl([connectorUri], 'all') | ||
return sendGetRequest(url) | ||
|
@@ -58,4 +64,53 @@ export class Hasoop { | |
const url = this.formatUrl([connectorUri], connectorName) | ||
return sendGetRequest(url) | ||
} | ||
|
||
// link | ||
createLink (config) { | ||
const body = setCreateLinkRequestBody(config) | ||
const url = this.formatUrl([linkUri]) | ||
return senPostRequest(url, JSON.stringify(body)) | ||
} | ||
|
||
updateLinkConfig (oldLinkName, config) { | ||
const body = setUpdateLinkRequestBody(config) | ||
const url = this.formatUrl([linkUri], oldLinkName) | ||
return senPutRequest(url, JSON.stringify(body)) | ||
} | ||
|
||
updateLinkEnable (linkName) { | ||
const url = this.formatUrl([linkUri], linkName, 'enable') | ||
return senPutRequest(url) | ||
} | ||
|
||
updateLinkDisable (linkName) { | ||
const url = this.formatUrl([linkUri], linkName, 'disable') | ||
return senPutRequest(url) | ||
} | ||
|
||
getLinkAll () { | ||
const url = this.formatUrl([linkUri], 'all') | ||
return sendGetRequest(url) | ||
} | ||
|
||
getLinkByConnectorName (connectorName) { | ||
const url = this.formatUrl([linkUri, {'cname': connectorName}], 'all') | ||
return sendGetRequest(url) | ||
} | ||
|
||
getLinkByLinkName (linkName) { | ||
const url = this.formatUrl([linkUri], linkName) | ||
return sendGetRequest(url) | ||
} | ||
|
||
deleteLink (linkName) { | ||
const url = this.formatUrl([linkUri], linkName) | ||
return senDeleteRequest(url) | ||
} | ||
|
||
async deleteLinkAll () { | ||
const data = await this.getLinkAll() | ||
const deleteList = data['links'].map(link => this.deleteLink(link['name'])) | ||
return await deleteList | ||
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. you should |
||
} | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
/** | ||
* Created by Chyroc on 17/1/11. | ||
*/ | ||
|
||
export function setCreateLinkRequestBody (linkConfig) { | ||
if (linkConfig['linkType'] === 'mysql') { | ||
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'] === 'hdfs') { | ||
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