Skip to content

Commit

Permalink
Merge pull request #532 from snetsystems/dev-1.4.0-jinhyeong
Browse files Browse the repository at this point in the history
Infrastructure 페이지 속도 개선
  • Loading branch information
snetsystems authored Sep 30, 2024
2 parents 2e80b81 + 7293f37 commit c3a0932
Show file tree
Hide file tree
Showing 23 changed files with 1,085 additions and 212 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION = 1.4.8
VERSION = 1.4.9
ifeq ($(OS), Windows_NT)
GOBINDATA := $(shell go-bindata.exe --version 2>nil)
else
Expand Down
18 changes: 14 additions & 4 deletions backend/cloudhub.go
Original file line number Diff line number Diff line change
Expand Up @@ -1013,10 +1013,20 @@ type Environment struct {

// Topology is represents represents an topology
type Topology struct {
ID string `json:"id,string,omitempty"`
Organization string `json:"organization,omitempty"` // Organization is the organization ID that resource belongs to
Diagram string `json:"diagram,string,omitempty"` // diagram xml
Preferences []string `json:"preferences,omitempty"` // User preferences
ID string `json:"id,string,omitempty"`
Organization string `json:"organization,omitempty"` // Organization is the organization ID that resource belongs to
Diagram string `json:"diagram,string,omitempty"` // diagram xml
Preferences []string `json:"preferences,omitempty"` // User preferences
TopologyOptions TopologyOptions `json:"topologyOptions,omitempty"` // Configuration options for the topology, defined in TopologyOptions
}

// TopologyOptions represents various settings for displaying elements of the topology.
// Each field controls the visibility of specific icons or features within the topology.
type TopologyOptions struct {
MinimapVisible bool `json:"minimapVisible"` // Controls whether the minimap is visible in the mxgraph
HostStatusVisible bool `json:"hostStatusVisible"` // Controls whether the host status is visible
IPMIVisible bool `json:"ipmiVisible"` // Controls whether the IPMI icon is visible
LinkVisible bool `json:"linkVisible"` // Controls whether the dashboard link icon is visible
}

// TopologyQuery represents the attributes that a topology may be retrieved by.
Expand Down
26 changes: 26 additions & 0 deletions backend/kv/internal/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,12 @@ func MarshalTopology(t *cloudhub.Topology) ([]byte, error) {
Organization: t.Organization,
Diagram: t.Diagram,
Preferences: t.Preferences,
TopologyOptions: &TopologyOptions{
MinimapVisible: t.TopologyOptions.MinimapVisible,
HostStatusVisible: t.TopologyOptions.HostStatusVisible,
IpmiVisible: t.TopologyOptions.IPMIVisible,
LinkVisible: t.TopologyOptions.LinkVisible,
},
})
}

Expand All @@ -987,9 +993,29 @@ func UnmarshalTopology(data []byte, t *cloudhub.Topology) error {
t.Diagram = pb.Diagram
t.Preferences = pb.Preferences

if pb.TopologyOptions != nil {
t.TopologyOptions = cloudhub.TopologyOptions{
MinimapVisible: pb.TopologyOptions.MinimapVisible,
HostStatusVisible: pb.TopologyOptions.HostStatusVisible,
IPMIVisible: pb.TopologyOptions.IpmiVisible,
LinkVisible: pb.TopologyOptions.LinkVisible,
}
} else {
t.TopologyOptions = getDefaultTopologyOptions()
}

return nil
}

func getDefaultTopologyOptions() cloudhub.TopologyOptions {
return cloudhub.TopologyOptions{
MinimapVisible: true,
HostStatusVisible: true,
IPMIVisible: true,
LinkVisible: true,
}
}

// MarshalCSP encodes a mapping to binary protobuf format.
func MarshalCSP(t *cloudhub.CSP) ([]byte, error) {
return proto.Marshal(&CSP{
Expand Down
8 changes: 8 additions & 0 deletions backend/kv/internal/internal.proto
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,14 @@ message Topology {
string Organization = 2; // Organization is the organization ID that resource belongs to
string Diagram = 3; // diagram xml
repeated string Preferences = 4; // Temperature type and values
TopologyOptions topologyOptions = 5; // Options for the topology
}

message TopologyOptions {
bool minimapVisible = 1; // Whether to show the minimap
bool hostStatusVisible = 2; // Whether to show the host status
bool ipmiVisible = 3; // Whether to show the IPMI icon
bool linkVisible = 4; // Whether to show the dashboard link icon
}

message CSP {
Expand Down
6 changes: 6 additions & 0 deletions backend/kv/internal/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,12 @@ func TestMarshalTopology(t *testing.T) {
"type:inside,active:0,min:38,max:55",
"type:outlet,active:0,min:30,max:50",
},
TopologyOptions: cloudhub.TopologyOptions{
MinimapVisible: true,
HostStatusVisible: false,
IPMIVisible: true,
LinkVisible: true,
},
}

var vv cloudhub.Topology
Expand Down
24 changes: 22 additions & 2 deletions backend/kv/topologys_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,24 @@ func TestTopologiesStore(t *testing.T) {
Organization: "133",
Diagram: "<mxGraphModel><root></root></mxGraphModel>",
Preferences: []string{"type:inlet,active:1,min:15,max:30"},
TopologyOptions: cloudhub.TopologyOptions{
MinimapVisible: true,
HostStatusVisible: false,
IPMIVisible: true,
LinkVisible: true,
},
},
{
ID: "",
Organization: "226541",
Diagram: "<mxGraphModel><root></root></mxGraphModel>",
Preferences: []string{"type:inlet,active:1,min:15,max:30"},
TopologyOptions: cloudhub.TopologyOptions{
MinimapVisible: false,
HostStatusVisible: true,
IPMIVisible: false,
LinkVisible: true,
},
},
}

Expand All @@ -56,11 +68,17 @@ func TestTopologiesStore(t *testing.T) {
tss[1].Preferences = []string{
"type:inlet,active:1,min:15,max:30",
}
tss[1].TopologyOptions = cloudhub.TopologyOptions{
MinimapVisible: true,
HostStatusVisible: true,
IPMIVisible: true,
LinkVisible: false,
}
if err := s.Update(ctx, &tss[1]); err != nil {
t.Fatal(err)
}

// Confirm topology have updated.
// Confirm topology has updated.
ts, err := s.Get(ctx, cloudhub.TopologyQuery{ID: &tss[1].ID})
fmt.Println(ts)
if err != nil {
Expand All @@ -69,9 +87,11 @@ func TestTopologiesStore(t *testing.T) {
t.Fatalf("topology 1 update error: got %v, expected %v", ts.Diagram, "<mxGraphModel><root><mxCell></mxCell></root></mxGraphModel>")
} else if ts.Preferences[0] != "type:inlet,active:1,min:15,max:30" {
t.Fatalf("topology 1 update error: got %v, expected %v", ts.Preferences[0], "type:inlet,active:1,min:15,max:30")
} else if !ts.TopologyOptions.MinimapVisible || !ts.TopologyOptions.HostStatusVisible || !ts.TopologyOptions.IPMIVisible || ts.TopologyOptions.LinkVisible {
t.Fatalf("topology 1 update error: topology options not updated correctly")
}

// Delete an topology.
// Delete a topology.
if err := s.Delete(ctx, ts); err != nil {
t.Fatal(err)
}
Expand Down
44 changes: 42 additions & 2 deletions backend/server/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"info": {
"title": "CloudHub",
"description": "API endpoints for CloudHub",
"version": "1.4.8"
"version": "1.4.9"
},
"schemes": ["http"],
"basePath": "/cloudhub/v1",
Expand Down Expand Up @@ -8129,6 +8129,27 @@
"password": "dkeidj@!@"
}
},
"TopologyOptions": {
"type": "object",
"properties": {
"minimapVisible": {
"type": "boolean",
"description": "Visibility of the minimap"
},
"hostStatusVisible": {
"type": "boolean",
"description": "Visibility of the host status"
},
"ipmiVisible": {
"type": "boolean",
"description": "Visibility of the IPMI (Intelligent Platform Management Interface)"
},
"linkVisible": {
"type": "boolean",
"description": "Visibility of the network links"
}
}
},
"InventoryTopologyReq": {
"type": "object",
"description": "inventory topology diagram xml content",
Expand All @@ -8149,6 +8170,9 @@
"type:inside,active:1,min:56,max:55",
"type:outlet,active:0,min:34,max:50"
]
},
"topologyOptions": {
"$ref": "#/definitions/TopologyOptions"
}
}
},
Expand Down Expand Up @@ -8176,9 +8200,19 @@
"type": "string"
}
},
"topologyOptions": {
"$ref": "#/definitions/TopologyOptions"
},
"links": {"type": "string", "description": "self url"}
},
"required": ["id", "organization", "diagram", "links", "preferences"],
"required": [
"id",
"organization",
"diagram",
"links",
"preferences",
"topologyOptions"
],
"example": {
"id": "1",
"organization": "2",
Expand All @@ -8190,6 +8224,12 @@
],
"links": {
"self": "/cloudhub/v1/topologies/1"
},
"topologyOptions": {
"minimapVisible": true,
"hostStatusVisible": true,
"ipmiVisible": true,
"linkVisible": true
}
}
},
Expand Down
46 changes: 37 additions & 9 deletions backend/server/topologys.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,20 @@ import (
)

type topologyResponse struct {
ID string `json:"id"`
Organization string `json:"organization"`
Links selfLinks `json:"links"`
Diagram string `json:"diagram,omitempty"`
Preferences []string `json:"preferences,omitempty"`
ID string `json:"id"`
Organization string `json:"organization"`
Links selfLinks `json:"links"`
Diagram string `json:"diagram,omitempty"`
Preferences []string `json:"preferences,omitempty"`
TopologyOptions cloudhub.TopologyOptions `json:"topologyOptions,omitempty"`
}

// RequestBody represents the structure of the request payload
// containing cells, user preferences, and topology options for the topology.
type RequestBody struct {
Cells string `json:"cells"`
Preferences []string `json:"preferences"`
Cells string `json:"cells"`
Preferences []string `json:"preferences"`
TopologyOptions cloudhub.TopologyOptions `json:"topologyOptions"`
}

func newTopologyResponse(t *cloudhub.Topology, resDiagram bool) *topologyResponse {
Expand All @@ -32,6 +36,12 @@ func newTopologyResponse(t *cloudhub.Topology, resDiagram bool) *topologyRespons
Organization: t.Organization,
Links: selfLinks{Self: selfLink},
Preferences: t.Preferences,
TopologyOptions: cloudhub.TopologyOptions{
MinimapVisible: t.TopologyOptions.MinimapVisible,
HostStatusVisible: t.TopologyOptions.HostStatusVisible,
IPMIVisible: t.TopologyOptions.IPMIVisible,
LinkVisible: t.TopologyOptions.LinkVisible,
},
}

if resDiagram {
Expand Down Expand Up @@ -60,6 +70,12 @@ func (s *Service) Topology(w http.ResponseWriter, r *http.Request) {
ID: "",
Organization: "",
Links: selfLinks{Self: ""},
TopologyOptions: cloudhub.TopologyOptions{
MinimapVisible: true,
HostStatusVisible: true,
IPMIVisible: true,
LinkVisible: true,
},
}
encodeJSON(w, http.StatusOK, res, s.Logger)
return
Expand Down Expand Up @@ -102,6 +118,12 @@ func (s *Service) NewTopology(w http.ResponseWriter, r *http.Request) {
Diagram: requestData.Cells,
Preferences: requestData.Preferences,
Organization: defaultOrg.ID,
TopologyOptions: cloudhub.TopologyOptions{
MinimapVisible: requestData.TopologyOptions.MinimapVisible,
HostStatusVisible: requestData.TopologyOptions.HostStatusVisible,
IPMIVisible: requestData.TopologyOptions.IPMIVisible,
LinkVisible: requestData.TopologyOptions.LinkVisible,
},
}

if err := ValidTopologRequest(topology, defaultOrg.ID); err != nil {
Expand All @@ -115,7 +137,7 @@ func (s *Service) NewTopology(w http.ResponseWriter, r *http.Request) {
return
}

// log registrationte
// log registration
org, _ := s.Store.Organizations(ctx).Get(ctx, cloudhub.OrganizationQuery{ID: &res.Organization})
msg := fmt.Sprintf(MsgTopologyCreated.String(), org.Name)
s.logRegistration(ctx, "Topologies", msg)
Expand Down Expand Up @@ -190,14 +212,20 @@ func (s *Service) UpdateTopology(w http.ResponseWriter, r *http.Request) {

topology.Diagram = requestData.Cells
topology.Preferences = requestData.Preferences
topology.TopologyOptions = cloudhub.TopologyOptions{
MinimapVisible: requestData.TopologyOptions.MinimapVisible,
HostStatusVisible: requestData.TopologyOptions.HostStatusVisible,
IPMIVisible: requestData.TopologyOptions.IPMIVisible,
LinkVisible: requestData.TopologyOptions.LinkVisible,
}

if err := s.Store.Topologies(ctx).Update(ctx, topology); err != nil {
msg := fmt.Sprintf("Error updating topology ID %s: %v", id, err)
Error(w, http.StatusInternalServerError, msg, s.Logger)
return
}

// log registrationte
// log registration
org, _ := s.Store.Organizations(ctx).Get(ctx, cloudhub.OrganizationQuery{ID: &topology.Organization})
msg := fmt.Sprintf(MsgTopologyModified.String(), org.Name)
s.logRegistration(ctx, "Topologies", msg)
Expand Down
Loading

0 comments on commit c3a0932

Please sign in to comment.