GithubHelp home page GithubHelp logo

oracle / coherence-dotnet-extend-client Goto Github PK

View Code? Open in Web Editor NEW
11.0 16.0 13.0 2.56 MB

Coherence .NET client library

License: Universal Permissive License v1.0

C# 98.81% Java 1.19%
dotnet coherence caching in-memory clustering distributed data-grid scalability microservices polyglot

coherence-dotnet-extend-client's Introduction


CI Build License

Oracle Coherence for .NET - Community Edition

Contents

  1. Introduction to Coherence
  2. How to Get Coherence Community Edition
  3. Getting Started
  4. Building
  5. CLI Hello Coherence Example
  6. Testing
  7. Documentation
  8. Contributing

Introduction to Coherence

Coherence is a scalable, fault-tolerant, cloud-ready, distributed platform for building grid-based applications and reliably storing data. The product is used at scale, for both compute and raw storage, in a vast array of industries such as critical financial trading systems, high performance telecommunication products and eCommerce applications.

Typically these deployments do not tolerate any downtime and Coherence is chosen due to its novel features in death detection, application data evolvability, and the robust, battle-hardened core of the product that enables it to be seamlessly deployed and adapted within any ecosystem.

At a high level, Coherence provides an implementation of the familiar IDictionary interface but rather than storing the associated data in the local process it is partitioned (or sharded) across a number of designated remote nodes. This partitioning enables applications to not only distribute (and therefore scale) their storage across multiple processes, machines, racks, and data centers but also to perform grid-based processing to truly harness the CPU resources of the machines.

The Coherence interface INamedCache (an extension of IDictionary) provides methods to query, aggregate (map/reduce style) and compute (send functions to storage nodes for locally executed mutations) the data set. These capabilities, in addition to numerous other features, enable Coherence to be used as a framework for writing robust, distributed applications.

How to Get Coherence Community Edition

For more details on how to obtain and use Coherence, please see the Coherence CE README.

Getting Started

Coherence for .NET allows .NET applications to access Coherence clustered services, including data, data events, and data processing from outside the Coherence cluster. Typical uses of Coherence for .NET include desktop and web applications that require access to Coherence caches.

Coherence for .NET consists of a lightweight .NET library that connects to a Coherence clustered service instance running within the Coherence cluster using a high performance TCP/IP-based communication layer. This library sends all client requests to the Coherence clustered proxy service which, in turn, responds to client requests by delegating to an actual Coherence clustered service (for example, a Partitioned or Replicated cache service).

See the documentation for details on building Coherence applications using .NET.

Building

Prerequisites and Dependencies

  1. Microsoft .NET 4.0 or higher runtime and SDK
  2. Supported Microsoft Windows operating system (see the systemrequirements for the appropriate .NET runtime above)
  3. Microsoft Visual Studio 2010+, or Visual Studio Code with the NET plugin installed is required to build

The Coherence for .NET also depends on the following libraries and software:

  1. Common.Logging, 2.0.0.0
  2. MSBuild.Extension.Pack, 1.9.1
  3. Sandcastle Help File Builder and Tools, 2019.11.17
  4. Microsoft Build Tools 2015

Common.Logging 2.0.0.0

Download and install Common.Logging 2.0.0.0 (https://www.nuget.org/packages/Common.Logging/2.0.0) or later. Copy Common.Logging.2.0.0\lib\2.0 to lib\net\2.0.

MSBuild.Extension.Pack.1.9.1

Download and install MSBuild.Extension.Pack, 1.9.1 (https://www.nuget.org/packages/MSbuild.Extension.Pack/1.9.0). Copy MSBuild.Extension.Pack.1.9.1 to tools\internal\msbuild.

Sandcastle Help File Builder and Tools, 2019.11.17

Coherence uses Sandcastle Help File Builder and Tools to build the Coherence .NET documentation. Down load and install Sandcastle Help File Builder and Tools, 2019.11.17 (https://github.com/EWSoftware/SHFB/releases). Then copy the "Sandcastle Help File Builder" directory to tools\internal\shfb.

Microsoft Build Tools 2015

Sandcastle Help File Builder and Tools requires Microsoft Build Tools 2015. You can down load Microsoft Build Tools 2015(https://www.microsoft.com/en-us/download/details.aspx?id=48159)or later and install it if you don't have it already.

The following additional dependencies are required for testing:

  1. NUnit 2 releases, 2.6.2
  2. NUnit.Runners, 2.6.2
  3. Ant, 1.7.0
  4. Java 1.8 or later
  5. WinHttpCertCfg.exe

NUnit 2.6.2

Download and install NUnit, 2.6.2 (https://nunit.org/download/#olderReleases) or later. Copy NUnit.2.6.2 to tools\internal\nunit

NUnit.Runners, 2.6.2

Download and install NUnit.Runners, 2.6.2 (https://www.nuget.org/packages/NUnit.Runners/2.6.2) or later. Copy NUnit.Runners.2.6.2 to tools\internal\NUnit.Runners

Ant

Download and install Ant, 1.7.0 or later. Then copy it to under tools\internal\ant.

WinHttpCertCfg.exe

Download and install WinHttpCertCfg.exe ('https://www.microsoft.com/en-us/download/details.aspx?id=19801`). Then copy it to tools\internal\resourcekit.

You can use NuGet Package Manager through Visual Studio or Develooper Command Prompt to download most of the dependency libraries and software.

If C:\coherence-net is your project root directory, it should contain the following directories

  • C:\coherence-net\lib\net\2.0
  • C:\coherence-net\tools\cluster-control
  • C:\coherence-net\tools\internal\ant
  • C:\coherence-net\tools\internal\cluster-control
  • C:\coherence-net\tools\internal\msbuild
  • C:\coherence-net\tools\internal\msbuild-custom
  • C:\coherence-net\tools\internal\nunit
  • C:\coherence-net\tools\internal\nunit.runners
  • C:\coherence-net\tools\internal\resourcekit
  • C:\coherence-net\tools\internal\shfb
  • C:\coherence-net\tools\msbuild-custom

The Coherence for .NET build system is based upon msbuild. To build Coherence for .NET, you must run the msbuild build utility, passing in the desired target that you would like to execute. The output from the build are in the build subdirectory.

To build Coherence for .NET, start a "Developer Command Prompt for VS" 2017 or 2019. Clone this repository and run the following command:

set JAVA_HOME=<Java Home Path>
bin\cfgbuild.cmd
msbuild /t:build Coherence.msbuild

The resulting files:

build\Coherence.2010\Debug - debug build

build\Coherence.2010\Release - release build

To clean all build artifacts from your build system, run the following command:

msbuild /t:clean Coherence.msbuild

CLI Hello Coherence Example

The following example illustrates starting a storage enabled Coherence server, followed by running the HelloCoherence console application. The HelloCoherence application inserts and retrieves data from the Coherence server.

Build HelloCoherence

  1. Using dotnet-cli to create a HelloCoherence console application:
dotnet new console -name "HelloCoherence"
  1. Add the following references to the HelloCoherence.csproj (provide the Coherence.dll location in the <HintPath>):
  <ItemGroup>
    <Reference Include="Coherence, Version=14.1.2.0, Culture=neutral, PublicKeyToken=0ada89708fdf1f9a, processorArchitecture=MSIL">
      <HintPath>Coherence.dll</HintPath>
    </Reference>
    <PackageReference Include="Common.Logging" Version="3.4.1" />
    <PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
  </ItemGroup>

Also include any Coherence configuration files you may have.

  1. Replace Program.cs code with the following source:
/*
 * Copyright (c) 2000, 2022, Oracle and/or its affiliates.
 *
 * Licensed under the Universal Permissive License v 1.0 as shown at
 * http://oss.oracle.com/licenses/upl.
 */
using System;
using Tangosol.Net;
using Tangosol.Net.Cache;
using Tangosol.Run.Xml;
namespace Hello
{
    class Program
    {
        static void Main(string[] args)
        {
            // Display title as the C# console Coherence app and
            // show user the valid commands:
            Console.WriteLine("Coherence for .NET Extend Client");
            Console.WriteLine("The following are the available cache operations:");
            Console.WriteLine("\tcache <cacheName> - specify a cache name to use");
            Console.WriteLine("\tput <key> <value> - put a <key, value> pair into the cache");
            Console.WriteLine("\tget <key> - get the value of a given key from the cache");
            Console.WriteLine("\tremove <key> - remove an entry of the given key from the cache");
            Console.WriteLine("\tlist - list all the entries in the cache");
            Console.WriteLine("\tsize - get the size of the cache");
            Console.WriteLine("\tbye - exit the console");
            Console.WriteLine();
            Console.Write("Map (?): ");

            // Declare variabs.
            String      cacheName  = null;
            INamedCache namedCache = null;
            String      op         = Console.ReadLine().ToLower();
            String[]    opList     = op.Split();

            // Processing cache operations.
            while (opList[0].CompareTo("bye") != 0)
            {
                String key;
                String value;

                if (!opList[0].Equals("cache") && namedCache == null)
                {
                    Console.WriteLine("No named cache.  Please specify a named cache to use.");
                }
                else
                {
                    switch (opList[0])
                    {
                        case "cache":
						    if (opList.Length < 2)
							{
								Console.WriteLine("No cache name.  Please specify a cache name to use.");
							}
							else
							{
								cacheName = opList[1];
								namedCache = CacheFactory.GetCache(cacheName);
							}
                            break;

                        case "put":
						    if (opList.Length < 3)
							{
								Console.WriteLine("No key/value pair.  Please specify the key and value to be put into the cache.");
							}
							else
							{
								key = opList[1];
								value = opList[2];
								namedCache[key] = value;
							}
                            break;

                        case "get":
						    if (opList.Length < 2)
							{
								Console.WriteLine("No key.  Please specify the key to get.");
							}
							else
							{
								key = opList[1];
								var result = namedCache[key];
								Console.WriteLine(result == null ? "NULL" : namedCache[key]);
							}
                            break;

                        case "remove":
						    if (opList.Length < 2)
							{
								Console.WriteLine("No key.  Please specify the key to remove.");
							}
							else
							{
								key = opList[1];
								namedCache.Remove(key);
							}
                            break;

                        case "list":
                            foreach (ICacheEntry entry in namedCache.Entries)
                            {
                                Console.WriteLine(entry.Key + " = " + entry.Value);
                            }
                            break;

                        case "size":
                            Console.WriteLine(namedCache.Count);
                            break;

                        default:
                            Console.WriteLine("Valid operations are: cache, put, get, remove, list, size, and bye.");
                            break;
                    }
                }

                Console.WriteLine("");
                if (namedCache == null)
                {
                    Console.Write("Map (?): ");
                }
                else
                {
                    Console.Write("Map (" + cacheName + "): ");
                }

                // Read cache operation
                op = Console.ReadLine().ToLower();
                opList = op.Split();
            }
        }
    }
}

By default, you need to provide a POF configure file, pof-config.xml, in the TargetFramework directory. Below are a sample pof-config.xml file:

<?xml version="1.0"?>
<!--
  Copyright (c) 2000, 2020, Oracle and/or its affiliates.

  Licensed under the Universal Permissive License v 1.0 as shown at
  http://oss.oracle.com/licenses/upl.
-->
<pof-config xmlns="http://schemas.tangosol.com/pof">
  <user-type-list>
    <!-- include all "standard" Coherence POF user types -->
    <include>assembly://Coherence/Tangosol.Config/coherence-pof-config.xml</include>

    <!-- include all application POF user types -->
  </user-type-list>
</pof-config>
  1. Build the HelloCoherence project
dotnet build

Start a Coherence server

"%JAVA_HOME%\bin\java" -Dcoherence.pof.enabled=true -Dcoherence.log.level=9 -jar coherence.jar

Run the Hello Coherence example

dotnet run
Coherence for .NET Extend Client
The following are the available cache operations:
        cache <cacheName> - specify a cache name to use
        put <key> <value> - put a <key, value> pair into the cache
        get <key> - get the value of a given key from the cache
        remove <key> - remove an entry of the given key from the cache
        list - list all the entries in the cache
        size - get the size of the cache
        bye - exit the console
		
Map (?): cache welcomes

Map (welcomes): get english
NULL

Map (welcomes): put english Hello

Map (welcomes): put spanish Hola

Map (welcomes): put french Bonjour

Map (welcomes): get english
Hello

Map (welcomes): list
french = Bonjour
english = Hello
spanish = Hola

Map (welcomes): bye
dotnet run
Coherence for .NET Extend Client
The following are the available cache operations:
        cache <cacheName> - specify a cache name to use
        put <key> <value> - put a <key, value> pair into the cache
        get <key> - get the value of a given key from the cache
        remove <key> - remove an entry of the given key from the cache
        list - list all the entries in the cache
        size - get the size of the cache
        bye - exit the console
		
Map (?): cache welcomes

Map (welcomes): list
french = Bonjour
english = Hello
spanish = Hola

Map (welcomes): bye

Testing

To run Coherence for .NET test suite, you must have a coherence.jar. Using ant, you can provide a build.properties file in the tools\ant directory to specify a maven repository from which coherence.jar can be downloaded. The test suite starts a Coherence server for the .NET clients to connect to run the tests.

msbuild /t:test Coherence.msbuild

To run Coherence for .NET test suite starting a Coherence server in docker container, use the following commaond:

msbuild /t:test Coherence.docker

Documentation

To build Coherence for .NET API documentation, run the following command. The API documentation can be viewed using Microsoft help viewer.

msbuild /t:doc Coherence.msbuild

To build Coherence for .NET installable package, use the following command. The command produces a Coherence.msi in the build directory that can be used to install Coherence for .NET.

msbuild /t:dist Coherence.msbuild

The resulting files:

dist\14.1.2.0b0 - Coherence MSI installer

For further details on developing Coherence for .NET applications, see the documentation here.

Contributing

This project welcomes contributions from the community. Before submitting a pull request, please review our contribution guide

Security

Please consult the security guide for our responsible security vulnerability disclosure process.

License

Copyright (c) 2020, 2024 Oracle and/or its affiliates.

Released under the Universal Permissive License v1.0 as shown at https://oss.oracle.com/licenses/upl/.

coherence-dotnet-extend-client's People

Contributors

agleyzer10 avatar aseovic avatar chpatel3 avatar dhirupandey avatar fryp avatar harveyraja avatar lsho avatar rlubke avatar thegridman avatar vasac avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

coherence-dotnet-extend-client's Issues

Broken Extend Proxy SSLHandling - Correct Server SSL Certificate fail with RemoteCertificateNameMismatch

Description

The SSL Handshake between Extend-Client and an SSL secured Extend-Proxy fails with RemoteCertificateNameMismatch when Certificate is correctly generated to match extend proxy host name.

Reproduce

  1. Generate a valid SSL Certificate with a CN matching the host on which the extend proxy is running.
  2. Secure the Extend Proxy with the SSL certificate
  3. Configure Extend Client to connect to SSL Secured Extend Proxy
  4. Configure Extend Client Configuration to use Tangosol.Net.SslStreamProvider.StrictCertificateValidation as the remote-certificate-validator (or write one which does not allow SSL Handshake errors)
  5. Attempt to establish a connection between the client and proxy

The SSL handshake will fail with RemoteCertificateNameMismatch.

Expected Behaviour

The SSL handshake should succeed.

Cause

The cause of this error is due to the parameters passed to the System.Net.Security.SslStream.AuthenticateAsClient method.

In Tangosol.net.SslStreamProvider:182, the serverName is always the IP Address of the targetHost and not the Fully Qualified Domain Name of the host.

This goes back to Tangosol.net.SslStreamProvider:172 where SslStreamProvider.ServerName is not correctly initialised at the point of creating the SslStreamProvider and is always null.

Correctly initialising the serverName with the FQDN of the remote endpoint would resolve this issue

I'm not sure about the correct place SslStreamProvider.ServerName should be initialised but a quick fix would be to replace SslStreamProvider:172

                string serverName = string.IsNullOrEmpty(ServerName)
                        ? ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString()
                        : ServerName;

with

string serverName ;
try {
   // try to get FQDN
   IPHostEntry host = Dns.GetHostEntry(((IPEndPoint)client.Client.RemoteEndPoint).Address);
   serverName = host.HostName ;
} catch (Exception x) 
{
   // failed - revert to IP Address 
   serverName = ((IPEndPoint)client.Client.RemoteEndPoint).Address.ToString();
   CacheFactory.Log("Failed to get FQDN for address " + serverName + " due to " + x.GetType().Name + " - " x.Message, CacheFactory.LogLevel.Warn);
}

Environment

Not Applicable.

cache-config local-certificate selector element does not override default LocalCertificateSelector callback

Description

The cache-config schema allows for the specification of a custom delegate to override the default LocalCertificateSelector.
However a bug in XML processing routine means that the <selector> element is never found and so it is not possible customise the LocalCertificateSelector.

How to reproduce this bug

Create a cache-config file which provides the <selector> element as per the cache-config.xsd

XPath:
/cache-config/caching-scheme/remote-cache-scheme/initiator-config/tcp-initiator/stream-provider/ssl/local-certificates/selector

XSD Snippet:

<xs:complexType name="local-certificates">
    <xs:sequence>
      <xs:element ref="certificate" maxOccurs="unbounded"/>
      <xs:element ref="selector" minOccurs="0"/>
    </xs:sequence>
</xs:complexType>

Example

...
<ssl>
   <local-certificates>
      <certificate>
...
      </certificate>
      <selector>
         <delegate>
            <type>static</type>
            <class-name>name.space.myclass,assembly-name, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</class-name>
            <method-name>MyLocalCertificateSelector</method-name>
         </delegate>
      </selector>
   </local-certificates>
</ssl>

Cause

This is due to a bug in the xml processing code in Tangosol.Net.SslStreamProvider.Config
where the lookup for the <selector> is performed not for a child element of <local-certificate> but of the <ssl> element.

Expected Behaviour

The behaviour should be for the delegate specified in the <selector> element to override the default LocalCertificateSelector. This does not happen.

Environment

This is a .Net library Client side configuration file processing bug in the C# library. The cluster side configuration beyond requiring 2 way ssl does not come in to the equation at all. Client side environment is

Item value
OS Windows 10
.Net Framework Version 4.7.2

This bug also exists in the non-community editions of the .Net libraries both for 12.2.1.4 and 14.1.1.0.

SSL Remote Certificate Validator - Insecure Defaults

Description

Tangosol.Net. SslStreamProvider - has insecure defaults. The default SSL Certificate Validator allows RemoteCertificateNameMismatch.

See Tangosol.Net. SslStreamProvider:272

The correct behaviour can be achieved by replacing

RemoteCertificateValidator = xmlSub == null
                        ? DefaultCertificateValidation
                        : XmlHelper.CreateDelegate<RemoteCertificateValidationCallback>(xmlSub.GetElement("delegate"));

with

RemoteCertificateValidator = xmlSub == null
                        ? StrictCertificateValidation
                        : XmlHelper.CreateDelegate<RemoteCertificateValidationCallback>(xmlSub.GetElement("delegate"));

Reproduce

Secure your extent-proxy with any valid SSL certificate on a host with a different name to what the certificate was issued for. Access the extend proxy from an extend client and the SSL handshake will succeed.

Expected Behaviour

SSL Handshake should fail with an error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.