Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents
minLevel1
maxLevel7
typeflat

...

Prerequisites

Key

Type

Description

lake_name

string

생성할 lake의 식별자

lake_plan

string

tiny / basic / business/ enterprise

owner

string

Lake의 소유주

(생략한 경우, API를 호출한 사용자)

region

string

AWS region name

timezone

string

Timezone name

storage_size

int

Storage size

tag_schema

JSON

Lake의 tag meta에 저장될 칼럼 스키마.

스키마 정보에는 다음의 3가지 칼럼을 갖는다. col_name, col_type, col_length.

col_name : 메타 칼럼 이름

col_type : 메타 칼럼 타입

  • short” : 2바이트 정수

  • int” : 4바이트 정수

  • long” : 8바이트 정수

  • float” : 4바이트 정수

  • double” : 8바이트 실수

  • datetime” : 나노세컨드 정밀도의 시간 (8바이트)

  • varchar” : 문자열

col_length : 문자열의 경우 길이를 지정해야 한다. (예제)

Code Block
 {'col_name': "name", 'col_type': "varchar", 'col_length': 40}

첫 번째 메타 칼럼의 데이터 타입, 즉 “col_type”은 “varchar”를 지정해야 한다.

추가로 지정한 메타 칼럼의 데이터 타입은 다른 형으로 지정이 가능하다.

value_schema

JSON

Lake에 저장될 데이터들의 칼럼 메타정보를 지정한다.

이 메타정보에서 두개의 필수 칼럼정보를 지정해야 한다. 이는 시간과 기본 센서값이다.

첫번째 필수 칼럼은 “datetime”으로 데이터 입력시간을 지정해야 하며, 두번째 칼럼의 데이터 타입은 반드시 “double” 타입으로 지정해야 한다.

Code Block
   {'col_name': "time", 'col_type': "datetime"},
   {'col_name': "value",'col_type': "double"}

세번째 칼럼 이후에는 원하는 타입으로 메타 정보를 추가하면 된다.

...

Code Block
Status 200

{
    "status": true,
    "data" : {lake id}
}

Sample Code

Expand
titlelinux(shell)

github

Code Block
# Text Encoding to UTF-8 in CMD
# Example For Create Lake API by using curl in shell script
# written by yeony kim

API_KEY=YOUR_API_TOKEN

CONTENT_HEADER=Content-Type:application/json
API_HEADER=x-api-key:$API_KEY

URL=https://api.machlake.com/lakes

# ------------------------------------------------------------------------------------------------- #

# CASE - create LAKE

curl -k -X POST $URL -H $CONTENT_HEADER -H $API_HEADER --data "{\"lake_id\":\"\",\"lake_info\":{\"lake_name\":\"sample_lake\",\"lake_plan\":\"basic\",\"owner\":\"YOUR_MACHLAKE_ID\",\"region\":\"ap-northeast-2\",\"timezone\":\"Asia/Seoul\",\"storage_size\":20},\"tag_schema\":[{\"col_name\":\"name\",\"col_type\":\"varchar\",\"col_length\":40}],\"value_schema\":[{\"col_name\":\"time\",\"col_type\":\"datetime\"},{\"col_name\":\"value\",\"col_type\":\"double\"}]}"

# Return Format
# {"data":"YOUR_LAKE_ID","status":"success"}

# ------------------------------------------------------------------------------------------------- #
Expand
titlejavascript

github

Code Block
// Example For Create LAKE API by using request in nodejs
// written by yeony kim

process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";

const express = require('express');
const app = express();
const API_KEY = "YOUR_API_TOKEN";
const URL = "https://api.machlake.com/lakes";

// CASE - create LAKE

app.get(
    '/create_lake', function(req, res) {
        const Data = {
            lake_id:"",
            lake_info:{
                lake_name:"sample_lake",
                lake_plan:"basic",
                owner:"YOUR_MACHLAKE_ID",
                region:"ap-northeast-2",
                timezone:"Asia/Seoul",
                storage_size:20
            },
            tag_schema:[
                {col_name:"name",col_type:"varchar",col_length:40}
            ],
            value_schema:[
                {col_name:"time",col_type:"datetime"},
                {col_name:"value",col_type:"double"}
            ]
        }
        var request = require('request');
        var option = {
            url: URL,
            headers: {
                'Content-Type': 'application/json',
                'x-api-key': API_KEY
            },
            body: JSON.stringify(Data)
        };
        request.post( option, function(error, response, body) {
            if (!error) {
                res.writeHead(200);
                res.end(body);
                console.log(body) // {"data":"YOUR_LAKE_ID","status":"success"}
            } else {
                console.log(error)
            }
        })
    }
)

app.listen(8888, function() {
    console.log('http://127.0.0.1:8888/create_lake is result for create LAKE')
})
Expand
titlepython

github

Code Block
"""
Example For Create LAKE API by using request in python
written by yeony kim
"""

import requests

API_KEY = "YOUR_API_TOKEN"
URL = f"https://api.machlake.com/lakes"

# CASE - CASE - create LAKE

headers = {
    'Content-Type': 'application/json',
    'x-api-key': API_KEY
}

params = {
    'lake_id': "",
    'lake_info': {
        'lake_name': "sample_lake",
        'lake_plan': "basic",
        'owner': "YOUR_MACHLAKE_ID",
        'region': "ap-northeast-2",
        'timezone': "Asia/Seoul",
        'storage_size': 20
    },
    'tag_schema': [
        {'col_name': "name", 'col_type': "varchar", 'col_length': 40}
    ],
    'value_schema': [
        {'col_name': "time", 'col_type': "datetime"},
        {'col_name': "value", 'col_type': "double"}
    ]
}

response = requests.post(URL, headers=headers, json=params, verify=False)
print(response.content.decode('utf-8'))  # {"data":"YOUR_LAKE_ID","status":"success"}