Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Origins now advertise themselves as writebackhosts #512

Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Origins now advertise themselves as writebackhosts
This is a bandaid fix for now to allow origins to show themselves as
writeback hosts to allow for puts. This helps seperate them from relying
on topology to get this information. This is just a band-aid for now, as
we should make the writebackhost configurable and able to be set or not
set when an origin is spun up.
joereuss12 committed Dec 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 614fa76379694a65176bcbd6c98ec9d449388b1f
7 changes: 6 additions & 1 deletion client/director.go
Original file line number Diff line number Diff line change
@@ -74,6 +74,7 @@ func CreateNsFromDirectorResp(dirResp *http.Response) (namespace namespaces.Name
namespace.UseTokenOnRead, _ = strconv.ParseBool(xPelicanNamespace["require-token"])
namespace.ReadHTTPS, _ = strconv.ParseBool(xPelicanNamespace["readhttps"])
namespace.DirListHost = xPelicanNamespace["collections-url"]
namespace.WritebackHost = xPelicanNamespace["writebackhost"]

var xPelicanAuthorization map[string]string
if len(dirResp.Header.Values("X-Pelican-Authorization")) > 0 {
@@ -125,7 +126,11 @@ func CreateNsFromDirectorResp(dirResp *http.Response) (namespace namespaces.Name
}

func QueryDirector(source string, directorUrl string) (resp *http.Response, err error) {
resourceUrl := directorUrl + source
resourceUrl, err := url.JoinPath(directorUrl, source)
if err != nil {
return nil, err
}

// Here we use http.Transport to prevent the client from following the director's
// redirect. We use the Location url elsewhere (plus we still need to do the token
// dance!)
4 changes: 2 additions & 2 deletions client/handle_http.go
Original file line number Diff line number Diff line change
@@ -835,7 +835,7 @@ func UploadFile(src string, origDest *url.URL, token string, namespace namespace
}

// Parse the writeback host as a URL
writebackhostUrl, err := url.Parse(namespace.WriteBackHost)
writebackhostUrl, err := url.Parse(namespace.WritebackHost)
if err != nil {
return 0, err
}
@@ -1089,7 +1089,7 @@ func StatHttp(dest *url.URL, namespace namespaces.Namespace) (uint64, error) {
}

// Parse the writeback host as a URL
writebackhostUrl, err := url.Parse(namespace.WriteBackHost)
writebackhostUrl, err := url.Parse(namespace.WritebackHost)
if err != nil {
return 0, err
}
2 changes: 1 addition & 1 deletion client/handle_http_test.go
Original file line number Diff line number Diff line change
@@ -389,7 +389,7 @@ func TestFullUpload(t *testing.T) {
testURL, err := url.Parse(ts.URL)
assert.NoError(t, err, "Error parsing test URL")
testNamespace := namespaces.Namespace{
WriteBackHost: "https://" + testURL.Host,
WritebackHost: "https://" + testURL.Host,
}

// Upload the file
36 changes: 26 additions & 10 deletions client/main.go
Original file line number Diff line number Diff line change
@@ -498,13 +498,33 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
// For write back, it will be the destination
// For read it will be the source.

OSDFDirectorUrl := param.Federation_DirectorUrl.GetString()
useOSDFDirector := viper.IsSet("Federation.DirectorURL")

var ns namespaces.Namespace

if destScheme == "stash" || destScheme == "osdf" || destScheme == "pelican" {
log.Debugln("Detected writeback")
ns, err := namespaces.MatchNamespace(dest_url.Path)
if err != nil {
log.Errorln("Failed to get namespace information:", err)
AddError(err)
return 0, err
// If we have a director set, go through that for namespace info, otherwise use topology
if useOSDFDirector {
destination = strings.TrimPrefix(destination, destScheme+"://")
dirResp, err := QueryDirector(destination, OSDFDirectorUrl)
if err != nil {
log.Errorln("Error while querying the Director:", err)
AddError(err)
return 0, err
}
ns, err = CreateNsFromDirectorResp(dirResp)
if err != nil {
AddError(err)
return 0, err
}
} else {
ns, err = namespaces.MatchNamespace(dest_url.Path)
if err != nil {
AddError(err)
return 0, err
}
}
_, err = doWriteBack(source_url.Path, dest_url, ns, recursive)
AddError(err)
@@ -522,11 +542,7 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
if string(sourceFile[0]) != "/" {
sourceFile = "/" + sourceFile
}

OSDFDirectorUrl := param.Federation_DirectorUrl.GetString()
useOSDFDirector := viper.IsSet("Federation.DirectorURL")

var ns namespaces.Namespace
// If we have a director set, go through that for namespace info, otherwise use topology
if useOSDFDirector {
dirResp, err := QueryDirector(sourceFile, OSDFDirectorUrl)
if err != nil {
2 changes: 1 addition & 1 deletion cmd/director_serve.go
Original file line number Diff line number Diff line change
@@ -60,8 +60,8 @@ func serveDirector( /*cmd*/ *cobra.Command /*args*/, []string) error {
if err := director.AdvertiseOSDF(); err != nil {
panic(err)
}
go director.PeriodicCacheReload()
}
go director.PeriodicCacheReload()

director.ConfigTTLCache(shutdownCtx, &wg)
wg.Add(1) // Add to wait group after ConfigTTLCache finishes to avoid deadlock
1 change: 1 addition & 0 deletions director/cache_ads.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ type (
BasePath string `json:"basePath"`
VaultServer string `json:"vaultServer"`
DirlistHost string `json:"dirlisthost"`
WritebackHost string `json:"writebackhost"`
}

ServerAd struct {
4 changes: 2 additions & 2 deletions director/redirect.go
Original file line number Diff line number Diff line change
@@ -227,8 +227,8 @@ func RedirectToCache(ginCtx *gin.Context) {
ginCtx.Writer.Header()["X-Pelican-Token-Generation"] = []string{tokenGen}
}
}
ginCtx.Writer.Header()["X-Pelican-Namespace"] = []string{fmt.Sprintf("namespace=%s, require-token=%v, collections-url=%s",
namespaceAd.Path, namespaceAd.RequireToken, namespaceAd.DirlistHost)}
ginCtx.Writer.Header()["X-Pelican-Namespace"] = []string{fmt.Sprintf("namespace=%s, require-token=%v, collections-url=%s, writebackhost=%s",
namespaceAd.Path, namespaceAd.RequireToken, namespaceAd.DirlistHost, namespaceAd.WritebackHost)}

// Note we only append the `authz` query parameter in the case of the redirect response and not the
// duplicate link metadata above. This is purposeful: the Link header might get too long if we repeat
2 changes: 1 addition & 1 deletion namespaces/namespaces.go
Original file line number Diff line number Diff line change
@@ -86,7 +86,7 @@ type Namespace struct {
Issuer string `json:"issuer"`
ReadHTTPS bool `json:"readhttps"`
UseTokenOnRead bool `json:"usetokenonread"`
WriteBackHost string `json:"writebackhost"`
WritebackHost string `json:"writebackhost"`
DirListHost string `json:"dirlisthost"`
}

2 changes: 1 addition & 1 deletion namespaces/namespaces_test.go
Original file line number Diff line number Diff line change
@@ -175,7 +175,7 @@ func TestFullNamespace(t *testing.T) {
assert.Equal(t, true, ns.ReadHTTPS)
assert.Equal(t, true, ns.UseTokenOnRead)
assert.Equal(t, "/ospool/PROTECTED", ns.Path)
assert.Equal(t, "https://origin-auth2001.chtc.wisc.edu:1095", ns.WriteBackHost)
assert.Equal(t, "https://origin-auth2001.chtc.wisc.edu:1095", ns.WritebackHost)

}

2 changes: 2 additions & 0 deletions origin_ui/advertise.go
Original file line number Diff line number Diff line change
@@ -62,6 +62,8 @@ func (server *OriginServer) CreateAdvertisement(name string, originUrl string, o
MaxScopeDepth: 3,
Strategy: "OAuth2",
BasePath: prefix,
// TODO: This is set to the origin for now needs to become configurable
WritebackHost: originUrl,
}
ad = director.OriginAdvertise{
Name: name,