# ---------------------------------------------------------------------------
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ---------------------------------------------------------------------------
apiVersion: camel.apache.org/v1alpha1
kind: Kamelet
metadata:
  name: infinispan-source
  labels:
    camel.apache.org/kamelet.type: "source"
  annotations:
    camel.apache.org/kamelet.support.level: "Stable"
    camel.apache.org/catalog.version: "3.21.0"
    camel.apache.org/provider: "Apache Software Foundation"
    camel.apache.org/kamelet.group: "Infinispan"
    camel.apache.org/kamelet.namespace: "Cache"
    camel.apache.org/kamelet.icon: "data:image/svg+xml;base64,[encoded data, 4340 characters]"
spec:
  definition:
    title: "Infinispan Source"
    description: |-
      Get Events from an Infinispan cache
    required:
      - cacheName
      - hosts
      - username
      - password
    type: object
    properties:
      cacheName:
        title: Cache Name
        description: The name of the Infinispan cache to use
        type: string
      hosts:
        title: Hosts
        description: Specifies the host of the cache on Infinispan instance
        type: string
      secure:
        title: Secure
        description: If the Infinispan instance is secured or not
        type: boolean
        default: true
        x-descriptors:
        - 'urn:alm:descriptor:com.tectonic.ui:checkbox'
      username:
        title: Username
        description: Username to connect to Infinispan.
        type: string
        x-descriptors:
        - urn:camel:group:credentials
      password:
        title: Password
        description: Password to connect to Infinispan.
        type: string
        format: password
        x-descriptors:
        - urn:alm:descriptor:com.tectonic.ui:password
        - urn:camel:group:credentials
      saslMechanism:
        title: SASL Mechanism
        description: The SASL Mechanism to use
        type: string
        default: "DIGEST-MD5"
      securityRealm:
        title: Security Realm
        description: Define the security realm to access the infinispan instance
        type: string
        default: "default"
      securityServerName:
        title: Security Server name
        description: Define the security server name to access the infinispan instance
        type: string
        default: "infinispan"
      eventTypes:
        title: Infinispan Cluster Name
        description: Specifies the set of event types to register by the consumer. Multiple event can be separated by comma without spaces.
        type: string
        example: "CLIENT_CACHE_ENTRY_CREATED,CLIENT_CACHE_ENTRY_MODIFIED"
        default: "CLIENT_CACHE_ENTRY_CREATED,CLIENT_CACHE_ENTRY_MODIFIED,CLIENT_CACHE_ENTRY_REMOVED,CLIENT_CACHE_ENTRY_EXPIRED,CLIENT_CACHE_FAILOVER"
        enum: ["CLIENT_CACHE_ENTRY_CREATED", "CLIENT_CACHE_ENTRY_MODIFIED", "CLIENT_CACHE_ENTRY_REMOVED", "CLIENT_CACHE_ENTRY_EXPIRED", "CLIENT_CACHE_FAILOVER"]
  dependencies:
    - "camel:kamelet"
    - "camel:core"
    - "camel:infinispan"
  template:
    beans:
      - name: local-infinispan
        type: "#class:org.apache.camel.component.infinispan.remote.InfinispanRemoteComponent"
    from:
      uri: "{{local-infinispan}}:{{cacheName}}"
      parameters:
        hosts: "{{hosts}}"
        secure: "{{secure}}"
        username: "{{username}}"
        password: "{{password}}"
        saslMechanism: "{{saslMechanism}}"
        securityRealm: "{{securityRealm}}"
        securityServerName: "{{securityServerName}}"
        eventTypes: "{{eventTypes}}"
      steps:
      - set-header:
          name: infinispan-cache-name
          simple: "${header[CamelInfinispanCacheName]}"
      - set-header:
          name: ce-infinispancachename
          simple: "${header[CamelInfinispanCacheName]}"
      - set-header:
          name: infinispan-entry-version
          simple: "${header[CamelInfinispanEntryVersion]}"
      - set-header:
          name: ce-infinispanentryversion
          simple: "${header[CamelInfinispanEntryVersion]}"
      - set-header:
          name: infinispan-event-type
          simple: "${header[CamelInfinispanEventType]}"
      - set-header:
          name: ce-infinispaneventtype
          simple: "${header[CamelInfinispanEventType]}"
      - set-header:
          name: infinispan-key
          simple: "${header[CamelInfinispanKey]}"
      - set-header:
          name: ce-infinispankey
          simple: "${header[CamelInfinispanKey]}"
      - to: kamelet:sink