Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
ACS
Public
VILLASframework
VILLASweb-backend-go
Commits
36112143
Commit
36112143
authored
Mar 12, 2020
by
Sonja Happ
Browse files
Merge branch 'renaming-simulator-simmodel' into 'master'
Renaming simulator and simmodel See merge request
!14
parents
9539c42e
ef1dede7
Changes
36
Pipelines
1
Expand all
Hide whitespace changes
Inline
Side-by-side
.gitlab-ci.yml
View file @
36112143
...
...
@@ -95,10 +95,10 @@ test:scenario:
variables
:
TEST_FOLDER
:
routes/scenario
test:
simulationmodel
:
extends
:
test:
scenario
test:
component-configuration
:
extends
:
test:
database
variables
:
TEST_FOLDER
:
routes/
simulationmodel
TEST_FOLDER
:
routes/
component-configuration
test:signal:
extends
:
test:database
...
...
@@ -115,10 +115,10 @@ test:widget:
variables
:
TEST_FOLDER
:
routes/widget
test:
simulator
:
test:
infrastructure-component
:
extends
:
test:database
variables
:
TEST_FOLDER
:
routes/
simulator
TEST_FOLDER
:
routes/
infrastructure-component
test:file:
extends
:
test:database
...
...
amqp/amqp_endpoints.go
View file @
36112143
...
...
@@ -24,32 +24,32 @@ package amqp
import
(
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/
simulator
"
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/
infrastructure-component
"
"github.com/gin-gonic/gin"
"net/http"
"time"
)
func
RegisterAMQPEndpoint
(
r
*
gin
.
RouterGroup
)
{
r
.
POST
(
"/
:simulator
ID/action"
,
sendActionTo
Simulator
)
r
.
POST
(
"/
IC
ID/action"
,
sendActionTo
IC
)
}
// sendActionTo
Simulator
godoc
// @Summary Send an action to
simulator
(only available if backend server is started with -amqp parameter)
// @ID sendActionTo
Simulator
// sendActionTo
IC
godoc
// @Summary Send an action to
IC
(only available if backend server is started with -amqp parameter)
// @ID sendActionTo
IC
// @Tags AMQP
// @Produce json
// @Param inputAction query string true "Action for
simulator
"
// @Param inputAction query string true "Action for
IC
"
// @Success 200 {object} docs.ResponseError "Action sent successfully"
// @Failure 400 {object} docs.ResponseError "Bad request"
// @Failure 404 {object} docs.ResponseError "Not found"
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
// @Failure 500 {object} docs.ResponseError "Internal server error"
// @Param
simulator
ID path int true "
Simulator
ID"
// @Router /
simulators/{simulator
ID}/action [post]
func
sendActionTo
Simulator
(
c
*
gin
.
Context
)
{
// @Param
IC
ID path int true "
InfrastructureComponent
ID"
// @Router /
ic/{IC
ID}/action [post]
func
sendActionTo
IC
(
c
*
gin
.
Context
)
{
ok
,
s
:=
simulator
.
CheckPermissions
(
c
,
database
.
Model
Simulator
Action
,
database
.
Update
,
true
)
ok
,
s
:=
infrastructure_component
.
CheckPermissions
(
c
,
database
.
Model
InfrastructureComponent
Action
,
database
.
Update
,
true
)
if
!
ok
{
return
}
...
...
@@ -70,7 +70,7 @@ func sendActionToSimulator(c *gin.Context) {
err
=
SendActionAMQP
(
action
,
s
.
UUID
)
if
err
!=
nil
{
helper
.
InternalServerError
(
c
,
"Unable to send actions to
simulator
: "
+
err
.
Error
())
helper
.
InternalServerError
(
c
,
"Unable to send actions to
IC
: "
+
err
.
Error
())
return
}
}
...
...
amqp/amqpclient.go
View file @
36112143
...
...
@@ -77,8 +77,8 @@ func ConnectAMQP(uri string) error {
return
fmt
.
Errorf
(
"AMQP: failed to declare the exchange"
)
}
// add a queue for the
simulator
s
simulator
Queue
,
err
:=
client
.
channel
.
QueueDeclare
(
"
simulator
s"
,
// add a queue for the
IC
s
IC
Queue
,
err
:=
client
.
channel
.
QueueDeclare
(
"
infrastructure_component
s"
,
true
,
false
,
false
,
...
...
@@ -88,13 +88,13 @@ func ConnectAMQP(uri string) error {
return
fmt
.
Errorf
(
"AMQP: failed to declare the queue"
)
}
err
=
client
.
channel
.
QueueBind
(
simulator
Queue
.
Name
,
""
,
VILLAS_EXCHANGE
,
false
,
nil
)
err
=
client
.
channel
.
QueueBind
(
IC
Queue
.
Name
,
""
,
VILLAS_EXCHANGE
,
false
,
nil
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"AMQP: failed to bind the queue"
)
}
// consume deliveries
client
.
replies
,
err
=
client
.
channel
.
Consume
(
simulator
Queue
.
Name
,
client
.
replies
,
err
=
client
.
channel
.
Consume
(
IC
Queue
.
Name
,
""
,
false
,
false
,
...
...
@@ -120,15 +120,15 @@ func ConnectAMQP(uri string) error {
continue
}
var
sToBeUpdated
database
.
Simulator
var
sToBeUpdated
database
.
InfrastructureComponent
db
:=
database
.
GetDB
()
simulator
UUID
:=
gjson
.
Get
(
content
,
"properties.uuid"
)
.
String
()
if
simulator
UUID
==
""
{
log
.
Println
(
"AMQP: Could not extract UUID of
simulator
from content of received message,
SIMULATOR
NOT UPDATED"
)
IC
UUID
:=
gjson
.
Get
(
content
,
"properties.uuid"
)
.
String
()
if
IC
UUID
==
""
{
log
.
Println
(
"AMQP: Could not extract UUID of
IC
from content of received message,
COMPONENT
NOT UPDATED"
)
}
else
{
err
=
db
.
Where
(
"UUID = ?"
,
simulator
UUID
)
.
Find
(
sToBeUpdated
)
.
Error
err
=
db
.
Where
(
"UUID = ?"
,
IC
UUID
)
.
Find
(
sToBeUpdated
)
.
Error
if
err
!=
nil
{
log
.
Println
(
"AMQP: Unable to find
simulator
with UUID: "
,
gjson
.
Get
(
content
,
"properties.uuid"
),
" DB error message: "
,
err
)
log
.
Println
(
"AMQP: Unable to find
IC
with UUID: "
,
gjson
.
Get
(
content
,
"properties.uuid"
),
" DB error message: "
,
err
)
}
err
=
db
.
Model
(
&
sToBeUpdated
)
.
Updates
(
map
[
string
]
interface
{}{
...
...
@@ -140,10 +140,10 @@ func ConnectAMQP(uri string) error {
"RawProperties"
:
gjson
.
Get
(
content
,
"properties"
),
})
.
Error
if
err
!=
nil
{
log
.
Println
(
"AMQP: Unable to update
simulator
in DB: "
,
err
)
log
.
Println
(
"AMQP: Unable to update
IC
in DB: "
,
err
)
}
log
.
Println
(
"AMQP: Updated
simulator
with UUID "
,
gjson
.
Get
(
content
,
"properties.uuid"
))
log
.
Println
(
"AMQP: Updated
IC
with UUID "
,
gjson
.
Get
(
content
,
"properties.uuid"
))
}
}
}()
...
...
@@ -182,7 +182,7 @@ func SendActionAMQP(action Action, uuid string) error {
}
func
PingAMQP
()
error
{
log
.
Println
(
"AMQP: sending ping command to all
simulator
s"
)
log
.
Println
(
"AMQP: sending ping command to all
IC
s"
)
var
a
Action
a
.
Act
=
"ping"
...
...
curl_villasAPI.sh
View file @
36112143
...
...
@@ -55,9 +55,9 @@ read_users () {
-X
GET | jq
'.'
&&
printf
'\n'
}
read_
simulator
s
()
{
printf
"> GET "
$apiBase
"/
simulators
\n
"
curl
"
$apiBase
"
/
simulators
-s
\
read_
infrastructure_component
s
()
{
printf
"> GET "
$apiBase
"/
ic
\n
"
curl
"
$apiBase
"
/
ic
-s
\
-H
"Contet-Type: application/json"
\
-H
"Authorization: Bearer
$(
< auth.jwt
)
"
\
-X
GET | jq
'.'
&&
printf
'\n'
...
...
@@ -114,7 +114,7 @@ login "$admin"
#create_user "$userC"
#read_users
#read_user 1
#read_
simulator
s
#read_
infrastructure_component
s
create_user
"
$newUserW
"
#read_users
read_user 4
...
...
database/database.go
View file @
36112143
...
...
@@ -102,9 +102,9 @@ func GetDB() *gorm.DB {
// TODO: Remove that function from the codebase and substitute the body
// to the Dummy*() where it is called
func
DropTables
(
db
*
gorm
.
DB
)
{
db
.
DropTableIfExists
(
&
Simulator
{})
db
.
DropTableIfExists
(
&
InfrastructureComponent
{})
db
.
DropTableIfExists
(
&
Signal
{})
db
.
DropTableIfExists
(
&
SimulationModel
{})
db
.
DropTableIfExists
(
&
ComponentConfiguration
{})
db
.
DropTableIfExists
(
&
File
{})
db
.
DropTableIfExists
(
&
Scenario
{})
db
.
DropTableIfExists
(
&
User
{})
...
...
@@ -116,9 +116,9 @@ func DropTables(db *gorm.DB) {
// AutoMigrate the models
func
MigrateModels
(
db
*
gorm
.
DB
)
{
db
.
AutoMigrate
(
&
Simulator
{})
db
.
AutoMigrate
(
&
InfrastructureComponent
{})
db
.
AutoMigrate
(
&
Signal
{})
db
.
AutoMigrate
(
&
SimulationModel
{})
db
.
AutoMigrate
(
&
ComponentConfiguration
{})
db
.
AutoMigrate
(
&
File
{})
db
.
AutoMigrate
(
&
Scenario
{})
db
.
AutoMigrate
(
&
User
{})
...
...
database/database_test.go
View file @
36112143
...
...
@@ -107,8 +107,8 @@ func TestScenarioAssociations(t *testing.T) {
user0
:=
User0
userA
:=
UserA
userB
:=
UserB
modelA
:=
SimulationModel
A
modelB
:=
SimulationModel
B
configA
:=
Config
A
configB
:=
Config
B
dashboardA
:=
DashboardA
dashboardB
:=
DashboardB
...
...
@@ -121,9 +121,9 @@ func TestScenarioAssociations(t *testing.T) {
assert
.
NoError
(
t
,
db
.
Create
(
&
userA
)
.
Error
)
// Normal User
assert
.
NoError
(
t
,
db
.
Create
(
&
userB
)
.
Error
)
// Normal User
// add
simulation model
s to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
model
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
model
B
)
.
Error
)
// add
component configuration
s to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
config
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
config
B
)
.
Error
)
// add dashboards to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
dashboardA
)
.
Error
)
...
...
@@ -136,9 +136,9 @@ func TestScenarioAssociations(t *testing.T) {
assert
.
NoError
(
t
,
db
.
Model
(
&
scenarioB
)
.
Association
(
"Users"
)
.
Append
(
&
userA
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
scenarioB
)
.
Association
(
"Users"
)
.
Append
(
&
userB
)
.
Error
)
// add scenario has many
simulation model
s associations
assert
.
NoError
(
t
,
db
.
Model
(
&
scenarioA
)
.
Association
(
"
SimulationModel
s"
)
.
Append
(
&
model
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
scenarioA
)
.
Association
(
"
SimulationModel
s"
)
.
Append
(
&
model
B
)
.
Error
)
// add scenario has many
component configuration
s associations
assert
.
NoError
(
t
,
db
.
Model
(
&
scenarioA
)
.
Association
(
"
ComponentConfiguration
s"
)
.
Append
(
&
config
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
scenarioA
)
.
Association
(
"
ComponentConfiguration
s"
)
.
Append
(
&
config
B
)
.
Error
)
// Scenario HM Dashboards
assert
.
NoError
(
t
,
db
.
Model
(
&
scenarioA
)
.
Association
(
"Dashboards"
)
.
Append
(
&
dashboardA
)
.
Error
)
...
...
@@ -156,12 +156,12 @@ func TestScenarioAssociations(t *testing.T) {
"Expected to have %v Users. Has %v."
,
2
,
len
(
users
))
}
// Get
simulation model
s of scenario1
var
models
[]
SimulationModel
assert
.
NoError
(
t
,
db
.
Model
(
&
scenario1
)
.
Related
(
&
models
,
"SimulationModel
s"
)
.
Error
)
if
len
(
model
s
)
!=
2
{
// Get
component configuration
s of scenario1
var
configs
[]
ComponentConfiguration
assert
.
NoError
(
t
,
db
.
Model
(
&
scenario1
)
.
Related
(
&
configs
,
"ComponentConfiguration
s"
)
.
Error
)
if
len
(
config
s
)
!=
2
{
assert
.
Fail
(
t
,
"Scenario Associations"
,
"Expected to have %v
simulation model
s. Has %v."
,
2
,
len
(
model
s
))
"Expected to have %v
component config
s. Has %v."
,
2
,
len
(
config
s
))
}
// Get dashboards of scenario1
...
...
@@ -173,50 +173,50 @@ func TestScenarioAssociations(t *testing.T) {
}
}
func
Test
Simulator
Associations
(
t
*
testing
.
T
)
{
func
Test
IC
Associations
(
t
*
testing
.
T
)
{
DropTables
(
db
)
MigrateModels
(
db
)
// create copies of global test data
simulatorA
:=
Simulator
A
simulatorB
:=
Simulator
B
modelA
:=
SimulationModel
A
modelB
:=
SimulationModel
B
// add
simulator
s to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
simulator
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
simulator
B
)
.
Error
)
// add
simulation model
s to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
model
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
model
B
)
.
Error
)
// add
simulator
has many
simulation model
s association to DB
assert
.
NoError
(
t
,
db
.
Model
(
&
simulator
A
)
.
Association
(
"
SimulationModel
s"
)
.
Append
(
&
model
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
simulator
A
)
.
Association
(
"
SimulationModel
s"
)
.
Append
(
&
model
B
)
.
Error
)
var
simulator1
Simulator
assert
.
NoError
(
t
,
db
.
Find
(
&
simulator
1
,
1
)
.
Error
,
fmt
.
Sprintf
(
"Find
Simulator
with ID=1"
))
assert
.
EqualValues
(
t
,
"Host_A"
,
simulator
1
.
Host
)
// Get
simulation models of simulator
1
var
models
[]
SimulationModel
assert
.
NoError
(
t
,
db
.
Model
(
&
simulator
1
)
.
Association
(
"
SimulationModel
s"
)
.
Find
(
&
model
s
)
.
Error
)
if
len
(
model
s
)
!=
2
{
assert
.
Fail
(
t
,
"
Simulator
Associations"
,
"Expected to have %v
SimulationModel
s. Has %v."
,
2
,
len
(
model
s
))
icA
:=
IC
A
icB
:=
IC
B
configA
:=
Config
A
configB
:=
Config
B
// add
IC
s to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
ic
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
ic
B
)
.
Error
)
// add
component configuration
s to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
config
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
config
B
)
.
Error
)
// add
IC
has many
component configuration
s association to DB
assert
.
NoError
(
t
,
db
.
Model
(
&
ic
A
)
.
Association
(
"
ComponentConfiguration
s"
)
.
Append
(
&
config
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
ic
A
)
.
Association
(
"
ComponentConfiguration
s"
)
.
Append
(
&
config
B
)
.
Error
)
var
ic1
InfrastructureComponent
assert
.
NoError
(
t
,
db
.
Find
(
&
ic
1
,
1
)
.
Error
,
fmt
.
Sprintf
(
"Find
InfrastructureComponent
with ID=1"
))
assert
.
EqualValues
(
t
,
"Host_A"
,
ic
1
.
Host
)
// Get
Component Configurations of ic
1
var
configs
[]
ComponentConfiguration
assert
.
NoError
(
t
,
db
.
Model
(
&
ic
1
)
.
Association
(
"
ComponentConfiguration
s"
)
.
Find
(
&
config
s
)
.
Error
)
if
len
(
config
s
)
!=
2
{
assert
.
Fail
(
t
,
"
InfrastructureComponent
Associations"
,
"Expected to have %v
Component Configuration
s. Has %v."
,
2
,
len
(
config
s
))
}
}
func
Test
SimulationModel
Associations
(
t
*
testing
.
T
)
{
func
Test
ComponentConfiguration
Associations
(
t
*
testing
.
T
)
{
DropTables
(
db
)
MigrateModels
(
db
)
// create copies of global test data
modelA
:=
SimulationModel
A
modelB
:=
SimulationModel
B
configA
:=
Config
A
configB
:=
Config
B
outSignalA
:=
OutSignalA
outSignalB
:=
OutSignalB
inSignalA
:=
InSignalA
...
...
@@ -225,12 +225,12 @@ func TestSimulationModelAssociations(t *testing.T) {
fileB
:=
FileB
fileC
:=
FileC
fileD
:=
FileD
simulatorA
:=
Simulator
A
simulatorB
:=
Simulator
B
icA
:=
IC
A
icB
:=
IC
B
// add
simulation model
s to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
model
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
model
B
)
.
Error
)
// add
Component Configuration
s to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
config
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
config
B
)
.
Error
)
// add signals to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
outSignalA
)
.
Error
)
...
...
@@ -244,46 +244,46 @@ func TestSimulationModelAssociations(t *testing.T) {
assert
.
NoError
(
t
,
db
.
Create
(
&
fileC
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
fileD
)
.
Error
)
// add
simulator
s to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
simulator
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
simulator
B
)
.
Error
)
// add
IC
s to DB
assert
.
NoError
(
t
,
db
.
Create
(
&
ic
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Create
(
&
ic
B
)
.
Error
)
// add
simulation model
has many signals associations
assert
.
NoError
(
t
,
db
.
Model
(
&
model
A
)
.
Association
(
"InputMapping"
)
.
Append
(
&
inSignalA
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
model
A
)
.
Association
(
"InputMapping"
)
.
Append
(
&
inSignalB
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
model
A
)
.
Association
(
"OutputMapping"
)
.
Append
(
&
outSignalA
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
model
A
)
.
Association
(
"OutputMapping"
)
.
Append
(
&
outSignalB
)
.
Error
)
// add
Component Configuration
has many signals associations
assert
.
NoError
(
t
,
db
.
Model
(
&
config
A
)
.
Association
(
"InputMapping"
)
.
Append
(
&
inSignalA
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
config
A
)
.
Association
(
"InputMapping"
)
.
Append
(
&
inSignalB
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
config
A
)
.
Association
(
"OutputMapping"
)
.
Append
(
&
outSignalA
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
config
A
)
.
Association
(
"OutputMapping"
)
.
Append
(
&
outSignalB
)
.
Error
)
// add
simulation model
has many files associations
assert
.
NoError
(
t
,
db
.
Model
(
&
model
A
)
.
Association
(
"Files"
)
.
Append
(
&
fileC
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
model
A
)
.
Association
(
"Files"
)
.
Append
(
&
fileD
)
.
Error
)
// add
Component Configuration
has many files associations
assert
.
NoError
(
t
,
db
.
Model
(
&
config
A
)
.
Association
(
"Files"
)
.
Append
(
&
fileC
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
config
A
)
.
Association
(
"Files"
)
.
Append
(
&
fileD
)
.
Error
)
// associate
simulation models with simulators
assert
.
NoError
(
t
,
db
.
Model
(
&
simulator
A
)
.
Association
(
"
SimulationModel
s"
)
.
Append
(
&
model
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
simulator
A
)
.
Association
(
"
SimulationModel
s"
)
.
Append
(
&
model
B
)
.
Error
)
// associate
Component Configurations with IC
assert
.
NoError
(
t
,
db
.
Model
(
&
ic
A
)
.
Association
(
"
ComponentConfiguration
s"
)
.
Append
(
&
config
A
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
ic
A
)
.
Association
(
"
ComponentConfiguration
s"
)
.
Append
(
&
config
B
)
.
Error
)
var
model1
SimulationModel
assert
.
NoError
(
t
,
db
.
Find
(
&
model
1
,
1
)
.
Error
,
fmt
.
Sprintf
(
"Find
SimulationModel
with ID=1"
))
assert
.
EqualValues
(
t
,
"SimulationModel_A"
,
model
1
.
Name
)
var
config1
ComponentConfiguration
assert
.
NoError
(
t
,
db
.
Find
(
&
config
1
,
1
)
.
Error
,
fmt
.
Sprintf
(
"Find
ComponentConfiguration
with ID=1"
))
assert
.
EqualValues
(
t
,
ConfigA
.
Name
,
config
1
.
Name
)
// Check
simulator
ID
if
model1
.
Simulator
ID
!=
1
{
assert
.
Fail
(
t
,
"
Simulation Model expected to have Simulator
ID 1, but is %v"
,
model1
.
Simulator
ID
)
// Check
IC
ID
if
config1
.
IC
ID
!=
1
{
assert
.
Fail
(
t
,
"
Component Configurations expected to have Infrastructure Component
ID 1, but is %v"
,
config1
.
IC
ID
)
}
// Get OutputMapping signals of
model
1
// Get OutputMapping signals of
config
1
var
signals
[]
Signal
assert
.
NoError
(
t
,
db
.
Model
(
&
model
1
)
.
Where
(
"Direction = ?"
,
"out"
)
.
Related
(
&
signals
,
"OutputMapping"
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
config
1
)
.
Where
(
"Direction = ?"
,
"out"
)
.
Related
(
&
signals
,
"OutputMapping"
)
.
Error
)
if
len
(
signals
)
!=
2
{
assert
.
Fail
(
t
,
"
SimulationModel
Associations"
,
assert
.
Fail
(
t
,
"
ComponentConfiguration
Associations"
,
"Expected to have %v Output Signals. Has %v."
,
2
,
len
(
signals
))
}
// Get files of
model
1
// Get files of
config
1
var
files
[]
File
assert
.
NoError
(
t
,
db
.
Model
(
&
model
1
)
.
Related
(
&
files
,
"Files"
)
.
Error
)
assert
.
NoError
(
t
,
db
.
Model
(
&
config
1
)
.
Related
(
&
files
,
"Files"
)
.
Error
)
if
len
(
files
)
!=
2
{
assert
.
Fail
(
t
,
"
SimulationModel
Associations"
,
assert
.
Fail
(
t
,
"
ComponentConfiguration
Associations"
,
"Expected to have %v Files. Has %v."
,
2
,
len
(
files
))
}
}
...
...
database/models.go
View file @
36112143
...
...
@@ -65,35 +65,35 @@ type Scenario struct {
StartParameters
postgres
.
Jsonb
`json:"startParameters"`
// Users that have access to the scenario
Users
[]
*
User
`json:"-" gorm:"many2many:user_scenarios;"`
//
SimulationModel
s that belong to the scenario
SimulationModels
[]
SimulationModel
`json:"-" gorm:"foreignkey:ScenarioID" `
//
ComponentConfiguration
s that belong to the scenario
ComponentConfigurations
[]
ComponentConfiguration
`json:"-" gorm:"foreignkey:ScenarioID" `
// Dashboards that belong to the Scenario
Dashboards
[]
Dashboard
`json:"-" gorm:"foreignkey:ScenarioID" `
}
//
SimulationModel
data model
type
SimulationModel
struct
{
//
ComponentConfiguration
data model
type
ComponentConfiguration
struct
{
Model
// Name of
simulation model
// Name of
Component Configuration
Name
string
`json:"name" gorm:"not null"`
// Number of output signals
OutputLength
int
`json:"outputLength" gorm:"default:0"`
// Number of input signals
InputLength
int
`json:"inputLength" gorm:"default:0"`
// Start parameters of
simulation model
as JSON
// Start parameters of
Component Configuration
as JSON
StartParameters
postgres
.
Jsonb
`json:"startParameters"`
// ID of Scenario to which
simulation model
belongs
// ID of Scenario to which
Component Configuration
belongs
ScenarioID
uint
`json:"scenarioID"`
// ID of
simulator
associated with
simulation model
Simulator
ID
uint
`json:"
simulator
ID"`
// Mapping of output signals of the
simulation model
, order of signals is important
OutputMapping
[]
Signal
`json:"-" gorm:"foreignkey:
SimulationModel
ID"`
// Mapping of input signals of the
simulation model
, order of signals is important
InputMapping
[]
Signal
`json:"-" gorm:"foreignkey:
SimulationModel
ID"`
// Files of
simulation model
(can be CIM and other
simulation model
file formats)
Files
[]
File
`json:"-" gorm:"foreignkey:
SimulationModel
ID"`
// Currently selected
simulation model
FileID
Selected
Model
FileID
uint
`json:"selected
Model
FileID" gorm:"default:0"`
// ID of
IC
associated with
Component Configuration
IC
ID
uint
`json:"
ic
ID"`
// Mapping of output signals of the
ComponentConfiguration
, order of signals is important
OutputMapping
[]
Signal
`json:"-" gorm:"foreignkey:
Config
ID"`
// Mapping of input signals of the
Component Configuration
, order of signals is important
InputMapping
[]
Signal
`json:"-" gorm:"foreignkey:
Config
ID"`
// Files of
Component Configuration
(can be CIM and other
ComponentConfiguration
file formats)
Files
[]
File
`json:"-" gorm:"foreignkey:
Config
ID"`
// Currently selected FileID
SelectedFileID
uint
`json:"selectedFileID" gorm:"default:0"`
}
// Signal data model
...
...
@@ -107,31 +107,31 @@ type Signal struct {
Index
uint
`json:"index"`
// Direction of the signal (in or out)
Direction
string
`json:"direction"`
// ID of
simulation model
SimulationModelID
uint
`json:"simulationModel
ID"`
// ID of
Component Configuration
ConfigID
uint
`json:"config
ID"`
}
//
Simulator
data model
type
Simulator
struct
{
//
InfrastructureComponent
data model
type
InfrastructureComponent
struct
{
Model
// UUID of the
simulator
// UUID of the
IC
UUID
string
`json:"uuid" gorm:"not null"`
// Host if the
simulator
// Host if the
IC
Host
string
`json:"host" gorm:"default:''"`
// Model type supported by the
simulator
// Model type supported by the
IC
Modeltype
string
`json:"modelType" gorm:"default:''"`
// Uptime of the
simulator
// Uptime of the
IC
Uptime
int
`json:"uptime" gorm:"default:0"`
// State of the
simulator
// State of the
IC
State
string
`json:"state" gorm:"default:''"`
// Time of last state update
StateUpdateAt
string
`json:"stateUpdateAt" gorm:"default:''"`
// Properties of
simulator
as JSON string
// Properties of
IC
as JSON string
Properties
postgres
.
Jsonb
`json:"properties"`
// Raw properties of
simulator
as JSON string
// Raw properties of
IC
as JSON string
RawProperties
postgres
.
Jsonb
`json:"rawProperties"`
//
SimulationModel
s in which the
simulator
is used
SimulationModels
[]
SimulationModel
`json:"-" gorm:"foreignkey:
Simulator
ID"`
//
ComponentConfiguration
s in which the
IC
is used
ComponentConfigurations
[]
ComponentConfiguration
`json:"-" gorm:"foreignkey:
IC
ID"`
}
// Dashboard data model
...
...
@@ -195,8 +195,8 @@ type File struct {
ImageWidth
uint
`json:"imageWidth"`
// Last modification time of file
Date
string
`json:"date"`
// ID of
model
to which file belongs
SimulationModelID
uint
`json:"simulationModel
ID"`
// ID of
Component Configuration
to which file belongs
ConfigID
uint
`json:"config
ID"`
// ID of widget to which file belongs
WidgetID
uint
`json:"widgetID"`
// File itself
...
...
database/roles.go
View file @
36112143
...
...
@@ -38,11 +38,11 @@ type ModelName string
const
ModelUser
=
ModelName
(
"user"
)
const
ModelUsers
=
ModelName
(
"users"
)
const
ModelScenario
=
ModelName
(
"scenario"
)
const
Model
Simulator
=
ModelName
(
"
simulator
"
)
const
Model
Simulator
Action
=
ModelName
(
"
simulator
action"
)
const
Model
InfrastructureComponent
=
ModelName
(
"
ic
"
)
const
Model
InfrastructureComponent
Action
=
ModelName
(
"
ic
action"
)
const
ModelDashboard
=
ModelName
(
"dashboard"
)
const
ModelWidget
=
ModelName
(
"widget"
)
const
Model
SimulationModel
=
ModelName
(
"simulationmodel
"
)
const
Model
ComponentConfiguration
=
ModelName
(
"component-configuration
"
)
const
ModelSignal
=
ModelName
(
"signal"
)
const
ModelFile
=
ModelName
(
"file"
)
...
...
@@ -73,40 +73,40 @@ var none = Permission{Create: false, Read: false, Update: false, Delete: false}
// allowed to do a certain action on a given model based on his role
var
Roles
=
RoleActions
{
"Admin"
:
{
ModelUser
:
crud
,
ModelUsers
:
crud
,
ModelScenario
:
crud
,
Model
SimulationModel
:
crud
,
Model
Simulator
:
crud
,
Model
Simulator
Action
:
crud
,
ModelWidget
:
crud
,
ModelDashboard
:
crud
,
ModelSignal
:
crud
,
ModelFile
:
crud
,
ModelUser
:
crud
,
ModelUsers
:
crud
,
ModelScenario
:
crud
,
Model
ComponentConfiguration
:
crud
,
Model
InfrastructureComponent
:
crud
,
Model
InfrastructureComponent
Action
:
crud
,
ModelWidget
:
crud
,
ModelDashboard
:
crud
,
ModelSignal
:
crud
,
ModelFile
:
crud
,
},
"User"
:
{
ModelUser
:
_ru_
,
ModelUsers
:
none
,
ModelScenario
:
crud
,
Model
SimulationModel
:
crud
,
Model
Simulator
:
_r__
,
Model
Simulator
Action
:
_ru_
,
ModelWidget
:
crud
,
ModelDashboard
:
crud
,
ModelSignal
:
crud
,
ModelFile
:
crud
,
ModelUser
:
_ru_
,
ModelUsers
:
none
,
ModelScenario
:
crud
,
Model
ComponentConfiguration
:
crud
,
Model
InfrastructureComponent
:
_r__
,
Model
InfrastructureComponent
Action
:
_ru_
,
ModelWidget
:
crud
,
ModelDashboard
:
crud
,
ModelSignal
:
crud
,
ModelFile
:
crud
,
},