17.5. 批处理操作示例

使用这些示例批处理操作作为使用 Batch CR 创建和修改 Data Grid 资源的起点。

注意

您只能通过 ConfigMap 将配置文件传递给 Data Grid Operator。

ConfigMap/etc/batch 的 Data Grid pod 中挂载,因此您必须使用该路径添加所有 --file= 指令。

17.5.1. 缓存

  • 从配置文件创建多个缓存。
echo "creating caches..."
create cache sessions --file=/etc/batch/infinispan-prod-sessions.xml
create cache tokens --file=/etc/batch/infinispan-prod-tokens.xml
create cache people --file=/etc/batch/infinispan-prod-people.xml
create cache books --file=/etc/batch/infinispan-prod-books.xml
create cache authors --file=/etc/batch/infinispan-prod-authors.xml
echo "list caches in the cluster"
ls caches
  • 从文件创建模板,然后从模板创建缓存。
echo "creating caches..."
create cache mytemplate --file=/etc/batch/mycache.xml
create cache sessions --template=mytemplate
create cache tokens --template=mytemplate
echo "list caches in the cluster"
ls caches

17.5.2. 计数器

使用 Batch CR 创建多个计数器,可以递增和缩减记录对象计数。

您可以使用计数器来生成标识符、作为速率限制器,或者跟踪访问资源的次数。

echo "creating counters..."
create counter --concurrency-level=1 --initial-value=5 --storage=PERSISTENT --type=weak mycounter1
create counter --initial-value=3 --storage=PERSISTENT --type=strong mycounter2
create counter --initial-value=13 --storage=PERSISTENT --type=strong --upper-bound=10 mycounter3
echo "list counters in the cluster"
ls counters

17.5.3. protobuf schema

注册 Protobuf 模式以在缓存中查询值。protobuf schema(.proto 文件)提供有关自定义实体和控制字段索引的元数据。

echo "creating schema..."
schema --upload=person.proto person.proto
schema --upload=book.proto book.proto
schema --upload=author.proto book.proto
echo "list Protobuf schema"
ls schemas

17.5.4. 任务

上传实现 org.infinispan.tasks.ServerTask 或与 javax.script 脚本 API 兼容的任务。

echo "creating tasks..."
task upload --file=/etc/batch/myfirstscript.js myfirstscript
task upload --file=/etc/batch/mysecondscript.js mysecondscript
task upload --file=/etc/batch/mythirdscript.js mythirdscript
echo "list tasks"
ls tasks

其他资源