Advertisement
Guest User

qwt

a guest
Jun 18th, 2019
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.59 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -o errexit
  4. set -o pipefail
  5. set -o nounset
  6.  
  7. export KAFKA_OPTS="-Djava.security.auth.login.config=/etc/kafka/kafka_server_jaas.conf"
  8.  
  9. #Global Variables
  10. topic_name="test-k1"
  11. cert="/mnt/cifsConfluentPlatform/ssl_certs/clients/ITERGO_ANSIBLE"
  12. kb="/etc/systemd/system/multi-user.target.wants/confluent-kafka.service"
  13. zk="/etc/systemd/system/multi-user.target.wants/confluent-zookeeper.service"
  14. cs="/etc/systemd/system/multi-user.target.wants/confluent-schema-registry.service"
  15. #zookeeper_server="{% for host in groups['zookeeper'] %}{% if loop.index > 1%},{% endif %}{{ host }}:{{zookeeper.clientPort}}{% endfor %}"
  16.  
  17. _check_zookeeper() {
  18.     resultCreateZnode=$(zookeeper-shell $hostname:2181 create /readinessCheck OK 2>&1 | grep -E "Node already exists: /readinessCheck|Created /readinessCheck")
  19.     [[ ! ${resultCreateZnode-} ]] && { echo "ERROR Something wrong with ZooKeeper... exiting"; exit; }
  20.     resultCheckZnode=$(zookeeper-shell $hostname:2181 get /readinessCheck 2>&1 | grep "^OK$")
  21.     [[ ! ${resultCheckZnode-} ]] && { echo "ERROR Something wrong with ZooKeeper... exiting"; exit; }
  22.     resultDeleteZnode=$(zookeeper-shell $hostname:2181 delete /readinessCheck)
  23. }
  24.  
  25. _check_schema() {
  26.  
  27.     #Listing available schemas
  28.  
  29.     schema="$(curl -k --cert $cert/client.ITERGO_ANSIBLE.cer --key $cert/client.ITERGO_ANSIBLE.kexstore.key -X POST -H "Content-Type: application/vnd.schemaregistry.v1+json" --data '{"schema": "{\"type\": \"string\"}"}'  https://$HOSTNAME:8081/subjects/ITERGO_A_Test-key/versions)"
  30.     schema="$(curl -k --cert $cert/client.ITERGO_ANSIBLE.cer --key $cert/client.ITERGO_ANSIBLE.kexstore.key -X GET https://$HOSTNAME:8081/subjects/ITERGO_A_Test-key/versions)"
  31.     if [[ $schema != "[1]"  ]]; then
  32.         echo "schema not found"
  33.         exit 1
  34.     fi
  35.     schema="$(curl -k --cert $cert/client.ITERGO_ANSIBLE.cer --key $cert/client.ITERGO_ANSIBLE.kexstore.key -X DELETE https://$HOSTNAME:8081/subjects/ITERGO_A_Test-key/versions/1)"
  36.     if [[ $schema -ne 1 ]]; then
  37.         echo "Failed to delete schema"
  38.         exit 1
  39.     fi  
  40. }
  41.  
  42. _check_broker() {
  43.  
  44.     partition="$(curl -s http://localhost:{{kafkabroker.port_jmx_http}} | grep "^kafka_server_replicamanager_underreplicatedpartitions" | awk '{print $2}')"
  45.     while [ $partition != "0.0" ]; do
  46.         sleep 1;
  47.     done
  48.     if [[ $? -ne 0 ]]; then
  49.         echo -e "check failed"
  50.         exit 1
  51.     fi
  52. }
  53.  
  54. if [ -f $kb ]; then
  55.     _check_broker()
  56. elif [ -f $zk ]; then
  57.     _check_zookeeper()
  58. elif [ -f $cs ]; then
  59.     _check_schema()
  60. else
  61.     echo "Script Fails"
  62.     exit 1;
  63. fi
  64.  
  65. echo -e "Success"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement