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
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion client/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.PutEndpoint = xPelicanNamespace["putendpoint"]

var xPelicanAuthorization map[string]string
if len(dirResp.Header.Values("X-Pelican-Authorization")) > 0 {
Expand Down Expand Up @@ -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!)
Expand Down
8 changes: 4 additions & 4 deletions client/handle_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,13 @@ func UploadFile(src string, origDest *url.URL, token string, namespace namespace
}

// Parse the writeback host as a URL
writebackhostUrl, err := url.Parse(namespace.WriteBackHost)
putEndpointUrl, err := url.Parse(namespace.PutEndpoint)
if err != nil {
return 0, err
}

dest := &url.URL{
Host: writebackhostUrl.Host,
Host: putEndpointUrl.Host,
Scheme: "https",
Path: origDest.Path,
}
Expand Down Expand Up @@ -1089,11 +1089,11 @@ func StatHttp(dest *url.URL, namespace namespaces.Namespace) (uint64, error) {
}

// Parse the writeback host as a URL
writebackhostUrl, err := url.Parse(namespace.WriteBackHost)
putEndpointUrl, err := url.Parse(namespace.PutEndpoint)
if err != nil {
return 0, err
}
dest.Host = writebackhostUrl.Host
dest.Host = putEndpointUrl.Host
dest.Scheme = "https"

canDisableProxy := CanDisableProxy()
Expand Down
2 changes: 1 addition & 1 deletion client/handle_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
PutEndpoint: "https://" + testURL.Host,
}

// Upload the file
Expand Down
35 changes: 27 additions & 8 deletions client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,13 +498,34 @@ 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")

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 !strings.HasPrefix(destination, "/") {
destination = strings.TrimPrefix(destination, destScheme+"://")
}
var ns namespaces.Namespace
// If we have a director set, go through that for namespace info, otherwise use topology
if useOSDFDirector {
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)
Expand All @@ -523,10 +544,8 @@ func DoStashCPSingle(sourceFile string, destination string, methods []string, re
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 {
Expand Down
2 changes: 1 addition & 1 deletion cmd/director_serve.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions director/advertise.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func AdvertiseOSDF() error {
nsAd.RequireToken = ns.UseTokenOnRead
nsAd.Path = ns.Path
nsAd.DirlistHost = ns.DirlistHost
nsAd.PutEndpoint = ns.PutEndpoint
issuerURL, err := url.Parse(ns.CredentialGeneration.Issuer)
if err != nil {
log.Warningf("Invalid URL %v when parsing topology response: %v\n", ns.CredentialGeneration.Issuer, err)
Expand Down
1 change: 1 addition & 0 deletions director/cache_ads.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type (
BasePath string `json:"basePath"`
VaultServer string `json:"vaultServer"`
DirlistHost string `json:"dirlisthost"`
PutEndpoint string `json:"writebackhost"`
}

ServerAd struct {
Expand Down
4 changes: 2 additions & 2 deletions director/redirect.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, putendpoint=%s",
namespaceAd.Path, namespaceAd.RequireToken, namespaceAd.DirlistHost, namespaceAd.PutEndpoint)}

// 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
Expand Down
2 changes: 1 addition & 1 deletion namespaces/namespaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ type Namespace struct {
Issuer string `json:"issuer"`
ReadHTTPS bool `json:"readhttps"`
UseTokenOnRead bool `json:"usetokenonread"`
WriteBackHost string `json:"writebackhost"`
PutEndpoint string `json:"writebackhost"`
DirListHost string `json:"dirlisthost"`
}

Expand Down
2 changes: 1 addition & 1 deletion namespaces/namespaces_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.PutEndpoint)

}

Expand Down
2 changes: 2 additions & 0 deletions origin_ui/advertise.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
PutEndpoint: originUrl,
}
ad = director.OriginAdvertise{
Name: name,
Expand Down
2 changes: 1 addition & 1 deletion utils/web_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type (
Path string `json:"path"`
ReadHTTPS bool `json:"readhttps"`
UseTokenOnRead bool `json:"usetokenonread"`
WritebackHost string `json:"writebackhost"`
PutEndpoint string `json:"writebackhost"`
}

TopologyNamespacesJSON struct {
Expand Down
Loading