Ejemplo n.º 1
0
    def __init__(self, appid='LHC_MD_ABP_ANALYSIS', clientid='BEAM PHYSICS',
                 source='all', loglevel=None):
        # Configure logging
        logging.basicConfig()
        self._log = logging.getLogger(__name__)
        if loglevel is not None:
            self._log.setLevel(loglevel)

        # Start JVM
        mgr = cmmnbuild_dep_manager.Manager()
        if not mgr.is_registered('pytimber'):
            mgr.install('pytimber')
        mgr.log.setLevel(logging.WARNING)
        mgr.start_jpype_jvm()

        # log4j config
        null = jpype.JPackage('org').apache.log4j.varia.NullAppender()
        jpype.JPackage('org').apache.log4j.BasicConfigurator.configure(null)

        # Data source preferences
        DataLocPrefs = (jpype.JPackage('cern').accsoft.cals.extr.domain
                        .core.datasource.DataLocationPreferences)
        loc = {'mdb': DataLocPrefs.MDB_PRO,
               'ldb': DataLocPrefs.LDB_PRO,
               'all': DataLocPrefs.MDB_AND_LDB_PRO}[source]

        ServiceBuilder = (jpype.JPackage('cern').accsoft.cals.extr.client
                          .service.ServiceBuilder)
        builder = ServiceBuilder.getInstance(appid, clientid, loc)
        self._md = builder.createMetaService()
        self._ts = builder.createTimeseriesService()
        self._FillService = FillService = builder.createLHCFillService()
        self.tree = Hierarchy('root', None, None, self._md)
Ejemplo n.º 2
0
 def run(self):
     if not self.no_jars:
         import cmmnbuild_dep_manager
         mgr = cmmnbuild_dep_manager.Manager()
         mgr.install('pytimber')
         print('registered pytimber with cmmnbuild_dep_manager')
     _install.run(self)
Ejemplo n.º 3
0
 def run(self):
     try:
         import cmmnbuild_dep_manager
         mgr = cmmnbuild_dep_manager.Manager()
         mgr.install('pytimber')
         print('registered pytimber with cmmnbuild_dep_manager')
     except ImportError:
         pass
     _install.run(self)
Ejemplo n.º 4
0
    def run(self):
        try:
            import pagestore
            import pip
            print('WARNING: removing standalone pagestore package')
            pip.main(['uninstall', 'pagestore', '-y'])
        except:
            pass

        if not self.no_jars:
            import cmmnbuild_dep_manager
            mgr = cmmnbuild_dep_manager.Manager()
            mgr.install('pytimber')
            print('registered pytimber with cmmnbuild_dep_manager')
        _install.run(self)
Ejemplo n.º 5
0
# -*- coding: utf-8 -*-
import os, re
from collections import namedtuple
import datetime

import numpy as np
import six

import cmmnbuild_dep_manager

# Use mgr.class_hints('LhcService')
# put deps in __init__.py
mgr = cmmnbuild_dep_manager.Manager('pylsa')
jpype = mgr.start_jpype_jvm()

cern = jpype.JPackage('cern')
org = jpype.JPackage('org')
java = jpype.JPackage('java')
System = java.lang.System

null = org.apache.log4j.varia.NullAppender()
org.apache.log4j.BasicConfigurator.configure(null)

ContextService = cern.lsa.client.ContextService
HyperCycleService = cern.lsa.client.HyperCycleService
ParameterService = cern.lsa.client.ParameterService
ServiceLocator = cern.lsa.client.ServiceLocator
SettingService = cern.lsa.client.SettingService
TrimService = cern.lsa.client.TrimService
LhcService = cern.lsa.client.LhcService
FidelService = cern.lsa.client.FidelService
Ejemplo n.º 6
0
    def __init__(self,
                 user=username,
                 keytab=keytab,
                 certs=certs,
                 loglevel=logging.ERROR):
        """
        Needs
           user: default user name
           keytab: default $HOME/.nxcals/keytab
           certs: default $HOME/.nxcals/nxcals_cacerts
        """

        # Configure logging
        logging.basicConfig()
        self._log = logging.getLogger(__name__)
        if loglevel is not None:
            self._log.setLevel(loglevel)

        # Setup keytab and certs
        self._keytab = None

        if os.path.isfile(keytab):
            self._keytab = keytab
        else:
            try:
                NXCals.create_keytab()
            except Exception as ex:
                print(ex)
                raise ValueError(f"Keytab file {keytab} could not be created")

        self._certs = None
        if os.path.isfile(certs):
            self._certs = certs
        else:
            try:
                NXCals.create_certs()
            except Exception as ex:
                print(ex)
                raise ValueError(
                    f"Certificate file {certs} could not be created")

        self._user = user

        # Start JVM and set basic hook
        import cmmnbuild_dep_manager

        self._mgr = cmmnbuild_dep_manager.Manager("pytimber", loglevel)
        self._jpype = self._mgr.start_jpype_jvm()
        self._org = self._jpype.JPackage("org")
        self._cern = self._jpype.JPackage("cern")
        self._java = self._jpype.java
        self._System = self._java.lang.System

        # spark config
        try:
            self.spark = self._get_spark()
        except self._jpype.JavaException as ex:
            print(ex.message())
            print(ex.stacktrace())
            raise ex

        # nxcals shortcuts
        self._builders = self._cern.nxcals.api.extraction.data.builders
        self._Variables = self._cern.nxcals.api.extraction.metadata.queries.Variables
        self._ServiceClientFactory = (
            self._cern.nxcals.api.extraction.metadata.ServiceClientFactory)

        # pytimber helpers
        self._SparkDataFrameConversions = (
            self._org.pytimber.utils.SparkDataFrameConversions)

        # nxcals services
        try:
            self._variableService = self._ServiceClientFactory.createVariableService(
            )
            self._entityService = self._ServiceClientFactory.createEntityService(
            )
        except TypeError:
            print("Possible problems with kerberos. Checking with keylist")
            os.system("klist")
Ejemplo n.º 7
0
import six
import logging

import jpype
import numpy as np
"""Latest version of the standalone jar is availale here:
http://abwww.cern.ch/ap/dist/accsoft/cals/accsoft-cals-extr-client/PRO/build/dist/accsoft-cals-extr-client-nodep.jar
"""

logging.basicConfig()
log = logging.getLogger(__name__)

try:
    # Try to get a lit of .jars from cmmnbuild_dep_manager.
    import cmmnbuild_dep_manager
    mgr = cmmnbuild_dep_manager.Manager()

    # During first installation with cmmnbuild_dep_manager some necessary jars
    # do not exist, so fall back to locally bundled .jar file in this case.
    if not mgr.is_registered("pytimber"):
        log.warn("pytimber is not registered with cmmnbuild_dep_manager "
                 "so falling back to bundled jar. Things may not work as "
                 "expected...")
        raise ImportError

    _jar = mgr.class_path()
except ImportError:
    # Could not import cmmnbuild_dep_manager -- it is probably not
    # installed. Fall back to using the locally bundled .jar file.
    _moddir = os.path.dirname(__file__)
    _jar = os.path.join(_moddir, 'jars', 'accsoft-cals-extr-client-nodep.jar')
Ejemplo n.º 8
0
    cmd = [
        env_py, '-m', 'pip', 'install', '--upgrade', 'pip',
        '--prefix={}'.format(install_loc)
    ]
    run_w_stream(cmd)

    env = {
        'PIP_INDEX_URL':
        'http://acc-py-repo.cern.ch:8081/repository/vr-py-releases/simple',
        'PIP_TRUSTED_HOST': 'acc-py-repo.cern.ch'
    }
    cmd = [env_py, '-m', 'pip', 'install', 'pytimber==3.*']
    run_w_stream(cmd, env)

    print('Resolving JARs for PyTimber')
    import cmmnbuild_dep_manager
    cmmnbuild_dep_manager.Manager().resolve()
    print('All done!')
else:
    print('Using existing environment in {}'.format(install_loc))

import pytimber
if not pytimber.__version__.startswith('3.'):
    print("Error installing newer version of PyTimber. " +
          "You have version {}. ".format(pytimber.__version__) +
          "Please try restarting the kernel and re-running.")

# Tidy up since this is being run in the active kernel environment
for local_before in set(locals()) - _locals_before:
    locals().pop(local_before)
locals().pop('_local_before', None)
Ejemplo n.º 9
0
    def __init__(
        self,
        appid="PYTIMBER3",
        clientid="PYTIMBER3",
        source="all",
        loglevel=None,
    ):
        # Configure logging
        logging.basicConfig()
        self._log = logging.getLogger(__name__)
        if loglevel is not None:
            self._log.setLevel(loglevel)

        # Start JVM
        mgr = cmmnbuild_dep_manager.Manager("pytimber")
        mgr.start_jpype_jvm()
        self._mgr = mgr

        # log4j config
        null = jpype.JPackage("org").apache.log4j.varia.NullAppender()
        jpype.JPackage("org").apache.log4j.BasicConfigurator.configure(null)

        self._source = source

        if source == "nxcals":
            check_kerberos()
            self._System = jpype.java.lang.System
            self._System.setProperty(
                "service.url",
                "https://cs-ccr-nxcals6.cern.ch:19093,https://cs-ccr-nxcals7.cern.ch:19093,https://cs-ccr-nxcals8.cern.ch:19093",
            )
            ServiceBuilder = jpype.JPackage(
                "cern").nxcals.api.backport.client.service.ServiceBuilder
            builder = ServiceBuilder.getInstance()
            self._md = builder.createMetaService()
            self._ts = builder.createTimeseriesService()
            self._FillService = builder.createLHCFillService()
            self._VariableDataType = jpype.JPackage(
                "cern"
            ).nxcals.api.backport.domain.core.constants.VariableDataType
        else:
            # Data source preferences
            DataLocPrefs = jpype.JPackage(
                "cern"
            ).accsoft.cals.extr.domain.core.datasource.DataLocationPreferences
            loc = {
                "mdb": DataLocPrefs.MDB_PRO,
                "ldb": DataLocPrefs.LDB_PRO,
                "all": DataLocPrefs.MDB_AND_LDB_PRO,
            }[source]

            ServiceBuilder = jpype.JPackage(
                "cern").accsoft.cals.extr.client.service.ServiceBuilder
            builder = ServiceBuilder.getInstance(appid, clientid, loc)
            self._builder = builder
            self._md = builder.createMetaService()
            self._ts = builder.createTimeseriesService()
            self._FillService = builder.createLHCFillService()
            self.tree = Hierarchy("root", None, None, self._md)
            self._VariableDataType = jpype.JPackage(
                "cern"
            ).accsoft.cals.extr.domain.core.constants.VariableDataType