Esempio n. 1
0
 def __init__(self, context=None, verbose=0):
     self.ddConfig = DDConfig()
     self.name = "DDRestServer"
     if context:
         Controller.__init__(self, context, __file__)
     rest_service = Service()
     rest_service.rest = RestService()
     self.rest = rest_service.rest
     self.config = self.setConfig(base=self.name)
     print "+++ %s is loaded, supported mime_types:" % self.name
     print self.rest.supportTypes
Esempio n. 2
0
 def __init__(self,dbManager,dbsInst="",verbose=1):
     """
        Constructor which takes two arguments DBS instance and verbosity level.
        It initialize internal logger with own name and pass verbosity level to it.
        @type  dbsInst: string 
        @param dbsInst: name of the DBS instance, e.g. MCGlobal/Writer (default)
        @type verbose: boolean or integer
        @param verbose: verbosity level
        @rtype : none
        @return: none
     """
     self.ddConfig  = DDConfig()
     if not dbsInst:
        dbsInst=self.ddConfig.dbsprimary()
     self.dbsInstance = dbsInst
     self.verbose     = verbose
     self.html        = 0
     self.ddrules     = DDRules(self.verbose)
     self.dbManager   = dbManager
     self.initDBS(self.dbsInstance)
Esempio n. 3
0
class DDQueryMaker(): 
  """
      DDQueryMaker class
  """
  def __init__(self,dbManager,dbsInst="",verbose=1):
      """
         Constructor which takes two arguments DBS instance and verbosity level.
         It initialize internal logger with own name and pass verbosity level to it.
         @type  dbsInst: string 
         @param dbsInst: name of the DBS instance, e.g. MCGlobal/Writer (default)
         @type verbose: boolean or integer
         @param verbose: verbosity level
         @rtype : none
         @return: none
      """
      self.ddConfig  = DDConfig()
      if not dbsInst:
         dbsInst=self.ddConfig.dbsprimary()
      self.dbsInstance = dbsInst
      self.verbose     = verbose
      self.html        = 0
      self.ddrules     = DDRules(self.verbose)
      self.dbManager   = dbManager
      self.initDBS(self.dbsInstance)

  def initDBS(self,dbsInst,iface="dd"):
      """
         Set DBS instance to use at given time.
      """
      if not DBS_INST_URL.keys().count(dbsInst):
         msg = "Wrong DBS instance '%s'\n"%dbsInst
         msg+= "Available instances:\n"
         for dbs in self.dbsdls.keys():
             msg+= dbs+"\n"
         raise msg
      self.dbsInstance = dbsInst

  def closeConnection(self,con):
      # if SQLAlchemy uses pool for engine, then it should correctly handle all connections
      # and there is no needs to close it, since a new one will be taken from pool
      # but I can keep it commented out here and use this function everywhere to rollback
      # quickly.
#      con.close()
      return

  def connectToDB(self,dbsInstance,iface="dd"):
      con=""
      try:
          con = self.dbManager.connect(dbsInstance,iface)
      except:
         try:
             con = self.dbManager.connect(dbsInstance,iface)
         except:
             try:
                 # try second time, but sleep for 2 seconds before retry
                 time.sleep(2)
                 self.dbManager.clear()
                 con = self.dbManager.connect(dbsInstance,iface)
             except Exception, ex:
                 raise DbsDatabaseError(args=ex)
             pass
         pass
      return con
Esempio n. 4
0
       print "##### DD ERROR: Cannot determine SQLAlchemy version"
       sys.__stdout__.flush()
       traceback.print_exc()
#    if not (int(rel)>=0 and int(max)>=4 and int(min)>=5):
#       msg="##### DD ERROR: Wrong SQLAlchemy version='%s', DD depends on 0.4.5 and higher"%ver
#       sys.__stdout__.flush()
#       raise msg
checkSQLAlchemyVersion()
################################################################################################
# DBS1, CGI server
DEFAULT_URL = "http://cmsdbs.cern.ch/cms/prod/comp/DBS/CGIServer/prodquerytest3"
#
# DLS instances are: https://twiki.cern.ch/twiki/bin/view/CMS/DLS#DLS_instances
# DBS2 instances are: https://twiki.cern.ch/twiki/bin/view/CMS/CMS-DMS-DBS-2-instances
#
config=DDConfig()
DBSGLOBAL=config.dbsprimary()
#DBSGLOBAL="cms_dbs_prod_global"
dbAuth = DDAuthentication() 
print "\n+++ Initialize DBS instances:"
for dbs in dbAuth.dbsInstances():
    print dbs
print "\n+++ Primary DBS instance:",DBSGLOBAL
print

################################################################################################
def getDictOfSites():
    """
       Read DLS_INFO file (default name is dls.all) and construct dictionary of
       {DBS instance: list of DLS sites}
    """
Esempio n. 5
0
class DDRestServer(DDLogger, Controller):
    def __init__(self, context=None, verbose=0):
        self.ddConfig = DDConfig()
        self.name = "DDRestServer"
        if context:
            Controller.__init__(self, context, __file__)
        rest_service = Service()
        rest_service.rest = RestService()
        self.rest = rest_service.rest
        self.config = self.setConfig(base=self.name)
        print "+++ %s is loaded, supported mime_types:" % self.name
        print self.rest.supportTypes

    def readyToRun(self):
        opts = self.context.CmdLineArgs().opts
        self.baseUrl = opts.baseUrl
        self.rest._url = opts.baseUrl + "/services"
        self.rest._mUrl = self.baseUrl + "sitedb/Common/masthead"
        self.rest._fUrl = self.baseUrl + "sitedb/Common/footer"
        self.rest._dbs = self.ddConfig.dbsprimary()
        self.rest._host = self.ddConfig.url()
        dbsUrl = self.ddConfig.dbsUrl()
        dbsVer = self.ddConfig.dbsVer()
        dbsConfig = {"url": dbsUrl, "mode": "POST", "version": dbsVer, "retry": 2}
        self.rest._dbsApi = DbsApi(dbsConfig)
        print "+++ %s url %s" % (self.name, self.rest._url)
        print "+++ %s use DBS-url %s" % (self.name, dbsUrl)
        print "+++ %s use DBS-version %s" % (self.name, dbsVer)
        cherrypy.config.update({"request.dispatch": cherrypy.dispatch.MethodDispatcher()})

    def setConfig(self, base=""):
        # used thread_pool, queue_size parameters to tune up server performance
        # see discussion on http://amix.dk/blog/viewEntry/119
        cherrypy.server.thread_pool = 30
        cherrypy.server.socket_queue_size = 15
        mime_types = self.rest.supportTypes
        httpHeader = [
            ("Expires", time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(time.time() + 315360000))),
            ("Accept-Encoding", "gzip"),
            ("TE", "deflate, gzip, x-gzip, identity, trailer"),
            ("Cache-Control", "max-age=315360000"),
            ("Authorization", "Basic"),
        ]
        conf = {
            "/": {
                "request.dispatch": cherrypy.dispatch.MethodDispatcher(),
                "tools.staticdir.root": os.getcwd(),
                "tools.response_headers.on": True,
                "tools.etags.on": True,
                "tools.etags.autotags": True,
                "tools.response_headers.headers": [
                    ("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"),
                    ("Accept-Encoding", "gzip"),
                    ("TE", "deflate, gzip, x-gzip, identity, trailer"),
                    ("Cache-Control", "no-store, no-cache, must-revalidate,post-check=0, pre-check=0"),
                ],
            },
            "/images": {
                "tools.gzip.on": True,
                "tools.gzip.mime_types": mime_types,
                "tools.staticdir.on": True,
                "tools.staticdir.root": os.getcwd(),
                "tools.staticdir.dir": "images",
                "tools.response_headers.on": True,
                "tools.response_headers.headers": httpHeader,
            },
            "/rss": {"tools.staticdir.on": True, "tools.staticdir.dir": "rss"},
            "/css": {
                "tools.gzip.on": True,
                "tools.gzip.mime_types": mime_types,
                "tools.staticdir.on": True,
                "tools.staticdir.root": os.getcwd(),
                "tools.staticdir.dir": "css",
                "tools.response_headers.on": True,
                "tools.response_headers.headers": httpHeader,
            },
            "/js": {
                "tools.gzip.on": True,
                "tools.gzip.mime_types": mime_types,
                "tools.staticdir.on": True,
                "tools.staticdir.dir": "js",
                "tools.staticdir.content_types": {"js": "text/javascript"},
                "tools.response_headers.on": True,
                "tools.response_headers.headers": httpHeader,
            },
            "/WEBTOOLS": {
                "tools.gzip.on": True,
                "tools.gzip.mime_types": mime_types,
                "tools.staticdir.on": True,
                "tools.staticdir.dir": "WEBTOOLS",
                "tools.staticdir.content_types": {"js": "text/javascript", "": "text/javascript", "css": "text/css"},
                "tools.response_headers.on": True,
                "tools.response_headers.headers": httpHeader,
            },
            "/Common": {
                "tools.gzip.on": True,
                "tools.gzip.mime_types": mime_types,
                "tools.staticdir.on": True,
                "tools.staticdir.dir": "WEBTOOLS/Common",
                "tools.response_headers.on": True,
                "tools.response_headers.headers": httpHeader,
            },
            "/yui": {
                "tools.gzip.on": True,
                "tools.gzip.mime_types": mime_types,
                "tools.staticdir.on": True,
                "tools.staticdir.root": os.getcwd(),
                "tools.staticdir.dir": "yui",
                "tools.staticdir.content_types": {"js": "text/javascript"},
                "tools.response_headers.on": True,
                "tools.response_headers.headers": httpHeader,
            },
            "/YUI": {
                "tools.gzip.on": True,
                "tools.gzip.mime_types": mime_types,
                "tools.staticdir.on": True,
                "tools.staticdir.root": os.getcwd(),
                "tools.staticdir.dir": "YUI",
                "tools.staticdir.content_types": {"js": "text/javascript"},
                "tools.response_headers.on": True,
                "tools.response_headers.headers": httpHeader,
            },
        }
        if base:
            newConf = {}
            for key in conf.keys():
                newConf[key] = conf[key]
                if key == "/":
                    newKey = "/%s" % base.replace("/", "")
                else:
                    newKey = "/%s/%s" % (base.replace("/", ""), key.replace("/", ""))
                newConf[newKey] = conf[key]
            return newConf
        return conf