Skip to content

Commit

Permalink
Merge pull request #1 from shangwen/master
Browse files Browse the repository at this point in the history
update emrdemo
  • Loading branch information
liubangchen authored Apr 23, 2018
2 parents 570492b + 32e0e86 commit 2c92ac6
Showing 1 changed file with 101 additions and 13 deletions.
114 changes: 101 additions & 13 deletions emr-sdk/src/main/python/emrdemo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

# 引入云API入口模块
from QcloudApi.qcloudapi import QcloudApi
import json
from emr import Emr


Expand Down Expand Up @@ -30,17 +31,22 @@ def _factory(self, module, config):
EmrDescribeClusterNode 查询集群节点信息
EmrScaleoutCluster 扩容接口
EmrDestroyTaskNode 缩容接口
UpdateServiceParamsForMC 参数更新接口
'''
action = 'EmrDescribeCluster'
clusterId = 'emr-xxxxxxxx'
appId = '1234567890'
operateUin = '1223333333'
ownerUin = '122222222'

'''
config: 云API的公共参数
'''
config = {
'Region': 'ap-beijing',
'secretId': '123',
'secretKey': '123',
'Region': 'gz',
'secretId': 'secret_id',
'secretKey': 'secret_key',
}
'''
查询集群信息参数
Expand All @@ -62,18 +68,100 @@ def _factory(self, module, config):
'ClusterId':'emr-123456',
'IPs.0':'192.168.0.1'
}
'''
# 接口参数
action_params = {

}

try:
service = EMRQcloudApi(module, config)
print(service.generateUrl(action, action_params))
print(service.call(action, action_params))
except Exception as e:
import traceback

print('traceback.format_exc():\n%s' % traceback.format_exc())
service = EMRQcloudApi(module, config)

def sendRequest(action, action_params):
try:
print(service.generateUrl(action, action_params))
print(service.call(action, action_params))
except Exception as e:
import traceback
print('traceback.format_exc():\n%s' % traceback.format_exc())

def restartService():
print('restart cluster service')
action_params = {
'clusterId': clusterId,
'appId': appId,
'serviceGroup': 1,
'serviceType': 1,
'operateUin': operateUin,
'ownerUin': ownerUin,
'Region':'gz'
}
sendRequest('RestartServiceForMC', action_params)

def scaloutClusterAndRunScripts():
print('scalout cluster and run sripts')
scriptItem1 = {
'FilePath':'frank/test1.sh',
'Region':'ap-guangzhou',
'Bucket':'huanan',
'Args':["12", "13", "15"]
}
scriptItem2 = {
'FilePath':'frank/test2.py',
'Region':'ap-guangzhou',
'Bucket':'huanan',
'Args':["12","16"]
}
cosInfo = {
'secretId':'secret_id',
'secretKey':'secret_key'
}
action_params = {
'ClusterId': clusterId,
'CoreNodes':0,
'TaskNodes':1,
'NodeChargeType':0,
'Region':'gz',
'Files.0':json.dumps(scriptItem1),
'Files.1':json.dumps(scriptItem2),
'CosInfo':json.dumps(cosInfo)
}
sendRequest('EmrScaleoutCluster', action_params)

def describeCluster():
print('restart cluster service')
action_params = {
'ClusterId': clusterId,
'NodeFlag':'all'
}
sendRequest('EmrDescribeCluster', action_params)

def updateParams():
print('update cluster params')
config = {
'dfs.datanode.handler.count':'112',
'foo-add-key':'foo-value'
}

configStr = json.dumps(config)
action_params = {
'clusterId': clusterId,
'appId': appId,
'serviceType':1,
'log':'test',
'remark':'foo test',
'operateUin': operateUin,
'ownerUin': ownerUin,
'op':'update',
'Region':'gz',
'paramsArray.0':configStr,
'fileNameArray.0':'hdfs-site.xml'
}
sendRequest('UpdateServiceParamsForMC', action_params)

def main():
#updateParams()
#describeCluster()
#restartService()
scaloutClusterAndRunScripts()

if __name__ == "__main__":
main()

0 comments on commit 2c92ac6

Please sign in to comment.