Skip to content

Commit

Permalink
Move SMQ scripts to MG
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Borovcanin <[email protected]>
  • Loading branch information
dborovcanin committed Dec 31, 2024
1 parent 5200ca5 commit 4c93db0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 30 deletions.
10 changes: 5 additions & 5 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ setup_protoc() {
}

setup_mg() {
echo "Setting up Magistrala..."
echo "Setting up SuperMQ..."
for p in $(ls *.pb.go); do
mv $p $p.tmp
done
Expand All @@ -70,15 +70,15 @@ setup_mg() {
fi
done
echo "Compile check for rabbitmq..."
MG_MESSAGE_BROKER_TYPE=rabbitmq make http
SMQ_MESSAGE_BROKER_TYPE=rabbitmq make http
echo "Compile check for redis..."
MG_ES_TYPE=redis make http
SMQ_ES_TYPE=redis make http
make -j$NPROC
}

setup_lint() {
# binary will be $(go env GOBIN)/golangci-lint
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOBIN) $GOLANGCI_LINT_VERSION
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/main/install.sh | sh -s -- -b $(go env GOBIN) $GOLANGCI_LINT_VERSION
}

setup() {
Expand All @@ -105,7 +105,7 @@ run_test() {
}

push() {
if test -n "$BRANCH_NAME" && test "$BRANCH_NAME" = "master"; then
if test -n "$BRANCH_NAME" && test "$BRANCH_NAME" = "main"; then
echo "Pushing Docker images..."
make -j$NPROC latest
fi
Expand Down
3 changes: 3 additions & 0 deletions scripts/csv/channels.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
channel_1
channel_2
channel_3
10 changes: 10 additions & 0 deletions scripts/csv/clients.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
client_1
client_2
client_3
client_4
client_5
client_6
client_7
client_8
client_9
client_10
30 changes: 15 additions & 15 deletions scripts/provision-dev.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
#

###
# Provisions example user, thing and channel on a clean Magistrala installation.
# Provisions example user, client and channel on a clean SuperMQ installation.
#
# Expects a running Magistrala installation.
# Expects a running SuperMQ installation.
#
#
###
Expand All @@ -25,26 +25,26 @@ CHANNEL=$4

#provision user:
printf "Provisoning user with email $EMAIL and password $PASSWORD \n"
curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X POST -H "Content-Type: application/json" https://localhost/users -d '{"credentials": {"identity": "'"$EMAIL"'","secret": "'"$PASSWORD"'"}, "status": "enabled", "role": "admin" }'
curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X POST -H "Content-Type: application/json" https://localhost/users -d '{"credentials": {"identity": "'"$EMAIL"'","secret": "'"$PASSWORD"'"}, "status": "enabled", "role": "admin" }'

#get jwt token
JWTTOKEN=$(curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X POST -H "Content-Type: application/json" https://localhost/users/tokens/issue -d '{"identity":"'"$EMAIL"'", "secret":"'"$PASSWORD"'"}' | grep -oP '"access_token":"\K[^"]+' )
JWTTOKEN=$(curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X POST -H "Content-Type: application/json" https://localhost/users/tokens/issue -d '{"identity":"'"$EMAIL"'", "secret":"'"$PASSWORD"'"}' | grep -oP '"access_token":"\K[^"]+' )
printf "JWT TOKEN for user is $JWTTOKEN \n"

#provision thing
printf "Provisioning thing with name $DEVICE \n"
DEVICEID=$(curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/things -d '{"name":"'"$DEVICE"'", "status": "enabled"}' | grep -oP '"id":"\K[^"]+' )
curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/things/$DEVICEID
#provision client
printf "Provisioning client with name $DEVICE \n"
DEVICEID=$(curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/clients -d '{"name":"'"$DEVICE"'", "status": "enabled"}' | grep -oP '"id":"\K[^"]+' )
curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/clients/$DEVICEID

#get thing token
DEVICETOKEN=$(curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -H "Authorization: Bearer $JWTTOKEN" https://localhost/things/$DEVICEID | grep -oP '"secret":"\K[^"]+' )
#get client token
DEVICETOKEN=$(curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -H "Authorization: Bearer $JWTTOKEN" https://localhost/clients/$DEVICEID | grep -oP '"secret":"\K[^"]+' )
printf "Device token is $DEVICETOKEN \n"

#provision channel
printf "Provisioning channel with name $CHANNEL \n"
CHANNELID=$(curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels -d '{"name":"'"$CHANNEL"'", "status": "enabled"}' | grep -oP '"id":"\K[^"]+' )
curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels/$CHANNELID
CHANNELID=$(curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels -d '{"name":"'"$CHANNEL"'", "status": "enabled"}' | grep -oP '"id":"\K[^"]+' )
curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X GET -H "Content-Type: application/json" -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels/$CHANNELID

#connect thing to channel
printf "Connecting thing of id $DEVICEID to channel of id $CHANNELID \n"
curl -s -S --cacert docker/ssl/certs/magistrala-server.crt --insecure -X PUT -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels/$CHANNELID/things/$DEVICEID
#connect client to channel
printf "Connecting client of id $DEVICEID to channel of id $CHANNELID \n"
curl -s -S --cacert docker/ssl/certs/supermq-server.crt --insecure -X PUT -H "Authorization: Bearer $JWTTOKEN" https://localhost/channels/$CHANNELID/clients/$DEVICEID
20 changes: 10 additions & 10 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# SPDX-License-Identifier: Apache-2.0

###
# Runs all Magistrala microservices (must be previously built and installed).
# Runs all SuperMQ microservices (must be previously built and installed).
#
# Expects that PostgreSQL and needed messaging DB are alredy running.
# Additionally, MQTT microservice demands that Redis is up and running.
Expand All @@ -12,9 +12,9 @@

BUILD_DIR=../build

# Kill all magistrala-* stuff
# Kill all supermq-* stuff
function cleanup {
pkill magistrala
pkill supermq
pkill nats
}

Expand All @@ -38,32 +38,32 @@ done
###
# Users
###
MG_USERS_LOG_LEVEL=info MG_USERS_HTTP_PORT=9002 MG_USERS_GRPC_PORT=7001 MG_USERS_ADMIN_EMAIL=admin@magistrala.com MG_USERS_ADMIN_PASSWORD=12345678 MG_USERS_ADMIN_USERNAME=admin MG_EMAIL_TEMPLATE=../docker/templates/users.tmpl $BUILD_DIR/magistrala-users &
SMQ_USERS_LOG_LEVEL=info SMQ_USERS_HTTP_PORT=9002 SMQ_USERS_GRPC_PORT=7001 SMQ_USERS_ADMIN_EMAIL=admin@supermq.com SMQ_USERS_ADMIN_PASSWORD=12345678 SMQ_USERS_ADMIN_USERNAME=admin SMQ_EMAIL_TEMPLATE=../docker/templates/users.tmpl $BUILD_DIR/supermq-users &

###
# Things
# Clients
###
MG_THINGS_LOG_LEVEL=info MG_THINGS_HTTP_PORT=9000 MG_THINGS_AUTH_GRPC_PORT=7000 MG_THINGS_AUTH_HTTP_PORT=9002 $BUILD_DIR/magistrala-things &
SMQ_CLIENTS_LOG_LEVEL=info SMQ_CLIENTS_HTTP_PORT=9000 SMQ_CLIENTS_AUTH_GRPC_PORT=7000 SMQ_CLIENTS_AUTH_HTTP_PORT=9002 $BUILD_DIR/supermq-clients &

###
# HTTP
###
MG_HTTP_ADAPTER_LOG_LEVEL=info MG_HTTP_ADAPTER_PORT=8008 MG_THINGS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/magistrala-http &
SMQ_HTTP_ADAPTER_LOG_LEVEL=info SMQ_HTTP_ADAPTER_PORT=8008 SMQ_CLIENTS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/supermq-http &

###
# WS
###
MG_WS_ADAPTER_LOG_LEVEL=info MG_WS_ADAPTER_HTTP_PORT=8190 MG_THINGS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/magistrala-ws &
SMQ_WS_ADAPTER_LOG_LEVEL=info SMQ_WS_ADAPTER_HTTP_PORT=8190 SMQ_CLIENTS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/supermq-ws &

###
# MQTT
###
MG_MQTT_ADAPTER_LOG_LEVEL=info MG_THINGS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/magistrala-mqtt &
SMQ_MQTT_ADAPTER_LOG_LEVEL=info SMQ_CLIENTS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/supermq-mqtt &

###
# CoAP
###
MG_COAP_ADAPTER_LOG_LEVEL=info MG_COAP_ADAPTER_PORT=5683 MG_THINGS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/magistrala-coap &
SMQ_COAP_ADAPTER_LOG_LEVEL=info SMQ_COAP_ADAPTER_PORT=5683 SMQ_CLIENTS_AUTH_GRPC_URL=localhost:7000 $BUILD_DIR/supermq-coap &

trap cleanup EXIT

Expand Down

0 comments on commit 4c93db0

Please sign in to comment.