
:guide-id: concepts-infinispan-cli-batch
:guide-title: Concepts to automate {jdgserver_name} CLI commands
:guide-summary: {jdgserver_name} CLI commands can be automated by creating a `Batch` CR instance.
:guide-priority: 999
:guide-tile-visible: false
:version: 26.2.2

include::../attributes.adoc[]

[[concepts-infinispan-cli-batch]]
= Concepts to automate {jdgserver_name} CLI commands

ifeval::["" == "true"]
WARNING: This {section} is describing a feature which is currently in preview.
ifeval::["" == ""]
Please provide your feedback while we’re continuing to work on this.
endif::[]
ifeval::["" != ""]
Please provide your feedback by link:[joining this discussion] while we’re continuing to work on this.
endif::[]
endif::[]


include::partials/infinispan/infinispan-attributes.adoc[]

When interacting with an external {jdgserver_name} in Kubernetes, the `Batch` CR allows you to automate this using standard `kubectl` commands.

== When to use it

Use this when automating interactions on Kubernetes.
This avoids providing usernames and passwords and checking shell script outputs and their status.

For human interactions, the CLI shell might still be a better fit.

== Example

The following `Batch` CR takes a site offline as described in the operational procedure link:{links_high-availability_operate-site-offline_url}[{links_high-availability_operate-site-offline_name}].

[source,yaml,subs="+attributes"]
----
apiVersion: infinispan.org/v2alpha1
kind: Batch
metadata:
  name: take-offline
  namespace: {ns} #<1>
spec:
  cluster: {cluster-name} #<2>
  config: | #<3>
    site take-offline --all-caches --site={site-a-cr}
    site status --all-caches --site={site-a-cr}
----
<1> The `Batch` CR must be created in the same namespace as the {jdgserver_name} deployment.
<2> The name of the Infinispan CR.
<3> A multiline string containing one or more {jdgserver_name} CLI commands.

Once the CR has been created, wait for the status to show the completion.

[source,bash,subs="+attributes"]
----
kubectl -n {ns} wait --for=jsonpath='{.status.phase}'=Succeeded Batch/take-offline
----

NOTE: Modifying a `Batch` CR instance has no effect. Batch operations are "`one-time`" events that modify Infinispan resources. To update `.spec` fields for the CR, or when a batch operation fails, you must create a new instance of the `Batch` CR.

== Further reading

For more information, see the link:{infinispan-operator-docs}#batch-cr[{jdgserver_name} Operator `Batch` CR documentation].


