{
    "kind": "Template",
    "apiVersion": "v1",
    "metadata": {
        "annotations": {
            "description": "Application template for JBoss A-MQ brokers. These are deployed as standalone and use persistent storage for saving messages. This template supports SSL and requires usage of OpenShift secrets.",
            "iconClass": "icon-jboss",
            "tags": "messaging,amq,jboss,xpaas",
            "version": "1.4.0",
            "openshift.io/display-name": "Red Hat JBoss A-MQ 6.2 (Persistent with SSL)"
        },
        "name": "amq62-persistent-ssl"
    },
    "labels": {
        "template": "amq62-persistent-ssl",
        "xpaas": "1.4.0"
    },
    "message": "A new persistent 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 the \"amq-service-account\" service account and 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": "Split Data?",
            "description": "Split the data directory for each node in a mesh.",
            "name": "AMQ_SPLIT",
            "value": "false",
            "required": false
        },
        {
            "displayName": "A-MQ Protocols",
            "description": "Protocols to configure, separated by commas.  Allowed values are: `openwire`, `amqp`, `stomp` and `mqtt`.",
            "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 Volume Size",
            "description": "Size of the volume used by A-MQ for persisting messages.",
            "name": "VOLUME_CAPACITY",
            "value": "512Mi",
            "required": true
        },
        {
            "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": "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": "kube",
            "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 Storage Limit",
            "description": "The A-MQ storage usage limit",
            "name": "AMQ_STORAGE_USAGE_LIMIT",
            "value": "100 gb",
            "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": "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.4"
                            }
                        }
                    },
                    {
                        "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
                                    },
                                    {
                                        "mountPath": "/opt/amq/data",
                                        "name": "${APPLICATION_NAME}-amq-pvol"
                                    }
                                ],
                                "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_SPLIT",
                                        "value": "${AMQ_SPLIT}"
                                    },
                                    {
                                        "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}"
                                }
                            },
                            {
                                "name": "${APPLICATION_NAME}-amq-pvol",
                                "persistentVolumeClaim": {
                                    "claimName": "${APPLICATION_NAME}-amq-claim"
                                }
                            }
                        ]
                    }
                }
            }
        },
        {
            "apiVersion": "v1",
            "kind": "PersistentVolumeClaim",
            "metadata": {
                "name": "${APPLICATION_NAME}-amq-claim",
                "labels": {
                    "application": "${APPLICATION_NAME}"
                }
            },
            "spec": {
                "accessModes": [
                    "ReadWriteMany"
                ],
                "resources": {
                    "requests": {
                        "storage": "${VOLUME_CAPACITY}"
                    }
                }
            }
        }
    ]
}
