{
    "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-jboss",
            "tags": "messaging,amq,jboss,xpaas",
            "version": "1.3.1"
        },
        "name": "amq62-ssl"
    },
    "labels": {
        "template": "amq62-ssl",
        "xpaas": "1.3.1"
    },
    "parameters": [
        {
            "description": "The name for the application.",
            "name": "APPLICATION_NAME",
            "value": "broker",
            "required": true
        },
        {
            "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
        },
        {
            "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
        },
        {
            "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
        },
        {
            "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
        },
        {
            "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
        },
        {
            "description": "Name of a secret containing SSL related files",
            "name": "AMQ_SECRET",
            "value": "amq-app-secret",
            "required": true
        },
        {
            "description": "SSL trust store filename",
            "name": "AMQ_TRUSTSTORE",
            "value": "broker.ts",
            "required": true
        },
        {
            "description": "SSL trust store password",
            "name": "AMQ_TRUSTSTORE_PASSWORD",
            "value": "",
            "required": true
        },
        {
            "description": "SSL key store filename",
            "name": "AMQ_KEYSTORE",
            "value": "broker.ks",
            "required": true
        },
        {
            "description": "Password for accessing SSL keystore",
            "name": "AMQ_KEYSTORE_PASSWORD",
            "value": "",
            "required": true
        },
        {
            "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": "kube",
            "required": false
        },
        {
            "description": "The A-MQ storage usage limit",
            "name": "AMQ_STORAGE_USAGE_LIMIT",
            "value": "100 gb",
            "required": false
        },
        {
            "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."
                }
            }
        },
        {
            "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.3"
                            }
                        }
                    },
                    {
                        "type": "ConfigChange"
                    }
                ],
                "replicas": 1,
                "selector": {
                    "deploymentConfig": "${APPLICATION_NAME}-amq"
                },
                "template": {
                    "metadata": {
                        "name": "${APPLICATION_NAME}-amq",
                        "labels": {
                            "deploymentConfig": "${APPLICATION_NAME}-amq",
                            "application": "${APPLICATION_NAME}"
                        }
                    },
                    "spec": {
                        "serviceAccountName": "amq-service-account",
                        "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": "AMQ_MESH_DISCOVERY_TYPE",
                                        "value": "${AMQ_MESH_DISCOVERY_TYPE}"
                                    },
                                    {
                                        "name": "AMQ_MESH_SERVICE_NAME",
                                        "value": "${APPLICATION_NAME}-amq-tcp"
                                    },
                                    {
                                        "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}"
                                    }
                                ]
                            }
                        ],
                        "volumes": [
                            {
                                "name": "broker-secret-volume",
                                "secret": {
                                    "secretName": "${AMQ_SECRET}"
                                }
                            }
                        ]
                    }
                }
            }
        }
    ]
}
