forked from PelicanPlatform/pelican
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Local lint & Director CLI hookup + bug fixes
PR #7 introduced a framework for including the Director in the Pelican CLI, toward making all Pelican services available under a single binary. This commit extends that PR to hook the Director package up to the CLI, the Pelican's configuration mechanisms, and to actually sort out a few bugs related to the untested director code. It should be noted that there are currently a few hacks in the code that need clearing up before any merge, but as of now the commit makes the following possible: `pelican director serve --cache-port 8000` This will serve the Director's cache-redirection service on port 8000 using a gin engine. When we've figured out how to handle Origin redirects and implemented an origin-redirect service, we'll be able to do: `pelican director serve --cache-port 8000 --origin-port 8001` to split apart the two endpoints. As for the local lint... I'm still trying to figure out how to shut that feature off in my editor. Sorry for the noise!
- Loading branch information
1 parent
62a0dd3
commit bc56423
Showing
10 changed files
with
253 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Copyright © 2023 Justin Hiemstra <jhiemstra@morgridge.org> | ||
*/ | ||
package main | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
// directorCmd represents the director command | ||
var ( | ||
directorCmd = &cobra.Command{ | ||
Use: "director", | ||
Short: "Launch a Pelican Director", | ||
Long: `Launch a Pelican Director service: | ||
The Pelican Director is responsible for origin/cache discovery within | ||
the Pelican Platform. When a client asks the Director how to obtain a | ||
specific namespaced resource, the Director will respond with the info | ||
needed by the client (usually a cache and some authentication details) | ||
to obtain that information. When a cache asks the Director for the same | ||
namespaced resource, the Director will point the cache to the origin | ||
responsible for serving the object.`, | ||
} | ||
|
||
directorServeCmd = &cobra.Command{ | ||
Use: "serve", | ||
Short: "serve the director service", | ||
RunE: serveDirector, | ||
SilenceUsage: true, | ||
} | ||
) | ||
|
||
func init() { | ||
// Tie the directorServe command to the root CLI command | ||
directorCmd.AddCommand(directorServeCmd) | ||
|
||
// Set up flags for the command | ||
directorServeCmd.Flags().StringP("cache-port", "p", "", "Set the port to which the Director's cache redirect service should be bound") | ||
err := viper.BindPFlag("cachePort", directorServeCmd.Flags().Lookup("cache-port")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
directorServeCmd.Flags().StringP("origin-port", "P", "", "Set the port to which the Director's origin redirect service should be bound") | ||
err = viper.BindPFlag("originPort", directorServeCmd.Flags().Lookup("origin-port")) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/gin-gonic/gin" | ||
"github.com/pelicanplatform/pelican/director" | ||
log "github.com/sirupsen/logrus" | ||
"github.com/spf13/cobra" | ||
"github.com/spf13/viper" | ||
) | ||
|
||
func serveDirector( /*cmd*/ *cobra.Command /*args*/, []string) error { | ||
log.Info("Initializing Director GeoIP database...") | ||
director.InitializeDB() | ||
|
||
log.Info("Generating/advertising server ads...") | ||
director.AdvertiseOSDF() | ||
|
||
gin.SetMode(gin.ReleaseMode) | ||
cacheEngine := gin.Default() | ||
director.RegisterDirector(cacheEngine.Group("/")) | ||
|
||
// Eventually we'll want a redirect-to-origin service split off | ||
// on another port. Can we use a groutine to handle that here? | ||
cachePort := viper.GetString("cachePort") | ||
//originPort := viper.GetString("originPort") | ||
log.Info("Serving cache redirector on port", cachePort) | ||
err := cacheEngine.Run(":" + cachePort) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.