diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ca20532..6b5bb51 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -95,10 +95,10 @@ test:scenario: variables: TEST_FOLDER: routes/scenario -test:simulationmodel: - extends: test:scenario +test:component-configuration: + extends: test:database variables: - TEST_FOLDER: routes/simulationmodel + TEST_FOLDER: routes/component-configuration test:signal: extends: test:database @@ -115,10 +115,10 @@ test:widget: variables: TEST_FOLDER: routes/widget -test:simulator: +test:infrastructure-component: extends: test:database variables: - TEST_FOLDER: routes/simulator + TEST_FOLDER: routes/infrastructure-component test:file: extends: test:database diff --git a/amqp/amqp_endpoints.go b/amqp/amqp_endpoints.go index 21a145e..ff4e3bf 100644 --- a/amqp/amqp_endpoints.go +++ b/amqp/amqp_endpoints.go @@ -24,32 +24,32 @@ package amqp import ( "git.rwth-aachen.de/acs/public/villas/web-backend-go/database" "git.rwth-aachen.de/acs/public/villas/web-backend-go/helper" - "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulator" + "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/infrastructure-component" "github.com/gin-gonic/gin" "net/http" "time" ) func RegisterAMQPEndpoint(r *gin.RouterGroup) { - r.POST("/:simulatorID/action", sendActionToSimulator) + r.POST("/ICID/action", sendActionToIC) } -// sendActionToSimulator godoc -// @Summary Send an action to simulator (only available if backend server is started with -amqp parameter) -// @ID sendActionToSimulator +// sendActionToIC godoc +// @Summary Send an action to IC (only available if backend server is started with -amqp parameter) +// @ID sendActionToIC // @Tags AMQP // @Produce json -// @Param inputAction query string true "Action for simulator" +// @Param inputAction query string true "Action for IC" // @Success 200 {object} docs.ResponseError "Action sent successfully" // @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" -// @Param simulatorID path int true "Simulator ID" -// @Router /simulators/{simulatorID}/action [post] -func sendActionToSimulator(c *gin.Context) { +// @Param ICID path int true "InfrastructureComponent ID" +// @Router /ic/{ICID}/action [post] +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 { return } @@ -70,7 +70,7 @@ func sendActionToSimulator(c *gin.Context) { err = SendActionAMQP(action, s.UUID) if err != nil { - helper.InternalServerError(c, "Unable to send actions to simulator: "+err.Error()) + helper.InternalServerError(c, "Unable to send actions to IC: "+err.Error()) return } } diff --git a/amqp/amqpclient.go b/amqp/amqpclient.go index 53c3597..374d4d5 100644 --- a/amqp/amqpclient.go +++ b/amqp/amqpclient.go @@ -77,8 +77,8 @@ func ConnectAMQP(uri string) error { return fmt.Errorf("AMQP: failed to declare the exchange") } - // add a queue for the simulators - simulatorQueue, err := client.channel.QueueDeclare("simulators", + // add a queue for the ICs + ICQueue, err := client.channel.QueueDeclare("infrastructure_components", true, false, false, @@ -88,13 +88,13 @@ func ConnectAMQP(uri string) error { return fmt.Errorf("AMQP: failed to declare the queue") } - err = client.channel.QueueBind(simulatorQueue.Name, "", VILLAS_EXCHANGE, false, nil) + err = client.channel.QueueBind(ICQueue.Name, "", VILLAS_EXCHANGE, false, nil) if err != nil { return fmt.Errorf("AMQP: failed to bind the queue") } // consume deliveries - client.replies, err = client.channel.Consume(simulatorQueue.Name, + client.replies, err = client.channel.Consume(ICQueue.Name, "", false, false, @@ -120,15 +120,15 @@ func ConnectAMQP(uri string) error { continue } - var sToBeUpdated database.Simulator + var sToBeUpdated database.InfrastructureComponent db := database.GetDB() - simulatorUUID := gjson.Get(content, "properties.uuid").String() - if simulatorUUID == "" { - log.Println("AMQP: Could not extract UUID of simulator from content of received message, SIMULATOR NOT UPDATED") + ICUUID := gjson.Get(content, "properties.uuid").String() + if ICUUID == "" { + log.Println("AMQP: Could not extract UUID of IC from content of received message, COMPONENT NOT UPDATED") } else { - err = db.Where("UUID = ?", simulatorUUID).Find(sToBeUpdated).Error + err = db.Where("UUID = ?", ICUUID).Find(sToBeUpdated).Error if err != nil { - log.Println("AMQP: Unable to find simulator with UUID: ", gjson.Get(content, "properties.uuid"), " DB error message: ", err) + log.Println("AMQP: Unable to find IC with UUID: ", gjson.Get(content, "properties.uuid"), " DB error message: ", err) } err = db.Model(&sToBeUpdated).Updates(map[string]interface{}{ @@ -140,10 +140,10 @@ func ConnectAMQP(uri string) error { "RawProperties": gjson.Get(content, "properties"), }).Error if err != nil { - log.Println("AMQP: Unable to update simulator in DB: ", err) + log.Println("AMQP: Unable to update IC in DB: ", err) } - log.Println("AMQP: Updated simulator with UUID ", gjson.Get(content, "properties.uuid")) + log.Println("AMQP: Updated IC with UUID ", gjson.Get(content, "properties.uuid")) } } }() @@ -182,7 +182,7 @@ func SendActionAMQP(action Action, uuid string) error { } func PingAMQP() error { - log.Println("AMQP: sending ping command to all simulators") + log.Println("AMQP: sending ping command to all ICs") var a Action a.Act = "ping" diff --git a/curl_villasAPI.sh b/curl_villasAPI.sh index 29b2eb5..db0cca6 100755 --- a/curl_villasAPI.sh +++ b/curl_villasAPI.sh @@ -55,9 +55,9 @@ read_users () { -X GET | jq '.' && printf '\n' } -read_simulators () { - printf "> GET "$apiBase"/simulators\n" - curl "$apiBase"/simulators -s \ +read_infrastructure_components () { + printf "> GET "$apiBase"/ic\n" + curl "$apiBase"/ic -s \ -H "Contet-Type: application/json" \ -H "Authorization: Bearer $(< auth.jwt)" \ -X GET | jq '.' && printf '\n' @@ -114,7 +114,7 @@ login "$admin" #create_user "$userC" #read_users #read_user 1 -#read_simulators +#read_infrastructure_components create_user "$newUserW" #read_users read_user 4 diff --git a/database/database.go b/database/database.go index c0b0500..4174f57 100644 --- a/database/database.go +++ b/database/database.go @@ -102,9 +102,9 @@ func GetDB() *gorm.DB { // TODO: Remove that function from the codebase and substitute the body // to the Dummy*() where it is called func DropTables(db *gorm.DB) { - db.DropTableIfExists(&Simulator{}) + db.DropTableIfExists(&InfrastructureComponent{}) db.DropTableIfExists(&Signal{}) - db.DropTableIfExists(&SimulationModel{}) + db.DropTableIfExists(&ComponentConfiguration{}) db.DropTableIfExists(&File{}) db.DropTableIfExists(&Scenario{}) db.DropTableIfExists(&User{}) @@ -116,9 +116,9 @@ func DropTables(db *gorm.DB) { // AutoMigrate the models func MigrateModels(db *gorm.DB) { - db.AutoMigrate(&Simulator{}) + db.AutoMigrate(&InfrastructureComponent{}) db.AutoMigrate(&Signal{}) - db.AutoMigrate(&SimulationModel{}) + db.AutoMigrate(&ComponentConfiguration{}) db.AutoMigrate(&File{}) db.AutoMigrate(&Scenario{}) db.AutoMigrate(&User{}) diff --git a/database/database_test.go b/database/database_test.go index 8476448..dd7c118 100644 --- a/database/database_test.go +++ b/database/database_test.go @@ -107,8 +107,8 @@ func TestScenarioAssociations(t *testing.T) { user0 := User0 userA := UserA userB := UserB - modelA := SimulationModelA - modelB := SimulationModelB + configA := ConfigA + configB := ConfigB dashboardA := DashboardA dashboardB := DashboardB @@ -121,9 +121,9 @@ func TestScenarioAssociations(t *testing.T) { assert.NoError(t, db.Create(&userA).Error) // Normal User assert.NoError(t, db.Create(&userB).Error) // Normal User - // add simulation models to DB - assert.NoError(t, db.Create(&modelA).Error) - assert.NoError(t, db.Create(&modelB).Error) + // add component configurations to DB + assert.NoError(t, db.Create(&configA).Error) + assert.NoError(t, db.Create(&configB).Error) // add dashboards to DB assert.NoError(t, db.Create(&dashboardA).Error) @@ -136,9 +136,9 @@ func TestScenarioAssociations(t *testing.T) { assert.NoError(t, db.Model(&scenarioB).Association("Users").Append(&userA).Error) assert.NoError(t, db.Model(&scenarioB).Association("Users").Append(&userB).Error) - // add scenario has many simulation models associations - assert.NoError(t, db.Model(&scenarioA).Association("SimulationModels").Append(&modelA).Error) - assert.NoError(t, db.Model(&scenarioA).Association("SimulationModels").Append(&modelB).Error) + // add scenario has many component configurations associations + assert.NoError(t, db.Model(&scenarioA).Association("ComponentConfigurations").Append(&configA).Error) + assert.NoError(t, db.Model(&scenarioA).Association("ComponentConfigurations").Append(&configB).Error) // Scenario HM Dashboards assert.NoError(t, db.Model(&scenarioA).Association("Dashboards").Append(&dashboardA).Error) @@ -156,12 +156,12 @@ func TestScenarioAssociations(t *testing.T) { "Expected to have %v Users. Has %v.", 2, len(users)) } - // Get simulation models of scenario1 - var models []SimulationModel - assert.NoError(t, db.Model(&scenario1).Related(&models, "SimulationModels").Error) - if len(models) != 2 { + // Get component configurations of scenario1 + var configs []ComponentConfiguration + assert.NoError(t, db.Model(&scenario1).Related(&configs, "ComponentConfigurations").Error) + if len(configs) != 2 { assert.Fail(t, "Scenario Associations", - "Expected to have %v simulation models. Has %v.", 2, len(models)) + "Expected to have %v component configs. Has %v.", 2, len(configs)) } // Get dashboards of scenario1 @@ -173,50 +173,50 @@ func TestScenarioAssociations(t *testing.T) { } } -func TestSimulatorAssociations(t *testing.T) { +func TestICAssociations(t *testing.T) { DropTables(db) MigrateModels(db) // create copies of global test data - simulatorA := SimulatorA - simulatorB := SimulatorB - modelA := SimulationModelA - modelB := SimulationModelB + icA := ICA + icB := ICB + configA := ConfigA + configB := ConfigB - // add simulators to DB - assert.NoError(t, db.Create(&simulatorA).Error) - assert.NoError(t, db.Create(&simulatorB).Error) + // add ICs to DB + assert.NoError(t, db.Create(&icA).Error) + assert.NoError(t, db.Create(&icB).Error) - // add simulation models to DB - assert.NoError(t, db.Create(&modelA).Error) - assert.NoError(t, db.Create(&modelB).Error) + // add component configurations to DB + assert.NoError(t, db.Create(&configA).Error) + assert.NoError(t, db.Create(&configB).Error) - // add simulator has many simulation models association to DB - assert.NoError(t, db.Model(&simulatorA).Association("SimulationModels").Append(&modelA).Error) - assert.NoError(t, db.Model(&simulatorA).Association("SimulationModels").Append(&modelB).Error) + // add IC has many component configurations association to DB + assert.NoError(t, db.Model(&icA).Association("ComponentConfigurations").Append(&configA).Error) + assert.NoError(t, db.Model(&icA).Association("ComponentConfigurations").Append(&configB).Error) - var simulator1 Simulator - assert.NoError(t, db.Find(&simulator1, 1).Error, fmt.Sprintf("Find Simulator with ID=1")) - assert.EqualValues(t, "Host_A", simulator1.Host) + var ic1 InfrastructureComponent + assert.NoError(t, db.Find(&ic1, 1).Error, fmt.Sprintf("Find InfrastructureComponent with ID=1")) + assert.EqualValues(t, "Host_A", ic1.Host) - // Get simulation models of simulator1 - var models []SimulationModel - assert.NoError(t, db.Model(&simulator1).Association("SimulationModels").Find(&models).Error) - if len(models) != 2 { - assert.Fail(t, "Simulator Associations", - "Expected to have %v SimulationModels. Has %v.", 2, len(models)) + // Get Component Configurations of ic1 + var configs []ComponentConfiguration + assert.NoError(t, db.Model(&ic1).Association("ComponentConfigurations").Find(&configs).Error) + if len(configs) != 2 { + assert.Fail(t, "InfrastructureComponent Associations", + "Expected to have %v Component Configurations. Has %v.", 2, len(configs)) } } -func TestSimulationModelAssociations(t *testing.T) { +func TestComponentConfigurationAssociations(t *testing.T) { DropTables(db) MigrateModels(db) // create copies of global test data - modelA := SimulationModelA - modelB := SimulationModelB + configA := ConfigA + configB := ConfigB outSignalA := OutSignalA outSignalB := OutSignalB inSignalA := InSignalA @@ -225,12 +225,12 @@ func TestSimulationModelAssociations(t *testing.T) { fileB := FileB fileC := FileC fileD := FileD - simulatorA := SimulatorA - simulatorB := SimulatorB + icA := ICA + icB := ICB - // add simulation models to DB - assert.NoError(t, db.Create(&modelA).Error) - assert.NoError(t, db.Create(&modelB).Error) + // add Component Configurations to DB + assert.NoError(t, db.Create(&configA).Error) + assert.NoError(t, db.Create(&configB).Error) // add signals to DB assert.NoError(t, db.Create(&outSignalA).Error) @@ -244,46 +244,46 @@ func TestSimulationModelAssociations(t *testing.T) { assert.NoError(t, db.Create(&fileC).Error) assert.NoError(t, db.Create(&fileD).Error) - // add simulators to DB - assert.NoError(t, db.Create(&simulatorA).Error) - assert.NoError(t, db.Create(&simulatorB).Error) + // add ICs to DB + assert.NoError(t, db.Create(&icA).Error) + assert.NoError(t, db.Create(&icB).Error) - // 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(&inSignalB).Error) - assert.NoError(t, db.Model(&modelA).Association("OutputMapping").Append(&outSignalA).Error) - assert.NoError(t, db.Model(&modelA).Association("OutputMapping").Append(&outSignalB).Error) + // add Component Configuration has many signals associations + assert.NoError(t, db.Model(&configA).Association("InputMapping").Append(&inSignalA).Error) + assert.NoError(t, db.Model(&configA).Association("InputMapping").Append(&inSignalB).Error) + assert.NoError(t, db.Model(&configA).Association("OutputMapping").Append(&outSignalA).Error) + assert.NoError(t, db.Model(&configA).Association("OutputMapping").Append(&outSignalB).Error) - // add simulation model has many files associations - assert.NoError(t, db.Model(&modelA).Association("Files").Append(&fileC).Error) - assert.NoError(t, db.Model(&modelA).Association("Files").Append(&fileD).Error) + // add Component Configuration has many files associations + assert.NoError(t, db.Model(&configA).Association("Files").Append(&fileC).Error) + assert.NoError(t, db.Model(&configA).Association("Files").Append(&fileD).Error) - // associate simulation models with simulators - assert.NoError(t, db.Model(&simulatorA).Association("SimulationModels").Append(&modelA).Error) - assert.NoError(t, db.Model(&simulatorA).Association("SimulationModels").Append(&modelB).Error) + // associate Component Configurations with IC + assert.NoError(t, db.Model(&icA).Association("ComponentConfigurations").Append(&configA).Error) + assert.NoError(t, db.Model(&icA).Association("ComponentConfigurations").Append(&configB).Error) - var model1 SimulationModel - assert.NoError(t, db.Find(&model1, 1).Error, fmt.Sprintf("Find SimulationModel with ID=1")) - assert.EqualValues(t, "SimulationModel_A", model1.Name) + var config1 ComponentConfiguration + assert.NoError(t, db.Find(&config1, 1).Error, fmt.Sprintf("Find ComponentConfiguration with ID=1")) + assert.EqualValues(t, ConfigA.Name, config1.Name) - // Check simulator ID - if model1.SimulatorID != 1 { - assert.Fail(t, "Simulation Model expected to have Simulator ID 1, but is %v", model1.SimulatorID) + // Check IC ID + if config1.ICID != 1 { + assert.Fail(t, "Component Configurations expected to have Infrastructure Component ID 1, but is %v", config1.ICID) } - // Get OutputMapping signals of model1 + // Get OutputMapping signals of config1 var signals []Signal - assert.NoError(t, db.Model(&model1).Where("Direction = ?", "out").Related(&signals, "OutputMapping").Error) + assert.NoError(t, db.Model(&config1).Where("Direction = ?", "out").Related(&signals, "OutputMapping").Error) if len(signals) != 2 { - assert.Fail(t, "SimulationModel Associations", + assert.Fail(t, "ComponentConfiguration Associations", "Expected to have %v Output Signals. Has %v.", 2, len(signals)) } - // Get files of model1 + // Get files of config1 var files []File - assert.NoError(t, db.Model(&model1).Related(&files, "Files").Error) + assert.NoError(t, db.Model(&config1).Related(&files, "Files").Error) if len(files) != 2 { - assert.Fail(t, "SimulationModel Associations", + assert.Fail(t, "ComponentConfiguration Associations", "Expected to have %v Files. Has %v.", 2, len(files)) } } diff --git a/database/models.go b/database/models.go index 9251669..fe2cc40 100644 --- a/database/models.go +++ b/database/models.go @@ -65,35 +65,35 @@ type Scenario struct { StartParameters postgres.Jsonb `json:"startParameters"` // Users that have access to the scenario Users []*User `json:"-" gorm:"many2many:user_scenarios;"` - // SimulationModels that belong to the scenario - SimulationModels []SimulationModel `json:"-" gorm:"foreignkey:ScenarioID" ` + // ComponentConfigurations that belong to the scenario + ComponentConfigurations []ComponentConfiguration `json:"-" gorm:"foreignkey:ScenarioID" ` // Dashboards that belong to the Scenario Dashboards []Dashboard `json:"-" gorm:"foreignkey:ScenarioID" ` } -// SimulationModel data model -type SimulationModel struct { +// ComponentConfiguration data model +type ComponentConfiguration struct { Model - // Name of simulation model + // Name of Component Configuration Name string `json:"name" gorm:"not null"` // Number of output signals OutputLength int `json:"outputLength" gorm:"default:0"` // Number of input signals InputLength int `json:"inputLength" gorm:"default:0"` - // Start parameters of simulation model as JSON + // Start parameters of Component Configuration as JSON StartParameters postgres.Jsonb `json:"startParameters"` - // ID of Scenario to which simulation model belongs + // ID of Scenario to which Component Configuration belongs ScenarioID uint `json:"scenarioID"` - // ID of simulator associated with simulation model - SimulatorID uint `json:"simulatorID"` - // Mapping of output signals of the simulation model, order of signals is important - OutputMapping []Signal `json:"-" gorm:"foreignkey:SimulationModelID"` - // Mapping of input signals of the simulation model, order of signals is important - InputMapping []Signal `json:"-" gorm:"foreignkey:SimulationModelID"` - // Files of simulation model (can be CIM and other simulation model file formats) - Files []File `json:"-" gorm:"foreignkey:SimulationModelID"` - // Currently selected simulation model FileID - SelectedModelFileID uint `json:"selectedModelFileID" gorm:"default:0"` + // ID of IC associated with Component Configuration + ICID uint `json:"icID"` + // Mapping of output signals of the ComponentConfiguration, order of signals is important + OutputMapping []Signal `json:"-" gorm:"foreignkey:ConfigID"` + // Mapping of input signals of the Component Configuration, order of signals is important + InputMapping []Signal `json:"-" gorm:"foreignkey:ConfigID"` + // Files of Component Configuration (can be CIM and other ComponentConfiguration file formats) + Files []File `json:"-" gorm:"foreignkey:ConfigID"` + // Currently selected FileID + SelectedFileID uint `json:"selectedFileID" gorm:"default:0"` } // Signal data model @@ -107,31 +107,31 @@ type Signal struct { Index uint `json:"index"` // Direction of the signal (in or out) Direction string `json:"direction"` - // ID of simulation model - SimulationModelID uint `json:"simulationModelID"` + // ID of Component Configuration + ConfigID uint `json:"configID"` } -// Simulator data model -type Simulator struct { +// InfrastructureComponent data model +type InfrastructureComponent struct { Model - // UUID of the simulator + // UUID of the IC UUID string `json:"uuid" gorm:"not null"` - // Host if the simulator + // Host if the IC Host string `json:"host" gorm:"default:''"` - // Model type supported by the simulator + // Model type supported by the IC Modeltype string `json:"modelType" gorm:"default:''"` - // Uptime of the simulator + // Uptime of the IC Uptime int `json:"uptime" gorm:"default:0"` - // State of the simulator + // State of the IC State string `json:"state" gorm:"default:''"` // Time of last state update StateUpdateAt string `json:"stateUpdateAt" gorm:"default:''"` - // Properties of simulator as JSON string + // Properties of IC as JSON string Properties postgres.Jsonb `json:"properties"` - // Raw properties of simulator as JSON string + // Raw properties of IC as JSON string RawProperties postgres.Jsonb `json:"rawProperties"` - // SimulationModels in which the simulator is used - SimulationModels []SimulationModel `json:"-" gorm:"foreignkey:SimulatorID"` + // ComponentConfigurations in which the IC is used + ComponentConfigurations []ComponentConfiguration `json:"-" gorm:"foreignkey:ICID"` } // Dashboard data model @@ -195,8 +195,8 @@ type File struct { ImageWidth uint `json:"imageWidth"` // Last modification time of file Date string `json:"date"` - // ID of model to which file belongs - SimulationModelID uint `json:"simulationModelID"` + // ID of Component Configuration to which file belongs + ConfigID uint `json:"configID"` // ID of widget to which file belongs WidgetID uint `json:"widgetID"` // File itself diff --git a/database/roles.go b/database/roles.go index 39acdca..2ac9464 100644 --- a/database/roles.go +++ b/database/roles.go @@ -38,11 +38,11 @@ type ModelName string const ModelUser = ModelName("user") const ModelUsers = ModelName("users") const ModelScenario = ModelName("scenario") -const ModelSimulator = ModelName("simulator") -const ModelSimulatorAction = ModelName("simulatoraction") +const ModelInfrastructureComponent = ModelName("ic") +const ModelInfrastructureComponentAction = ModelName("icaction") const ModelDashboard = ModelName("dashboard") const ModelWidget = ModelName("widget") -const ModelSimulationModel = ModelName("simulationmodel") +const ModelComponentConfiguration = ModelName("component-configuration") const ModelSignal = ModelName("signal") const ModelFile = ModelName("file") @@ -73,40 +73,40 @@ var none = Permission{Create: false, Read: false, Update: false, Delete: false} // allowed to do a certain action on a given model based on his role var Roles = RoleActions{ "Admin": { - ModelUser: crud, - ModelUsers: crud, - ModelScenario: crud, - ModelSimulationModel: crud, - ModelSimulator: crud, - ModelSimulatorAction: crud, - ModelWidget: crud, - ModelDashboard: crud, - ModelSignal: crud, - ModelFile: crud, + ModelUser: crud, + ModelUsers: crud, + ModelScenario: crud, + ModelComponentConfiguration: crud, + ModelInfrastructureComponent: crud, + ModelInfrastructureComponentAction: crud, + ModelWidget: crud, + ModelDashboard: crud, + ModelSignal: crud, + ModelFile: crud, }, "User": { - ModelUser: _ru_, - ModelUsers: none, - ModelScenario: crud, - ModelSimulationModel: crud, - ModelSimulator: _r__, - ModelSimulatorAction: _ru_, - ModelWidget: crud, - ModelDashboard: crud, - ModelSignal: crud, - ModelFile: crud, + ModelUser: _ru_, + ModelUsers: none, + ModelScenario: crud, + ModelComponentConfiguration: crud, + ModelInfrastructureComponent: _r__, + ModelInfrastructureComponentAction: _ru_, + ModelWidget: crud, + ModelDashboard: crud, + ModelSignal: crud, + ModelFile: crud, }, "Guest": { - ModelScenario: _r__, - ModelSimulationModel: _r__, - ModelDashboard: _r__, - ModelWidget: _r__, - ModelSimulator: _r__, - ModelSimulatorAction: _r__, - ModelUser: _ru_, - ModelUsers: none, - ModelSignal: _r__, - ModelFile: _r__, + ModelScenario: _r__, + ModelComponentConfiguration: _r__, + ModelDashboard: _r__, + ModelWidget: _r__, + ModelInfrastructureComponent: _r__, + ModelInfrastructureComponentAction: _r__, + ModelUser: _ru_, + ModelUsers: none, + ModelSignal: _r__, + ModelFile: _r__, }, } diff --git a/database/testdata.go b/database/testdata.go index dfd0a04..ca32da4 100644 --- a/database/testdata.go +++ b/database/testdata.go @@ -55,12 +55,12 @@ var UserB = User{Username: "User_B", Password: string(pwB), var UserC = User{Username: "User_C", Password: string(pwC), 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 propertiesB = json.RawMessage(`{"name" : "TestNameB", "category" : "CategoryB", "location" : "where ever you want", "type": "generic"}`) +var propertiesA = json.RawMessage(`{"name" : "DPsim simulator", "category" : "Simulator", "location" : "ACSlab", "type": "DPsim"}`) +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", Host: "Host_A", Modeltype: "ModelTypeA", @@ -71,7 +71,7 @@ var SimulatorA = Simulator{ RawProperties: postgres.Jsonb{propertiesA}, } -var SimulatorB = Simulator{ +var ICB = InfrastructureComponent{ UUID: "7be0322d-354e-431e-84bd-ae4c9633138b", Host: "Host_B", Modeltype: "ModelTypeB", @@ -98,18 +98,18 @@ var ScenarioB = Scenario{ StartParameters: postgres.Jsonb{startParametersB}, } -// Simulation Models +// Component Configuration -var SimulationModelA = SimulationModel{ - Name: "SimulationModel_A", - StartParameters: postgres.Jsonb{startParametersA}, - SelectedModelFileID: 3, +var ConfigA = ComponentConfiguration{ + Name: "Example simulation", + StartParameters: postgres.Jsonb{startParametersA}, + SelectedFileID: 3, } -var SimulationModelB = SimulationModel{ - Name: "SimulationModel_B", - StartParameters: postgres.Jsonb{startParametersB}, - SelectedModelFileID: 4, +var ConfigB = ComponentConfiguration{ + Name: "VILLASnode gateway X", + StartParameters: postgres.Jsonb{startParametersB}, + SelectedFileID: 4, } // Signals @@ -198,7 +198,7 @@ var customPropertiesLabel = json.RawMessage(`{"textSize" : "20", "fontColor" : 5 var customPropertiesButton = json.RawMessage(`{"toggle" : "Value1", "on_value" : "Value2", "off_value" : Value3}`) var customPropertiesCustomActions = json.RawMessage(`{"actions" : "Value1", "icon" : "Value2"}`) var customPropertiesGauge = json.RawMessage(`{ "valueMin": 0, "valueMax": 1}`) -var customPropertiesLamp = json.RawMessage(`{"simulationModel" : "null", "signal" : 0, "on_color" : 4, "off_color": 2 , "threshold" : 0.5}`) +var customPropertiesLamp = json.RawMessage(`{"signal" : 0, "on_color" : 4, "off_color": 2 , "threshold" : 0.5}`) var WidgetA = Widget{ Name: "Label", @@ -316,8 +316,8 @@ func DBAddTestData(db *gorm.DB) error { userB := UserB userC := UserC - simulatorA := SimulatorA - simulatorB := SimulatorB + ICA := ICA + ICB := ICB scenarioA := ScenarioA scenarioB := ScenarioB @@ -327,8 +327,8 @@ func DBAddTestData(db *gorm.DB) error { inSignalA := InSignalA inSignalB := InSignalB - modelA := SimulationModelA - modelB := SimulationModelB + configA := ConfigA + configB := ConfigB dashboardA := DashboardA dashboardB := DashboardB @@ -354,9 +354,9 @@ func DBAddTestData(db *gorm.DB) error { // add Guest user to DB err = db.Create(&userC).Error - // Simulators - err = db.Create(&simulatorA).Error - err = db.Create(&simulatorB).Error + // ICs + err = db.Create(&ICA).Error + err = db.Create(&ICB).Error // Scenarios err = db.Create(&scenarioA).Error @@ -368,9 +368,9 @@ func DBAddTestData(db *gorm.DB) error { err = db.Create(&outSignalA).Error err = db.Create(&outSignalB).Error - // Simulation Models - err = db.Create(&modelA).Error - err = db.Create(&modelB).Error + // Component Configuration + err = db.Create(&configA).Error + err = db.Create(&configB).Error // Dashboards err = db.Create(&dashboardA).Error @@ -400,9 +400,9 @@ func DBAddTestData(db *gorm.DB) error { err = db.Model(&scenarioA).Association("Users").Append(&userC).Error err = db.Model(&scenarioA).Association("Users").Append(&user0).Error - // Scenario HM SimulationModels - err = db.Model(&scenarioA).Association("SimulationModels").Append(&modelA).Error - err = db.Model(&scenarioA).Association("SimulationModels").Append(&modelB).Error + // Scenario HM Component Configurations + err = db.Model(&scenarioA).Association("ComponentConfigurations").Append(&configA).Error + err = db.Model(&scenarioA).Association("ComponentConfigurations").Append(&configB).Error // Scenario HM Dashboards err = db.Model(&scenarioA).Association("Dashboards").Append(&dashboardA).Error @@ -415,19 +415,19 @@ func DBAddTestData(db *gorm.DB) error { err = db.Model(&dashboardA).Association("Widgets").Append(&widgetD).Error err = db.Model(&dashboardA).Association("Widgets").Append(&widgetE).Error - // SimulationModel HM Signals - err = db.Model(&modelA).Association("InputMapping").Append(&inSignalA).Error - err = db.Model(&modelA).Association("InputMapping").Append(&inSignalB).Error - err = db.Model(&modelA).Association("InputMapping").Append(&outSignalA).Error - err = db.Model(&modelA).Association("InputMapping").Append(&outSignalB).Error + // ComponentConfiguration HM Signals + err = db.Model(&configA).Association("InputMapping").Append(&inSignalA).Error + err = db.Model(&configA).Association("InputMapping").Append(&inSignalB).Error + err = db.Model(&configA).Association("InputMapping").Append(&outSignalA).Error + err = db.Model(&configA).Association("InputMapping").Append(&outSignalB).Error - // SimulationModel HM Files - err = db.Model(&modelA).Association("Files").Append(&fileC).Error - err = db.Model(&modelA).Association("Files").Append(&fileD).Error + // ComponentConfiguration HM Files + err = db.Model(&configA).Association("Files").Append(&fileC).Error + err = db.Model(&configA).Association("Files").Append(&fileD).Error - // Simulator HM SimulationModels - err = db.Model(&simulatorA).Association("SimulationModels").Append(&modelA).Error - err = db.Model(&simulatorA).Association("SimulationModels").Append(&modelB).Error + // InfrastructureComponent HM ComponentConfigurations + err = db.Model(&ICA).Association("ComponentConfigurations").Append(&configA).Error + err = db.Model(&ICA).Association("ComponentConfigurations").Append(&configB).Error // Widget HM Files err = db.Model(&widgetA).Association("Files").Append(&fileA).Error diff --git a/doc/api/docs.go b/doc/api/docs.go index c6f1850..11b7513 100644 --- a/doc/api/docs.go +++ b/doc/api/docs.go @@ -1,6 +1,6 @@ // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // This file was generated by swaggo/swag at -// 2019-11-26 14:19:55.359561459 +0100 CET m=+0.107753669 +// 2020-03-06 15:07:22.664243647 +0100 CET m=+0.093312600 package docs @@ -81,6 +81,337 @@ var doc = `{ } } }, + "/configs": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "component-configurations" + ], + "summary": "Get all component configurations of scenario", + "operationId": "getConfigs", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Scenario ID", + "name": "scenarioID", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Component configurations which belong to scenario", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfigs" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "component-configurations" + ], + "summary": "Add a component configuration to a scenario", + "operationId": "addConfig", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "component configuration to be added incl. IDs of scenario and IC", + "name": "inputConfig", + "in": "body", + "required": true, + "schema": { + "type": "object", + "$ref": "#/definitions/component_configuration.addConfigRequest" + } + } + ], + "responses": { + "200": { + "description": "Component configuration that was added", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfig" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + } + }, + "/configs/{configID}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "component-configurations" + ], + "summary": "Get a component configuration", + "operationId": "getConfig", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Config ID", + "name": "configID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "component configuration that was requested", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfig" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "component-configurations" + ], + "summary": "Update a component configuration", + "operationId": "updateConfig", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "component configuration to be updated", + "name": "inputConfig", + "in": "body", + "required": true, + "schema": { + "type": "object", + "$ref": "#/definitions/component_configuration.updateConfigRequest" + } + }, + { + "type": "integer", + "description": "Config ID", + "name": "configID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Component configuration that was added", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfig" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + }, + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "component-configurations" + ], + "summary": "Delete a component configuration", + "operationId": "deleteConfig", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Config ID", + "name": "configID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "component configuration that was deleted", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfig" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + } + }, "/dashboards": { "get": { "produces": [ @@ -420,7 +751,7 @@ var doc = `{ "tags": [ "files" ], - "summary": "Get all files of a specific model or widget", + "summary": "Get all files of a specific component configuration or widget", "operationId": "getFiles", "parameters": [ { @@ -432,14 +763,14 @@ var doc = `{ }, { "type": "string", - "description": "Set to model for files of model, set to widget for files of widget", + "description": "Set to config for files of component configuration, set to widget for files of widget", "name": "objectType", "in": "query", "required": true }, { "type": "integer", - "description": "ID of either model or widget of which files are requested", + "description": "ID of either config or widget of which files are requested", "name": "objectID", "in": "query", "required": true @@ -447,7 +778,7 @@ var doc = `{ ], "responses": { "200": { - "description": "Files which belong to simulation model or widget", + "description": "Files which belong to config or widget", "schema": { "type": "object", "$ref": "#/definitions/docs.ResponseFiles" @@ -491,7 +822,7 @@ var doc = `{ "tags": [ "files" ], - "summary": "Add a file to a specific model or widget", + "summary": "Add a file to a specific component config or widget", "operationId": "addFile", "parameters": [ { @@ -510,14 +841,14 @@ var doc = `{ }, { "type": "string", - "description": "Set to model for files of model, set to widget for files of widget", + "description": "Set to config for files of component config, set to widget for files of widget", "name": "objectType", "in": "query", "required": true }, { "type": "integer", - "description": "ID of either model or widget of which files are requested", + "description": "ID of either config or widget of which files are requested", "name": "objectID", "in": "query", "required": true @@ -797,33 +1128,16 @@ var doc = `{ } } }, - "/metrics": { + "/ic": { "get": { "produces": [ "application/json" ], "tags": [ - "metrics" + "infrastructure-components" ], - "summary": "Prometheus metrics endpoint", - "operationId": "getMetrics", - "responses": { - "200": { - "description": "Returns Prometheus metrics" - } - } - } - }, - "/models": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "simulationModels" - ], - "summary": "Get all simulation models of scenario", - "operationId": "getSimulationModels", + "summary": "Get all infrastructure components", + "operationId": "getICs", "parameters": [ { "type": "string", @@ -831,21 +1145,14 @@ var doc = `{ "name": "Authorization", "in": "header", "required": true - }, - { - "type": "integer", - "description": "Scenario ID", - "name": "scenarioID", - "in": "query", - "required": true } ], "responses": { "200": { - "description": "Simulation models which belong to scenario", + "description": "ICs requested", "schema": { "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModels" + "$ref": "#/definitions/docs.ResponseICs" } }, "404": { @@ -879,10 +1186,10 @@ var doc = `{ "application/json" ], "tags": [ - "simulationModels" + "infrastructure-components" ], - "summary": "Add a simulation model to a scenario", - "operationId": "addSimulationModel", + "summary": "Add an infrastructure component", + "operationId": "addIC", "parameters": [ { "type": "string", @@ -892,22 +1199,22 @@ var doc = `{ "required": true }, { - "description": "Simulation model to be added incl. IDs of scenario and simulator", - "name": "inputSimulationModel", + "description": "Infrastructure Component to be added", + "name": "inputIC", "in": "body", "required": true, "schema": { "type": "object", - "$ref": "#/definitions/simulationmodel.addSimulationModelRequest" + "$ref": "#/definitions/infrastructure_component.addICRequest" } } ], "responses": { "200": { - "description": "simulation model that was added", + "description": "Infrastructure Component that was added", "schema": { "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModel" + "$ref": "#/definitions/docs.ResponseIC" } }, "400": { @@ -941,16 +1248,16 @@ var doc = `{ } } }, - "/models/{modelID}": { + "/ic/{ICID}": { "get": { "produces": [ "application/json" ], "tags": [ - "simulationModels" + "infrastructure-components" ], - "summary": "Get a simulation model", - "operationId": "getSimulationModel", + "summary": "Get infrastructure component", + "operationId": "getIC", "parameters": [ { "type": "string", @@ -961,18 +1268,18 @@ var doc = `{ }, { "type": "integer", - "description": "Model ID", - "name": "modelID", + "description": "Infrastructure Component ID", + "name": "ICID", "in": "path", "required": true } ], "responses": { "200": { - "description": "simulation model that was requested", + "description": "Infrastructure Component that was requested", "schema": { "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModel" + "$ref": "#/definitions/docs.ResponseIC" } }, "400": { @@ -1013,10 +1320,10 @@ var doc = `{ "application/json" ], "tags": [ - "simulationModels" + "infrastructure-components" ], - "summary": "Update a simulation model", - "operationId": "updateSimulationModel", + "summary": "Update an infrastructure component", + "operationId": "updateIC", "parameters": [ { "type": "string", @@ -1026,29 +1333,29 @@ var doc = `{ "required": true }, { - "description": "Simulation model to be updated", - "name": "inputSimulationModel", + "description": "InfrastructureComponent to be updated", + "name": "inputIC", "in": "body", "required": true, "schema": { "type": "object", - "$ref": "#/definitions/simulationmodel.updateSimulationModelRequest" + "$ref": "#/definitions/infrastructure_component.updateICRequest" } }, { "type": "integer", - "description": "Model ID", - "name": "modelID", + "description": "InfrastructureComponent ID", + "name": "ICID", "in": "path", "required": true } ], "responses": { "200": { - "description": "simulation model that was added", + "description": "Infrastructure Component that was updated", "schema": { "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModel" + "$ref": "#/definitions/docs.ResponseIC" } }, "400": { @@ -1086,10 +1393,10 @@ var doc = `{ "application/json" ], "tags": [ - "simulationModels" + "infrastructure-components" ], - "summary": "Delete a simulation model", - "operationId": "deleteSimulationModel", + "summary": "Delete an infrastructure component", + "operationId": "deleteIC", "parameters": [ { "type": "string", @@ -1100,18 +1407,18 @@ var doc = `{ }, { "type": "integer", - "description": "Model ID", - "name": "modelID", + "description": "Infrastructure Component ID", + "name": "ICID", "in": "path", "required": true } ], "responses": { "200": { - "description": "simulation model that was deleted", + "description": "Infrastructure Component that was deleted", "schema": { "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModel" + "$ref": "#/definitions/docs.ResponseIC" } }, "400": { @@ -1145,6 +1452,153 @@ var doc = `{ } } }, + "/ic/{ICID}/action": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "AMQP" + ], + "summary": "Send an action to IC (only available if backend server is started with -amqp parameter)", + "operationId": "sendActionToIC", + "parameters": [ + { + "type": "string", + "description": "Action for IC", + "name": "inputAction", + "in": "query", + "required": true + }, + { + "type": "integer", + "description": "InfrastructureComponent ID", + "name": "ICID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Action sent successfully", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + } + }, + "/ic/{ICID}/configs": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "infrastructure-components" + ], + "summary": "Get all configurations of the infrastructure component", + "operationId": "getConfigsOfIC", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Infrastructure Component ID", + "name": "ICID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Configs requested by user", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfigs" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + } + }, + "/metrics": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "metrics" + ], + "summary": "Prometheus metrics endpoint", + "operationId": "getMetrics", + "responses": { + "200": { + "description": "Returns Prometheus metrics" + } + } + } + }, "/scenarios": { "get": { "produces": [ @@ -1661,8 +2115,8 @@ var doc = `{ }, { "type": "string", - "description": "Model ID of signals to be obtained", - "name": "modelID", + "description": "Config ID of signals to be obtained", + "name": "configID", "in": "query", "required": true }, @@ -1676,7 +2130,7 @@ var doc = `{ ], "responses": { "200": { - "description": "Signals which belong to simulation model", + "description": "Signals which belong to component configuration", "schema": { "type": "object", "$ref": "#/definitions/docs.ResponseSignals" @@ -1715,7 +2169,7 @@ var doc = `{ "tags": [ "signals" ], - "summary": "Add a signal to a signal mapping of a model", + "summary": "Add a signal to a signal mapping of a component configuration", "operationId": "AddSignal", "parameters": [ { @@ -1726,7 +2180,7 @@ var doc = `{ "required": true }, { - "description": "A signal to be added to the model incl. direction and model ID to which signal shall be added", + "description": "A signal to be added to the component configuration incl. direction and config ID to which signal shall be added", "name": "inputSignal", "in": "body", "required": true, @@ -1976,460 +2430,6 @@ var doc = `{ } } }, - "/simulators": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Get all simulators", - "operationId": "getSimulators", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - } - ], - "responses": { - "200": { - "description": "Simulators requested", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulators" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - }, - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Add a simulator", - "operationId": "addSimulator", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "description": "Simulator to be added", - "name": "inputSimulator", - "in": "body", - "required": true, - "schema": { - "type": "object", - "$ref": "#/definitions/simulator.addSimulatorRequest" - } - } - ], - "responses": { - "200": { - "description": "Simulator that was added", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulator" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - } - }, - "/simulators/{simulatorID}": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Get simulator", - "operationId": "getSimulator", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "Simulator ID", - "name": "simulatorID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Simulator that was requested", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulator" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - }, - "put": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Update a simulator", - "operationId": "updateSimulator", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "description": "Simulator to be updated", - "name": "inputSimulator", - "in": "body", - "required": true, - "schema": { - "type": "object", - "$ref": "#/definitions/simulator.updateSimulatorRequest" - } - }, - { - "type": "integer", - "description": "Simulator ID", - "name": "simulatorID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Simulator that was updated", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulator" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - }, - "delete": { - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Delete a simulator", - "operationId": "deleteSimulator", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "Simulator ID", - "name": "simulatorID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Simulator that was deleted", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulator" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - } - }, - "/simulators/{simulatorID}/action": { - "post": { - "produces": [ - "application/json" - ], - "tags": [ - "AMQP" - ], - "summary": "Send an action to simulator (only available if backend server is started with -amqp parameter)", - "operationId": "sendActionToSimulator", - "parameters": [ - { - "type": "string", - "description": "Action for simulator", - "name": "inputAction", - "in": "query", - "required": true - }, - { - "type": "integer", - "description": "Simulator ID", - "name": "simulatorID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Action sent successfully", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - } - }, - "/simulators/{simulatorID}/models": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Get all simulation models in which the simulator is used", - "operationId": "getModelsOfSimulator", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "Simulator ID", - "name": "simulatorID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Simulation models requested by user", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModels" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - } - }, "/users": { "get": { "produces": [ @@ -3080,6 +3080,67 @@ var doc = `{ } }, "definitions": { + "component_configuration.addConfigRequest": { + "type": "object", + "properties": { + "config": { + "type": "object", + "$ref": "#/definitions/component_configuration.validNewConfig" + } + } + }, + "component_configuration.updateConfigRequest": { + "type": "object", + "properties": { + "config": { + "type": "object", + "$ref": "#/definitions/component_configuration.validUpdatedConfig" + } + } + }, + "component_configuration.validNewConfig": { + "type": "object", + "required": [ + "ICID", + "Name", + "ScenarioID", + "StartParameters" + ], + "properties": { + "ICID": { + "type": "integer" + }, + "Name": { + "type": "string" + }, + "ScenarioID": { + "type": "integer" + }, + "SelectedFileID": { + "type": "integer" + }, + "StartParameters": { + "type": "string" + } + } + }, + "component_configuration.validUpdatedConfig": { + "type": "object", + "properties": { + "ICID": { + "type": "integer" + }, + "Name": { + "type": "string" + }, + "SelectedFileID": { + "type": "integer" + }, + "StartParameters": { + "type": "string" + } + } + }, "dashboard.addDashboardRequest": { "type": "object", "properties": { @@ -3128,6 +3189,42 @@ var doc = `{ } } }, + "database.ComponentConfiguration": { + "type": "object", + "properties": { + "icID": { + "description": "ID of IC associated with Component Configuration", + "type": "integer" + }, + "id": { + "type": "integer" + }, + "inputLength": { + "description": "Number of input signals", + "type": "integer" + }, + "name": { + "description": "Name of Component Configuration", + "type": "string" + }, + "outputLength": { + "description": "Number of output signals", + "type": "integer" + }, + "scenarioID": { + "description": "ID of Scenario to which Component Configuration belongs", + "type": "integer" + }, + "selectedFileID": { + "description": "Currently selected FileID", + "type": "integer" + }, + "startParameters": { + "description": "Start parameters of Component Configuration as JSON", + "type": "string" + } + } + }, "database.Dashboard": { "type": "object", "properties": { @@ -3151,6 +3248,10 @@ var doc = `{ "database.File": { "type": "object", "properties": { + "configID": { + "description": "ID of Component Configuration to which file belongs", + "type": "integer" + }, "date": { "description": "Last modification time of file", "type": "string" @@ -3170,10 +3271,6 @@ var doc = `{ "description": "Name of file", "type": "string" }, - "simulationModelID": { - "description": "ID of model to which file belongs", - "type": "integer" - }, "size": { "description": "Size of file (in byte)", "type": "integer" @@ -3188,6 +3285,46 @@ var doc = `{ } } }, + "database.InfrastructureComponent": { + "type": "object", + "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" + } + } + }, "database.Scenario": { "type": "object", "properties": { @@ -3211,6 +3348,10 @@ var doc = `{ "database.Signal": { "type": "object", "properties": { + "configID": { + "description": "ID of Component Configuration", + "type": "integer" + }, "direction": { "description": "Direction of the signal (in or out)", "type": "string" @@ -3226,88 +3367,12 @@ var doc = `{ "description": "Name of Signal", "type": "string" }, - "simulationModelID": { - "description": "ID of simulation model", - "type": "integer" - }, "unit": { "description": "Unit of Signal", "type": "string" } } }, - "database.SimulationModel": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "inputLength": { - "description": "Number of input signals", - "type": "integer" - }, - "name": { - "description": "Name of simulation model", - "type": "string" - }, - "outputLength": { - "description": "Number of output signals", - "type": "integer" - }, - "scenarioID": { - "description": "ID of Scenario to which simulation model belongs", - "type": "integer" - }, - "simulatorID": { - "description": "ID of simulator associated with simulation model", - "type": "integer" - }, - "startParameters": { - "description": "Start parameters of simulation model as JSON", - "type": "string" - } - } - }, - "database.Simulator": { - "type": "object", - "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" - } - } - }, "database.User": { "type": "object", "properties": { @@ -3366,6 +3431,10 @@ var doc = `{ "description": "Name of widget", "type": "string" }, + "signalIDs": { + "description": "IDs of signals that widget uses", + "type": "string" + }, "type": { "description": "Type of widget", "type": "string" @@ -3406,6 +3475,26 @@ var doc = `{ } } }, + "docs.ResponseConfig": { + "type": "object", + "properties": { + "config": { + "type": "object", + "$ref": "#/definitions/database.ComponentConfiguration" + } + } + }, + "docs.ResponseConfigs": { + "type": "object", + "properties": { + "configs": { + "type": "array", + "items": { + "$ref": "#/definitions/database.ComponentConfiguration" + } + } + } + }, "docs.ResponseDashboard": { "type": "object", "properties": { @@ -3457,6 +3546,26 @@ var doc = `{ } } }, + "docs.ResponseIC": { + "type": "object", + "properties": { + "ic": { + "type": "object", + "$ref": "#/definitions/database.InfrastructureComponent" + } + } + }, + "docs.ResponseICs": { + "type": "object", + "properties": { + "ics": { + "type": "array", + "items": { + "$ref": "#/definitions/database.InfrastructureComponent" + } + } + } + }, "docs.ResponseScenario": { "type": "object", "properties": { @@ -3497,46 +3606,6 @@ var doc = `{ } } }, - "docs.ResponseSimulationModel": { - "type": "object", - "properties": { - "simulationModel": { - "type": "object", - "$ref": "#/definitions/database.SimulationModel" - } - } - }, - "docs.ResponseSimulationModels": { - "type": "object", - "properties": { - "simulationModels": { - "type": "array", - "items": { - "$ref": "#/definitions/database.SimulationModel" - } - } - } - }, - "docs.ResponseSimulator": { - "type": "object", - "properties": { - "simulator": { - "type": "object", - "$ref": "#/definitions/database.Simulator" - } - } - }, - "docs.ResponseSimulators": { - "type": "object", - "properties": { - "simulators": { - "type": "array", - "items": { - "$ref": "#/definitions/database.Simulator" - } - } - } - }, "docs.ResponseUser": { "type": "object", "properties": { @@ -3577,6 +3646,70 @@ var doc = `{ } } }, + "infrastructure_component.addICRequest": { + "type": "object", + "properties": { + "ic": { + "type": "object", + "$ref": "#/definitions/infrastructure_component.validNewIC" + } + } + }, + "infrastructure_component.updateICRequest": { + "type": "object", + "properties": { + "ic": { + "type": "object", + "$ref": "#/definitions/infrastructure_component.validUpdatedIC" + } + } + }, + "infrastructure_component.validNewIC": { + "type": "object", + "required": [ + "Host", + "Modeltype", + "Properties", + "UUID" + ], + "properties": { + "Host": { + "type": "string" + }, + "Modeltype": { + "type": "string" + }, + "Properties": { + "type": "string" + }, + "State": { + "type": "string" + }, + "UUID": { + "type": "string" + } + } + }, + "infrastructure_component.validUpdatedIC": { + "type": "object", + "properties": { + "Host": { + "type": "string" + }, + "Modeltype": { + "type": "string" + }, + "Properties": { + "type": "string" + }, + "State": { + "type": "string" + }, + "UUID": { + "type": "string" + } + } + }, "scenario.addScenarioRequest": { "type": "object", "properties": { @@ -3648,12 +3781,15 @@ var doc = `{ "signal.validNewSignal": { "type": "object", "required": [ + "ConfigID", "Direction", "Index", - "Name", - "SimulationModelID" + "Name" ], "properties": { + "ConfigID": { + "type": "integer" + }, "Direction": { "type": "string" }, @@ -3663,9 +3799,6 @@ var doc = `{ "Name": { "type": "string" }, - "SimulationModelID": { - "type": "integer" - }, "Unit": { "type": "string" } @@ -3685,125 +3818,6 @@ var doc = `{ } } }, - "simulationmodel.addSimulationModelRequest": { - "type": "object", - "properties": { - "simulationModel": { - "type": "object", - "$ref": "#/definitions/simulationmodel.validNewSimulationModel" - } - } - }, - "simulationmodel.updateSimulationModelRequest": { - "type": "object", - "properties": { - "simulationModel": { - "type": "object", - "$ref": "#/definitions/simulationmodel.validUpdatedSimulationModel" - } - } - }, - "simulationmodel.validNewSimulationModel": { - "type": "object", - "required": [ - "Name", - "ScenarioID", - "SimulatorID", - "StartParameters" - ], - "properties": { - "Name": { - "type": "string" - }, - "ScenarioID": { - "type": "integer" - }, - "SimulatorID": { - "type": "integer" - }, - "StartParameters": { - "type": "string" - } - } - }, - "simulationmodel.validUpdatedSimulationModel": { - "type": "object", - "properties": { - "Name": { - "type": "string" - }, - "SimulatorID": { - "type": "integer" - }, - "StartParameters": { - "type": "string" - } - } - }, - "simulator.addSimulatorRequest": { - "type": "object", - "properties": { - "simulator": { - "type": "object", - "$ref": "#/definitions/simulator.validNewSimulator" - } - } - }, - "simulator.updateSimulatorRequest": { - "type": "object", - "properties": { - "simulator": { - "type": "object", - "$ref": "#/definitions/simulator.validUpdatedSimulator" - } - } - }, - "simulator.validNewSimulator": { - "type": "object", - "required": [ - "Host", - "Modeltype", - "Properties", - "UUID" - ], - "properties": { - "Host": { - "type": "string" - }, - "Modeltype": { - "type": "string" - }, - "Properties": { - "type": "string" - }, - "State": { - "type": "string" - }, - "UUID": { - "type": "string" - } - } - }, - "simulator.validUpdatedSimulator": { - "type": "object", - "properties": { - "Host": { - "type": "string" - }, - "Modeltype": { - "type": "string" - }, - "Properties": { - "type": "string" - }, - "State": { - "type": "string" - }, - "UUID": { - "type": "string" - } - } - }, "user.addUserRequest": { "type": "object", "properties": { @@ -3932,6 +3946,12 @@ var doc = `{ "Name": { "type": "string" }, + "SignalIDs": { + "type": "array", + "items": { + "type": "integer" + } + }, "Type": { "type": "string" }, @@ -3970,6 +3990,12 @@ var doc = `{ "Name": { "type": "string" }, + "SignalIDs": { + "type": "array", + "items": { + "type": "integer" + } + }, "Type": { "type": "string" }, diff --git a/doc/api/responses.go b/doc/api/responses.go index cdcad5d..e72b25e 100644 --- a/doc/api/responses.go +++ b/doc/api/responses.go @@ -46,12 +46,12 @@ type ResponseUser struct { user database.User } -type ResponseSimulators struct { - simulators []database.Simulator +type ResponseICs struct { + ics []database.InfrastructureComponent } -type ResponseSimulator struct { - simulator database.Simulator +type ResponseIC struct { + ic database.InfrastructureComponent } type ResponseScenarios struct { @@ -62,12 +62,12 @@ type ResponseScenario struct { scenario database.Scenario } -type ResponseSimulationModels struct { - simulationModels []database.SimulationModel +type ResponseConfigs struct { + configs []database.ComponentConfiguration } -type ResponseSimulationModel struct { - simulationModel database.SimulationModel +type ResponseConfig struct { + config database.ComponentConfiguration } type ResponseDashboards struct { diff --git a/doc/api/swagger.json b/doc/api/swagger.json index 978d342..f9772a2 100644 --- a/doc/api/swagger.json +++ b/doc/api/swagger.json @@ -66,6 +66,337 @@ } } }, + "/configs": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "component-configurations" + ], + "summary": "Get all component configurations of scenario", + "operationId": "getConfigs", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Scenario ID", + "name": "scenarioID", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "Component configurations which belong to scenario", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfigs" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + }, + "post": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "component-configurations" + ], + "summary": "Add a component configuration to a scenario", + "operationId": "addConfig", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "component configuration to be added incl. IDs of scenario and IC", + "name": "inputConfig", + "in": "body", + "required": true, + "schema": { + "type": "object", + "$ref": "#/definitions/component_configuration.addConfigRequest" + } + } + ], + "responses": { + "200": { + "description": "Component configuration that was added", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfig" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + } + }, + "/configs/{configID}": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "component-configurations" + ], + "summary": "Get a component configuration", + "operationId": "getConfig", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Config ID", + "name": "configID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "component configuration that was requested", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfig" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + }, + "put": { + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "component-configurations" + ], + "summary": "Update a component configuration", + "operationId": "updateConfig", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "description": "component configuration to be updated", + "name": "inputConfig", + "in": "body", + "required": true, + "schema": { + "type": "object", + "$ref": "#/definitions/component_configuration.updateConfigRequest" + } + }, + { + "type": "integer", + "description": "Config ID", + "name": "configID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Component configuration that was added", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfig" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + }, + "delete": { + "produces": [ + "application/json" + ], + "tags": [ + "component-configurations" + ], + "summary": "Delete a component configuration", + "operationId": "deleteConfig", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Config ID", + "name": "configID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "component configuration that was deleted", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfig" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + } + }, "/dashboards": { "get": { "produces": [ @@ -405,7 +736,7 @@ "tags": [ "files" ], - "summary": "Get all files of a specific model or widget", + "summary": "Get all files of a specific component configuration or widget", "operationId": "getFiles", "parameters": [ { @@ -417,14 +748,14 @@ }, { "type": "string", - "description": "Set to model for files of model, set to widget for files of widget", + "description": "Set to config for files of component configuration, set to widget for files of widget", "name": "objectType", "in": "query", "required": true }, { "type": "integer", - "description": "ID of either model or widget of which files are requested", + "description": "ID of either config or widget of which files are requested", "name": "objectID", "in": "query", "required": true @@ -432,7 +763,7 @@ ], "responses": { "200": { - "description": "Files which belong to simulation model or widget", + "description": "Files which belong to config or widget", "schema": { "type": "object", "$ref": "#/definitions/docs.ResponseFiles" @@ -476,7 +807,7 @@ "tags": [ "files" ], - "summary": "Add a file to a specific model or widget", + "summary": "Add a file to a specific component config or widget", "operationId": "addFile", "parameters": [ { @@ -495,14 +826,14 @@ }, { "type": "string", - "description": "Set to model for files of model, set to widget for files of widget", + "description": "Set to config for files of component config, set to widget for files of widget", "name": "objectType", "in": "query", "required": true }, { "type": "integer", - "description": "ID of either model or widget of which files are requested", + "description": "ID of either config or widget of which files are requested", "name": "objectID", "in": "query", "required": true @@ -782,33 +1113,16 @@ } } }, - "/metrics": { + "/ic": { "get": { "produces": [ "application/json" ], "tags": [ - "metrics" + "infrastructure-components" ], - "summary": "Prometheus metrics endpoint", - "operationId": "getMetrics", - "responses": { - "200": { - "description": "Returns Prometheus metrics" - } - } - } - }, - "/models": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "simulationModels" - ], - "summary": "Get all simulation models of scenario", - "operationId": "getSimulationModels", + "summary": "Get all infrastructure components", + "operationId": "getICs", "parameters": [ { "type": "string", @@ -816,21 +1130,14 @@ "name": "Authorization", "in": "header", "required": true - }, - { - "type": "integer", - "description": "Scenario ID", - "name": "scenarioID", - "in": "query", - "required": true } ], "responses": { "200": { - "description": "Simulation models which belong to scenario", + "description": "ICs requested", "schema": { "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModels" + "$ref": "#/definitions/docs.ResponseICs" } }, "404": { @@ -864,10 +1171,10 @@ "application/json" ], "tags": [ - "simulationModels" + "infrastructure-components" ], - "summary": "Add a simulation model to a scenario", - "operationId": "addSimulationModel", + "summary": "Add an infrastructure component", + "operationId": "addIC", "parameters": [ { "type": "string", @@ -877,22 +1184,22 @@ "required": true }, { - "description": "Simulation model to be added incl. IDs of scenario and simulator", - "name": "inputSimulationModel", + "description": "Infrastructure Component to be added", + "name": "inputIC", "in": "body", "required": true, "schema": { "type": "object", - "$ref": "#/definitions/simulationmodel.addSimulationModelRequest" + "$ref": "#/definitions/infrastructure_component.addICRequest" } } ], "responses": { "200": { - "description": "simulation model that was added", + "description": "Infrastructure Component that was added", "schema": { "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModel" + "$ref": "#/definitions/docs.ResponseIC" } }, "400": { @@ -926,16 +1233,16 @@ } } }, - "/models/{modelID}": { + "/ic/{ICID}": { "get": { "produces": [ "application/json" ], "tags": [ - "simulationModels" + "infrastructure-components" ], - "summary": "Get a simulation model", - "operationId": "getSimulationModel", + "summary": "Get infrastructure component", + "operationId": "getIC", "parameters": [ { "type": "string", @@ -946,18 +1253,18 @@ }, { "type": "integer", - "description": "Model ID", - "name": "modelID", + "description": "Infrastructure Component ID", + "name": "ICID", "in": "path", "required": true } ], "responses": { "200": { - "description": "simulation model that was requested", + "description": "Infrastructure Component that was requested", "schema": { "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModel" + "$ref": "#/definitions/docs.ResponseIC" } }, "400": { @@ -998,10 +1305,10 @@ "application/json" ], "tags": [ - "simulationModels" + "infrastructure-components" ], - "summary": "Update a simulation model", - "operationId": "updateSimulationModel", + "summary": "Update an infrastructure component", + "operationId": "updateIC", "parameters": [ { "type": "string", @@ -1011,29 +1318,29 @@ "required": true }, { - "description": "Simulation model to be updated", - "name": "inputSimulationModel", + "description": "InfrastructureComponent to be updated", + "name": "inputIC", "in": "body", "required": true, "schema": { "type": "object", - "$ref": "#/definitions/simulationmodel.updateSimulationModelRequest" + "$ref": "#/definitions/infrastructure_component.updateICRequest" } }, { "type": "integer", - "description": "Model ID", - "name": "modelID", + "description": "InfrastructureComponent ID", + "name": "ICID", "in": "path", "required": true } ], "responses": { "200": { - "description": "simulation model that was added", + "description": "Infrastructure Component that was updated", "schema": { "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModel" + "$ref": "#/definitions/docs.ResponseIC" } }, "400": { @@ -1071,10 +1378,10 @@ "application/json" ], "tags": [ - "simulationModels" + "infrastructure-components" ], - "summary": "Delete a simulation model", - "operationId": "deleteSimulationModel", + "summary": "Delete an infrastructure component", + "operationId": "deleteIC", "parameters": [ { "type": "string", @@ -1085,18 +1392,18 @@ }, { "type": "integer", - "description": "Model ID", - "name": "modelID", + "description": "Infrastructure Component ID", + "name": "ICID", "in": "path", "required": true } ], "responses": { "200": { - "description": "simulation model that was deleted", + "description": "Infrastructure Component that was deleted", "schema": { "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModel" + "$ref": "#/definitions/docs.ResponseIC" } }, "400": { @@ -1130,6 +1437,153 @@ } } }, + "/ic/{ICID}/action": { + "post": { + "produces": [ + "application/json" + ], + "tags": [ + "AMQP" + ], + "summary": "Send an action to IC (only available if backend server is started with -amqp parameter)", + "operationId": "sendActionToIC", + "parameters": [ + { + "type": "string", + "description": "Action for IC", + "name": "inputAction", + "in": "query", + "required": true + }, + { + "type": "integer", + "description": "InfrastructureComponent ID", + "name": "ICID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Action sent successfully", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + } + }, + "/ic/{ICID}/configs": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "infrastructure-components" + ], + "summary": "Get all configurations of the infrastructure component", + "operationId": "getConfigsOfIC", + "parameters": [ + { + "type": "string", + "description": "Authorization token", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "integer", + "description": "Infrastructure Component ID", + "name": "ICID", + "in": "path", + "required": true + } + ], + "responses": { + "200": { + "description": "Configs requested by user", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseConfigs" + } + }, + "400": { + "description": "Bad request", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "404": { + "description": "Not found", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "422": { + "description": "Unprocessable entity", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + }, + "500": { + "description": "Internal server error", + "schema": { + "type": "object", + "$ref": "#/definitions/docs.ResponseError" + } + } + } + } + }, + "/metrics": { + "get": { + "produces": [ + "application/json" + ], + "tags": [ + "metrics" + ], + "summary": "Prometheus metrics endpoint", + "operationId": "getMetrics", + "responses": { + "200": { + "description": "Returns Prometheus metrics" + } + } + } + }, "/scenarios": { "get": { "produces": [ @@ -1646,8 +2100,8 @@ }, { "type": "string", - "description": "Model ID of signals to be obtained", - "name": "modelID", + "description": "Config ID of signals to be obtained", + "name": "configID", "in": "query", "required": true }, @@ -1661,7 +2115,7 @@ ], "responses": { "200": { - "description": "Signals which belong to simulation model", + "description": "Signals which belong to component configuration", "schema": { "type": "object", "$ref": "#/definitions/docs.ResponseSignals" @@ -1700,7 +2154,7 @@ "tags": [ "signals" ], - "summary": "Add a signal to a signal mapping of a model", + "summary": "Add a signal to a signal mapping of a component configuration", "operationId": "AddSignal", "parameters": [ { @@ -1711,7 +2165,7 @@ "required": true }, { - "description": "A signal to be added to the model incl. direction and model ID to which signal shall be added", + "description": "A signal to be added to the component configuration incl. direction and config ID to which signal shall be added", "name": "inputSignal", "in": "body", "required": true, @@ -1961,460 +2415,6 @@ } } }, - "/simulators": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Get all simulators", - "operationId": "getSimulators", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - } - ], - "responses": { - "200": { - "description": "Simulators requested", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulators" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - }, - "post": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Add a simulator", - "operationId": "addSimulator", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "description": "Simulator to be added", - "name": "inputSimulator", - "in": "body", - "required": true, - "schema": { - "type": "object", - "$ref": "#/definitions/simulator.addSimulatorRequest" - } - } - ], - "responses": { - "200": { - "description": "Simulator that was added", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulator" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - } - }, - "/simulators/{simulatorID}": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Get simulator", - "operationId": "getSimulator", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "Simulator ID", - "name": "simulatorID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Simulator that was requested", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulator" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - }, - "put": { - "consumes": [ - "application/json" - ], - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Update a simulator", - "operationId": "updateSimulator", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "description": "Simulator to be updated", - "name": "inputSimulator", - "in": "body", - "required": true, - "schema": { - "type": "object", - "$ref": "#/definitions/simulator.updateSimulatorRequest" - } - }, - { - "type": "integer", - "description": "Simulator ID", - "name": "simulatorID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Simulator that was updated", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulator" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - }, - "delete": { - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Delete a simulator", - "operationId": "deleteSimulator", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "Simulator ID", - "name": "simulatorID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Simulator that was deleted", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulator" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - } - }, - "/simulators/{simulatorID}/action": { - "post": { - "produces": [ - "application/json" - ], - "tags": [ - "AMQP" - ], - "summary": "Send an action to simulator (only available if backend server is started with -amqp parameter)", - "operationId": "sendActionToSimulator", - "parameters": [ - { - "type": "string", - "description": "Action for simulator", - "name": "inputAction", - "in": "query", - "required": true - }, - { - "type": "integer", - "description": "Simulator ID", - "name": "simulatorID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Action sent successfully", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - } - }, - "/simulators/{simulatorID}/models": { - "get": { - "produces": [ - "application/json" - ], - "tags": [ - "simulators" - ], - "summary": "Get all simulation models in which the simulator is used", - "operationId": "getModelsOfSimulator", - "parameters": [ - { - "type": "string", - "description": "Authorization token", - "name": "Authorization", - "in": "header", - "required": true - }, - { - "type": "integer", - "description": "Simulator ID", - "name": "simulatorID", - "in": "path", - "required": true - } - ], - "responses": { - "200": { - "description": "Simulation models requested by user", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseSimulationModels" - } - }, - "400": { - "description": "Bad request", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "404": { - "description": "Not found", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "422": { - "description": "Unprocessable entity", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "$ref": "#/definitions/docs.ResponseError" - } - } - } - } - }, "/users": { "get": { "produces": [ @@ -3065,6 +3065,67 @@ } }, "definitions": { + "component_configuration.addConfigRequest": { + "type": "object", + "properties": { + "config": { + "type": "object", + "$ref": "#/definitions/component_configuration.validNewConfig" + } + } + }, + "component_configuration.updateConfigRequest": { + "type": "object", + "properties": { + "config": { + "type": "object", + "$ref": "#/definitions/component_configuration.validUpdatedConfig" + } + } + }, + "component_configuration.validNewConfig": { + "type": "object", + "required": [ + "ICID", + "Name", + "ScenarioID", + "StartParameters" + ], + "properties": { + "ICID": { + "type": "integer" + }, + "Name": { + "type": "string" + }, + "ScenarioID": { + "type": "integer" + }, + "SelectedFileID": { + "type": "integer" + }, + "StartParameters": { + "type": "string" + } + } + }, + "component_configuration.validUpdatedConfig": { + "type": "object", + "properties": { + "ICID": { + "type": "integer" + }, + "Name": { + "type": "string" + }, + "SelectedFileID": { + "type": "integer" + }, + "StartParameters": { + "type": "string" + } + } + }, "dashboard.addDashboardRequest": { "type": "object", "properties": { @@ -3113,6 +3174,42 @@ } } }, + "database.ComponentConfiguration": { + "type": "object", + "properties": { + "icID": { + "description": "ID of IC associated with Component Configuration", + "type": "integer" + }, + "id": { + "type": "integer" + }, + "inputLength": { + "description": "Number of input signals", + "type": "integer" + }, + "name": { + "description": "Name of Component Configuration", + "type": "string" + }, + "outputLength": { + "description": "Number of output signals", + "type": "integer" + }, + "scenarioID": { + "description": "ID of Scenario to which Component Configuration belongs", + "type": "integer" + }, + "selectedFileID": { + "description": "Currently selected FileID", + "type": "integer" + }, + "startParameters": { + "description": "Start parameters of Component Configuration as JSON", + "type": "string" + } + } + }, "database.Dashboard": { "type": "object", "properties": { @@ -3136,6 +3233,10 @@ "database.File": { "type": "object", "properties": { + "configID": { + "description": "ID of Component Configuration to which file belongs", + "type": "integer" + }, "date": { "description": "Last modification time of file", "type": "string" @@ -3155,10 +3256,6 @@ "description": "Name of file", "type": "string" }, - "simulationModelID": { - "description": "ID of model to which file belongs", - "type": "integer" - }, "size": { "description": "Size of file (in byte)", "type": "integer" @@ -3173,6 +3270,46 @@ } } }, + "database.InfrastructureComponent": { + "type": "object", + "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" + } + } + }, "database.Scenario": { "type": "object", "properties": { @@ -3196,6 +3333,10 @@ "database.Signal": { "type": "object", "properties": { + "configID": { + "description": "ID of Component Configuration", + "type": "integer" + }, "direction": { "description": "Direction of the signal (in or out)", "type": "string" @@ -3211,88 +3352,12 @@ "description": "Name of Signal", "type": "string" }, - "simulationModelID": { - "description": "ID of simulation model", - "type": "integer" - }, "unit": { "description": "Unit of Signal", "type": "string" } } }, - "database.SimulationModel": { - "type": "object", - "properties": { - "id": { - "type": "integer" - }, - "inputLength": { - "description": "Number of input signals", - "type": "integer" - }, - "name": { - "description": "Name of simulation model", - "type": "string" - }, - "outputLength": { - "description": "Number of output signals", - "type": "integer" - }, - "scenarioID": { - "description": "ID of Scenario to which simulation model belongs", - "type": "integer" - }, - "simulatorID": { - "description": "ID of simulator associated with simulation model", - "type": "integer" - }, - "startParameters": { - "description": "Start parameters of simulation model as JSON", - "type": "string" - } - } - }, - "database.Simulator": { - "type": "object", - "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" - } - } - }, "database.User": { "type": "object", "properties": { @@ -3351,6 +3416,10 @@ "description": "Name of widget", "type": "string" }, + "signalIDs": { + "description": "IDs of signals that widget uses", + "type": "string" + }, "type": { "description": "Type of widget", "type": "string" @@ -3391,6 +3460,26 @@ } } }, + "docs.ResponseConfig": { + "type": "object", + "properties": { + "config": { + "type": "object", + "$ref": "#/definitions/database.ComponentConfiguration" + } + } + }, + "docs.ResponseConfigs": { + "type": "object", + "properties": { + "configs": { + "type": "array", + "items": { + "$ref": "#/definitions/database.ComponentConfiguration" + } + } + } + }, "docs.ResponseDashboard": { "type": "object", "properties": { @@ -3442,6 +3531,26 @@ } } }, + "docs.ResponseIC": { + "type": "object", + "properties": { + "ic": { + "type": "object", + "$ref": "#/definitions/database.InfrastructureComponent" + } + } + }, + "docs.ResponseICs": { + "type": "object", + "properties": { + "ics": { + "type": "array", + "items": { + "$ref": "#/definitions/database.InfrastructureComponent" + } + } + } + }, "docs.ResponseScenario": { "type": "object", "properties": { @@ -3482,46 +3591,6 @@ } } }, - "docs.ResponseSimulationModel": { - "type": "object", - "properties": { - "simulationModel": { - "type": "object", - "$ref": "#/definitions/database.SimulationModel" - } - } - }, - "docs.ResponseSimulationModels": { - "type": "object", - "properties": { - "simulationModels": { - "type": "array", - "items": { - "$ref": "#/definitions/database.SimulationModel" - } - } - } - }, - "docs.ResponseSimulator": { - "type": "object", - "properties": { - "simulator": { - "type": "object", - "$ref": "#/definitions/database.Simulator" - } - } - }, - "docs.ResponseSimulators": { - "type": "object", - "properties": { - "simulators": { - "type": "array", - "items": { - "$ref": "#/definitions/database.Simulator" - } - } - } - }, "docs.ResponseUser": { "type": "object", "properties": { @@ -3562,6 +3631,70 @@ } } }, + "infrastructure_component.addICRequest": { + "type": "object", + "properties": { + "ic": { + "type": "object", + "$ref": "#/definitions/infrastructure_component.validNewIC" + } + } + }, + "infrastructure_component.updateICRequest": { + "type": "object", + "properties": { + "ic": { + "type": "object", + "$ref": "#/definitions/infrastructure_component.validUpdatedIC" + } + } + }, + "infrastructure_component.validNewIC": { + "type": "object", + "required": [ + "Host", + "Modeltype", + "Properties", + "UUID" + ], + "properties": { + "Host": { + "type": "string" + }, + "Modeltype": { + "type": "string" + }, + "Properties": { + "type": "string" + }, + "State": { + "type": "string" + }, + "UUID": { + "type": "string" + } + } + }, + "infrastructure_component.validUpdatedIC": { + "type": "object", + "properties": { + "Host": { + "type": "string" + }, + "Modeltype": { + "type": "string" + }, + "Properties": { + "type": "string" + }, + "State": { + "type": "string" + }, + "UUID": { + "type": "string" + } + } + }, "scenario.addScenarioRequest": { "type": "object", "properties": { @@ -3633,12 +3766,15 @@ "signal.validNewSignal": { "type": "object", "required": [ + "ConfigID", "Direction", "Index", - "Name", - "SimulationModelID" + "Name" ], "properties": { + "ConfigID": { + "type": "integer" + }, "Direction": { "type": "string" }, @@ -3648,9 +3784,6 @@ "Name": { "type": "string" }, - "SimulationModelID": { - "type": "integer" - }, "Unit": { "type": "string" } @@ -3670,125 +3803,6 @@ } } }, - "simulationmodel.addSimulationModelRequest": { - "type": "object", - "properties": { - "simulationModel": { - "type": "object", - "$ref": "#/definitions/simulationmodel.validNewSimulationModel" - } - } - }, - "simulationmodel.updateSimulationModelRequest": { - "type": "object", - "properties": { - "simulationModel": { - "type": "object", - "$ref": "#/definitions/simulationmodel.validUpdatedSimulationModel" - } - } - }, - "simulationmodel.validNewSimulationModel": { - "type": "object", - "required": [ - "Name", - "ScenarioID", - "SimulatorID", - "StartParameters" - ], - "properties": { - "Name": { - "type": "string" - }, - "ScenarioID": { - "type": "integer" - }, - "SimulatorID": { - "type": "integer" - }, - "StartParameters": { - "type": "string" - } - } - }, - "simulationmodel.validUpdatedSimulationModel": { - "type": "object", - "properties": { - "Name": { - "type": "string" - }, - "SimulatorID": { - "type": "integer" - }, - "StartParameters": { - "type": "string" - } - } - }, - "simulator.addSimulatorRequest": { - "type": "object", - "properties": { - "simulator": { - "type": "object", - "$ref": "#/definitions/simulator.validNewSimulator" - } - } - }, - "simulator.updateSimulatorRequest": { - "type": "object", - "properties": { - "simulator": { - "type": "object", - "$ref": "#/definitions/simulator.validUpdatedSimulator" - } - } - }, - "simulator.validNewSimulator": { - "type": "object", - "required": [ - "Host", - "Modeltype", - "Properties", - "UUID" - ], - "properties": { - "Host": { - "type": "string" - }, - "Modeltype": { - "type": "string" - }, - "Properties": { - "type": "string" - }, - "State": { - "type": "string" - }, - "UUID": { - "type": "string" - } - } - }, - "simulator.validUpdatedSimulator": { - "type": "object", - "properties": { - "Host": { - "type": "string" - }, - "Modeltype": { - "type": "string" - }, - "Properties": { - "type": "string" - }, - "State": { - "type": "string" - }, - "UUID": { - "type": "string" - } - } - }, "user.addUserRequest": { "type": "object", "properties": { @@ -3917,6 +3931,12 @@ "Name": { "type": "string" }, + "SignalIDs": { + "type": "array", + "items": { + "type": "integer" + } + }, "Type": { "type": "string" }, @@ -3955,6 +3975,12 @@ "Name": { "type": "string" }, + "SignalIDs": { + "type": "array", + "items": { + "type": "integer" + } + }, "Type": { "type": "string" }, diff --git a/doc/api/swagger.yaml b/doc/api/swagger.yaml index 46d289d..9865bed 100644 --- a/doc/api/swagger.yaml +++ b/doc/api/swagger.yaml @@ -1,5 +1,46 @@ basePath: /api/v2 definitions: + component_configuration.addConfigRequest: + properties: + config: + $ref: '#/definitions/component_configuration.validNewConfig' + type: object + type: object + component_configuration.updateConfigRequest: + properties: + config: + $ref: '#/definitions/component_configuration.validUpdatedConfig' + type: object + type: object + component_configuration.validNewConfig: + properties: + ICID: + type: integer + Name: + type: string + ScenarioID: + type: integer + SelectedFileID: + type: integer + StartParameters: + type: string + required: + - ICID + - Name + - ScenarioID + - StartParameters + type: object + component_configuration.validUpdatedConfig: + properties: + ICID: + type: integer + Name: + type: string + SelectedFileID: + type: integer + StartParameters: + type: string + type: object dashboard.addDashboardRequest: properties: dashboard: @@ -32,6 +73,32 @@ definitions: name: type: string type: object + database.ComponentConfiguration: + properties: + icID: + description: ID of IC associated with Component Configuration + type: integer + id: + type: integer + inputLength: + description: Number of input signals + type: integer + name: + description: Name of Component Configuration + type: string + outputLength: + description: Number of output signals + type: integer + scenarioID: + description: ID of Scenario to which Component Configuration belongs + type: integer + selectedFileID: + description: Currently selected FileID + type: integer + startParameters: + description: Start parameters of Component Configuration as JSON + type: string + type: object database.Dashboard: properties: grid: @@ -48,6 +115,9 @@ definitions: type: object database.File: properties: + configID: + description: ID of Component Configuration to which file belongs + type: integer date: description: Last modification time of file type: string @@ -62,9 +132,6 @@ definitions: name: description: Name of file type: string - simulationModelID: - description: ID of model to which file belongs - type: integer size: description: Size of file (in byte) type: integer @@ -75,6 +142,35 @@ definitions: description: ID of widget to which file belongs type: integer 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: properties: id: @@ -91,6 +187,9 @@ definitions: type: object database.Signal: properties: + configID: + description: ID of Component Configuration + type: integer direction: description: Direction of the signal (in or out) type: string @@ -102,65 +201,10 @@ definitions: name: description: Name of Signal type: string - simulationModelID: - description: ID of simulation model - type: integer unit: description: Unit of Signal type: string type: object - database.SimulationModel: - properties: - id: - type: integer - inputLength: - description: Number of input signals - type: integer - name: - description: Name of simulation model - type: string - outputLength: - description: Number of output signals - type: integer - scenarioID: - description: ID of Scenario to which simulation model belongs - type: integer - simulatorID: - description: ID of simulator associated with simulation model - type: integer - startParameters: - description: Start parameters of simulation model as JSON - type: string - 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: properties: active: @@ -204,6 +248,9 @@ definitions: name: description: Name of widget type: string + signalIDs: + description: IDs of signals that widget uses + type: string type: description: Type of widget type: string @@ -232,6 +279,19 @@ definitions: $ref: '#/definitions/database.User' type: object type: object + docs.ResponseConfig: + properties: + config: + $ref: '#/definitions/database.ComponentConfiguration' + type: object + type: object + docs.ResponseConfigs: + properties: + configs: + items: + $ref: '#/definitions/database.ComponentConfiguration' + type: array + type: object docs.ResponseDashboard: properties: dashboard: @@ -265,6 +325,19 @@ definitions: $ref: '#/definitions/database.File' type: array 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: properties: scenario: @@ -291,32 +364,6 @@ definitions: $ref: '#/definitions/database.Signal' type: array type: object - docs.ResponseSimulationModel: - properties: - simulationModel: - $ref: '#/definitions/database.SimulationModel' - type: object - type: object - docs.ResponseSimulationModels: - properties: - simulationModels: - items: - $ref: '#/definitions/database.SimulationModel' - type: array - 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: properties: user: @@ -343,6 +390,49 @@ definitions: $ref: '#/definitions/database.Widget' type: array 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: properties: scenario: @@ -390,21 +480,21 @@ definitions: type: object signal.validNewSignal: properties: + ConfigID: + type: integer Direction: type: string Index: type: integer Name: type: string - SimulationModelID: - type: integer Unit: type: string required: + - ConfigID - Direction - Index - Name - - SimulationModelID type: object signal.validUpdatedSignal: properties: @@ -415,86 +505,6 @@ definitions: Unit: type: string type: object - simulationmodel.addSimulationModelRequest: - properties: - simulationModel: - $ref: '#/definitions/simulationmodel.validNewSimulationModel' - type: object - type: object - simulationmodel.updateSimulationModelRequest: - properties: - simulationModel: - $ref: '#/definitions/simulationmodel.validUpdatedSimulationModel' - type: object - type: object - simulationmodel.validNewSimulationModel: - properties: - Name: - type: string - ScenarioID: - type: integer - SimulatorID: - type: integer - StartParameters: - type: string - required: - - Name - - ScenarioID - - SimulatorID - - StartParameters - type: object - simulationmodel.validUpdatedSimulationModel: - properties: - Name: - type: string - SimulatorID: - type: integer - StartParameters: - type: string - 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: properties: user: @@ -576,6 +586,10 @@ definitions: type: integer Name: type: string + SignalIDs: + items: + type: integer + type: array Type: type: string Width: @@ -607,6 +621,10 @@ definitions: type: integer Name: type: string + SignalIDs: + items: + type: integer + type: array Type: type: string Width: @@ -668,6 +686,237 @@ paths: summary: Authentication for user tags: - authentication + /configs: + get: + operationId: getConfigs + parameters: + - description: Authorization token + in: header + name: Authorization + required: true + type: string + - description: Scenario ID + in: query + name: scenarioID + required: true + type: integer + produces: + - application/json + responses: + "200": + description: Component configurations which belong to scenario + schema: + $ref: '#/definitions/docs.ResponseConfigs' + 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 component configurations of scenario + tags: + - component-configurations + post: + consumes: + - application/json + operationId: addConfig + parameters: + - description: Authorization token + in: header + name: Authorization + required: true + type: string + - description: component configuration to be added incl. IDs of scenario and + IC + in: body + name: inputConfig + required: true + schema: + $ref: '#/definitions/component_configuration.addConfigRequest' + type: object + produces: + - application/json + responses: + "200": + description: Component configuration that was added + schema: + $ref: '#/definitions/docs.ResponseConfig' + 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 component configuration to a scenario + tags: + - component-configurations + /configs/{configID}: + delete: + operationId: deleteConfig + parameters: + - description: Authorization token + in: header + name: Authorization + required: true + type: string + - description: Config ID + in: path + name: configID + required: true + type: integer + produces: + - application/json + responses: + "200": + description: component configuration that was deleted + schema: + $ref: '#/definitions/docs.ResponseConfig' + 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 component configuration + tags: + - component-configurations + get: + operationId: getConfig + parameters: + - description: Authorization token + in: header + name: Authorization + required: true + type: string + - description: Config ID + in: path + name: configID + required: true + type: integer + produces: + - application/json + responses: + "200": + description: component configuration that was requested + schema: + $ref: '#/definitions/docs.ResponseConfig' + 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 a component configuration + tags: + - component-configurations + put: + consumes: + - application/json + operationId: updateConfig + parameters: + - description: Authorization token + in: header + name: Authorization + required: true + type: string + - description: component configuration to be updated + in: body + name: inputConfig + required: true + schema: + $ref: '#/definitions/component_configuration.updateConfigRequest' + type: object + - description: Config ID + in: path + name: configID + required: true + type: integer + produces: + - application/json + responses: + "200": + description: Component configuration that was added + schema: + $ref: '#/definitions/docs.ResponseConfig' + 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 component configuration + tags: + - component-configurations /dashboards: get: operationId: getDashboards @@ -907,12 +1156,13 @@ paths: name: Authorization required: true type: string - - description: Set to model for files of model, set to widget for files of widget + - description: Set to config for files of component configuration, set to widget + for files of widget in: query name: objectType required: true type: string - - description: ID of either model or widget of which files are requested + - description: ID of either config or widget of which files are requested in: query name: objectID required: true @@ -921,7 +1171,7 @@ paths: - application/json responses: "200": - description: Files which belong to simulation model or widget + description: Files which belong to config or widget schema: $ref: '#/definitions/docs.ResponseFiles' type: object @@ -940,7 +1190,7 @@ paths: schema: $ref: '#/definitions/docs.ResponseError' type: object - summary: Get all files of a specific model or widget + summary: Get all files of a specific component configuration or widget tags: - files post: @@ -963,12 +1213,13 @@ paths: name: inputFile required: true type: file - - description: Set to model for files of model, set to widget for files of widget + - description: Set to config for files of component config, set to widget for + files of widget in: query name: objectType required: true type: string - - description: ID of either model or widget of which files are requested + - description: ID of either config or widget of which files are requested in: query name: objectID required: true @@ -1001,7 +1252,7 @@ paths: schema: $ref: '#/definitions/docs.ResponseError' type: object - summary: Add a file to a specific model or widget + summary: Add a file to a specific component config or widget tags: - files /files/{fileID}: @@ -1171,6 +1422,322 @@ paths: summary: Get health status of backend tags: - 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}/configs: + 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.ResponseConfigs' + 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: get: operationId: getMetrics @@ -1182,236 +1749,6 @@ paths: summary: Prometheus metrics endpoint tags: - metrics - /models: - get: - operationId: getSimulationModels - parameters: - - description: Authorization token - in: header - name: Authorization - required: true - type: string - - description: Scenario ID - in: query - name: scenarioID - required: true - type: integer - produces: - - application/json - responses: - "200": - description: Simulation models which belong to scenario - schema: - $ref: '#/definitions/docs.ResponseSimulationModels' - 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 of scenario - tags: - - simulationModels - post: - consumes: - - application/json - operationId: addSimulationModel - parameters: - - description: Authorization token - in: header - name: Authorization - required: true - type: string - - description: Simulation model to be added incl. IDs of scenario and simulator - in: body - name: inputSimulationModel - required: true - schema: - $ref: '#/definitions/simulationmodel.addSimulationModelRequest' - type: object - produces: - - application/json - responses: - "200": - description: simulation model that was added - schema: - $ref: '#/definitions/docs.ResponseSimulationModel' - 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 simulation model to a scenario - tags: - - simulationModels - /models/{modelID}: - delete: - operationId: deleteSimulationModel - parameters: - - description: Authorization token - in: header - name: Authorization - required: true - type: string - - description: Model ID - in: path - name: modelID - required: true - type: integer - produces: - - application/json - responses: - "200": - description: simulation model that was deleted - schema: - $ref: '#/definitions/docs.ResponseSimulationModel' - 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 simulation model - tags: - - simulationModels - get: - operationId: getSimulationModel - parameters: - - description: Authorization token - in: header - name: Authorization - required: true - type: string - - description: Model ID - in: path - name: modelID - required: true - type: integer - produces: - - application/json - responses: - "200": - description: simulation model that was requested - schema: - $ref: '#/definitions/docs.ResponseSimulationModel' - 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 a simulation model - tags: - - simulationModels - put: - consumes: - - application/json - operationId: updateSimulationModel - parameters: - - description: Authorization token - in: header - name: Authorization - required: true - type: string - - description: Simulation model to be updated - in: body - name: inputSimulationModel - required: true - schema: - $ref: '#/definitions/simulationmodel.updateSimulationModelRequest' - type: object - - description: Model ID - in: path - name: modelID - required: true - type: integer - produces: - - application/json - responses: - "200": - description: simulation model that was added - schema: - $ref: '#/definitions/docs.ResponseSimulationModel' - 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 simulation model - tags: - - simulationModels /scenarios: get: operationId: getScenarios @@ -1765,9 +2102,9 @@ paths: name: direction required: true type: string - - description: Model ID of signals to be obtained + - description: Config ID of signals to be obtained in: query - name: modelID + name: configID required: true type: string - description: Authorization token @@ -1779,7 +2116,7 @@ paths: - application/json responses: "200": - description: Signals which belong to simulation model + description: Signals which belong to component configuration schema: $ref: '#/definitions/docs.ResponseSignals' type: object @@ -1811,8 +2148,8 @@ paths: name: Authorization required: true type: string - - description: A signal to be added to the model incl. direction and model ID - to which signal shall be added + - description: A signal to be added to the component configuration incl. direction + and config ID to which signal shall be added in: body name: inputSignal required: true @@ -1847,7 +2184,7 @@ paths: schema: $ref: '#/definitions/docs.ResponseError' type: object - summary: Add a signal to a signal mapping of a model + summary: Add a signal to a signal mapping of a component configuration tags: - signals /signals/{signalID}: @@ -1990,322 +2327,6 @@ paths: summary: Update a signal tags: - 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: get: operationId: GetUsers diff --git a/routes/simulationmodel/simulationmodel_endpoints.go b/routes/component-configuration/config_endpoints.go similarity index 54% rename from routes/simulationmodel/simulationmodel_endpoints.go rename to routes/component-configuration/config_endpoints.go index e11d3f8..23309b4 100644 --- a/routes/simulationmodel/simulationmodel_endpoints.go +++ b/routes/component-configuration/config_endpoints.go @@ -1,4 +1,4 @@ -/** Simulationmodel package, endpoints. +/** component_configuration package, endpoints. * * @author Sonja Happ * @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 * along with this program. If not, see . *********************************************************************************/ -package simulationmodel +package component_configuration import ( "git.rwth-aachen.de/acs/public/villas/web-backend-go/helper" @@ -31,27 +31,27 @@ import ( "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario" ) -func RegisterSimulationModelEndpoints(r *gin.RouterGroup) { - r.GET("", getSimulationModels) - r.POST("", addSimulationModel) - r.PUT("/:modelID", updateSimulationModel) - r.GET("/:modelID", getSimulationModel) - r.DELETE("/:modelID", deleteSimulationModel) +func RegisterComponentConfigurationEndpoints(r *gin.RouterGroup) { + r.GET("", getConfigs) + r.POST("", addConfig) + r.PUT("/:configID", updateConfig) + r.GET("/:configID", getConfig) + r.DELETE("/:configID", deleteConfig) } -// getSimulationModels godoc -// @Summary Get all simulation models of scenario -// @ID getSimulationModels +// getConfigs godoc +// @Summary Get all component configurations of scenario +// @ID getConfigs // @Produce json -// @Tags simulationModels -// @Success 200 {object} docs.ResponseSimulationModels "Simulation models which belong to scenario" +// @Tags component-configurations +// @Success 200 {object} docs.ResponseConfigs "Component configurations which belong to scenario" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" // @Param scenarioID query int true "Scenario ID" -// @Router /models [get] -func getSimulationModels(c *gin.Context) { +// @Router /configs [get] +func getConfigs(c *gin.Context) { ok, so := scenario.CheckPermissions(c, database.Read, "query", -1) if !ok { @@ -59,32 +59,32 @@ func getSimulationModels(c *gin.Context) { } db := database.GetDB() - var models []database.SimulationModel - err := db.Order("ID asc").Model(so).Related(&models, "Models").Error + var configs []database.ComponentConfiguration + err := db.Order("ID asc").Model(so).Related(&configs, "ComponentConfigurations").Error if !helper.DBError(c, err) { - c.JSON(http.StatusOK, gin.H{"simulationModels": models}) + c.JSON(http.StatusOK, gin.H{"configs": configs}) } } -// addSimulationModel godoc -// @Summary Add a simulation model to a scenario -// @ID addSimulationModel +// addConfig godoc +// @Summary Add a component configuration to a scenario +// @ID addConfig // @Accept json // @Produce json -// @Tags simulationModels -// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was added" +// @Tags component-configurations +// @Success 200 {object} docs.ResponseConfig "Component configuration that was added" // @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param inputSimulationModel body simulationmodel.addSimulationModelRequest true "Simulation model to be added incl. IDs of scenario and simulator" -// @Router /models [post] -func addSimulationModel(c *gin.Context) { +// @Param inputConfig body component_configuration.addConfigRequest true "component configuration to be added incl. IDs of scenario and IC" +// @Router /configs [post] +func addConfig(c *gin.Context) { // Bind the request to JSON - var req addSimulationModelRequest + var req addConfigRequest err := c.ShouldBindJSON(&req) if err != nil { helper.BadRequestError(c, "Bad request. Error binding form data to JSON: "+err.Error()) @@ -97,46 +97,46 @@ func addSimulationModel(c *gin.Context) { return } - // Create the new simulation model from the request - newSimulationModel := req.createSimulationModel() + // Create the new Component Configuration from the request + newConfig := req.createConfig() // check access to the scenario - ok, _ := scenario.CheckPermissions(c, database.Update, "body", int(newSimulationModel.ScenarioID)) + ok, _ := scenario.CheckPermissions(c, database.Update, "body", int(newConfig.ScenarioID)) if !ok { return } - // add the new simulation model to the scenario - err = newSimulationModel.addToScenario() + // add the new Component Configuration to the scenario + err = newConfig.addToScenario() if !helper.DBError(c, err) { - c.JSON(http.StatusOK, gin.H{"simulationModel": newSimulationModel.SimulationModel}) + c.JSON(http.StatusOK, gin.H{"config": newConfig.ComponentConfiguration}) } } -// updateSimulationModel godoc -// @Summary Update a simulation model -// @ID updateSimulationModel -// @Tags simulationModels +// updateConfig godoc +// @Summary Update a component configuration +// @ID updateConfig +// @Tags component-configurations // @Accept json // @Produce json -// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was added" +// @Success 200 {object} docs.ResponseConfig "Component configuration that was added" // @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param inputSimulationModel body simulationmodel.updateSimulationModelRequest true "Simulation model to be updated" -// @Param modelID path int true "Model ID" -// @Router /models/{modelID} [put] -func updateSimulationModel(c *gin.Context) { +// @Param inputConfig body component_configuration.updateConfigRequest true "component configuration to be updated" +// @Param configID path int true "Config ID" +// @Router /configs/{configID} [put] +func updateConfig(c *gin.Context) { - ok, oldSimulationModel := CheckPermissions(c, database.Update, "path", -1) + ok, oldConfig := CheckPermissions(c, database.Update, "path", -1) if !ok { return } - var req updateSimulationModelRequest + var req updateConfigRequest err := c.BindJSON(&req) if err != nil { helper.BadRequestError(c, "Error binding form data to JSON: "+err.Error()) @@ -144,59 +144,59 @@ func updateSimulationModel(c *gin.Context) { } // Validate the request - if err := req.SimulationModel.validate(); err != nil { + if err := req.Config.validate(); err != nil { helper.BadRequestError(c, err.Error()) return } - // Create the updatedSimulationModel from oldSimulationModel - updatedSimulationModel := req.updatedSimulationModel(oldSimulationModel) + // Create the updateConfig from oldConfig + updatedConfig := req.updateConfig(oldConfig) - // Finally, update the simulation model - err = oldSimulationModel.Update(updatedSimulationModel) + // Finally, update the Component Configuration + err = oldConfig.Update(updatedConfig) if !helper.DBError(c, err) { - c.JSON(http.StatusOK, gin.H{"simulationModel": updatedSimulationModel.SimulationModel}) + c.JSON(http.StatusOK, gin.H{"config": updatedConfig.ComponentConfiguration}) } } -// getSimulationModel godoc -// @Summary Get a simulation model -// @ID getSimulationModel -// @Tags simulationModels +// getConfig godoc +// @Summary Get a component configuration +// @ID getConfig +// @Tags component-configurations // @Produce json -// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was requested" +// @Success 200 {object} docs.ResponseConfig "component configuration that was requested" // @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param modelID path int true "Model ID" -// @Router /models/{modelID} [get] -func getSimulationModel(c *gin.Context) { +// @Param configID path int true "Config ID" +// @Router /configs/{configID} [get] +func getConfig(c *gin.Context) { ok, m := CheckPermissions(c, database.Read, "path", -1) if !ok { return } - c.JSON(http.StatusOK, gin.H{"simulationModel": m.SimulationModel}) + c.JSON(http.StatusOK, gin.H{"config": m.ComponentConfiguration}) } -// deleteSimulationModel godoc -// @Summary Delete a simulation model -// @ID deleteSimulationModel -// @Tags simulationModels +// deleteConfig godoc +// @Summary Delete a component configuration +// @ID deleteConfig +// @Tags component-configurations // @Produce json -// @Success 200 {object} docs.ResponseSimulationModel "simulation model that was deleted" +// @Success 200 {object} docs.ResponseConfig "component configuration that was deleted" // @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param modelID path int true "Model ID" -// @Router /models/{modelID} [delete] -func deleteSimulationModel(c *gin.Context) { +// @Param configID path int true "Config ID" +// @Router /configs/{configID} [delete] +func deleteConfig(c *gin.Context) { ok, m := CheckPermissions(c, database.Delete, "path", -1) if !ok { @@ -205,6 +205,6 @@ func deleteSimulationModel(c *gin.Context) { err := m.delete() if !helper.DBError(c, err) { - c.JSON(http.StatusOK, gin.H{"simulationModel": m.SimulationModel}) + c.JSON(http.StatusOK, gin.H{"config": m.ComponentConfiguration}) } } diff --git a/routes/simulationmodel/simulationmodel_methods.go b/routes/component-configuration/config_methods.go similarity index 50% rename from routes/simulationmodel/simulationmodel_methods.go rename to routes/component-configuration/config_methods.go index 6b23021..7be2d32 100644 --- a/routes/simulationmodel/simulationmodel_methods.go +++ b/routes/component-configuration/config_methods.go @@ -1,4 +1,4 @@ -/** Simulationmodel package, methods. +/** component_configuration package, methods. * * @author Sonja Happ * @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC @@ -19,25 +19,25 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . *********************************************************************************/ -package simulationmodel +package component_configuration import ( "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/simulator" ) -type SimulationModel struct { - database.SimulationModel +type ComponentConfiguration struct { + database.ComponentConfiguration } -func (m *SimulationModel) save() error { +func (m *ComponentConfiguration) save() error { db := database.GetDB() err := db.Create(m).Error return err } -func (m *SimulationModel) ByID(id uint) error { +func (m *ComponentConfiguration) ByID(id uint) error { db := database.GetDB() err := db.Find(m, id).Error if err != nil { @@ -46,7 +46,7 @@ func (m *SimulationModel) ByID(id uint) error { return nil } -func (m *SimulationModel) addToScenario() error { +func (m *ComponentConfiguration) addToScenario() error { db := database.GetDB() var so scenario.Scenario err := so.ByID(m.ScenarioID) @@ -54,65 +54,65 @@ func (m *SimulationModel) addToScenario() error { return err } - // save simulation model to DB + // save component configuration to DB err = m.save() if err != nil { return err } - // associate simulator with simulation model - var simltr simulator.Simulator - err = simltr.ByID(m.SimulatorID) - err = db.Model(&simltr).Association("SimulationModels").Append(m).Error + // associate IC with component configuration + var ic infrastructure_component.InfrastructureComponent + err = ic.ByID(m.ICID) + err = db.Model(&ic).Association("ComponentConfigurations").Append(m).Error if err != nil { return err } - // associate simulation model with scenario - err = db.Model(&so).Association("SimulationModels").Append(m).Error + // associate component configuration with scenario + err = db.Model(&so).Association("ComponentConfigurations").Append(m).Error return err } -func (m *SimulationModel) Update(modifiedSimulationModel SimulationModel) error { +func (m *ComponentConfiguration) Update(modifiedConfig ComponentConfiguration) error { db := database.GetDB() - // check if simulator has been updated - if m.SimulatorID != modifiedSimulationModel.SimulatorID { - // update simulator - var s simulator.Simulator - var s_old simulator.Simulator - err := s.ByID(modifiedSimulationModel.SimulatorID) + // check if IC has been updated + if m.ICID != modifiedConfig.ICID { + // update IC + var s infrastructure_component.InfrastructureComponent + var s_old infrastructure_component.InfrastructureComponent + err := s.ByID(modifiedConfig.ICID) if err != nil { return err } - err = s_old.ByID(m.SimulatorID) + err = s_old.ByID(m.ICID) if err != nil { return err } - // remove simulation model from old simulator - err = db.Model(&s_old).Association("SimulationModels").Delete(m).Error + // remove component configuration from old IC + err = db.Model(&s_old).Association("ComponentConfigurations").Delete(m).Error if err != nil { return err } - // add simulation model to new simulator - err = db.Model(&s).Association("SimulationModels").Append(m).Error + // add component configuration to new IC + err = db.Model(&s).Association("ComponentConfigurations").Append(m).Error if err != nil { return err } } err := db.Model(m).Updates(map[string]interface{}{ - "Name": modifiedSimulationModel.Name, - "StartParameters": modifiedSimulationModel.StartParameters, - "SimulatorID": modifiedSimulationModel.SimulatorID, - "SelectedModelFileID": modifiedSimulationModel.SelectedModelFileID, + "Name": modifiedConfig.Name, + "StartParameters": modifiedConfig.StartParameters, + "ICID": modifiedConfig.ICID, + "SelectedFileID": modifiedConfig.SelectedFileID, }).Error return err } -func (m *SimulationModel) delete() error { +func (m *ComponentConfiguration) delete() error { db := database.GetDB() var so scenario.Scenario @@ -121,9 +121,9 @@ func (m *SimulationModel) delete() error { return err } - // remove association between SimulationModel and Scenario - // SimulationModel itself is not deleted from DB, it remains as "dangling" - err = db.Model(&so).Association("SimulationModels").Delete(m).Error + // remove association between ComponentConfiguration and Scenario + // ComponentConfiguration itself is not deleted from DB, it remains as "dangling" + err = db.Model(&so).Association("ComponentConfigurations").Delete(m).Error return err } diff --git a/routes/simulationmodel/simulationmodel_middleware.go b/routes/component-configuration/config_middleware.go similarity index 74% rename from routes/simulationmodel/simulationmodel_middleware.go rename to routes/component-configuration/config_middleware.go index 5835b8c..8f19c41 100644 --- a/routes/simulationmodel/simulationmodel_middleware.go +++ b/routes/component-configuration/config_middleware.go @@ -1,4 +1,4 @@ -/** Simulationmodel package, middleware. +/** component_configuration package, middleware. * * @author Sonja Happ * @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 * along with this program. If not, see . *********************************************************************************/ -package simulationmodel +package component_configuration import ( "fmt" @@ -30,22 +30,22 @@ import ( "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/scenario" ) -func CheckPermissions(c *gin.Context, operation database.CRUD, modelIDSource string, modelIDBody int) (bool, SimulationModel) { +func CheckPermissions(c *gin.Context, operation database.CRUD, configIDSource string, configIDBody int) (bool, ComponentConfiguration) { - var m SimulationModel + var m ComponentConfiguration - err := database.ValidateRole(c, database.ModelSimulationModel, operation) + err := database.ValidateRole(c, database.ModelComponentConfiguration, operation) if err != nil { - helper.UnprocessableEntityError(c, fmt.Sprintf("Access denied (role validation of simulation model failed): %v", err.Error())) + helper.UnprocessableEntityError(c, fmt.Sprintf("Access denied (role validation of Component Configuration failed): %v", err.Error())) return false, m } - modelID, err := helper.GetIDOfElement(c, "modelID", modelIDSource, modelIDBody) + configID, err := helper.GetIDOfElement(c, "configID", configIDSource, configIDBody) if err != nil { return false, m } - err = m.ByID(uint(modelID)) + err = m.ByID(uint(configID)) if helper.DBError(c, err) { return false, m } diff --git a/routes/simulationmodel/simulationmodel_test.go b/routes/component-configuration/config_test.go similarity index 52% rename from routes/simulationmodel/simulationmodel_test.go rename to routes/component-configuration/config_test.go index 1a3fff5..41bb5f5 100644 --- a/routes/simulationmodel/simulationmodel_test.go +++ b/routes/component-configuration/config_test.go @@ -1,4 +1,4 @@ -/** Simulationmodel package, testing. +/** component_configuration package, testing. * * @author Sonja Happ * @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC @@ -19,15 +19,15 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . *********************************************************************************/ -package simulationmodel +package component_configuration import ( "fmt" "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/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/simulator" "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user" "github.com/gin-gonic/gin" "github.com/jinzhu/gorm" @@ -39,16 +39,18 @@ import ( var router *gin.Engine var db *gorm.DB +var base_api_configs = "/api/configs" +var base_api_auth = "/api/authenticate" -type SimulationModelRequest struct { - Name string `json:"name,omitempty"` - ScenarioID uint `json:"scenarioID,omitempty"` - SimulatorID uint `json:"simulatorID,omitempty"` - StartParameters postgres.Jsonb `json:"startParameters,omitempty"` - SelectedModelFileID uint `json:"selectedModelFileID,omitempty"` +type ConfigRequest struct { + Name string `json:"name,omitempty"` + ScenarioID uint `json:"scenarioID,omitempty"` + ICID uint `json:"icID,omitempty"` + StartParameters postgres.Jsonb `json:"startParameters,omitempty"` + SelectedFileID uint `json:"selectedFileID,omitempty"` } -type SimulatorRequest struct { +type ICRequest struct { UUID string `json:"uuid,omitempty"` Host string `json:"host,omitempty"` Modeltype string `json:"modelType,omitempty"` @@ -62,40 +64,40 @@ type ScenarioRequest struct { StartParameters postgres.Jsonb `json:"startParameters,omitempty"` } -func addScenarioAndSimulator() (scenarioID uint, simulatorID uint) { +func addScenarioAndIC() (scenarioID uint, ICID uint) { // authenticate as admin token, _ := helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.AdminCredentials) + base_api_auth, "POST", helper.AdminCredentials) - // POST $newSimulatorA - newSimulatorA := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // POST $newICA + newICA := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } _, 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 - newSimulatorID, _ := helper.GetResponseID(resp) + // Read newIC's ID from the response + newICID, _ := helper.GetResponseID(resp) - // POST a second simulator to change to that simulator during testing - newSimulatorB := SimulatorRequest{ - UUID: database.SimulatorB.UUID, - Host: database.SimulatorB.Host, - Modeltype: database.SimulatorB.Modeltype, - State: database.SimulatorB.State, - Properties: database.SimulatorB.Properties, + // POST a second IC to change to that IC during testing + newICB := ICRequest{ + UUID: database.ICB.UUID, + Host: database.ICB.Host, + Modeltype: database.ICB.Modeltype, + State: database.ICB.State, + Properties: database.ICB.Properties, } _, resp, _ = helper.TestEndpoint(router, token, - "/api/simulators", "POST", helper.KeyModels{"simulator": newSimulatorB}) + "/api/ic", "POST", helper.KeyModels{"ic": newICB}) // authenticate as normal user token, _ = helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserACredentials) + base_api_auth, "POST", helper.UserACredentials) // POST $newScenario newScenario := ScenarioRequest{ @@ -113,7 +115,7 @@ func addScenarioAndSimulator() (scenarioID uint, simulatorID uint) { _, resp, _ = helper.TestEndpoint(router, token, 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) { @@ -133,342 +135,342 @@ func TestMain(m *testing.M) { user.RegisterAuthenticate(api.Group("/authenticate")) api.Use(user.Authentication(true)) - RegisterSimulationModelEndpoints(api.Group("/models")) + RegisterComponentConfigurationEndpoints(api.Group("/configs")) // 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 component configuration scenario.RegisterScenarioEndpoints(api.Group("/scenarios")) - // simulator endpoints required here to first add a simulator to the DB - // that can be associated with a new simulation model - simulator.RegisterSimulatorEndpoints(api.Group("/simulators")) + // IC endpoints required here to first add a IC to the DB + // that can be associated with a new component configuration + infrastructure_component.RegisterICEndpoints(api.Group("/ic")) os.Exit(m.Run()) } -func TestAddSimulationModel(t *testing.T) { +func TestAddConfig(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) // 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 - scenarioID, simulatorID := addScenarioAndSimulator() + scenarioID, ICID := addScenarioAndIC() - newSimulationModel := SimulationModelRequest{ - Name: database.SimulationModelA.Name, - ScenarioID: scenarioID, - SimulatorID: simulatorID, - StartParameters: database.SimulationModelA.StartParameters, - SelectedModelFileID: database.SimulationModelA.SelectedModelFileID, + newConfig := ConfigRequest{ + Name: database.ConfigA.Name, + ScenarioID: scenarioID, + ICID: ICID, + StartParameters: database.ConfigA.StartParameters, + SelectedFileID: database.ConfigA.SelectedFileID, } // authenticate as normal userB who has no access to new scenario token, err := helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserBCredentials) + base_api_auth, "POST", helper.UserBCredentials) assert.NoError(t, err) // try to POST with no access // should result in unprocessable entity code, resp, err := helper.TestEndpoint(router, token, - "/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel}) + base_api_configs, "POST", helper.KeyModels{"config": newConfig}) assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) // authenticate as normal user token, err = helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserACredentials) + base_api_auth, "POST", helper.UserACredentials) assert.NoError(t, err) // try to POST non JSON body code, resp, err = helper.TestEndpoint(router, token, - "/api/models", "POST", "this is not JSON") + base_api_configs, "POST", "this is not JSON") assert.NoError(t, err) assert.Equalf(t, 400, code, "Response body: \n%v\n", resp) // authenticate as normal user token, err = helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserACredentials) + base_api_auth, "POST", helper.UserACredentials) assert.NoError(t, err) - // test POST models/ $newSimulationModel + // test POST newConfig code, resp, err = helper.TestEndpoint(router, token, - "/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel}) + base_api_configs, "POST", helper.KeyModels{"config": newConfig}) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare POST's response with the newSimulationModel - err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": newSimulationModel}) + // Compare POST's response with the newConfig + err = helper.CompareResponse(resp, helper.KeyModels{"config": newConfig}) assert.NoError(t, err) - // Read newSimulationModel's ID from the response - newSimulationModelID, err := helper.GetResponseID(resp) + // Read newConfig's ID from the response + newConfigID, err := helper.GetResponseID(resp) assert.NoError(t, err) - // Get the newSimulationModel + // Get the newConfig code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID), "GET", nil) + fmt.Sprintf("%v/%v", base_api_configs, newConfigID), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare GET's response with the newSimulationModel - err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": newSimulationModel}) + // Compare GET's response with the newConfig + err = helper.CompareResponse(resp, helper.KeyModels{"config": newConfig}) assert.NoError(t, err) - // try to POST a malformed simulation model + // try to POST a malformed component config // Required fields are missing - malformedNewSimulationModel := SimulationModelRequest{ + malformedNewConfig := ConfigRequest{ Name: "ThisIsAMalformedRequest", } // this should NOT work and return a unprocessable entity 442 status code code, resp, err = helper.TestEndpoint(router, token, - "/api/models", "POST", helper.KeyModels{"simulationModel": malformedNewSimulationModel}) + base_api_configs, "POST", helper.KeyModels{"config": malformedNewConfig}) assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) // authenticate as normal userB who has no access to new scenario token, err = helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserBCredentials) + base_api_auth, "POST", helper.UserBCredentials) assert.NoError(t, err) - // Try to GET the newSimulationModel with no access + // Try to GET the newConfig with no access // Should result in unprocessable entity code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID), "GET", nil) + fmt.Sprintf("%v/%v", base_api_configs, newConfigID), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) } -func TestUpdateSimulationModel(t *testing.T) { +func TestUpdateConfig(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) // 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 - scenarioID, simulatorID := addScenarioAndSimulator() + scenarioID, ICID := addScenarioAndIC() // authenticate as normal user token, err := helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserACredentials) + base_api_auth, "POST", helper.UserACredentials) assert.NoError(t, err) - // test POST models/ $newSimulationModel - newSimulationModel := SimulationModelRequest{ - Name: database.SimulationModelA.Name, - ScenarioID: scenarioID, - SimulatorID: simulatorID, - StartParameters: database.SimulationModelA.StartParameters, - SelectedModelFileID: database.SimulationModelA.SelectedModelFileID, + // test POST newConfig + newConfig := ConfigRequest{ + Name: database.ConfigA.Name, + ScenarioID: scenarioID, + ICID: ICID, + StartParameters: database.ConfigA.StartParameters, + SelectedFileID: database.ConfigA.SelectedFileID, } code, resp, err := helper.TestEndpoint(router, token, - "/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel}) + base_api_configs, "POST", helper.KeyModels{"config": newConfig}) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Read newSimulationModel's ID from the response - newSimulationModelID, err := helper.GetResponseID(resp) + // Read newConfig's ID from the response + newConfigID, err := helper.GetResponseID(resp) assert.NoError(t, err) - updatedSimulationModel := SimulationModelRequest{ - Name: database.SimulationModelB.Name, - StartParameters: database.SimulationModelB.StartParameters, + updatedConfig := ConfigRequest{ + Name: database.ConfigB.Name, + StartParameters: database.ConfigB.StartParameters, } // authenticate as normal userB who has no access to new scenario token, err = helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserBCredentials) + base_api_auth, "POST", helper.UserBCredentials) assert.NoError(t, err) // try to PUT with no access // should result in unprocessable entity code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel}) + fmt.Sprintf("%v/%v", base_api_configs, newConfigID), "PUT", helper.KeyModels{"config": updatedConfig}) assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) - // authenticate as guest user who has access to simulation model + // authenticate as guest user who has access to component config token, err = helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.GuestCredentials) + base_api_auth, "POST", helper.GuestCredentials) assert.NoError(t, err) // try to PUT as guest // should NOT work and result in unprocessable entity code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel}) + fmt.Sprintf("%v/%v", base_api_configs, newConfigID), "PUT", helper.KeyModels{"config": updatedConfig}) assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) // authenticate as normal user token, err = helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserACredentials) + base_api_auth, "POST", helper.UserACredentials) assert.NoError(t, err) // try to PUT a non JSON body // should result in a bad request code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", "This is not JSON") + fmt.Sprintf("%v/%v", base_api_configs, newConfigID), "PUT", "This is not JSON") assert.NoError(t, err) assert.Equalf(t, 400, code, "Response body: \n%v\n", resp) // test PUT code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel}) + fmt.Sprintf("%v/%v", base_api_configs, newConfigID), "PUT", helper.KeyModels{"config": updatedConfig}) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare PUT's response with the updatedSimulationModel - err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": updatedSimulationModel}) + // Compare PUT's response with the updateConfig + err = helper.CompareResponse(resp, helper.KeyModels{"config": updatedConfig}) assert.NoError(t, err) - //Change simulator ID to use second simulator available in DB - updatedSimulationModel.SimulatorID = simulatorID + 1 + //Change IC ID to use second IC available in DB + updatedConfig.ICID = ICID + 1 // test PUT again code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel}) + fmt.Sprintf("%v/%v", base_api_configs, newConfigID), "PUT", helper.KeyModels{"config": updatedConfig}) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare PUT's response with the updatedSimulationModel - err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": updatedSimulationModel}) + // Compare PUT's response with the updateConfig + err = helper.CompareResponse(resp, helper.KeyModels{"config": updatedConfig}) assert.NoError(t, err) - // Get the updatedSimulationModel + // Get the updateConfig code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID), "GET", nil) + fmt.Sprintf("%v/%v", base_api_configs, newConfigID), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare GET's response with the updatedSimulationModel - err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": updatedSimulationModel}) + // Compare GET's response with the updateConfig + err = helper.CompareResponse(resp, helper.KeyModels{"config": updatedConfig}) assert.NoError(t, err) - // try to update a simulation model that does not exist (should return not found 404 status code) + // try to update a component config that does not exist (should return not found 404 status code) code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID+1), "PUT", helper.KeyModels{"simulationModel": updatedSimulationModel}) + fmt.Sprintf("%v/%v", base_api_configs, newConfigID+1), "PUT", helper.KeyModels{"config": updatedConfig}) assert.NoError(t, err) assert.Equalf(t, 404, code, "Response body: \n%v\n", resp) } -func TestDeleteSimulationModel(t *testing.T) { +func TestDeleteConfig(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) // 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 - scenarioID, simulatorID := addScenarioAndSimulator() + scenarioID, ICID := addScenarioAndIC() - newSimulationModel := SimulationModelRequest{ - Name: database.SimulationModelA.Name, - ScenarioID: scenarioID, - SimulatorID: simulatorID, - StartParameters: database.SimulationModelA.StartParameters, - SelectedModelFileID: database.SimulationModelA.SelectedModelFileID, + newConfig := ConfigRequest{ + Name: database.ConfigA.Name, + ScenarioID: scenarioID, + ICID: ICID, + StartParameters: database.ConfigA.StartParameters, + SelectedFileID: database.ConfigA.SelectedFileID, } // authenticate as normal user token, err := helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserACredentials) + base_api_auth, "POST", helper.UserACredentials) assert.NoError(t, err) - // test POST models/ $newSimulationModel + // test POST newConfig code, resp, err := helper.TestEndpoint(router, token, - "/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel}) + base_api_configs, "POST", helper.KeyModels{"config": newConfig}) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Read newSimulationModel's ID from the response - newSimulationModelID, err := helper.GetResponseID(resp) + // Read newConfig's ID from the response + newConfigID, err := helper.GetResponseID(resp) assert.NoError(t, err) // authenticate as normal userB who has no access to new scenario token, err = helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserBCredentials) + base_api_auth, "POST", helper.UserBCredentials) assert.NoError(t, err) // try to DELETE with no access // should result in unprocessable entity code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID), "DELETE", nil) + fmt.Sprintf("%v/%v", base_api_configs, newConfigID), "DELETE", nil) assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) // authenticate as normal user token, err = helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserACredentials) + base_api_auth, "POST", helper.UserACredentials) assert.NoError(t, err) - // Count the number of all the simulation models returned for scenario + // Count the number of all the component config returned for scenario initialNumber, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/models?scenarioID=%v", scenarioID), "GET", nil) + fmt.Sprintf("%v?scenarioID=%v", base_api_configs, scenarioID), "GET", nil) assert.NoError(t, err) - // Delete the added newSimulationModel + // Delete the added newConfig code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models/%v", newSimulationModelID), "DELETE", nil) + fmt.Sprintf("%v/%v", base_api_configs, newConfigID), "DELETE", nil) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare DELETE's response with the newSimulationModel - err = helper.CompareResponse(resp, helper.KeyModels{"simulationModel": newSimulationModel}) + // Compare DELETE's response with the newConfig + err = helper.CompareResponse(resp, helper.KeyModels{"config": newConfig}) assert.NoError(t, err) - // Again count the number of all the simulation models returned + // Again count the number of all the component configs returned finalNumber, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/models?scenarioID=%v", scenarioID), "GET", nil) + fmt.Sprintf("%v?scenarioID=%v", base_api_configs, scenarioID), "GET", nil) assert.NoError(t, err) assert.Equal(t, initialNumber-1, finalNumber) } -func TestGetAllSimulationModelsOfScenario(t *testing.T) { +func TestGetAllConfigsOfScenario(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) // 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 - scenarioID, simulatorID := addScenarioAndSimulator() + scenarioID, ICID := addScenarioAndIC() // authenticate as normal user token, err := helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserACredentials) + base_api_auth, "POST", helper.UserACredentials) assert.NoError(t, err) - // test POST models/ $newSimulationModel - newSimulationModel := SimulationModelRequest{ - Name: database.SimulationModelA.Name, - ScenarioID: scenarioID, - SimulatorID: simulatorID, - StartParameters: database.SimulationModelA.StartParameters, - SelectedModelFileID: database.SimulationModelA.SelectedModelFileID, + // test POST newConfig + newConfig := ConfigRequest{ + Name: database.ConfigA.Name, + ScenarioID: scenarioID, + ICID: ICID, + StartParameters: database.ConfigA.StartParameters, + SelectedFileID: database.ConfigA.SelectedFileID, } code, resp, err := helper.TestEndpoint(router, token, - "/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel}) + base_api_configs, "POST", helper.KeyModels{"config": newConfig}) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Count the number of all the simulation models returned for scenario - NumberOfSimulationModels, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/models?scenarioID=%v", scenarioID), "GET", nil) + // Count the number of all the component config returned for scenario + NumberOfConfigs, err := helper.LengthOfResponse(router, token, + fmt.Sprintf("%v?scenarioID=%v", base_api_configs, scenarioID), "GET", nil) assert.NoError(t, err) - assert.Equal(t, 1, NumberOfSimulationModels) + assert.Equal(t, 1, NumberOfConfigs) // authenticate as normal userB who has no access to scenario token, err = helper.AuthenticateForTest(router, - "/api/authenticate", "POST", helper.UserBCredentials) + base_api_auth, "POST", helper.UserBCredentials) assert.NoError(t, err) - // try to get models without access + // try to get configs without access // should result in unprocessable entity code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/models?scenarioID=%v", scenarioID), "GET", nil) + fmt.Sprintf("%v?scenarioID=%v", base_api_configs, scenarioID), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) diff --git a/routes/component-configuration/config_validators.go b/routes/component-configuration/config_validators.go new file mode 100644 index 0000000..975c319 --- /dev/null +++ b/routes/component-configuration/config_validators.go @@ -0,0 +1,108 @@ +/** component_configuration package, validators. +* +* @author Sonja Happ +* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC +* @license GNU General Public License (version 3) +* +* VILLASweb-backend-go +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation, either version 3 of the License, or +* any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*********************************************************************************/ +package component_configuration + +import ( + "encoding/json" + "github.com/jinzhu/gorm/dialects/postgres" + "github.com/nsf/jsondiff" + "gopkg.in/go-playground/validator.v9" +) + +var validate *validator.Validate + +type validNewConfig struct { + Name string `form:"Name" validate:"required"` + ScenarioID uint `form:"ScenarioID" validate:"required"` + ICID uint `form:"ICID" validate:"required"` + StartParameters postgres.Jsonb `form:"StartParameters" validate:"required"` + SelectedFileID uint `form:"SelectedFileID" validate:"omitempty"` +} + +type validUpdatedConfig struct { + Name string `form:"Name" validate:"omitempty"` + ICID uint `form:"ICID" validate:"omitempty"` + StartParameters postgres.Jsonb `form:"StartParameters" validate:"omitempty"` + SelectedFileID uint `form:"SelectedFileID" validate:"omitempty"` +} + +type addConfigRequest struct { + Config validNewConfig `json:"config"` +} + +type updateConfigRequest struct { + Config validUpdatedConfig `json:"config"` +} + +func (r *addConfigRequest) validate() error { + validate = validator.New() + errs := validate.Struct(r) + return errs +} + +func (r *validUpdatedConfig) validate() error { + validate = validator.New() + errs := validate.Struct(r) + return errs +} + +func (r *addConfigRequest) createConfig() ComponentConfiguration { + var s ComponentConfiguration + + s.Name = r.Config.Name + s.ScenarioID = r.Config.ScenarioID + s.ICID = r.Config.ICID + s.StartParameters = r.Config.StartParameters + s.SelectedFileID = r.Config.SelectedFileID + + return s +} + +func (r *updateConfigRequest) updateConfig(oldConfig ComponentConfiguration) ComponentConfiguration { + // Use the old ComponentConfiguration as a basis for the updated config + s := oldConfig + + if r.Config.Name != "" { + s.Name = r.Config.Name + } + + if r.Config.ICID != 0 { + s.ICID = r.Config.ICID + } + + if r.Config.SelectedFileID != 0 { + s.SelectedFileID = r.Config.SelectedFileID + } + + // only update Params if not empty + var emptyJson postgres.Jsonb + // Serialize empty json and params + emptyJson_ser, _ := json.Marshal(emptyJson) + startParams_ser, _ := json.Marshal(r.Config.StartParameters) + opts := jsondiff.DefaultConsoleOptions() + diff, _ := jsondiff.Compare(emptyJson_ser, startParams_ser, &opts) + if diff.String() != "FullMatch" { + s.StartParameters = r.Config.StartParameters + } + + return s +} diff --git a/routes/file/file_endpoints.go b/routes/file/file_endpoints.go index 1378dda..00ec497 100644 --- a/routes/file/file_endpoints.go +++ b/routes/file/file_endpoints.go @@ -30,7 +30,7 @@ import ( "github.com/gin-gonic/gin" "git.rwth-aachen.de/acs/public/villas/web-backend-go/database" - "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel" + "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration" "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget" ) @@ -43,23 +43,23 @@ func RegisterFileEndpoints(r *gin.RouterGroup) { } // getFiles godoc -// @Summary Get all files of a specific model or widget +// @Summary Get all files of a specific component configuration or widget // @ID getFiles // @Tags files // @Produce json -// @Success 200 {object} docs.ResponseFiles "Files which belong to simulation model or widget" +// @Success 200 {object} docs.ResponseFiles "Files which belong to config or widget" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param objectType query string true "Set to model for files of model, set to widget for files of widget" -// @Param objectID query int true "ID of either model or widget of which files are requested" +// @Param objectType query string true "Set to config for files of component configuration, set to widget for files of widget" +// @Param objectID query int true "ID of either config or widget of which files are requested" // @Router /files [get] func getFiles(c *gin.Context) { var err error objectType := c.Request.URL.Query().Get("objectType") - if objectType != "model" && objectType != "widget" { + if objectType != "config" && objectType != "widget" { helper.BadRequestError(c, fmt.Sprintf("Object type not supported for files: %s", objectType)) return } @@ -72,10 +72,10 @@ func getFiles(c *gin.Context) { //Check access var ok bool - var m simulationmodel.SimulationModel + var m component_configuration.ComponentConfiguration var w widget.Widget - if objectType == "model" { - ok, m = simulationmodel.CheckPermissions(c, database.Read, "body", objectID) + if objectType == "config" { + ok, m = component_configuration.CheckPermissions(c, database.Read, "body", objectID) } else { ok, w = widget.CheckPermissions(c, database.Read, objectID) } @@ -88,7 +88,7 @@ func getFiles(c *gin.Context) { var files []database.File - if objectType == "model" { + if objectType == "config" { err = db.Order("ID asc").Model(&m).Related(&files, "Files").Error } else { err = db.Order("ID asc").Model(&w).Related(&files, "Files").Error @@ -101,7 +101,7 @@ func getFiles(c *gin.Context) { } // addFile godoc -// @Summary Add a file to a specific model or widget +// @Summary Add a file to a specific component config or widget // @ID addFile // @Tags files // @Produce json @@ -118,13 +118,13 @@ func getFiles(c *gin.Context) { // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" // @Param inputFile formData file true "File to be uploaded" -// @Param objectType query string true "Set to model for files of model, set to widget for files of widget" -// @Param objectID query int true "ID of either model or widget of which files are requested" +// @Param objectType query string true "Set to config for files of component config, set to widget for files of widget" +// @Param objectID query int true "ID of either config or widget of which files are requested" // @Router /files [post] func addFile(c *gin.Context) { objectType := c.Request.URL.Query().Get("objectType") - if objectType != "model" && objectType != "widget" { + if objectType != "config" && objectType != "widget" { helper.BadRequestError(c, fmt.Sprintf("Object type not supported for files: %s", objectType)) return } @@ -137,8 +137,8 @@ func addFile(c *gin.Context) { // Check access var ok bool - if objectType == "model" { - ok, _ = simulationmodel.CheckPermissions(c, database.Update, "body", objectID) + if objectType == "config" { + ok, _ = component_configuration.CheckPermissions(c, database.Update, "body", objectID) if !ok { return } diff --git a/routes/file/file_methods.go b/routes/file/file_methods.go index 25b863f..5888755 100644 --- a/routes/file/file_methods.go +++ b/routes/file/file_methods.go @@ -31,7 +31,7 @@ import ( "time" "git.rwth-aachen.de/acs/public/villas/web-backend-go/database" - "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel" + "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration" "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget" ) @@ -84,14 +84,14 @@ func (f *File) register(fileHeader *multipart.FileHeader, objectType string, obj f.ImageWidth = 0 // TODO: do we need this? f.ImageHeight = 0 // TODO: do we need this? - var m simulationmodel.SimulationModel + var m component_configuration.ComponentConfiguration var w widget.Widget var err error - if objectType == "model" { - // check if model exists + if objectType == "config" { + // check if config exists err = m.ByID(objectID) f.WidgetID = 0 - f.SimulationModelID = objectID + f.ConfigID = objectID if err != nil { return err } @@ -99,7 +99,7 @@ func (f *File) register(fileHeader *multipart.FileHeader, objectType string, obj } else { // check if widget exists f.WidgetID = objectID - f.SimulationModelID = 0 + f.ConfigID = 0 err = w.ByID(uint(objectID)) if err != nil { return err @@ -122,8 +122,8 @@ func (f *File) register(fileHeader *multipart.FileHeader, objectType string, obj return err } - // Create association to model or widget - if objectType == "model" { + // Create association to config or widget + if objectType == "config" { db := database.GetDB() err := db.Model(&m).Association("Files").Append(f).Error if err != nil { @@ -174,9 +174,9 @@ func (f *File) delete() error { return err } } else { - // remove association between file and simulation model - var m simulationmodel.SimulationModel - err := m.ByID(f.SimulationModelID) + // remove association between file and config + var m component_configuration.ComponentConfiguration + err := m.ByID(f.ConfigID) if err != nil { return err } diff --git a/routes/file/file_middleware.go b/routes/file/file_middleware.go index 8504c40..4a76f71 100644 --- a/routes/file/file_middleware.go +++ b/routes/file/file_middleware.go @@ -25,7 +25,7 @@ import ( "fmt" "git.rwth-aachen.de/acs/public/villas/web-backend-go/database" "git.rwth-aachen.de/acs/public/villas/web-backend-go/helper" - "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel" + "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration" "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget" "github.com/gin-gonic/gin" ) @@ -50,8 +50,8 @@ func checkPermissions(c *gin.Context, operation database.CRUD) (bool, File) { return false, f } - if f.SimulationModelID > 0 { - ok, _ := simulationmodel.CheckPermissions(c, operation, "body", int(f.SimulationModelID)) + if f.ConfigID > 0 { + ok, _ := component_configuration.CheckPermissions(c, operation, "body", int(f.ConfigID)) if !ok { return false, f } diff --git a/routes/file/file_test.go b/routes/file/file_test.go index de85f0f..cbe1d1a 100644 --- a/routes/file/file_test.go +++ b/routes/file/file_test.go @@ -27,10 +27,10 @@ import ( "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/helper" + "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration" "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/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/widget" "github.com/gin-gonic/gin" @@ -49,14 +49,14 @@ import ( var router *gin.Engine var db *gorm.DB -type SimulationModelRequest struct { +type ConfigRequest struct { Name string `json:"name,omitempty"` ScenarioID uint `json:"scenarioID,omitempty"` - SimulatorID uint `json:"simulatorID,omitempty"` + ICID uint `json:"icID,omitempty"` StartParameters postgres.Jsonb `json:"startParameters,omitempty"` } -type SimulatorRequest struct { +type ICRequest struct { UUID string `json:"uuid,omitempty"` Host string `json:"host,omitempty"` Modeltype string `json:"modelType,omitempty"` @@ -91,25 +91,25 @@ type WidgetRequest struct { CustomProperties postgres.Jsonb `json:"customProperties,omitempty"` } -func addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() (scenarioID uint, simulatorID uint, simulationModelID uint, dashboardID uint, widgetID uint) { +func addScenarioAndICAndConfigAndDashboardAndWidget() (scenarioID uint, ICID uint, configID uint, dashboardID uint, widgetID uint) { // authenticate as admin token, _ := helper.AuthenticateForTest(router, "/api/authenticate", "POST", helper.AdminCredentials) - // POST $newSimulatorA - newSimulatorA := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // POST $newICA + newICA := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } _, 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 - newSimulatorID, _ := helper.GetResponseID(resp) + // Read newIC's ID from the response + newICID, _ := helper.GetResponseID(resp) // authenticate as normal user token, _ = helper.AuthenticateForTest(router, @@ -127,18 +127,18 @@ func addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() (scenarioI // Read newScenario's ID from the response newScenarioID, _ := helper.GetResponseID(resp) - // POST new simulation model - newSimulationModel := SimulationModelRequest{ - Name: database.SimulationModelA.Name, + // POST new component config + newConfig := ConfigRequest{ + Name: database.ConfigA.Name, ScenarioID: uint(newScenarioID), - SimulatorID: uint(newSimulatorID), - StartParameters: database.SimulationModelA.StartParameters, + ICID: uint(newICID), + StartParameters: database.ConfigA.StartParameters, } _, resp, _ = helper.TestEndpoint(router, token, - "/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel}) + "/api/configs", "POST", helper.KeyModels{"config": newConfig}) - // Read newSimulationModel's ID from the response - newSimulationModelID, _ := helper.GetResponseID(resp) + // Read newConfig's ID from the response + newConfigID, _ := helper.GetResponseID(resp) // POST new dashboard newDashboard := DashboardRequest{ @@ -177,7 +177,7 @@ func addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() (scenarioI _, resp, _ = helper.TestEndpoint(router, token, 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(newConfigID), uint(newDashboardID), uint(newWidgetID) } func TestMain(m *testing.M) { @@ -196,15 +196,15 @@ func TestMain(m *testing.M) { user.RegisterAuthenticate(api.Group("/authenticate")) api.Use(user.Authentication(true)) - // simulationmodel endpoints required here to first add a simulation to the DB + // component-configuration endpoints required here to first add a config to the DB // that can be associated with a new file - simulationmodel.RegisterSimulationModelEndpoints(api.Group("/models")) + component_configuration.RegisterComponentConfigurationEndpoints(api.Group("/configs")) // 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 component config scenario.RegisterScenarioEndpoints(api.Group("/scenarios")) - // simulator endpoints required here to first add a simulator to the DB - // that can be associated with a new simulation model - simulator.RegisterSimulatorEndpoints(api.Group("/simulators")) + // IC endpoints required here to first add a IC to the DB + // that can be associated with a new component config + infrastructure_component.RegisterICEndpoints(api.Group("/ic")) // dashboard endpoints required here to first add a dashboard to the DB // that can be associated with a new widget dashboard.RegisterDashboardEndpoints(api.Group("/dashboards")) @@ -224,7 +224,7 @@ func TestAddFile(t *testing.T) { // prepare the content of the DB for testing // using the respective endpoints of the API - _, _, simulationModelID, _, widgetID := addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() + _, _, configID, _, widgetID := addScenarioAndICAndConfigAndDashboardAndWidget() // authenticate as userB who has no access to the elements in the DB token, err := helper.AuthenticateForTest(router, @@ -233,10 +233,10 @@ func TestAddFile(t *testing.T) { emptyBuf := &bytes.Buffer{} - // try to POST to a simulation model to which UserB has no access + // try to POST to a component config to which UserB has no access // should return a 422 unprocessable entity error code, resp, err := helper.TestEndpoint(router, token, - fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), "POST", emptyBuf) + fmt.Sprintf("/api/files?objectID=%v&objectType=config", configID), "POST", emptyBuf) assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) @@ -262,14 +262,14 @@ func TestAddFile(t *testing.T) { // try to POST without an object ID // should return a bad request error code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/files?objectType=model"), "POST", emptyBuf) + fmt.Sprintf("/api/files?objectType=config"), "POST", emptyBuf) assert.NoError(t, err) assert.Equalf(t, 400, code, "Response body: \n%v\n", resp) // try to POST an invalid file // should return a bad request code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), "POST", emptyBuf) + fmt.Sprintf("/api/files?objectID=%v&objectType=config", configID), "POST", emptyBuf) assert.NoError(t, err) assert.Equalf(t, 400, code, "Response body: \n%v\n", resp) @@ -299,7 +299,7 @@ func TestAddFile(t *testing.T) { // Create the request w := httptest.NewRecorder() - req, err := http.NewRequest("POST", fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), bodyBuf) + req, err := http.NewRequest("POST", fmt.Sprintf("/api/files?objectID=%v&objectType=config", configID), bodyBuf) assert.NoError(t, err, "create request") req.Header.Set("Content-Type", contentType) @@ -340,7 +340,7 @@ func TestUpdateFile(t *testing.T) { // prepare the content of the DB for testing // using the respective endpoints of the API - _, _, simulationModelID, _, _ := addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() + _, _, configID, _, _ := addScenarioAndICAndConfigAndDashboardAndWidget() // authenticate as normal user token, err := helper.AuthenticateForTest(router, @@ -372,7 +372,7 @@ func TestUpdateFile(t *testing.T) { // Create the POST request w := httptest.NewRecorder() - req, err := http.NewRequest("POST", fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), bodyBuf) + req, err := http.NewRequest("POST", fmt.Sprintf("/api/files?objectID=%v&objectType=config", configID), bodyBuf) assert.NoError(t, err, "create request") req.Header.Set("Content-Type", contentType) @@ -474,7 +474,7 @@ func TestDeleteFile(t *testing.T) { // prepare the content of the DB for testing // using the respective endpoints of the API - _, _, simulationModelID, _, widgetID := addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() + _, _, configID, _, widgetID := addScenarioAndICAndConfigAndDashboardAndWidget() // authenticate as normal user token, err := helper.AuthenticateForTest(router, @@ -504,7 +504,7 @@ func TestDeleteFile(t *testing.T) { // Create the request w := httptest.NewRecorder() - req, err := http.NewRequest("POST", fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), bodyBuf) + req, err := http.NewRequest("POST", fmt.Sprintf("/api/files?objectID=%v&objectType=config", configID), bodyBuf) assert.NoError(t, err, "create request") req.Header.Set("Content-Type", contentType) req.Header.Add("Authorization", "Bearer "+token) @@ -542,7 +542,7 @@ func TestDeleteFile(t *testing.T) { "/api/authenticate", "POST", helper.UserBCredentials) assert.NoError(t, err) - // try to DELETE file of simulation model to which userB has no access + // try to DELETE file of component config to which userB has no access // should return an unprocessable entity error code, resp, err := helper.TestEndpoint(router, token, fmt.Sprintf("/api/files/%v", newFileID), "DELETE", nil) @@ -561,9 +561,9 @@ func TestDeleteFile(t *testing.T) { "/api/authenticate", "POST", helper.UserACredentials) assert.NoError(t, err) - // Count the number of all files returned for simulation model + // Count the number of all files returned for component config initialNumber, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), "GET", nil) + fmt.Sprintf("/api/files?objectID=%v&objectType=config", configID), "GET", nil) assert.NoError(t, err) // try to DELETE non-existing fileID @@ -578,7 +578,7 @@ func TestDeleteFile(t *testing.T) { "/api/authenticate", "POST", helper.GuestCredentials) assert.NoError(t, err) - // try to DELETE file of simulation model as guest + // try to DELETE file of component config as guest // should return an unprocessable entity error code, resp, err = helper.TestEndpoint(router, token, fmt.Sprintf("/api/files/%v", newFileID), "DELETE", nil) @@ -609,15 +609,15 @@ func TestDeleteFile(t *testing.T) { assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Again count the number of all the files returned for simulation model + // Again count the number of all the files returned for component config finalNumber, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), "GET", nil) + fmt.Sprintf("/api/files?objectID=%v&objectType=config", configID), "GET", nil) assert.NoError(t, err) assert.Equal(t, initialNumber-1, finalNumber) } -func TestGetAllFilesOfSimulationModel(t *testing.T) { +func TestGetAllFilesOfConfig(t *testing.T) { database.DropTables(db) database.MigrateModels(db) @@ -625,17 +625,17 @@ func TestGetAllFilesOfSimulationModel(t *testing.T) { // prepare the content of the DB for testing // using the respective endpoints of the API - _, _, simulationModelID, _, widgetID := addScenarioAndSimulatorAndSimulationModelAndDashboardAndWidget() + _, _, ConfigID, _, widgetID := addScenarioAndICAndConfigAndDashboardAndWidget() // authenticate as userB who has no access to the elements in the DB token, err := helper.AuthenticateForTest(router, "/api/authenticate", "POST", helper.UserBCredentials) assert.NoError(t, err) - // try to get all files for simulation model to which userB has not access + // try to get all files for component config to which userB has not access // should return unprocessable entity error code, resp, err := helper.TestEndpoint(router, token, - fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), "GET", nil) + fmt.Sprintf("/api/files?objectID=%v&objectType=config", ConfigID), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) @@ -653,19 +653,19 @@ func TestGetAllFilesOfSimulationModel(t *testing.T) { //try to get all files for unsupported object type; should return a bad request error code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/files?objectID=%v&objectType=wrongtype", simulationModelID), "GET", nil) + fmt.Sprintf("/api/files?objectID=%v&objectType=wrongtype", ConfigID), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 400, code, "Response body: \n%v\n", resp) //try to get all files with missing object ID; should return a bad request error code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/files?objectType=model"), "GET", nil) + fmt.Sprintf("/api/files?objectType=config"), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 400, code, "Response body: \n%v\n", resp) - // Count the number of all files returned for simulation model - initialNumberModel, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), "GET", nil) + // Count the number of all files returned for component config + initialNumberConfig, err := helper.LengthOfResponse(router, token, + fmt.Sprintf("/api/files?objectID=%v&objectType=config", ConfigID), "GET", nil) assert.NoError(t, err) // Count the number of all files returned for widget @@ -683,30 +683,30 @@ func TestGetAllFilesOfSimulationModel(t *testing.T) { assert.NoError(t, err, "opening file") defer fh.Close() - // test POST a file to simulation model and widget - bodyBufModel1 := &bytes.Buffer{} + // test POST a file to component config and widget + bodyBufConfig1 := &bytes.Buffer{} bodyBufWidget1 := &bytes.Buffer{} - bodyWriterModel1 := multipart.NewWriter(bodyBufModel1) + bodyWriterConfig1 := multipart.NewWriter(bodyBufConfig1) bodyWriterWidget1 := multipart.NewWriter(bodyBufWidget1) - fileWriterModel1, err := bodyWriterModel1.CreateFormFile("file", "testuploadfile.txt") + fileWriterConfig1, err := bodyWriterConfig1.CreateFormFile("file", "testuploadfile.txt") assert.NoError(t, err, "writing to buffer") fileWriterWidget1, err := bodyWriterWidget1.CreateFormFile("file", "testuploadfile.txt") assert.NoError(t, err, "writing to buffer") // io copy - _, err = io.Copy(fileWriterModel1, fh) + _, err = io.Copy(fileWriterConfig1, fh) assert.NoError(t, err, "IO copy") _, err = io.Copy(fileWriterWidget1, fh) assert.NoError(t, err, "IO copy") - contentTypeModel1 := bodyWriterModel1.FormDataContentType() + contentTypeConfig1 := bodyWriterConfig1.FormDataContentType() contentTypeWidget1 := bodyWriterWidget1.FormDataContentType() - bodyWriterModel1.Close() + bodyWriterConfig1.Close() bodyWriterWidget1.Close() - // Create the request for simulation model + // Create the request for component config w := httptest.NewRecorder() - req, err := http.NewRequest("POST", fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), bodyBufModel1) + req, err := http.NewRequest("POST", fmt.Sprintf("/api/files?objectID=%v&objectType=config", ConfigID), bodyBufConfig1) assert.NoError(t, err, "create request") - req.Header.Set("Content-Type", contentTypeModel1) + req.Header.Set("Content-Type", contentTypeConfig1) req.Header.Add("Authorization", "Bearer "+token) router.ServeHTTP(w, req) assert.Equalf(t, 200, w.Code, "Response body: \n%v\n", w.Body) @@ -720,36 +720,36 @@ func TestGetAllFilesOfSimulationModel(t *testing.T) { router.ServeHTTP(w2, req2) assert.Equalf(t, 200, w2.Code, "Response body: \n%v\n", w2.Body) - // POST a second file to simulation model and widget + // POST a second file to component config and widget // open a second file handle fh2, err := os.Open("testfile.txt") assert.NoError(t, err, "opening file") defer fh2.Close() - bodyBufModel2 := &bytes.Buffer{} + bodyBufConfig2 := &bytes.Buffer{} bodyBufWidget2 := &bytes.Buffer{} - bodyWriterModel2 := multipart.NewWriter(bodyBufModel2) + bodyWriterConfig2 := multipart.NewWriter(bodyBufConfig2) bodyWriterWidget2 := multipart.NewWriter(bodyBufWidget2) - fileWriterModel2, err := bodyWriterModel2.CreateFormFile("file", "testuploadfile2.txt") + fileWriterConfig2, err := bodyWriterConfig2.CreateFormFile("file", "testuploadfile2.txt") assert.NoError(t, err, "writing to buffer") fileWriterWidget2, err := bodyWriterWidget2.CreateFormFile("file", "testuploadfile2.txt") assert.NoError(t, err, "writing to buffer") // io copy - _, err = io.Copy(fileWriterModel2, fh2) + _, err = io.Copy(fileWriterConfig2, fh2) assert.NoError(t, err, "IO copy") _, err = io.Copy(fileWriterWidget2, fh2) assert.NoError(t, err, "IO copy") - contentTypeModel2 := bodyWriterModel2.FormDataContentType() + contentTypeConfig2 := bodyWriterConfig2.FormDataContentType() contentTypeWidget2 := bodyWriterWidget2.FormDataContentType() - bodyWriterModel2.Close() + bodyWriterConfig2.Close() bodyWriterWidget2.Close() w3 := httptest.NewRecorder() - req3, err := http.NewRequest("POST", fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), bodyBufModel2) + req3, err := http.NewRequest("POST", fmt.Sprintf("/api/files?objectID=%v&objectType=config", ConfigID), bodyBufConfig2) assert.NoError(t, err, "create request") - req3.Header.Set("Content-Type", contentTypeModel2) + req3.Header.Set("Content-Type", contentTypeConfig2) req3.Header.Add("Authorization", "Bearer "+token) router.ServeHTTP(w3, req3) assert.Equalf(t, 200, w3.Code, "Response body: \n%v\n", w3.Body) @@ -762,11 +762,11 @@ func TestGetAllFilesOfSimulationModel(t *testing.T) { router.ServeHTTP(w4, req4) assert.Equalf(t, 200, w4.Code, "Response body: \n%v\n", w4.Body) - // Again count the number of all the files returned for simulation model - finalNumberModel, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/files?objectID=%v&objectType=model", simulationModelID), "GET", nil) + // Again count the number of all the files returned for component config + finalNumberConfig, err := helper.LengthOfResponse(router, token, + fmt.Sprintf("/api/files?objectID=%v&objectType=config", ConfigID), "GET", nil) assert.NoError(t, err) - assert.Equal(t, initialNumberModel+2, finalNumberModel) + assert.Equal(t, initialNumberConfig+2, finalNumberConfig) // Again count the number of all the files returned for widget finalNumberWidget, err := helper.LengthOfResponse(router, token, diff --git a/routes/simulator/simulator_endpoints.go b/routes/infrastructure-component/ic_endpoints.go similarity index 51% rename from routes/simulator/simulator_endpoints.go rename to routes/infrastructure-component/ic_endpoints.go index f5bb5a3..f50bf25 100644 --- a/routes/simulator/simulator_endpoints.go +++ b/routes/infrastructure-component/ic_endpoints.go @@ -1,4 +1,4 @@ -/** Simulator package, endpoints. +/** InfrastructureComponent package, endpoints. * * @author Sonja Happ * @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 * along with this program. If not, see . *********************************************************************************/ -package simulator +package infrastructure_component import ( "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" ) -func RegisterSimulatorEndpoints(r *gin.RouterGroup) { - r.GET("", getSimulators) - r.POST("", addSimulator) - r.PUT("/:simulatorID", updateSimulator) - r.GET("/:simulatorID", getSimulator) - r.DELETE("/:simulatorID", deleteSimulator) - r.GET("/:simulatorID/models", getModelsOfSimulator) +func RegisterICEndpoints(r *gin.RouterGroup) { + r.GET("", getICs) + r.POST("", addIC) + r.PUT("/:ICID", updateIC) + r.GET("/:ICID", getIC) + r.DELETE("/:ICID", deleteIC) + r.GET("/:ICID/configs", getConfigsOfIC) } -// getSimulators godoc -// @Summary Get all simulators -// @ID getSimulators -// @Tags simulators +// getICs godoc +// @Summary Get all infrastructure components +// @ID getICs +// @Tags infrastructure-components // @Produce json -// @Success 200 {object} docs.ResponseSimulators "Simulators requested" +// @Success 200 {object} docs.ResponseICs "ICs requested" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Router /simulators [get] -func getSimulators(c *gin.Context) { +// @Router /ic [get] +func getICs(c *gin.Context) { // Checking permission is not required here since READ access is independent of user's role db := database.GetDB() - var simulators []database.Simulator - err := db.Order("ID asc").Find(&simulators).Error + var ics []database.InfrastructureComponent + err := db.Order("ID asc").Find(&ics).Error if !helper.DBError(c, err) { - c.JSON(http.StatusOK, gin.H{"simulators": simulators}) + c.JSON(http.StatusOK, gin.H{"ics": ics}) } } -// addSimulator godoc -// @Summary Add a simulator -// @ID addSimulator +// addIC godoc +// @Summary Add an infrastructure component +// @ID addIC // @Accept json // @Produce json -// @Tags simulators -// @Success 200 {object} docs.ResponseSimulator "Simulator that was added" +// @Tags infrastructure-components +// @Success 200 {object} docs.ResponseIC "Infrastructure Component that was added" // @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param inputSimulator body simulator.addSimulatorRequest true "Simulator to be added" -// @Router /simulators [post] -func addSimulator(c *gin.Context) { +// @Param inputIC body infrastructure_component.addICRequest true "Infrastructure Component to be added" +// @Router /ic [post] +func addIC(c *gin.Context) { - ok, _ := CheckPermissions(c, database.ModelSimulator, database.Create, false) + ok, _ := CheckPermissions(c, database.ModelInfrastructureComponent, database.Create, false) if !ok { return } - var req addSimulatorRequest + var req addICRequest err := c.BindJSON(&req) if err != nil { helper.BadRequestError(c, "Error binding form data to JSON: "+err.Error()) @@ -96,40 +96,40 @@ func addSimulator(c *gin.Context) { return } - // Create the new simulator from the request - newSimulator := req.createSimulator() + // Create the new IC from the request + newIC := req.createIC() - // Save new simulator to DB - err = newSimulator.save() + // Save new IC to DB + err = newIC.save() 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 -// @Summary Update a simulator -// @ID updateSimulator -// @Tags simulators +// updateIC godoc +// @Summary Update an infrastructure component +// @ID updateIC +// @Tags infrastructure-components // @Accept 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 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param inputSimulator body simulator.updateSimulatorRequest true "Simulator to be updated" -// @Param simulatorID path int true "Simulator ID" -// @Router /simulators/{simulatorID} [put] -func updateSimulator(c *gin.Context) { +// @Param inputIC body infrastructure_component.updateICRequest true "InfrastructureComponent to be updated" +// @Param ICID path int true "InfrastructureComponent ID" +// @Router /ic/{ICID} [put] +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 { return } - var req updateSimulatorRequest + var req updateICRequest err := c.BindJSON(&req) if err != nil { helper.BadRequestError(c, "Error binding form data to JSON: "+err.Error()) @@ -137,97 +137,97 @@ func updateSimulator(c *gin.Context) { } // Validate the request - if err = req.Simulator.validate(); err != nil { + if err = req.InfrastructureComponent.validate(); err != nil { helper.UnprocessableEntityError(c, err.Error()) return } - // Create the updatedSimulator from oldSimulator - updatedSimulator := req.updatedSimulator(oldSimulator) + // Create the updatedIC from oldIC + updatedIC := req.updatedIC(oldIC) - // Finally update the simulator in the DB - err = oldSimulator.update(updatedSimulator) + // Finally update the IC in the DB + err = oldIC.update(updatedIC) 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 -// @Summary Get simulator -// @ID getSimulator +// getIC godoc +// @Summary Get infrastructure component +// @ID getIC // @Produce json -// @Tags simulators -// @Success 200 {object} docs.ResponseSimulator "Simulator that was requested" +// @Tags infrastructure-components +// @Success 200 {object} docs.ResponseIC "Infrastructure Component that was requested" // @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param simulatorID path int true "Simulator ID" -// @Router /simulators/{simulatorID} [get] -func getSimulator(c *gin.Context) { +// @Param ICID path int true "Infrastructure Component ID" +// @Router /ic/{ICID} [get] +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 { return } - c.JSON(http.StatusOK, gin.H{"simulator": s.Simulator}) + c.JSON(http.StatusOK, gin.H{"ic": s.InfrastructureComponent}) } -// deleteSimulator godoc -// @Summary Delete a simulator -// @ID deleteSimulator -// @Tags simulators +// deleteIC godoc +// @Summary Delete an infrastructure component +// @ID deleteIC +// @Tags infrastructure-components // @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 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param simulatorID path int true "Simulator ID" -// @Router /simulators/{simulatorID} [delete] -func deleteSimulator(c *gin.Context) { +// @Param ICID path int true "Infrastructure Component ID" +// @Router /ic/{ICID} [delete] +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 { return } - // Delete the simulator + // Delete the IC err := s.delete() 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 -// @Summary Get all simulation models in which the simulator is used -// @ID getModelsOfSimulator -// @Tags simulators +// getConfigsOfIC godoc +// @Summary Get all configurations of the infrastructure component +// @ID getConfigsOfIC +// @Tags infrastructure-components // @Produce json -// @Success 200 {object} docs.ResponseSimulationModels "Simulation models requested by user" +// @Success 200 {object} docs.ResponseConfigs "Configs requested by user" // @Failure 400 {object} docs.ResponseError "Bad request" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param simulatorID path int true "Simulator ID" -// @Router /simulators/{simulatorID}/models [get] -func getModelsOfSimulator(c *gin.Context) { +// @Param ICID path int true "Infrastructure Component ID" +// @Router /ic/{ICID}/configs [get] +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 { return } - // get all associated simulation models - allModels, _, err := s.getModels() + // get all associated configurations + allConfigs, _, err := s.getConfigs() if !helper.DBError(c, err) { - c.JSON(http.StatusOK, gin.H{"simulationModels": allModels}) + c.JSON(http.StatusOK, gin.H{"configs": allConfigs}) } } diff --git a/routes/simulator/simulator_methods.go b/routes/infrastructure-component/ic_methods.go similarity index 56% rename from routes/simulator/simulator_methods.go rename to routes/infrastructure-component/ic_methods.go index 6f8d54f..2636436 100644 --- a/routes/simulator/simulator_methods.go +++ b/routes/infrastructure-component/ic_methods.go @@ -1,4 +1,4 @@ -/** Simulator package, methods. +/** InfrastructureComponent package, methods. * * @author Sonja Happ * @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 * along with this program. If not, see . *********************************************************************************/ -package simulator +package infrastructure_component import ( "fmt" @@ -27,47 +27,47 @@ import ( "git.rwth-aachen.de/acs/public/villas/web-backend-go/database" ) -type Simulator struct { - database.Simulator +type InfrastructureComponent struct { + database.InfrastructureComponent } -func (s *Simulator) save() error { +func (s *InfrastructureComponent) save() error { db := database.GetDB() err := db.Create(s).Error return err } -func (s *Simulator) ByID(id uint) error { +func (s *InfrastructureComponent) ByID(id uint) error { db := database.GetDB() err := db.Find(s, id).Error return err } -func (s *Simulator) update(updatedSimulator Simulator) error { +func (s *InfrastructureComponent) update(updatedIC InfrastructureComponent) error { db := database.GetDB() - err := db.Model(s).Updates(updatedSimulator).Error + err := db.Model(s).Updates(updatedIC).Error return err } -func (s *Simulator) delete() error { +func (s *InfrastructureComponent) delete() error { db := database.GetDB() - no_simulationmodels := db.Model(s).Association("SimulationModels").Count() + no_configs := db.Model(s).Association("ComponentConfigurations").Count() - if no_simulationmodels > 0 { - return fmt.Errorf("Simulator cannot be deleted as it is still used in SimulationModels (active or dangling)") + if no_configs > 0 { + return fmt.Errorf("Infrastructure Component cannot be deleted as it is still used in configurations (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 return err } -func (s *Simulator) getModels() ([]database.SimulationModel, int, error) { +func (s *InfrastructureComponent) getConfigs() ([]database.ComponentConfiguration, int, error) { db := database.GetDB() - var models []database.SimulationModel - err := db.Order("ID asc").Model(s).Related(&models, "SimulationModels").Error - return models, len(models), err + var configs []database.ComponentConfiguration + err := db.Order("ID asc").Model(s).Related(&configs, "ComponentConfigurations").Error + return configs, len(configs), err } diff --git a/routes/simulator/simulator_middleware.go b/routes/infrastructure-component/ic_middleware.go similarity index 77% rename from routes/simulator/simulator_middleware.go rename to routes/infrastructure-component/ic_middleware.go index 7c6c689..a5c7d5a 100644 --- a/routes/simulator/simulator_middleware.go +++ b/routes/infrastructure-component/ic_middleware.go @@ -1,4 +1,4 @@ -/** Simulator package, middleware. +/** InfrastructureComponent package, middleware. * * @author Sonja Happ * @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 * along with this program. If not, see . *********************************************************************************/ -package simulator +package infrastructure_component import ( "fmt" @@ -28,24 +28,24 @@ import ( "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) 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 } if hasID { - // Get the ID of the simulator from the context - simulatorID, err := helper.GetIDOfElement(c, "simulatorID", "path", -1) + // Get the ID of the infrastructure component from the context + ICID, err := helper.GetIDOfElement(c, "ICID", "path", -1) if err != nil { return false, s } - err = s.ByID(uint(simulatorID)) + err = s.ByID(uint(ICID)) if helper.DBError(c, err) { return false, s } diff --git a/routes/simulator/simulator_test.go b/routes/infrastructure-component/ic_test.go similarity index 54% rename from routes/simulator/simulator_test.go rename to routes/infrastructure-component/ic_test.go index 66198f0..58ff248 100644 --- a/routes/simulator/simulator_test.go +++ b/routes/infrastructure-component/ic_test.go @@ -1,4 +1,4 @@ -/** Simulator package, testing. +/** InfrastructureComponent package, testing. * * @author Sonja Happ * @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 * along with this program. If not, see . *********************************************************************************/ -package simulator +package infrastructure_component import ( "fmt" @@ -40,7 +40,7 @@ import ( var router *gin.Engine var db *gorm.DB -type SimulatorRequest struct { +type ICRequest struct { UUID string `json:"uuid,omitempty"` Host string `json:"host,omitempty"` Modeltype string `json:"modelType,omitempty"` @@ -65,12 +65,12 @@ func TestMain(m *testing.M) { user.RegisterAuthenticate(api.Group("/authenticate")) api.Use(user.Authentication(true)) - RegisterSimulatorEndpoints(api.Group("/simulators")) + RegisterICEndpoints(api.Group("/ic")) os.Exit(m.Run()) } -func TestAddSimulatorAsAdmin(t *testing.T) { +func TestAddICAsAdmin(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) @@ -83,61 +83,61 @@ func TestAddSimulatorAsAdmin(t *testing.T) { // try to POST with non JSON body // should result in bad request 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.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 - newMalformedSimulator := SimulatorRequest{ - UUID: database.SimulatorB.UUID, + newMalformedIC := ICRequest{ + UUID: database.ICB.UUID, } 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.Equalf(t, 422, code, "Response body: \n%v\n", resp) - // test POST simulators/ $newSimulator - newSimulator := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // test POST ic/ $newIC + newIC := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare POST's response with the newSimulator - err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator}) + // Compare POST's response with the newIC + err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC}) assert.NoError(t, err) - // Read newSimulator's ID from the response - newSimulatorID, err := helper.GetResponseID(resp) + // Read newIC's ID from the response + newICID, err := helper.GetResponseID(resp) assert.NoError(t, err) - // Get the newSimulator + // Get the newIC 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare GET's response with the newSimulator - err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator}) + // Compare GET's response with the newIC + err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC}) 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 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.Equalf(t, 404, code, "Response body: \n%v\n", resp) } -func TestAddSimulatorAsUser(t *testing.T) { +func TestAddICAsUser(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) @@ -147,24 +147,24 @@ func TestAddSimulatorAsUser(t *testing.T) { "/api/authenticate", "POST", helper.UserACredentials) assert.NoError(t, err) - // test POST simulators/ $newSimulator - newSimulator := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // test POST ic/ $newIC + newIC := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } // 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, - "/api/simulators", "POST", helper.KeyModels{"simulator": newSimulator}) + "/api/ic", "POST", helper.KeyModels{"ic": newIC}) assert.NoError(t, err) 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.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) @@ -174,59 +174,59 @@ func TestUpdateSimulatorAsAdmin(t *testing.T) { "/api/authenticate", "POST", helper.AdminCredentials) assert.NoError(t, err) - // test POST simulators/ $newSimulator - newSimulator := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // test POST ic/ $newIC + newIC := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare POST's response with the newSimulator - err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator}) + // Compare POST's response with the newIC + err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC}) assert.NoError(t, err) - // Read newSimulator's ID from the response - newSimulatorID, err := helper.GetResponseID(resp) + // Read newIC's ID from the response + newICID, err := helper.GetResponseID(resp) assert.NoError(t, err) // try to PUT with non JSON body // should result in bad request 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.Equalf(t, 400, code, "Response body: \n%v\n", resp) - // Test PUT simulators - newSimulator.Host = "ThisIsMyNewHost" + // Test PUT IC + newIC.Host = "ThisIsMyNewHost" 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare PUT's response with the updated newSimulator - err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator}) + // Compare PUT's response with the updated newIC + err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC}) assert.NoError(t, err) - // Get the updated newSimulator + // Get the updated newIC 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare GET's response with the updated newSimulator - err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator}) + // Compare GET's response with the updated newIC + err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC}) assert.NoError(t, err) } -func TestUpdateSimulatorAsUser(t *testing.T) { +func TestUpdateICAsUser(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) @@ -236,21 +236,21 @@ func TestUpdateSimulatorAsUser(t *testing.T) { "/api/authenticate", "POST", helper.AdminCredentials) assert.NoError(t, err) - // test POST simulators/ $newSimulator - newSimulator := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // test POST ic/ $newIC + newIC := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Read newSimulator's ID from the response - newSimulatorID, err := helper.GetResponseID(resp) + // Read newIC's ID from the response + newICID, err := helper.GetResponseID(resp) assert.NoError(t, err) // authenticate as user @@ -258,17 +258,17 @@ func TestUpdateSimulatorAsUser(t *testing.T) { "/api/authenticate", "POST", helper.UserACredentials) assert.NoError(t, err) - // Test PUT simulators + // Test PUT IC // This should fail with unprocessable entity status code 422 - newSimulator.Host = "ThisIsMyNewHost" + newIC.Host = "ThisIsMyNewHost" 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.Equalf(t, 422, code, "Response body: \n%v\n", resp) } -func TestDeleteSimulatorAsAdmin(t *testing.T) { +func TestDeleteICAsAdmin(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) @@ -278,47 +278,47 @@ func TestDeleteSimulatorAsAdmin(t *testing.T) { "/api/authenticate", "POST", helper.AdminCredentials) assert.NoError(t, err) - // test POST simulators/ $newSimulator - newSimulator := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // test POST ic/ $newIC + newIC := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Read newSimulator's ID from the response - newSimulatorID, err := helper.GetResponseID(resp) + // Read newIC's ID from the response + newICID, err := helper.GetResponseID(resp) 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, - "/api/simulators", "GET", nil) + "/api/ic", "GET", nil) assert.NoError(t, err) - // Delete the added newSimulator + // Delete the added newIC 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Compare DELETE's response with the newSimulator - err = helper.CompareResponse(resp, helper.KeyModels{"simulator": newSimulator}) + // Compare DELETE's response with the newIC + err = helper.CompareResponse(resp, helper.KeyModels{"ic": newIC}) 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, - "/api/simulators", "GET", nil) + "/api/ic", "GET", nil) assert.NoError(t, err) assert.Equal(t, finalNumber, initialNumber-1) } -func TestDeleteSimulatorAsUser(t *testing.T) { +func TestDeleteICAsUser(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) @@ -328,21 +328,21 @@ func TestDeleteSimulatorAsUser(t *testing.T) { "/api/authenticate", "POST", helper.AdminCredentials) assert.NoError(t, err) - // test POST simulators/ $newSimulator - newSimulator := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // test POST ic/ $newIC + newIC := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Read newSimulator's ID from the response - newSimulatorID, err := helper.GetResponseID(resp) + // Read newIC's ID from the response + newICID, err := helper.GetResponseID(resp) assert.NoError(t, err) // authenticate as user @@ -350,16 +350,16 @@ func TestDeleteSimulatorAsUser(t *testing.T) { "/api/authenticate", "POST", helper.UserACredentials) assert.NoError(t, err) - // Test DELETE simulators + // Test DELETE ICs // This should fail with unprocessable entity status code 422 - newSimulator.Host = "ThisIsMyNewHost" + newIC.Host = "ThisIsMyNewHost" 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.Equalf(t, 422, code, "Response body: \n%v\n", resp) } -func TestGetAllSimulators(t *testing.T) { +func TestGetAllICs(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) @@ -369,40 +369,40 @@ func TestGetAllSimulators(t *testing.T) { "/api/authenticate", "POST", helper.AdminCredentials) 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, - "/api/simulators", "GET", nil) + "/api/ic", "GET", nil) assert.NoError(t, err) - // test POST simulators/ $newSimulatorA - newSimulatorA := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // test POST ic/ $newICA + newICA := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // test POST simulators/ $newSimulatorB - newSimulatorB := SimulatorRequest{ - UUID: database.SimulatorB.UUID, - Host: database.SimulatorB.Host, - Modeltype: database.SimulatorB.Modeltype, - State: database.SimulatorB.State, - Properties: database.SimulatorB.Properties, + // test POST ic/ $newICB + newICB := ICRequest{ + UUID: database.ICB.UUID, + Host: database.ICB.Host, + Modeltype: database.ICB.Modeltype, + State: database.ICB.State, + Properties: database.ICB.Properties, } 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.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, - "/api/simulators", "GET", nil) + "/api/ic", "GET", nil) assert.NoError(t, err) assert.Equal(t, finalNumber, initialNumber+2) @@ -412,15 +412,15 @@ func TestGetAllSimulators(t *testing.T) { "/api/authenticate", "POST", helper.UserACredentials) 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, - "/api/simulators", "GET", nil) + "/api/ic", "GET", nil) assert.NoError(t, err) assert.Equal(t, finalNumber2, initialNumber+2) } -func TestGetSimulationModelsOfSimulator(t *testing.T) { +func TestGetConfigsOfIC(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) @@ -430,50 +430,50 @@ func TestGetSimulationModelsOfSimulator(t *testing.T) { "/api/authenticate", "POST", helper.AdminCredentials) assert.NoError(t, err) - // test POST simulators/ $newSimulatorA - newSimulatorA := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // test POST ic/ $newICA + newICA := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } 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.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Read newSimulator's ID from the response - newSimulatorID, err := helper.GetResponseID(resp) + // Read newIC's ID from the response + newICID, err := helper.GetResponseID(resp) assert.NoError(t, err) - // test GET simulators/ID/models - // TODO how to properly test this without using simulation model endpoints? - numberOfModels, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/simulators/%v/models", newSimulatorID), "GET", nil) + // test GET ic/ID/confis + // TODO how to properly test this without using component configuration endpoints? + numberOfConfigs, err := helper.LengthOfResponse(router, token, + fmt.Sprintf("/api/ic/%v/configs", newICID), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - assert.Equal(t, 0, numberOfModels) + assert.Equal(t, 0, numberOfConfigs) // authenticate as normal user token, err = helper.AuthenticateForTest(router, "/api/authenticate", "POST", helper.UserACredentials) assert.NoError(t, err) - // test GET simulators/ID/models - // TODO how to properly test this without using simulation model endpoints? - numberOfModels, err = helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/simulators/%v/models", newSimulatorID), "GET", nil) + // test GET ic/ID/configs + // TODO how to properly test this without using component configuration endpoints? + numberOfConfigs, err = helper.LengthOfResponse(router, token, + fmt.Sprintf("/api/ic/%v/configs", newICID), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - assert.Equal(t, 0, numberOfModels) + assert.Equal(t, 0, numberOfConfigs) - // Try to get models of simulator that does not exist + // Try to get configs of IC that does not exist // should result in not found code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/simulators/%v/models", newSimulatorID+1), "GET", nil) + fmt.Sprintf("/api/ic/%v/configs", newICID+1), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 404, code, "Response body: \n%v\n", resp) } diff --git a/routes/simulator/simulator_validators.go b/routes/infrastructure-component/ic_validators.go similarity index 60% rename from routes/simulator/simulator_validators.go rename to routes/infrastructure-component/ic_validators.go index df3fd1f..c901eba 100644 --- a/routes/simulator/simulator_validators.go +++ b/routes/infrastructure-component/ic_validators.go @@ -1,4 +1,4 @@ -/** Simulator package, validators. +/** InfrastructureComponent package, validators. * * @author Sonja Happ * @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 * along with this program. If not, see . *********************************************************************************/ -package simulator +package infrastructure_component import ( "encoding/json" @@ -30,7 +30,7 @@ import ( var validate *validator.Validate -type validNewSimulator struct { +type validNewIC struct { UUID string `form:"UUID" validate:"required"` Host string `form:"Host" validate:"required"` Modeltype string `form:"Modeltype" validate:"required"` @@ -38,7 +38,7 @@ type validNewSimulator struct { State string `form:"State"` } -type validUpdatedSimulator struct { +type validUpdatedIC struct { UUID string `form:"UUID" validate:"omitempty"` Host string `form:"Host" validate:"omitempty"` Modeltype string `form:"Modeltype" validate:"omitempty"` @@ -46,68 +46,68 @@ type validUpdatedSimulator struct { State string `form:"State" validate:"omitempty"` } -type addSimulatorRequest struct { - Simulator validNewSimulator `json:"simulator"` +type addICRequest struct { + InfrastructureComponent validNewIC `json:"ic"` } -type updateSimulatorRequest struct { - Simulator validUpdatedSimulator `json:"simulator"` +type updateICRequest struct { + InfrastructureComponent validUpdatedIC `json:"ic"` } -func (r *addSimulatorRequest) validate() error { +func (r *addICRequest) validate() error { validate = validator.New() errs := validate.Struct(r) return errs } -func (r *validUpdatedSimulator) validate() error { +func (r *validUpdatedIC) validate() error { validate = validator.New() errs := validate.Struct(r) return errs } -func (r *addSimulatorRequest) createSimulator() Simulator { - var s Simulator +func (r *addICRequest) createIC() InfrastructureComponent { + var s InfrastructureComponent - s.UUID = r.Simulator.UUID - s.Host = r.Simulator.Host - s.Modeltype = r.Simulator.Modeltype - s.Properties = r.Simulator.Properties - if r.Simulator.State != "" { - s.State = r.Simulator.State + s.UUID = r.InfrastructureComponent.UUID + s.Host = r.InfrastructureComponent.Host + s.Modeltype = r.InfrastructureComponent.Modeltype + s.Properties = r.InfrastructureComponent.Properties + if r.InfrastructureComponent.State != "" { + s.State = r.InfrastructureComponent.State } return s } -func (r *updateSimulatorRequest) updatedSimulator(oldSimulator Simulator) Simulator { - // Use the old Simulator as a basis for the updated Simulator `s` - s := oldSimulator +func (r *updateICRequest) updatedIC(oldIC InfrastructureComponent) InfrastructureComponent { + // Use the old InfrastructureComponent as a basis for the updated InfrastructureComponent `s` + s := oldIC - if r.Simulator.UUID != "" { - s.UUID = r.Simulator.UUID + if r.InfrastructureComponent.UUID != "" { + s.UUID = r.InfrastructureComponent.UUID } - if r.Simulator.Host != "" { - s.Host = r.Simulator.Host + if r.InfrastructureComponent.Host != "" { + s.Host = r.InfrastructureComponent.Host } - if r.Simulator.Modeltype != "" { - s.Modeltype = r.Simulator.Modeltype + if r.InfrastructureComponent.Modeltype != "" { + s.Modeltype = r.InfrastructureComponent.Modeltype } - if r.Simulator.State != "" { - s.State = r.Simulator.State + if r.InfrastructureComponent.State != "" { + s.State = r.InfrastructureComponent.State } // only update props if not empty var emptyJson postgres.Jsonb // Serialize empty json and params emptyJson_ser, _ := json.Marshal(emptyJson) - startParams_ser, _ := json.Marshal(r.Simulator.Properties) + startParams_ser, _ := json.Marshal(r.InfrastructureComponent.Properties) opts := jsondiff.DefaultConsoleOptions() diff, _ := jsondiff.Compare(emptyJson_ser, startParams_ser, &opts) if diff.String() != "FullMatch" { - s.Properties = r.Simulator.Properties + s.Properties = r.InfrastructureComponent.Properties } return s diff --git a/routes/metrics/metrics_endpoint.go b/routes/metrics/metrics_endpoint.go index 9bd0202..4d37606 100644 --- a/routes/metrics/metrics_endpoint.go +++ b/routes/metrics/metrics_endpoint.go @@ -30,17 +30,17 @@ import ( ) var ( - SimulatorCounter = prometheus.NewCounter( + ICCounter = prometheus.NewCounter( prometheus.CounterOpts{ - Name: "simulators", - Help: "A counter for the total number of simulators", + Name: "infrastructure_components", + Help: "A counter for the total number of infrastructure_components", }, ) - SimulationModelCounter = prometheus.NewCounter( + ComponentConfigurationCounter = prometheus.NewCounter( prometheus.CounterOpts{ - Name: "simulation_models", - Help: "A counter for the total number of simulation models", + Name: "component_configurations", + Help: "A counter for the total number of component configurations", }, ) @@ -102,8 +102,8 @@ func RegisterMetricsEndpoint(rg *gin.RouterGroup) { // Register metrics prometheus.MustRegister( - SimulatorCounter, - SimulationModelCounter, + ICCounter, + ComponentConfigurationCounter, FileCounter, ScenarioCounter, UserCounter, @@ -112,17 +112,17 @@ func RegisterMetricsEndpoint(rg *gin.RouterGroup) { } func InitCounters(db *gorm.DB) { - var simulators, simulation_models, files, scenarios, users, dashboards float64 + var infrastructure_components, component_configurations, files, scenarios, users, dashboards float64 - db.Table("simulators").Count(&simulators) - db.Table("simulation_models").Count(&simulation_models) + db.Table("infrastructure_components").Count(&infrastructure_components) + db.Table("component_configurations").Count(&component_configurations) db.Table("files").Count(&files) db.Table("scenarios").Count(&scenarios) db.Table("users").Count(&users) db.Table("dashboards").Count(&dashboards) - SimulatorCounter.Add(simulators) - SimulationModelCounter.Add(simulation_models) + ICCounter.Add(infrastructure_components) + ComponentConfigurationCounter.Add(component_configurations) FileCounter.Add(files) ScenarioCounter.Add(scenarios) UserCounter.Add(users) diff --git a/routes/scenario/scenario_endpoints.go b/routes/scenario/scenario_endpoints.go index bdba49e..bcfd940 100644 --- a/routes/scenario/scenario_endpoints.go +++ b/routes/scenario/scenario_endpoints.go @@ -82,7 +82,7 @@ func getScenarios(c *gin.Context) { return } } - // TODO return list of simulationModelIDs, dashboardIDs and userIDs per scenario + // TODO return list of configIDs, dashboardIDs and userIDs per scenario c.JSON(http.StatusOK, gin.H{"scenarios": scenarios}) } @@ -211,7 +211,7 @@ func getScenario(c *gin.Context) { return } - // TODO return list of simulationModelIDs, dashboardIDs and userIDs per scenario + // TODO return list of configIDs, dashboardIDs and userIDs per scenario c.JSON(http.StatusOK, gin.H{"scenario": so.Scenario}) } diff --git a/routes/signal/signal_endpoints.go b/routes/signal/signal_endpoints.go index d20943e..4c21705 100644 --- a/routes/signal/signal_endpoints.go +++ b/routes/signal/signal_endpoints.go @@ -28,7 +28,7 @@ import ( "github.com/gin-gonic/gin" "git.rwth-aachen.de/acs/public/villas/web-backend-go/database" - "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel" + "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration" ) func RegisterSignalEndpoints(r *gin.RouterGroup) { @@ -45,8 +45,8 @@ func RegisterSignalEndpoints(r *gin.RouterGroup) { // @Produce json // @Tags signals // @Param direction query string true "Direction of signal (in or out)" -// @Param modelID query string true "Model ID of signals to be obtained" -// @Success 200 {object} docs.ResponseSignals "Signals which belong to simulation model" +// @Param configID query string true "Config ID of signals to be obtained" +// @Success 200 {object} docs.ResponseSignals "Signals which belong to component configuration" // @Failure 404 {object} docs.ResponseError "Not found" // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" @@ -54,7 +54,7 @@ func RegisterSignalEndpoints(r *gin.RouterGroup) { // @Router /signals [get] func getSignals(c *gin.Context) { - ok, m := simulationmodel.CheckPermissions(c, database.Read, "query", -1) + ok, m := component_configuration.CheckPermissions(c, database.Read, "query", -1) if !ok { return } @@ -80,7 +80,7 @@ func getSignals(c *gin.Context) { } // AddSignal godoc -// @Summary Add a signal to a signal mapping of a model +// @Summary Add a signal to a signal mapping of a component configuration // @ID AddSignal // @Accept json // @Produce json @@ -91,7 +91,7 @@ func getSignals(c *gin.Context) { // @Failure 422 {object} docs.ResponseError "Unprocessable entity" // @Failure 500 {object} docs.ResponseError "Internal server error" // @Param Authorization header string true "Authorization token" -// @Param inputSignal body signal.addSignalRequest true "A signal to be added to the model incl. direction and model ID to which signal shall be added" +// @Param inputSignal body signal.addSignalRequest true "A signal to be added to the component configuration incl. direction and config ID to which signal shall be added" // @Router /signals [post] func addSignal(c *gin.Context) { @@ -110,13 +110,13 @@ func addSignal(c *gin.Context) { // Create the new signal from the request newSignal := req.createSignal() - ok, _ := simulationmodel.CheckPermissions(c, database.Update, "body", int(newSignal.SimulationModelID)) + ok, _ := component_configuration.CheckPermissions(c, database.Update, "body", int(newSignal.ConfigID)) if !ok { return } - // Add signal to model - err := newSignal.addToSimulationModel() + // Add signal to component configuration + err := newSignal.addToConfig() if !helper.DBError(c, err) { c.JSON(http.StatusOK, gin.H{"signal": newSignal.Signal}) } diff --git a/routes/signal/signal_methods.go b/routes/signal/signal_methods.go index 7619e93..9dbb8cc 100644 --- a/routes/signal/signal_methods.go +++ b/routes/signal/signal_methods.go @@ -23,7 +23,7 @@ package signal import ( "git.rwth-aachen.de/acs/public/villas/web-backend-go/database" - "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel" + "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration" ) type Signal struct { @@ -45,10 +45,10 @@ func (s *Signal) byID(id uint) error { return nil } -func (s *Signal) addToSimulationModel() error { +func (s *Signal) addToConfig() error { db := database.GetDB() - var m simulationmodel.SimulationModel - err := m.ByID(s.SimulationModelID) + var m component_configuration.ComponentConfiguration + err := m.ByID(s.ConfigID) if err != nil { return err } @@ -59,7 +59,7 @@ func (s *Signal) addToSimulationModel() error { return err } - // associate signal with simulation model in correct direction + // associate signal with component configuration in correct direction if s.Direction == "in" { err = db.Model(&m).Association("InputMapping").Append(s).Error if err != nil { @@ -99,13 +99,13 @@ func (s *Signal) update(modifiedSignal Signal) error { func (s *Signal) delete() error { db := database.GetDB() - var m simulationmodel.SimulationModel - err := m.ByID(s.SimulationModelID) + var m component_configuration.ComponentConfiguration + err := m.ByID(s.ConfigID) if err != nil { return err } - // remove association between Signal and SimulationModel + // remove association between Signal and ComponentConfiguration // Signal itself is not deleted from DB, it remains as "dangling" if s.Direction == "in" { err = db.Model(&m).Association("InputMapping").Delete(s).Error diff --git a/routes/signal/signal_middleware.go b/routes/signal/signal_middleware.go index c22be42..8f80b8d 100644 --- a/routes/signal/signal_middleware.go +++ b/routes/signal/signal_middleware.go @@ -27,7 +27,7 @@ import ( "github.com/gin-gonic/gin" "git.rwth-aachen.de/acs/public/villas/web-backend-go/database" - "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/simulationmodel" + "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration" ) func checkPermissions(c *gin.Context, operation database.CRUD) (bool, Signal) { @@ -50,7 +50,7 @@ func checkPermissions(c *gin.Context, operation database.CRUD) (bool, Signal) { return false, sig } - ok, _ := simulationmodel.CheckPermissions(c, operation, "body", int(sig.SimulationModelID)) + ok, _ := component_configuration.CheckPermissions(c, operation, "body", int(sig.ConfigID)) if !ok { return false, sig } diff --git a/routes/signal/signal_test.go b/routes/signal/signal_test.go index de24773..3670e7d 100644 --- a/routes/signal/signal_test.go +++ b/routes/signal/signal_test.go @@ -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/database" "git.rwth-aachen.de/acs/public/villas/web-backend-go/helper" + "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/component-configuration" + "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/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" "github.com/gin-gonic/gin" "github.com/jinzhu/gorm" @@ -42,21 +42,21 @@ var router *gin.Engine var db *gorm.DB type SignalRequest struct { - Name string `json:"name,omitempty"` - Unit string `json:"unit,omitempty"` - Index uint `json:"index,omitempty"` - Direction string `json:"direction,omitempty"` - SimulationModelID uint `json:"simulationModelID,omitempty"` + Name string `json:"name,omitempty"` + Unit string `json:"unit,omitempty"` + Index uint `json:"index,omitempty"` + Direction string `json:"direction,omitempty"` + ConfigID uint `json:"configID,omitempty"` } -type SimulationModelRequest struct { +type ConfigRequest struct { Name string `json:"name,omitempty"` ScenarioID uint `json:"scenarioID,omitempty"` - SimulatorID uint `json:"simulatorID,omitempty"` + ICID uint `json:"icID,omitempty"` StartParameters postgres.Jsonb `json:"startParameters,omitempty"` } -type SimulatorRequest struct { +type ICRequest struct { UUID string `json:"uuid,omitempty"` Host string `json:"host,omitempty"` Modeltype string `json:"modelType,omitempty"` @@ -70,25 +70,25 @@ type ScenarioRequest struct { StartParameters postgres.Jsonb `json:"startParameters,omitempty"` } -func addScenarioAndSimulatorAndSimulationModel() (scenarioID uint, simulatorID uint, simulationModelID uint) { +func addScenarioAndICAndConfig() (scenarioID uint, ICID uint, configID uint) { // authenticate as admin token, _ := helper.AuthenticateForTest(router, "/api/authenticate", "POST", helper.AdminCredentials) - // POST $newSimulatorA - newSimulatorA := SimulatorRequest{ - UUID: database.SimulatorA.UUID, - Host: database.SimulatorA.Host, - Modeltype: database.SimulatorA.Modeltype, - State: database.SimulatorA.State, - Properties: database.SimulatorA.Properties, + // POST $newICA + newICA := ICRequest{ + UUID: database.ICA.UUID, + Host: database.ICA.Host, + Modeltype: database.ICA.Modeltype, + State: database.ICA.State, + Properties: database.ICA.Properties, } _, 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 - newSimulatorID, _ := helper.GetResponseID(resp) + // Read newIC's ID from the response + newICID, _ := helper.GetResponseID(resp) // authenticate as normal user token, _ = helper.AuthenticateForTest(router, @@ -106,24 +106,24 @@ func addScenarioAndSimulatorAndSimulationModel() (scenarioID uint, simulatorID u // Read newScenario's ID from the response newScenarioID, _ := helper.GetResponseID(resp) - // test POST models/ $newSimulationModel - newSimulationModel := SimulationModelRequest{ - Name: database.SimulationModelA.Name, + // test POST newConfig + newConfig := ConfigRequest{ + Name: database.ConfigA.Name, ScenarioID: uint(newScenarioID), - SimulatorID: uint(newSimulatorID), - StartParameters: database.SimulationModelA.StartParameters, + ICID: uint(newICID), + StartParameters: database.ConfigA.StartParameters, } _, resp, _ = helper.TestEndpoint(router, token, - "/api/models", "POST", helper.KeyModels{"simulationModel": newSimulationModel}) + "/api/configs", "POST", helper.KeyModels{"config": newConfig}) - // Read newSimulationModel's ID from the response - newSimulationModelID, _ := helper.GetResponseID(resp) + // Read newConfig's ID from the response + newConfigID, _ := helper.GetResponseID(resp) // add the guest user to the new scenario _, resp, _ = helper.TestEndpoint(router, token, 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(newConfigID) } func TestMain(m *testing.M) { @@ -143,15 +143,15 @@ func TestMain(m *testing.M) { user.RegisterAuthenticate(api.Group("/authenticate")) api.Use(user.Authentication(true)) - // simulationmodel endpoints required here to first add a simulation to the DB - // that can be associated with a new signal model - simulationmodel.RegisterSimulationModelEndpoints(api.Group("/models")) + // component-configuration endpoints required here to first add a component config to the DB + // that can be associated with a new signal + component_configuration.RegisterComponentConfigurationEndpoints(api.Group("/configs")) // 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 component config scenario.RegisterScenarioEndpoints(api.Group("/scenarios")) - // simulator endpoints required here to first add a simulator to the DB - // that can be associated with a new simulation model - simulator.RegisterSimulatorEndpoints(api.Group("/simulators")) + // IC endpoints required here to first add a IC to the DB + // that can be associated with a new component config + infrastructure_component.RegisterICEndpoints(api.Group("/ic")) RegisterSignalEndpoints(api.Group("/signals")) os.Exit(m.Run()) @@ -163,9 +163,9 @@ func TestAddSignal(t *testing.T) { assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) // 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 - _, _, simulationModelID := addScenarioAndSimulatorAndSimulationModel() + _, _, configID := addScenarioAndICAndConfig() // authenticate as normal user token, err := helper.AuthenticateForTest(router, @@ -173,11 +173,11 @@ func TestAddSignal(t *testing.T) { assert.NoError(t, err) newSignal := SignalRequest{ - Name: database.InSignalA.Name, - Unit: database.InSignalA.Unit, - Direction: database.InSignalA.Direction, - Index: 1, - SimulationModelID: simulationModelID, + Name: database.InSignalA.Name, + Unit: database.InSignalA.Unit, + Direction: database.InSignalA.Direction, + Index: 1, + ConfigID: configID, } // authenticate as normal userB who has no access to new scenario @@ -185,7 +185,7 @@ func TestAddSignal(t *testing.T) { "/api/authenticate", "POST", helper.UserBCredentials) assert.NoError(t, err) - // try to POST to simulation model without access + // try to POST to component config without access // should result in unprocessable entity code, resp, err := helper.TestEndpoint(router, token, "/api/signals", "POST", helper.KeyModels{"signal": newSignal}) @@ -258,9 +258,9 @@ func TestUpdateSignal(t *testing.T) { assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) // 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 - _, _, simulationModelID := addScenarioAndSimulatorAndSimulationModel() + _, _, configID := addScenarioAndICAndConfig() // authenticate as normal user token, err := helper.AuthenticateForTest(router, @@ -269,11 +269,11 @@ func TestUpdateSignal(t *testing.T) { // test POST signals/ $newSignal newSignal := SignalRequest{ - Name: database.InSignalA.Name, - Unit: database.InSignalA.Unit, - Direction: database.InSignalA.Direction, - Index: 1, - SimulationModelID: simulationModelID, + Name: database.InSignalA.Name, + Unit: database.InSignalA.Unit, + Direction: database.InSignalA.Direction, + Index: 1, + ConfigID: configID, } code, resp, err := helper.TestEndpoint(router, token, "/api/signals", "POST", helper.KeyModels{"signal": newSignal}) @@ -360,9 +360,9 @@ func TestDeleteSignal(t *testing.T) { assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) // 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 - _, _, simulationModelID := addScenarioAndSimulatorAndSimulationModel() + _, _, configID := addScenarioAndICAndConfig() // authenticate as normal user token, err := helper.AuthenticateForTest(router, @@ -371,11 +371,11 @@ func TestDeleteSignal(t *testing.T) { // test POST signals/ $newSignal newSignal := SignalRequest{ - Name: database.InSignalA.Name, - Unit: database.InSignalA.Unit, - Direction: database.InSignalA.Direction, - Index: 1, - SimulationModelID: simulationModelID, + Name: database.InSignalA.Name, + Unit: database.InSignalA.Unit, + Direction: database.InSignalA.Direction, + Index: 1, + ConfigID: configID, } code, resp, err := helper.TestEndpoint(router, token, "/api/signals", "POST", helper.KeyModels{"signal": newSignal}) @@ -403,18 +403,18 @@ func TestDeleteSignal(t *testing.T) { "/api/authenticate", "POST", helper.UserACredentials) assert.NoError(t, err) - // Count the number of all the input signals returned for simulation model + // Count the number of all the input signals returned for component config initialNumber, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/signals?modelID=%v&direction=in", simulationModelID), "GET", nil) + fmt.Sprintf("/api/signals?configID=%v&direction=in", configID), "GET", nil) assert.NoError(t, err) // add an output signal to make sure that counting of input signals works newSignalout := SignalRequest{ - Name: database.OutSignalA.Name, - Unit: database.OutSignalA.Unit, - Direction: database.OutSignalA.Direction, - Index: 1, - SimulationModelID: simulationModelID, + Name: database.OutSignalA.Name, + Unit: database.OutSignalA.Unit, + Direction: database.OutSignalA.Direction, + Index: 1, + ConfigID: configID, } code, resp, err = helper.TestEndpoint(router, token, "/api/signals", "POST", helper.KeyModels{"signal": newSignalout}) @@ -435,9 +435,9 @@ func TestDeleteSignal(t *testing.T) { err = helper.CompareResponse(resp, helper.KeyModels{"signal": newSignal}) assert.NoError(t, err) - // Again count the number of all the input signals returned for simulation model + // Again count the number of all the input signals returned for component config finalNumber, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/signals?modelID=%v&direction=in", simulationModelID), "GET", nil) + fmt.Sprintf("/api/signals?configID=%v&direction=in", configID), "GET", nil) assert.NoError(t, err) assert.Equal(t, initialNumber-1, finalNumber) @@ -449,33 +449,33 @@ func TestDeleteSignal(t *testing.T) { assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) } -func TestGetAllInputSignalsOfSimulationModel(t *testing.T) { +func TestGetAllInputSignalsOfConfig(t *testing.T) { database.DropTables(db) database.MigrateModels(db) assert.NoError(t, database.DBAddAdminAndUserAndGuest(db)) // 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 - _, _, simulationModelID := addScenarioAndSimulatorAndSimulationModel() + _, _, configID := addScenarioAndICAndConfig() // authenticate as normal user token, err := helper.AuthenticateForTest(router, "/api/authenticate", "POST", helper.UserACredentials) assert.NoError(t, err) - // Count the number of all the input signals returned for simulation model + // Count the number of all the input signals returned for component config initialNumber, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/signals?modelID=%v&direction=in", simulationModelID), "GET", nil) + fmt.Sprintf("/api/signals?configID=%v&direction=in", configID), "GET", nil) assert.NoError(t, err) // test POST signals/ $newSignal newSignalA := SignalRequest{ - Name: database.InSignalA.Name, - Unit: database.InSignalA.Unit, - Direction: database.InSignalA.Direction, - Index: 1, - SimulationModelID: simulationModelID, + Name: database.InSignalA.Name, + Unit: database.InSignalA.Unit, + Direction: database.InSignalA.Direction, + Index: 1, + ConfigID: configID, } code, resp, err := helper.TestEndpoint(router, token, "/api/signals", "POST", helper.KeyModels{"signal": newSignalA}) @@ -484,11 +484,11 @@ func TestGetAllInputSignalsOfSimulationModel(t *testing.T) { // add a second input signal newSignalB := SignalRequest{ - Name: database.InSignalB.Name, - Unit: database.InSignalB.Unit, - Direction: database.InSignalB.Direction, - Index: 2, - SimulationModelID: simulationModelID, + Name: database.InSignalB.Name, + Unit: database.InSignalB.Unit, + Direction: database.InSignalB.Direction, + Index: 2, + ConfigID: configID, } code, resp, err = helper.TestEndpoint(router, token, "/api/signals", "POST", helper.KeyModels{"signal": newSignalB}) @@ -497,11 +497,11 @@ func TestGetAllInputSignalsOfSimulationModel(t *testing.T) { // add an output signal newSignalAout := SignalRequest{ - Name: database.OutSignalA.Name, - Unit: database.OutSignalA.Unit, - Direction: database.OutSignalA.Direction, - Index: 1, - SimulationModelID: simulationModelID, + Name: database.OutSignalA.Name, + Unit: database.OutSignalA.Unit, + Direction: database.OutSignalA.Direction, + Index: 1, + ConfigID: configID, } code, resp, err = helper.TestEndpoint(router, token, "/api/signals", "POST", helper.KeyModels{"signal": newSignalAout}) @@ -510,34 +510,34 @@ func TestGetAllInputSignalsOfSimulationModel(t *testing.T) { // add a second output signal newSignalBout := SignalRequest{ - Name: database.OutSignalB.Name, - Unit: database.OutSignalB.Unit, - Direction: database.OutSignalB.Direction, - Index: 1, - SimulationModelID: simulationModelID, + Name: database.OutSignalB.Name, + Unit: database.OutSignalB.Unit, + Direction: database.OutSignalB.Direction, + Index: 1, + ConfigID: configID, } code, resp, err = helper.TestEndpoint(router, token, "/api/signals", "POST", helper.KeyModels{"signal": newSignalBout}) assert.NoError(t, err) assert.Equalf(t, 200, code, "Response body: \n%v\n", resp) - // Again count the number of all the input signals returned for simulation model + // Again count the number of all the input signals returned for component config finalNumber, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/signals?modelID=%v&direction=in", simulationModelID), "GET", nil) + fmt.Sprintf("/api/signals?configID=%v&direction=in", configID), "GET", nil) assert.NoError(t, err) assert.Equal(t, initialNumber+2, finalNumber) // Get the number of output signals outputNumber, err := helper.LengthOfResponse(router, token, - fmt.Sprintf("/api/signals?modelID=%v&direction=out", simulationModelID), "GET", nil) + fmt.Sprintf("/api/signals?configID=%v&direction=out", configID), "GET", nil) assert.NoError(t, err) assert.Equal(t, initialNumber+2, outputNumber) // Try to get all signals for non-existing direction // should result in bad request code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/signals?modelID=%v&direction=thisiswrong", simulationModelID), "GET", nil) + fmt.Sprintf("/api/signals?configID=%v&direction=thisiswrong", configID), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 400, code, "Response body: \n%v\n", resp) @@ -549,7 +549,7 @@ func TestGetAllInputSignalsOfSimulationModel(t *testing.T) { // try to get all input signals // should result in unprocessable entity code, resp, err = helper.TestEndpoint(router, token, - fmt.Sprintf("/api/signals?modelID=%v&direction=in", simulationModelID), "GET", nil) + fmt.Sprintf("/api/signals?configID=%v&direction=in", configID), "GET", nil) assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) diff --git a/routes/signal/signal_validators.go b/routes/signal/signal_validators.go index fe9a8dc..8972ae5 100644 --- a/routes/signal/signal_validators.go +++ b/routes/signal/signal_validators.go @@ -28,11 +28,11 @@ import ( var validate *validator.Validate type validNewSignal struct { - Name string `form:"Name" validate:"required"` - Unit string `form:"unit" validate:"omitempty"` - Index uint `form:"index" validate:"required"` - Direction string `form:"direction" validate:"required,oneof=in out"` - SimulationModelID uint `form:"simulationModelID" validate:"required"` + Name string `form:"Name" validate:"required"` + Unit string `form:"unit" validate:"omitempty"` + Index uint `form:"index" validate:"required"` + Direction string `form:"direction" validate:"required,oneof=in out"` + ConfigID uint `form:"configID" validate:"required"` } type validUpdatedSignal struct { @@ -68,7 +68,7 @@ func (r *addSignalRequest) createSignal() Signal { s.Unit = r.Signal.Unit s.Index = r.Signal.Index s.Direction = r.Signal.Direction - s.SimulationModelID = r.Signal.SimulationModelID + s.ConfigID = r.Signal.ConfigID return s } diff --git a/routes/simulationmodel/simulationmodel_validators.go b/routes/simulationmodel/simulationmodel_validators.go deleted file mode 100644 index d8afc4c..0000000 --- a/routes/simulationmodel/simulationmodel_validators.go +++ /dev/null @@ -1,108 +0,0 @@ -/** Simulationmodel package, validators. -* -* @author Sonja Happ -* @copyright 2014-2019, Institute for Automation of Complex Power Systems, EONERC -* @license GNU General Public License (version 3) -* -* VILLASweb-backend-go -* -* This program is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* any later version. -* -* This program is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with this program. If not, see . -*********************************************************************************/ -package simulationmodel - -import ( - "encoding/json" - "github.com/jinzhu/gorm/dialects/postgres" - "github.com/nsf/jsondiff" - "gopkg.in/go-playground/validator.v9" -) - -var validate *validator.Validate - -type validNewSimulationModel struct { - Name string `form:"Name" validate:"required"` - ScenarioID uint `form:"ScenarioID" validate:"required"` - SimulatorID uint `form:"SimulatorID" validate:"required"` - StartParameters postgres.Jsonb `form:"StartParameters" validate:"required"` - SelectedModelFileID uint `form:"SelectedModelFilID" validate:"omitempty"` -} - -type validUpdatedSimulationModel struct { - Name string `form:"Name" validate:"omitempty"` - SimulatorID uint `form:"SimulatorID" validate:"omitempty"` - StartParameters postgres.Jsonb `form:"StartParameters" validate:"omitempty"` - SelectedModelFileID uint `form:"SelectedModelFileID" validate:"omitempty"` -} - -type addSimulationModelRequest struct { - SimulationModel validNewSimulationModel `json:"simulationModel"` -} - -type updateSimulationModelRequest struct { - SimulationModel validUpdatedSimulationModel `json:"simulationModel"` -} - -func (r *addSimulationModelRequest) validate() error { - validate = validator.New() - errs := validate.Struct(r) - return errs -} - -func (r *validUpdatedSimulationModel) validate() error { - validate = validator.New() - errs := validate.Struct(r) - return errs -} - -func (r *addSimulationModelRequest) createSimulationModel() SimulationModel { - var s SimulationModel - - s.Name = r.SimulationModel.Name - s.ScenarioID = r.SimulationModel.ScenarioID - s.SimulatorID = r.SimulationModel.SimulatorID - s.StartParameters = r.SimulationModel.StartParameters - s.SelectedModelFileID = r.SimulationModel.SelectedModelFileID - - return s -} - -func (r *updateSimulationModelRequest) updatedSimulationModel(oldSimulationModel SimulationModel) SimulationModel { - // Use the old SimulationModel as a basis for the updated Simulation model - s := oldSimulationModel - - if r.SimulationModel.Name != "" { - s.Name = r.SimulationModel.Name - } - - if r.SimulationModel.SimulatorID != 0 { - s.SimulatorID = r.SimulationModel.SimulatorID - } - - if r.SimulationModel.SelectedModelFileID != 0 { - s.SelectedModelFileID = r.SimulationModel.SelectedModelFileID - } - - // only update Params if not empty - var emptyJson postgres.Jsonb - // Serialize empty json and params - emptyJson_ser, _ := json.Marshal(emptyJson) - startParams_ser, _ := json.Marshal(r.SimulationModel.StartParameters) - opts := jsondiff.DefaultConsoleOptions() - diff, _ := jsondiff.Compare(emptyJson_ser, startParams_ser, &opts) - if diff.String() != "FullMatch" { - s.StartParameters = r.SimulationModel.StartParameters - } - - return s -} diff --git a/routes/widget/widget_test.go b/routes/widget/widget_test.go index 571d0db..2bfc280 100644 --- a/routes/widget/widget_test.go +++ b/routes/widget/widget_test.go @@ -289,7 +289,7 @@ func TestUpdateWidget(t *testing.T) { assert.NoError(t, err) assert.Equalf(t, 422, code, "Response body: \n%v\n", resp) - // authenticate as guest user who has access to simulation model + // authenticate as guest user who has access to scenario token, err = helper.AuthenticateForTest(router, "/api/authenticate", "POST", helper.GuestCredentials) assert.NoError(t, err) diff --git a/start.go b/start.go index f091d98..705ecc4 100644 --- a/start.go +++ b/start.go @@ -34,13 +34,13 @@ import ( "git.rwth-aachen.de/acs/public/villas/web-backend-go/configuration" "git.rwth-aachen.de/acs/public/villas/web-backend-go/database" 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/component-configuration" "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/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/scenario" "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/simulator" "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/user" "git.rwth-aachen.de/acs/public/villas/web-backend-go/routes/widget" ) @@ -114,13 +114,13 @@ func main() { api.Use(user.Authentication(true)) scenario.RegisterScenarioEndpoints(api.Group("/scenarios")) - simulationmodel.RegisterSimulationModelEndpoints(api.Group("/models")) + component_configuration.RegisterComponentConfigurationEndpoints(api.Group("/configs")) signal.RegisterSignalEndpoints(api.Group("/signals")) dashboard.RegisterDashboardEndpoints(api.Group("/dashboards")) widget.RegisterWidgetEndpoints(api.Group("/widgets")) file.RegisterFileEndpoints(api.Group("/files")) user.RegisterUserEndpoints(api.Group("/users")) - simulator.RegisterSimulatorEndpoints(api.Group("/simulators")) + infrastructure_component.RegisterICEndpoints(api.Group("/ic")) r.GET("swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) @@ -133,10 +133,10 @@ func main() { log.Panic(err) } - // register simulator action endpoint only if AMQP client is used - amqp.RegisterAMQPEndpoint(api.Group("/simulators")) + // register IC action endpoint only if AMQP client is used + 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) go func() {