Ejemplo n.º 1
0
  def registerType( self, index, mapping ):
    """
    It register the type and index, if does not exists
    :param str index name of the index
    :param dict mapping mapping used to create the index.
    """

    all_index = "%s-*" % index

    if self.exists( all_index ):
      indexes = self.getIndexes()
      if indexes:
        actualindexName = generateFullIndexName( index )
        if self.exists( actualindexName ):
          self.log.info( "The index is exists:", actualindexName )
        else:
          result = self.createIndex( index, mapping )
          if not result['OK']:
            self.log.error( result['Message'] )
            return result
          self.log.info( "The index is created", actualindexName )
    else:
      # in that case no index exists
      result = self.createIndex( index, mapping )
      if not result['OK']:
        self.log.error( result['Message'] )
      else:
        return result
Ejemplo n.º 2
0
  def registerType(self, index, mapping, period=None):
    """
    It register the type and index, if does not exists

    :param str index: name of the index
    :param dict mapping: mapping used to create the index.
    :param str period: We can specify, which kind of indexes will be created.
                       Currently only daily and monthly indexes are supported.

    """

    all_index = "%s-*" % index

    if self.exists(all_index):
      indexes = self.getIndexes()
      if indexes:
        actualindexName = generateFullIndexName(index, period)
        if self.exists(actualindexName):
          self.log.info("The index is exists:", actualindexName)
        else:
          result = self.createIndex(index, mapping, period)
          if not result['OK']:
            self.log.error(result['Message'])
            return result
          self.log.info("The index is created", actualindexName)
    else:
      # in that case no index exists
      result = self.createIndex(index, mapping, period)
      if not result['OK']:
        self.log.error(result['Message'])
      else:
        return result
Ejemplo n.º 3
0
    def registerType(self, index, mapping, period=None):
        """
    It register the type and index, if does not exists

    :param str index: name of the index
    :param dict mapping: mapping used to create the index.
    :param str period: We can specify, which kind of indexes will be created. Currently only daily and monthly indexes are supported.
    
    """

        all_index = "%s-*" % index

        if self.exists(all_index):
            indexes = self.getIndexes()
            if indexes:
                actualindexName = generateFullIndexName(index, period)
                if self.exists(actualindexName):
                    self.log.info("The index is exists:", actualindexName)
                else:
                    result = self.createIndex(index, mapping, period)
                    if not result['OK']:
                        self.log.error(result['Message'])
                        return result
                    self.log.info("The index is created", actualindexName)
        else:
            # in that case no index exists
            result = self.createIndex(index, mapping, period)
            if not result['OK']:
                self.log.error(result['Message'])
            else:
                return result
Ejemplo n.º 4
0
  def setUp(self):
    self.elasticSearchDB = ElasticSearchDB(host=elHost,
                                           port=elPort,
                                           useSSL=False)
    result = generateFullIndexName('integrationtest')
    self.assertTrue(len(result) > len('integrationtest'))
    self.index_name = result

    result = self.elasticSearchDB.index(self.index_name, 'test', {"Color": "red",
                                                                  "quantity": 1,
                                                                  "Product": "a",
                                                                  "timestamp": 1458226213})
    self.assertTrue(result['OK'])
Ejemplo n.º 5
0
 def test_generateFullIndexName2(self):
   indexName = 'test'
   month = datetime.datetime.today().strftime("%Y-%m")
   expected = "%s-%s" % (indexName, month)
   result = generateFullIndexName(indexName, 'month')
   self.assertEqual(result, expected)
Ejemplo n.º 6
0
 def test_generateFullIndexName(self):
   indexName = 'test'
   today = datetime.datetime.today().strftime("%Y-%m-%d")
   expected = "%s-%s" % (indexName, today)
   result = generateFullIndexName(indexName)
   self.assertEqual(result, expected)
Ejemplo n.º 7
0
 def setUp(self):
     self.el = ElasticSearchDB(elHost, elPort)
     result = generateFullIndexName("integrationtest")
     self.assert_(len(result) > len("integrationtest"))
     self.index_name = result
Ejemplo n.º 8
0
 def test_deleteIndex(self):
     result = generateFullIndexName("integrationtest")
     res = self.el.deleteIndex(result)
     self.assert_(res["OK"])
     self.assertEqual(res["Value"], result)