Exemplo n.º 1
0
    def setup(self):
        """Create an SQL database from the all_errors.json generated by production"""

        self.timestamp = time.time()

        if self.data_location:
            data_location = self.data_location
        else:
            data_location = serverconfig.all_errors_path()

        # Store everything into an SQL database for fast retrival

        if isinstance(data_location, str) and data_location.endswith('.db') \
                and os.path.exists(data_location):
            self.conn = sqlite3.connect(data_location, check_same_thread=False)
            curs = self.conn.cursor()
            self.curs = curs

        else:
            self.conn = sqlite3.connect(':memory:', check_same_thread=False)
            curs = self.conn.cursor()
            self.curs = curs

            errorutils.create_table(self)
            errorutils.add_to_database(self, data_location)

        self.set_all_lists()
        self.readiness = [
            sitereadiness.site_readiness(site) for site in self.info[3]
        ]

        if not self.data_location:
            current_workflows = self.return_workflows()

            prep_ids = {
                self.get_workflow(wf).get_prep_id()
                for wf in current_workflows
            }

            other_workflows = sum([self.get_prepid(prep_id).get_workflows() \
                                       for prep_id in prep_ids], [])

            errorutils.add_to_database(self, [new for new in other_workflows \
                                                  if new not in current_workflows])
            self.set_all_lists()
            current_workflows = self.return_workflows()

            # If all ACDCs are to be shown, include the ones with zero errors like this
            if serverconfig.config_dict().get('include_all_acdcs'):
                self.allsteps.extend(['/%s/' % zero for zero in other_workflows \
                                          if zero not in current_workflows])
                self.allsteps.sort()

            self.readiness = [
                sitereadiness.site_readiness(site) for site in self.info[3]
            ]

        self.connection_log('opened')
Exemplo n.º 2
0
 def test_site_readiness(self):
     for site, stat, drain in sr.i_site_readiness():
         self.assertNotEqual(sr.site_readiness(site), 'none',
                             'Site not found: %s' % site)
         self.assertEqual(sr.site_readiness(site), stat,
                          'Inconsistent result: %s' % site)
         self.assertEqual(stat in ['green', 'yellow', 'red'], True,
                          'Status is not valid: %s' % site)
         self.assertEqual(drain in ['enabled', 'disabled', 'drain', 'test'],
                          True, 'Drain status is not valid: %s' % site)
Exemplo n.º 3
0
 def test_site_readiness(self):
     for site, stat, drain in sr.i_site_readiness():
         self.assertNotEqual(sr.site_readiness(site), 'none',
                             'Site not found: %s' % site)
         self.assertEqual(sr.site_readiness(site), stat,
                          'Inconsistent result: %s' % site)
         self.assertEqual(stat in ['green', 'yellow', 'red'], True,
                          'Status is not valid: %s' % site)
         self.assertEqual(drain in ['enabled', 'disabled', 'drain', 'test'], True,
                          'Drain status is not valid: %s' % site)
Exemplo n.º 4
0
    def setup(self):
        """Create an SQL database from the all_errors.json generated by production"""

        self.timestamp = time.time()

        if self.data_location:
            data_location = self.data_location
        else:
            data_location = serverconfig.all_errors_path()

        # Store everything into an SQL database for fast retrival

        if isinstance(data_location, str) and data_location.endswith('.db') \
                and os.path.exists(data_location):
            self.conn = sqlite3.connect(data_location, check_same_thread=False)
            curs = self.conn.cursor()
            self.curs = curs

        else:
            self.conn = sqlite3.connect(':memory:', check_same_thread=False)
            curs = self.conn.cursor()
            self.curs = curs

            errorutils.create_table(self)
            errorutils.add_to_database(self, data_location)


        self.set_all_lists()
        self.readiness = [sitereadiness.site_readiness(site) for site in self.info[3]]

        if not self.data_location:
            current_workflows = self.return_workflows()

            prep_ids = set([self.get_workflow(wf).get_prep_id() for wf in current_workflows])

            other_workflows = sum([self.get_prepid(prep_id).get_workflows() \
                                       for prep_id in prep_ids], [])

            errorutils.add_to_database(self, [new for new in other_workflows \
                                                  if new not in current_workflows])
            self.set_all_lists()
            current_workflows = self.return_workflows()

            # If all ACDCs are to be shown, include the ones with zero errors like this
            if serverconfig.config_dict().get('include_all_acdcs'):
                self.allsteps.extend(['/%s/' % zero for zero in other_workflows \
                                          if zero not in current_workflows])
                self.allsteps.sort()

            self.readiness = [sitereadiness.site_readiness(site) for site in self.info[3]]

        self.connection_log('opened')
    def __call__(self , good_sites={} , bad_sites={} , wf=None , tsk=None ):
        """
        returns the prediction of the model for the input good/bad site errors
        :param dict good_sites: map of good sites and number of failed jobs in eash site, like what is provided by 'actionhistory' in old-console
        :param dict bad_sites: map of bad sites and number of failed jobs in eash site, like what is provided by 'actionhistory' in old-console
        """
        if wf :
            wfinfo = workflowinfo.WorkflowInfo( wf )
            errors = wfinfo.get_errors()[ tsk ]
            for err in errors :
                try:
                    a = int(err)
                except :
                    print( "error %s skipped" % err )
                    continue
                for site in errors[err] :
                    stat = sitereadiness.site_readiness( site )
                    if stat == 'green' :
                        good_sites.setdefault( err , {} )[ site ] = errors[err][site]
                    else:
                        bad_sites.setdefault( err , {} )[ site ] = errors[err][site]
            #print good_sites
            #print bad_sites

        self.Task.normalize_errors( good_sites , bad_sites , TiersOnly=self.TiersOnly )
        prediction = self.model.predict( np.array( [ self.Task.Get2DArrayOfErrors() ] ) )
        PRED = str(prediction)
        if self.IsBinary:
            PRED = self.all_actions[ prediction[0][0] > 0.5 ]
        self.Prediction.SetValues( PRED , "" , "" )
        return self.Prediction
Exemplo n.º 6
0
def add_to_database(curs, data_location):  # pylint: disable=too-complex
    """Add data from a file to a central database through the passed cursor

    :param sqlite3.Cursor curs: is the cursor to the database
    :param data_location: If a string, this
         is the location of the file
         or url of data to add to the database.
         This should be in JSON format, and if a local file does not exist,
         a url will be assumed. If the url is invalid,
         an empty database will be returned.
         If a list, it's a list of status to get workflows from wmstats.
    :type data_location: str or list
    """

    indict = get_list_info(data_location) \
        if isinstance(data_location, list) else \
        (open_location(data_location) or {})

    number_added = 0

    for stepname, errorcodes in indict.items():
        if 'LogCollect' in stepname or 'Cleanup' in stepname:
            continue

        for errorcode, sitenames in errorcodes.items():
            if errorcode == 'NotReported':
                errorcode = '-1'

            elif not re.match(r'\d+', errorcode):
                continue

            for sitename, numbererrors in sitenames.items():
                numbererrors = numbererrors or int(errorcode == '-1')

                if numbererrors:
                    full_key = '_'.join([stepname, sitename, errorcode])
                    if not list(
                            curs.execute(
                                'SELECT EXISTS(SELECT 1 FROM workflows WHERE fullkey=? LIMIT 1)',
                                (full_key, )))[0][0]:
                        number_added += 1
                        curs.execute(
                            'INSERT INTO workflows VALUES (?,?,?,?,?,?)',
                            (full_key, stepname, errorcode, sitename,
                             numbererrors,
                             sitereadiness.site_readiness(sitename)))

    # This is to prevent the ErrorInfo objects from locking the database
    if 'conn' in dir(curs):
        curs.conn.commit()

    if number_added:
        cherrypy.log('Number of points added to the database: %i' %
                     number_added)
Exemplo n.º 7
0
def add_to_database(curs, data_location): # pylint: disable=too-complex
    """Add data from a file to a central database through the passed cursor

    :param sqlite3.Cursor curs: is the cursor to the database
    :param data_location: If a string, this
         is the location of the file
         or url of data to add to the database.
         This should be in JSON format, and if a local file does not exist,
         a url will be assumed. If the url is invalid,
         an empty database will be returned.
         If a list, it's a list of status to get workflows from wmstats.
    :type data_location: str or list
    """

    indict = get_list_info(data_location) \
        if isinstance(data_location, list) else \
        (open_location(data_location) or {})

    number_added = 0

    for stepname, errorcodes in indict.items():
        if 'LogCollect' in stepname or 'Cleanup' in stepname:
            continue

        for errorcode, sitenames in errorcodes.items():
            if errorcode == 'NotReported':
                errorcode = '-1'

            elif not re.match(r'\d+', errorcode):
                continue

            for sitename, numbererrors in sitenames.items():
                numbererrors = numbererrors or int(errorcode == '-1')

                if numbererrors:
                    full_key = '_'.join([stepname, sitename, errorcode])
                    if not list(curs.execute(
                            'SELECT EXISTS(SELECT 1 FROM workflows WHERE fullkey=? LIMIT 1)',
                            (full_key,)))[0][0]:
                        number_added += 1
                        curs.execute('INSERT INTO workflows VALUES (?,?,?,?,?,?)',
                                     (full_key, stepname, errorcode,
                                      sitename, numbererrors,
                                      sitereadiness.site_readiness(sitename)))

    # This is to prevent the ErrorInfo objects from locking the database
    if 'conn' in dir(curs):
        curs.conn.commit()

    if number_added:
        cherrypy.log('Number of points added to the database: %i' % number_added)
Exemplo n.º 8
0
 def test_bad_site(self):
     self.assertEqual(sr.site_readiness('not_a_site'), 'none',
                      'Bad return on fake site')
     self.assertEqual(sr.site_drain_status('not_a_site'), 'none',
                      'Bad return on fake site')
Exemplo n.º 9
0
 def test_bad_site(self):
     self.assertEqual(sr.site_readiness('not_a_site'), 'none',
                      'Bad return on fake site')
     self.assertEqual(sr.site_drain_status('not_a_site'), 'none',
                      'Bad return on fake site')