#
# NOTE: Before running this, create an OCP 4.2 cluster and log in.
#

# 1. Create an OCP 4.2 Cluster
#2. make es (from the jaeger-operator source) to create an ES instance in the default project
#3. Install Jaeger Operator and AMQ Streams Operator via OperatorHub
#4. Create a project named kafka, then create a kafka instance in it: oc create --namespace kafka -f https://raw.githubusercontent.com/strimzi/strimzi-kafka-operator/release-0.14.x/examples/kafka/kafka-ephemeral.yaml
#5. Create a new project, and create a Jaeger instance in it using the simple-streaming.yaml file attached to this JIRA. This should have 2 ingester pods.
#6. Create a simple vertx app using this file: vertx.yaml in the same project as the Jaeger instance
#7. Do oc log on either of the ingester pods. You should get non-stop info messages.

set -x
# Create an elasticsearch instance in the default namespace and wiat for it to be ready
oc create -f https://raw.githubusercontent.com/jaegertracing/jaeger-operator/master/test/elasticsearch.yml --namespace default
oc wait --for=condition=ready pod/elasticsearch-0 --namespace default --timeout=120s

# Install the Jaeger and AMQ Streams Operators
oc apply -f https://gist.githubusercontent.com/kevinearls/c1aff72b0b94f574bcc4b3d1957a0b61/raw/19c8352e4447f3e032c085bbeb1da75e4d557ee8/amq-streams-subscription.yaml
oc apply -f https://gist.githubusercontent.com/kevinearls/ef53f44cdcfac84311c94305dbe6789d/raw/817e4ca86f46619deeaf1a6b8480c2fd2604ba4a/jaeger-subscription.yaml

# We need to sleep here to wait for the deployments to appear
sleep 60
oc wait --for=condition=available deployment/jaeger-operator --namespace openshift-operators
oc wait --for=condition=available deployment/amq-streams-cluster-operator-v1.3.0 --namespace openshift-operators

# Create the kafka instance
oc new-project kafka
oc create --namespace kafka -f https://gist.githubusercontent.com/rubenvp8510/1008782982fac8e7bafa3e7076ef6916/raw/3d7558175d5c044bda8ae1e22c3fca3f0be0e71c/kafka-ephemeral-single.yaml
sleep 120
oc wait --for=condition=available deployment/my-cluster-entity-operator --namespace kafka

sleep 120
# Create the jaeger instance
oc new-project tracing809
oc create --namespace tracing809 -f https://gist.githubusercontent.com/rubenvp8510/c36a81e65efc9a61b75aeb7c46e1cce3/raw/ca1e5e9c47b5c165b546f5353c03b12524683cde/simple-streaming.yaml
sleep 30
oc wait --for=condition=available deployment/simple-streaming-collector --namespace tracing809
oc wait --for=condition=available deployment/simple-streaming-ingester --namespace tracing809
oc wait --for=condition=available deployment/simple-streaming-query --namespace tracing809

# Create the vertx instance
oc create --namespace tracing809 -f https://gist.githubusercontent.com/kevinearls/2f01d14a4cb573110efa0cb295705a8e/raw/309b7bcdfc0f2408380a96dc57a51698e271d1e5/vertx.yaml
sleep 30
oc wait --for=condition=available deployment/vertx-create-span --namespace tracing809

oc scale deployment simple-streaming-ingester --replicas=2 -n tracing809
sleep 120
# Now let's check one of the ingester logs
oc get pods --namespace tracing809 | grep simple-streaming-ingester | awk '{print $1}' | head -1 | xargs oc logs -f

