A newer version of Hazelcast Operator is available.

View latest

User Code Deployment

Hazelcast allows you to deploy your own custom and domain classes to cluster members. From Hazelcast Platform Operator, you can deploy your application code from external buckets and ConfigMap objects in Kubernetes.

This topic explains how to configure code deployments. It also brings together examples of when you might use code deployments as part of the configuration of other features, such as the implementation of an external data store or an executor service for the asynchronous execution of tasks.

Configuring User Code Deployment

Below are the configuration options for the User Code Deployment feature. For more information, see the API Reference.

Field Description

clientEnabled

When set to true, this option enables custom code deployment from Hazelcast clients.

bucketConfig

JAR files from an external bucket are placed under the Java classpath when the following parameter values are supplied:

  • secretName: Name of the Secret object which holds the credentials for your cloud provider.

  • bucketURI: Full path for the external bucket. For example: gs://your-bucket/path/to/jars.

configMaps

Files specified in the ConfigMaps are placed under the Java classpath.

The data stored in a ConfigMap cannot exceed 1 MiB. For more info, see Kubernetes Documentation for Config Map.

remoteURLs

Files downloaded from the URLS will be placed under the Java classpath.

triggerSequence

Triggers a rolling restart to begin another download of the custom code.

Example Configuration

The example configuration below:

  • downloads the JAR files from the specified external bucket and places them under the classpath of each of the Hazelcast members

  • puts all the files specified in the ConfigMap objects under the classpath of each of the Hazelcast members.

Currently, mounted persistent volumes are not supported; only cloud provider external buckets are supported.
  • AWS

  • GCP

  • Azure

User Code Deployment in AWS S3:

apiVersion: hazelcast.com/v1alpha1
kind: Hazelcast
metadata:
  name: hazelcast
spec:
  userCodeDeployment:
    clientEnabled: true
    bucketConfig:
      secretName: map-store-bucket-secret (1)
      bucketURI: s3://map-store-bucket/path/to/jars (2)
    configMaps:
    - domain-classes-cm
    - entryprocessor-cm
    remoteURLs:
    - https://example.com/entry-processor.jar
    triggerSequence: "001"

User Code Deployment in GCP:

apiVersion: hazelcast.com/v1alpha1
kind: Hazelcast
metadata:
  name: hazelcast
spec:
  userCodeDeployment:
    clientEnabled: true
    bucketConfig:
      secretName: map-store-bucket-secret (1)
      bucketURI: gs://map-store-bucket/path/to/jars (2)
    configMaps:
    - domain-classes-cm
    - entryprocessor-cm
    remoteURLs:
    - https://example.com/entry-processor.jar
    triggerSequence: "001"

User Code Deployment in Azure Blob:

apiVersion: hazelcast.com/v1alpha1
kind: Hazelcast
metadata:
  name: hazelcast
spec:
  userCodeDeployment:
    clientEnabled: true
    bucketConfig:
      secretName: map-store-bucket-secret (1)
      bucketURI: azblob://map-store-bucket/path/to/jars (2)
    configMaps:
    - domain-classes-cm
    - entryprocessor-cm
    remoteURLs:
    - https://example.com/entry-processor.jar
    triggerSequence: "001"
1 The bucket URI where backup data will be stored in
2 Name of the secret with credentials for accessing the Bucket URI.

Configuring an External Data Store with Hazelcast Platform Operator

The MapLoader and MapStore interfaces in Hazelcast allow you to load map entries from and save map entries to an external data store. See Working with an External Data Store for implementation details.

To use an external data store, you need to create MapLoader and/or MapStore classes and add configuration. In Hazelcast Platform Operator:

  1. Deploy the MapLoader and/or MapStore classes to the classpath of each Hazelcast member.

  2. Configure a Map resource for the MapLoader or MapStore.

Use the following configuration options in the Map resource for a MapStore. The example shows how you might implement these options. For more detailed information, see the API Reference.

Field Description

initialMode

Sets the initial entry loading mode. LAZY is the default load mode, where load is asynchronous. EAGER means map operations are blocked until all partitions are loaded.

className

Name of your class that implements the MapLoader and/or MapStore interface.

writeDelaySeconds

Number of seconds to delay the storing of map entries.

writeBatchSize

Used to create batches when writing to the map store. In default mode, with a value of less than two, Hazelcast tries to write all map entries in one go.

writeCoealescing

For use with write-behind mode in a MapStore. When this option is set to true, Hazelcast coalesces updates on a specific key, and so applies only the last update. Set this option to false to store all updates performed on a key to the data store.

propertiesSecretName

You can use properties to give information to the MapStore implementation. In this case, properties are taken from the secret with the given name.

Example MapStore Configuration

An example Map resource with MapStore configuration.

Example configuration
apiVersion: hazelcast.com/v1alpha1
kind: Map
metadata:
  name: map-sample
spec:
  hazelcastResourceName: hazelcast-sample
  mapStore:
    className: com.example.SimpleStore
    propertiesSecretName: props
    initialMode: LAZY
    writeDelaySeconds: 1
    writeBatchSize: 20
    writeCoalescing: false

Configuring Executor Services with the Hazelcast Platform Operator

Hazelcast offers an executor service (IExecutorService), which is an implementation of java.util.concurrent.ExecutorService. With IExecutorService, you can execute tasks asynchronously and perform other useful tasks.

To use the executor service, you need to create Callable and/or Runnable classes and add configuration. In Hazelcast Platform Operator:

  1. Deploy your Callable or Runnable classes to the classpath of each Hazelcast member.

  2. Configure a Hazelcast resource for the Callable or Runnable interface.

There are three variants of the executor service:

  • Executor Service

  • Durable Executor Service

  • Scheduled Executor Service.

Configuration options for a Hazelcast resource to work with all three variants are shown in this section, along with examples of how you might implement these options. For more detailed implementation information, see Java Executor Service.

  • Executor Service

  • Durable Executor Service

  • Scheduled Executor Service

See API Reference for more information.

Field Description

name

The name of the executor service.

poolSize

The number of executor threads per member.

queueCapacity

Task queue capacity of the executor.

See API Reference for more information.

Field Description

name

The name of the executor service.

poolSize

The number of executor threads per member.

durability

Number of backups in the cluster for the submitted task.

capacity

Capacity of the executor task per partition.

See API Reference for more information.

Field Description

name

The name of the executor service.

poolSize

The number of executor threads per member.

durability

Number of backups in the cluster for the submitted task.

capacity

Capacity of the executor task per partition.

capacityPolicy

The active policy for the capacity setting.

Example Executor Services

An example Hazelcast resource with Executor Services configured.

  • Executor Service

  • Durable Executor Service

  • Scheduled Executor Service

apiVersion: hazelcast.com/v1alpha1
kind: Hazelcast
metadata:
  name: hazelcast
spec:
  executorServices:
    - name: service1
      capacity: 8
      queueCapacity: 0
apiVersion: hazelcast.com/v1alpha1
kind: Hazelcast
metadata:
  name: hazelcast
spec:
  durableExecutorServices:
    - name: service1
      poolSize: 16
      capacity: 100
      durability: 1
apiVersion: hazelcast.com/v1alpha1
kind: Hazelcast
metadata:
  name: hazelcast
spec:
  scheduledExecutorServices:
    - name: service1
      poolSize: 16
      capacity: 100
      durability: 1
      capacityPolicy: PER_NODE

Configuring an Entry Processor with Hazelcast Platform Operator

An entry processor executes your code on a map entry in an atomic way. To implement the EntryProcessor interface, you can deploy an EntryProcessor class from the Hazelcast Platform Operator to the classpath of a Hazelcast member. See Entry Processor for more detailed information.