# $SnapHashLicense:
#
# SnapLogic - Open source data services
#
# Copyright (C) 2008 - 2009, SnapLogic, Inc. All rights reserved.
#
# See http://www.snaplogic.org for more information about
# the SnapLogic project.
#
# This program is free software, distributed under the terms of
# the GNU General Public License Version 2. See the LEGAL file
# at the top of the source tree.
#
# "SnapLogic" is a trademark of SnapLogic, Inc.
#
#
# $
# $Id: __init__.py 9868 2009-11-21 17:50:45Z dhiraj $
""" The Component Container package """
from snaplogic.common import snap_log,uri_prefix,headers,snap_http_lib
from snaplogic import snapi_base
from snaplogic.snapi_base.exceptions import SnapiHttpException
my_process_uri = None
"URI of this process."
config = None
logger = None
log = None
elog = None
rlog = None
log_level = None
stats = None
stats_group = None
cc_token = None
PLACE_HOLDER_CC_TOKEN = "99999"
cc_name = None
"""Name given to the CC."""
cc_username = None
"""User ID used in the credentials provided to the CC."""
server_uri = None
"""Main process server's official URI."""
def init_loggers(cc_name, log_dir, level, to_console, disable_logging, max_log_size, log_backup_count):
# Initialize log
global logger, log, elog, rlog, log_level
logger = snap_log.SnapLog(cc_name, log_dir, to_console, disable_logging, level, max_log_size, log_backup_count)
(log, elog, rlog) = logger.make_specific_loggers(snap_log.LOG_CC)
log_level = level
def is_my_server_uri(target_uri):
"""
Check if the URI specified points to my server.
@param target_uri: URI to be checked.
@type target_uri: str
@return: True if URI does belong to my server, else False
@rtype: bool
"""
if target_uri.startswith('/'):
# Got a relative URI here.
return True
u = snap_http_lib.concat_paths(server_uri, uri_prefix.URI_CHECK)
custom_hdr = {}
# Never send None value in header, it gets stringified to the string "None"
if cc_token is not None:
custom_hdr[headers.CC_TOKEN_HEADER] = cc_token
else:
custom_hdr[headers.CC_TOKEN_HEADER] = PLACE_HOLDER_CC_TOKEN
if cc_username is not None:
custom_hdr[headers.INVOKER_HEADER] = cc_username
try:
resp = snapi_base.send_req("POST", u, target_uri, custom_hdr)
except SnapiHttpException, e:
if e.status == 404:
return False
else:
raise
return True
|