Commit 1f0455d9 authored by Sonja Happ's avatar Sonja Happ
Browse files

Parameter cleanup in IC model

parent 33eab641
......@@ -28,7 +28,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/google/uuid"
"github.com/jinzhu/gorm"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/streadway/amqp"
"log"
"time"
......@@ -54,14 +53,16 @@ type Action struct {
type ICUpdate struct {
State *string `json:"state"`
Properties struct {
UUID string `json:"uuid"`
Name *string `json:"name"`
Category *string `json:"category"`
Type *string `json:"type"`
Location *string `json:"location"`
WS_url *string `json:"ws_url"`
API_url *string `json:"api_url"`
UUID string `json:"uuid"`
Name *string `json:"name"`
Category *string `json:"category"`
Type *string `json:"type"`
Location *string `json:"location"`
WS_url *string `json:"ws_url"`
API_url *string `json:"api_url"`
Description *string `json:"description"`
} `json:"properties"`
// TODO add JSON start parameter scheme
}
var client AMQPclient
......@@ -272,14 +273,18 @@ func processMessage(message amqp.Delivery) {
newICReq.InfrastructureComponent.State = "unknown"
}
if payload.Properties.WS_url != nil {
newICReq.InfrastructureComponent.Host = *payload.Properties.WS_url
newICReq.InfrastructureComponent.WebsocketURL = *payload.Properties.WS_url
}
if payload.Properties.API_url != nil {
newICReq.InfrastructureComponent.APIHost = *payload.Properties.API_url
newICReq.InfrastructureComponent.APIURL = *payload.Properties.API_url
}
if payload.Properties.Location != nil {
newICReq.InfrastructureComponent.Properties = postgres.Jsonb{json.RawMessage(`{"location" : " ` + *payload.Properties.Location + `"}`)}
newICReq.InfrastructureComponent.Location = *payload.Properties.Location
}
if payload.Properties.Description != nil {
newICReq.InfrastructureComponent.Description = *payload.Properties.Description
}
// TODO add JSON start parameter scheme
// Validate the new IC
err = newICReq.Validate()
......@@ -319,14 +324,19 @@ func processMessage(message amqp.Delivery) {
updatedICReq.InfrastructureComponent.Name = *payload.Properties.Name
}
if payload.Properties.WS_url != nil {
updatedICReq.InfrastructureComponent.Host = *payload.Properties.WS_url
updatedICReq.InfrastructureComponent.WebsocketURL = *payload.Properties.WS_url
}
if payload.Properties.API_url != nil {
updatedICReq.InfrastructureComponent.APIHost = *payload.Properties.API_url
updatedICReq.InfrastructureComponent.APIURL = *payload.Properties.API_url
}
if payload.Properties.Location != nil {
updatedICReq.InfrastructureComponent.Properties = postgres.Jsonb{json.RawMessage(`{"location" : " ` + *payload.Properties.Location + `"}`)}
//postgres.Jsonb{json.RawMessage(`{"location" : " ` + *payload.Properties.Location + `"}`)}
updatedICReq.InfrastructureComponent.Location = *payload.Properties.Location
}
if payload.Properties.Description != nil {
updatedICReq.InfrastructureComponent.Description = *payload.Properties.Description
}
// TODO add JSON start parameter scheme
// Validate the updated IC
if err = updatedICReq.Validate(); err != nil {
......
......@@ -120,10 +120,10 @@ type InfrastructureComponent struct {
UUID string `json:"uuid" gorm:"not null"`
// Name of the IC
Name string `json:"name" gorm:"default:''"`
// Host if the IC
Host string `json:"host" gorm:"default:''"`
// Host of API for IC
APIHost string `json:"apihost" gorm:"default:''"`
// WebsocketURL if the IC
WebsocketURL string `json:"websocketurl" gorm:"default:''"`
// API URL of API for IC
APIURL string `json:"apiurl" gorm:"default:''"`
// Category of IC (simulator, gateway, database, etc.)
Category string `json:"category" gorm:"default:''"`
// Type of IC (RTDS, VILLASnode, RTDS, etc.)
......@@ -134,10 +134,12 @@ type InfrastructureComponent struct {
State string `json:"state" gorm:"default:''"`
// Time of last state update
StateUpdateAt string `json:"stateUpdateAt" gorm:"default:''"`
// Location of the IC
Location string `json:"location" gorm:"default:''"`
// Description of the IC
Description string `json:"description" gorm:"default:''"`
// Properties of IC as JSON string
Properties postgres.Jsonb `json:"properties"`
// Raw properties of IC as JSON string
RawProperties postgres.Jsonb `json:"rawProperties"`
// ComponentConfigurations in which the IC is used
ComponentConfigurations []ComponentConfiguration `json:"-" gorm:"foreignkey:ICID"`
}
......
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2020-09-25 16:13:15.130920598 +0200 CEST m=+0.092357808
// 2020-10-20 12:56:57.842992188 +0200 CEST m=+0.084567298
package docs
......@@ -1078,7 +1078,7 @@ var doc = `{
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/infrastructure_component.addICRequest"
"$ref": "#/definitions/infrastructure_component.AddICRequest"
}
}
],
......@@ -1198,7 +1198,7 @@ var doc = `{
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/infrastructure_component.updateICRequest"
"$ref": "#/definitions/infrastructure_component.UpdateICRequest"
}
},
{
......@@ -2977,21 +2977,25 @@ var doc = `{
"database.InfrastructureComponent": {
"type": "object",
"properties": {
"apihost": {
"description": "Host of API for IC",
"apiurl": {
"description": "API URL of API for IC",
"type": "string"
},
"category": {
"description": "Category of IC (simulator, gateway, database, etc.)",
"type": "string"
},
"host": {
"description": "Host if the IC",
"description": {
"description": "Description of the IC",
"type": "string"
},
"id": {
"type": "integer"
},
"location": {
"description": "Location of the IC",
"type": "string"
},
"name": {
"description": "Name of the IC",
"type": "string"
......@@ -3000,10 +3004,6 @@ var doc = `{
"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"
......@@ -3023,6 +3023,10 @@ var doc = `{
"uuid": {
"description": "UUID of the IC",
"type": "string"
},
"websocketurl": {
"description": "WebsocketURL if the IC",
"type": "string"
}
}
},
......@@ -3351,7 +3355,7 @@ var doc = `{
}
}
},
"infrastructure_component.addICRequest": {
"infrastructure_component.AddICRequest": {
"type": "object",
"properties": {
"ic": {
......@@ -3360,7 +3364,7 @@ var doc = `{
}
}
},
"infrastructure_component.updateICRequest": {
"infrastructure_component.UpdateICRequest": {
"type": "object",
"properties": {
"ic": {
......@@ -3378,13 +3382,16 @@ var doc = `{
"UUID"
],
"properties": {
"APIHost": {
"APIURL": {
"type": "string"
},
"Category": {
"type": "string"
},
"Host": {
"Description": {
"type": "string"
},
"Location": {
"type": "string"
},
"Name": {
......@@ -3401,19 +3408,25 @@ var doc = `{
},
"UUID": {
"type": "string"
},
"WebsocketURL": {
"type": "string"
}
}
},
"infrastructure_component.validUpdatedIC": {
"type": "object",
"properties": {
"APIHost": {
"APIURL": {
"type": "string"
},
"Category": {
"type": "string"
},
"Host": {
"Description": {
"type": "string"
},
"Location": {
"type": "string"
},
"Name": {
......@@ -3430,6 +3443,9 @@ var doc = `{
},
"UUID": {
"type": "string"
},
"WebsocketURL": {
"type": "string"
}
}
},
......@@ -3765,7 +3781,7 @@ type swaggerInfo struct {
var SwaggerInfo = swaggerInfo{
Version: "2.0",
Host: "",
BasePath: "http://localhost:4000/api/v2/",
BasePath: "/api/v2",
Schemes: []string{},
Title: "VILLASweb Backend API",
Description: "This is the [VILLASweb Backend](https://git.rwth-aachen.de/acs/public/villas/web-backend-go) API v2.0.\nThis documentation is auto-generated based on the API documentation in the code. The tool [swag](https://github.com/swaggo/swag) is used to auto-generate API docs for the [gin-gonic](https://github.com/gin-gonic/gin) framework.\nAuthentication: Use the authenticate endpoint below to obtain a token for your user account, copy the token into to the value field of the dialog showing up for the green Authorize button below and confirm with Done.",
......
......@@ -13,7 +13,7 @@
},
"version": "2.0"
},
"basePath": "http://localhost:4000/api/v2/",
"basePath": "/api/v2",
"paths": {
"/authenticate": {
"post": {
......@@ -1061,7 +1061,7 @@
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/infrastructure_component.addICRequest"
"$ref": "#/definitions/infrastructure_component.AddICRequest"
}
}
],
......@@ -1181,7 +1181,7 @@
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/infrastructure_component.updateICRequest"
"$ref": "#/definitions/infrastructure_component.UpdateICRequest"
}
},
{
......@@ -2960,21 +2960,25 @@
"database.InfrastructureComponent": {
"type": "object",
"properties": {
"apihost": {
"description": "Host of API for IC",
"apiurl": {
"description": "API URL of API for IC",
"type": "string"
},
"category": {
"description": "Category of IC (simulator, gateway, database, etc.)",
"type": "string"
},
"host": {
"description": "Host if the IC",
"description": {
"description": "Description of the IC",
"type": "string"
},
"id": {
"type": "integer"
},
"location": {
"description": "Location of the IC",
"type": "string"
},
"name": {
"description": "Name of the IC",
"type": "string"
......@@ -2983,10 +2987,6 @@
"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"
......@@ -3006,6 +3006,10 @@
"uuid": {
"description": "UUID of the IC",
"type": "string"
},
"websocketurl": {
"description": "WebsocketURL if the IC",
"type": "string"
}
}
},
......@@ -3334,7 +3338,7 @@
}
}
},
"infrastructure_component.addICRequest": {
"infrastructure_component.AddICRequest": {
"type": "object",
"properties": {
"ic": {
......@@ -3343,7 +3347,7 @@
}
}
},
"infrastructure_component.updateICRequest": {
"infrastructure_component.UpdateICRequest": {
"type": "object",
"properties": {
"ic": {
......@@ -3361,13 +3365,16 @@
"UUID"
],
"properties": {
"APIHost": {
"APIURL": {
"type": "string"
},
"Category": {
"type": "string"
},
"Host": {
"Description": {
"type": "string"
},
"Location": {
"type": "string"
},
"Name": {
......@@ -3384,19 +3391,25 @@
},
"UUID": {
"type": "string"
},
"WebsocketURL": {
"type": "string"
}
}
},
"infrastructure_component.validUpdatedIC": {
"type": "object",
"properties": {
"APIHost": {
"APIURL": {
"type": "string"
},
"Category": {
"type": "string"
},
"Host": {
"Description": {
"type": "string"
},
"Location": {
"type": "string"
},
"Name": {
......@@ -3413,6 +3426,9 @@
},
"UUID": {
"type": "string"
},
"WebsocketURL": {
"type": "string"
}
}
},
......
basePath: http://localhost:4000/api/v2/
basePath: /api/v2
definitions:
component_configuration.addConfigRequest:
properties:
......@@ -146,26 +146,26 @@ definitions:
type: object
database.InfrastructureComponent:
properties:
apihost:
description: Host of API for IC
apiurl:
description: API URL of API for IC
type: string
category:
description: Category of IC (simulator, gateway, database, etc.)
type: string
host:
description: Host if the IC
description:
description: Description of the IC
type: string
id:
type: integer
location:
description: Location of the IC
type: string
name:
description: Name of 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
......@@ -181,6 +181,9 @@ definitions:
uuid:
description: UUID of the IC
type: string
websocketurl:
description: WebsocketURL if the IC
type: string
type: object
database.Scenario:
properties:
......@@ -404,13 +407,13 @@ definitions:
$ref: '#/definitions/database.Widget'
type: array
type: object
infrastructure_component.addICRequest:
infrastructure_component.AddICRequest:
properties:
ic:
$ref: '#/definitions/infrastructure_component.validNewIC'
type: object
type: object
infrastructure_component.updateICRequest:
infrastructure_component.UpdateICRequest:
properties:
ic:
$ref: '#/definitions/infrastructure_component.validUpdatedIC'
......@@ -418,11 +421,13 @@ definitions:
type: object
infrastructure_component.validNewIC:
properties:
APIHost:
APIURL:
type: string
Category:
type: string
Host:
Description:
type: string
Location:
type: string
Name:
type: string
......@@ -434,6 +439,8 @@ definitions:
type: string
UUID:
type: string
WebsocketURL:
type: string
required:
- Category
- Name
......@@ -442,11 +449,13 @@ definitions:
type: object
infrastructure_component.validUpdatedIC:
properties:
APIHost:
APIURL:
type: string
Category:
type: string
Host:
Description:
type: string
Location:
type: string
Name:
type: string
......@@ -458,6 +467,8 @@ definitions:
type: string
UUID:
type: string
WebsocketURL:
type: string
type: object
scenario.addScenarioRequest:
properties:
......@@ -1357,7 +1368,7 @@ paths:
name: inputIC
required: true
schema:
$ref: '#/definitions/infrastructure_component.addICRequest'
$ref: '#/definitions/infrastructure_component.AddICRequest'
type: object
produces:
- application/json
......@@ -1470,7 +1481,7 @@ paths:
name: inputIC
required: true
schema:
$ref: '#/definitions/infrastructure_component.updateICRequest'
$ref: '#/definitions/infrastructure_component.UpdateICRequest'
type: object
- description: InfrastructureComponent ID
in: path
......
......@@ -88,34 +88,36 @@ var NewUserC = UserRequest{
// Infrastructure components
var propertiesA = json.RawMessage(`{"location" : "ACSlab"}`)
var propertiesB = json.RawMessage(`{"location" : "ACSlab"}`)
var propertiesA = json.RawMessage(`{"prop1" : "a nice prop"}`)
var propertiesB = json.RawMessage(`{"prop1" : "not so nice"}`)
var ICA = database.InfrastructureComponent{
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
Host: "xxx.yyy.zzz.aaa",
Type: "DPsim",
Category: "Simulator",
Name: "Test DPsim Simulator",
Uptime: 0,
State: "running",
StateUpdateAt: time.Now().Format(time.RFC1123),
Properties: postgres.Jsonb{propertiesA},
RawProperties: postgres.Jsonb{propertiesA},
UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
WebsocketURL: "xxx.yyy.zzz.aaa",
Type: "DPsim",
Category: "Simulator",
Name: "Test DPsim Simulator",
Uptime: 0,
State: "running",
Location: "ACS Laboratory",
Description: "This is a test description",
//StateUpdateAt: time.Now().Format(time.RFC1123),
Properties: postgres.Jsonb{propertiesA},
}
var ICB = database.InfrastructureComponent{
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
Host: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
APIHost: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/api",
Type: "VILLASnode Signal Generator",
Category: "Signal Generator",
Name: "ACS Demo Signals",
Uptime: 0,
State: "idle",
StateUpdateAt: time.Now().Format(time.RFC1123),
Properties: postgres.Jsonb{propertiesB},
RawProperties: postgres.Jsonb{propertiesB},
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
WebsocketURL: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
APIURL: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/api",
Type: "VILLASnode Signal Generator",
Category: "Signal Generator",
Name: "ACS Demo Signals",
Uptime: 0,
State: "idle",
Location: "k8s",
Description: "A signal generator for testing purposes",
//StateUpdateAt: time.Now().Format(time.RFC1123),
Properties: postgres.Jsonb{propertiesB},
}
// Scenarios
......
......@@ -49,13 +49,15 @@ type ConfigRequest struct {
}
type ICRequest struct {
UUID string `json:"uuid,omitempty"`
Host string `json:"host,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Category string `json:"category,omitempty"`
State string `json:"state,omitempty"`
Properties postgres.Jsonb `json:"properties,omitempty"`
UUID string `json:"uuid,omitempty"`
WebsocketURL string `json:"websocketurl,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
Category string `json:"category,omitempty"`
State string `json:"state,omitempty"`
Location string `json:"location,omitempty"`
Description string `json:"description,omitempty"`
Properties postgres.Jsonb `json:"properties,omitempty"`
}
type ScenarioRequest struct {
......@@ -72,13 +74,15 @@ func addScenarioAndIC() (scenarioID uint, ICID uint) {
// POST $newICA
newICA := ICRequest{
UUID: helper.ICA.UUID,
Host: helper.ICA.Host,
Type: helper.ICA.Type,
Name: helper.ICA.Name,