Skip to content

Commit

Permalink
Merge pull request #985 from golemfactory/feature/JST-982/rename-leas…
Browse files Browse the repository at this point in the history
…e-to-rental

Rename lease to rental
  • Loading branch information
mgordel authored Jun 20, 2024
2 parents 80e8c04 + 1c1d6ae commit ec78913
Show file tree
Hide file tree
Showing 38 changed files with 775 additions and 769 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ yagna payment fund --network holesky
yagna payment status --network holesky
```

#### Obtain an `app-key` to use with SDK
### Obtain an `app-key` to use with SDK

If you don't have any app-keys available from `yagna app-key list`, go ahead and create one with the command below.
You will need this key in order to communicate with `yagna` from your application. You can set it
Expand Down Expand Up @@ -147,13 +147,13 @@ const order: MarketOrderSpec = {

try {
await glm.connect();
// Lease a machine
const lease = await glm.oneOf(order);
await lease
// Rent a machine
const rental = await glm.oneOf(order);
await rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem! 👋"))
.then((res) => console.log(res.stdout));
await lease.finalize();
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
Expand Down Expand Up @@ -188,27 +188,27 @@ const order: MarketOrderSpec = {

try {
await glm.connect();
// create a pool that can grow up to 3 leases at the same time
// create a pool that can grow up to 3 rentals at the same time
const pool = await glm.manyOf({
concurrency: 3,
order,
});
// run 3 tasks in parallel on 3 different machines
await Promise.allSettled([
pool.withLease(async (lease) =>
lease
pool.withRental(async (rental) =>
rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the first machine! 👋"))
.then((res) => console.log(res.stdout)),
),
pool.withLease(async (lease) =>
lease
pool.withRental(async (rental) =>
rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the second machine! 👋"))
.then((res) => console.log(res.stdout)),
),
pool.withLease(async (lease) =>
lease
pool.withRental(async (rental) =>
rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the third machine! 👋"))
.then((res) => console.log(res.stdout)),
Expand Down Expand Up @@ -270,8 +270,8 @@ securely between the nodes.
```ts
const network = await glm.createNetwork({ ip: "192.168.7.0/24" });
// ...
const exe1 = await lease1.getExeUnit();
const exe2 = await lease2.getExeUnit();
const exe1 = await rental1.getExeUnit();
const exe2 = await rental2.getExeUnit();
await exe1
.run(`ping ${exe2.getIp()} -c 4`)
.then((res) => console.log(`Response from provider: ${exe1.provider.name} (ip: ${exe1.getIp()})`, res.stdout));
Expand Down
4 changes: 2 additions & 2 deletions examples/advanced/local-image/serveLocalGvmi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ const getImagePath = (path: string) => new URL(path, import.meta.url).toString()
},
};

const lease = await glm.oneOf(order);
const rental = await glm.oneOf(order);
// in our Dockerfile we have created a file called hello.txt, let's read it
const result = await lease
const result = await rental
.getExeUnit()
.then((exe) => exe.run("cat hello.txt"))
.then((res) => res.stdout);
Expand Down
16 changes: 8 additions & 8 deletions examples/advanced/manual-pools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,29 @@ const demandOptions = {
market: glm.market,
activity: glm.activity,
payment: glm.payment,
lease: glm.lease,
rental: glm.rental,
};

const pool = depModules.lease.createLeaseProcessPool(proposalPool, allocation, {
const pool = depModules.rental.createResourceRentalPool(proposalPool, allocation, {
replicas: { max: CONCURRENCY },
});

const lease = await pool.acquire();
const lease2 = await pool.acquire();
const rental1 = await pool.acquire();
const rental2 = await pool.acquire();

await Promise.allSettled([
lease
rental1
.getExeUnit()
.then((exe) => exe.run("echo Hello from first activity 👋"))
.then((result) => console.log(result.stdout)),
lease2
rental2
.getExeUnit()
.then((exe) => exe.run("echo Hello from second activity 👋"))
.then((result) => console.log(result.stdout)),
]);

await pool.release(lease);
await pool.release(lease2);
await pool.release(rental1);
await pool.release(rental2);

proposalSubscription.unsubscribe();
await pool.drainAndClear();
Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/override-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ const order: MarketOrderSpec = {

try {
await glm.connect();
const lease = await glm.oneOf(order);
await lease
const rental = await glm.oneOf(order);
await rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem! 👋"))
.then((res) => console.log(res.stdout));
await lease.finalize();
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/payment-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ const order: MarketOrderSpec = {

try {
await glm.connect();
const lease = await glm.oneOf(order);
await lease
const rental = await glm.oneOf(order);
await rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem! 👋"))
.then((res) => console.log(res.stdout));
await lease.finalize();
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/proposal-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ const order: MarketOrderSpec = {

try {
await glm.connect();
const lease = await glm.oneOf(order);
await lease
const rental = await glm.oneOf(order);
await rental
.getExeUnit()
.then((exe) => exe.run(`echo [provider:${exe.provider.name}] Hello, Golem! 👋`))
.then((res) => console.log(res.stdout));
await lease.finalize();
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/proposal-predefined-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ const order: MarketOrderSpec = {

try {
await glm.connect();
const lease = await glm.oneOf(order);
await lease
const rental = await glm.oneOf(order);
await rental
.getExeUnit()
.then((exe) => exe.run(`echo [provider:${exe.provider.name}] Hello, Golem! 👋`))
.then((res) => console.log(res.stdout));
await lease.finalize();
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
Expand Down
6 changes: 3 additions & 3 deletions examples/advanced/proposal-selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const order: MarketOrderSpec = {

try {
await glm.connect();
const lease = await glm.oneOf(order);
await lease
const rental = await glm.oneOf(order);
await rental
.getExeUnit()
.then((exe) => exe.run(`echo [provider:${exe.provider.name}] Hello, Golem! 👋`))
.then((res) => console.log(res.stdout));
await lease.finalize();
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
Expand Down
16 changes: 8 additions & 8 deletions examples/advanced/reuse-allocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
},
};

const lease1 = await glm.oneOf(firstOrder);
const lease2 = await glm.oneOf(secondOrder);
const rental1 = await glm.oneOf(firstOrder);
const rental2 = await glm.oneOf(secondOrder);

await lease1
await rental1
.getExeUnit()
.then((exe) => exe.run("echo Running on first lease"))
.then((exe) => exe.run("echo Running on first rental"))
.then((res) => console.log(res.stdout));
await lease2
await rental2
.getExeUnit()
.then((exe) => exe.run("echo Running on second lease"))
.then((exe) => exe.run("echo Running on second rental"))
.then((res) => console.log(res.stdout));

await lease1.finalize();
await lease2.finalize();
await rental1.stopAndFinalize();
await rental2.stopAndFinalize();
await glm.payment.releaseAllocation(allocation);
} catch (err) {
console.error("Failed to run the example", err);
Expand Down
6 changes: 3 additions & 3 deletions examples/basic/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
console.warn("Proposal rejected by provider", event);
});

const lease = await glm.oneOf({
const rental = await glm.oneOf({
demand: {
workload: { imageTag: "golem/alpine:latest" },
},
Expand All @@ -50,12 +50,12 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
},
});

await lease
await rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem! 👋"))
.then((res) => console.log(res.stdout));

await lease.finalize();
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
Expand Down
16 changes: 8 additions & 8 deletions examples/basic/many-of.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* This example demonstrates how easily lease multiple machines at once.
* This example demonstrates how easily rent multiple machines at once.
*/

import { GolemNetwork, MarketOrderSpec } from "@golem-sdk/golem-js";
Expand Down Expand Up @@ -29,26 +29,26 @@ const order: MarketOrderSpec = {

try {
await glm.connect();
// create a pool that can grow up to 3 leases at the same time
// create a pool that can grow up to 3 rentals at the same time
const pool = await glm.manyOf({
concurrency: 3,
order,
});
await Promise.allSettled([
pool.withLease(async (lease) =>
lease
pool.withRental(async (rental) =>
rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the first machine! 👋"))
.then((res) => console.log(res.stdout)),
),
pool.withLease(async (lease) =>
lease
pool.withRental(async (rental) =>
rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the second machine! 👋"))
.then((res) => console.log(res.stdout)),
),
pool.withLease(async (lease) =>
lease
pool.withRental(async (rental) =>
rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem from the third machine! 👋"))
.then((res) => console.log(res.stdout)),
Expand Down
6 changes: 3 additions & 3 deletions examples/basic/one-of.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ const order: MarketOrderSpec = {

try {
await glm.connect();
const lease = await glm.oneOf(order);
await lease
const rental = await glm.oneOf(order);
await rental
.getExeUnit()
.then((exe) => exe.run("echo Hello, Golem! 👋"))
.then((res) => console.log(res.stdout));
await lease.finalize();
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
Expand Down
6 changes: 3 additions & 3 deletions examples/basic/run-and-stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const order: MarketOrderSpec = {

try {
await glm.connect();
const lease = await glm.oneOf(order);
const exe = await lease.getExeUnit();
const rental = await glm.oneOf(order);
const exe = await rental.getExeUnit();

const remoteProcess = await exe.runAndStream(
`
Expand All @@ -50,7 +50,7 @@ const order: MarketOrderSpec = {
remoteProcess.stderr.on("data", (data) => console.error("stderr>", data));
await remoteProcess.waitForExit();

await lease.finalize();
await rental.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
Expand Down
12 changes: 6 additions & 6 deletions examples/basic/transfer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ const order: MarketOrderSpec = {
concurrency: 2,
order,
});
const lease1 = await pool.acquire();
const lease2 = await pool.acquire();
const rental1 = await pool.acquire();
const rental2 = await pool.acquire();

const exe1 = await lease1.getExeUnit();
const exe2 = await lease2.getExeUnit();
const exe1 = await rental1.getExeUnit();
const exe2 = await rental2.getExeUnit();

await exe1
.beginBatch()
Expand All @@ -54,8 +54,8 @@ const order: MarketOrderSpec = {
console.log("File content: ");
console.log(await readFile("./results.txt", { encoding: "utf-8" }));

await lease1.finalize();
await lease2.finalize();
await rental1.stopAndFinalize();
await rental2.stopAndFinalize();
} catch (err) {
console.error("Failed to run the example", err);
} finally {
Expand Down
14 changes: 7 additions & 7 deletions examples/basic/vpn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,23 +26,23 @@ import { pinoPrettyLogger } from "@golem-sdk/pino-logger";
},
network,
};
// create a pool that can grow up to 2 leases at the same time
// create a pool that can grow up to 2 rentals at the same time
const pool = await glm.manyOf({
concurrency: 2,
order,
});
const lease1 = await pool.acquire();
const lease2 = await pool.acquire();
const exe1 = await lease1.getExeUnit();
const exe2 = await lease2.getExeUnit();
const rental1 = await pool.acquire();
const rental2 = await pool.acquire();
const exe1 = await rental1.getExeUnit();
const exe2 = await rental2.getExeUnit();
await exe1
.run(`ping ${exe2.getIp()} -c 4`)
.then((res) => console.log(`Response from provider: ${exe1.provider.name} (ip: ${exe1.getIp()})`, res.stdout));
await exe2
.run(`ping ${exe1.getIp()} -c 4`)
.then((res) => console.log(`Response from provider: ${exe2.provider.name} (ip: ${exe2.getIp()})`, res.stdout));
await pool.destroy(lease1);
await pool.destroy(lease2);
await pool.destroy(rental1);
await pool.destroy(rental2);

await glm.destroyNetwork(network);
} catch (err) {
Expand Down
Loading

0 comments on commit ec78913

Please sign in to comment.