Skip to content

Commit

Permalink
Merge pull request #1096 from golemfactory/feature/JST-186/drop-gftp
Browse files Browse the repository at this point in the history
JST-186: drop gftp
  • Loading branch information
grisha87 authored Oct 11, 2024
2 parents 6698336 + ae82718 commit baa402e
Show file tree
Hide file tree
Showing 14 changed files with 350 additions and 83 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ const order: MarketOrderSpec = {
},
market: {
// We're only going to rent the provider for 5 minutes max
rentHours: 5 / 60,
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
Expand Down
14 changes: 7 additions & 7 deletions docs/UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ import { GolemNetwork } from "@golem-sdk/golem-js";
try {
await glm.connect();

const retnal = await glm.oneOf({
const rental = await glm.oneOf({
order: {
demand: {
workload: { imageTag: "golem/alpine:latest" },
},
// You have to be now explicit about about your terms and expectatios from the market
// You have to be now explicit about about your terms and expectations from the market
market: {
rentHours: 5 / 60,
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
Expand Down Expand Up @@ -132,9 +132,9 @@ import { GolemNetwork } from "@golem-sdk/golem-js";
demand: {
workload: { imageTag: "golem/alpine:latest" },
},
// You have to be now explicit about about your terms and expectatios from the market
// You have to be now explicit about about your terms and expectations from the market
market: {
rentHours: 5 / 60,
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
Expand All @@ -147,13 +147,13 @@ import { GolemNetwork } from "@golem-sdk/golem-js";

const inputs = [1, 2, 3, 4, 5];

// You still take the necessary precaucions, pipeline your work and processing
// You still take the necessary precautions, pipeline your work and processing
const results = await Promise.allSettled(
inputs.map((input) =>
// 🌟🌟 You access rentals from the pool
pool.withRental((rental) =>
rental
// 🌟🌟🌟 You issue the comands as in case of a single-provider scenario
// 🌟🌟🌟 You issue the commands as in case of a single-provider scenario
.getExeUnit()
.then((exe) => exe.run(`echo 'Hello ${input}`))
.then((res) => res.stdout),
Expand Down
4 changes: 2 additions & 2 deletions docs/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const order: MarketOrderSpec = {
workload: { imageTag: "golem/alpine:latest" },
},
market: {
// We're only going to rent the provider for 5 minutes max
rentHours: 5 / 60,
// We're only going to rent the provider for 15 minutes max
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 0.5,
Expand Down
2 changes: 1 addition & 1 deletion examples/rental-model/advanced/local-image/local-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const getImagePath = (path: string) => new URL(path, import.meta.url).toString()
},
},
market: {
rentHours: 5 / 60,
rentHours: 15 / 60,
pricing: {
model: "linear",
maxStartPrice: 1,
Expand Down
17 changes: 13 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"@types/eventsource": "^1.1.15",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/node": "^20.11.20",
"@types/node": "^18.19.55",
"@types/semver": "^7.5.8",
"@types/supertest": "^6.0.2",
"@types/tmp": "^0.2.6",
Expand Down
4 changes: 2 additions & 2 deletions src/golem-network/golem-network.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { MarketApiAdapter, PaymentApiAdapter } from "../shared/yagna";
import { ActivityApiAdapter } from "../shared/yagna/adapters/activity-api-adapter";
import { GolemNetwork, MarketOrderSpec } from "./golem-network";
import { _, instance, mock, reset, spy, verify, when } from "@johanblumenberg/ts-mockito";
import { GftpStorageProvider } from "../shared/storage";
import { WebSocketStorageProvider } from "../shared/storage";

const order: MarketOrderSpec = Object.freeze({
demand: {
Expand All @@ -34,7 +34,7 @@ const mockYagna = mock(YagnaApi);
const mockPaymentApi = mock(PaymentApiAdapter);
const mockActivityApi = mock(ActivityApiAdapter);
const mockMarketApi = mock(MarketApiAdapter);
const mockStorageProvider = mock(GftpStorageProvider);
const mockStorageProvider = mock(WebSocketStorageProvider);

afterEach(() => {
reset(mockYagna);
Expand Down
27 changes: 13 additions & 14 deletions src/golem-network/golem-network.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { anyAbortSignal, createAbortSignalFromTimeout, defaultLogger, isNode, Logger, YagnaApi } from "../shared/utils";
import { anyAbortSignal, createAbortSignalFromTimeout, defaultLogger, Logger, YagnaApi } from "../shared/utils";
import {
Demand,
DraftOfferProposalPool,
Expand Down Expand Up @@ -29,17 +29,13 @@ import { ProposalRepository } from "../shared/yagna/repository/proposal-reposito
import { CacheService } from "../shared/cache/CacheService";
import { DemandRepository } from "../shared/yagna/repository/demand-repository";
import { IDemandRepository, OrderDemandOptions } from "../market/demand";
import { GftpServerAdapter } from "../shared/storage/GftpServerAdapter";
import {
GftpStorageProvider,
NullStorageProvider,
StorageProvider,
WebSocketBrowserStorageProvider,
} from "../shared/storage";
import { StorageServerAdapter } from "../shared/storage/StorageServerAdapter";
import { GftpStorageProvider, NullStorageProvider, StorageProvider, WebSocketStorageProvider } from "../shared/storage";
import { DataTransferProtocol } from "../shared/types";
import { NetworkApiAdapter } from "../shared/yagna/adapters/network-api-adapter";
import { IProposalRepository } from "../market/proposal";
import { Subscription } from "rxjs";
import { GolemConfigError } from "../shared/error/golem-error";

/**
* Instance of an object or a factory function that you can call `new` on.
Expand Down Expand Up @@ -105,7 +101,7 @@ export interface GolemNetworkOptions {

/**
* Set the data transfer protocol to use for file transfers.
* Default is `gftp`.
* Default is `ws`.
*/
dataTransferProtocol?: DataTransferProtocol;

Expand Down Expand Up @@ -228,7 +224,7 @@ export class GolemNetwork {

constructor(options: Partial<GolemNetworkOptions> = {}) {
const optDefaults: GolemNetworkOptions = {
dataTransferProtocol: isNode ? "gftp" : "ws",
dataTransferProtocol: "ws",
};

this.options = {
Expand Down Expand Up @@ -285,7 +281,7 @@ export class GolemNetwork {
this.options.override?.marketApi ||
new MarketApiAdapter(this.yagna, agreementRepository, proposalRepository, demandRepository, this.logger),
networkApi: this.options.override?.networkApi || new NetworkApiAdapter(this.yagna),
fileServer: this.options.override?.fileServer || new GftpServerAdapter(this.storageProvider),
fileServer: this.options.override?.fileServer || new StorageServerAdapter(this.storageProvider),
};
this.network = getFactory(NetworkModuleImpl, this.options.override?.network)(this.services);
this.market = getFactory(MarketModuleImpl, this.options.override?.market)(
Expand Down Expand Up @@ -655,13 +651,16 @@ export class GolemNetwork {
private createStorageProvider(): StorageProvider {
if (typeof this.options.dataTransferProtocol === "string") {
switch (this.options.dataTransferProtocol) {
case "gftp":
return new GftpStorageProvider(this.logger);
case "ws":
return new WebSocketBrowserStorageProvider(this.yagna, {
return new WebSocketStorageProvider(this.yagna, {
logger: this.logger,
});
case "gftp":
default:
return new GftpStorageProvider(this.logger);
throw new GolemConfigError(
`Unsupported data transfer protocol ${this.options.dataTransferProtocol}. Supported protocols are "gftp" and "ws"`,
);
}
} else if (this.options.dataTransferProtocol !== undefined) {
return this.options.dataTransferProtocol;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import fs from "fs";
import jsSha3 from "js-sha3";

/**
* This class provides GFTP based implementation of the IFileServer interface used in the SDK
* IFileServer implementation that uses any StorageProvider to serve files.
* Make sure that the storage provider implements the `.publishFile()` method.
*/
export class GftpServerAdapter implements IFileServer {
class StorageServerAdapter implements IFileServer {
private published = new Map<string, FileServerEntry>();

constructor(private readonly storage: StorageProvider) {}
Expand Down Expand Up @@ -57,3 +58,12 @@ export class GftpServerAdapter implements IFileServer {
});
}
}

/**
* @deprecated Use StorageServerAdapter instead. This will be removed in the next major version.
*
* This class provides GFTP based implementation of the IFileServer interface used in the SDK
*/
class GftpServerAdapter extends StorageServerAdapter {}

export { GftpServerAdapter, StorageServerAdapter };
18 changes: 5 additions & 13 deletions src/shared/storage/default.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
import { GftpStorageProvider } from "./gftp";
import { WebSocketBrowserStorageProvider } from "./ws-browser";
import { NullStorageProvider } from "./null";
import { Logger, YagnaApi, isNode, isBrowser } from "../utils";
import { WebSocketStorageProvider } from "./ws";
import { Logger, YagnaApi } from "../utils";

export function createDefaultStorageProvider(yagnaApi: YagnaApi, logger?: Logger) {
if (isNode) {
return new GftpStorageProvider(logger?.child("storage"));
}
if (isBrowser) {
return new WebSocketBrowserStorageProvider(yagnaApi, {
logger: logger?.child("storage"),
});
}
return new NullStorageProvider();
return new WebSocketStorageProvider(yagnaApi, {
logger: logger?.child("storage"),
});
}
5 changes: 5 additions & 0 deletions src/shared/storage/gftp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ import { GolemInternalError, GolemUserError } from "../error/golem-error";
import { v4 } from "uuid";
import AsyncLock from "async-lock";

/**
* @deprecated Use WebSocketStorageProvider instead. This will be removed in the next major version.
*
* Storage provider that spawns a GFTP process and uses it to serve files.
*/
export class GftpStorageProvider implements StorageProvider {
private gftpServerProcess?: ChildProcess;
private logger: Logger;
Expand Down
2 changes: 1 addition & 1 deletion src/shared/storage/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export { StorageProvider } from "./provider";
export { GftpStorageProvider } from "./gftp";
export { NullStorageProvider } from "./null";
export { WebSocketBrowserStorageProvider, WebSocketStorageProviderOptions } from "./ws-browser";
export { WebSocketStorageProvider, WebSocketStorageProviderOptions } from "./ws";
export { createDefaultStorageProvider } from "./default";
Loading

0 comments on commit baa402e

Please sign in to comment.