Skip to content
This repository has been archived by the owner on May 30, 2022. It is now read-only.

Commit

Permalink
Additional fixes and cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
rtorrero committed Jul 26, 2021
1 parent 9106f60 commit 99add59
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
2 changes: 1 addition & 1 deletion agent/discovery/sapsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func storeSAPSystemTags(client consul.Client, systems sapsystem.SAPSystemsList)
landName = land.Name
}

sysNames := systems.GetSIDs()
sysNames := systems.GetSIDsString()

// Store host metadata
metadata := hosts.Metadata{
Expand Down
17 changes: 5 additions & 12 deletions internal/hosts/hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,21 @@ func (n *Host) HAChecks() *check.Controls {
return checks
}

func (n *Host) GetSAPSystems() (map[string]*sapsystem.SAPSystem, error) {
func (n *Host) GetSAPSystems() (sapsystem.SAPSystemsMap, error) {
systems, err := sapsystem.Load(n.client, n.Name())
if err != nil {
return nil, err
}
return systems, nil
}

func (n *Host) GetSAPSystemsList() (sapsystem.SAPSystemsList, error) {
systems, err := sapsystem.Load(n.client, n.Name())
func (n *Host) GetSIDsString() string {
systems, err := n.GetSAPSystems()
if err != nil {
return nil, err
}

systemsList := make(sapsystem.SAPSystemsList, len(systems))
var i int
for _, value := range systems {
systemsList[i] = value
i++
return ""
}

return systemsList, nil
return systems.GetSIDsString()
}

// Use github.com/hashicorp/go-bexpr to create the filter
Expand Down
26 changes: 17 additions & 9 deletions internal/sapsystem/sapsystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const (
)

type SAPSystemsList []*SAPSystem
type SAPSystemsMap map[string]*SAPSystem

// A SAPSystem in this context is a SAP installation under one SID.
// It will have application or database type, mutually exclusive
Expand Down Expand Up @@ -77,17 +78,24 @@ type CustomCommand func(name string, arg ...string) *exec.Cmd

var customExecCommand CustomCommand = exec.Command

func (systems SAPSystemsList) GetSIDs() string {
var sysNames string
for i, system := range systems {
separator := ","
if i < 1 {
separator = ""
}
sysNames = strings.Join([]string{sysNames, system.SID}, separator)
func (sm SAPSystemsMap) GetSIDsString() string {
var sidString []string

for _, system := range sm {
sidString = append(sidString, system.SID)
}

return strings.Join(sidString, ",")
}

func (sl SAPSystemsList) GetSIDsString() string {
var sidString []string

for _, system := range sl {
sidString = append(sidString, system.SID)
}

return sysNames
return strings.Join(sidString, ",")
}

func NewSAPSystemsList() (SAPSystemsList, error) {
Expand Down
4 changes: 4 additions & 0 deletions web/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/fs"
"net/http"
"path/filepath"
"strings"

log "github.com/sirupsen/logrus"

Expand Down Expand Up @@ -149,6 +150,9 @@ func (r *LayoutRender) addFileFromFS(templatesFS fs.FS, file string) {
return a + b
},
"markdown": markdownToHTML,
"split": func(s string, sep string) []string {
return strings.Split(s, sep)
},
})
patterns := append([]string{r.root, file}, r.blocks...)
tmpl = template.Must(tmpl.ParseFS(templatesFS, patterns...))
Expand Down
6 changes: 3 additions & 3 deletions web/templates/blocks/hosts_table.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@
</a>
</td>
<td>
{{- range $i, $v := .GetSAPSystemsList }}{{- if $i }},{{- end }}
<a href='/sapsystems/{{ .SID }}?environment={{ index $TrentoMeta "trento-sap-environment" }}&landscape={{ index $TrentoMeta "trento-sap-landscape" }}'>
{{ $v.SID }}
{{- range $i, $v := split .GetSIDsString "," }}{{- if $i }},{{- end }}
<a href='/sapsystems/{{ $v }}?environment={{ index $TrentoMeta "trento-sap-environment" }}&landscape={{ index $TrentoMeta "trento-sap-landscape" }}'>
{{ $v }}
</a>
{{- end }}
</td>
Expand Down
4 changes: 2 additions & 2 deletions web/templates/host.html.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<dd class="inline"><a href="/landscapes/{{ $Land }}?environment={{ $Env }}">{{ $Land }}</a></dd>
<dt class="inline">SAP System</dt>
<dd class="inline">
{{- range $i, $v := .Host.GetSAPSystemsList }}{{- if $i }},{{- end }} <a
href="/sapsystems/{{ $v.SID }}?environment={{ $Env }}&landscape={{ $Land }}">{{ $v.SID }}</a>{{- end }}
{{- range $i, $v := split (.Host).GetSIDsString ","}}{{- if $i }},{{- end }} <a
href="/sapsystems/{{ $v }}?environment={{ $Env }}&landscape={{ $Land }}">{{ $v }}</a>{{- end }}
</dd>

<dt class="inline">Cluster</dt>
Expand Down

0 comments on commit 99add59

Please sign in to comment.