Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion aliyun/log/export_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from .logresponse import LogResponse
from .util import Util

__all__ = ['CreateExportResponse', 'DeleteExportResponse', 'GetExportResponse', 'ListExportResponse']
__all__ = ['CreateExportResponse', 'DeleteExportResponse', 'GetExportResponse', 'ListExportResponse', 'UpdateExportResponse']


class CreateExportResponse(LogResponse):
Expand All @@ -32,6 +32,15 @@ def log_print(self):
print('headers:', self.get_all_headers())


class UpdateExportResponse(LogResponse):
def __init__(self, header, resp=''):
LogResponse.__init__(self, header, resp)

def log_print(self):
print('UpdateExportResponse:')
print('headers:', self.get_all_headers())


class GetExportResponse(LogResponse):
""" The response of the get_export API from log.

Expand Down
25 changes: 24 additions & 1 deletion aliyun/log/logclient.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# coding=utf-8
"""
LogClient class is the main class in the SDK. It can be used to communicate with
log service server to put/get data.
Expand Down Expand Up @@ -5062,7 +5063,7 @@ def create_export(self, project_name, export):
:type project_name: string
:param project_name: the Project name

:type export: string
:type export: Export
:param export: the export job configuration
"""
params = {}
Expand All @@ -5081,6 +5082,28 @@ def create_export(self, project_name, export):
(resp, header) = self._send("POST", project_name, body, resource, params, headers)
return CreateExportResponse(header, resp)

def update_export(self, project_name, job_name, export):
""" Update and Restart an export job
Unsuccessful opertaion will cause an LogException.

:type project_name: string
:param project_name: the Project name

:type job_name: string
:param job_name: the job name of export job

:type export: string
:param export: the export job configuration
"""
if not isinstance(export, str):
raise TypeError("export type must be string")
params = {"action": "RESTART"}
body = six.b(export)
headers = {'Content-Type': 'application/json', 'x-log-bodyrawsize': str(len(body))}
resource = "/jobs/" + job_name
(resp, header) = self._send("PUT", project_name, body, resource, params, headers)
return UpdateExportResponse(header, resp)

def delete_export(self, project_name, job_name):
""" Create an export job
Unsuccessful opertaion will cause an LogException.
Expand Down
2 changes: 1 addition & 1 deletion aliyun/log/odps_sink.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def setFields(self, fields):
def getPartitionColumn(self):
return self.__params["partitionColumn"]

def setPartitionColumn(self, partitionColumn: list):
def setPartitionColumn(self, partitionColumn):
self.__params["partitionColumn"] = partitionColumn

def getParams(self):
Expand Down
26 changes: 23 additions & 3 deletions tests/export_examples/export_odps_sink_demo.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
# coding=utf-8
import time
from aliyun.log import LogClient
from aliyun.log.odps_sink import AliyunMaxComputeSink
from aliyun.log.job import Export, ExportConfiguration
import json


def main():
def create_export():
project = "my-test-project"
sink = AliyunMaxComputeSink()
sink = AliyunMaxComputeSink([], [])
sink.setOdpsRolearn("my-test-roleArn")
sink.setOdpsEndpoint("my-test-endpoint")
sink.setOdpsTunnelEndpoint("my-test-tunnelendpoint")
Expand All @@ -31,5 +33,23 @@ def main():
print(response.get_request_id())
print(response.get_all_headers())


def getJobConfig(client, project, jobName):
res = client.get_export(project, jobName)
return res.body


def update_export():
# 本示例演示更新displayName参数的值
client = LogClient("region", "ak", "ak_key")
project = 'my-test-project'
jobName = 'my-odps-sink'
config = getJobConfig(client, project, jobName) # 获取任务的配置
config['displayName'] = config['displayName'] + 'new'
export = json.dumps(config)
client.update_export(project_name=project, job_name=jobName, export=export)
print('done')


if __name__ == "__main__":
main()
update_export()