You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by di...@apache.org on 2026/09/10 14:30:02 UTC
(airavata) branch refactor-single-module updated: SCP file metadata read support
This is an automated email from the ASF dual-hosted git repository.
DImuthuUpe pushed a commit to branch refactor-single-module
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/refactor-single-module by this push:
new a7bc5bce91 SCP file metadata read support
a7bc5bce91 is described below
commit a7bc5bce916dc0ab1bb0c702b201fd9da31fdfc7
Author: DImuthuUpe <di...@gmail.com>
AuthorDate: Thu Sep 10 10:29:56 2026 -0400
SCP file metadata read support
---
internal/orchestration/activities/data.go | 25 ++++++++++++
internal/orchestration/activities/ssh.go | 56 ++++++++++++++++++++++-----
internal/orchestration/activities/ssh_test.go | 22 +++++++++++
3 files changed, 94 insertions(+), 9 deletions(-)
diff --git a/internal/orchestration/activities/data.go b/internal/orchestration/activities/data.go
index 9a42ef280c..e398619b7e 100644
--- a/internal/orchestration/activities/data.go
+++ b/internal/orchestration/activities/data.go
@@ -3,8 +3,17 @@ package activities
import (
"context"
"log/slog"
+ "os"
+
+ datamodel "github.com/apache/airavata/api/data/model"
)
+type FileMetadata struct {
+ Path string
+ Size int64
+ Mode os.FileMode
+}
+
func (a *Activities) CopyData(ctx context.Context, processId string, dataStagingTaskId string) (int, error) {
dataStagingTask, err := a.svcs.DataStagingTask.Get(ctx, processId, dataStagingTaskId)
if err != nil {
@@ -12,5 +21,21 @@ func (a *Activities) CopyData(ctx context.Context, processId string, dataStaging
}
slog.Info("Copying data ...", "taskId", dataStagingTask.ID, "processId", dataStagingTask.ProcessID)
+ if *dataStagingTask.SourceDataStorageType == datamodel.DataStorageTypeSCP {
+
+ }
+
+ if *dataStagingTask.SourceDataStorageType == datamodel.DataStorageTypeHPC {
+
+ }
+
+ if *dataStagingTask.DestinationDataStorageType == datamodel.DataStorageTypeSCP {
+
+ }
+
+ if *dataStagingTask.DestinationDataStorageType == datamodel.DataStorageTypeHPC {
+
+ }
+
return 0, nil
}
diff --git a/internal/orchestration/activities/ssh.go b/internal/orchestration/activities/ssh.go
index 1e1832a78f..a3fc4ce829 100644
--- a/internal/orchestration/activities/ssh.go
+++ b/internal/orchestration/activities/ssh.go
@@ -82,6 +82,42 @@ func UploadFileToSCP(ctx context.Context, host string, port int, username string
return nil
}
+// Reads the mode, size and name a remote scp announces for a single remote file,
+// without transferring its contents.
+func GetSCPFileMetadata(ctx context.Context, host string, port int, username string, key credmodel.SSHKey, remotePath string) (*FileMetadata, error) {
+ target := fmt.Sprintf("scp stat %s@%s:%s", username, host, remotePath)
+
+ t, err := intializeSession(ctx, host, port, username, key, "-f", remotePath, target)
+ if err != nil {
+ return nil, err
+ }
+ defer t.close()
+
+ // The opening acknowledgement invites the header, and nothing beyond it.
+ if err := scpAck(t.stdin); err != nil {
+ return nil, t.fail(err)
+ }
+ msg, err := readSCPMessage(t.stdout)
+ if err != nil {
+ return nil, t.fail(err)
+ }
+ if msg[0] != 'C' {
+ return nil, t.fail(fmt.Errorf("remote path is not a plain file: scp announced %q", msg))
+ }
+ mode, size, name, err := parseSCPFileHeader(msg)
+ if err != nil {
+ return nil, t.fail(err)
+ }
+
+ // Path carries the name scp announced, which is the remote basename rather than
+ // the path asked about.
+ return &FileMetadata{
+ Path: name,
+ Size: size,
+ Mode: mode,
+ }, nil
+}
+
// ========================== Utility section =====================================
// scpOK is the byte each side of the SCP wire protocol writes to acknowledge the
@@ -254,7 +290,7 @@ func receiveSCPFile(r *bufio.Reader, w io.Writer, localPath string) error {
return err
}
case 'C':
- mode, size, err := parseSCPFileHeader(msg)
+ mode, size, _, err := parseSCPFileHeader(msg)
if err != nil {
return err
}
@@ -309,23 +345,25 @@ func readSCPMessage(r *bufio.Reader) (string, error) {
return string(kind) + line, nil
}
-// parseSCPFileHeader reads a "C<mode> <size> <name>" header. The name is the remote's
-// basename and is deliberately ignored: the caller chose where the bytes land, and
-// honouring a name the remote picked would let it write outside that path.
-func parseSCPFileHeader(msg string) (os.FileMode, int64, error) {
+// parseSCPFileHeader reads a "C<mode> <size> <name>" header. The name is split off as
+// the last field rather than on every space, because a remote file name may contain
+// them. A download ignores the name — the caller chose where the bytes land, and
+// honouring a name the remote picked would let it write outside that path — but a
+// metadata probe reports it.
+func parseSCPFileHeader(msg string) (os.FileMode, int64, string, error) {
fields := strings.SplitN(msg[1:], " ", 3)
if len(fields) != 3 {
- return 0, 0, fmt.Errorf("malformed scp file header %q", msg)
+ return 0, 0, "", fmt.Errorf("malformed scp file header %q", msg)
}
mode, err := strconv.ParseUint(fields[0], 8, 32)
if err != nil {
- return 0, 0, fmt.Errorf("malformed mode in scp file header %q", msg)
+ return 0, 0, "", fmt.Errorf("malformed mode in scp file header %q", msg)
}
size, err := strconv.ParseInt(fields[1], 10, 64)
if err != nil || size < 0 {
- return 0, 0, fmt.Errorf("malformed size in scp file header %q", msg)
+ return 0, 0, "", fmt.Errorf("malformed size in scp file header %q", msg)
}
- return os.FileMode(mode).Perm(), size, nil
+ return os.FileMode(mode).Perm(), size, fields[2], nil
}
// writeLocalFile stages size bytes into a sibling temporary file and renames it into
diff --git a/internal/orchestration/activities/ssh_test.go b/internal/orchestration/activities/ssh_test.go
index 66f6574e7a..fd996bb700 100644
--- a/internal/orchestration/activities/ssh_test.go
+++ b/internal/orchestration/activities/ssh_test.go
@@ -92,4 +92,26 @@ func TestSCPUpload(t *testing.T) {
t.Fatalf("SCP upload failed: %v", err)
}
t.Logf("SCP upload completed in %v", time.Since(startTime))
+
+ metadata, err := GetSCPFileMetadata(t.Context(), host, 22, username, credmodel.SSHKey{
+ PrivateKey: privateKeyStr,
+ Passphrase: &passphrase,
+ }, "/home/"+username+"/randomupload.bin")
+
+ if err != nil {
+ t.Fatalf("Failed to get SCP file metadata: %v", err)
+ }
+
+ if metadata == nil {
+ t.Fatalf("SCP file metadata is nil")
+ }
+
+ if metadata.Size != int64(len("random data")) {
+ t.Fatalf("SCP file size mismatch: expected %d, got %d", len("random data"), metadata.Size)
+ }
+
+ if !metadata.Mode.Perm().IsRegular() {
+ t.Fatalf("SCP file mode mismatch: expected a regular file")
+ }
+ t.Logf("SCP file metadata: %+v", metadata)
}