Skip to content

Commit

Permalink
Address code review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
haoming29 committed Feb 5, 2024
1 parent 199d983 commit 8784f7b
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 48 deletions.
3 changes: 2 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,6 @@ func InitServer(ctx context.Context, currentServers ServerType) error {
viper.SetDefault("OIDC.ClientSecretFile", filepath.Join(configDir, "oidc-client-secret"))
viper.SetDefault("Cache.ExportLocation", "/")
viper.SetDefault("Registry.RequireKeyChaining", true)
viper.SetDefault("Shoveler.TokenLocation", "/etc/pelican/shoveler-token")
if IsRootExecution() {
viper.SetDefault("Xrootd.RunLocation", filepath.Join("/run", "pelican", "xrootd", xrootdPrefix))
viper.SetDefault("Cache.DataLocation", "/run/pelican/xcache")
Expand All @@ -669,11 +668,13 @@ func InitServer(ctx context.Context, currentServers ServerType) error {
viper.SetDefault("Registry.DbLocation", "/var/lib/pelican/registry.sqlite")
viper.SetDefault("Monitoring.DataLocation", "/var/lib/pelican/monitoring/data")
viper.SetDefault("Shoveler.QueueDirectory", "/var/spool/pelican/shoveler/queue")
viper.SetDefault("Shoveler.AMQPTokenLocation", "/etc/pelican/shoveler-token")
} else {
viper.SetDefault("Director.GeoIPLocation", filepath.Join(configDir, "maxmind", "GeoLite2-City.mmdb"))
viper.SetDefault("Registry.DbLocation", filepath.Join(configDir, "ns-registry.sqlite"))
viper.SetDefault("Monitoring.DataLocation", filepath.Join(configDir, "monitoring/data"))
viper.SetDefault("Shoveler.QueueDirectory", filepath.Join(configDir, "shoveler/queue"))
viper.SetDefault("Shoveler.AMQPTokenLocation", filepath.Join(configDir, "shoveler-token"))

if userRuntimeDir := os.Getenv("XDG_RUNTIME_DIR"); userRuntimeDir != "" {
runtimeDir := filepath.Join(userRuntimeDir, "pelican", xrootdPrefix)
Expand Down
2 changes: 1 addition & 1 deletion config/resources/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ Shoveler:
MessageQueueProtocol: amqp
PortLower: 9930
PortHigher: 9999
Exchange: shoveled-xrd
AMQPExchange: shoveled-xrd
Xrootd:
Port: 8443
Mount: ""
Expand Down
41 changes: 21 additions & 20 deletions docs/parameters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1342,17 +1342,17 @@ description: >-
For amqp, the following configurations are required:
- URL: amqps://username:password@example.com/vhost
- Exchange: shoveled-xrd
- Topic: mytopic
- TokenLocation: /etc/pelican/xrootd-monitoring-shoveler-token
- AMQPExchange: shoveled-xrd
- AMQPTokenLocation: /etc/pelican/xrootd-monitoring-shoveler-token
For stomp, the following configurations are required:
- User: username
- Password: password
- URL: messagebroker.org:port
- Topic: mytopic
- Cert: path/to/cert/file
- CertKey: path/to/certkey/file
- StompUsername: username
- StompPassword: password
- StompCert: path/to/cert/file
- StompCertKey: path/to/certkey/file
type: string
default: amqp
components: ["origin", "cache"]
Expand All @@ -1366,34 +1366,35 @@ type: url
default: none
components: ["origin", "cache"]
---
name: Shoveler.Exchange
name: Shoveler.Topic
description: >-
For amqp only.
For amqp and stomp.
The exchange to shovel messages
The topic of the messages. For stomp, it defaults to xrootd.shoveler
type: string
default: "shoveled-xrd"
default: none
components: ["origin", "cache"]
---
name: Shoveler.Topic
name: Shoveler.AMQPExchange
description: >-
For amqp and stomp.
For amqp only.
The topic of the messages. For stomp, it defaults to xrootd.shoveler
The exchange to shovel messages
type: string
default: none
default: "shoveled-xrd"
components: ["origin", "cache"]
---
name: Shoveler.TokenLocation
name: Shoveler.AMQPTokenLocation
description: >-
For amqp only.
A filepath to the location of the JWT used for authenticating amqp connection
type: filename
default: /etc/pelican/shoveler-token
default: $ConfigBase/shoveler-token
root_default: /etc/pelican/shoveler-token
components: ["origin", "cache"]
---
name: Shoveler.Username
name: Shoveler.StompUsername
description: >-
For stomp only.
Expand All @@ -1402,7 +1403,7 @@ type: string
default: none
components: ["origin", "cache"]
---
name: Shoveler.Password
name: Shoveler.StompPassword
description: >-
For stomp only.
Expand All @@ -1411,7 +1412,7 @@ type: string
default: none
components: ["origin", "cache"]
---
name: Shoveler.Cert
name: Shoveler.StompCert
description: >-
For stomp only.
Expand All @@ -1420,7 +1421,7 @@ type: filename
default: none
components: ["origin", "cache"]
---
name: Shoveler.CertKey
name: Shoveler.StompCertKey
description: >-
For stomp only.
Expand Down
16 changes: 8 additions & 8 deletions metrics/shoveler.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,28 @@ func configShoveler(c *shoveler.Config) error {
log.Debugln("AMQP URL:", c.AmqpURL.String())

// Get the AMQP Exchange
c.AmqpExchange = param.Shoveler_Exchange.GetString()
c.AmqpExchange = param.Shoveler_AMQPExchange.GetString()
log.Debugln("AMQP Exchange:", c.AmqpExchange)

c.AmqpToken = param.Shoveler_TokenLocation.GetString()
c.AmqpToken = param.Shoveler_AMQPTokenLocation.GetString()
log.Debugln("AMQP Token location:", c.AmqpToken)
_, err := os.Stat(c.AmqpToken)
if err != nil {
return fmt.Errorf("Token in Shoveler.TokenLocation does not exists: %s", err.Error())
return fmt.Errorf("Token in Shoveler.AMQPTokenLocation does not exists: %s", err.Error())
}
tokenContents, err := os.ReadFile(c.AmqpToken)
if err != nil {
return fmt.Errorf("Unable to read file: %s", c.AmqpToken)
}
if strings.TrimSpace(string(tokenContents)) == "" {
return fmt.Errorf("Token content is empty. Reading from Shoveler.TokenLocation at %s", c.AmqpToken)
return fmt.Errorf("Token content is empty. Reading from Shoveler.AMQPTokenLocation at %s", c.AmqpToken)
}
} else { // Stomp
viper.SetDefault("Shoveler.Topic", "xrootd.shoveler")

c.StompUser = param.Shoveler_Username.GetString()
c.StompUser = param.Shoveler_StompUsername.GetString()
log.Debugln("STOMP User:", c.StompUser)
c.StompPassword = param.Shoveler_Password.GetString()
c.StompPassword = param.Shoveler_StompPassword.GetString()

// Get the STOMP URL
c.StompURL, err = url.Parse(param.Shoveler_URL.GetString())
Expand All @@ -97,11 +97,11 @@ func configShoveler(c *shoveler.Config) error {
log.Debugln("STOMP Topic:", c.StompTopic)

// Get the STOMP cert
c.StompCert = param.Shoveler_Cert.GetString()
c.StompCert = param.Shoveler_StompCert.GetString()
log.Debugln("STOMP CERT:", c.StompCert)

// Get the STOMP certkey
c.StompCertKey = param.Shoveler_CertKey.GetString()
c.StompCertKey = param.Shoveler_StompCertKey.GetString()
log.Debugln("STOMP CERTKEY:", c.StompCertKey)
}

Expand Down
12 changes: 6 additions & 6 deletions param/parameters.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 12 additions & 12 deletions param/parameters_struct.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8784f7b

Please sign in to comment.