Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sprint 3 #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 57 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,18 @@
minikube start
```

## Установка helm

## Добавление токена авторизации GitHub
https://helm.sh/

[Получение токена](https://github.com/settings/tokens/new)
## Запуск

Перейти в директорию charts

```bash
kubectl create secret docker-registry ghcr --docker-server=https://ghcr.io --docker-username=<github_username> --docker-password=<github_token> -n default
helm install smart-home ./smart-home
```


## Установка API GW kusk

[Install Kusk CLI](https://docs.kusk.io/getting-started/install-kusk-cli)
Expand All @@ -26,44 +28,74 @@ kubectl create secret docker-registry ghcr --docker-server=https://ghcr.io --doc
kusk cluster install
```

## Настройка API GW

## Настройка terraform
Перейти в директорию gateway

[Установите Terraform](https://yandex.cloud/ru/docs/tutorials/infrastructure-management/terraform-quickstart#install-terraform)
Куск не поддерживает
```bash
kusk deploy -i kafka-proxy-api.yaml
```

Прокинуть порт гейтвея

Создайте файл ~/.terraformrc
```bash
kubectl port-forward svc/kusk-gateway-envoy-fleet -n kusk-system 8080:80
```

```hcl
provider_installation {
network_mirror {
url = "https://terraform-mirror.yandexcloud.net/"
include = ["registry.terraform.io/*/*"]
}
direct {
exclude = ["registry.terraform.io/*/*"]
}
}
Получить информацию кластера

```bash
curl --location 'http://localhost:8080/v3/clusters'
```

## Применяем terraform конфигурацию
Для дальнейших запросов необходим id кластера
![img_2.png](img_2.png)

Посмотреть топики
```bash
cd terraform
terraform apply
curl --location 'http://localhost:8080/v3/clusters/<ID cluster>/topics'
```

## Настройка API GW
Создать топик если не создался

```bash
kusk deploy -i api.yaml
curl --location 'http://localhost:8080/v3/clusters/<ID cluster>/topics' \
--header 'Content-Type: application/json' \
--data '{"topic_name":"telemetry-data-topic"}'
```

## Проверяем работоспособность
Создать сообщение
```bash
curl --location 'http://localhost:8080/v3/clusters/7vxqJa7TNyxlAI468x2gQ/topics/telemetry-data-topic/records' \
--header 'Content-Type: application/json' \
--data '{
"value": {
"type": "JSON",
"data": {
"timestamp": "2024-08-29T12:34:56Z",
"deviceId": "b1e0bfc4-79c3-49a1-8df4-e6e8b8471d9a",
"data": {
"temperature": 22.5,
"humidity": 60,
"status": "ok"
}
}
}
}
'
```

Проверим данные в монго

Не разобрался как в куск подгрузить несколько файлов с апи
```bash
kubectl port-forward svc/kusk-gateway-envoy-fleet -n kusk-system 8080:80
curl localhost:8080/hello
kusk deploy -i .\api-device.yaml
```

```bash
curl --location 'http://localhost:8080/device-service/api/v1/devices/<ID device который отправили на предыдущем запросе>/telemetry/latest' \
--header 'Accept: application/json'
```


Expand Down
208 changes: 208 additions & 0 deletions charts/gateway/api-device.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
openapi: 3.0.0
info:
title: simple-api
version: 0.1.0

x-kusk:
upstream:
service:
name: device-service
namespace: default
port: 8080
paths:
/device-service/api/v1/devices:
post:
summary: Add a new device
operationId: addDevice
requestBody:
description: Device information to add
content:
application/json:
schema:
$ref: '#/components/schemas/DeviceDTO'
required: true
responses:
'201':
description: Device created
'400':
description: Invalid request
/device-service/api/v1/devices/{device_id}:
get:
summary: Get device information
operationId: getDeviceInfo
parameters:
- name: device_id
in: path
required: true
schema:
type: string
format: uuid
responses:
'200':
description: Device information
content:
application/json:
schema:
$ref: '#/components/schemas/DeviceDTO'
'404':
description: Device not found
delete:
summary: Delete a device
operationId: deleteDevice
parameters:
- name: device_id
in: path
required: true
schema:
type: string
format: uuid
responses:
'204':
description: Device deleted
'404':
description: Device not found
/device-service/api/v1/devices/{device_id}/configuration:
put:
summary: Update device configuration
operationId: updateDeviceConfiguration
parameters:
- name: device_id
in: path
required: true
schema:
type: string
format: uuid
requestBody:
description: Device configuration to update
content:
application/json:
schema:
$ref: '#/components/schemas/DeviceConfigurationDTO'
required: true
responses:
'200':
description: Configuration updated
'400':
description: Invalid request
'404':
description: Device not found
get:
summary: Get device configuration
operationId: getDeviceConfiguration
parameters:
- name: device_id
in: path
required: true
schema:
type: string
format: uuid
responses:
'200':
description: Device configuration
content:
application/json:
schema:
$ref: '#/components/schemas/DeviceConfigurationDTO'
'404':
description: Device not found
/device-service/api/v1/devices/{device_id}/telemetry/latest:
get:
summary: Get latest telemetry data
operationId: getLatestTelemetry
parameters:
- name: device_id
in: path
required: true
schema:
type: string
format: uuid
responses:
'200':
description: Latest telemetry data
content:
application/json:
schema:
$ref: '#/components/schemas/TelemetryDTO'
'404':
description: Device not found
/device-service/api/v1/devices/{device_id}/telemetry/history:
get:
summary: Get telemetry history
operationId: getTelemetryHistory
parameters:
- name: device_id
in: path
required: true
schema:
type: string
format: uuid
- name: start_time
in: query
required: true
schema:
type: string
format: date-time
- name: end_time
in: query
required: true
schema:
type: string
format: date-time
responses:
'200':
description: Telemetry history
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/TelemetryDTO'
'404':
description: Device not found
/device-service/api/v1/users/{user_id}/devices:
get:
summary: Get devices for a user
operationId: getUserDevices
parameters:
- name: user_id
in: path
required: true
schema:
type: string
format: uuid
responses:
'200':
description: List of devices for the user
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/DeviceDTO'
'404':
description: User not found
components:
schemas:
DeviceDTO:
type: object
properties:
id:
type: string
format: uuid
name:
type: string
type:
type: string
DeviceConfigurationDTO:
type: object
properties:
configuration:
type: string
TelemetryDTO:
type: object
properties:
timestamp:
type: string
format: date-time
data:
type: string
Loading