Skip to content

Commit 1236d3f

Browse files
Katia Arestikaresti
authored andcommitted
Include non Java guides
1 parent 198e0e4 commit 1236d3f

9 files changed

Lines changed: 343 additions & 12 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ build
5353
# node.js dependency directory
5454
# https://docs.npmjs.com/misc/faq#should-i-check-my-node-modules-folder-into-git
5555
node_modules
56+
# Python virtual environments
57+
.venv
5658
# OpenShift
5759
openshift.local.clusterup
5860
non-java-clients/node.js/package-lock.json

docs-maven-plugin/src/main/java/org/infinispan/tutorial/docs/GuideMetadataGenerator.java

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class GuideMetadataGenerator {
2929

3030
private static final Set<String> SKIP_DIRS = Set.of(
31-
"target", "docs", "documentation", "docs-maven-plugin", "non-java-clients", ".git", ".github");
31+
"target", "docs", "documentation", "docs-maven-plugin", ".git", ".github");
3232

3333
private final Path srcDir;
3434
private final Path outputDir;
@@ -63,12 +63,8 @@ public void generate() throws IOException {
6363
}
6464
Files.createDirectories(guidesOutputDir);
6565

66-
Options options = Options.builder()
67-
.safe(SafeMode.UNSAFE)
68-
.build();
69-
7066
try (Asciidoctor asciidoctor = Asciidoctor.Factory.create()) {
71-
collectGuides(srcDir, "", asciidoctor, options, guides, guidesOutputDir);
67+
collectGuides(srcDir, "", asciidoctor, guides, guidesOutputDir);
7268
}
7369

7470
guides.sort(Comparator.comparing(g -> (String) g.get("id")));
@@ -88,7 +84,7 @@ public void generate() throws IOException {
8884
}
8985

9086
private void collectGuides(Path dir, String prefix, Asciidoctor asciidoctor,
91-
Options options, List<Map<String, Object>> guides, Path guidesOutputDir)
87+
List<Map<String, Object>> guides, Path guidesOutputDir)
9288
throws IOException {
9389
try (Stream<Path> entries = Files.list(dir)) {
9490
List<Path> sorted = entries.sorted().toList();
@@ -104,10 +100,11 @@ private void collectGuides(Path dir, String prefix, Asciidoctor asciidoctor,
104100
String dirName = stripPrefix(entry.getFileName().toString());
105101
if (Files.exists(guideFile)) {
106102
String id = prefix.isEmpty() ? dirName : prefix + "-" + dirName;
107-
processGuide(guideFile, id, asciidoctor, options, guides, guidesOutputDir);
103+
String language = deriveLanguage(guideFile);
104+
processGuide(guideFile, id, language, asciidoctor, guides, guidesOutputDir);
108105
}
109106
String subPrefix = prefix.isEmpty() ? dirName : prefix + "-" + dirName;
110-
collectGuides(entry, subPrefix, asciidoctor, options, guides, guidesOutputDir);
107+
collectGuides(entry, subPrefix, asciidoctor, guides, guidesOutputDir);
111108
}
112109
}
113110
}
@@ -119,17 +116,33 @@ private String stripPrefix(String dirName) {
119116
return dirName;
120117
}
121118

122-
private void processGuide(Path guideFile, String id, Asciidoctor asciidoctor,
123-
Options options, List<Map<String, Object>> guides, Path guidesOutputDir)
119+
private static final String NON_JAVA_CLIENTS_DIR = "non-java-clients";
120+
121+
private String deriveLanguage(Path guideFile) {
122+
Path relative = srcDir.relativize(guideFile.getParent());
123+
if (relative.getNameCount() >= 2
124+
&& relative.getName(0).toString().equals(NON_JAVA_CLIENTS_DIR)) {
125+
return relative.getName(1).toString();
126+
}
127+
return "java";
128+
}
129+
130+
private void processGuide(Path guideFile, String id, String language, Asciidoctor asciidoctor,
131+
List<Map<String, Object>> guides, Path guidesOutputDir)
124132
throws IOException {
125133
String content = Files.readString(guideFile);
126-
Document doc = asciidoctor.load(content, options);
134+
Options perGuideOptions = Options.builder()
135+
.safe(SafeMode.UNSAFE)
136+
.baseDir(guideFile.getParent().toFile())
137+
.build();
138+
Document doc = asciidoctor.load(content, perGuideOptions);
127139

128140
Map<String, Object> guide = new LinkedHashMap<>();
129141
guide.put("id", id);
130142
guide.put("title", doc.getDoctitle());
131143
guide.put("summary", attrString(doc, "summary"));
132144
guide.put("mode", attrString(doc, "mode"));
145+
guide.put("language", language);
133146
guide.put("topics", splitComma(attrString(doc, "topics")));
134147
guide.put("keywords", splitComma(attrString(doc, "keywords")));
135148
guide.put("source-dir", attrString(doc, "source-dir"));

docs-maven-plugin/src/test/java/org/infinispan/tutorial/docs/GuideMetadataGeneratorTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void generatesIndexFromGuideFiles() throws Exception {
3232
assertTrue(yaml.contains("mode: remote"), "should contain mode attribute");
3333
assertTrue(yaml.contains("mode: embedded"), "should contain mode attribute");
3434
assertTrue(yaml.contains("caching"), "should contain topic");
35+
assertTrue(yaml.contains("language: java"), "should default language to java");
3536
}
3637

3738
@Test

non-java-clients/c#/guide.adoc

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
= C# Hot Rod Client: Getting Started
2+
:summary: Connect to an Infinispan Server and perform basic cache operations with the C# Hot Rod client
3+
:mode: remote
4+
:topics: caching,getting-started,non-java
5+
:keywords: cache,put,get,remote,hot-rod,csharp,dotnet
6+
:duration: 10
7+
:source-dir: non-java-clients/c#
8+
9+
== What You Will Learn
10+
11+
How to connect a C# Hot Rod client to an Infinispan Server and perform basic cache operations: put, get, and print values.
12+
13+
== Prerequisites
14+
15+
* .NET Framework 4.5+ or Mono
16+
* Infinispan C# Hot Rod client library (`hotrodcs.dll`)
17+
* An Infinispan Server running on `127.0.0.1:11222`
18+
19+
== Step 1: Configure the Client
20+
21+
Create a `ConfigurationBuilder` and point it to the Infinispan Server:
22+
23+
[source,csharp]
24+
----
25+
ConfigurationBuilder builder = new ConfigurationBuilder();
26+
Configuration conf = builder.AddServers("127.0.0.1:11222").Build();
27+
----
28+
29+
== Step 2: Connect and Perform Cache Operations
30+
31+
Initialize the `RemoteCacheManager`, get a cache, and store and retrieve a value:
32+
33+
[source,csharp]
34+
----
35+
RemoteCacheManager remoteManager = new RemoteCacheManager(conf);
36+
remoteManager.Start();
37+
IRemoteCache<string, string> cache = remoteManager.GetCache<string, string>();
38+
cache.Put("key", "value");
39+
Console.WriteLine("key = {0}", cache.Get("key"));
40+
remoteManager.Stop();
41+
----
42+
43+
== Step 3: Build and Run
44+
45+
Build the project with MSBuild or Mono:
46+
47+
[source,bash]
48+
----
49+
# MSBuild (Windows)
50+
msbuild simple.sln
51+
52+
# Mono (Linux/macOS)
53+
xbuild simple.sln
54+
----
55+
56+
You should see output like:
57+
58+
----
59+
key = value
60+
----

non-java-clients/c++/guide.adoc

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
= C++ Hot Rod Client: Getting Started
2+
:summary: Connect to an Infinispan Server and perform basic cache operations with the C++ Hot Rod client
3+
:mode: remote
4+
:topics: caching,getting-started,non-java
5+
:keywords: cache,put,get,remote,hot-rod,cpp
6+
:duration: 10
7+
:source-dir: non-java-clients/c++
8+
9+
== What You Will Learn
10+
11+
How to connect a C++ Hot Rod client to an Infinispan Server and perform basic cache operations: put, get, and print values.
12+
13+
== Prerequisites
14+
15+
* C++11 compatible compiler
16+
* CMake 2.6+
17+
* Infinispan C++ Hot Rod client library (`libhotrod`)
18+
* An Infinispan Server running on `127.0.0.1:11222`
19+
20+
== Step 1: Configure the Client
21+
22+
Create a `ConfigurationBuilder` and add the server connection:
23+
24+
[source,cpp]
25+
----
26+
ConfigurationBuilder builder;
27+
builder.addServer().host("127.0.0.1").port(11222);
28+
----
29+
30+
== Step 2: Connect and Perform Cache Operations
31+
32+
Initialize the `RemoteCacheManager`, get a cache, and store and retrieve a value:
33+
34+
[source,cpp]
35+
----
36+
RemoteCacheManager cacheManager(builder.build(), false);
37+
RemoteCache<std::string, std::string> cache =
38+
cacheManager.getCache<std::string, std::string>("default", false);
39+
cacheManager.start();
40+
cache.put("key", "value");
41+
std::cout << "key = " << *cache.get("key") << std::endl;
42+
cacheManager.stop();
43+
----
44+
45+
== Step 3: Build and Run
46+
47+
Build the project with CMake:
48+
49+
[source,bash]
50+
----
51+
mkdir build && cd build
52+
cmake ..
53+
make
54+
./simple
55+
----
56+
57+
You should see output like:
58+
59+
----
60+
key = value
61+
----
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
= Node.js Hot Rod Client: Getting Started
2+
:summary: Connect to an Infinispan Server and perform basic cache operations with the Node.js Hot Rod client
3+
:mode: remote
4+
:topics: caching,getting-started,non-java
5+
:keywords: cache,put,get,remote,hot-rod,nodejs,javascript
6+
:duration: 10
7+
:source-dir: non-java-clients/node.js
8+
9+
== What You Will Learn
10+
11+
How to connect a Node.js Hot Rod client to an Infinispan Server and perform basic cache operations: put, get, and print values.
12+
13+
== Prerequisites
14+
15+
* Node.js
16+
* An Infinispan Server running on `127.0.0.1:11222`
17+
18+
== Step 1: Install Dependencies
19+
20+
[source,bash]
21+
----
22+
npm install
23+
----
24+
25+
This installs the `infinispan` Hot Rod client package.
26+
27+
== Step 2: Connect and Perform Cache Operations
28+
29+
Create a client with authentication and connect to the server:
30+
31+
[source,javascript]
32+
----
33+
var infinispan = require('infinispan');
34+
35+
var connected = infinispan.client(
36+
{port: 11222, host: '127.0.0.1'},
37+
{
38+
cacheName: 'my-cache',
39+
clientIntelligence: 'BASIC',
40+
authentication: {
41+
enabled: true,
42+
saslMechanism: 'DIGEST-MD5',
43+
userName: 'admin',
44+
password: 'password'
45+
}
46+
}
47+
);
48+
----
49+
50+
Then put and get a value:
51+
52+
[source,javascript]
53+
----
54+
connected.then(function(client) {
55+
client.put('key', 'value').then(function () {
56+
return client.get('key').then(function (value) {
57+
console.log('key = ' + value);
58+
});
59+
}).finally(function() {
60+
return client.disconnect();
61+
});
62+
});
63+
----
64+
65+
== Step 3: Run the Tutorial
66+
67+
[source,bash]
68+
----
69+
npm start
70+
----
71+
72+
You should see output like:
73+
74+
----
75+
Connected
76+
key = value
77+
Disconnected
78+
----

non-java-clients/python/guide.adoc

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
= Python REST Client: Getting Started
2+
:summary: Connect to an Infinispan Server and perform basic cache operations with Python and the REST API
3+
:mode: remote
4+
:topics: caching,getting-started,non-java
5+
:keywords: cache,put,get,remote,rest,python
6+
:duration: 10
7+
:source-dir: non-java-clients/python
8+
9+
== What You Will Learn
10+
11+
How to connect a Python client to an Infinispan Server using the REST API and perform basic cache operations: create a cache, put, get, and print values.
12+
13+
== Prerequisites
14+
15+
* Python 3.8+
16+
* An Infinispan Server running on `127.0.0.1:11222`
17+
18+
== Step 1: Install Dependencies
19+
20+
[source,bash]
21+
----
22+
python3 -m venv .venv
23+
source .venv/bin/activate
24+
pip install -r requirements.txt
25+
----
26+
27+
== Step 2: Create a Cache
28+
29+
Use the REST API to create a distributed cache:
30+
31+
[source,python]
32+
----
33+
requests.post(
34+
f"{SERVER_URL}/rest/v2/caches/{CACHE_NAME}",
35+
headers={"Content-Type": "application/json"},
36+
data='{"distributed-cache": {"mode": "SYNC"}}',
37+
auth=AUTH,
38+
)
39+
----
40+
41+
== Step 3: Store and Retrieve Data
42+
43+
Put a value and get it back:
44+
45+
[source,python]
46+
----
47+
requests.put(
48+
f"{SERVER_URL}/rest/v2/caches/{CACHE_NAME}/key",
49+
data="value",
50+
headers={"Content-Type": "text/plain"},
51+
auth=AUTH,
52+
)
53+
54+
response = requests.get(
55+
f"{SERVER_URL}/rest/v2/caches/{CACHE_NAME}/key",
56+
auth=AUTH,
57+
)
58+
print(f"key = {response.text}")
59+
----
60+
61+
== Step 4: Run the Tutorial
62+
63+
[source,bash]
64+
----
65+
python3 simple.py
66+
----
67+
68+
You should see output like:
69+
70+
----
71+
key = value
72+
----
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requests>=2.28

0 commit comments

Comments
 (0)