IgGusev commented on code in PR #5889: URL: https://github.com/apache/ignite-3/pull/5889#discussion_r2104477572
########## modules/platforms/dotnet/README.md: ########## @@ -222,22 +222,73 @@ await tx.CommitAsync(); ## Compute -Compute API is used to execute distributed computations on the cluster. Compute jobs should be implemented in Java, deployed to server nodes, and called by the full class name. +Compute API is used to execute distributed computations on the cluster. -```cs -IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); +Compute jobs can be implemented in Java or .NET. +Resulting binaries (jar or dll files) should be [deployed](https://ignite.apache.org/docs/ignite3/latest/developers-guide/code-deployment/code-deployment) to the server nodes and called by the full class name. + +Java job invocation example: +```csharp +IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); IJobTarget<IEnumerable<IClusterNode>> jobTarget = JobTarget.AnyNode(nodes); var jobDesc = new JobDescriptor<string, string>( - "org.foo.bar.MyJob"); + JobClassName: "org.foo.bar.MyJob", + DeploymentUnits: [new DeploymentUnit("Unit1")]); IJobExecution<string> jobExecution = await client.Compute.SubmitAsync( jobTarget, jobDesc, "Job Arg"); string jobResult = await jobExecution.GetResultAsync(); ``` +### Implement a .NET Compute Job + +1. Prepare a "class library" project for the job implementations (`dotnet new classlib`). Prefer a separate project for compute jobs to reduce deployment size. Review Comment: ```suggestion 1. Prepare a "class library" project for the job implementation (`dotnet new classlib`). In most cases, it is better to use a separate project for compute jobs to reduce deployment size. ``` ########## modules/platforms/dotnet/README.md: ########## @@ -222,22 +222,73 @@ await tx.CommitAsync(); ## Compute -Compute API is used to execute distributed computations on the cluster. Compute jobs should be implemented in Java, deployed to server nodes, and called by the full class name. +Compute API is used to execute distributed computations on the cluster. -```cs -IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); +Compute jobs can be implemented in Java or .NET. +Resulting binaries (jar or dll files) should be [deployed](https://ignite.apache.org/docs/ignite3/latest/developers-guide/code-deployment/code-deployment) to the server nodes and called by the full class name. + +Java job invocation example: +```csharp +IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); IJobTarget<IEnumerable<IClusterNode>> jobTarget = JobTarget.AnyNode(nodes); var jobDesc = new JobDescriptor<string, string>( - "org.foo.bar.MyJob"); + JobClassName: "org.foo.bar.MyJob", + DeploymentUnits: [new DeploymentUnit("Unit1")]); IJobExecution<string> jobExecution = await client.Compute.SubmitAsync( jobTarget, jobDesc, "Job Arg"); string jobResult = await jobExecution.GetResultAsync(); ``` +### Implement a .NET Compute Job + +1. Prepare a "class library" project for the job implementations (`dotnet new classlib`). Prefer a separate project for compute jobs to reduce deployment size. +2. Add a reference to `Apache.Ignite` package to the class library project (`dotnet add package Apache.Ignite`). +3. Create a class that implements `IComputeJob<TArg, TRes>` interface + ```csharp + public class HelloJob : IComputeJob<string, string> + { + public ValueTask<string> ExecuteAsync(IJobExecutionContext context, string arg, CancellationToken cancellationToken) => + ValueTask.FromResult("Hello " + arg); + } + ``` +4. Publish the project (`dotnet publish -c Release`) +5. Copy the resulting dll file (and any extra dependencies, EXCLUDING Ignite dlls) to a separate directory. + * Note: The directory must not contain any subdirectories. +6. Use [Ignite CLI](https://ignite.apache.org/docs/ignite3/latest/ignite-cli-tool#cluster-commands) `cluster unit deploy` command to deploy the directory to the cluster as a deployment unit. + +### Run a .NET Compute Job + +.NET compute jobs can be executed from any client (.NET, Java, C++, etc), +by specifying the assembly-qualified class name and using the `JobExecutorType.DotNetSidecar` option. + +```csharp +var jobTarget = JobTarget.AnyNode(await client.GetClusterNodesAsync()); +var jobDesc = new JobDescriptor<string, string>( + JobClassName: typeof(HelloJob).AssemblyQualifiedName!, + DeploymentUnits: [new DeploymentUnit("unit1")], + Options: new JobExecutionOptions(ExecutorType: JobExecutorType.DotNetSidecar)); + +IJobExecution<string> jobExec = await client.Compute.SubmitAsync(jobTarget, jobDesc, "world"); +``` + +Alternatively, use `JobDescriptor.Of` shortcut method to create a job descriptor from a job instance: + +```csharp +JobDescriptor<string, string> jobDesc = JobDescriptor.Of(new HelloJob()) + with { DeploymentUnits = [new DeploymentUnit("unit1")] }; +``` + +#### .NET Compute Server-side Requirements + +* .NET compute jobs are executed in a separate process (sidecar) on the server node. +* The process is started on the first .NET job call and then reused for subsequent jobs. +* Every deployment unit combination is loaded into a separate [AssemblyLoadContext](https://learn.microsoft.com/en-us/dotnet/core/dependency-loading/understanding-assemblyloadcontext). +* .NET 8 (or later) runtime (not SDK) is required on the server node. Review Comment: This should be the first bullet point, as many readers will miss it otherwise. ########## modules/platforms/dotnet/README.md: ########## @@ -222,22 +222,73 @@ await tx.CommitAsync(); ## Compute -Compute API is used to execute distributed computations on the cluster. Compute jobs should be implemented in Java, deployed to server nodes, and called by the full class name. +Compute API is used to execute distributed computations on the cluster. -```cs -IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); +Compute jobs can be implemented in Java or .NET. +Resulting binaries (jar or dll files) should be [deployed](https://ignite.apache.org/docs/ignite3/latest/developers-guide/code-deployment/code-deployment) to the server nodes and called by the full class name. + +Java job invocation example: +```csharp +IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); IJobTarget<IEnumerable<IClusterNode>> jobTarget = JobTarget.AnyNode(nodes); var jobDesc = new JobDescriptor<string, string>( - "org.foo.bar.MyJob"); + JobClassName: "org.foo.bar.MyJob", + DeploymentUnits: [new DeploymentUnit("Unit1")]); IJobExecution<string> jobExecution = await client.Compute.SubmitAsync( jobTarget, jobDesc, "Job Arg"); string jobResult = await jobExecution.GetResultAsync(); ``` +### Implement a .NET Compute Job + +1. Prepare a "class library" project for the job implementations (`dotnet new classlib`). Prefer a separate project for compute jobs to reduce deployment size. +2. Add a reference to `Apache.Ignite` package to the class library project (`dotnet add package Apache.Ignite`). +3. Create a class that implements `IComputeJob<TArg, TRes>` interface + ```csharp + public class HelloJob : IComputeJob<string, string> + { + public ValueTask<string> ExecuteAsync(IJobExecutionContext context, string arg, CancellationToken cancellationToken) => + ValueTask.FromResult("Hello " + arg); + } + ``` +4. Publish the project (`dotnet publish -c Release`) +5. Copy the resulting dll file (and any extra dependencies, EXCLUDING Ignite dlls) to a separate directory. + * Note: The directory must not contain any subdirectories. Review Comment: ```suggestion * Note: The directory with the dll must not contain any subdirectories. ``` ########## modules/platforms/dotnet/README.md: ########## @@ -222,22 +222,73 @@ await tx.CommitAsync(); ## Compute -Compute API is used to execute distributed computations on the cluster. Compute jobs should be implemented in Java, deployed to server nodes, and called by the full class name. +Compute API is used to execute distributed computations on the cluster. -```cs -IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); +Compute jobs can be implemented in Java or .NET. +Resulting binaries (jar or dll files) should be [deployed](https://ignite.apache.org/docs/ignite3/latest/developers-guide/code-deployment/code-deployment) to the server nodes and called by the full class name. + +Java job invocation example: +```csharp +IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); IJobTarget<IEnumerable<IClusterNode>> jobTarget = JobTarget.AnyNode(nodes); var jobDesc = new JobDescriptor<string, string>( - "org.foo.bar.MyJob"); + JobClassName: "org.foo.bar.MyJob", + DeploymentUnits: [new DeploymentUnit("Unit1")]); IJobExecution<string> jobExecution = await client.Compute.SubmitAsync( jobTarget, jobDesc, "Job Arg"); string jobResult = await jobExecution.GetResultAsync(); ``` +### Implement a .NET Compute Job + +1. Prepare a "class library" project for the job implementations (`dotnet new classlib`). Prefer a separate project for compute jobs to reduce deployment size. +2. Add a reference to `Apache.Ignite` package to the class library project (`dotnet add package Apache.Ignite`). +3. Create a class that implements `IComputeJob<TArg, TRes>` interface + ```csharp + public class HelloJob : IComputeJob<string, string> + { + public ValueTask<string> ExecuteAsync(IJobExecutionContext context, string arg, CancellationToken cancellationToken) => + ValueTask.FromResult("Hello " + arg); + } + ``` +4. Publish the project (`dotnet publish -c Release`) Review Comment: ```suggestion 4. Publish the project (`dotnet publish -c Release`). ``` ########## modules/platforms/dotnet/README.md: ########## @@ -222,22 +222,73 @@ await tx.CommitAsync(); ## Compute -Compute API is used to execute distributed computations on the cluster. Compute jobs should be implemented in Java, deployed to server nodes, and called by the full class name. +Compute API is used to execute distributed computations on the cluster. -```cs -IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); +Compute jobs can be implemented in Java or .NET. +Resulting binaries (jar or dll files) should be [deployed](https://ignite.apache.org/docs/ignite3/latest/developers-guide/code-deployment/code-deployment) to the server nodes and called by the full class name. + +Java job invocation example: +```csharp +IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); IJobTarget<IEnumerable<IClusterNode>> jobTarget = JobTarget.AnyNode(nodes); var jobDesc = new JobDescriptor<string, string>( - "org.foo.bar.MyJob"); + JobClassName: "org.foo.bar.MyJob", + DeploymentUnits: [new DeploymentUnit("Unit1")]); IJobExecution<string> jobExecution = await client.Compute.SubmitAsync( jobTarget, jobDesc, "Job Arg"); string jobResult = await jobExecution.GetResultAsync(); ``` +### Implement a .NET Compute Job + +1. Prepare a "class library" project for the job implementations (`dotnet new classlib`). Prefer a separate project for compute jobs to reduce deployment size. +2. Add a reference to `Apache.Ignite` package to the class library project (`dotnet add package Apache.Ignite`). +3. Create a class that implements `IComputeJob<TArg, TRes>` interface Review Comment: ```suggestion 3. Create a class that implements `IComputeJob<TArg, TRes>` interface, for example: ``` ########## modules/platforms/dotnet/README.md: ########## @@ -222,22 +222,73 @@ await tx.CommitAsync(); ## Compute -Compute API is used to execute distributed computations on the cluster. Compute jobs should be implemented in Java, deployed to server nodes, and called by the full class name. +Compute API is used to execute distributed computations on the cluster. -```cs -IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); +Compute jobs can be implemented in Java or .NET. +Resulting binaries (jar or dll files) should be [deployed](https://ignite.apache.org/docs/ignite3/latest/developers-guide/code-deployment/code-deployment) to the server nodes and called by the full class name. + +Java job invocation example: Review Comment: This would read better as a subsection. Maybe something like this ```suggestion ### Call a Java Compute Job You can call [Java computing jobs](https://ignite.apache.org/docs/ignite3/latest/developers-guide/compute/compute) from your .NET code, for example: ``` ########## modules/platforms/dotnet/README.md: ########## @@ -222,22 +222,73 @@ await tx.CommitAsync(); ## Compute -Compute API is used to execute distributed computations on the cluster. Compute jobs should be implemented in Java, deployed to server nodes, and called by the full class name. +Compute API is used to execute distributed computations on the cluster. -```cs -IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); +Compute jobs can be implemented in Java or .NET. +Resulting binaries (jar or dll files) should be [deployed](https://ignite.apache.org/docs/ignite3/latest/developers-guide/code-deployment/code-deployment) to the server nodes and called by the full class name. + +Java job invocation example: +```csharp +IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); IJobTarget<IEnumerable<IClusterNode>> jobTarget = JobTarget.AnyNode(nodes); var jobDesc = new JobDescriptor<string, string>( - "org.foo.bar.MyJob"); + JobClassName: "org.foo.bar.MyJob", + DeploymentUnits: [new DeploymentUnit("Unit1")]); IJobExecution<string> jobExecution = await client.Compute.SubmitAsync( jobTarget, jobDesc, "Job Arg"); string jobResult = await jobExecution.GetResultAsync(); ``` +### Implement a .NET Compute Job + +1. Prepare a "class library" project for the job implementations (`dotnet new classlib`). Prefer a separate project for compute jobs to reduce deployment size. +2. Add a reference to `Apache.Ignite` package to the class library project (`dotnet add package Apache.Ignite`). +3. Create a class that implements `IComputeJob<TArg, TRes>` interface + ```csharp + public class HelloJob : IComputeJob<string, string> + { + public ValueTask<string> ExecuteAsync(IJobExecutionContext context, string arg, CancellationToken cancellationToken) => + ValueTask.FromResult("Hello " + arg); + } + ``` +4. Publish the project (`dotnet publish -c Release`) +5. Copy the resulting dll file (and any extra dependencies, EXCLUDING Ignite dlls) to a separate directory. + * Note: The directory must not contain any subdirectories. +6. Use [Ignite CLI](https://ignite.apache.org/docs/ignite3/latest/ignite-cli-tool#cluster-commands) `cluster unit deploy` command to deploy the directory to the cluster as a deployment unit. + +### Run a .NET Compute Job + +.NET compute jobs can be executed from any client (.NET, Java, C++, etc), +by specifying the assembly-qualified class name and using the `JobExecutorType.DotNetSidecar` option. + Review Comment: ```suggestion For information about running jobs from Java, see [Distributed Computing](https://ignite.apache.org/docs/ignite3/latest/developers-guide/compute/compute) in Ignite documentation. To run your job from .NET: ``` ########## modules/platforms/dotnet/README.md: ########## @@ -222,22 +222,73 @@ await tx.CommitAsync(); ## Compute -Compute API is used to execute distributed computations on the cluster. Compute jobs should be implemented in Java, deployed to server nodes, and called by the full class name. +Compute API is used to execute distributed computations on the cluster. -```cs -IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); +Compute jobs can be implemented in Java or .NET. +Resulting binaries (jar or dll files) should be [deployed](https://ignite.apache.org/docs/ignite3/latest/developers-guide/code-deployment/code-deployment) to the server nodes and called by the full class name. + +Java job invocation example: +```csharp +IList<IClusterNode> nodes = await client.GetClusterNodesAsync(); IJobTarget<IEnumerable<IClusterNode>> jobTarget = JobTarget.AnyNode(nodes); var jobDesc = new JobDescriptor<string, string>( - "org.foo.bar.MyJob"); + JobClassName: "org.foo.bar.MyJob", + DeploymentUnits: [new DeploymentUnit("Unit1")]); IJobExecution<string> jobExecution = await client.Compute.SubmitAsync( jobTarget, jobDesc, "Job Arg"); string jobResult = await jobExecution.GetResultAsync(); ``` +### Implement a .NET Compute Job + +1. Prepare a "class library" project for the job implementations (`dotnet new classlib`). Prefer a separate project for compute jobs to reduce deployment size. +2. Add a reference to `Apache.Ignite` package to the class library project (`dotnet add package Apache.Ignite`). +3. Create a class that implements `IComputeJob<TArg, TRes>` interface + ```csharp + public class HelloJob : IComputeJob<string, string> + { + public ValueTask<string> ExecuteAsync(IJobExecutionContext context, string arg, CancellationToken cancellationToken) => + ValueTask.FromResult("Hello " + arg); + } + ``` +4. Publish the project (`dotnet publish -c Release`) +5. Copy the resulting dll file (and any extra dependencies, EXCLUDING Ignite dlls) to a separate directory. + * Note: The directory must not contain any subdirectories. +6. Use [Ignite CLI](https://ignite.apache.org/docs/ignite3/latest/ignite-cli-tool#cluster-commands) `cluster unit deploy` command to deploy the directory to the cluster as a deployment unit. + +### Run a .NET Compute Job + +.NET compute jobs can be executed from any client (.NET, Java, C++, etc), +by specifying the assembly-qualified class name and using the `JobExecutorType.DotNetSidecar` option. + +```csharp +var jobTarget = JobTarget.AnyNode(await client.GetClusterNodesAsync()); +var jobDesc = new JobDescriptor<string, string>( + JobClassName: typeof(HelloJob).AssemblyQualifiedName!, + DeploymentUnits: [new DeploymentUnit("unit1")], + Options: new JobExecutionOptions(ExecutorType: JobExecutorType.DotNetSidecar)); + +IJobExecution<string> jobExec = await client.Compute.SubmitAsync(jobTarget, jobDesc, "world"); +``` + +Alternatively, use `JobDescriptor.Of` shortcut method to create a job descriptor from a job instance: Review Comment: ```suggestion Alternatively, use the `JobDescriptor.Of` shortcut method to create a job descriptor from a job instance: ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: notifications-unsubscr...@ignite.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org