Skip to content

Commit

Permalink
Merge pull request PelicanPlatform#177 from bbockelm/client-module
Browse files Browse the repository at this point in the history
Refactor the client to be in a sub-package
  • Loading branch information
turetske authored Oct 3, 2023
2 parents 6b617d3 + 581cc4f commit d0729f2
Show file tree
Hide file tree
Showing 26 changed files with 60 additions and 60 deletions.
2 changes: 1 addition & 1 deletion acquire_token.go → client/acquire_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion director.go → client/director.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"net/http"
Expand Down
2 changes: 1 addition & 1 deletion director_test.go → client/director_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion errorAccum.go → client/errorAccum.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion errorAccum_test.go → client/errorAccum_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion get_best_cache.go → client/get_best_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"bytes"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package pelican
package client

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion handle_http.go → client/handle_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"context"
Expand Down
2 changes: 1 addition & 1 deletion handle_http_test.go → client/handle_http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion handle_ingest.go → client/handle_ingest.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion main.go → client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion main_test.go → client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import (
"net"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion unique_hash_darwin.go → client/unique_hash_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
***************************************************************/

package pelican
package client

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion unique_hash_linux.go → client/unique_hash_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
***************************************************************/

package pelican
package client

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion unique_hash_windows.go → client/unique_hash_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*
***************************************************************/

package pelican
package client

import (
"bytes"
Expand Down
2 changes: 1 addition & 1 deletion util.go → client/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
***************************************************************/

package pelican
package client

import "fmt"

Expand Down
4 changes: 2 additions & 2 deletions cmd/config_mgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"os"
"path"

"github.com/pelicanplatform/pelican"
"github.com/pelicanplatform/pelican/client"
"github.com/pelicanplatform/pelican/config"
"github.com/pelicanplatform/pelican/namespaces"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -149,7 +149,7 @@ func addTokenSubcommands(tokenCmd *cobra.Command) {
os.Exit(1)
}

token, err := pelican.AcquireToken(&dest, namespace, isWrite)
token, err := client.AcquireToken(&dest, namespace, isWrite)
if err != nil {
fmt.Fprintln(os.Stderr, "Failed to get a token:", err)
os.Exit(1)
Expand Down
36 changes: 18 additions & 18 deletions cmd/object_copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"path/filepath"
"strings"

"github.com/pelicanplatform/pelican"
"github.com/pelicanplatform/pelican/client"
"github.com/pelicanplatform/pelican/config"
"github.com/pelicanplatform/pelican/namespaces"
log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -72,7 +72,7 @@ func init() {

func copyMain(cmd *cobra.Command, args []string) {

pelican.ObjectClientOptions.Version = version
client.ObjectClientOptions.Version = version

if val, err := cmd.Flags().GetBool("debug"); err == nil && val {
setLogging(log.DebugLevel)
Expand All @@ -95,14 +95,14 @@ func copyMain(cmd *cobra.Command, args []string) {
}

// Set the progress bars to the command line option
pelican.ObjectClientOptions.Token, _ = cmd.Flags().GetString("token")
client.ObjectClientOptions.Token, _ = cmd.Flags().GetString("token")

// Check if the program was executed from a terminal
// https://rosettacode.org/wiki/Check_output_device_is_a_terminal#Go
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
pelican.ObjectClientOptions.ProgressBars = true
client.ObjectClientOptions.ProgressBars = true
} else {
pelican.ObjectClientOptions.ProgressBars = false
client.ObjectClientOptions.ProgressBars = false
}

if val, err := cmd.Flags().GetBool("namespaces"); err == nil && val {
Expand All @@ -119,7 +119,7 @@ func copyMain(cmd *cobra.Command, args []string) {
// Print out all of the caches and exit
if val, err := cmd.Flags().GetBool("list-names"); err == nil && val {
listName, _ := cmd.Flags().GetString("cache-list-name")
cacheList, err := pelican.GetBestCache(listName)
cacheList, err := client.GetBestCache(listName)
if err != nil {
log.Errorln("Failed to get best caches:", err)
os.Exit(1)
Expand All @@ -135,7 +135,7 @@ func copyMain(cmd *cobra.Command, args []string) {
log.Errorln("Failed to determine correct cache list")
os.Exit(1)
}
cacheList, err := pelican.GetBestCache(listName)
cacheList, err := client.GetBestCache(listName)
if err != nil {
log.Errorln("Failed to get best cache: ", err)
}
Expand All @@ -162,21 +162,21 @@ func copyMain(cmd *cobra.Command, args []string) {
nearestCache, nearestCacheIsPresent := os.LookupEnv("NEAREST_CACHE")

if nearestCacheIsPresent {
pelican.NearestCache = nearestCache
pelican.NearestCacheList = append(pelican.NearestCacheList, pelican.NearestCache)
pelican.CacheOverride = true
client.NearestCache = nearestCache
client.NearestCacheList = append(client.NearestCacheList, client.NearestCache)
client.CacheOverride = true
} else if cache, _ := cmd.Flags().GetString("cache"); cache != "" {
pelican.NearestCache = cache
pelican.NearestCacheList = append(pelican.NearestCacheList, cache)
pelican.CacheOverride = true
client.NearestCache = cache
client.NearestCacheList = append(client.NearestCacheList, cache)
client.CacheOverride = true
}

// Convert the methods
methodNames, _ := cmd.Flags().GetString("methods")
splitMethods := strings.Split(methodNames, ",")

// If the user overrides the cache, then only use HTTP
if pelican.CacheOverride {
if client.CacheOverride {
splitMethods = []string{"http"}
}

Expand All @@ -193,25 +193,25 @@ func copyMain(cmd *cobra.Command, args []string) {
for _, src := range source {
var tmpDownloaded int64
isRecursive, _ := cmd.Flags().GetBool("recursive")
tmpDownloaded, result = pelican.DoStashCPSingle(src, dest, splitMethods, isRecursive)
tmpDownloaded, result = client.DoStashCPSingle(src, dest, splitMethods, isRecursive)
downloaded += tmpDownloaded
if result != nil {
lastSrc = src
break
} else {
pelican.ClearErrors()
client.ClearErrors()
}
}

// Exit with failure
if result != nil {
// Print the list of errors
errMsg := pelican.GetErrors()
errMsg := client.GetErrors()
if errMsg == "" {
errMsg = result.Error()
}
log.Errorln("Failure transferring " + lastSrc + ": " + errMsg)
if pelican.ErrorsRetryable() {
if client.ErrorsRetryable() {
log.Errorln("Errors are retryable")
os.Exit(11)
}
Expand Down
24 changes: 12 additions & 12 deletions cmd/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"strings"
"time"

"github.com/pelicanplatform/pelican"
"github.com/pelicanplatform/pelican/classads"
"github.com/pelicanplatform/pelican/client"
"github.com/pelicanplatform/pelican/config"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -75,9 +75,9 @@ func stashPluginMain(args []string) {
// Parse command line arguments
var upload bool = false
// Set the options
pelican.ObjectClientOptions.Recursive = false
pelican.ObjectClientOptions.ProgressBars = false
pelican.ObjectClientOptions.Version = version
client.ObjectClientOptions.Recursive = false
client.ObjectClientOptions.ProgressBars = false
client.ObjectClientOptions.Version = version
setLogging(log.PanicLevel)
methods := []string{"http"}
var infile, outfile, testCachePath string
Expand Down Expand Up @@ -134,12 +134,12 @@ func stashPluginMain(args []string) {
}

if getCaches {
urls, err := pelican.GetCacheHostnames(testCachePath)
urls, err := client.GetCacheHostnames(testCachePath)
if err != nil {
log.Panicln("Failed to get cache URLs:", err)
}

cachesToTry := pelican.CachesToTry
cachesToTry := client.CachesToTry
if cachesToTry > len(urls) {
cachesToTry = len(urls)
}
Expand Down Expand Up @@ -190,11 +190,11 @@ func stashPluginMain(args []string) {
if upload {
source = append(source, transfer.localFile)
log.Debugln("Uploading:", transfer.localFile, "to", transfer.url)
tmpDownloaded, result = pelican.DoStashCPSingle(transfer.localFile, transfer.url, methods, false)
tmpDownloaded, result = client.DoStashCPSingle(transfer.localFile, transfer.url, methods, false)
} else {
source = append(source, transfer.url)
log.Debugln("Downloading:", transfer.url, "to", transfer.localFile)
tmpDownloaded, result = pelican.DoStashCPSingle(transfer.url, transfer.localFile, methods, false)
tmpDownloaded, result = client.DoStashCPSingle(transfer.url, transfer.localFile, methods, false)
}
startTime := time.Now().Unix()
resultAd := classads.NewClassAd()
Expand All @@ -216,7 +216,7 @@ func stashPluginMain(args []string) {
resultAd.Set("TransferTotalBytes", tmpDownloaded)
} else {
resultAd.Set("TransferSuccess", false)
if pelican.GetErrors() == "" {
if client.GetErrors() == "" {
resultAd.Set("TransferError", result.Error())
} else {
errMsg := " Failure "
Expand All @@ -225,13 +225,13 @@ func stashPluginMain(args []string) {
} else {
errMsg += "downloading "
}
errMsg += transfer.url + ": " + pelican.GetErrors()
errMsg += transfer.url + ": " + client.GetErrors()
resultAd.Set("TransferError", errMsg)
pelican.ClearErrors()
client.ClearErrors()
}
resultAd.Set("TransferFileBytes", 0)
resultAd.Set("TransferTotalBytes", 0)
if pelican.ErrorsRetryable() {
if client.ErrorsRetryable() {
resultAd.Set("TransferRetryable", true)
retryable = true
} else {
Expand Down
14 changes: 7 additions & 7 deletions cmd/plugin_stage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ import (
"regexp"
"strings"

"github.com/pelicanplatform/pelican"
"github.com/pelicanplatform/pelican/classads"
"github.com/pelicanplatform/pelican/client"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -115,14 +115,14 @@ func stagePluginMain(cmd *cobra.Command, args []string) {
}

// Set the progress bars to the command line option
pelican.ObjectClientOptions.Token = viper.GetString("StagePlugin.Token")
client.ObjectClientOptions.Token = viper.GetString("StagePlugin.Token")

// Check if the program was executed from a terminal
// https://rosettacode.org/wiki/Check_output_device_is_a_terminal#Go
if fileInfo, _ := os.Stdout.Stat(); (fileInfo.Mode() & os.ModeCharDevice) != 0 {
pelican.ObjectClientOptions.ProgressBars = true
client.ObjectClientOptions.ProgressBars = true
} else {
pelican.ObjectClientOptions.ProgressBars = false
client.ObjectClientOptions.ProgressBars = false
}

var sources []string
Expand Down Expand Up @@ -185,7 +185,7 @@ func stagePluginMain(cmd *cobra.Command, args []string) {
var result error
var xformSources []string
for _, src := range sources {
_, newSource, result := pelican.DoShadowIngest(src, mountPrefixStr, shadowOriginPrefixStr)
_, newSource, result := client.DoShadowIngest(src, mountPrefixStr, shadowOriginPrefixStr)
if result != nil {
// What's the correct behavior on failure? For now, we silently put the transfer
// back on the original list. This is arguably the wrong approach as it might
Expand All @@ -202,8 +202,8 @@ func stagePluginMain(cmd *cobra.Command, args []string) {
// Exit with failure
if result != nil {
// Print the list of errors
log.Errorln(pelican.GetErrors())
if pelican.ErrorsRetryable() {
log.Errorln(client.GetErrors())
if client.ErrorsRetryable() {
log.Errorln("Errors are retryable")
os.Exit(11)
}
Expand Down
Loading

0 comments on commit d0729f2

Please sign in to comment.