def on_message(client, userdata, message):
        LOG.info('MQTT: ' + str(message.payload.decode("utf-8")))
        y = json.loads(str(message.payload.decode("utf-8")))
        sub_topics = str(message.topic).split('/')[1:-1]
        while True:
                LOG.info('Try insertion of message: ' + str(message.payload.decode("utf-8")) + ' in GridDB...')
                try:
                        conInfo = griddb.ContainerInfo("home-"+sub_topics[0]+"_device-"+sub_topics[1],
                                [["timestamp", griddb.Type.TIMESTAMP],
                                #["timestamp2", griddb.Type.TIMESTAMP],
                                ["label", griddb.Type.STRING],
                                ["value", griddb.Type.STRING]],
                                griddb.ContainerType.TIME_SERIES, True)

                        col = gridstore.put_container(conInfo)
                        col.set_auto_commit(True)
                        #now = datetime.datetime.utcnow(), str(y["device_id"])
                        r = col.put([datetime.utcfromtimestamp(y["timestamp"]), str(y["label"]), str(y["value"])])
                        LOG.info("GridDB reply: " + str(r) + '.')
                        break
                except:
                        LOG.error("Error during update GridDB cluster.")
Ejemplo n.º 2
0
argv = sys.argv

NumContainer = 100
NumRow = 100

try:
    store = factory.get_store(host=argv[1],
                              port=int(argv[2]),
                              cluster_name=argv[3],
                              username=argv[4],
                              password=argv[5])

    for i in range(NumContainer):
        conInfo = griddb.ContainerInfo(
            "container" + str(i),
            [["name", griddb.Type.STRING], ["status", griddb.Type.BOOL],
             ["count", griddb.Type.LONG]], griddb.ContainerType.COLLECTION,
            True)
        col = store.put_container(conInfo)

    print("[MultiPut S]")

    containerEntry = {}
    collectionListRows = []
    for i in range(NumContainer):
        for j in range(NumRow):
            collectionListRows.append(["name" + str(j), True, j])
        containerEntry.update({"container" + str(i): collectionListRows})
    store.multi_put(containerEntry)

    print("[MultiPut E]")
Ejemplo n.º 3
0
factory = griddb.StoreFactory.get_instance()

argv = sys.argv

#Get GridStore object
gridstore = factory.get_store(host=argv[1],
                              port=int(argv[2]),
                              cluster_name=argv[3],
                              username=argv[4],
                              password=argv[5])

#Create TimeSeries
conInfo = griddb.ContainerInfo(
    "point01",
    [["timestamp", griddb.GS_TYPE_TIMESTAMP], ["active", griddb.GS_TYPE_BOOL],
     ["voltage", griddb.GS_TYPE_DOUBLE]], griddb.GS_CONTAINER_TIME_SERIES,
    True)
ts = gridstore.put_container(conInfo)

#Put row to timeseries with current timestamp
now = datetime.datetime.utcnow()
ts.put([now, False, 100])

#Create normal query for range of timestamp from 6 hours ago to now
query = ts.query("select * where timestamp > TIMESTAMPADD(HOUR, NOW(), -6)")
rs = query.fetch()

#Get result
while rs.has_next():
    data = rs.next()
Ejemplo n.º 4
0
    # Get GridStore object
    gridstore = factory.get_store(host=argv[1],
                                  port=int(argv[2]),
                                  cluster_name=argv[3],
                                  username=argv[4],
                                  password=argv[5])

    # When operations such as container creation and acquisition are performed, it is connected to the cluster.
    gridstore.get_container("containerName")
    print("Connect to Cluster")

    conInfo = griddb.ContainerInfo(
        name=containerName,
        column_info_list=[["id", griddb.Type.INTEGER],
                          ["productName", griddb.Type.STRING],
                          ["count", griddb.Type.INTEGER]],
        type=griddb.ContainerType.COLLECTION,
        row_key=True)

    col = gridstore.put_container(conInfo)
    print("Sample data generation: Create Collection name=", containerName)

    # Register multiple rows
    rowList = []
    for i in range(0, rowCount):
        rowList.append([i, nameList[i], numberList[i]])
    col.multi_put(rowList)
    print("Sample data generation: Put Rows count=", rowCount)

    # Delete a row
Ejemplo n.º 5
0
    # Get GridStore object
    gridstore = factory.get_store(host=argv[1],
                                  port=int(argv[2]),
                                  cluster_name=argv[3],
                                  username=argv[4],
                                  password=argv[5])

    # When operations such as container creation and acquisition are performed, it is connected to the cluster.
    gridstore.get_container("containerName")
    print("Connect to Cluster")

    # Create Collection
    conInfo = griddb.ContainerInfo(
        name="SamplePython_collection1",
        column_info_list=[["id", griddb.Type.INTEGER],
                          ["productName", griddb.Type.STRING],
                          ["columnInfo", griddb.Type.INTEGER]],
        type=griddb.ContainerType.COLLECTION,
        row_key=True)
    col = gridstore.put_container(conInfo)
    print("Create Collection name=SamplePython_collection1")
    print("success!")

except griddb.GSException as e:
    for i in range(e.get_error_stack_size()):
        print("[", i, "]")
        print(e.get_error_code(i))
        print(e.get_location(i))
        print(e.get_message(i))
Ejemplo n.º 6
0
import datetime

factory = griddb.StoreFactory.get_instance()

argv = sys.argv

#Get GridStore object
gridstore = factory.get_store(host=argv[1],
                              port=int(argv[2]),
                              cluster_name=argv[3],
                              username=argv[4],
                              password=argv[5])

#Create TimeSeries
conInfo = griddb.ContainerInfo(
    "point01", [["timestamp", griddb.Type.TIMESTAMP],
                ["active", griddb.Type.BOOL], ["voltage", griddb.Type.DOUBLE]],
    griddb.ContainerType.TIME_SERIES, True)
ts = gridstore.put_container(conInfo)

#Put row to timeseries with current timestamp
now = datetime.datetime.utcnow()
ts.put([now, False, 100])

#Create normal query for range of timestamp from 6 hours ago to now
query = ts.query("select * where timestamp > TIMESTAMPADD(HOUR, NOW(), -6)")
rs = query.fetch()

#Get result
while rs.has_next():
    data = rs.next()
    timestamp = str(data[0])
Ejemplo n.º 7
0
    # Provide the necessary arguments
    gridstore = factory.get_store(host=argv[1],
                                  port=int(argv[2]),
                                  cluster_name=argv[3],
                                  username=argv[4],
                                  password=argv[5])

    nobelprize_container = "nobelprize_1901"

    nobelprize_data.info()

    # Create Collection circuits
    nobelprize_containerInfo = griddb.ContainerInfo(
        nobelprize_container,
        [["ID", griddb.Type.INTEGER], ["year", griddb.Type.INTEGER],
         ["category", griddb.Type.STRING], ["prize", griddb.Type.STRING],
         ["prize_share", griddb.Type.STRING],
         ["laureate_id", griddb.Type.INTEGER],
         ["laureate_type", griddb.Type.STRING], ["sex", griddb.Type.STRING]],
        griddb.ContainerType.COLLECTION, True)

    nobelprize_columns = gridstore.put_container(nobelprize_containerInfo)

    print("Container created and columns added")

    # Put rows
    # Define the data frames
    nobelprize_columns.put_rows(nobelprize_data)

    print("Data Inserted using the DataFrame")

except griddb.GSException as e:
Ejemplo n.º 8
0
conInfo = griddb.ContainerInfo("Phishing Websites",
                    [              
                     ["having_IP_Address", griddb.Type.INTEGER],
                     ["URL_Length", griddb.Type.INTEGER],
                     ["Shortining_Service", griddb.Type.INTEGER],
                     ["having_At_Symbol", griddb.Type.INTEGER],
                     ["double_slash_redirecting", griddb.Type.INTEGER],
                     ["Prefix_Suffix", griddb.Type.INTEGER],
                     ["having_Sub_Domain", griddb.Type.INTEGER],
                     ["SSLfinal_State", griddb.Type.INTEGER],
                     ["Domain_registeration_length", griddb.Type.INTEGER],
                     ["Favicon", griddb.Type.INTEGER],
                     ["port", griddb.Type.INTEGER],
                     ["HTTPS_token", griddb.Type.INTEGER],
                     ["Request_URL", griddb.Type.INTEGER],
                     ["URL_of_Anchor", griddb.Type.INTEGER],
                     ["Links_in_tags", griddb.Type.INTEGER],
                     ["SFH", griddb.Type.INTEGER],
                     ["Submitting_to_email", griddb.Type.INTEGER],
                     ["Abnormal_URL", griddb.Type.INTEGER],
                     ["Redirect", griddb.Type.INTEGER],
                     ["on_mouseover", griddb.Type.INTEGER],
                     ["RightClick", griddb.Type.INTEGER],
                     ["popUpWidnow", griddb.Type.INTEGER],
                     ["Iframe", griddb.Type.INTEGER],
                     ["age_of_domain", griddb.Type.INTEGER],
                     ["DNSRecord", griddb.Type.INTEGER],
                     ["web_traffic", griddb.Type.INTEGER],
                     ["Page_Rank", griddb.Type.INTEGER],
                     ["Google_Index", griddb.Type.INTEGER],
                     ["Links_pointing_to_page", griddb.Type.INTEGER],
                     ["Statistical_report", griddb.Type.INTEGER],
                     ["Result", griddb.Type.INTEGER],                    
                    ],
                    griddb.ContainerType.COLLECTION, True)
Ejemplo n.º 9
0
factory = griddb.StoreFactory.get_instance()
try:
    # Get GridStore object
    gridstore = factory.get_store(host='10.10.10.100',
                                  port=250,
                                  cluster_name='default',
                                  username='******',
                                  password='******')

    # Create Collection
    containerName = "Crypto_Data_Container"
    crypto_container = griddb.ContainerInfo(
        containerName,
        [["symbol", griddb.Type.STRING], ["priceChange", griddb.Type.FLOAT],
         ["priceChangePercent", griddb.Type.FLOAT],
         ["weightedAvgPrice", griddb.Type.FLOAT],
         ["prevClosePrice", griddb.Type.FLOAT],
         ["lastPrice", griddb.Type.FLOAT], ["openPrice", griddb.Type.FLOAT],
         ["highPrice", griddb.Type.FLOAT], ["lowPrice", griddb.Type.FLOAT],
         ["volume", griddb.Type.FLOAT], ["openTime", griddb.Type.TIMESTAMP],
         ["closeTime", griddb.Type.TIMESTAMP]],
        griddb.ContainerType.COLLECTION, True)

    data_container = gridstore.put_container(crypto_container)

except griddb.GSException as e:
    for i in range(e.get_error_stack_size()):
        print("[", i, "]")
        print(e.get_error_code(i))
        print(e.get_location(i))
        print(e.get_message(i))
Ejemplo n.º 10
0
try:

    # Get GridStore object
    gridstore = factory.get_store(host=argv[1],
                                  port=int(argv[2]),
                                  cluster_name=argv[3],
                                  username=argv[4],
                                  password=argv[5])

    # When operations such as container creation and acquisition are performed, it is connected to the cluster.
    gridstore.get_container("containerName")
    print("Connect to Cluster")

    conInfo = griddb.ContainerInfo(
        name=containerName,
        column_info_list=[["date", griddb.Type.TIMESTAMP],
                          ["value1", griddb.Type.INTEGER],
                          ["value2", griddb.Type.DOUBLE]],
        type=griddb.ContainerType.TIME_SERIES)

    col = gridstore.put_container(conInfo)
    print("Sample data generation: Create Collection name=", containerName)
    print("Sample data generation:  column=(", conInfo.column_info_list[0][0],
          ",", conInfo.column_info_list[1][0], ",",
          conInfo.column_info_list[2][0], ")")

    for i in range(0, rowCount):
        print("Sample data generation:  row=(", dateList[i], ", ",
              value1List[i], ",", "%f" % (value2List[i]), ")")
    # Register multiple rows
    rowList = []
Ejemplo n.º 11
0
    # Get GridStore object
    gridstore = factory.get_store(host=argv[1],
                                  port=int(argv[2]),
                                  cluster_name=argv[3],
                                  username=argv[4],
                                  password=argv[5])

    # When operations such as container creation and acquisition are performed, it is connected to the cluster.
    gridstore.get_container("containerName")
    print("Connect to Cluster")

    # Create Collection
    conInfo = griddb.ContainerInfo(
        name="SamplePython_BlobData",
        column_info_list=[["id", griddb.Type.INTEGER],
                          ["blob", griddb.Type.BLOB]],
        type=griddb.ContainerType.COLLECTION,
        row_key=True)

    col = gridstore.put_container(conInfo)
    print("Create Collection name=SamplePython_BlobData")

    # Register binary
    # (1)Read binary file
    f = open("BlobData.py", "rb")
    blobString = f.read().decode("utf-8")
    f.close()

    # (2)Register a row
    col.put([0, blobString])
    print("Put Row (Blob)")
Ejemplo n.º 12
0
try:

    # Get GridStore object
    gridstore = factory.get_store(host=argv[1],
                                  port=int(argv[2]),
                                  cluster_name=argv[3],
                                  username=argv[4],
                                  password=argv[5])

    # When operations such as container creation and acquisition are performed, it is connected to the cluster.
    gridstore.get_container("containerName")
    print("Connect to Cluster")

    # Create a timeseries container
    conInfo = griddb.ContainerInfo(
        name="SamplePython_timeseries1",
        column_info_list=[["date", griddb.Type.TIMESTAMP],
                          ["value", griddb.Type.DOUBLE]],
        type=griddb.ContainerType.TIME_SERIES)

    ts = gridstore.put_container(conInfo)
    print("Create TimeSeries name=SamplePython_timeseries1")
    print("success!")

except griddb.GSException as e:
    for i in range(e.get_error_stack_size()):
        print("[", i, "]")
        print(e.get_error_code(i))
        print(e.get_location(i))
        print(e.get_message(i))
LOG.info('Trying to connect to GridDB...')

while True:
    time.sleep(5)
    try:
        factory = griddb.StoreFactory.get_instance()
        gridstore = factory.get_store(
            notification_member=
            "10.0.0.28:10001,10.0.0.37:10001,10.0.0.172:10001",
            cluster_name="defaultCluster",
            username="******",
            password="******")

        conInfo = griddb.ContainerInfo("SensorValuesKalpaLast",
                                       [["timestamp", griddb.Type.TIMESTAMP],
                                        ["sensorId", griddb.Type.STRING],
                                        ["sensorValue", griddb.Type.STRING]],
                                       griddb.ContainerType.TIME_SERIES, True)

        col = gridstore.put_container(conInfo)
        LOG.info('CONNECTED to GridDB.....')
        break

    except griddb.GSException as e:
        LOG.error('Error during connection to GridDB.....')


def callback(ch, method, properties, body):
    y = json.loads(str(body.decode()))
    LOG.info("Received %r" % y)
    while True:
Ejemplo n.º 14
0
blob = bytearray([65, 66, 67, 68, 69, 70, 71, 72, 73, 74])
containerName = "SamplePython_FetchRows"
update = False

try:
    # Get GridStore object
    gridstore = factory.get_store(host=argv[1],
                                  port=int(argv[2]),
                                  cluster_name=argv[3],
                                  username=argv[4],
                                  password=argv[5])

    # Create Collection
    conInfo = griddb.ContainerInfo(
        containerName,
        [["name", griddb.Type.STRING], ["status", griddb.Type.BOOL],
         ["count", griddb.Type.LONG], ["lob", griddb.Type.BLOB]],
        griddb.ContainerType.COLLECTION, True)
    col = gridstore.put_container(conInfo)
    print("Create Collection name=", containerName)

    # Put rows
    rows = pandas.DataFrame([["name01", True, 1, blob],
                             ["name02", False, 2, blob]])
    col.put_rows(rows)
    print("Put rows with DataFrame")

    # Fetch rows
    query = col.query("select *")
    rs = query.fetch(update)
    print("Fetch rows with DataFrame")
    gridstore = factory.get_store(host=argv[1],
                                  port=int(argv[2]),
                                  cluster_name=argv[3],
                                  username=argv[4],
                                  password=argv[5])

    # When operations such as container creation and acquisition are performed, it is connected to the cluster.
    gridstore.get_container("containerName")
    print("Connect to Cluster")

    # Set row expiration release
    timeProp = griddb.ExpirationInfo(100, griddb.GS_TIME_UNIT_DAY, 5)
    # Create a time series container
    conInfo = griddb.ContainerInfo(
        name="SamplePython_RowExpiration",
        column_info_list=[["date", griddb.Type.TIMESTAMP],
                          ["value", griddb.Type.DOUBLE]],
        type=griddb.ContainerType.TIME_SERIES,
        expiration=timeProp)

    ts = gridstore.put_container(conInfo)
    print(
        "Create TimeSeries & Set Row Expiration name=SamplePython_RowExpiration"
    )
    print("success!")

except griddb.GSException as e:
    for i in range(e.get_error_stack_size()):
        print("[", i, "]")
        print(e.get_error_code(i))
        print(e.get_location(i))
        print(e.get_message(i))
Ejemplo n.º 16
0
    # Get GridStore object
    gridstore = factory.get_store(host=argv[1],
                                  port=int(argv[2]),
                                  cluster_name=argv[3],
                                  username=argv[4],
                                  password=argv[5])

    # When operations such as container creation and acquisition are performed, it is connected to the cluster.
    gridstore.get_container("containerName")
    print("Connect to Cluster")

    # Create Collection
    conInfo = griddb.ContainerInfo(
        name="SamplePython_ArrayData",
        column_info_list=[["id", griddb.Type.INTEGER],
                          ["string_array", griddb.Type.STRING_ARRAY],
                          ["integer_array", griddb.Type.INTEGER_ARRAY]],
        type=griddb.ContainerType.COLLECTION,
        row_key=True)

    col = gridstore.put_container(conInfo)
    print("Create Collection name=SamplePython_ArrayData")

    # Register array type data
    # (1)Array type data
    stringArray = ["Sales", "Development", "Marketing", "Research"]
    integerArray = [39, 92, 18, 51]
    # (2)Register a row
    col.put([0, stringArray, integerArray])
    print("Put Row (Array)")