示例#1
0
def _log(level, message, caller=None):
    """
    Print a message to the log. This method is usually wrapped by the above.

    :param int level: log level
    :param str message: log message
    :param str caller: name of function
    """
    if caller:
        caller = 'PythonLRMS.%s' % caller
    else:
        caller = 'PythonLRMS'
    arc.Logger(arc.Logger_getRootLogger(), caller).msg(level, message)
示例#2
0
    def __init__(self,
                 config_path=None,
                 log=sys.stdout,
                 log_level=LogLevels.INFO):
        """
        Create an object to interface with the ARC server.

        :param config_path: Path to config JSON file, or ``None`` to use the default settings
        :param log:         File-like object to write log messages to, or ``None`` to disable
                            logging. Use ``sys.stdout`` or ``sys.stderr`` to print messages
                            (default: ``sys.stdout``).
        :param log_level:   The level of detail logs should show (default: `LogLevels.INFO`).
                            See `LogLevels` for the available levels

        :raises InvalidConfigError: if config is not valid JSON or is otherwise invalid
        """

        self.logger = arc.Logger(arc.Logger_getRootLogger(), "jobsubmit")
        # Add a log destination if the user has provided one
        if log:
            log_dest = arc.LogStream(log)
            log_dest.setFormat(arc.ShortFormat)
            arc.Logger_getRootLogger().addDestination(log_dest)
            arc.Logger_getRootLogger().setThreshold(log_level.value)

        config_dict = {}
        if config_path:
            try:
                self.logger.msg(
                    arc.DEBUG,
                    "Using jasmin_arc config: {}".format(config_path))
                # Let errors reading file bubble to calling code
                with open(config_path) as config_file:
                    config_dict = json.load(config_file)

            # Catch JSON parsing errors
            except ValueError as e:
                raise InvalidConfigError(e.message)

        self.config = ConnectionConfig(config_dict, logger=self.logger)

        # Create jinja2 environment for loading JSDL template(s)
        self.env = Environment(loader=PackageLoader(__name__, TEMPLATES_DIR),
                               autoescape=select_autoescape(["xml"]))

        self.cached_user_config = None
示例#3
0
import arc
import time

logger = arc.Logger(arc.Logger_getRootLogger(), 'EchoService.py')

wsrf_rp_ns = "http://docs.oasis-open.org/wsrf/rp-2"
echo_ns = "http://www.nordugrid.org/schemas/echo"
import threading


class EchoService(object):
    def __init__(self, cfg):
        logger.msg(arc.INFO, "EchoService (python) constructor called")
        # get the response-prefix from the config XML
        self.prefix = str(cfg.Get('prefix'))
        # get the response-suffix from the config XML
        self.suffix = str(cfg.Get('suffix'))
        logger.msg(
            arc.DEBUG,
            "EchoService (python) has prefix %(prefix)s and suffix %(suffix)s"
            % {
                'prefix': self.prefix,
                'suffix': self.suffix
            })
        self.ssl_config = self.parse_ssl_config(cfg)
        thread_test = str(cfg.Get('ThreadTest'))
        if thread_test:
            threading.Thread(target=self.infinite, args=[thread_test]).start()

    def __del__(self):
        logger.msg(arc.INFO, "EchoService (python) destructor called")
示例#4
0
import arc
import sys

# Set up logging to stderr with level VERBOSE (a lot of output will be shown)
logstdout = arc.LogStream(sys.stdout)
logstdout.setFormat(arc.ShortFormat)
arc.Logger_getRootLogger().addDestination(logstdout)
arc.Logger_getRootLogger().setThreshold(arc.VERBOSE)
logger = arc.Logger(arc.Logger_getRootLogger(), "jobsubmit")

# UserConfig contains information on credentials and default services to use.
# This form of the constructor is necessary to initialise the local job list.
usercfg = arc.UserConfig("", "")

# Simple job description which outputs hostname to stdout
jobdescstring = "&(executable=/bin/hostname)(stdout=stdout)"

# Parse job description
jobdescs = arc.JobDescriptionList()
if not arc.JobDescription_Parse(jobdescstring, jobdescs):
    logger.msg(arc.ERROR, "Invalid job description")
    sys.exit(1)

# Use 'arc.JobDescription_ParseFromFile("helloworld.xrsl", jobdescs)'
# to parse job description from file.

# Use top-level NorduGrid information index to find resources
index = arc.Endpoint(
    "ldap://index1.nordugrid.org:2135/Mds-Vo-name=NorduGrid,o=grid",
    arc.Endpoint.REGISTRY, "org.nordugrid.ldapegiis")
services = arc.EndpointList(1, index)
示例#5
0
#! /usr/bin/env python

from __future__ import print_function

import arc

import sys
root_logger = arc.Logger_getRootLogger()
root_logger.addDestination(arc.LogStream(sys.stdout))
logger = arc.Logger(root_logger, "Test")

logger.msg(arc.INFO, "Creating a soap client")

cfg = arc.MCCConfig()
# cfg.AddPrivateKey('key.pem')
# cfg.AddCertificate('cert.pem')
# cfg.AddCAFile('ca.pem')

# s = arc.ClientSOAP(cfg, 'localhost', 60000, True, '/Echo')
s = arc.ClientSOAP(cfg, 'localhost', 60000, False, '/Echo')

logger.msg(arc.INFO, "Creating and sending request")
ns = arc.NS({'echo': 'http://www.nordugrid.org/schemas/echo'})
outpayload = arc.PayloadSOAP(ns)
outpayload.NewChild('echo:echo').NewChild('echo:say').Set('HELLO')

resp, status = s.process(outpayload)

if not status:
    logger.msg(arc.ERROR, "SOAP invocation failed")
elif not resp: