Kasun Samarasinghe

16 papers B 4Journal 6Unranked 4
YearRankTypeTitle / Venue / Authors
2023 conf
SWAT4HCLS
Lydie Lane, Kasun Samarasinghe, Pierre-André Michel
2020 J jnl
Theor. Comput. Sci.
Pierre Leone, Kasun Samarasinghe, José D. P. Rolim
2020 J jnl
Nucleic Acids Res.
Monique Zahn-Zabal, Pierre-André Michel, Alain Gateau, Frédéric Nikitin, Mathieu Schaeffer, Estelle Audot, Pascale Gaudet, Paula Duek Roggli, Daniel Dinis Teixeira, Valentine Rech de Laval, Kasun Samarasinghe, Amos Bairoch, Lydie Lane
2019 ch.
Mission-Oriented Sensor Networks and Systems (1)
Pierre Leone, Kasun Samarasinghe
2016 J jnl
CoRR
Pierre Leone, Kasun Samarasinghe
2016 J jnl
Theor. Comput. Sci.
Pierre Leone, Kasun Samarasinghe
2016
Kasun Samarasinghe
2016 B conf
DCOSS
Pierre Leone, Kasun Samarasinghe
2016 conf
AINA Workshops
Kasun Samarasinghe, Ricardo Wehbe, Pierre Leone
2015 B conf
SECON
Kasun Samarasinghe, Pierre Leone
2015 J jnl
CoRR
Pierre Leone, Kasun Samarasinghe
2014 conf
SENSORNETS
Kasun Samarasinghe, Pierre Leone
2013 B conf
DCOSS
Orestis Evangelatos, Kasun Samarasinghe, José D. P. Rolim
2012 conf
MASS Workshops
Orestis Evangelatos, Kasun Samarasinghe, José D. P. Rolim
2012 B conf
ICPADS
Kasun Samarasinghe, Pierre Leone
2012 J jnl
SIGBED Rev.
Thiemo Voigt, Utz Roedig, Olaf Landsiedel, Kasun Samarasinghe, Mahesh Bogadi Shankar Prasad
redb/utils/push_to_elastic.py
← Index redb/utils/push_to_elastic.py python
import json
import os
#from redb.settings import elasticsearch as es
from elasticsearch import Elasticsearch
from dataclasses import asdict
from dotenv import load_dotenv

class Utils():
    """
    Utility class for pushing

    """
    @staticmethod
    def push_to_elastic(sample_dict):
        """
        Pushes the sample_dict to elastic search
        """
        load_dotenv()
        ELASTIC_ENDPOINT = os.getenv("ELASTIC_HOST")
        ELASTIC_ENFORCE_SSL = os.getenv("ELASTIC_ENFORCE_SSL", False) == "True"
        ELASTIC_USER = os.getenv("ELASTIC_USER")
        ELASTIC_PASSWORD = os.getenv("ELASTIC_PASSWORD")
        ELASTIC_BINARIES_COLLECTION = os.getenv(
            "ELASTIC_BINARIES_COLLECTION", "redb_test"
        )
        es = Elasticsearch(
            ELASTIC_ENDPOINT,
            verify_certs=ELASTIC_ENFORCE_SSL,
            basic_auth=(ELASTIC_USER, ELASTIC_PASSWORD),
            maxsize=20,
            retry_on_timeout=True,
            timeout=30,
        )

        try:
            dict_dump = json.dumps(sample_dict)
        except Exception as e:
            print(f"Error: {e}")
            return False
        elastic = es.index(index=ELASTIC_BINARIES_COLLECTION, body=dict_dump)
        return True
    
    def push_to_index(sample_dict, index_name):
        """
        Pushes the sample_dict to elastic search
        """
        load_dotenv()
        ELASTIC_ENDPOINT = os.getenv("ELASTIC_HOST")
        ELASTIC_ENFORCE_SSL = os.getenv("ELASTIC_ENFORCE_SSL", False) == "True"
        ELASTIC_USER = os.getenv("ELASTIC_USER")
        ELASTIC_PASSWORD = os.getenv("ELASTIC_PASSWORD")
        ELASTIC_BINARIES_COLLECTION = index_name
        
        es = Elasticsearch(
            ELASTIC_ENDPOINT,
            verify_certs=ELASTIC_ENFORCE_SSL,
            basic_auth=(ELASTIC_USER, ELASTIC_PASSWORD),
            maxsize=20,
            retry_on_timeout=True,
            timeout=30,
        )

        try:
            dict_dump = json.dumps(sample_dict)
        except Exception as e:
            print(f"Error: {e}")
            return False
        elastic = es.index(index=ELASTIC_BINARIES_COLLECTION, body=dict_dump)
        return True