mirror of
https://git.rwth-aachen.de/acs/public/villas/web-backend-go/
synced 2025-03-30 00:00:12 +01:00
rename simulator to infrastructure component
This commit is contained in:
parent
9539c42e0b
commit
11a0c53b85
26 changed files with 2166 additions and 2096 deletions
|
@ -115,10 +115,10 @@ test:widget:
|
||||||
variables:
|
variables:
|
||||||
TEST_FOLDER: routes/widget
|
TEST_FOLDER: routes/widget
|
||||||
|
|
||||||
test:simulator:
|
test:infrastructure-component:
|
||||||
extends: test:database
|
extends: test:database
|
||||||
variables:
|
variables:
|
||||||
TEST_FOLDER: routes/simulator
|
TEST_FOLDER: routes/infrastructure-component
|
||||||
|
|
||||||
test:file:
|
test:file:
|
||||||
extends: test:database
|
extends: test:database
|
||||||
|
|
|
@ -24,32 +24,32 @@ package amqp
|
||||||
import (
|
import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"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/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"
|
"github.com/gin-gonic/gin"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterAMQPEndpoint(r *gin.RouterGroup) {
|
func RegisterAMQPEndpoint(r *gin.RouterGroup) {
|
||||||
r.POST("/:simulatorID/action", sendActionToSimulator)
|
r.POST("/ICID/action", sendActionToIC)
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendActionToSimulator godoc
|
// sendActionToIC godoc
|
||||||
// @Summary Send an action to simulator (only available if backend server is started with -amqp parameter)
|
// @Summary Send an action to IC (only available if backend server is started with -amqp parameter)
|
||||||
// @ID sendActionToSimulator
|
// @ID sendActionToIC
|
||||||
// @Tags AMQP
|
// @Tags AMQP
|
||||||
// @Produce json
|
// @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"
|
// @Success 200 {object} docs.ResponseError "Action sent successfully"
|
||||||
// @Failure 400 {object} docs.ResponseError "Bad request"
|
// @Failure 400 {object} docs.ResponseError "Bad request"
|
||||||
// @Failure 404 {object} docs.ResponseError "Not found"
|
// @Failure 404 {object} docs.ResponseError "Not found"
|
||||||
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
||||||
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
||||||
// @Param simulatorID path int true "Simulator ID"
|
// @Param ICID path int true "InfrastructureComponent ID"
|
||||||
// @Router /simulators/{simulatorID}/action [post]
|
// @Router /ic/{ICID}/action [post]
|
||||||
func sendActionToSimulator(c *gin.Context) {
|
func sendActionToIC(c *gin.Context) {
|
||||||
|
|
||||||
ok, s := simulator.CheckPermissions(c, database.ModelSimulatorAction, database.Update, true)
|
ok, s := infrastructure_component.CheckPermissions(c, database.ModelInfrastructureComponentAction, database.Update, true)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func sendActionToSimulator(c *gin.Context) {
|
||||||
|
|
||||||
err = SendActionAMQP(action, s.UUID)
|
err = SendActionAMQP(action, s.UUID)
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,8 @@ func ConnectAMQP(uri string) error {
|
||||||
return fmt.Errorf("AMQP: failed to declare the exchange")
|
return fmt.Errorf("AMQP: failed to declare the exchange")
|
||||||
}
|
}
|
||||||
|
|
||||||
// add a queue for the simulators
|
// add a queue for the ICs
|
||||||
simulatorQueue, err := client.channel.QueueDeclare("simulators",
|
ICQueue, err := client.channel.QueueDeclare("infrastructure_components",
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
@ -88,13 +88,13 @@ func ConnectAMQP(uri string) error {
|
||||||
return fmt.Errorf("AMQP: failed to declare the queue")
|
return fmt.Errorf("AMQP: failed to declare the queue")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = client.channel.QueueBind(simulatorQueue.Name, "", VILLAS_EXCHANGE, false, nil)
|
err = client.channel.QueueBind(ICQueue.Name, "", VILLAS_EXCHANGE, false, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("AMQP: failed to bind the queue")
|
return fmt.Errorf("AMQP: failed to bind the queue")
|
||||||
}
|
}
|
||||||
|
|
||||||
// consume deliveries
|
// consume deliveries
|
||||||
client.replies, err = client.channel.Consume(simulatorQueue.Name,
|
client.replies, err = client.channel.Consume(ICQueue.Name,
|
||||||
"",
|
"",
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
|
@ -120,15 +120,15 @@ func ConnectAMQP(uri string) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
var sToBeUpdated database.Simulator
|
var sToBeUpdated database.InfrastructureComponent
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
simulatorUUID := gjson.Get(content, "properties.uuid").String()
|
ICUUID := gjson.Get(content, "properties.uuid").String()
|
||||||
if simulatorUUID == "" {
|
if ICUUID == "" {
|
||||||
log.Println("AMQP: Could not extract UUID of simulator from content of received message, SIMULATOR NOT UPDATED")
|
log.Println("AMQP: Could not extract UUID of IC from content of received message, COMPONENT NOT UPDATED")
|
||||||
} else {
|
} else {
|
||||||
err = db.Where("UUID = ?", simulatorUUID).Find(sToBeUpdated).Error
|
err = db.Where("UUID = ?", ICUUID).Find(sToBeUpdated).Error
|
||||||
if err != nil {
|
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{}{
|
err = db.Model(&sToBeUpdated).Updates(map[string]interface{}{
|
||||||
|
@ -140,10 +140,10 @@ func ConnectAMQP(uri string) error {
|
||||||
"RawProperties": gjson.Get(content, "properties"),
|
"RawProperties": gjson.Get(content, "properties"),
|
||||||
}).Error
|
}).Error
|
||||||
if err != nil {
|
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 {
|
func PingAMQP() error {
|
||||||
log.Println("AMQP: sending ping command to all simulators")
|
log.Println("AMQP: sending ping command to all ICs")
|
||||||
|
|
||||||
var a Action
|
var a Action
|
||||||
a.Act = "ping"
|
a.Act = "ping"
|
||||||
|
|
|
@ -55,9 +55,9 @@ read_users () {
|
||||||
-X GET | jq '.' && printf '\n'
|
-X GET | jq '.' && printf '\n'
|
||||||
}
|
}
|
||||||
|
|
||||||
read_simulators () {
|
read_infrastructure_components () {
|
||||||
printf "> GET "$apiBase"/simulators\n"
|
printf "> GET "$apiBase"/ic\n"
|
||||||
curl "$apiBase"/simulators -s \
|
curl "$apiBase"/ic -s \
|
||||||
-H "Contet-Type: application/json" \
|
-H "Contet-Type: application/json" \
|
||||||
-H "Authorization: Bearer $(< auth.jwt)" \
|
-H "Authorization: Bearer $(< auth.jwt)" \
|
||||||
-X GET | jq '.' && printf '\n'
|
-X GET | jq '.' && printf '\n'
|
||||||
|
@ -114,7 +114,7 @@ login "$admin"
|
||||||
#create_user "$userC"
|
#create_user "$userC"
|
||||||
#read_users
|
#read_users
|
||||||
#read_user 1
|
#read_user 1
|
||||||
#read_simulators
|
#read_infrastructure_components
|
||||||
create_user "$newUserW"
|
create_user "$newUserW"
|
||||||
#read_users
|
#read_users
|
||||||
read_user 4
|
read_user 4
|
||||||
|
|
|
@ -102,7 +102,7 @@ func GetDB() *gorm.DB {
|
||||||
// TODO: Remove that function from the codebase and substitute the body
|
// TODO: Remove that function from the codebase and substitute the body
|
||||||
// to the Dummy*() where it is called
|
// to the Dummy*() where it is called
|
||||||
func DropTables(db *gorm.DB) {
|
func DropTables(db *gorm.DB) {
|
||||||
db.DropTableIfExists(&Simulator{})
|
db.DropTableIfExists(&InfrastructureComponent{})
|
||||||
db.DropTableIfExists(&Signal{})
|
db.DropTableIfExists(&Signal{})
|
||||||
db.DropTableIfExists(&SimulationModel{})
|
db.DropTableIfExists(&SimulationModel{})
|
||||||
db.DropTableIfExists(&File{})
|
db.DropTableIfExists(&File{})
|
||||||
|
@ -116,7 +116,7 @@ func DropTables(db *gorm.DB) {
|
||||||
|
|
||||||
// AutoMigrate the models
|
// AutoMigrate the models
|
||||||
func MigrateModels(db *gorm.DB) {
|
func MigrateModels(db *gorm.DB) {
|
||||||
db.AutoMigrate(&Simulator{})
|
db.AutoMigrate(&InfrastructureComponent{})
|
||||||
db.AutoMigrate(&Signal{})
|
db.AutoMigrate(&Signal{})
|
||||||
db.AutoMigrate(&SimulationModel{})
|
db.AutoMigrate(&SimulationModel{})
|
||||||
db.AutoMigrate(&File{})
|
db.AutoMigrate(&File{})
|
||||||
|
|
|
@ -173,38 +173,38 @@ func TestScenarioAssociations(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSimulatorAssociations(t *testing.T) {
|
func TestICAssociations(t *testing.T) {
|
||||||
|
|
||||||
DropTables(db)
|
DropTables(db)
|
||||||
MigrateModels(db)
|
MigrateModels(db)
|
||||||
|
|
||||||
// create copies of global test data
|
// create copies of global test data
|
||||||
simulatorA := SimulatorA
|
icA := ICA
|
||||||
simulatorB := SimulatorB
|
icB := ICB
|
||||||
modelA := SimulationModelA
|
modelA := SimulationModelA
|
||||||
modelB := SimulationModelB
|
modelB := SimulationModelB
|
||||||
|
|
||||||
// add simulators to DB
|
// add ICs to DB
|
||||||
assert.NoError(t, db.Create(&simulatorA).Error)
|
assert.NoError(t, db.Create(&icA).Error)
|
||||||
assert.NoError(t, db.Create(&simulatorB).Error)
|
assert.NoError(t, db.Create(&icB).Error)
|
||||||
|
|
||||||
// add simulation models to DB
|
// add simulation models to DB
|
||||||
assert.NoError(t, db.Create(&modelA).Error)
|
assert.NoError(t, db.Create(&modelA).Error)
|
||||||
assert.NoError(t, db.Create(&modelB).Error)
|
assert.NoError(t, db.Create(&modelB).Error)
|
||||||
|
|
||||||
// add simulator has many simulation models association to DB
|
// add IC has many simulation models association to DB
|
||||||
assert.NoError(t, db.Model(&simulatorA).Association("SimulationModels").Append(&modelA).Error)
|
assert.NoError(t, db.Model(&icA).Association("SimulationModels").Append(&modelA).Error)
|
||||||
assert.NoError(t, db.Model(&simulatorA).Association("SimulationModels").Append(&modelB).Error)
|
assert.NoError(t, db.Model(&icA).Association("SimulationModels").Append(&modelB).Error)
|
||||||
|
|
||||||
var simulator1 Simulator
|
var ic1 InfrastructureComponent
|
||||||
assert.NoError(t, db.Find(&simulator1, 1).Error, fmt.Sprintf("Find Simulator with ID=1"))
|
assert.NoError(t, db.Find(&ic1, 1).Error, fmt.Sprintf("Find InfrastructureComponent with ID=1"))
|
||||||
assert.EqualValues(t, "Host_A", simulator1.Host)
|
assert.EqualValues(t, "Host_A", ic1.Host)
|
||||||
|
|
||||||
// Get simulation models of simulator1
|
// Get simulation models of ic1
|
||||||
var models []SimulationModel
|
var models []SimulationModel
|
||||||
assert.NoError(t, db.Model(&simulator1).Association("SimulationModels").Find(&models).Error)
|
assert.NoError(t, db.Model(&ic1).Association("SimulationModels").Find(&models).Error)
|
||||||
if len(models) != 2 {
|
if len(models) != 2 {
|
||||||
assert.Fail(t, "Simulator Associations",
|
assert.Fail(t, "InfrastructureComponent Associations",
|
||||||
"Expected to have %v SimulationModels. Has %v.", 2, len(models))
|
"Expected to have %v SimulationModels. Has %v.", 2, len(models))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,8 +225,8 @@ func TestSimulationModelAssociations(t *testing.T) {
|
||||||
fileB := FileB
|
fileB := FileB
|
||||||
fileC := FileC
|
fileC := FileC
|
||||||
fileD := FileD
|
fileD := FileD
|
||||||
simulatorA := SimulatorA
|
icA := ICA
|
||||||
simulatorB := SimulatorB
|
icB := ICB
|
||||||
|
|
||||||
// add simulation models to DB
|
// add simulation models to DB
|
||||||
assert.NoError(t, db.Create(&modelA).Error)
|
assert.NoError(t, db.Create(&modelA).Error)
|
||||||
|
@ -244,9 +244,9 @@ func TestSimulationModelAssociations(t *testing.T) {
|
||||||
assert.NoError(t, db.Create(&fileC).Error)
|
assert.NoError(t, db.Create(&fileC).Error)
|
||||||
assert.NoError(t, db.Create(&fileD).Error)
|
assert.NoError(t, db.Create(&fileD).Error)
|
||||||
|
|
||||||
// add simulators to DB
|
// add ICs to DB
|
||||||
assert.NoError(t, db.Create(&simulatorA).Error)
|
assert.NoError(t, db.Create(&icA).Error)
|
||||||
assert.NoError(t, db.Create(&simulatorB).Error)
|
assert.NoError(t, db.Create(&icB).Error)
|
||||||
|
|
||||||
// add simulation model has many signals associations
|
// add simulation model has many signals associations
|
||||||
assert.NoError(t, db.Model(&modelA).Association("InputMapping").Append(&inSignalA).Error)
|
assert.NoError(t, db.Model(&modelA).Association("InputMapping").Append(&inSignalA).Error)
|
||||||
|
@ -258,17 +258,17 @@ func TestSimulationModelAssociations(t *testing.T) {
|
||||||
assert.NoError(t, db.Model(&modelA).Association("Files").Append(&fileC).Error)
|
assert.NoError(t, db.Model(&modelA).Association("Files").Append(&fileC).Error)
|
||||||
assert.NoError(t, db.Model(&modelA).Association("Files").Append(&fileD).Error)
|
assert.NoError(t, db.Model(&modelA).Association("Files").Append(&fileD).Error)
|
||||||
|
|
||||||
// associate simulation models with simulators
|
// associate simulation models with IC
|
||||||
assert.NoError(t, db.Model(&simulatorA).Association("SimulationModels").Append(&modelA).Error)
|
assert.NoError(t, db.Model(&icA).Association("SimulationModels").Append(&modelA).Error)
|
||||||
assert.NoError(t, db.Model(&simulatorA).Association("SimulationModels").Append(&modelB).Error)
|
assert.NoError(t, db.Model(&icA).Association("SimulationModels").Append(&modelB).Error)
|
||||||
|
|
||||||
var model1 SimulationModel
|
var model1 SimulationModel
|
||||||
assert.NoError(t, db.Find(&model1, 1).Error, fmt.Sprintf("Find SimulationModel with ID=1"))
|
assert.NoError(t, db.Find(&model1, 1).Error, fmt.Sprintf("Find SimulationModel with ID=1"))
|
||||||
assert.EqualValues(t, "SimulationModel_A", model1.Name)
|
assert.EqualValues(t, "SimulationModel_A", model1.Name)
|
||||||
|
|
||||||
// Check simulator ID
|
// Check IC ID
|
||||||
if model1.SimulatorID != 1 {
|
if model1.ICID != 1 {
|
||||||
assert.Fail(t, "Simulation Model expected to have Simulator ID 1, but is %v", model1.SimulatorID)
|
assert.Fail(t, "Simulation Model expected to have InfrastructureComponent ID 1, but is %v", model1.ICID)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get OutputMapping signals of model1
|
// Get OutputMapping signals of model1
|
||||||
|
|
|
@ -84,8 +84,8 @@ type SimulationModel struct {
|
||||||
StartParameters postgres.Jsonb `json:"startParameters"`
|
StartParameters postgres.Jsonb `json:"startParameters"`
|
||||||
// ID of Scenario to which simulation model belongs
|
// ID of Scenario to which simulation model belongs
|
||||||
ScenarioID uint `json:"scenarioID"`
|
ScenarioID uint `json:"scenarioID"`
|
||||||
// ID of simulator associated with simulation model
|
// ID of IC associated with simulation model
|
||||||
SimulatorID uint `json:"simulatorID"`
|
ICID uint `json:"icID"`
|
||||||
// Mapping of output signals of the simulation model, order of signals is important
|
// Mapping of output signals of the simulation model, order of signals is important
|
||||||
OutputMapping []Signal `json:"-" gorm:"foreignkey:SimulationModelID"`
|
OutputMapping []Signal `json:"-" gorm:"foreignkey:SimulationModelID"`
|
||||||
// Mapping of input signals of the simulation model, order of signals is important
|
// Mapping of input signals of the simulation model, order of signals is important
|
||||||
|
@ -111,27 +111,27 @@ type Signal struct {
|
||||||
SimulationModelID uint `json:"simulationModelID"`
|
SimulationModelID uint `json:"simulationModelID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Simulator data model
|
// InfrastructureComponent data model
|
||||||
type Simulator struct {
|
type InfrastructureComponent struct {
|
||||||
Model
|
Model
|
||||||
// UUID of the simulator
|
// UUID of the IC
|
||||||
UUID string `json:"uuid" gorm:"not null"`
|
UUID string `json:"uuid" gorm:"not null"`
|
||||||
// Host if the simulator
|
// Host if the IC
|
||||||
Host string `json:"host" gorm:"default:''"`
|
Host string `json:"host" gorm:"default:''"`
|
||||||
// Model type supported by the simulator
|
// Model type supported by the IC
|
||||||
Modeltype string `json:"modelType" gorm:"default:''"`
|
Modeltype string `json:"modelType" gorm:"default:''"`
|
||||||
// Uptime of the simulator
|
// Uptime of the IC
|
||||||
Uptime int `json:"uptime" gorm:"default:0"`
|
Uptime int `json:"uptime" gorm:"default:0"`
|
||||||
// State of the simulator
|
// State of the IC
|
||||||
State string `json:"state" gorm:"default:''"`
|
State string `json:"state" gorm:"default:''"`
|
||||||
// Time of last state update
|
// Time of last state update
|
||||||
StateUpdateAt string `json:"stateUpdateAt" gorm:"default:''"`
|
StateUpdateAt string `json:"stateUpdateAt" gorm:"default:''"`
|
||||||
// Properties of simulator as JSON string
|
// Properties of IC as JSON string
|
||||||
Properties postgres.Jsonb `json:"properties"`
|
Properties postgres.Jsonb `json:"properties"`
|
||||||
// Raw properties of simulator as JSON string
|
// Raw properties of IC as JSON string
|
||||||
RawProperties postgres.Jsonb `json:"rawProperties"`
|
RawProperties postgres.Jsonb `json:"rawProperties"`
|
||||||
// SimulationModels in which the simulator is used
|
// SimulationModels in which the IC is used
|
||||||
SimulationModels []SimulationModel `json:"-" gorm:"foreignkey:SimulatorID"`
|
SimulationModels []SimulationModel `json:"-" gorm:"foreignkey:ICID"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dashboard data model
|
// Dashboard data model
|
||||||
|
|
|
@ -38,8 +38,8 @@ type ModelName string
|
||||||
const ModelUser = ModelName("user")
|
const ModelUser = ModelName("user")
|
||||||
const ModelUsers = ModelName("users")
|
const ModelUsers = ModelName("users")
|
||||||
const ModelScenario = ModelName("scenario")
|
const ModelScenario = ModelName("scenario")
|
||||||
const ModelSimulator = ModelName("simulator")
|
const ModelInfrastructureComponent = ModelName("ic")
|
||||||
const ModelSimulatorAction = ModelName("simulatoraction")
|
const ModelInfrastructureComponentAction = ModelName("icaction")
|
||||||
const ModelDashboard = ModelName("dashboard")
|
const ModelDashboard = ModelName("dashboard")
|
||||||
const ModelWidget = ModelName("widget")
|
const ModelWidget = ModelName("widget")
|
||||||
const ModelSimulationModel = ModelName("simulationmodel")
|
const ModelSimulationModel = ModelName("simulationmodel")
|
||||||
|
@ -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
|
// allowed to do a certain action on a given model based on his role
|
||||||
var Roles = RoleActions{
|
var Roles = RoleActions{
|
||||||
"Admin": {
|
"Admin": {
|
||||||
ModelUser: crud,
|
ModelUser: crud,
|
||||||
ModelUsers: crud,
|
ModelUsers: crud,
|
||||||
ModelScenario: crud,
|
ModelScenario: crud,
|
||||||
ModelSimulationModel: crud,
|
ModelSimulationModel: crud,
|
||||||
ModelSimulator: crud,
|
ModelInfrastructureComponent: crud,
|
||||||
ModelSimulatorAction: crud,
|
ModelInfrastructureComponentAction: crud,
|
||||||
ModelWidget: crud,
|
ModelWidget: crud,
|
||||||
ModelDashboard: crud,
|
ModelDashboard: crud,
|
||||||
ModelSignal: crud,
|
ModelSignal: crud,
|
||||||
ModelFile: crud,
|
ModelFile: crud,
|
||||||
},
|
},
|
||||||
"User": {
|
"User": {
|
||||||
ModelUser: _ru_,
|
ModelUser: _ru_,
|
||||||
ModelUsers: none,
|
ModelUsers: none,
|
||||||
ModelScenario: crud,
|
ModelScenario: crud,
|
||||||
ModelSimulationModel: crud,
|
ModelSimulationModel: crud,
|
||||||
ModelSimulator: _r__,
|
ModelInfrastructureComponent: _r__,
|
||||||
ModelSimulatorAction: _ru_,
|
ModelInfrastructureComponentAction: _ru_,
|
||||||
ModelWidget: crud,
|
ModelWidget: crud,
|
||||||
ModelDashboard: crud,
|
ModelDashboard: crud,
|
||||||
ModelSignal: crud,
|
ModelSignal: crud,
|
||||||
ModelFile: crud,
|
ModelFile: crud,
|
||||||
},
|
},
|
||||||
"Guest": {
|
"Guest": {
|
||||||
ModelScenario: _r__,
|
ModelScenario: _r__,
|
||||||
ModelSimulationModel: _r__,
|
ModelSimulationModel: _r__,
|
||||||
ModelDashboard: _r__,
|
ModelDashboard: _r__,
|
||||||
ModelWidget: _r__,
|
ModelWidget: _r__,
|
||||||
ModelSimulator: _r__,
|
ModelInfrastructureComponent: _r__,
|
||||||
ModelSimulatorAction: _r__,
|
ModelInfrastructureComponentAction: _r__,
|
||||||
ModelUser: _ru_,
|
ModelUser: _ru_,
|
||||||
ModelUsers: none,
|
ModelUsers: none,
|
||||||
ModelSignal: _r__,
|
ModelSignal: _r__,
|
||||||
ModelFile: _r__,
|
ModelFile: _r__,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,12 +55,12 @@ var UserB = User{Username: "User_B", Password: string(pwB),
|
||||||
var UserC = User{Username: "User_C", Password: string(pwC),
|
var UserC = User{Username: "User_C", Password: string(pwC),
|
||||||
Role: "Guest", Mail: "User_C@example.com", Active: true}
|
Role: "Guest", Mail: "User_C@example.com", Active: true}
|
||||||
|
|
||||||
// Simulators
|
// Infrastructure components
|
||||||
|
|
||||||
var propertiesA = json.RawMessage(`{"name" : "TestNameA", "category" : "CategoryA", "location" : "anywhere on earth", "type": "dummy"}`)
|
var propertiesA = json.RawMessage(`{"name" : "DPsim simulator", "category" : "Simulator", "location" : "ACSlab", "type": "DPsim"}`)
|
||||||
var propertiesB = json.RawMessage(`{"name" : "TestNameB", "category" : "CategoryB", "location" : "where ever you want", "type": "generic"}`)
|
var propertiesB = json.RawMessage(`{"name" : "VILLASnode gateway", "category" : "Gateway", "location" : "ACSlab", "type": "VILLASnode"}`)
|
||||||
|
|
||||||
var SimulatorA = Simulator{
|
var ICA = InfrastructureComponent{
|
||||||
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
|
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
|
||||||
Host: "Host_A",
|
Host: "Host_A",
|
||||||
Modeltype: "ModelTypeA",
|
Modeltype: "ModelTypeA",
|
||||||
|
@ -71,7 +71,7 @@ var SimulatorA = Simulator{
|
||||||
RawProperties: postgres.Jsonb{propertiesA},
|
RawProperties: postgres.Jsonb{propertiesA},
|
||||||
}
|
}
|
||||||
|
|
||||||
var SimulatorB = Simulator{
|
var ICB = InfrastructureComponent{
|
||||||
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
|
||||||
Host: "Host_B",
|
Host: "Host_B",
|
||||||
Modeltype: "ModelTypeB",
|
Modeltype: "ModelTypeB",
|
||||||
|
@ -316,8 +316,8 @@ func DBAddTestData(db *gorm.DB) error {
|
||||||
userB := UserB
|
userB := UserB
|
||||||
userC := UserC
|
userC := UserC
|
||||||
|
|
||||||
simulatorA := SimulatorA
|
ICA := ICA
|
||||||
simulatorB := SimulatorB
|
ICB := ICB
|
||||||
|
|
||||||
scenarioA := ScenarioA
|
scenarioA := ScenarioA
|
||||||
scenarioB := ScenarioB
|
scenarioB := ScenarioB
|
||||||
|
@ -354,9 +354,9 @@ func DBAddTestData(db *gorm.DB) error {
|
||||||
// add Guest user to DB
|
// add Guest user to DB
|
||||||
err = db.Create(&userC).Error
|
err = db.Create(&userC).Error
|
||||||
|
|
||||||
// Simulators
|
// ICs
|
||||||
err = db.Create(&simulatorA).Error
|
err = db.Create(&ICA).Error
|
||||||
err = db.Create(&simulatorB).Error
|
err = db.Create(&ICB).Error
|
||||||
|
|
||||||
// Scenarios
|
// Scenarios
|
||||||
err = db.Create(&scenarioA).Error
|
err = db.Create(&scenarioA).Error
|
||||||
|
@ -425,9 +425,9 @@ func DBAddTestData(db *gorm.DB) error {
|
||||||
err = db.Model(&modelA).Association("Files").Append(&fileC).Error
|
err = db.Model(&modelA).Association("Files").Append(&fileC).Error
|
||||||
err = db.Model(&modelA).Association("Files").Append(&fileD).Error
|
err = db.Model(&modelA).Association("Files").Append(&fileD).Error
|
||||||
|
|
||||||
// Simulator HM SimulationModels
|
// InfrastructureComponent HM SimulationModels
|
||||||
err = db.Model(&simulatorA).Association("SimulationModels").Append(&modelA).Error
|
err = db.Model(&ICA).Association("SimulationModels").Append(&modelA).Error
|
||||||
err = db.Model(&simulatorA).Association("SimulationModels").Append(&modelB).Error
|
err = db.Model(&ICA).Association("SimulationModels").Append(&modelB).Error
|
||||||
|
|
||||||
// Widget HM Files
|
// Widget HM Files
|
||||||
err = db.Model(&widgetA).Association("Files").Append(&fileA).Error
|
err = db.Model(&widgetA).Association("Files").Append(&fileA).Error
|
||||||
|
|
1196
doc/api/docs.go
1196
doc/api/docs.go
File diff suppressed because it is too large
Load diff
|
@ -46,12 +46,12 @@ type ResponseUser struct {
|
||||||
user database.User
|
user database.User
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseSimulators struct {
|
type ResponseICs struct {
|
||||||
simulators []database.Simulator
|
ics []database.InfrastructureComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseSimulator struct {
|
type ResponseIC struct {
|
||||||
simulator database.Simulator
|
ic database.InfrastructureComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
type ResponseScenarios struct {
|
type ResponseScenarios struct {
|
||||||
|
|
1194
doc/api/swagger.json
1194
doc/api/swagger.json
File diff suppressed because it is too large
Load diff
|
@ -75,6 +75,35 @@ definitions:
|
||||||
description: ID of widget to which file belongs
|
description: ID of widget to which file belongs
|
||||||
type: integer
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
|
database.InfrastructureComponent:
|
||||||
|
properties:
|
||||||
|
host:
|
||||||
|
description: Host if the IC
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
modelType:
|
||||||
|
description: Model type supported by the IC
|
||||||
|
type: string
|
||||||
|
properties:
|
||||||
|
description: Properties of IC as JSON string
|
||||||
|
type: string
|
||||||
|
rawProperties:
|
||||||
|
description: Raw properties of IC as JSON string
|
||||||
|
type: string
|
||||||
|
state:
|
||||||
|
description: State of the IC
|
||||||
|
type: string
|
||||||
|
stateUpdateAt:
|
||||||
|
description: Time of last state update
|
||||||
|
type: string
|
||||||
|
uptime:
|
||||||
|
description: Uptime of the IC
|
||||||
|
type: integer
|
||||||
|
uuid:
|
||||||
|
description: UUID of the IC
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
database.Scenario:
|
database.Scenario:
|
||||||
properties:
|
properties:
|
||||||
id:
|
id:
|
||||||
|
@ -111,6 +140,9 @@ definitions:
|
||||||
type: object
|
type: object
|
||||||
database.SimulationModel:
|
database.SimulationModel:
|
||||||
properties:
|
properties:
|
||||||
|
icID:
|
||||||
|
description: ID of IC associated with simulation model
|
||||||
|
type: integer
|
||||||
id:
|
id:
|
||||||
type: integer
|
type: integer
|
||||||
inputLength:
|
inputLength:
|
||||||
|
@ -125,42 +157,13 @@ definitions:
|
||||||
scenarioID:
|
scenarioID:
|
||||||
description: ID of Scenario to which simulation model belongs
|
description: ID of Scenario to which simulation model belongs
|
||||||
type: integer
|
type: integer
|
||||||
simulatorID:
|
selectedModelFileID:
|
||||||
description: ID of simulator associated with simulation model
|
description: Currently selected simulation model FileID
|
||||||
type: integer
|
type: integer
|
||||||
startParameters:
|
startParameters:
|
||||||
description: Start parameters of simulation model as JSON
|
description: Start parameters of simulation model as JSON
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
database.Simulator:
|
|
||||||
properties:
|
|
||||||
host:
|
|
||||||
description: Host if the simulator
|
|
||||||
type: string
|
|
||||||
id:
|
|
||||||
type: integer
|
|
||||||
modelType:
|
|
||||||
description: Model type supported by the simulator
|
|
||||||
type: string
|
|
||||||
properties:
|
|
||||||
description: Properties of simulator as JSON string
|
|
||||||
type: string
|
|
||||||
rawProperties:
|
|
||||||
description: Raw properties of simulator as JSON string
|
|
||||||
type: string
|
|
||||||
state:
|
|
||||||
description: State of the simulator
|
|
||||||
type: string
|
|
||||||
stateUpdateAt:
|
|
||||||
description: Time of last state update
|
|
||||||
type: string
|
|
||||||
uptime:
|
|
||||||
description: Uptime of the simulator
|
|
||||||
type: integer
|
|
||||||
uuid:
|
|
||||||
description: UUID of the simulator
|
|
||||||
type: string
|
|
||||||
type: object
|
|
||||||
database.User:
|
database.User:
|
||||||
properties:
|
properties:
|
||||||
active:
|
active:
|
||||||
|
@ -204,6 +207,9 @@ definitions:
|
||||||
name:
|
name:
|
||||||
description: Name of widget
|
description: Name of widget
|
||||||
type: string
|
type: string
|
||||||
|
signalIDs:
|
||||||
|
description: IDs of signals that widget uses
|
||||||
|
type: string
|
||||||
type:
|
type:
|
||||||
description: Type of widget
|
description: Type of widget
|
||||||
type: string
|
type: string
|
||||||
|
@ -265,6 +271,19 @@ definitions:
|
||||||
$ref: '#/definitions/database.File'
|
$ref: '#/definitions/database.File'
|
||||||
type: array
|
type: array
|
||||||
type: object
|
type: object
|
||||||
|
docs.ResponseIC:
|
||||||
|
properties:
|
||||||
|
ic:
|
||||||
|
$ref: '#/definitions/database.InfrastructureComponent'
|
||||||
|
type: object
|
||||||
|
type: object
|
||||||
|
docs.ResponseICs:
|
||||||
|
properties:
|
||||||
|
ics:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/database.InfrastructureComponent'
|
||||||
|
type: array
|
||||||
|
type: object
|
||||||
docs.ResponseScenario:
|
docs.ResponseScenario:
|
||||||
properties:
|
properties:
|
||||||
scenario:
|
scenario:
|
||||||
|
@ -304,19 +323,6 @@ definitions:
|
||||||
$ref: '#/definitions/database.SimulationModel'
|
$ref: '#/definitions/database.SimulationModel'
|
||||||
type: array
|
type: array
|
||||||
type: object
|
type: object
|
||||||
docs.ResponseSimulator:
|
|
||||||
properties:
|
|
||||||
simulator:
|
|
||||||
$ref: '#/definitions/database.Simulator'
|
|
||||||
type: object
|
|
||||||
type: object
|
|
||||||
docs.ResponseSimulators:
|
|
||||||
properties:
|
|
||||||
simulators:
|
|
||||||
items:
|
|
||||||
$ref: '#/definitions/database.Simulator'
|
|
||||||
type: array
|
|
||||||
type: object
|
|
||||||
docs.ResponseUser:
|
docs.ResponseUser:
|
||||||
properties:
|
properties:
|
||||||
user:
|
user:
|
||||||
|
@ -343,6 +349,49 @@ definitions:
|
||||||
$ref: '#/definitions/database.Widget'
|
$ref: '#/definitions/database.Widget'
|
||||||
type: array
|
type: array
|
||||||
type: object
|
type: object
|
||||||
|
infrastructure_component.addICRequest:
|
||||||
|
properties:
|
||||||
|
ic:
|
||||||
|
$ref: '#/definitions/infrastructure_component.validNewIC'
|
||||||
|
type: object
|
||||||
|
type: object
|
||||||
|
infrastructure_component.updateICRequest:
|
||||||
|
properties:
|
||||||
|
ic:
|
||||||
|
$ref: '#/definitions/infrastructure_component.validUpdatedIC'
|
||||||
|
type: object
|
||||||
|
type: object
|
||||||
|
infrastructure_component.validNewIC:
|
||||||
|
properties:
|
||||||
|
Host:
|
||||||
|
type: string
|
||||||
|
Modeltype:
|
||||||
|
type: string
|
||||||
|
Properties:
|
||||||
|
type: string
|
||||||
|
State:
|
||||||
|
type: string
|
||||||
|
UUID:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- Host
|
||||||
|
- Modeltype
|
||||||
|
- Properties
|
||||||
|
- UUID
|
||||||
|
type: object
|
||||||
|
infrastructure_component.validUpdatedIC:
|
||||||
|
properties:
|
||||||
|
Host:
|
||||||
|
type: string
|
||||||
|
Modeltype:
|
||||||
|
type: string
|
||||||
|
Properties:
|
||||||
|
type: string
|
||||||
|
State:
|
||||||
|
type: string
|
||||||
|
UUID:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
scenario.addScenarioRequest:
|
scenario.addScenarioRequest:
|
||||||
properties:
|
properties:
|
||||||
scenario:
|
scenario:
|
||||||
|
@ -429,72 +478,33 @@ definitions:
|
||||||
type: object
|
type: object
|
||||||
simulationmodel.validNewSimulationModel:
|
simulationmodel.validNewSimulationModel:
|
||||||
properties:
|
properties:
|
||||||
|
ICID:
|
||||||
|
type: integer
|
||||||
Name:
|
Name:
|
||||||
type: string
|
type: string
|
||||||
ScenarioID:
|
ScenarioID:
|
||||||
type: integer
|
type: integer
|
||||||
SimulatorID:
|
SelectedModelFileID:
|
||||||
type: integer
|
type: integer
|
||||||
StartParameters:
|
StartParameters:
|
||||||
type: string
|
type: string
|
||||||
required:
|
required:
|
||||||
|
- ICID
|
||||||
- Name
|
- Name
|
||||||
- ScenarioID
|
- ScenarioID
|
||||||
- SimulatorID
|
|
||||||
- StartParameters
|
- StartParameters
|
||||||
type: object
|
type: object
|
||||||
simulationmodel.validUpdatedSimulationModel:
|
simulationmodel.validUpdatedSimulationModel:
|
||||||
properties:
|
properties:
|
||||||
|
ICID:
|
||||||
|
type: integer
|
||||||
Name:
|
Name:
|
||||||
type: string
|
type: string
|
||||||
SimulatorID:
|
SelectedModelFileID:
|
||||||
type: integer
|
type: integer
|
||||||
StartParameters:
|
StartParameters:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
simulator.addSimulatorRequest:
|
|
||||||
properties:
|
|
||||||
simulator:
|
|
||||||
$ref: '#/definitions/simulator.validNewSimulator'
|
|
||||||
type: object
|
|
||||||
type: object
|
|
||||||
simulator.updateSimulatorRequest:
|
|
||||||
properties:
|
|
||||||
simulator:
|
|
||||||
$ref: '#/definitions/simulator.validUpdatedSimulator'
|
|
||||||
type: object
|
|
||||||
type: object
|
|
||||||
simulator.validNewSimulator:
|
|
||||||
properties:
|
|
||||||
Host:
|
|
||||||
type: string
|
|
||||||
Modeltype:
|
|
||||||
type: string
|
|
||||||
Properties:
|
|
||||||
type: string
|
|
||||||
State:
|
|
||||||
type: string
|
|
||||||
UUID:
|
|
||||||
type: string
|
|
||||||
required:
|
|
||||||
- Host
|
|
||||||
- Modeltype
|
|
||||||
- Properties
|
|
||||||
- UUID
|
|
||||||
type: object
|
|
||||||
simulator.validUpdatedSimulator:
|
|
||||||
properties:
|
|
||||||
Host:
|
|
||||||
type: string
|
|
||||||
Modeltype:
|
|
||||||
type: string
|
|
||||||
Properties:
|
|
||||||
type: string
|
|
||||||
State:
|
|
||||||
type: string
|
|
||||||
UUID:
|
|
||||||
type: string
|
|
||||||
type: object
|
|
||||||
user.addUserRequest:
|
user.addUserRequest:
|
||||||
properties:
|
properties:
|
||||||
user:
|
user:
|
||||||
|
@ -576,6 +586,10 @@ definitions:
|
||||||
type: integer
|
type: integer
|
||||||
Name:
|
Name:
|
||||||
type: string
|
type: string
|
||||||
|
SignalIDs:
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
type: array
|
||||||
Type:
|
Type:
|
||||||
type: string
|
type: string
|
||||||
Width:
|
Width:
|
||||||
|
@ -607,6 +621,10 @@ definitions:
|
||||||
type: integer
|
type: integer
|
||||||
Name:
|
Name:
|
||||||
type: string
|
type: string
|
||||||
|
SignalIDs:
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
type: array
|
||||||
Type:
|
Type:
|
||||||
type: string
|
type: string
|
||||||
Width:
|
Width:
|
||||||
|
@ -1171,6 +1189,322 @@ paths:
|
||||||
summary: Get health status of backend
|
summary: Get health status of backend
|
||||||
tags:
|
tags:
|
||||||
- healthz
|
- healthz
|
||||||
|
/ic:
|
||||||
|
get:
|
||||||
|
operationId: getICs
|
||||||
|
parameters:
|
||||||
|
- description: Authorization token
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: ICs requested
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseICs'
|
||||||
|
type: object
|
||||||
|
"404":
|
||||||
|
description: Not found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"422":
|
||||||
|
description: Unprocessable entity
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal server error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
summary: Get all infrastructure components
|
||||||
|
tags:
|
||||||
|
- infrastructure-components
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
operationId: addIC
|
||||||
|
parameters:
|
||||||
|
- description: Authorization token
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Infrastructure Component to be added
|
||||||
|
in: body
|
||||||
|
name: inputIC
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/infrastructure_component.addICRequest'
|
||||||
|
type: object
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Infrastructure Component that was added
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseIC'
|
||||||
|
type: object
|
||||||
|
"400":
|
||||||
|
description: Bad request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"404":
|
||||||
|
description: Not found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"422":
|
||||||
|
description: Unprocessable entity
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal server error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
summary: Add an infrastructure component
|
||||||
|
tags:
|
||||||
|
- infrastructure-components
|
||||||
|
/ic/{ICID}:
|
||||||
|
delete:
|
||||||
|
operationId: deleteIC
|
||||||
|
parameters:
|
||||||
|
- description: Authorization token
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Infrastructure Component ID
|
||||||
|
in: path
|
||||||
|
name: ICID
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Infrastructure Component that was deleted
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseIC'
|
||||||
|
type: object
|
||||||
|
"400":
|
||||||
|
description: Bad request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"404":
|
||||||
|
description: Not found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"422":
|
||||||
|
description: Unprocessable entity
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal server error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
summary: Delete an infrastructure component
|
||||||
|
tags:
|
||||||
|
- infrastructure-components
|
||||||
|
get:
|
||||||
|
operationId: getIC
|
||||||
|
parameters:
|
||||||
|
- description: Authorization token
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Infrastructure Component ID
|
||||||
|
in: path
|
||||||
|
name: ICID
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Infrastructure Component that was requested
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseIC'
|
||||||
|
type: object
|
||||||
|
"400":
|
||||||
|
description: Bad request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"404":
|
||||||
|
description: Not found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"422":
|
||||||
|
description: Unprocessable entity
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal server error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
summary: Get infrastructure component
|
||||||
|
tags:
|
||||||
|
- infrastructure-components
|
||||||
|
put:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
operationId: updateIC
|
||||||
|
parameters:
|
||||||
|
- description: Authorization token
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: InfrastructureComponent to be updated
|
||||||
|
in: body
|
||||||
|
name: inputIC
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/infrastructure_component.updateICRequest'
|
||||||
|
type: object
|
||||||
|
- description: InfrastructureComponent ID
|
||||||
|
in: path
|
||||||
|
name: ICID
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Infrastructure Component that was updated
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseIC'
|
||||||
|
type: object
|
||||||
|
"400":
|
||||||
|
description: Bad request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"404":
|
||||||
|
description: Not found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"422":
|
||||||
|
description: Unprocessable entity
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal server error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
summary: Update an infrastructure component
|
||||||
|
tags:
|
||||||
|
- infrastructure-components
|
||||||
|
/ic/{ICID}/action:
|
||||||
|
post:
|
||||||
|
operationId: sendActionToIC
|
||||||
|
parameters:
|
||||||
|
- description: Action for IC
|
||||||
|
in: query
|
||||||
|
name: inputAction
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: InfrastructureComponent ID
|
||||||
|
in: path
|
||||||
|
name: ICID
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Action sent successfully
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"400":
|
||||||
|
description: Bad request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"404":
|
||||||
|
description: Not found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"422":
|
||||||
|
description: Unprocessable entity
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal server error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
summary: Send an action to IC (only available if backend server is started with
|
||||||
|
-amqp parameter)
|
||||||
|
tags:
|
||||||
|
- AMQP
|
||||||
|
/ic/{ICID}/models:
|
||||||
|
get:
|
||||||
|
operationId: getConfigsOfIC
|
||||||
|
parameters:
|
||||||
|
- description: Authorization token
|
||||||
|
in: header
|
||||||
|
name: Authorization
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Infrastructure Component ID
|
||||||
|
in: path
|
||||||
|
name: ICID
|
||||||
|
required: true
|
||||||
|
type: integer
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Configs requested by user
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseSimulationModels'
|
||||||
|
type: object
|
||||||
|
"400":
|
||||||
|
description: Bad request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"404":
|
||||||
|
description: Not found
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"422":
|
||||||
|
description: Unprocessable entity
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
"500":
|
||||||
|
description: Internal server error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/docs.ResponseError'
|
||||||
|
type: object
|
||||||
|
summary: Get all configurations of the infrastructure component
|
||||||
|
tags:
|
||||||
|
- infrastructure-components
|
||||||
/metrics:
|
/metrics:
|
||||||
get:
|
get:
|
||||||
operationId: getMetrics
|
operationId: getMetrics
|
||||||
|
@ -1232,7 +1566,7 @@ paths:
|
||||||
name: Authorization
|
name: Authorization
|
||||||
required: true
|
required: true
|
||||||
type: string
|
type: string
|
||||||
- description: Simulation model to be added incl. IDs of scenario and simulator
|
- description: Simulation model to be added incl. IDs of scenario and IC
|
||||||
in: body
|
in: body
|
||||||
name: inputSimulationModel
|
name: inputSimulationModel
|
||||||
required: true
|
required: true
|
||||||
|
@ -1990,322 +2324,6 @@ paths:
|
||||||
summary: Update a signal
|
summary: Update a signal
|
||||||
tags:
|
tags:
|
||||||
- signals
|
- signals
|
||||||
/simulators:
|
|
||||||
get:
|
|
||||||
operationId: getSimulators
|
|
||||||
parameters:
|
|
||||||
- description: Authorization token
|
|
||||||
in: header
|
|
||||||
name: Authorization
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Simulators requested
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseSimulators'
|
|
||||||
type: object
|
|
||||||
"404":
|
|
||||||
description: Not found
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"422":
|
|
||||||
description: Unprocessable entity
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"500":
|
|
||||||
description: Internal server error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
summary: Get all simulators
|
|
||||||
tags:
|
|
||||||
- simulators
|
|
||||||
post:
|
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
operationId: addSimulator
|
|
||||||
parameters:
|
|
||||||
- description: Authorization token
|
|
||||||
in: header
|
|
||||||
name: Authorization
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
- description: Simulator to be added
|
|
||||||
in: body
|
|
||||||
name: inputSimulator
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/simulator.addSimulatorRequest'
|
|
||||||
type: object
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Simulator that was added
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseSimulator'
|
|
||||||
type: object
|
|
||||||
"400":
|
|
||||||
description: Bad request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"404":
|
|
||||||
description: Not found
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"422":
|
|
||||||
description: Unprocessable entity
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"500":
|
|
||||||
description: Internal server error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
summary: Add a simulator
|
|
||||||
tags:
|
|
||||||
- simulators
|
|
||||||
/simulators/{simulatorID}:
|
|
||||||
delete:
|
|
||||||
operationId: deleteSimulator
|
|
||||||
parameters:
|
|
||||||
- description: Authorization token
|
|
||||||
in: header
|
|
||||||
name: Authorization
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
- description: Simulator ID
|
|
||||||
in: path
|
|
||||||
name: simulatorID
|
|
||||||
required: true
|
|
||||||
type: integer
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Simulator that was deleted
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseSimulator'
|
|
||||||
type: object
|
|
||||||
"400":
|
|
||||||
description: Bad request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"404":
|
|
||||||
description: Not found
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"422":
|
|
||||||
description: Unprocessable entity
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"500":
|
|
||||||
description: Internal server error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
summary: Delete a simulator
|
|
||||||
tags:
|
|
||||||
- simulators
|
|
||||||
get:
|
|
||||||
operationId: getSimulator
|
|
||||||
parameters:
|
|
||||||
- description: Authorization token
|
|
||||||
in: header
|
|
||||||
name: Authorization
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
- description: Simulator ID
|
|
||||||
in: path
|
|
||||||
name: simulatorID
|
|
||||||
required: true
|
|
||||||
type: integer
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Simulator that was requested
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseSimulator'
|
|
||||||
type: object
|
|
||||||
"400":
|
|
||||||
description: Bad request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"404":
|
|
||||||
description: Not found
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"422":
|
|
||||||
description: Unprocessable entity
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"500":
|
|
||||||
description: Internal server error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
summary: Get simulator
|
|
||||||
tags:
|
|
||||||
- simulators
|
|
||||||
put:
|
|
||||||
consumes:
|
|
||||||
- application/json
|
|
||||||
operationId: updateSimulator
|
|
||||||
parameters:
|
|
||||||
- description: Authorization token
|
|
||||||
in: header
|
|
||||||
name: Authorization
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
- description: Simulator to be updated
|
|
||||||
in: body
|
|
||||||
name: inputSimulator
|
|
||||||
required: true
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/simulator.updateSimulatorRequest'
|
|
||||||
type: object
|
|
||||||
- description: Simulator ID
|
|
||||||
in: path
|
|
||||||
name: simulatorID
|
|
||||||
required: true
|
|
||||||
type: integer
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Simulator that was updated
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseSimulator'
|
|
||||||
type: object
|
|
||||||
"400":
|
|
||||||
description: Bad request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"404":
|
|
||||||
description: Not found
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"422":
|
|
||||||
description: Unprocessable entity
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"500":
|
|
||||||
description: Internal server error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
summary: Update a simulator
|
|
||||||
tags:
|
|
||||||
- simulators
|
|
||||||
/simulators/{simulatorID}/action:
|
|
||||||
post:
|
|
||||||
operationId: sendActionToSimulator
|
|
||||||
parameters:
|
|
||||||
- description: Action for simulator
|
|
||||||
in: query
|
|
||||||
name: inputAction
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
- description: Simulator ID
|
|
||||||
in: path
|
|
||||||
name: simulatorID
|
|
||||||
required: true
|
|
||||||
type: integer
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Action sent successfully
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"400":
|
|
||||||
description: Bad request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"404":
|
|
||||||
description: Not found
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"422":
|
|
||||||
description: Unprocessable entity
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"500":
|
|
||||||
description: Internal server error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
summary: Send an action to simulator (only available if backend server is started
|
|
||||||
with -amqp parameter)
|
|
||||||
tags:
|
|
||||||
- AMQP
|
|
||||||
/simulators/{simulatorID}/models:
|
|
||||||
get:
|
|
||||||
operationId: getModelsOfSimulator
|
|
||||||
parameters:
|
|
||||||
- description: Authorization token
|
|
||||||
in: header
|
|
||||||
name: Authorization
|
|
||||||
required: true
|
|
||||||
type: string
|
|
||||||
- description: Simulator ID
|
|
||||||
in: path
|
|
||||||
name: simulatorID
|
|
||||||
required: true
|
|
||||||
type: integer
|
|
||||||
produces:
|
|
||||||
- application/json
|
|
||||||
responses:
|
|
||||||
"200":
|
|
||||||
description: Simulation models requested by user
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseSimulationModels'
|
|
||||||
type: object
|
|
||||||
"400":
|
|
||||||
description: Bad request
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"404":
|
|
||||||
description: Not found
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"422":
|
|
||||||
description: Unprocessable entity
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
"500":
|
|
||||||
description: Internal server error
|
|
||||||
schema:
|
|
||||||
$ref: '#/definitions/docs.ResponseError'
|
|
||||||
type: object
|
|
||||||
summary: Get all simulation models in which the simulator is used
|
|
||||||
tags:
|
|
||||||
- simulators
|
|
||||||
/users:
|
/users:
|
||||||
get:
|
get:
|
||||||
operationId: GetUsers
|
operationId: GetUsers
|
||||||
|
|
|
@ -28,9 +28,9 @@ import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"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/helper"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/dashboard"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/dashboard"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulator"
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -52,11 +52,11 @@ var db *gorm.DB
|
||||||
type SimulationModelRequest struct {
|
type SimulationModelRequest struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
ScenarioID uint `json:"scenarioID,omitempty"`
|
ScenarioID uint `json:"scenarioID,omitempty"`
|
||||||
SimulatorID uint `json:"simulatorID,omitempty"`
|
ICID uint `json:"icID,omitempty"`
|
||||||
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SimulatorRequest struct {
|
type ICRequest struct {
|
||||||
UUID string `json:"uuid,omitempty"`
|
UUID string `json:"uuid,omitempty"`
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Modeltype string `json:"modelType,omitempty"`
|
Modeltype string `json:"modelType,omitempty"`
|
||||||
|
@ -91,25 +91,25 @@ type WidgetRequest struct {
|
||||||
CustomProperties postgres.Jsonb `json:"customProperties,omitempty"`
|
CustomProperties postgres.Jsonb `json:"customProperties,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() (scenarioID uint, simulatorID uint, simulationModelID uint, dashboardID uint, widgetID uint) {
|
func addScenarioAndICAndSimulationModelAndDashboardAndWidget() (scenarioID uint, ICID uint, simulationModelID uint, dashboardID uint, widgetID uint) {
|
||||||
|
|
||||||
// authenticate as admin
|
// authenticate as admin
|
||||||
token, _ := helper.AuthenticateForTest(router,
|
token, _ := helper.AuthenticateForTest(router,
|
||||||
"/api/authenticate", "POST", helper.AdminCredentials)
|
"/api/authenticate", "POST", helper.AdminCredentials)
|
||||||
|
|
||||||
// POST $newSimulatorA
|
// POST $newICA
|
||||||
newSimulatorA := SimulatorRequest{
|
newICA := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
_, resp, _ := helper.TestEndpoint(router, token,
|
_, resp, _ := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulatorA})
|
"/api/ic", "POST", helper.KeyModels{"ic": newICA})
|
||||||
|
|
||||||
// Read newSimulator's ID from the response
|
// Read newIC's ID from the response
|
||||||
newSimulatorID, _ := helper.GetResponseID(resp)
|
newICID, _ := helper.GetResponseID(resp)
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, _ = helper.AuthenticateForTest(router,
|
token, _ = helper.AuthenticateForTest(router,
|
||||||
|
@ -131,7 +131,7 @@ func addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() (scenarioI
|
||||||
newSimulationModel := SimulationModelRequest{
|
newSimulationModel := SimulationModelRequest{
|
||||||
Name: database.SimulationModelA.Name,
|
Name: database.SimulationModelA.Name,
|
||||||
ScenarioID: uint(newScenarioID),
|
ScenarioID: uint(newScenarioID),
|
||||||
SimulatorID: uint(newSimulatorID),
|
ICID: uint(newICID),
|
||||||
StartParameters: database.SimulationModelA.StartParameters,
|
StartParameters: database.SimulationModelA.StartParameters,
|
||||||
}
|
}
|
||||||
_, resp, _ = helper.TestEndpoint(router, token,
|
_, resp, _ = helper.TestEndpoint(router, token,
|
||||||
|
@ -177,7 +177,7 @@ func addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() (scenarioI
|
||||||
_, resp, _ = helper.TestEndpoint(router, token,
|
_, resp, _ = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/scenarios/%v/user?username=User_C", newScenarioID), "PUT", nil)
|
fmt.Sprintf("/api/scenarios/%v/user?username=User_C", newScenarioID), "PUT", nil)
|
||||||
|
|
||||||
return uint(newScenarioID), uint(newSimulatorID), uint(newSimulationModelID), uint(newDashboardID), uint(newWidgetID)
|
return uint(newScenarioID), uint(newICID), uint(newSimulationModelID), uint(newDashboardID), uint(newWidgetID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -202,9 +202,9 @@ func TestMain(m *testing.M) {
|
||||||
// scenario endpoints required here to first add a scenario to the DB
|
// scenario endpoints required here to first add a scenario to the DB
|
||||||
// that can be associated with a new simulation model
|
// that can be associated with a new simulation model
|
||||||
scenario.RegisterScenarioEndpoints(api.Group("/scenarios"))
|
scenario.RegisterScenarioEndpoints(api.Group("/scenarios"))
|
||||||
// simulator endpoints required here to first add a simulator to the DB
|
// IC endpoints required here to first add a IC to the DB
|
||||||
// that can be associated with a new simulation model
|
// that can be associated with a new simulation model
|
||||||
simulator.RegisterSimulatorEndpoints(api.Group("/simulators"))
|
infrastructure_component.RegisterICEndpoints(api.Group("/ic"))
|
||||||
// dashboard endpoints required here to first add a dashboard to the DB
|
// dashboard endpoints required here to first add a dashboard to the DB
|
||||||
// that can be associated with a new widget
|
// that can be associated with a new widget
|
||||||
dashboard.RegisterDashboardEndpoints(api.Group("/dashboards"))
|
dashboard.RegisterDashboardEndpoints(api.Group("/dashboards"))
|
||||||
|
@ -224,7 +224,7 @@ func TestAddFile(t *testing.T) {
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
_, _, simulationModelID, _, widgetID := addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget()
|
_, _, simulationModelID, _, widgetID := addScenarioAndICAndSimulationModelAndDashboardAndWidget()
|
||||||
|
|
||||||
// authenticate as userB who has no access to the elements in the DB
|
// authenticate as userB who has no access to the elements in the DB
|
||||||
token, err := helper.AuthenticateForTest(router,
|
token, err := helper.AuthenticateForTest(router,
|
||||||
|
@ -340,7 +340,7 @@ func TestUpdateFile(t *testing.T) {
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
_, _, simulationModelID, _, _ := addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget()
|
_, _, simulationModelID, _, _ := addScenarioAndICAndSimulationModelAndDashboardAndWidget()
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, err := helper.AuthenticateForTest(router,
|
token, err := helper.AuthenticateForTest(router,
|
||||||
|
@ -474,7 +474,7 @@ func TestDeleteFile(t *testing.T) {
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
_, _, simulationModelID, _, widgetID := addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget()
|
_, _, simulationModelID, _, widgetID := addScenarioAndICAndSimulationModelAndDashboardAndWidget()
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, err := helper.AuthenticateForTest(router,
|
token, err := helper.AuthenticateForTest(router,
|
||||||
|
@ -625,7 +625,7 @@ func TestGetAllFilesOfSimulationModel(t *testing.T) {
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
_, _, simulationModelID, _, widgetID := addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget()
|
_, _, simulationModelID, _, widgetID := addScenarioAndICAndSimulationModelAndDashboardAndWidget()
|
||||||
|
|
||||||
// authenticate as userB who has no access to the elements in the DB
|
// authenticate as userB who has no access to the elements in the DB
|
||||||
token, err := helper.AuthenticateForTest(router,
|
token, err := helper.AuthenticateForTest(router,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/** Simulator package, endpoints.
|
/** InfrastructureComponent package, endpoints.
|
||||||
*
|
*
|
||||||
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
||||||
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
package simulator
|
package infrastructure_component
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/helper"
|
||||||
|
@ -29,61 +29,61 @@ import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
func RegisterSimulatorEndpoints(r *gin.RouterGroup) {
|
func RegisterICEndpoints(r *gin.RouterGroup) {
|
||||||
r.GET("", getSimulators)
|
r.GET("", getICs)
|
||||||
r.POST("", addSimulator)
|
r.POST("", addIC)
|
||||||
r.PUT("/:simulatorID", updateSimulator)
|
r.PUT("/:ICID", updateIC)
|
||||||
r.GET("/:simulatorID", getSimulator)
|
r.GET("/:ICID", getIC)
|
||||||
r.DELETE("/:simulatorID", deleteSimulator)
|
r.DELETE("/:ICID", deleteIC)
|
||||||
r.GET("/:simulatorID/models", getModelsOfSimulator)
|
r.GET("/:ICID/models", getConfigsOfIC)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSimulators godoc
|
// getICs godoc
|
||||||
// @Summary Get all simulators
|
// @Summary Get all infrastructure components
|
||||||
// @ID getSimulators
|
// @ID getICs
|
||||||
// @Tags simulators
|
// @Tags infrastructure-components
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} docs.ResponseSimulators "Simulators requested"
|
// @Success 200 {object} docs.ResponseICs "ICs requested"
|
||||||
// @Failure 404 {object} docs.ResponseError "Not found"
|
// @Failure 404 {object} docs.ResponseError "Not found"
|
||||||
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
||||||
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
||||||
// @Param Authorization header string true "Authorization token"
|
// @Param Authorization header string true "Authorization token"
|
||||||
// @Router /simulators [get]
|
// @Router /ic [get]
|
||||||
func getSimulators(c *gin.Context) {
|
func getICs(c *gin.Context) {
|
||||||
|
|
||||||
// Checking permission is not required here since READ access is independent of user's role
|
// Checking permission is not required here since READ access is independent of user's role
|
||||||
|
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
var simulators []database.Simulator
|
var ics []database.InfrastructureComponent
|
||||||
err := db.Order("ID asc").Find(&simulators).Error
|
err := db.Order("ID asc").Find(&ics).Error
|
||||||
if !helper.DBError(c, err) {
|
if !helper.DBError(c, err) {
|
||||||
c.JSON(http.StatusOK, gin.H{"simulators": simulators})
|
c.JSON(http.StatusOK, gin.H{"ics": ics})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// addSimulator godoc
|
// addIC godoc
|
||||||
// @Summary Add a simulator
|
// @Summary Add an infrastructure component
|
||||||
// @ID addSimulator
|
// @ID addIC
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Tags simulators
|
// @Tags infrastructure-components
|
||||||
// @Success 200 {object} docs.ResponseSimulator "Simulator that was added"
|
// @Success 200 {object} docs.ResponseIC "Infrastructure Component that was added"
|
||||||
// @Failure 400 {object} docs.ResponseError "Bad request"
|
// @Failure 400 {object} docs.ResponseError "Bad request"
|
||||||
// @Failure 404 {object} docs.ResponseError "Not found"
|
// @Failure 404 {object} docs.ResponseError "Not found"
|
||||||
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
||||||
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
||||||
// @Param Authorization header string true "Authorization token"
|
// @Param Authorization header string true "Authorization token"
|
||||||
// @Param inputSimulator body simulator.addSimulatorRequest true "Simulator to be added"
|
// @Param inputIC body infrastructure_component.addICRequest true "Infrastructure Component to be added"
|
||||||
// @Router /simulators [post]
|
// @Router /ic [post]
|
||||||
func addSimulator(c *gin.Context) {
|
func addIC(c *gin.Context) {
|
||||||
|
|
||||||
ok, _ := CheckPermissions(c, database.ModelSimulator, database.Create, false)
|
ok, _ := CheckPermissions(c, database.ModelInfrastructureComponent, database.Create, false)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var req addSimulatorRequest
|
var req addICRequest
|
||||||
err := c.BindJSON(&req)
|
err := c.BindJSON(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.BadRequestError(c, "Error binding form data to JSON: "+err.Error())
|
helper.BadRequestError(c, "Error binding form data to JSON: "+err.Error())
|
||||||
|
@ -96,40 +96,40 @@ func addSimulator(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the new simulator from the request
|
// Create the new IC from the request
|
||||||
newSimulator := req.createSimulator()
|
newIC := req.createIC()
|
||||||
|
|
||||||
// Save new simulator to DB
|
// Save new IC to DB
|
||||||
err = newSimulator.save()
|
err = newIC.save()
|
||||||
if !helper.DBError(c, err) {
|
if !helper.DBError(c, err) {
|
||||||
c.JSON(http.StatusOK, gin.H{"simulator": newSimulator.Simulator})
|
c.JSON(http.StatusOK, gin.H{"ic": newIC.InfrastructureComponent})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateSimulator godoc
|
// updateIC godoc
|
||||||
// @Summary Update a simulator
|
// @Summary Update an infrastructure component
|
||||||
// @ID updateSimulator
|
// @ID updateIC
|
||||||
// @Tags simulators
|
// @Tags infrastructure-components
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} docs.ResponseSimulator "Simulator that was updated"
|
// @Success 200 {object} docs.ResponseIC "Infrastructure Component that was updated"
|
||||||
// @Failure 400 {object} docs.ResponseError "Bad request"
|
// @Failure 400 {object} docs.ResponseError "Bad request"
|
||||||
// @Failure 404 {object} docs.ResponseError "Not found"
|
// @Failure 404 {object} docs.ResponseError "Not found"
|
||||||
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
||||||
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
||||||
// @Param Authorization header string true "Authorization token"
|
// @Param Authorization header string true "Authorization token"
|
||||||
// @Param inputSimulator body simulator.updateSimulatorRequest true "Simulator to be updated"
|
// @Param inputIC body infrastructure_component.updateICRequest true "InfrastructureComponent to be updated"
|
||||||
// @Param simulatorID path int true "Simulator ID"
|
// @Param ICID path int true "InfrastructureComponent ID"
|
||||||
// @Router /simulators/{simulatorID} [put]
|
// @Router /ic/{ICID} [put]
|
||||||
func updateSimulator(c *gin.Context) {
|
func updateIC(c *gin.Context) {
|
||||||
|
|
||||||
ok, oldSimulator := CheckPermissions(c, database.ModelSimulator, database.Update, true)
|
ok, oldIC := CheckPermissions(c, database.ModelInfrastructureComponent, database.Update, true)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
var req updateSimulatorRequest
|
var req updateICRequest
|
||||||
err := c.BindJSON(&req)
|
err := c.BindJSON(&req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.BadRequestError(c, "Error binding form data to JSON: "+err.Error())
|
helper.BadRequestError(c, "Error binding form data to JSON: "+err.Error())
|
||||||
|
@ -137,89 +137,89 @@ func updateSimulator(c *gin.Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the request
|
// Validate the request
|
||||||
if err = req.Simulator.validate(); err != nil {
|
if err = req.InfrastructureComponent.validate(); err != nil {
|
||||||
helper.UnprocessableEntityError(c, err.Error())
|
helper.UnprocessableEntityError(c, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the updatedSimulator from oldSimulator
|
// Create the updatedIC from oldIC
|
||||||
updatedSimulator := req.updatedSimulator(oldSimulator)
|
updatedIC := req.updatedIC(oldIC)
|
||||||
|
|
||||||
// Finally update the simulator in the DB
|
// Finally update the IC in the DB
|
||||||
err = oldSimulator.update(updatedSimulator)
|
err = oldIC.update(updatedIC)
|
||||||
if !helper.DBError(c, err) {
|
if !helper.DBError(c, err) {
|
||||||
c.JSON(http.StatusOK, gin.H{"simulator": updatedSimulator.Simulator})
|
c.JSON(http.StatusOK, gin.H{"ic": updatedIC.InfrastructureComponent})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getSimulator godoc
|
// getIC godoc
|
||||||
// @Summary Get simulator
|
// @Summary Get infrastructure component
|
||||||
// @ID getSimulator
|
// @ID getIC
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Tags simulators
|
// @Tags infrastructure-components
|
||||||
// @Success 200 {object} docs.ResponseSimulator "Simulator that was requested"
|
// @Success 200 {object} docs.ResponseIC "Infrastructure Component that was requested"
|
||||||
// @Failure 400 {object} docs.ResponseError "Bad request"
|
// @Failure 400 {object} docs.ResponseError "Bad request"
|
||||||
// @Failure 404 {object} docs.ResponseError "Not found"
|
// @Failure 404 {object} docs.ResponseError "Not found"
|
||||||
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
||||||
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
||||||
// @Param Authorization header string true "Authorization token"
|
// @Param Authorization header string true "Authorization token"
|
||||||
// @Param simulatorID path int true "Simulator ID"
|
// @Param ICID path int true "Infrastructure Component ID"
|
||||||
// @Router /simulators/{simulatorID} [get]
|
// @Router /ic/{ICID} [get]
|
||||||
func getSimulator(c *gin.Context) {
|
func getIC(c *gin.Context) {
|
||||||
|
|
||||||
ok, s := CheckPermissions(c, database.ModelSimulator, database.Read, true)
|
ok, s := CheckPermissions(c, database.ModelInfrastructureComponent, database.Read, true)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{"simulator": s.Simulator})
|
c.JSON(http.StatusOK, gin.H{"ic": s.InfrastructureComponent})
|
||||||
}
|
}
|
||||||
|
|
||||||
// deleteSimulator godoc
|
// deleteIC godoc
|
||||||
// @Summary Delete a simulator
|
// @Summary Delete an infrastructure component
|
||||||
// @ID deleteSimulator
|
// @ID deleteIC
|
||||||
// @Tags simulators
|
// @Tags infrastructure-components
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} docs.ResponseSimulator "Simulator that was deleted"
|
// @Success 200 {object} docs.ResponseIC "Infrastructure Component that was deleted"
|
||||||
// @Failure 400 {object} docs.ResponseError "Bad request"
|
// @Failure 400 {object} docs.ResponseError "Bad request"
|
||||||
// @Failure 404 {object} docs.ResponseError "Not found"
|
// @Failure 404 {object} docs.ResponseError "Not found"
|
||||||
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
||||||
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
||||||
// @Param Authorization header string true "Authorization token"
|
// @Param Authorization header string true "Authorization token"
|
||||||
// @Param simulatorID path int true "Simulator ID"
|
// @Param ICID path int true "Infrastructure Component ID"
|
||||||
// @Router /simulators/{simulatorID} [delete]
|
// @Router /ic/{ICID} [delete]
|
||||||
func deleteSimulator(c *gin.Context) {
|
func deleteIC(c *gin.Context) {
|
||||||
|
|
||||||
ok, s := CheckPermissions(c, database.ModelSimulator, database.Delete, true)
|
ok, s := CheckPermissions(c, database.ModelInfrastructureComponent, database.Delete, true)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete the simulator
|
// Delete the IC
|
||||||
err := s.delete()
|
err := s.delete()
|
||||||
if !helper.DBError(c, err) {
|
if !helper.DBError(c, err) {
|
||||||
c.JSON(http.StatusOK, gin.H{"simulator": s.Simulator})
|
c.JSON(http.StatusOK, gin.H{"ic": s.InfrastructureComponent})
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// getModelsOfSimulator godoc
|
// getConfigsOfIC godoc
|
||||||
// @Summary Get all simulation models in which the simulator is used
|
// @Summary Get all configurations of the infrastructure component
|
||||||
// @ID getModelsOfSimulator
|
// @ID getConfigsOfIC
|
||||||
// @Tags simulators
|
// @Tags infrastructure-components
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {object} docs.ResponseSimulationModels "Simulation models requested by user"
|
// @Success 200 {object} docs.ResponseSimulationModels "Configs requested by user"
|
||||||
// @Failure 400 {object} docs.ResponseError "Bad request"
|
// @Failure 400 {object} docs.ResponseError "Bad request"
|
||||||
// @Failure 404 {object} docs.ResponseError "Not found"
|
// @Failure 404 {object} docs.ResponseError "Not found"
|
||||||
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
||||||
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
||||||
// @Param Authorization header string true "Authorization token"
|
// @Param Authorization header string true "Authorization token"
|
||||||
// @Param simulatorID path int true "Simulator ID"
|
// @Param ICID path int true "Infrastructure Component ID"
|
||||||
// @Router /simulators/{simulatorID}/models [get]
|
// @Router /ic/{ICID}/models [get]
|
||||||
func getModelsOfSimulator(c *gin.Context) {
|
func getConfigsOfIC(c *gin.Context) {
|
||||||
|
|
||||||
ok, s := CheckPermissions(c, database.ModelSimulator, database.Read, true)
|
ok, s := CheckPermissions(c, database.ModelInfrastructureComponent, database.Read, true)
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
/** Simulator package, methods.
|
/** InfrastructureComponent package, methods.
|
||||||
*
|
*
|
||||||
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
||||||
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
package simulator
|
package infrastructure_component
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -27,45 +27,45 @@ import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Simulator struct {
|
type InfrastructureComponent struct {
|
||||||
database.Simulator
|
database.InfrastructureComponent
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Simulator) save() error {
|
func (s *InfrastructureComponent) save() error {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
err := db.Create(s).Error
|
err := db.Create(s).Error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Simulator) ByID(id uint) error {
|
func (s *InfrastructureComponent) ByID(id uint) error {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
err := db.Find(s, id).Error
|
err := db.Find(s, id).Error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Simulator) update(updatedSimulator Simulator) error {
|
func (s *InfrastructureComponent) update(updatedIC InfrastructureComponent) error {
|
||||||
|
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
err := db.Model(s).Updates(updatedSimulator).Error
|
err := db.Model(s).Updates(updatedIC).Error
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Simulator) delete() error {
|
func (s *InfrastructureComponent) delete() error {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
|
|
||||||
no_simulationmodels := db.Model(s).Association("SimulationModels").Count()
|
no_simulationmodels := db.Model(s).Association("SimulationModels").Count()
|
||||||
|
|
||||||
if no_simulationmodels > 0 {
|
if no_simulationmodels > 0 {
|
||||||
return fmt.Errorf("Simulator cannot be deleted as it is still used in SimulationModels (active or dangling)")
|
return fmt.Errorf("InfrastructureComponent cannot be deleted as it is still used in SimulationModels (active or dangling)")
|
||||||
}
|
}
|
||||||
|
|
||||||
// delete Simulator from DB (does NOT remain as dangling)
|
// delete InfrastructureComponent from DB (does NOT remain as dangling)
|
||||||
err := db.Delete(s).Error
|
err := db.Delete(s).Error
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Simulator) getModels() ([]database.SimulationModel, int, error) {
|
func (s *InfrastructureComponent) getModels() ([]database.SimulationModel, int, error) {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
var models []database.SimulationModel
|
var models []database.SimulationModel
|
||||||
err := db.Order("ID asc").Model(s).Related(&models, "SimulationModels").Error
|
err := db.Order("ID asc").Model(s).Related(&models, "SimulationModels").Error
|
|
@ -1,4 +1,4 @@
|
||||||
/** Simulator package, middleware.
|
/** InfrastructureComponent package, middleware.
|
||||||
*
|
*
|
||||||
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
||||||
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
package simulator
|
package infrastructure_component
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -28,24 +28,24 @@ import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CheckPermissions(c *gin.Context, modeltype database.ModelName, operation database.CRUD, hasID bool) (bool, Simulator) {
|
func CheckPermissions(c *gin.Context, modeltype database.ModelName, operation database.CRUD, hasID bool) (bool, InfrastructureComponent) {
|
||||||
|
|
||||||
var s Simulator
|
var s InfrastructureComponent
|
||||||
|
|
||||||
err := database.ValidateRole(c, modeltype, operation)
|
err := database.ValidateRole(c, modeltype, operation)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.UnprocessableEntityError(c, fmt.Sprintf("Access denied (role validation of simulator failed): %v", err.Error()))
|
helper.UnprocessableEntityError(c, fmt.Sprintf("Access denied (role validation of infrastructure component failed): %v", err.Error()))
|
||||||
return false, s
|
return false, s
|
||||||
}
|
}
|
||||||
|
|
||||||
if hasID {
|
if hasID {
|
||||||
// Get the ID of the simulator from the context
|
// Get the ID of the infrastructure component from the context
|
||||||
simulatorID, err := helper.GetIDOfElement(c, "simulatorID", "path", -1)
|
ICID, err := helper.GetIDOfElement(c, "ICID", "path", -1)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return false, s
|
return false, s
|
||||||
}
|
}
|
||||||
|
|
||||||
err = s.ByID(uint(simulatorID))
|
err = s.ByID(uint(ICID))
|
||||||
if helper.DBError(c, err) {
|
if helper.DBError(c, err) {
|
||||||
return false, s
|
return false, s
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
/** Simulator package, testing.
|
/** InfrastructureComponent package, testing.
|
||||||
*
|
*
|
||||||
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
||||||
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
package simulator
|
package infrastructure_component
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
@ -40,7 +40,7 @@ import (
|
||||||
var router *gin.Engine
|
var router *gin.Engine
|
||||||
var db *gorm.DB
|
var db *gorm.DB
|
||||||
|
|
||||||
type SimulatorRequest struct {
|
type ICRequest struct {
|
||||||
UUID string `json:"uuid,omitempty"`
|
UUID string `json:"uuid,omitempty"`
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Modeltype string `json:"modelType,omitempty"`
|
Modeltype string `json:"modelType,omitempty"`
|
||||||
|
@ -65,12 +65,12 @@ func TestMain(m *testing.M) {
|
||||||
|
|
||||||
user.RegisterAuthenticate(api.Group("/authenticate"))
|
user.RegisterAuthenticate(api.Group("/authenticate"))
|
||||||
api.Use(user.Authentication(true))
|
api.Use(user.Authentication(true))
|
||||||
RegisterSimulatorEndpoints(api.Group("/simulators"))
|
RegisterICEndpoints(api.Group("/ic"))
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddSimulatorAsAdmin(t *testing.T) {
|
func TestAddICAsAdmin(t *testing.T) {
|
||||||
database.DropTables(db)
|
database.DropTables(db)
|
||||||
database.MigrateModels(db)
|
database.MigrateModels(db)
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
@ -83,61 +83,61 @@ func TestAddSimulatorAsAdmin(t *testing.T) {
|
||||||
// try to POST with non JSON body
|
// try to POST with non JSON body
|
||||||
// should result in bad request
|
// should result in bad request
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", "This is no JSON")
|
"/api/ic", "POST", "This is no JSON")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 400, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 400, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// try to POST malformed simulator (required fields missing, validation should fail)
|
// try to POST malformed IC (required fields missing, validation should fail)
|
||||||
// should result in an unprocessable entity
|
// should result in an unprocessable entity
|
||||||
newMalformedSimulator := SimulatorRequest{
|
newMalformedIC := ICRequest{
|
||||||
UUID: database.SimulatorB.UUID,
|
UUID: database.ICB.UUID,
|
||||||
}
|
}
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newMalformedSimulator})
|
"/api/ic", "POST", helper.KeyModels{"ic": newMalformedIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// test POST simulators/ $newSimulator
|
// test POST ic/ $newIC
|
||||||
newSimulator := SimulatorRequest{
|
newIC := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulator})
|
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Compare POST's response with the newSimulator
|
// Compare POST's response with the newIC
|
||||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator})
|
err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Read newSimulator's ID from the response
|
// Read newIC's ID from the response
|
||||||
newSimulatorID, err := helper.GetResponseID(resp)
|
newICID, err := helper.GetResponseID(resp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Get the newSimulator
|
// Get the newIC
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v", newSimulatorID), "GET", nil)
|
fmt.Sprintf("/api/ic/%v", newICID), "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Compare GET's response with the newSimulator
|
// Compare GET's response with the newIC
|
||||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator})
|
err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Try to GET a simulator that does not exist
|
// Try to GET a IC that does not exist
|
||||||
// should result in not found
|
// should result in not found
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v", newSimulatorID+1), "GET", nil)
|
fmt.Sprintf("/api/ic/%v", newICID+1), "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 404, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 404, code, "Response body: \n%v\n", resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAddSimulatorAsUser(t *testing.T) {
|
func TestAddICAsUser(t *testing.T) {
|
||||||
database.DropTables(db)
|
database.DropTables(db)
|
||||||
database.MigrateModels(db)
|
database.MigrateModels(db)
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
@ -147,24 +147,24 @@ func TestAddSimulatorAsUser(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.UserACredentials)
|
"/api/authenticate", "POST", helper.UserACredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// test POST simulators/ $newSimulator
|
// test POST ic/ $newIC
|
||||||
newSimulator := SimulatorRequest{
|
newIC := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
|
|
||||||
// This should fail with unprocessable entity 422 error code
|
// This should fail with unprocessable entity 422 error code
|
||||||
// Normal users are not allowed to add simulators
|
// Normal users are not allowed to add ICs
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulator})
|
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateSimulatorAsAdmin(t *testing.T) {
|
func TestUpdateICAsAdmin(t *testing.T) {
|
||||||
database.DropTables(db)
|
database.DropTables(db)
|
||||||
database.MigrateModels(db)
|
database.MigrateModels(db)
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
@ -174,59 +174,59 @@ func TestUpdateSimulatorAsAdmin(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.AdminCredentials)
|
"/api/authenticate", "POST", helper.AdminCredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// test POST simulators/ $newSimulator
|
// test POST ic/ $newIC
|
||||||
newSimulator := SimulatorRequest{
|
newIC := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulator})
|
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Compare POST's response with the newSimulator
|
// Compare POST's response with the newIC
|
||||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator})
|
err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Read newSimulator's ID from the response
|
// Read newIC's ID from the response
|
||||||
newSimulatorID, err := helper.GetResponseID(resp)
|
newICID, err := helper.GetResponseID(resp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// try to PUT with non JSON body
|
// try to PUT with non JSON body
|
||||||
// should result in bad request
|
// should result in bad request
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v", newSimulatorID), "PUT", "This is no JSON")
|
fmt.Sprintf("/api/ic/%v", newICID), "PUT", "This is no JSON")
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 400, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 400, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Test PUT simulators
|
// Test PUT IC
|
||||||
newSimulator.Host = "ThisIsMyNewHost"
|
newIC.Host = "ThisIsMyNewHost"
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v", newSimulatorID), "PUT", helper.KeyModels{"simulator": newSimulator})
|
fmt.Sprintf("/api/ic/%v", newICID), "PUT", helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Compare PUT's response with the updated newSimulator
|
// Compare PUT's response with the updated newIC
|
||||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator})
|
err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Get the updated newSimulator
|
// Get the updated newIC
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v", newSimulatorID), "GET", nil)
|
fmt.Sprintf("/api/ic/%v", newICID), "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Compare GET's response with the updated newSimulator
|
// Compare GET's response with the updated newIC
|
||||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator})
|
err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdateSimulatorAsUser(t *testing.T) {
|
func TestUpdateICAsUser(t *testing.T) {
|
||||||
database.DropTables(db)
|
database.DropTables(db)
|
||||||
database.MigrateModels(db)
|
database.MigrateModels(db)
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
@ -236,21 +236,21 @@ func TestUpdateSimulatorAsUser(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.AdminCredentials)
|
"/api/authenticate", "POST", helper.AdminCredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// test POST simulators/ $newSimulator
|
// test POST ic/ $newIC
|
||||||
newSimulator := SimulatorRequest{
|
newIC := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulator})
|
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Read newSimulator's ID from the response
|
// Read newIC's ID from the response
|
||||||
newSimulatorID, err := helper.GetResponseID(resp)
|
newICID, err := helper.GetResponseID(resp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// authenticate as user
|
// authenticate as user
|
||||||
|
@ -258,17 +258,17 @@ func TestUpdateSimulatorAsUser(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.UserACredentials)
|
"/api/authenticate", "POST", helper.UserACredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Test PUT simulators
|
// Test PUT IC
|
||||||
// This should fail with unprocessable entity status code 422
|
// This should fail with unprocessable entity status code 422
|
||||||
newSimulator.Host = "ThisIsMyNewHost"
|
newIC.Host = "ThisIsMyNewHost"
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v", newSimulatorID), "PUT", helper.KeyModels{"simulator": newSimulator})
|
fmt.Sprintf("/api/ic/%v", newICID), "PUT", helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteSimulatorAsAdmin(t *testing.T) {
|
func TestDeleteICAsAdmin(t *testing.T) {
|
||||||
database.DropTables(db)
|
database.DropTables(db)
|
||||||
database.MigrateModels(db)
|
database.MigrateModels(db)
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
@ -278,47 +278,47 @@ func TestDeleteSimulatorAsAdmin(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.AdminCredentials)
|
"/api/authenticate", "POST", helper.AdminCredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// test POST simulators/ $newSimulator
|
// test POST ic/ $newIC
|
||||||
newSimulator := SimulatorRequest{
|
newIC := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulator})
|
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Read newSimulator's ID from the response
|
// Read newIC's ID from the response
|
||||||
newSimulatorID, err := helper.GetResponseID(resp)
|
newICID, err := helper.GetResponseID(resp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Count the number of all the simulators returned for admin
|
// Count the number of all the ICs returned for admin
|
||||||
initialNumber, err := helper.LengthOfResponse(router, token,
|
initialNumber, err := helper.LengthOfResponse(router, token,
|
||||||
"/api/simulators", "GET", nil)
|
"/api/ic", "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Delete the added newSimulator
|
// Delete the added newIC
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v", newSimulatorID), "DELETE", nil)
|
fmt.Sprintf("/api/ic/%v", newICID), "DELETE", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Compare DELETE's response with the newSimulator
|
// Compare DELETE's response with the newIC
|
||||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator})
|
err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Again count the number of all the simulators returned
|
// Again count the number of all the ICs returned
|
||||||
finalNumber, err := helper.LengthOfResponse(router, token,
|
finalNumber, err := helper.LengthOfResponse(router, token,
|
||||||
"/api/simulators", "GET", nil)
|
"/api/ic", "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, finalNumber, initialNumber-1)
|
assert.Equal(t, finalNumber, initialNumber-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDeleteSimulatorAsUser(t *testing.T) {
|
func TestDeleteICAsUser(t *testing.T) {
|
||||||
database.DropTables(db)
|
database.DropTables(db)
|
||||||
database.MigrateModels(db)
|
database.MigrateModels(db)
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
@ -328,21 +328,21 @@ func TestDeleteSimulatorAsUser(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.AdminCredentials)
|
"/api/authenticate", "POST", helper.AdminCredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// test POST simulators/ $newSimulator
|
// test POST ic/ $newIC
|
||||||
newSimulator := SimulatorRequest{
|
newIC := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulator})
|
"/api/ic", "POST", helper.KeyModels{"ic": newIC})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Read newSimulator's ID from the response
|
// Read newIC's ID from the response
|
||||||
newSimulatorID, err := helper.GetResponseID(resp)
|
newICID, err := helper.GetResponseID(resp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// authenticate as user
|
// authenticate as user
|
||||||
|
@ -350,16 +350,16 @@ func TestDeleteSimulatorAsUser(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.UserACredentials)
|
"/api/authenticate", "POST", helper.UserACredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Test DELETE simulators
|
// Test DELETE ICs
|
||||||
// This should fail with unprocessable entity status code 422
|
// This should fail with unprocessable entity status code 422
|
||||||
newSimulator.Host = "ThisIsMyNewHost"
|
newIC.Host = "ThisIsMyNewHost"
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v", newSimulatorID), "DELETE", nil)
|
fmt.Sprintf("/api/ic/%v", newICID), "DELETE", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 422, code, "Response body: \n%v\n", resp)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetAllSimulators(t *testing.T) {
|
func TestGetAllICs(t *testing.T) {
|
||||||
database.DropTables(db)
|
database.DropTables(db)
|
||||||
database.MigrateModels(db)
|
database.MigrateModels(db)
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
@ -369,40 +369,40 @@ func TestGetAllSimulators(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.AdminCredentials)
|
"/api/authenticate", "POST", helper.AdminCredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// get the length of the GET all simulators response for user
|
// get the length of the GET all ICs response for user
|
||||||
initialNumber, err := helper.LengthOfResponse(router, token,
|
initialNumber, err := helper.LengthOfResponse(router, token,
|
||||||
"/api/simulators", "GET", nil)
|
"/api/ic", "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// test POST simulators/ $newSimulatorA
|
// test POST ic/ $newICA
|
||||||
newSimulatorA := SimulatorRequest{
|
newICA := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulatorA})
|
"/api/ic", "POST", helper.KeyModels{"ic": newICA})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// test POST simulators/ $newSimulatorB
|
// test POST ic/ $newICB
|
||||||
newSimulatorB := SimulatorRequest{
|
newICB := ICRequest{
|
||||||
UUID: database.SimulatorB.UUID,
|
UUID: database.ICB.UUID,
|
||||||
Host: database.SimulatorB.Host,
|
Host: database.ICB.Host,
|
||||||
Modeltype: database.SimulatorB.Modeltype,
|
Modeltype: database.ICB.Modeltype,
|
||||||
State: database.SimulatorB.State,
|
State: database.ICB.State,
|
||||||
Properties: database.SimulatorB.Properties,
|
Properties: database.ICB.Properties,
|
||||||
}
|
}
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulatorB})
|
"/api/ic", "POST", helper.KeyModels{"ic": newICB})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// get the length of the GET all simulators response again
|
// get the length of the GET all ICs response again
|
||||||
finalNumber, err := helper.LengthOfResponse(router, token,
|
finalNumber, err := helper.LengthOfResponse(router, token,
|
||||||
"/api/simulators", "GET", nil)
|
"/api/ic", "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, finalNumber, initialNumber+2)
|
assert.Equal(t, finalNumber, initialNumber+2)
|
||||||
|
@ -412,15 +412,15 @@ func TestGetAllSimulators(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.UserACredentials)
|
"/api/authenticate", "POST", helper.UserACredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// get the length of the GET all simulators response again
|
// get the length of the GET all ICs response again
|
||||||
finalNumber2, err := helper.LengthOfResponse(router, token,
|
finalNumber2, err := helper.LengthOfResponse(router, token,
|
||||||
"/api/simulators", "GET", nil)
|
"/api/ic", "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
assert.Equal(t, finalNumber2, initialNumber+2)
|
assert.Equal(t, finalNumber2, initialNumber+2)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetSimulationModelsOfSimulator(t *testing.T) {
|
func TestGetConfigsOfIC(t *testing.T) {
|
||||||
database.DropTables(db)
|
database.DropTables(db)
|
||||||
database.MigrateModels(db)
|
database.MigrateModels(db)
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
@ -430,27 +430,27 @@ func TestGetSimulationModelsOfSimulator(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.AdminCredentials)
|
"/api/authenticate", "POST", helper.AdminCredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// test POST simulators/ $newSimulatorA
|
// test POST ic/ $newICA
|
||||||
newSimulatorA := SimulatorRequest{
|
newICA := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
code, resp, err := helper.TestEndpoint(router, token,
|
code, resp, err := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulatorA})
|
"/api/ic", "POST", helper.KeyModels{"ic": newICA})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
// Read newSimulator's ID from the response
|
// Read newIC's ID from the response
|
||||||
newSimulatorID, err := helper.GetResponseID(resp)
|
newICID, err := helper.GetResponseID(resp)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// test GET simulators/ID/models
|
// test GET ic/ID/models
|
||||||
// TODO how to properly test this without using simulation model endpoints?
|
// TODO how to properly test this without using simulation model endpoints?
|
||||||
numberOfModels, err := helper.LengthOfResponse(router, token,
|
numberOfModels, err := helper.LengthOfResponse(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v/models", newSimulatorID), "GET", nil)
|
fmt.Sprintf("/api/ic/%v/models", newICID), "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
|
@ -461,19 +461,19 @@ func TestGetSimulationModelsOfSimulator(t *testing.T) {
|
||||||
"/api/authenticate", "POST", helper.UserACredentials)
|
"/api/authenticate", "POST", helper.UserACredentials)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// test GET simulators/ID/models
|
// test GET ic/ID/models
|
||||||
// TODO how to properly test this without using simulation model endpoints?
|
// TODO how to properly test this without using simulation model endpoints?
|
||||||
numberOfModels, err = helper.LengthOfResponse(router, token,
|
numberOfModels, err = helper.LengthOfResponse(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v/models", newSimulatorID), "GET", nil)
|
fmt.Sprintf("/api/ic/%v/models", newICID), "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 200, code, "Response body: \n%v\n", resp)
|
||||||
|
|
||||||
assert.Equal(t, 0, numberOfModels)
|
assert.Equal(t, 0, numberOfModels)
|
||||||
|
|
||||||
// Try to get models of simulator that does not exist
|
// Try to get models of IC that does not exist
|
||||||
// should result in not found
|
// should result in not found
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/simulators/%v/models", newSimulatorID+1), "GET", nil)
|
fmt.Sprintf("/api/ic/%v/models", newICID+1), "GET", nil)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equalf(t, 404, code, "Response body: \n%v\n", resp)
|
assert.Equalf(t, 404, code, "Response body: \n%v\n", resp)
|
||||||
}
|
}
|
|
@ -1,4 +1,4 @@
|
||||||
/** Simulator package, validators.
|
/** InfrastructureComponent package, validators.
|
||||||
*
|
*
|
||||||
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
* @author Sonja Happ <sonja.happ@eonerc.rwth-aachen.de>
|
||||||
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC
|
||||||
|
@ -19,7 +19,7 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*********************************************************************************/
|
*********************************************************************************/
|
||||||
package simulator
|
package infrastructure_component
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
@ -30,7 +30,7 @@ import (
|
||||||
|
|
||||||
var validate *validator.Validate
|
var validate *validator.Validate
|
||||||
|
|
||||||
type validNewSimulator struct {
|
type validNewIC struct {
|
||||||
UUID string `form:"UUID" validate:"required"`
|
UUID string `form:"UUID" validate:"required"`
|
||||||
Host string `form:"Host" validate:"required"`
|
Host string `form:"Host" validate:"required"`
|
||||||
Modeltype string `form:"Modeltype" validate:"required"`
|
Modeltype string `form:"Modeltype" validate:"required"`
|
||||||
|
@ -38,7 +38,7 @@ type validNewSimulator struct {
|
||||||
State string `form:"State"`
|
State string `form:"State"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type validUpdatedSimulator struct {
|
type validUpdatedIC struct {
|
||||||
UUID string `form:"UUID" validate:"omitempty"`
|
UUID string `form:"UUID" validate:"omitempty"`
|
||||||
Host string `form:"Host" validate:"omitempty"`
|
Host string `form:"Host" validate:"omitempty"`
|
||||||
Modeltype string `form:"Modeltype" validate:"omitempty"`
|
Modeltype string `form:"Modeltype" validate:"omitempty"`
|
||||||
|
@ -46,68 +46,68 @@ type validUpdatedSimulator struct {
|
||||||
State string `form:"State" validate:"omitempty"`
|
State string `form:"State" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type addSimulatorRequest struct {
|
type addICRequest struct {
|
||||||
Simulator validNewSimulator `json:"simulator"`
|
InfrastructureComponent validNewIC `json:"ic"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type updateSimulatorRequest struct {
|
type updateICRequest struct {
|
||||||
Simulator validUpdatedSimulator `json:"simulator"`
|
InfrastructureComponent validUpdatedIC `json:"ic"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *addSimulatorRequest) validate() error {
|
func (r *addICRequest) validate() error {
|
||||||
validate = validator.New()
|
validate = validator.New()
|
||||||
errs := validate.Struct(r)
|
errs := validate.Struct(r)
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *validUpdatedSimulator) validate() error {
|
func (r *validUpdatedIC) validate() error {
|
||||||
validate = validator.New()
|
validate = validator.New()
|
||||||
errs := validate.Struct(r)
|
errs := validate.Struct(r)
|
||||||
return errs
|
return errs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *addSimulatorRequest) createSimulator() Simulator {
|
func (r *addICRequest) createIC() InfrastructureComponent {
|
||||||
var s Simulator
|
var s InfrastructureComponent
|
||||||
|
|
||||||
s.UUID = r.Simulator.UUID
|
s.UUID = r.InfrastructureComponent.UUID
|
||||||
s.Host = r.Simulator.Host
|
s.Host = r.InfrastructureComponent.Host
|
||||||
s.Modeltype = r.Simulator.Modeltype
|
s.Modeltype = r.InfrastructureComponent.Modeltype
|
||||||
s.Properties = r.Simulator.Properties
|
s.Properties = r.InfrastructureComponent.Properties
|
||||||
if r.Simulator.State != "" {
|
if r.InfrastructureComponent.State != "" {
|
||||||
s.State = r.Simulator.State
|
s.State = r.InfrastructureComponent.State
|
||||||
}
|
}
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *updateSimulatorRequest) updatedSimulator(oldSimulator Simulator) Simulator {
|
func (r *updateICRequest) updatedIC(oldIC InfrastructureComponent) InfrastructureComponent {
|
||||||
// Use the old Simulator as a basis for the updated Simulator `s`
|
// Use the old InfrastructureComponent as a basis for the updated InfrastructureComponent `s`
|
||||||
s := oldSimulator
|
s := oldIC
|
||||||
|
|
||||||
if r.Simulator.UUID != "" {
|
if r.InfrastructureComponent.UUID != "" {
|
||||||
s.UUID = r.Simulator.UUID
|
s.UUID = r.InfrastructureComponent.UUID
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Simulator.Host != "" {
|
if r.InfrastructureComponent.Host != "" {
|
||||||
s.Host = r.Simulator.Host
|
s.Host = r.InfrastructureComponent.Host
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Simulator.Modeltype != "" {
|
if r.InfrastructureComponent.Modeltype != "" {
|
||||||
s.Modeltype = r.Simulator.Modeltype
|
s.Modeltype = r.InfrastructureComponent.Modeltype
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.Simulator.State != "" {
|
if r.InfrastructureComponent.State != "" {
|
||||||
s.State = r.Simulator.State
|
s.State = r.InfrastructureComponent.State
|
||||||
}
|
}
|
||||||
|
|
||||||
// only update props if not empty
|
// only update props if not empty
|
||||||
var emptyJson postgres.Jsonb
|
var emptyJson postgres.Jsonb
|
||||||
// Serialize empty json and params
|
// Serialize empty json and params
|
||||||
emptyJson_ser, _ := json.Marshal(emptyJson)
|
emptyJson_ser, _ := json.Marshal(emptyJson)
|
||||||
startParams_ser, _ := json.Marshal(r.Simulator.Properties)
|
startParams_ser, _ := json.Marshal(r.InfrastructureComponent.Properties)
|
||||||
opts := jsondiff.DefaultConsoleOptions()
|
opts := jsondiff.DefaultConsoleOptions()
|
||||||
diff, _ := jsondiff.Compare(emptyJson_ser, startParams_ser, &opts)
|
diff, _ := jsondiff.Compare(emptyJson_ser, startParams_ser, &opts)
|
||||||
if diff.String() != "FullMatch" {
|
if diff.String() != "FullMatch" {
|
||||||
s.Properties = r.Simulator.Properties
|
s.Properties = r.InfrastructureComponent.Properties
|
||||||
}
|
}
|
||||||
|
|
||||||
return s
|
return s
|
|
@ -30,10 +30,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
SimulatorCounter = prometheus.NewCounter(
|
ICCounter = prometheus.NewCounter(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Name: "simulators",
|
Name: "infrastructure_components",
|
||||||
Help: "A counter for the total number of simulators",
|
Help: "A counter for the total number of infrastructure_components",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ func RegisterMetricsEndpoint(rg *gin.RouterGroup) {
|
||||||
|
|
||||||
// Register metrics
|
// Register metrics
|
||||||
prometheus.MustRegister(
|
prometheus.MustRegister(
|
||||||
SimulatorCounter,
|
ICCounter,
|
||||||
SimulationModelCounter,
|
SimulationModelCounter,
|
||||||
FileCounter,
|
FileCounter,
|
||||||
ScenarioCounter,
|
ScenarioCounter,
|
||||||
|
@ -112,16 +112,16 @@ func RegisterMetricsEndpoint(rg *gin.RouterGroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitCounters(db *gorm.DB) {
|
func InitCounters(db *gorm.DB) {
|
||||||
var simulators, simulation_models, files, scenarios, users, dashboards float64
|
var infrastructure_components, simulation_models, files, scenarios, users, dashboards float64
|
||||||
|
|
||||||
db.Table("simulators").Count(&simulators)
|
db.Table("infrastructure_components").Count(&infrastructure_components)
|
||||||
db.Table("simulation_models").Count(&simulation_models)
|
db.Table("simulation_models").Count(&simulation_models)
|
||||||
db.Table("files").Count(&files)
|
db.Table("files").Count(&files)
|
||||||
db.Table("scenarios").Count(&scenarios)
|
db.Table("scenarios").Count(&scenarios)
|
||||||
db.Table("users").Count(&users)
|
db.Table("users").Count(&users)
|
||||||
db.Table("dashboards").Count(&dashboards)
|
db.Table("dashboards").Count(&dashboards)
|
||||||
|
|
||||||
SimulatorCounter.Add(simulators)
|
ICCounter.Add(infrastructure_components)
|
||||||
SimulationModelCounter.Add(simulation_models)
|
SimulationModelCounter.Add(simulation_models)
|
||||||
FileCounter.Add(files)
|
FileCounter.Add(files)
|
||||||
ScenarioCounter.Add(scenarios)
|
ScenarioCounter.Add(scenarios)
|
||||||
|
|
|
@ -26,9 +26,9 @@ import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"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/helper"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulator"
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
@ -52,11 +52,11 @@ type SignalRequest struct {
|
||||||
type SimulationModelRequest struct {
|
type SimulationModelRequest struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
ScenarioID uint `json:"scenarioID,omitempty"`
|
ScenarioID uint `json:"scenarioID,omitempty"`
|
||||||
SimulatorID uint `json:"simulatorID,omitempty"`
|
ICID uint `json:"icID,omitempty"`
|
||||||
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SimulatorRequest struct {
|
type ICRequest struct {
|
||||||
UUID string `json:"uuid,omitempty"`
|
UUID string `json:"uuid,omitempty"`
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Modeltype string `json:"modelType,omitempty"`
|
Modeltype string `json:"modelType,omitempty"`
|
||||||
|
@ -70,25 +70,25 @@ type ScenarioRequest struct {
|
||||||
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func addScenarioAndSimulatorAndSimulationModel() (scenarioID uint, simulatorID uint, simulationModelID uint) {
|
func addScenarioAndICAndSimulationModel() (scenarioID uint, ICID uint, simulationModelID uint) {
|
||||||
|
|
||||||
// authenticate as admin
|
// authenticate as admin
|
||||||
token, _ := helper.AuthenticateForTest(router,
|
token, _ := helper.AuthenticateForTest(router,
|
||||||
"/api/authenticate", "POST", helper.AdminCredentials)
|
"/api/authenticate", "POST", helper.AdminCredentials)
|
||||||
|
|
||||||
// POST $newSimulatorA
|
// POST $newICA
|
||||||
newSimulatorA := SimulatorRequest{
|
newICA := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
_, resp, _ := helper.TestEndpoint(router, token,
|
_, resp, _ := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulatorA})
|
"/api/ic", "POST", helper.KeyModels{"ic": newICA})
|
||||||
|
|
||||||
// Read newSimulator's ID from the response
|
// Read newIC's ID from the response
|
||||||
newSimulatorID, _ := helper.GetResponseID(resp)
|
newICID, _ := helper.GetResponseID(resp)
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, _ = helper.AuthenticateForTest(router,
|
token, _ = helper.AuthenticateForTest(router,
|
||||||
|
@ -110,7 +110,7 @@ func addScenarioAndSimulatorAndSimulationModel() (scenarioID uint, simulatorID u
|
||||||
newSimulationModel := SimulationModelRequest{
|
newSimulationModel := SimulationModelRequest{
|
||||||
Name: database.SimulationModelA.Name,
|
Name: database.SimulationModelA.Name,
|
||||||
ScenarioID: uint(newScenarioID),
|
ScenarioID: uint(newScenarioID),
|
||||||
SimulatorID: uint(newSimulatorID),
|
ICID: uint(newICID),
|
||||||
StartParameters: database.SimulationModelA.StartParameters,
|
StartParameters: database.SimulationModelA.StartParameters,
|
||||||
}
|
}
|
||||||
_, resp, _ = helper.TestEndpoint(router, token,
|
_, resp, _ = helper.TestEndpoint(router, token,
|
||||||
|
@ -123,7 +123,7 @@ func addScenarioAndSimulatorAndSimulationModel() (scenarioID uint, simulatorID u
|
||||||
_, resp, _ = helper.TestEndpoint(router, token,
|
_, resp, _ = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/scenarios/%v/user?username=User_C", newScenarioID), "PUT", nil)
|
fmt.Sprintf("/api/scenarios/%v/user?username=User_C", newScenarioID), "PUT", nil)
|
||||||
|
|
||||||
return uint(newScenarioID), uint(newSimulatorID), uint(newSimulationModelID)
|
return uint(newScenarioID), uint(newICID), uint(newSimulationModelID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -149,9 +149,9 @@ func TestMain(m *testing.M) {
|
||||||
// scenario endpoints required here to first add a scenario to the DB
|
// scenario endpoints required here to first add a scenario to the DB
|
||||||
// that can be associated with a new simulation model
|
// that can be associated with a new simulation model
|
||||||
scenario.RegisterScenarioEndpoints(api.Group("/scenarios"))
|
scenario.RegisterScenarioEndpoints(api.Group("/scenarios"))
|
||||||
// simulator endpoints required here to first add a simulator to the DB
|
// IC endpoints required here to first add a IC to the DB
|
||||||
// that can be associated with a new simulation model
|
// that can be associated with a new simulation model
|
||||||
simulator.RegisterSimulatorEndpoints(api.Group("/simulators"))
|
infrastructure_component.RegisterICEndpoints(api.Group("/ic"))
|
||||||
RegisterSignalEndpoints(api.Group("/signals"))
|
RegisterSignalEndpoints(api.Group("/signals"))
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
|
@ -163,9 +163,9 @@ func TestAddSignal(t *testing.T) {
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// by adding a scenario and a simulator to the DB
|
// by adding a scenario and a IC to the DB
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
_, _, simulationModelID := addScenarioAndSimulatorAndSimulationModel()
|
_, _, simulationModelID := addScenarioAndICAndSimulationModel()
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, err := helper.AuthenticateForTest(router,
|
token, err := helper.AuthenticateForTest(router,
|
||||||
|
@ -258,9 +258,9 @@ func TestUpdateSignal(t *testing.T) {
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// by adding a scenario and a simulator to the DB
|
// by adding a scenario and a IC to the DB
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
_, _, simulationModelID := addScenarioAndSimulatorAndSimulationModel()
|
_, _, simulationModelID := addScenarioAndICAndSimulationModel()
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, err := helper.AuthenticateForTest(router,
|
token, err := helper.AuthenticateForTest(router,
|
||||||
|
@ -360,9 +360,9 @@ func TestDeleteSignal(t *testing.T) {
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// by adding a scenario and a simulator to the DB
|
// by adding a scenario and a IC to the DB
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
_, _, simulationModelID := addScenarioAndSimulatorAndSimulationModel()
|
_, _, simulationModelID := addScenarioAndICAndSimulationModel()
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, err := helper.AuthenticateForTest(router,
|
token, err := helper.AuthenticateForTest(router,
|
||||||
|
@ -455,9 +455,9 @@ func TestGetAllInputSignalsOfSimulationModel(t *testing.T) {
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// by adding a scenario and a simulator to the DB
|
// by adding a scenario and a IC to the DB
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
_, _, simulationModelID := addScenarioAndSimulatorAndSimulationModel()
|
_, _, simulationModelID := addScenarioAndICAndSimulationModel()
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, err := helper.AuthenticateForTest(router,
|
token, err := helper.AuthenticateForTest(router,
|
||||||
|
|
|
@ -79,7 +79,7 @@ func getSimulationModels(c *gin.Context) {
|
||||||
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
// @Failure 422 {object} docs.ResponseError "Unprocessable entity"
|
||||||
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
// @Failure 500 {object} docs.ResponseError "Internal server error"
|
||||||
// @Param Authorization header string true "Authorization token"
|
// @Param Authorization header string true "Authorization token"
|
||||||
// @Param inputSimulationModel body simulationmodel.addSimulationModelRequest true "Simulation model to be added incl. IDs of scenario and simulator"
|
// @Param inputSimulationModel body simulationmodel.addSimulationModelRequest true "Simulation model to be added incl. IDs of scenario and IC"
|
||||||
// @Router /models [post]
|
// @Router /models [post]
|
||||||
func addSimulationModel(c *gin.Context) {
|
func addSimulationModel(c *gin.Context) {
|
||||||
|
|
||||||
|
|
|
@ -23,8 +23,8 @@ package simulationmodel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulator"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SimulationModel struct {
|
type SimulationModel struct {
|
||||||
|
@ -60,10 +60,10 @@ func (m *SimulationModel) addToScenario() error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// associate simulator with simulation model
|
// associate IC with simulation model
|
||||||
var simltr simulator.Simulator
|
var ic infrastructure_component.InfrastructureComponent
|
||||||
err = simltr.ByID(m.SimulatorID)
|
err = ic.ByID(m.ICID)
|
||||||
err = db.Model(&simltr).Association("SimulationModels").Append(m).Error
|
err = db.Model(&ic).Association("SimulationModels").Append(m).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -77,25 +77,25 @@ func (m *SimulationModel) addToScenario() error {
|
||||||
func (m *SimulationModel) Update(modifiedSimulationModel SimulationModel) error {
|
func (m *SimulationModel) Update(modifiedSimulationModel SimulationModel) error {
|
||||||
db := database.GetDB()
|
db := database.GetDB()
|
||||||
|
|
||||||
// check if simulator has been updated
|
// check if IC has been updated
|
||||||
if m.SimulatorID != modifiedSimulationModel.SimulatorID {
|
if m.ICID != modifiedSimulationModel.ICID {
|
||||||
// update simulator
|
// update IC
|
||||||
var s simulator.Simulator
|
var s infrastructure_component.InfrastructureComponent
|
||||||
var s_old simulator.Simulator
|
var s_old infrastructure_component.InfrastructureComponent
|
||||||
err := s.ByID(modifiedSimulationModel.SimulatorID)
|
err := s.ByID(modifiedSimulationModel.ICID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = s_old.ByID(m.SimulatorID)
|
err = s_old.ByID(m.ICID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// remove simulation model from old simulator
|
// remove simulation model from old IC
|
||||||
err = db.Model(&s_old).Association("SimulationModels").Delete(m).Error
|
err = db.Model(&s_old).Association("SimulationModels").Delete(m).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// add simulation model to new simulator
|
// add simulation model to new IC
|
||||||
err = db.Model(&s).Association("SimulationModels").Append(m).Error
|
err = db.Model(&s).Association("SimulationModels").Append(m).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -105,7 +105,7 @@ func (m *SimulationModel) Update(modifiedSimulationModel SimulationModel) error
|
||||||
err := db.Model(m).Updates(map[string]interface{}{
|
err := db.Model(m).Updates(map[string]interface{}{
|
||||||
"Name": modifiedSimulationModel.Name,
|
"Name": modifiedSimulationModel.Name,
|
||||||
"StartParameters": modifiedSimulationModel.StartParameters,
|
"StartParameters": modifiedSimulationModel.StartParameters,
|
||||||
"SimulatorID": modifiedSimulationModel.SimulatorID,
|
"ICID": modifiedSimulationModel.ICID,
|
||||||
"SelectedModelFileID": modifiedSimulationModel.SelectedModelFileID,
|
"SelectedModelFileID": modifiedSimulationModel.SelectedModelFileID,
|
||||||
}).Error
|
}).Error
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@ import (
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/database"
|
"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/helper"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulator"
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/jinzhu/gorm"
|
"github.com/jinzhu/gorm"
|
||||||
|
@ -43,12 +43,12 @@ var db *gorm.DB
|
||||||
type SimulationModelRequest struct {
|
type SimulationModelRequest struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
ScenarioID uint `json:"scenarioID,omitempty"`
|
ScenarioID uint `json:"scenarioID,omitempty"`
|
||||||
SimulatorID uint `json:"simulatorID,omitempty"`
|
ICID uint `json:"icID,omitempty"`
|
||||||
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
||||||
SelectedModelFileID uint `json:"selectedModelFileID,omitempty"`
|
SelectedModelFileID uint `json:"selectedModelFileID,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SimulatorRequest struct {
|
type ICRequest struct {
|
||||||
UUID string `json:"uuid,omitempty"`
|
UUID string `json:"uuid,omitempty"`
|
||||||
Host string `json:"host,omitempty"`
|
Host string `json:"host,omitempty"`
|
||||||
Modeltype string `json:"modelType,omitempty"`
|
Modeltype string `json:"modelType,omitempty"`
|
||||||
|
@ -62,36 +62,36 @@ type ScenarioRequest struct {
|
||||||
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
StartParameters postgres.Jsonb `json:"startParameters,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func addScenarioAndSimulator() (scenarioID uint, simulatorID uint) {
|
func addScenarioAndIC() (scenarioID uint, ICID uint) {
|
||||||
|
|
||||||
// authenticate as admin
|
// authenticate as admin
|
||||||
token, _ := helper.AuthenticateForTest(router,
|
token, _ := helper.AuthenticateForTest(router,
|
||||||
"/api/authenticate", "POST", helper.AdminCredentials)
|
"/api/authenticate", "POST", helper.AdminCredentials)
|
||||||
|
|
||||||
// POST $newSimulatorA
|
// POST $newICA
|
||||||
newSimulatorA := SimulatorRequest{
|
newICA := ICRequest{
|
||||||
UUID: database.SimulatorA.UUID,
|
UUID: database.ICA.UUID,
|
||||||
Host: database.SimulatorA.Host,
|
Host: database.ICA.Host,
|
||||||
Modeltype: database.SimulatorA.Modeltype,
|
Modeltype: database.ICA.Modeltype,
|
||||||
State: database.SimulatorA.State,
|
State: database.ICA.State,
|
||||||
Properties: database.SimulatorA.Properties,
|
Properties: database.ICA.Properties,
|
||||||
}
|
}
|
||||||
_, resp, _ := helper.TestEndpoint(router, token,
|
_, resp, _ := helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulatorA})
|
"/api/ic", "POST", helper.KeyModels{"ic": newICA})
|
||||||
|
|
||||||
// Read newSimulator's ID from the response
|
// Read newIC's ID from the response
|
||||||
newSimulatorID, _ := helper.GetResponseID(resp)
|
newICID, _ := helper.GetResponseID(resp)
|
||||||
|
|
||||||
// POST a second simulator to change to that simulator during testing
|
// POST a second IC to change to that IC during testing
|
||||||
newSimulatorB := SimulatorRequest{
|
newICB := ICRequest{
|
||||||
UUID: database.SimulatorB.UUID,
|
UUID: database.ICB.UUID,
|
||||||
Host: database.SimulatorB.Host,
|
Host: database.ICB.Host,
|
||||||
Modeltype: database.SimulatorB.Modeltype,
|
Modeltype: database.ICB.Modeltype,
|
||||||
State: database.SimulatorB.State,
|
State: database.ICB.State,
|
||||||
Properties: database.SimulatorB.Properties,
|
Properties: database.ICB.Properties,
|
||||||
}
|
}
|
||||||
_, resp, _ = helper.TestEndpoint(router, token,
|
_, resp, _ = helper.TestEndpoint(router, token,
|
||||||
"/api/simulators", "POST", helper.KeyModels{"simulator": newSimulatorB})
|
"/api/ic", "POST", helper.KeyModels{"ic": newICB})
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, _ = helper.AuthenticateForTest(router,
|
token, _ = helper.AuthenticateForTest(router,
|
||||||
|
@ -113,7 +113,7 @@ func addScenarioAndSimulator() (scenarioID uint, simulatorID uint) {
|
||||||
_, resp, _ = helper.TestEndpoint(router, token,
|
_, resp, _ = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/scenarios/%v/user?username=User_C", newScenarioID), "PUT", nil)
|
fmt.Sprintf("/api/scenarios/%v/user?username=User_C", newScenarioID), "PUT", nil)
|
||||||
|
|
||||||
return uint(newScenarioID), uint(newSimulatorID)
|
return uint(newScenarioID), uint(newICID)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
|
@ -137,9 +137,9 @@ func TestMain(m *testing.M) {
|
||||||
// scenario endpoints required here to first add a scenario to the DB
|
// scenario endpoints required here to first add a scenario to the DB
|
||||||
// that can be associated with a new simulation model
|
// that can be associated with a new simulation model
|
||||||
scenario.RegisterScenarioEndpoints(api.Group("/scenarios"))
|
scenario.RegisterScenarioEndpoints(api.Group("/scenarios"))
|
||||||
// simulator endpoints required here to first add a simulator to the DB
|
// IC endpoints required here to first add a IC to the DB
|
||||||
// that can be associated with a new simulation model
|
// that can be associated with a new simulation model
|
||||||
simulator.RegisterSimulatorEndpoints(api.Group("/simulators"))
|
infrastructure_component.RegisterICEndpoints(api.Group("/ic"))
|
||||||
|
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
@ -150,14 +150,14 @@ func TestAddSimulationModel(t *testing.T) {
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// by adding a scenario and a simulator to the DB
|
// by adding a scenario and a IC to the DB
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
scenarioID, simulatorID := addScenarioAndSimulator()
|
scenarioID, ICID := addScenarioAndIC()
|
||||||
|
|
||||||
newSimulationModel := SimulationModelRequest{
|
newSimulationModel := SimulationModelRequest{
|
||||||
Name: database.SimulationModelA.Name,
|
Name: database.SimulationModelA.Name,
|
||||||
ScenarioID: scenarioID,
|
ScenarioID: scenarioID,
|
||||||
SimulatorID: simulatorID,
|
ICID: ICID,
|
||||||
StartParameters: database.SimulationModelA.StartParameters,
|
StartParameters: database.SimulationModelA.StartParameters,
|
||||||
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
||||||
}
|
}
|
||||||
|
@ -246,9 +246,9 @@ func TestUpdateSimulationModel(t *testing.T) {
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// by adding a scenario and a simulator to the DB
|
// by adding a scenario and a IC to the DB
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
scenarioID, simulatorID := addScenarioAndSimulator()
|
scenarioID, ICID := addScenarioAndIC()
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, err := helper.AuthenticateForTest(router,
|
token, err := helper.AuthenticateForTest(router,
|
||||||
|
@ -259,7 +259,7 @@ func TestUpdateSimulationModel(t *testing.T) {
|
||||||
newSimulationModel := SimulationModelRequest{
|
newSimulationModel := SimulationModelRequest{
|
||||||
Name: database.SimulationModelA.Name,
|
Name: database.SimulationModelA.Name,
|
||||||
ScenarioID: scenarioID,
|
ScenarioID: scenarioID,
|
||||||
SimulatorID: simulatorID,
|
ICID: ICID,
|
||||||
StartParameters: database.SimulationModelA.StartParameters,
|
StartParameters: database.SimulationModelA.StartParameters,
|
||||||
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
||||||
}
|
}
|
||||||
|
@ -323,8 +323,8 @@ func TestUpdateSimulationModel(t *testing.T) {
|
||||||
err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": updatedSimulationModel})
|
err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": updatedSimulationModel})
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
||||||
//Change simulator ID to use second simulator available in DB
|
//Change IC ID to use second IC available in DB
|
||||||
updatedSimulationModel.SimulatorID = simulatorID + 1
|
updatedSimulationModel.ICID = ICID + 1
|
||||||
// test PUT again
|
// test PUT again
|
||||||
code, resp, err = helper.TestEndpoint(router, token,
|
code, resp, err = helper.TestEndpoint(router, token,
|
||||||
fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel})
|
fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel})
|
||||||
|
@ -358,14 +358,14 @@ func TestDeleteSimulationModel(t *testing.T) {
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// by adding a scenario and a simulator to the DB
|
// by adding a scenario and a IC to the DB
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
scenarioID, simulatorID := addScenarioAndSimulator()
|
scenarioID, ICID := addScenarioAndIC()
|
||||||
|
|
||||||
newSimulationModel := SimulationModelRequest{
|
newSimulationModel := SimulationModelRequest{
|
||||||
Name: database.SimulationModelA.Name,
|
Name: database.SimulationModelA.Name,
|
||||||
ScenarioID: scenarioID,
|
ScenarioID: scenarioID,
|
||||||
SimulatorID: simulatorID,
|
ICID: ICID,
|
||||||
StartParameters: database.SimulationModelA.StartParameters,
|
StartParameters: database.SimulationModelA.StartParameters,
|
||||||
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
||||||
}
|
}
|
||||||
|
@ -431,9 +431,9 @@ func TestGetAllSimulationModelsOfScenario(t *testing.T) {
|
||||||
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
assert.NoError(t, database.DBAddAdminAndUserAndGuest(db))
|
||||||
|
|
||||||
// prepare the content of the DB for testing
|
// prepare the content of the DB for testing
|
||||||
// by adding a scenario and a simulator to the DB
|
// by adding a scenario and a IC to the DB
|
||||||
// using the respective endpoints of the API
|
// using the respective endpoints of the API
|
||||||
scenarioID, simulatorID := addScenarioAndSimulator()
|
scenarioID, ICID := addScenarioAndIC()
|
||||||
|
|
||||||
// authenticate as normal user
|
// authenticate as normal user
|
||||||
token, err := helper.AuthenticateForTest(router,
|
token, err := helper.AuthenticateForTest(router,
|
||||||
|
@ -444,7 +444,7 @@ func TestGetAllSimulationModelsOfScenario(t *testing.T) {
|
||||||
newSimulationModel := SimulationModelRequest{
|
newSimulationModel := SimulationModelRequest{
|
||||||
Name: database.SimulationModelA.Name,
|
Name: database.SimulationModelA.Name,
|
||||||
ScenarioID: scenarioID,
|
ScenarioID: scenarioID,
|
||||||
SimulatorID: simulatorID,
|
ICID: ICID,
|
||||||
StartParameters: database.SimulationModelA.StartParameters,
|
StartParameters: database.SimulationModelA.StartParameters,
|
||||||
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
SelectedModelFileID: database.SimulationModelA.SelectedModelFileID,
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,14 +33,14 @@ var validate *validator.Validate
|
||||||
type validNewSimulationModel struct {
|
type validNewSimulationModel struct {
|
||||||
Name string `form:"Name" validate:"required"`
|
Name string `form:"Name" validate:"required"`
|
||||||
ScenarioID uint `form:"ScenarioID" validate:"required"`
|
ScenarioID uint `form:"ScenarioID" validate:"required"`
|
||||||
SimulatorID uint `form:"SimulatorID" validate:"required"`
|
ICID uint `form:"ICID" validate:"required"`
|
||||||
StartParameters postgres.Jsonb `form:"StartParameters" validate:"required"`
|
StartParameters postgres.Jsonb `form:"StartParameters" validate:"required"`
|
||||||
SelectedModelFileID uint `form:"SelectedModelFilID" validate:"omitempty"`
|
SelectedModelFileID uint `form:"SelectedModelFilID" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type validUpdatedSimulationModel struct {
|
type validUpdatedSimulationModel struct {
|
||||||
Name string `form:"Name" validate:"omitempty"`
|
Name string `form:"Name" validate:"omitempty"`
|
||||||
SimulatorID uint `form:"SimulatorID" validate:"omitempty"`
|
ICID uint `form:"ICID" validate:"omitempty"`
|
||||||
StartParameters postgres.Jsonb `form:"StartParameters" validate:"omitempty"`
|
StartParameters postgres.Jsonb `form:"StartParameters" validate:"omitempty"`
|
||||||
SelectedModelFileID uint `form:"SelectedModelFileID" validate:"omitempty"`
|
SelectedModelFileID uint `form:"SelectedModelFileID" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
@ -70,7 +70,7 @@ func (r *addSimulationModelRequest) createSimulationModel() SimulationModel {
|
||||||
|
|
||||||
s.Name = r.SimulationModel.Name
|
s.Name = r.SimulationModel.Name
|
||||||
s.ScenarioID = r.SimulationModel.ScenarioID
|
s.ScenarioID = r.SimulationModel.ScenarioID
|
||||||
s.SimulatorID = r.SimulationModel.SimulatorID
|
s.ICID = r.SimulationModel.ICID
|
||||||
s.StartParameters = r.SimulationModel.StartParameters
|
s.StartParameters = r.SimulationModel.StartParameters
|
||||||
s.SelectedModelFileID = r.SimulationModel.SelectedModelFileID
|
s.SelectedModelFileID = r.SimulationModel.SelectedModelFileID
|
||||||
|
|
||||||
|
@ -85,8 +85,8 @@ func (r *updateSimulationModelRequest) updatedSimulationModel(oldSimulationModel
|
||||||
s.Name = r.SimulationModel.Name
|
s.Name = r.SimulationModel.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.SimulationModel.SimulatorID != 0 {
|
if r.SimulationModel.ICID != 0 {
|
||||||
s.SimulatorID = r.SimulationModel.SimulatorID
|
s.ICID = r.SimulationModel.ICID
|
||||||
}
|
}
|
||||||
|
|
||||||
if r.SimulationModel.SelectedModelFileID != 0 {
|
if r.SimulationModel.SelectedModelFileID != 0 {
|
||||||
|
|
10
start.go
10
start.go
|
@ -36,11 +36,11 @@ import (
|
||||||
apidocs "git.rwth-aachen.de/acs/public/villas/web-backend-go/doc/api" // doc/api folder is used by Swag CLI, you have to import it
|
apidocs "git.rwth-aachen.de/acs/public/villas/web-backend-go/doc/api" // doc/api folder is used by Swag CLI, you have to import it
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/dashboard"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/dashboard"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/file"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/file"
|
||||||
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/metrics"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/metrics"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/signal"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/signal"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulator"
|
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user"
|
||||||
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget"
|
"git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget"
|
||||||
)
|
)
|
||||||
|
@ -120,7 +120,7 @@ func main() {
|
||||||
widget.RegisterWidgetEndpoints(api.Group("/widgets"))
|
widget.RegisterWidgetEndpoints(api.Group("/widgets"))
|
||||||
file.RegisterFileEndpoints(api.Group("/files"))
|
file.RegisterFileEndpoints(api.Group("/files"))
|
||||||
user.RegisterUserEndpoints(api.Group("/users"))
|
user.RegisterUserEndpoints(api.Group("/users"))
|
||||||
simulator.RegisterSimulatorEndpoints(api.Group("/simulators"))
|
infrastructure_component.RegisterICEndpoints(api.Group("/ic"))
|
||||||
|
|
||||||
r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||||
|
|
||||||
|
@ -133,10 +133,10 @@ func main() {
|
||||||
log.Panic(err)
|
log.Panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// register simulator action endpoint only if AMQP client is used
|
// register IC action endpoint only if AMQP client is used
|
||||||
amqp.RegisterAMQPEndpoint(api.Group("/simulators"))
|
amqp.RegisterAMQPEndpoint(api.Group("/ic"))
|
||||||
|
|
||||||
// Periodically call the Ping function to check which simulators are still there
|
// Periodically call the Ping function to check which ICs are still there
|
||||||
ticker := time.NewTicker(10 * time.Second)
|
ticker := time.NewTicker(10 * time.Second)
|
||||||
go func() {
|
go func() {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue