-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Install function on roll call if it wasn't installed already (#78)
* Rename function handler/interface to fstore in node code * Add method to check if a function is installed * Separate installing and getting a function * Update tests * Clarify naming - REST API endpoint publishes function install - doesnt actually install it * Add method for function install * Function install done on roll call * Improve log messages * Update tests * Remove "store" as a dependency for the node
- Loading branch information
Showing
29 changed files
with
518 additions
and
425 deletions.
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
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 |
---|---|---|
@@ -1,89 +1,18 @@ | ||
package fstore | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"path/filepath" | ||
|
||
"github.com/blocklessnetworking/b7s/models/blockless" | ||
) | ||
|
||
// Get retrieves the function manifest from the given address. `useCached` indicates whether, | ||
// if the function is found in the store/db, it should be used, or if we should re-download it. | ||
func (h *FStore) Get(address string, cid string, useCached bool) (*blockless.FunctionManifest, error) { | ||
// Get retrieves a function manifest for the given function from storage. | ||
func (h *FStore) Get(cid string) (*blockless.FunctionManifest, error) { | ||
|
||
h.log.Debug(). | ||
Str("cid", cid). | ||
Str("address", address). | ||
Bool("use_cached", useCached). | ||
Msg("getting manifest") | ||
|
||
cachedFn, err := h.getFunction(cid) | ||
// Return cached version if so requested. | ||
if err == nil && useCached { | ||
|
||
h.log.Debug(). | ||
Str("cid", cid). | ||
Str("address", address). | ||
Msg("function manifest was already cached, done") | ||
|
||
return &cachedFn.Manifest, nil | ||
} | ||
if err != nil && !errors.Is(err, blockless.ErrNotFound) { | ||
return nil, fmt.Errorf("could not get function from store: %w", err) | ||
} | ||
|
||
// Being here means that we either did not find the manifest, or we don't | ||
// want to use the cached one. | ||
|
||
// Retrieve function manifest from the given address. | ||
var manifest blockless.FunctionManifest | ||
err = h.getJSON(address, &manifest) | ||
fn, err := h.getFunction(cid) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not retrieve manifest: %w", err) | ||
} | ||
|
||
// If the runtime URL is specified, use it to fill in the deployment info. | ||
if manifest.Runtime.URL != "" { | ||
err = updateDeploymentInfo(&manifest, address) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not update deployment info: %w", err) | ||
} | ||
} | ||
|
||
// Download the function identified by the manifest. | ||
functionPath, err := h.download(manifest) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not download function: %w", err) | ||
} | ||
|
||
out := filepath.Join(h.workdir, cid) | ||
|
||
// Unpack the .tar.gz archive. | ||
// TODO: Would be good to know the content of the .tar.gz archive. | ||
// We're unpacking the archive here and storing the path to the .tar.gz in the DB. | ||
err = h.unpackArchive(functionPath, out) | ||
if err != nil { | ||
return nil, fmt.Errorf("could not unpack gzip archive (file: %s): %w", functionPath, err) | ||
} | ||
|
||
manifest.Deployment.File = functionPath | ||
|
||
// Store the function record. | ||
fn := functionRecord{ | ||
CID: cid, | ||
URL: address, | ||
Manifest: manifest, | ||
Archive: functionPath, | ||
Files: out, | ||
} | ||
err = h.saveFunction(fn) | ||
if err != nil { | ||
h.log.Error(). | ||
Err(err). | ||
Str("cid", cid). | ||
Msg("could not save function record") | ||
return nil, fmt.Errorf("could not get function from store: %w", err) | ||
} | ||
|
||
return &manifest, nil | ||
return &fn.Manifest, 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
Oops, something went wrong.