Skip to content

Commit

Permalink
fix issue #46
Browse files Browse the repository at this point in the history
  • Loading branch information
wjo1212 committed Jan 22, 2018
1 parent b43d416 commit cbf1d12
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
10 changes: 7 additions & 3 deletions aliyun/log/logclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def get_logstore(self, project_name, logstore_name):
(resp, header) = self._send("GET", project_name, None, resource, params, headers)
return GetLogStoreResponse(resp, header)

def update_logstore(self, project_name, logstore_name, ttl, shard_count):
def update_logstore(self, project_name, logstore_name, ttl, shard_count=None):
"""
update the logstore meta info
Unsuccessful opertaion will cause an LogException.
Expand All @@ -754,7 +754,7 @@ def update_logstore(self, project_name, logstore_name, ttl, shard_count):
:param ttl: the life cycle of log in the logstore in days
:type shard_count: int
:param shard_count: the shard count of the logstore to create
:param shard_count: deprecated, the shard count could only be updated by split & merge
:return: UpdateLogStoreResponse
Expand All @@ -765,7 +765,7 @@ def update_logstore(self, project_name, logstore_name, ttl, shard_count):

params = {}
resource = "/logstores/" + logstore_name
body = {"logstoreName": logstore_name, "ttl": int(ttl), "shardCount": int(shard_count)}
body = {"logstoreName": logstore_name, "ttl": int(ttl), "enableWebTracking": True}
body_str = six.b(json.dumps(body))
(resp, header) = self._send("PUT", project_name, body_str, resource, params, headers)
return UpdateLogStoreResponse(header, resp)
Expand Down Expand Up @@ -1011,6 +1011,10 @@ def create_logtail_config(self, project_name, config_detail):
:raise: LogException
"""

if config_detail.logstore_name:
# try to verify if the logstore exists or not.
self.get_logstore(project_name, config_detail.logstore_name)

headers = {}
params = {}
resource = "/configs"
Expand Down
17 changes: 12 additions & 5 deletions aliyun/log/logtail_config_detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@
import warnings
from enum import Enum
from .logexception import LogException
import logging

__all__ = ['SeperatorFileConfigDetail', 'SimpleFileConfigDetail', 'FullRegFileConfigDetail',
'JsonFileConfigDetail', 'ApsaraFileConfigDetail', 'SyslogConfigDetail',
'LogtailConfigGenerator', 'CommonRegLogConfigDetail']

logger = logging.getLogger(__name__)


class LogtailInputType(Enum):
FILE = 'file'
Expand Down Expand Up @@ -76,7 +79,7 @@ class LogtailConfigDetail(object):

def __init__(self, config_name, logstore_name, endpoint, log_path, file_pattern, log_begin_regex, topic_format,
filter_keys, filter_keys_reg, logSample='', log_type='common_reg_log', **extended_items):
warnings.warn("aliyun.log.LogtailConfigDetail is deprecated and will be removed in future version.")
logger.warning("aliyun.log.LogtailConfigDetail is deprecated and will be removed in future version.")

self.config_name = config_name
self.logstore_name = logstore_name
Expand All @@ -102,7 +105,7 @@ def set_last_modify_time(self, last_modify_time):

@staticmethod
def from_json(json_value):
warnings.warn("aliyun.log.LogtailConfigDetail is deprecated and will be removed in future version.")
logger.warning("aliyun.log.LogtailConfigDetail is deprecated and will be removed in future version.")
return LogtailConfigHelper.generate_logtail_config(json_value)


Expand Down Expand Up @@ -161,7 +164,7 @@ def __init__(self, config_name, logstore_name, endpoint, log_path, file_pattern,
log_parse_regex, reg_keys,
topic_format="none", filter_keys=None, filter_keys_reg=None, logSample='',
log_type='common_reg_log', **extended_items):
warnings.warn("aliyun.log.CommonRegLogConfigDetail is deprecated and will be removed in future version."
logger.warning("aliyun.log.CommonRegLogConfigDetail is deprecated and will be removed in future version."
"Use ConfigDetailBase based class instead")

if filter_keys is None:
Expand Down Expand Up @@ -237,7 +240,7 @@ class ApsaraLogConfigDetail(LogtailConfigDetail):
def __init__(self, config_name, logstore_name, endpoint, log_path, file_pattern,
log_begin_regex=r'\[\d+-\d+-\d+ \d+:\d+:\d+\.\d+.*', topic_format="none", filter_keys=None,
filter_keys_reg=None, logSample='', **extended_items):
warnings.warn("aliyun.log.ApsaraLogConfigDetail is deprecated and will be removed in future version. "
logger.warning("aliyun.log.ApsaraLogConfigDetail is deprecated and will be removed in future version. "
"Use ConfigDetailBase based class instead")

if filter_keys_reg is None:
Expand Down Expand Up @@ -343,7 +346,7 @@ def generate_logtail_config(json_value):
:param json_value:
:return:
"""
warnings.warn("aliyun.log.LogtailConfigHelper is deprecated and will be removed in future version."
logger.warning("aliyun.log.LogtailConfigHelper is deprecated and will be removed in future version."
"Use LogtailConfigGenerator instead")

if json_value['inputDetail']['logType'] == 'apsara_log':
Expand Down Expand Up @@ -379,6 +382,10 @@ def __init__(self, logstoreName, configName, inputType, createTime=None, modifyT
if k not in self.value["inputDetail"]:
self.value["inputDetail"][k] = v

@property
def logstore_name(self):
return self.value["outputDetail"]["logstoreName"]

def __clean_up_non_items(self):
none_items = [k for k, v in self.value.items() if v is None]
for k in none_items:
Expand Down
2 changes: 1 addition & 1 deletion aliyun/log/version.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '0.6.16'
__version__ = '0.6.17'
USER_AGENT = 'log-python-sdk-v-' + __version__
API_VERSION = '0.6.0'

Expand Down

0 comments on commit cbf1d12

Please sign in to comment.