-
Notifications
You must be signed in to change notification settings - Fork 10
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
NOISSUE - Enable WASM Support and FileSystem Support #189
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
5b8bc7e
feat(algorithm): Add wasm as an algo type
rodneyosodo f670295
feat(algorithm): Use filesystem to store results
rodneyosodo f589cf5
test: test new filesystem changes
rodneyosodo b0918c8
refactor(files): rename resultFile to resultsFilePath
rodneyosodo 960267e
feat(wasm-runtime): change from wasmtime to wasmedge
rodneyosodo fa7bd7d
feat(algorithm): send results as zipped directory
rodneyosodo e1e88c3
fix(wasm): runtime argument
rodneyosodo a327e41
fix(errors): provide useful error message
rodneyosodo b3bd5d5
chore(gitignore): add results zip to gitignore
rodneyosodo 442ac77
feat(filesystem): Enable storing results on filesystem for python algos
rodneyosodo 4b76d5c
refactor: revert to upstream cocos repo
rodneyosodo 4a2e6b9
fix: remove AddDataset from algorithm interface
rodneyosodo 30d8ca4
fix: agent to handle results zipping
rodneyosodo f85db39
test: test zipping directories
rodneyosodo e4be311
refactor(agent): Handle file operations from agent
rodneyosodo 5743223
test: run test inside eos
rodneyosodo a144468
refactor(test): Document and test algos are running
rodneyosodo 8415c41
fix: remove witheDataset option
rodneyosodo 089a24e
test: test without dataset argument
rodneyosodo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -10,5 +10,5 @@ cmd/manager/tmp | |
*.pem | ||
|
||
dist/ | ||
result.bin | ||
result.zip | ||
*.spec |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) Ultraviolet | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package algorithm | ||
|
||
import ( | ||
"archive/zip" | ||
"bytes" | ||
"fmt" | ||
"io" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
// ZipDirectory zips a directory and returns the zipped bytes. | ||
func ZipDirectory() ([]byte, error) { | ||
buf := new(bytes.Buffer) | ||
zipWriter := zip.NewWriter(buf) | ||
|
||
err := filepath.Walk(ResultsDir, func(path string, info os.FileInfo, err error) error { | ||
if err != nil { | ||
return fmt.Errorf("error walking the path %q: %v", path, err) | ||
} | ||
|
||
if info.IsDir() { | ||
return nil | ||
} | ||
|
||
relPath, err := filepath.Rel(ResultsDir, path) | ||
if err != nil { | ||
return fmt.Errorf("error getting relative path for %q: %v", path, err) | ||
} | ||
|
||
file, err := os.Open(path) | ||
if err != nil { | ||
return fmt.Errorf("error opening file %q: %v", path, err) | ||
} | ||
defer file.Close() | ||
|
||
zipFile, err := zipWriter.Create(relPath) | ||
if err != nil { | ||
return fmt.Errorf("error creating zip file for %q: %v", path, err) | ||
} | ||
|
||
if _, err = io.Copy(zipFile, file); err != nil { | ||
return fmt.Errorf("error copying file %q to zip: %v", path, err) | ||
} | ||
|
||
return err | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if err = zipWriter.Close(); err != nil { | ||
return nil, err | ||
} | ||
|
||
return buf.Bytes(), 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright (c) Ultraviolet | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package algorithm_test | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/ultravioletrs/cocos/agent/algorithm" | ||
) | ||
|
||
func TestZipDirectory(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
directories []string | ||
files []string | ||
expected []string | ||
}{ | ||
{ | ||
name: "empty directory", | ||
directories: []string{"testdata"}, | ||
}, | ||
{ | ||
name: "single file", | ||
files: []string{"file1.txt"}, | ||
}, | ||
{ | ||
name: "directory with single file", | ||
directories: []string{"testdata"}, | ||
expected: []string{"testdata/file1.txt"}, | ||
}, | ||
{ | ||
name: "directory with multiple files", | ||
directories: []string{"testdata"}, | ||
expected: []string{ | ||
"testdata/file1.txt", | ||
"testdata/file2.txt", | ||
"testdata/file3.txt", | ||
}, | ||
}, | ||
{ | ||
name: "nested directories", | ||
directories: []string{"testdata", "testdata/nested"}, | ||
expected: []string{ | ||
"testdata/nested/file1.txt", | ||
"testdata/nested/file2.txt", | ||
"testdata/nested/file3.txt", | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
if err := os.Mkdir(algorithm.ResultsDir, 0o755); err != nil { | ||
t.Fatalf("error creating results directory: %s", err.Error()) | ||
} | ||
defer func() { | ||
if err := os.RemoveAll(algorithm.ResultsDir); err != nil { | ||
t.Fatalf("error removing results directory and its contents: %s", err.Error()) | ||
} | ||
}() | ||
|
||
for _, dir := range tc.directories { | ||
if dir != "" { | ||
if err := os.Mkdir(algorithm.ResultsDir+"/"+dir, 0o755); err != nil { | ||
t.Fatalf("error creating test directory: %s", err.Error()) | ||
} | ||
} | ||
} | ||
for _, file := range tc.files { | ||
if _, err := os.Create(algorithm.ResultsDir + "/" + file); err != nil { | ||
t.Fatalf("error creating test file: %s", err.Error()) | ||
} | ||
} | ||
|
||
if _, err := algorithm.ZipDirectory(); err != nil { | ||
t.Errorf("ZipDirectory() error = %v", err) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add test