{
    "kind": "Template",
    "apiVersion": "v1",
    "metadata": {
        "annotations": {
            "description": "Application template for JBoss A-MQ brokers. These can be deployed as standalone or in a mesh. This template supports SSL and requires usage of OpenShift secrets.",
            "iconClass": "icon-amq",
            "tags": "messaging,amq,jboss,hidden",
            "version": "1.4.14",
            "openshift.io/display-name": "JBoss A-MQ 6.2 (Ephemeral with SSL)",
            "openshift.io/provider-display-name": "Red Hat, Inc."
        },
        "name": "amq62-ssl"
    },
    "labels": {
        "template": "amq62-ssl",
        "xpaas": "1.4.14"
    },
    "message": "A new messaging service with SSL support has been created in your project. It will handle the protocol(s) \"${MQ_PROTOCOL}\". The username/password for accessing the service is ${MQ_USERNAME}/${MQ_PASSWORD}. Please be sure to create a secret named \"${AMQ_SECRET}\" containing the trust store and key store files (\"${AMQ_TRUSTSTORE}\" and \"${AMQ_KEYSTORE}\") used for serving secure content.",
    "parameters": [
        {
            "displayName": "Application Name",
            "description": "The name for the application.",
            "name": "APPLICATION_NAME",
            "value": "broker",
            "required": true
        },
        {
            "displayName": "A-MQ Protocols",
            "description": "Protocols to configure, separated by commas. Allowed values are: `openwire`, `amqp`, `stomp` and `mqtt`. SSL variants of these protocols will be configured automaticaly.",
            "name": "MQ_PROTOCOL",
            "value": "openwire",
            "required": false
        },
        {
            "displayName": "Queues",
            "description": "Queue names, separated by commas. These queues will be automatically created when the broker starts. If left empty, queues will be still created dynamically.",
            "name": "MQ_QUEUES",
            "value": "",
            "required": false
        },
        {
            "displayName": "Topics",
            "description": "Topic names, separated by commas. These topics will be automatically created when the broker starts. If left empty, topics will be still created dynamically.",
            "name": "MQ_TOPICS",
            "value": "",
            "required": false
        },
        {
            "displayName": "A-MQ Serializable Packages",
            "description": "List of packages that are allowed to be serialized for use in ObjectMessage, separated by commas. If your app doesn't use ObjectMessages, leave this blank. This is a security enforcement. For the rationale, see http://activemq.apache.org/objectmessage.html",
            "name": "MQ_SERIALIZABLE_PACKAGES",
            "value": "",
            "required": false
        },
        {
            "displayName": "A-MQ Username",
            "description": "User name for standard broker user. It is required for connecting to the broker. If left empty, it will be generated.",
            "name": "MQ_USERNAME",
            "from": "user[a-zA-Z0-9]{3}",
            "generate": "expression",
            "required": false
        },
        {
            "displayName": "A-MQ Password",
            "description": "Password for standard broker user. It is required for connecting to the broker. If left empty, it will be generated.",
            "name": "MQ_PASSWORD",
            "from": "[a-zA-Z0-9]{8}",
            "generate": "expression",
            "required": false
        },
        {
            "displayName": "Secret Name",
            "description": "Name of a secret containing SSL related files",
            "name": "AMQ_SECRET",
            "value": "amq-app-secret",
            "required": true
        },
        {
            "displayName": "Trust Store Filename",
            "description": "SSL trust store filename",
            "name": "AMQ_TRUSTSTORE",
            "value": "broker.ts",
            "required": true
        },
        {
            "displayName": "Trust Store Password",
            "description": "SSL trust store password",
            "name": "AMQ_TRUSTSTORE_PASSWORD",
            "value": "",
            "required": true
        },
        {
            "displayName": "A-MQ Keystore Filename",
            "description": "SSL key store filename",
            "name": "AMQ_KEYSTORE",
            "value": "broker.ks",
            "required": true
        },
        {
            "displayName": "A-MQ Keystore Password",
            "description": "Password for accessing SSL keystore",
            "name": "AMQ_KEYSTORE_PASSWORD",
            "value": "",
            "required": true
        },
        {
            "displayName": "A-MQ Mesh Discovery Type",
            "description": "The discovery agent type to use for discovering mesh endpoints.  'dns' will use OpenShift's DNS service to resolve endpoints.  'kube' will use Kubernetes REST API to resolve service endpoints.  If using 'kube' the service account for the pod must have the 'view' role, which can be added via 'oc policy add-role-to-user view system:serviceaccount:<namespace>:default' where <namespace> is the project namespace.",
            "name": "AMQ_MESH_DISCOVERY_TYPE",
            "value": "dns",
            "required": false
        },
        {
            "displayName": "A-MQ Store Usage Limit",
            "description": "Sets the store disk limit usage in activemq.xml. If the value set is greater than the disk size, it will be resized to the available disk space.",
            "name": "AMQ_STORAGE_USAGE_LIMIT",
            "value": "100 gb",
            "required": false
        },
        {
            "displayName": "Queue Memory Limit",
            "description": "The queue memory limit (default is 1mb)",
            "name": "AMQ_QUEUE_MEMORY_LIMIT",
            "value": "",
            "required": false
        },
        {
            "displayName": "ImageStream Namespace",
            "description": "Namespace in which the ImageStreams for Red Hat Middleware images are installed. These ImageStreams are normally installed in the openshift namespace. You should only need to modify this if you've installed the ImageStreams in a different namespace/project.",
            "name": "IMAGE_STREAM_NAMESPACE",
            "value": "openshift",
            "required": true
        }
    ],
    "objects": [
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 5672,
                        "targetPort": 5672
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-amqp",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's AMQP port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 5671,
                        "targetPort": 5671
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-amqp-ssl",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's AMQP SSL port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 1883,
                        "targetPort": 1883
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-mqtt",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's MQTT port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 8883,
                        "targetPort": 8883
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-mqtt-ssl",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's MQTT SSL port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 61613,
                        "targetPort": 61613
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-stomp",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's STOMP port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 61612,
                        "targetPort": 61612
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-stomp-ssl",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's STOMP SSL port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 61616,
                        "targetPort": 61616
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-tcp",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's OpenWire port."
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "ports": [
                    {
                        "port": 61617,
                        "targetPort": 61617
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-tcp-ssl",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "description": "The broker's OpenWire (SSL) port.",
                    "service.alpha.openshift.io/dependencies": "[{\"name\": \"${APPLICATION_NAME}-amq-tcp\", \"kind\": \"Service\"},{\"name\": \"${APPLICATION_NAME}-amq-amqp\", \"kind\": \"Service\"},{\"name\": \"${APPLICATION_NAME}-amq-mqtt\", \"kind\": \"Service\"},{\"name\": \"${APPLICATION_NAME}-amq-stomp\", \"kind\": \"Service\"},{\"name\": \"${APPLICATION_NAME}-amq-amqp-ssl\", \"kind\": \"Service\"},{\"name\": \"${APPLICATION_NAME}-amq-mqtt-ssl\", \"kind\": \"Service\"},{\"name\": \"${APPLICATION_NAME}-amq-stomp-ssl\", \"kind\": \"Service\"}]"
                }
            }
        },
        {
            "kind": "Service",
            "apiVersion": "v1",
            "spec": {
                "clusterIP": "None",
                "ports": [
                    {
                        "name": "mesh",
                        "port": 61616
                    }
                ],
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                }
            },
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-mesh",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                },
                "annotations": {
                    "service.alpha.kubernetes.io/tolerate-unready-endpoints": "true",
                    "description": "Supports node discovery for mesh formation."
                }
            }
        },
        {
            "kind": "DeploymentConfig",
            "apiVersion": "v1",
            "metadata": {
                "name": "${APPLICATION_NAME}-amq",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                }
            },
            "spec": {
                "strategy": {
                    "type": "Rolling",
                    "rollingParams": {
                        "maxSurge": 0
                    }
                },
                "triggers": [
                    {
                        "type": "ImageChange",
                        "imageChangeParams": {
                            "automatic": true,
                            "containerNames": [
                                "${APPLICATION_NAME}-amq"
                            ],
                            "from": {
                                "kind": "ImageStreamTag",
                                "namespace": "${IMAGE_STREAM_NAMESPACE}",
                                "name": "jboss-amq-62:1.7"
                            }
                        }
                    },
                    {
                        "type": "ConfigChange"
                    }
                ],
                "replicas": 1,
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                },
                "template": {
                    "metadata": {
                        "name": "${APPLICATION_NAME}-amq",
                        "labels": {
                            "deploymentConfig": "${APPLICATION_NAME}-amq",
                            "application": "${APPLICATION_NAME}"
                        }
                    },
                    "spec": {
                        "terminationGracePeriodSeconds": 60,
                        "containers": [
                            {
                                "name": "${APPLICATION_NAME}-amq",
                                "image": "jboss-amq-62",
                                "imagePullPolicy": "Always",
                                "volumeMounts": [
                                    {
                                        "name": "broker-secret-volume",
                                        "mountPath": "/etc/amq-secret-volume",
                                        "readOnly": true
                                    }
                                ],
                                "readinessProbe": {
                                    "exec": {
                                        "command": [
                                            "/bin/bash",
                                            "-c",
                                            "/opt/amq/bin/readinessProbe.sh"
                                        ]
                                    }
                                },
                                "ports": [
                                    {
                                        "name": "jolokia",
                                        "containerPort": 8778,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "amqp",
                                        "containerPort": 5672,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "amqp-ssl",
                                        "containerPort": 5671,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "mqtt",
                                        "containerPort": 1883,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "mqtt-ssl",
                                        "containerPort": 8883,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "stomp",
                                        "containerPort": 61613,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "stomp-ssl",
                                        "containerPort": 61612,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "tcp",
                                        "containerPort": 61616,
                                        "protocol": "TCP"
                                    },
                                    {
                                        "name": "tcp-ssl",
                                        "containerPort": 61617,
                                        "protocol": "TCP"
                                    }
                                ],
                                "env": [
                                    {
                                        "name": "AMQ_USER",
                                        "value": "${MQ_USERNAME}"
                                    },
                                    {
                                        "name": "AMQ_PASSWORD",
                                        "value": "${MQ_PASSWORD}"
                                    },
                                    {
                                        "name": "AMQ_TRANSPORTS",
                                        "value": "${MQ_PROTOCOL}"
                                    },
                                    {
                                        "name": "AMQ_QUEUES",
                                        "value": "${MQ_QUEUES}"
                                    },
                                    {
                                        "name": "AMQ_TOPICS",
                                        "value": "${MQ_TOPICS}"
                                    },
                                    {
                                        "name": "MQ_SERIALIZABLE_PACKAGES",
                                        "value": "${MQ_SERIALIZABLE_PACKAGES}"
                                    },
                                    {
                                        "name": "AMQ_MESH_DISCOVERY_TYPE",
                                        "value": "${AMQ_MESH_DISCOVERY_TYPE}"
                                    },
                                    {
                                        "name": "AMQ_MESH_SERVICE_NAME",
                                        "value": "${APPLICATION_NAME}-amq-mesh"
                                    },
                                    {
                                        "name": "AMQ_MESH_SERVICE_NAMESPACE",
                                        "valueFrom": {
                                            "fieldRef": {
                                                "fieldPath": "metadata.namespace"
                                            }
                                        }
                                    },
                                    {
                                        "name": "AMQ_KEYSTORE_TRUSTSTORE_DIR",
                                        "value": "/etc/amq-secret-volume"
                                    },
                                    {
                                        "name": "AMQ_TRUSTSTORE",
                                        "value": "${AMQ_TRUSTSTORE}"
                                    },
                                    {
                                        "name": "AMQ_TRUSTSTORE_PASSWORD",
                                        "value": "${AMQ_TRUSTSTORE_PASSWORD}"
                                    },
                                    {
                                        "name": "AMQ_KEYSTORE",
                                        "value": "${AMQ_KEYSTORE}"
                                    },
                                    {
                                        "name": "AMQ_KEYSTORE_PASSWORD",
                                        "value": "${AMQ_KEYSTORE_PASSWORD}"
                                    },
                                    {
                                        "name": "AMQ_STORAGE_USAGE_LIMIT",
                                        "value": "${AMQ_STORAGE_USAGE_LIMIT}"
                                    },
                                    {
                                        "name": "AMQ_QUEUE_MEMORY_LIMIT",
                                        "value": "${AMQ_QUEUE_MEMORY_LIMIT}"
                                    }
                                ]
                            }
                        ],
                        "volumes": [
                            {
                                "name": "broker-secret-volume",
                                "secret": {
                                    "secretName": "${AMQ_SECRET}"
                                }
                            }
                        ]
                    }
                }
            }
        }
    ]
}
