Parameter cleanup in IC model

This commit is contained in:
Sonja Happ 2020-10-20 12:57:38 +02:00
parent 33eab641cb
commit 1f0455d901
10 changed files with 327 additions and 225 deletions

View file

@ -28,7 +28,6 @@ import (
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/jinzhu/gorm" "github.com/jinzhu/gorm"
"github.com/jinzhu/gorm/dialects/postgres"
"github.com/streadway/amqp" "github.com/streadway/amqp"
"log" "log"
"time" "time"
@ -61,7 +60,9 @@ type ICUpdate struct {
Location *string `json:"location"` Location *string `json:"location"`
WS_url *string `json:"ws_url"` WS_url *string `json:"ws_url"`
API_url *string `json:"api_url"` API_url *string `json:"api_url"`
Description *string `json:"description"`
} `json:"properties"` } `json:"properties"`
// TODO add JSON start parameter scheme
} }
var client AMQPclient var client AMQPclient
@ -272,14 +273,18 @@ func processMessage(message amqp.Delivery) {
newICReq.InfrastructureComponent.State = "unknown" newICReq.InfrastructureComponent.State = "unknown"
} }
if payload.Properties.WS_url != nil { 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 { 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 { 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 // Validate the new IC
err = newICReq.Validate() err = newICReq.Validate()
@ -319,14 +324,19 @@ func processMessage(message amqp.Delivery) {
updatedICReq.InfrastructureComponent.Name = *payload.Properties.Name updatedICReq.InfrastructureComponent.Name = *payload.Properties.Name
} }
if payload.Properties.WS_url != nil { 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 { 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 { 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 // Validate the updated IC
if err = updatedICReq.Validate(); err != nil { if err = updatedICReq.Validate(); err != nil {

View file

@ -120,10 +120,10 @@ type InfrastructureComponent struct {
UUID string `json:"uuid" gorm:"not null"` UUID string `json:"uuid" gorm:"not null"`
// Name of the IC // Name of the IC
Name string `json:"name" gorm:"default:''"` Name string `json:"name" gorm:"default:''"`
// Host if the IC // WebsocketURL if the IC
Host string `json:"host" gorm:"default:''"` WebsocketURL string `json:"websocketurl" gorm:"default:''"`
// Host of API for IC // API URL of API for IC
APIHost string `json:"apihost" gorm:"default:''"` APIURL string `json:"apiurl" gorm:"default:''"`
// Category of IC (simulator, gateway, database, etc.) // Category of IC (simulator, gateway, database, etc.)
Category string `json:"category" gorm:"default:''"` Category string `json:"category" gorm:"default:''"`
// Type of IC (RTDS, VILLASnode, RTDS, etc.) // Type of IC (RTDS, VILLASnode, RTDS, etc.)
@ -134,10 +134,12 @@ type InfrastructureComponent struct {
State string `json:"state" gorm:"default:''"` State string `json:"state" gorm:"default:''"`
// Time of last state update // Time of last state update
StateUpdateAt string `json:"stateUpdateAt" gorm:"default:''"` StateUpdateAt string `json:"stateUpdateAt" gorm:"default:''"`
// 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 of IC as JSON string
Properties postgres.Jsonb `json:"properties"` 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 in which the IC is used
ComponentConfigurations []ComponentConfiguration `json:"-" gorm:"foreignkey:ICID"` ComponentConfigurations []ComponentConfiguration `json:"-" gorm:"foreignkey:ICID"`
} }

View file

@ -1,6 +1,6 @@
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT // GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at // 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 package docs
@ -1078,7 +1078,7 @@ var doc = `{
"required": true, "required": true,
"schema": { "schema": {
"type": "object", "type": "object",
"$ref": "#/definitions/infrastructure_component.addICRequest" "$ref": "#/definitions/infrastructure_component.AddICRequest"
} }
} }
], ],
@ -1198,7 +1198,7 @@ var doc = `{
"required": true, "required": true,
"schema": { "schema": {
"type": "object", "type": "object",
"$ref": "#/definitions/infrastructure_component.updateICRequest" "$ref": "#/definitions/infrastructure_component.UpdateICRequest"
} }
}, },
{ {
@ -2977,21 +2977,25 @@ var doc = `{
"database.InfrastructureComponent": { "database.InfrastructureComponent": {
"type": "object", "type": "object",
"properties": { "properties": {
"apihost": { "apiurl": {
"description": "Host of API for IC", "description": "API URL of API for IC",
"type": "string" "type": "string"
}, },
"category": { "category": {
"description": "Category of IC (simulator, gateway, database, etc.)", "description": "Category of IC (simulator, gateway, database, etc.)",
"type": "string" "type": "string"
}, },
"host": { "description": {
"description": "Host if the IC", "description": "Description of the IC",
"type": "string" "type": "string"
}, },
"id": { "id": {
"type": "integer" "type": "integer"
}, },
"location": {
"description": "Location of the IC",
"type": "string"
},
"name": { "name": {
"description": "Name of the IC", "description": "Name of the IC",
"type": "string" "type": "string"
@ -3000,10 +3004,6 @@ var doc = `{
"description": "Properties of IC as JSON string", "description": "Properties of IC as JSON string",
"type": "string" "type": "string"
}, },
"rawProperties": {
"description": "Raw properties of IC as JSON string",
"type": "string"
},
"state": { "state": {
"description": "State of the IC", "description": "State of the IC",
"type": "string" "type": "string"
@ -3023,6 +3023,10 @@ var doc = `{
"uuid": { "uuid": {
"description": "UUID of the IC", "description": "UUID of the IC",
"type": "string" "type": "string"
},
"websocketurl": {
"description": "WebsocketURL if the IC",
"type": "string"
} }
} }
}, },
@ -3351,7 +3355,7 @@ var doc = `{
} }
} }
}, },
"infrastructure_component.addICRequest": { "infrastructure_component.AddICRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
"ic": { "ic": {
@ -3360,7 +3364,7 @@ var doc = `{
} }
} }
}, },
"infrastructure_component.updateICRequest": { "infrastructure_component.UpdateICRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
"ic": { "ic": {
@ -3378,13 +3382,16 @@ var doc = `{
"UUID" "UUID"
], ],
"properties": { "properties": {
"APIHost": { "APIURL": {
"type": "string" "type": "string"
}, },
"Category": { "Category": {
"type": "string" "type": "string"
}, },
"Host": { "Description": {
"type": "string"
},
"Location": {
"type": "string" "type": "string"
}, },
"Name": { "Name": {
@ -3401,19 +3408,25 @@ var doc = `{
}, },
"UUID": { "UUID": {
"type": "string" "type": "string"
},
"WebsocketURL": {
"type": "string"
} }
} }
}, },
"infrastructure_component.validUpdatedIC": { "infrastructure_component.validUpdatedIC": {
"type": "object", "type": "object",
"properties": { "properties": {
"APIHost": { "APIURL": {
"type": "string" "type": "string"
}, },
"Category": { "Category": {
"type": "string" "type": "string"
}, },
"Host": { "Description": {
"type": "string"
},
"Location": {
"type": "string" "type": "string"
}, },
"Name": { "Name": {
@ -3430,6 +3443,9 @@ var doc = `{
}, },
"UUID": { "UUID": {
"type": "string" "type": "string"
},
"WebsocketURL": {
"type": "string"
} }
} }
}, },
@ -3765,7 +3781,7 @@ type swaggerInfo struct {
var SwaggerInfo = swaggerInfo{ var SwaggerInfo = swaggerInfo{
Version: "2.0", Version: "2.0",
Host: "", Host: "",
BasePath: "http://localhost:4000/api/v2/", BasePath: "/api/v2",
Schemes: []string{}, Schemes: []string{},
Title: "VILLASweb Backend API", 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.", 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.",

View file

@ -13,7 +13,7 @@
}, },
"version": "2.0" "version": "2.0"
}, },
"basePath": "http://localhost:4000/api/v2/", "basePath": "/api/v2",
"paths": { "paths": {
"/authenticate": { "/authenticate": {
"post": { "post": {
@ -1061,7 +1061,7 @@
"required": true, "required": true,
"schema": { "schema": {
"type": "object", "type": "object",
"$ref": "#/definitions/infrastructure_component.addICRequest" "$ref": "#/definitions/infrastructure_component.AddICRequest"
} }
} }
], ],
@ -1181,7 +1181,7 @@
"required": true, "required": true,
"schema": { "schema": {
"type": "object", "type": "object",
"$ref": "#/definitions/infrastructure_component.updateICRequest" "$ref": "#/definitions/infrastructure_component.UpdateICRequest"
} }
}, },
{ {
@ -2960,21 +2960,25 @@
"database.InfrastructureComponent": { "database.InfrastructureComponent": {
"type": "object", "type": "object",
"properties": { "properties": {
"apihost": { "apiurl": {
"description": "Host of API for IC", "description": "API URL of API for IC",
"type": "string" "type": "string"
}, },
"category": { "category": {
"description": "Category of IC (simulator, gateway, database, etc.)", "description": "Category of IC (simulator, gateway, database, etc.)",
"type": "string" "type": "string"
}, },
"host": { "description": {
"description": "Host if the IC", "description": "Description of the IC",
"type": "string" "type": "string"
}, },
"id": { "id": {
"type": "integer" "type": "integer"
}, },
"location": {
"description": "Location of the IC",
"type": "string"
},
"name": { "name": {
"description": "Name of the IC", "description": "Name of the IC",
"type": "string" "type": "string"
@ -2983,10 +2987,6 @@
"description": "Properties of IC as JSON string", "description": "Properties of IC as JSON string",
"type": "string" "type": "string"
}, },
"rawProperties": {
"description": "Raw properties of IC as JSON string",
"type": "string"
},
"state": { "state": {
"description": "State of the IC", "description": "State of the IC",
"type": "string" "type": "string"
@ -3006,6 +3006,10 @@
"uuid": { "uuid": {
"description": "UUID of the IC", "description": "UUID of the IC",
"type": "string" "type": "string"
},
"websocketurl": {
"description": "WebsocketURL if the IC",
"type": "string"
} }
} }
}, },
@ -3334,7 +3338,7 @@
} }
} }
}, },
"infrastructure_component.addICRequest": { "infrastructure_component.AddICRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
"ic": { "ic": {
@ -3343,7 +3347,7 @@
} }
} }
}, },
"infrastructure_component.updateICRequest": { "infrastructure_component.UpdateICRequest": {
"type": "object", "type": "object",
"properties": { "properties": {
"ic": { "ic": {
@ -3361,13 +3365,16 @@
"UUID" "UUID"
], ],
"properties": { "properties": {
"APIHost": { "APIURL": {
"type": "string" "type": "string"
}, },
"Category": { "Category": {
"type": "string" "type": "string"
}, },
"Host": { "Description": {
"type": "string"
},
"Location": {
"type": "string" "type": "string"
}, },
"Name": { "Name": {
@ -3384,19 +3391,25 @@
}, },
"UUID": { "UUID": {
"type": "string" "type": "string"
},
"WebsocketURL": {
"type": "string"
} }
} }
}, },
"infrastructure_component.validUpdatedIC": { "infrastructure_component.validUpdatedIC": {
"type": "object", "type": "object",
"properties": { "properties": {
"APIHost": { "APIURL": {
"type": "string" "type": "string"
}, },
"Category": { "Category": {
"type": "string" "type": "string"
}, },
"Host": { "Description": {
"type": "string"
},
"Location": {
"type": "string" "type": "string"
}, },
"Name": { "Name": {
@ -3413,6 +3426,9 @@
}, },
"UUID": { "UUID": {
"type": "string" "type": "string"
},
"WebsocketURL": {
"type": "string"
} }
} }
}, },

View file

@ -1,4 +1,4 @@
basePath: http://localhost:4000/api/v2/ basePath: /api/v2
definitions: definitions:
component_configuration.addConfigRequest: component_configuration.addConfigRequest:
properties: properties:
@ -146,26 +146,26 @@ definitions:
type: object type: object
database.InfrastructureComponent: database.InfrastructureComponent:
properties: properties:
apihost: apiurl:
description: Host of API for IC description: API URL of API for IC
type: string type: string
category: category:
description: Category of IC (simulator, gateway, database, etc.) description: Category of IC (simulator, gateway, database, etc.)
type: string type: string
host: description:
description: Host if the IC description: Description of the IC
type: string type: string
id: id:
type: integer type: integer
location:
description: Location of the IC
type: string
name: name:
description: Name of the IC description: Name of the IC
type: string type: string
properties: properties:
description: Properties of IC as JSON string description: Properties of IC as JSON string
type: string type: string
rawProperties:
description: Raw properties of IC as JSON string
type: string
state: state:
description: State of the IC description: State of the IC
type: string type: string
@ -181,6 +181,9 @@ definitions:
uuid: uuid:
description: UUID of the IC description: UUID of the IC
type: string type: string
websocketurl:
description: WebsocketURL if the IC
type: string
type: object type: object
database.Scenario: database.Scenario:
properties: properties:
@ -404,13 +407,13 @@ definitions:
$ref: '#/definitions/database.Widget' $ref: '#/definitions/database.Widget'
type: array type: array
type: object type: object
infrastructure_component.addICRequest: infrastructure_component.AddICRequest:
properties: properties:
ic: ic:
$ref: '#/definitions/infrastructure_component.validNewIC' $ref: '#/definitions/infrastructure_component.validNewIC'
type: object type: object
type: object type: object
infrastructure_component.updateICRequest: infrastructure_component.UpdateICRequest:
properties: properties:
ic: ic:
$ref: '#/definitions/infrastructure_component.validUpdatedIC' $ref: '#/definitions/infrastructure_component.validUpdatedIC'
@ -418,11 +421,13 @@ definitions:
type: object type: object
infrastructure_component.validNewIC: infrastructure_component.validNewIC:
properties: properties:
APIHost: APIURL:
type: string type: string
Category: Category:
type: string type: string
Host: Description:
type: string
Location:
type: string type: string
Name: Name:
type: string type: string
@ -434,6 +439,8 @@ definitions:
type: string type: string
UUID: UUID:
type: string type: string
WebsocketURL:
type: string
required: required:
- Category - Category
- Name - Name
@ -442,11 +449,13 @@ definitions:
type: object type: object
infrastructure_component.validUpdatedIC: infrastructure_component.validUpdatedIC:
properties: properties:
APIHost: APIURL:
type: string type: string
Category: Category:
type: string type: string
Host: Description:
type: string
Location:
type: string type: string
Name: Name:
type: string type: string
@ -458,6 +467,8 @@ definitions:
type: string type: string
UUID: UUID:
type: string type: string
WebsocketURL:
type: string
type: object type: object
scenario.addScenarioRequest: scenario.addScenarioRequest:
properties: properties:
@ -1357,7 +1368,7 @@ paths:
name: inputIC name: inputIC
required: true required: true
schema: schema:
$ref: '#/definitions/infrastructure_component.addICRequest' $ref: '#/definitions/infrastructure_component.AddICRequest'
type: object type: object
produces: produces:
- application/json - application/json
@ -1470,7 +1481,7 @@ paths:
name: inputIC name: inputIC
required: true required: true
schema: schema:
$ref: '#/definitions/infrastructure_component.updateICRequest' $ref: '#/definitions/infrastructure_component.UpdateICRequest'
type: object type: object
- description: InfrastructureComponent ID - description: InfrastructureComponent ID
in: path in: path

View file

@ -88,34 +88,36 @@ var NewUserC = UserRequest{
// Infrastructure components // Infrastructure components
var propertiesA = json.RawMessage(`{"location" : "ACSlab"}`) var propertiesA = json.RawMessage(`{"prop1" : "a nice prop"}`)
var propertiesB = json.RawMessage(`{"location" : "ACSlab"}`) var propertiesB = json.RawMessage(`{"prop1" : "not so nice"}`)
var ICA = database.InfrastructureComponent{ var ICA = database.InfrastructureComponent{
UUID: "4854af30-325f-44a5-ad59-b67b2597de68", UUID: "4854af30-325f-44a5-ad59-b67b2597de68",
Host: "xxx.yyy.zzz.aaa", WebsocketURL: "xxx.yyy.zzz.aaa",
Type: "DPsim", Type: "DPsim",
Category: "Simulator", Category: "Simulator",
Name: "Test DPsim Simulator", Name: "Test DPsim Simulator",
Uptime: 0, Uptime: 0,
State: "running", State: "running",
StateUpdateAt: time.Now().Format(time.RFC1123), Location: "ACS Laboratory",
Description: "This is a test description",
//StateUpdateAt: time.Now().Format(time.RFC1123),
Properties: postgres.Jsonb{propertiesA}, Properties: postgres.Jsonb{propertiesA},
RawProperties: postgres.Jsonb{propertiesA},
} }
var ICB = database.InfrastructureComponent{ var ICB = database.InfrastructureComponent{
UUID: "7be0322d-354e-431e-84bd-ae4c9633138b", UUID: "7be0322d-354e-431e-84bd-ae4c9633138b",
Host: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/ws_sig", WebsocketURL: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/ws_sig",
APIHost: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/api", APIURL: "https://villas-new.k8s.eonerc.rwth-aachen.de/ws/api",
Type: "VILLASnode Signal Generator", Type: "VILLASnode Signal Generator",
Category: "Signal Generator", Category: "Signal Generator",
Name: "ACS Demo Signals", Name: "ACS Demo Signals",
Uptime: 0, Uptime: 0,
State: "idle", State: "idle",
StateUpdateAt: time.Now().Format(time.RFC1123), Location: "k8s",
Description: "A signal generator for testing purposes",
//StateUpdateAt: time.Now().Format(time.RFC1123),
Properties: postgres.Jsonb{propertiesB}, Properties: postgres.Jsonb{propertiesB},
RawProperties: postgres.Jsonb{propertiesB},
} }
// Scenarios // Scenarios

View file

@ -50,11 +50,13 @@ type ConfigRequest struct {
type ICRequest struct { type ICRequest struct {
UUID string `json:"uuid,omitempty"` UUID string `json:"uuid,omitempty"`
Host string `json:"host,omitempty"` WebsocketURL string `json:"websocketurl,omitempty"`
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Category string `json:"category,omitempty"` Category string `json:"category,omitempty"`
State string `json:"state,omitempty"` State string `json:"state,omitempty"`
Location string `json:"location,omitempty"`
Description string `json:"description,omitempty"`
Properties postgres.Jsonb `json:"properties,omitempty"` Properties postgres.Jsonb `json:"properties,omitempty"`
} }
@ -73,11 +75,13 @@ func addScenarioAndIC() (scenarioID uint, ICID uint) {
// POST $newICA // POST $newICA
newICA := ICRequest{ newICA := ICRequest{
UUID: helper.ICA.UUID, UUID: helper.ICA.UUID,
Host: helper.ICA.Host, WebsocketURL: helper.ICA.WebsocketURL,
Type: helper.ICA.Type, Type: helper.ICA.Type,
Name: helper.ICA.Name, Name: helper.ICA.Name,
Category: helper.ICA.Category, Category: helper.ICA.Category,
State: helper.ICA.State, State: helper.ICA.State,
Location: helper.ICA.Location,
Description: helper.ICA.Description,
Properties: helper.ICA.Properties, Properties: helper.ICA.Properties,
} }
_, resp, _ := helper.TestEndpoint(router, token, _, resp, _ := helper.TestEndpoint(router, token,
@ -89,11 +93,13 @@ func addScenarioAndIC() (scenarioID uint, ICID uint) {
// POST a second IC to change to that IC during testing // POST a second IC to change to that IC during testing
newICB := ICRequest{ newICB := ICRequest{
UUID: helper.ICB.UUID, UUID: helper.ICB.UUID,
Host: helper.ICB.Host, WebsocketURL: helper.ICB.WebsocketURL,
Type: helper.ICB.Type, Type: helper.ICB.Type,
Name: helper.ICB.Name, Name: helper.ICB.Name,
Category: helper.ICB.Category, Category: helper.ICB.Category,
State: helper.ICB.State, State: helper.ICB.State,
Location: helper.ICB.Location,
Description: helper.ICB.Description,
Properties: helper.ICB.Properties, Properties: helper.ICB.Properties,
} }
_, resp, _ = helper.TestEndpoint(router, token, _, resp, _ = helper.TestEndpoint(router, token,

View file

@ -40,12 +40,14 @@ var router *gin.Engine
type ICRequest struct { type ICRequest struct {
UUID string `json:"uuid,omitempty"` UUID string `json:"uuid,omitempty"`
Host string `json:"host,omitempty"` WebsocketURL string `json:"websocketurl,omitempty"`
APIHost string `json:"apihost,omitempty"` APIURL string `json:"apiurl,omitempty"`
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Category string `json:"category,omitempty"` Category string `json:"category,omitempty"`
State string `json:"state,omitempty"` State string `json:"state,omitempty"`
Location string `json:"location,omitempty"`
Description string `json:"description,omitempty"`
Properties postgres.Jsonb `json:"properties,omitempty"` Properties postgres.Jsonb `json:"properties,omitempty"`
} }
@ -101,11 +103,14 @@ func TestAddICAsAdmin(t *testing.T) {
// test POST ic/ $newIC // test POST ic/ $newIC
newIC := ICRequest{ newIC := ICRequest{
UUID: helper.ICA.UUID, UUID: helper.ICA.UUID,
Host: helper.ICA.Host, WebsocketURL: helper.ICA.WebsocketURL,
APIURL: helper.ICB.APIURL,
Type: helper.ICA.Type, Type: helper.ICA.Type,
Name: helper.ICA.Name, Name: helper.ICA.Name,
Category: helper.ICA.Category, Category: helper.ICA.Category,
State: helper.ICA.State, State: helper.ICA.State,
Location: helper.ICA.Location,
Description: helper.ICA.Description,
Properties: helper.ICA.Properties, Properties: helper.ICA.Properties,
} }
code, resp, err = helper.TestEndpoint(router, token, code, resp, err = helper.TestEndpoint(router, token,
@ -153,11 +158,13 @@ func TestAddICAsUser(t *testing.T) {
// test POST ic/ $newIC // test POST ic/ $newIC
newIC := ICRequest{ newIC := ICRequest{
UUID: helper.ICA.UUID, UUID: helper.ICA.UUID,
Host: helper.ICA.Host, WebsocketURL: helper.ICA.WebsocketURL,
Type: helper.ICA.Type, Type: helper.ICA.Type,
Name: helper.ICA.Name, Name: helper.ICA.Name,
Category: helper.ICA.Category, Category: helper.ICA.Category,
State: helper.ICA.State, State: helper.ICA.State,
Location: helper.ICA.Location,
Description: helper.ICA.Description,
Properties: helper.ICA.Properties, Properties: helper.ICA.Properties,
} }
@ -182,11 +189,13 @@ func TestUpdateICAsAdmin(t *testing.T) {
// test POST ic/ $newIC // test POST ic/ $newIC
newIC := ICRequest{ newIC := ICRequest{
UUID: helper.ICA.UUID, UUID: helper.ICA.UUID,
Host: helper.ICA.Host, WebsocketURL: helper.ICA.WebsocketURL,
Type: helper.ICA.Type, Type: helper.ICA.Type,
Name: helper.ICA.Name, Name: helper.ICA.Name,
Category: helper.ICA.Category, Category: helper.ICA.Category,
State: helper.ICA.State, State: helper.ICA.State,
Location: helper.ICA.Location,
Description: helper.ICA.Description,
Properties: helper.ICA.Properties, Properties: helper.ICA.Properties,
} }
code, resp, err := helper.TestEndpoint(router, token, code, resp, err := helper.TestEndpoint(router, token,
@ -210,7 +219,7 @@ func TestUpdateICAsAdmin(t *testing.T) {
assert.Equalf(t, 400, code, "Response body: \n%v\n", resp) assert.Equalf(t, 400, code, "Response body: \n%v\n", resp)
// Test PUT IC // Test PUT IC
newIC.Host = "ThisIsMyNewHost" newIC.WebsocketURL = "ThisIsMyNewURL"
code, resp, err = helper.TestEndpoint(router, token, code, resp, err = helper.TestEndpoint(router, token,
fmt.Sprintf("/api/ic/%v", newICID), "PUT", helper.KeyModels{"ic": newIC}) fmt.Sprintf("/api/ic/%v", newICID), "PUT", helper.KeyModels{"ic": newIC})
assert.NoError(t, err) assert.NoError(t, err)
@ -246,11 +255,13 @@ func TestUpdateICAsUser(t *testing.T) {
// test POST ic/ $newIC // test POST ic/ $newIC
newIC := ICRequest{ newIC := ICRequest{
UUID: helper.ICA.UUID, UUID: helper.ICA.UUID,
Host: helper.ICA.Host, WebsocketURL: helper.ICA.WebsocketURL,
Type: helper.ICA.Type, Type: helper.ICA.Type,
Name: helper.ICA.Name, Name: helper.ICA.Name,
Category: helper.ICA.Category, Category: helper.ICA.Category,
State: helper.ICA.State, State: helper.ICA.State,
Location: helper.ICA.Location,
Description: helper.ICA.Description,
Properties: helper.ICA.Properties, Properties: helper.ICA.Properties,
} }
code, resp, err := helper.TestEndpoint(router, token, code, resp, err := helper.TestEndpoint(router, token,
@ -269,7 +280,7 @@ func TestUpdateICAsUser(t *testing.T) {
// Test PUT IC // Test PUT IC
// This should fail with unprocessable entity status code 422 // This should fail with unprocessable entity status code 422
newIC.Host = "ThisIsMyNewHost" newIC.WebsocketURL = "ThisIsMyNewURL"
code, resp, err = helper.TestEndpoint(router, token, code, resp, err = helper.TestEndpoint(router, token,
fmt.Sprintf("/api/ic/%v", newICID), "PUT", helper.KeyModels{"ic": newIC}) fmt.Sprintf("/api/ic/%v", newICID), "PUT", helper.KeyModels{"ic": newIC})
assert.NoError(t, err) assert.NoError(t, err)
@ -290,11 +301,13 @@ func TestDeleteICAsAdmin(t *testing.T) {
// test POST ic/ $newIC // test POST ic/ $newIC
newIC := ICRequest{ newIC := ICRequest{
UUID: helper.ICA.UUID, UUID: helper.ICA.UUID,
Host: helper.ICA.Host, WebsocketURL: helper.ICA.WebsocketURL,
Type: helper.ICA.Type, Type: helper.ICA.Type,
Name: helper.ICA.Name, Name: helper.ICA.Name,
Category: helper.ICA.Category, Category: helper.ICA.Category,
State: helper.ICA.State, State: helper.ICA.State,
Location: helper.ICA.Location,
Description: helper.ICA.Description,
Properties: helper.ICA.Properties, Properties: helper.ICA.Properties,
} }
code, resp, err := helper.TestEndpoint(router, token, code, resp, err := helper.TestEndpoint(router, token,
@ -342,11 +355,13 @@ func TestDeleteICAsUser(t *testing.T) {
// test POST ic/ $newIC // test POST ic/ $newIC
newIC := ICRequest{ newIC := ICRequest{
UUID: helper.ICA.UUID, UUID: helper.ICA.UUID,
Host: helper.ICA.Host, WebsocketURL: helper.ICA.WebsocketURL,
Type: helper.ICA.Type, Type: helper.ICA.Type,
Name: helper.ICA.Name, Name: helper.ICA.Name,
Category: helper.ICA.Category, Category: helper.ICA.Category,
State: helper.ICA.State, State: helper.ICA.State,
Location: helper.ICA.Location,
Description: helper.ICA.Description,
Properties: helper.ICA.Properties, Properties: helper.ICA.Properties,
} }
code, resp, err := helper.TestEndpoint(router, token, code, resp, err := helper.TestEndpoint(router, token,
@ -365,7 +380,7 @@ func TestDeleteICAsUser(t *testing.T) {
// Test DELETE ICs // Test DELETE ICs
// This should fail with unprocessable entity status code 422 // This should fail with unprocessable entity status code 422
newIC.Host = "ThisIsMyNewHost" newIC.WebsocketURL = "ThisIsMyNewURL"
code, resp, err = helper.TestEndpoint(router, token, code, resp, err = helper.TestEndpoint(router, token,
fmt.Sprintf("/api/ic/%v", newICID), "DELETE", nil) fmt.Sprintf("/api/ic/%v", newICID), "DELETE", nil)
assert.NoError(t, err) assert.NoError(t, err)
@ -390,11 +405,13 @@ func TestGetAllICs(t *testing.T) {
// test POST ic/ $newICA // test POST ic/ $newICA
newICA := ICRequest{ newICA := ICRequest{
UUID: helper.ICA.UUID, UUID: helper.ICA.UUID,
Host: helper.ICA.Host, WebsocketURL: helper.ICA.WebsocketURL,
Type: helper.ICA.Type, Type: helper.ICA.Type,
Name: helper.ICA.Name, Name: helper.ICA.Name,
Category: helper.ICA.Category, Category: helper.ICA.Category,
State: helper.ICA.State, State: helper.ICA.State,
Location: helper.ICA.Location,
Description: helper.ICA.Description,
Properties: helper.ICA.Properties, Properties: helper.ICA.Properties,
} }
code, resp, err := helper.TestEndpoint(router, token, code, resp, err := helper.TestEndpoint(router, token,
@ -405,11 +422,13 @@ func TestGetAllICs(t *testing.T) {
// test POST ic/ $newICB // test POST ic/ $newICB
newICB := ICRequest{ newICB := ICRequest{
UUID: helper.ICB.UUID, UUID: helper.ICB.UUID,
Host: helper.ICB.Host, WebsocketURL: helper.ICB.WebsocketURL,
Type: helper.ICB.Type, Type: helper.ICB.Type,
Name: helper.ICB.Name, Name: helper.ICB.Name,
Category: helper.ICB.Category, Category: helper.ICB.Category,
State: helper.ICB.State, State: helper.ICB.State,
Location: helper.ICB.Location,
Description: helper.ICB.Description,
Properties: helper.ICB.Properties, Properties: helper.ICB.Properties,
} }
code, resp, err = helper.TestEndpoint(router, token, code, resp, err = helper.TestEndpoint(router, token,
@ -450,11 +469,13 @@ func TestGetConfigsOfIC(t *testing.T) {
// test POST ic/ $newICA // test POST ic/ $newICA
newICA := ICRequest{ newICA := ICRequest{
UUID: helper.ICA.UUID, UUID: helper.ICA.UUID,
Host: helper.ICA.Host, WebsocketURL: helper.ICA.WebsocketURL,
Type: helper.ICA.Type, Type: helper.ICA.Type,
Name: helper.ICA.Name, Name: helper.ICA.Name,
Category: helper.ICA.Category, Category: helper.ICA.Category,
State: helper.ICA.State, State: helper.ICA.State,
Location: helper.ICA.Location,
Description: helper.ICA.Description,
Properties: helper.ICA.Properties, Properties: helper.ICA.Properties,
} }
code, resp, err := helper.TestEndpoint(router, token, code, resp, err := helper.TestEndpoint(router, token,

View file

@ -33,24 +33,28 @@ var validate *validator.Validate
type validNewIC struct { type validNewIC struct {
UUID string `form:"UUID" validate:"required"` UUID string `form:"UUID" validate:"required"`
Host string `form:"Host" validate:"omitempty"` WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
APIHost string `form:"APIHost" validate:"omitempty"` APIURL string `form:"APIURL" validate:"omitempty"`
Type string `form:"Type" validate:"required"` Type string `form:"Type" validate:"required"`
Name string `form:"Name" validate:"required"` Name string `form:"Name" validate:"required"`
Category string `form:"Category" validate:"required"` Category string `form:"Category" validate:"required"`
Properties postgres.Jsonb `form:"Properties" validate:"omitempty"` Properties postgres.Jsonb `form:"Properties" validate:"omitempty"`
State string `form:"State" validate:"omitempty"` State string `form:"State" validate:"omitempty"`
Location string `form:"Location" validate:"omitempty"`
Description string `form:"Description" validate:"omitempty"`
} }
type validUpdatedIC struct { type validUpdatedIC struct {
UUID string `form:"UUID" validate:"omitempty"` UUID string `form:"UUID" validate:"omitempty"`
Host string `form:"Host" validate:"omitempty"` WebsocketURL string `form:"WebsocketURL" validate:"omitempty"`
APIHost string `form:"APIHost" validate:"omitempty"` APIURL string `form:"APIURL" validate:"omitempty"`
Type string `form:"Type" validate:"omitempty"` Type string `form:"Type" validate:"omitempty"`
Name string `form:"Name" validate:"omitempty"` Name string `form:"Name" validate:"omitempty"`
Category string `form:"Category" validate:"omitempty"` Category string `form:"Category" validate:"omitempty"`
Properties postgres.Jsonb `form:"Properties" validate:"omitempty"` Properties postgres.Jsonb `form:"Properties" validate:"omitempty"`
State string `form:"State" validate:"omitempty"` State string `form:"State" validate:"omitempty"`
Location string `form:"Location" validate:"omitempty"`
Description string `form:"Description" validate:"omitempty"`
} }
type AddICRequest struct { type AddICRequest struct {
@ -77,11 +81,13 @@ func (r *AddICRequest) CreateIC() InfrastructureComponent {
var s InfrastructureComponent var s InfrastructureComponent
s.UUID = r.InfrastructureComponent.UUID s.UUID = r.InfrastructureComponent.UUID
s.Host = r.InfrastructureComponent.Host s.WebsocketURL = r.InfrastructureComponent.WebsocketURL
s.APIHost = r.InfrastructureComponent.APIHost s.APIURL = r.InfrastructureComponent.APIURL
s.Type = r.InfrastructureComponent.Type s.Type = r.InfrastructureComponent.Type
s.Name = r.InfrastructureComponent.Name s.Name = r.InfrastructureComponent.Name
s.Category = r.InfrastructureComponent.Category s.Category = r.InfrastructureComponent.Category
s.Location = r.InfrastructureComponent.Location
s.Description = r.InfrastructureComponent.Description
s.Properties = r.InfrastructureComponent.Properties s.Properties = r.InfrastructureComponent.Properties
if r.InfrastructureComponent.State != "" { if r.InfrastructureComponent.State != "" {
s.State = r.InfrastructureComponent.State s.State = r.InfrastructureComponent.State
@ -102,12 +108,12 @@ func (r *UpdateICRequest) UpdatedIC(oldIC InfrastructureComponent) Infrastructur
s.UUID = r.InfrastructureComponent.UUID s.UUID = r.InfrastructureComponent.UUID
} }
if r.InfrastructureComponent.Host != "" { if r.InfrastructureComponent.WebsocketURL != "" {
s.Host = r.InfrastructureComponent.Host s.WebsocketURL = r.InfrastructureComponent.WebsocketURL
} }
if r.InfrastructureComponent.APIHost != "" { if r.InfrastructureComponent.APIURL != "" {
s.APIHost = r.InfrastructureComponent.APIHost s.APIURL = r.InfrastructureComponent.APIURL
} }
if r.InfrastructureComponent.Type != "" { if r.InfrastructureComponent.Type != "" {
@ -126,6 +132,14 @@ func (r *UpdateICRequest) UpdatedIC(oldIC InfrastructureComponent) Infrastructur
s.State = r.InfrastructureComponent.State s.State = r.InfrastructureComponent.State
} }
if r.InfrastructureComponent.Location != "" {
s.Location = r.InfrastructureComponent.Location
}
if r.InfrastructureComponent.Description != "" {
s.Description = r.InfrastructureComponent.Description
}
// set last update time // set last update time
s.StateUpdateAt = time.Now().Format(time.RFC1123) s.StateUpdateAt = time.Now().Format(time.RFC1123)

View file

@ -57,11 +57,13 @@ type ConfigRequest struct {
type ICRequest struct { type ICRequest struct {
UUID string `json:"uuid,omitempty"` UUID string `json:"uuid,omitempty"`
Host string `json:"host,omitempty"` WebsocketURL string `json:"websocketurl,omitempty"`
Type string `json:"type,omitempty"` Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
Category string `json:"category,omitempty"` Category string `json:"category,omitempty"`
State string `json:"state,omitempty"` State string `json:"state,omitempty"`
Location string `json:"location,omitempty"`
Description string `json:"description,omitempty"`
Properties postgres.Jsonb `json:"properties,omitempty"` Properties postgres.Jsonb `json:"properties,omitempty"`
} }
@ -80,11 +82,13 @@ func addScenarioAndICAndConfig() (scenarioID uint, ICID uint, configID uint) {
// POST $newICA // POST $newICA
newICA := ICRequest{ newICA := ICRequest{
UUID: helper.ICA.UUID, UUID: helper.ICA.UUID,
Host: helper.ICA.Host, WebsocketURL: helper.ICA.WebsocketURL,
Type: helper.ICA.Type, Type: helper.ICA.Type,
Name: helper.ICA.Name, Name: helper.ICA.Name,
Category: helper.ICA.Category, Category: helper.ICA.Category,
State: helper.ICA.State, State: helper.ICA.State,
Location: helper.ICA.Location,
Description: helper.ICA.Description,
Properties: helper.ICA.Properties, Properties: helper.ICA.Properties,
} }
_, resp, _ := helper.TestEndpoint(router, token, _, resp, _ := helper.TestEndpoint(router, token,