-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upload dist so version can be downloaded directly form github
- Loading branch information
Showing
144 changed files
with
20,417 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,6 @@ | |
node_modules/ | ||
|
||
#Outputs | ||
dist/ | ||
coverage/ | ||
/.nyc_output | ||
/examples/blender/*.png | ||
|
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,41 @@ | ||
import { Agreement, ProviderInfo } from "../market/agreement"; | ||
export declare enum ActivityStateEnum { | ||
New = "New", | ||
Initialized = "Initialized", | ||
Deployed = "Deployed", | ||
Ready = "Ready", | ||
Unresponsive = "Unresponsive", | ||
Terminated = "Terminated", | ||
/** In case when we couldn't establish the in on yagna */ | ||
Unknown = "Unknown" | ||
} | ||
export type ActivityUsageInfo = { | ||
currentUsage?: number[]; | ||
timestamp: number; | ||
}; | ||
export interface IActivityRepository { | ||
getById(id: string): Promise<Activity>; | ||
getStateOfActivity(id: string): Promise<ActivityStateEnum>; | ||
} | ||
/** | ||
* Activity module - an object representing the runtime environment on the provider in accordance with the `Package` specification. | ||
* As part of a given activity, it is possible to execute exe script commands and capture their results. | ||
*/ | ||
export declare class Activity { | ||
readonly id: string; | ||
readonly agreement: Agreement; | ||
protected readonly currentState: ActivityStateEnum; | ||
protected readonly previousState: ActivityStateEnum; | ||
protected readonly usage: ActivityUsageInfo; | ||
/** | ||
* @param id The ID of the activity in Yagna | ||
* @param agreement The agreement that's related to this activity | ||
* @param currentState The current state as it was obtained from yagna | ||
* @param previousState The previous state (or New if this is the first time we're creating the activity) | ||
* @param usage Current resource usage vector information | ||
*/ | ||
constructor(id: string, agreement: Agreement, currentState: ActivityStateEnum, previousState: ActivityStateEnum, usage: ActivityUsageInfo); | ||
get provider(): ProviderInfo; | ||
getState(): ActivityStateEnum; | ||
getPreviousState(): ActivityStateEnum; | ||
} |
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,101 @@ | ||
import { EventEmitter } from "eventemitter3"; | ||
import { Agreement } from "../market"; | ||
import { Activity, ActivityEvents, Result } from "./index"; | ||
import { GolemServices } from "../golem-network"; | ||
import { ExeUnit, ExeUnitOptions } from "./exe-unit"; | ||
import { ExecutionOptions, ExeScriptExecutor, ExeScriptRequest } from "./exe-script-executor"; | ||
import { Observable } from "rxjs"; | ||
import { StreamingBatchEvent } from "./results"; | ||
export interface ActivityModule { | ||
events: EventEmitter<ActivityEvents>; | ||
/** | ||
* Create and start a new activity on the provider for the supplied agreement | ||
* | ||
* @return The resulting activity on the provider for further use | ||
*/ | ||
createActivity(agreement: Agreement): Promise<Activity>; | ||
/** | ||
* Definitely terminate any work on the provider | ||
* | ||
* @return The activity that was permanently terminated | ||
*/ | ||
destroyActivity(activity: Activity): Promise<Activity>; | ||
/** | ||
* Fetches the latest state of the activity. It's recommended to use this method | ||
* before performing any actions on the activity to make sure it's in the correct state. | ||
* If the fetched activity's state is different from the one you have, an event will be emitted. | ||
*/ | ||
refreshActivity(staleActivity: Activity): Promise<Activity>; | ||
/** | ||
* Fetches the activity by its ID from yagna. If the activity doesn't exist, an error will be thrown. | ||
*/ | ||
findActivityById(activityId: string): Promise<Activity>; | ||
/** | ||
* Create a exe-unit "within" the activity so that you can perform commands on the rented resources | ||
* | ||
* @return An ExeUnit that's fully commissioned and the user can execute their commands | ||
*/ | ||
createExeUnit(activity: Activity, options?: ExeUnitOptions): Promise<ExeUnit>; | ||
/** | ||
* Factory method for creating a script executor for the activity | ||
*/ | ||
createScriptExecutor(activity: Activity, options?: ExecutionOptions): ExeScriptExecutor; | ||
/** | ||
* Execute a script on the activity. | ||
*/ | ||
executeScript(activity: Activity, script: ExeScriptRequest): Promise<string>; | ||
/** | ||
* Fetch the results of a batch execution. | ||
*/ | ||
getBatchResults(activity: Activity, batchId: string, commandIndex?: number, timeout?: number): Promise<Result[]>; | ||
/** | ||
* Create an observable that will emit events from the streaming batch. | ||
*/ | ||
observeStreamingBatchEvents(activity: Activity, batchId: string, commandIndex?: number): Observable<StreamingBatchEvent>; | ||
} | ||
/** | ||
* Information about a file that has been published via the FileServer | ||
*/ | ||
export type FileServerEntry = { | ||
/** The URL of the file, that the clients can use to reach and download the file */ | ||
fileUrl: string; | ||
/** The checksum that can be used by clients to validate integrity of the downloaded file */ | ||
fileHash: string; | ||
}; | ||
/** | ||
* An abstract interface describing a File Server that can be used to expose files from the Requestor to the Golem Network | ||
*/ | ||
export interface IFileServer { | ||
/** | ||
* Exposes a file that can be accessed via Golem Network and GFTP | ||
*/ | ||
publishFile(sourcePath: string): Promise<FileServerEntry>; | ||
/** | ||
* Tells if the file was already published on the server | ||
*/ | ||
isFilePublished(sourcePath: string): boolean; | ||
/** | ||
* Returns publishing information for a file that has been already served | ||
*/ | ||
getPublishInfo(sourcePath: string): FileServerEntry | undefined; | ||
/** | ||
* Tells if the server is currently serving any files | ||
*/ | ||
isServing(): boolean; | ||
} | ||
export declare class ActivityModuleImpl implements ActivityModule { | ||
private readonly services; | ||
readonly events: EventEmitter<ActivityEvents>; | ||
private readonly logger; | ||
private readonly activityApi; | ||
constructor(services: GolemServices); | ||
createScriptExecutor(activity: Activity, options?: ExecutionOptions): ExeScriptExecutor; | ||
executeScript(activity: Activity, script: ExeScriptRequest): Promise<string>; | ||
getBatchResults(activity: Activity, batchId: string, commandIndex?: number | undefined, timeout?: number | undefined): Promise<Result[]>; | ||
observeStreamingBatchEvents(activity: Activity, batchId: string, commandIndex?: number | undefined): Observable<StreamingBatchEvent>; | ||
createActivity(agreement: Agreement): Promise<Activity>; | ||
destroyActivity(activity: Activity): Promise<Activity>; | ||
refreshActivity(staleActivity: Activity): Promise<Activity>; | ||
findActivityById(activityId: string): Promise<Activity>; | ||
createExeUnit(activity: Activity, options?: ExeUnitOptions): Promise<ExeUnit>; | ||
} |
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 @@ | ||
import { Activity, ActivityStateEnum } from "./activity"; | ||
import { Agreement } from "../market"; | ||
import { ExeScriptRequest } from "./exe-script-executor"; | ||
import { Result, StreamingBatchEvent } from "./results"; | ||
import { Observable } from "rxjs"; | ||
export type ActivityEvents = { | ||
activityCreated: (event: { | ||
activity: Activity; | ||
}) => void; | ||
errorCreatingActivity: (event: { | ||
error: Error; | ||
}) => void; | ||
activityDestroyed: (event: { | ||
activity: Activity; | ||
}) => void; | ||
errorDestroyingActivity: (event: { | ||
activity: Activity; | ||
error: Error; | ||
}) => void; | ||
exeUnitInitialized: (event: { | ||
activity: Activity; | ||
}) => void; | ||
errorInitializingExeUnit: (event: { | ||
activity: Activity; | ||
error: Error; | ||
}) => void; | ||
activityStateChanged: (event: { | ||
activity: Activity; | ||
previousState: ActivityStateEnum; | ||
}) => void; | ||
errorRefreshingActivity: (event: { | ||
activity: Activity; | ||
error: Error; | ||
}) => void; | ||
scriptSent: (event: { | ||
activity: Activity; | ||
script: ExeScriptRequest; | ||
}) => void; | ||
scriptExecuted: (event: { | ||
activity: Activity; | ||
script: ExeScriptRequest; | ||
result: string; | ||
}) => void; | ||
errorExecutingScript: (event: { | ||
activity: Activity; | ||
script: ExeScriptRequest; | ||
error: Error; | ||
}) => void; | ||
batchResultsReceived: (event: { | ||
activity: Activity; | ||
batchId: string; | ||
results: Result[]; | ||
}) => void; | ||
errorGettingBatchResults: (event: { | ||
activity: Activity; | ||
batchId: string; | ||
error: Error; | ||
}) => void; | ||
batchEventsReceived: (event: { | ||
activity: Activity; | ||
batchId: string; | ||
event: StreamingBatchEvent; | ||
}) => void; | ||
errorGettingBatchEvents: (event: { | ||
activity: Activity; | ||
batchId: string; | ||
error: Error; | ||
}) => void; | ||
}; | ||
/** | ||
* Represents a set of use cases related to managing the lifetime of an activity | ||
*/ | ||
export interface IActivityApi { | ||
getActivity(id: string): Promise<Activity>; | ||
createActivity(agreement: Agreement): Promise<Activity>; | ||
destroyActivity(activity: Activity): Promise<Activity>; | ||
getActivityState(id: string): Promise<ActivityStateEnum>; | ||
executeScript(activity: Activity, script: ExeScriptRequest): Promise<string>; | ||
getExecBatchResults(activity: Activity, batchId: string, commandIndex?: number, timeout?: number): Promise<Result[]>; | ||
getExecBatchEvents(activity: Activity, batchId: string, commandIndex?: number): Observable<StreamingBatchEvent>; | ||
} |
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,9 @@ | ||
import { ExecutionOptions } from "./exe-script-executor"; | ||
/** | ||
* @internal | ||
*/ | ||
export declare class ExecutionConfig { | ||
readonly activityExeBatchResultPollIntervalSeconds: number; | ||
readonly activityExeBatchResultMaxRetries: number; | ||
constructor(options?: ExecutionOptions); | ||
} |
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,54 @@ | ||
import { Logger } from "../shared/utils"; | ||
import { Result } from "./results"; | ||
import { Activity } from "./activity"; | ||
import { ActivityModule } from "./activity.module"; | ||
import { Observable } from "rxjs"; | ||
/** | ||
* Information needed to fetch the results of a script execution | ||
*/ | ||
export interface ScriptExecutionMetadata { | ||
batchId: string; | ||
batchSize: number; | ||
} | ||
export interface ExeScriptRequest { | ||
text: string; | ||
} | ||
export interface ExecutionOptions { | ||
/** interval for fetching batch results while polling */ | ||
activityExeBatchResultPollIntervalSeconds?: number; | ||
/** maximum number of retries retrieving results when an error occurs, default: 10 */ | ||
activityExeBatchResultMaxRetries?: number; | ||
/** The timeout in milliseconds or an AbortSignal that will be used to cancel the execution */ | ||
signalOrTimeout?: number | AbortSignal; | ||
} | ||
export declare class ExeScriptExecutor { | ||
readonly activity: Activity; | ||
private readonly activityModule; | ||
private readonly logger; | ||
private readonly options; | ||
private readonly abortSignal; | ||
constructor(activity: Activity, activityModule: ActivityModule, logger: Logger, options?: ExecutionOptions); | ||
/** | ||
* Executes the provided script and returns the batch id and batch size that can be used | ||
* to fetch it's results | ||
* @param script | ||
* @returns script execution metadata - batch id and batch size that can be used to fetch results using `getResultsObservable` | ||
*/ | ||
execute(script: ExeScriptRequest): Promise<ScriptExecutionMetadata>; | ||
/** | ||
* Given a batch id and batch size collect the results from yagna. You can choose to either | ||
* stream them as they go or poll for them. When a timeout is reached (by either the timeout provided | ||
* as an argument here or in the constructor) the observable will emit an error. | ||
* | ||
* | ||
* @param batch - batch id and batch size | ||
* @param stream - define type of getting results from execution (polling or streaming) | ||
* @param signalOrTimeout - the timeout in milliseconds or an AbortSignal that will be used to cancel the execution | ||
* @param maxRetries - maximum number of retries retrieving results when an error occurs, default: 10 | ||
*/ | ||
getResultsObservable(batch: ScriptExecutionMetadata, stream?: boolean, signalOrTimeout?: number | AbortSignal, maxRetries?: number): Observable<Result>; | ||
protected send(script: ExeScriptRequest): Promise<string>; | ||
private pollingBatch; | ||
private streamingBatch; | ||
private parseEventToResult; | ||
} |
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,35 @@ | ||
import { Result } from "../index"; | ||
import { StorageProvider } from "../../shared/storage"; | ||
import { Logger } from "../../shared/utils"; | ||
import { ExeScriptExecutor } from "../exe-script-executor"; | ||
import { Observable } from "rxjs"; | ||
export declare class Batch { | ||
private executor; | ||
private storageProvider; | ||
private logger; | ||
private readonly script; | ||
constructor(executor: ExeScriptExecutor, storageProvider: StorageProvider, logger: Logger); | ||
/** | ||
* Execute a command on provider using a shell (/bin/sh). | ||
* | ||
* @param commandLine Shell command to execute. | ||
*/ | ||
run(commandLine: string): Batch; | ||
/** | ||
* Execute an executable on provider. | ||
* | ||
* @param executable Executable to run. | ||
* @param args Executable arguments. | ||
*/ | ||
run(executable: string, args: string[]): Batch; | ||
transfer(from: string, to: string): Batch; | ||
uploadFile(src: string, dst: string): Batch; | ||
uploadJson(json: object, dst: string): Batch; | ||
uploadData(data: Uint8Array, dst: string): Batch; | ||
downloadFile(src: string, dst: string): Batch; | ||
/** | ||
* Executes the batch of commands added via {@link run} returning result for each of the steps. | ||
*/ | ||
end(): Promise<Result[]>; | ||
endStream(): Promise<Observable<Result>>; | ||
} |
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,24 @@ | ||
import { GolemModuleError } from "../../shared/error/golem-error"; | ||
import { Agreement, ProviderInfo } from "../../market/agreement"; | ||
import { Activity } from "../index"; | ||
export declare enum WorkErrorCode { | ||
ServiceNotInitialized = "ServiceNotInitialized", | ||
ScriptExecutionFailed = "ScriptExecutionFailed", | ||
ActivityDestroyingFailed = "ActivityDestroyingFailed", | ||
ActivityResultsFetchingFailed = "ActivityResultsFetchingFailed", | ||
ActivityCreationFailed = "ActivityCreationFailed", | ||
NetworkSetupMissing = "NetworkSetupMissing", | ||
ScriptInitializationFailed = "ScriptInitializationFailed", | ||
ActivityDeploymentFailed = "ActivityDeploymentFailed", | ||
ActivityStatusQueryFailed = "ActivityStatusQueryFailed", | ||
ActivityResetFailed = "ActivityResetFailed" | ||
} | ||
export declare class GolemWorkError extends GolemModuleError { | ||
#private; | ||
code: WorkErrorCode; | ||
previous?: Error | undefined; | ||
constructor(message: string, code: WorkErrorCode, agreement?: Agreement, activity?: Activity, provider?: ProviderInfo, previous?: Error | undefined); | ||
getAgreement(): Agreement | undefined; | ||
getActivity(): Activity | undefined; | ||
getProvider(): ProviderInfo | undefined; | ||
} |
Oops, something went wrong.