Cleanup Elasticsearch indices before test
[integration/test.git] / csit / scripts / set_jvm_common_attribute.sh
1 #!/bin/bash
2
3 cat > ${WORKSPACE}/org.apache.karaf.decanter.collector.jmx-local.cfg <<EOF
4 type=jmx-local
5 url=local
6 object.name=java.lang:type=*,name=*
7
8 EOF
9
10 cat > ${WORKSPACE}/org.apache.karaf.decanter.collector.jmx-others.cfg <<EOF
11 type=jmx-local
12 url=local
13 object.name=java.lang:type=*
14
15 EOF
16
17
18 for i in `seq 1 ${NUM_ODL_SYSTEM}`
19 do
20     CONTROLLERIP=ODL_SYSTEM_${i}_IP
21
22     cat > ${WORKSPACE}/elasticsearch.yml <<EOF
23     cluster.name: elasticsearch
24     network.host: ${!CONTROLLERIP}
25
26 EOF
27     cat > ${WORKSPACE}/org.apache.karaf.decanter.appender.elasticsearch.cfg <<EOF
28     host=${!CONTROLLERIP}
29     port=9300
30     clusterName=elasticsearch
31
32 EOF
33
34     out='{"acknowledged":true}'
35     cmd='http://'${!CONTROLLERIP}':9200/_all'
36     command_='curl -XDELETE '${cmd}' 2> /dev/null'
37     command2='curl '${!CONTROLLERIP}':9200/_cat/indices?v'
38
39     cat > ${WORKSPACE}/elasticsearch_startup.sh <<EOF
40     cd /tmp/elasticsearch
41     echo "Starting Elasticsearch node"
42     sudo /tmp/elasticsearch/elasticsearch-1.7.5/bin/elasticsearch > /dev/null 2>&1 &
43     ls -al /tmp/elasticsearch/elasticsearch-1.7.5/bin/elasticsearch
44
45     for ((i=1;i<=100;i++));
46     do
47         output=${command_};
48         outpu1=${command2};
49         echo $output1;
50         echo $output;
51         if [[ "$out" ==  "$output" ]];
52         then
53             echo "indices deleted";
54             break;
55         fi
56         echo "could not reach server, retrying";
57         sleep 2;
58     done;
59
60 EOF
61     echo "Setup ODL_SYSTEM_IP specific config files for ${!CONTROLLERIP} "
62
63     cat ${WORKSPACE}/org.apache.karaf.decanter.appender.elasticsearch.cfg
64     cat ${WORKSPACE}/elasticsearch.yml
65
66
67     echo "Copying config files to ${!CONTROLLERIP}"
68
69     scp ${WORKSPACE}/org.apache.karaf.decanter.appender.elasticsearch.cfg ${!CONTROLLERIP}:/tmp/${BUNDLEFOLDER}/etc/
70     scp ${WORKSPACE}/org.apache.karaf.decanter.collector.jmx-local.cfg ${!CONTROLLERIP}:/tmp/${BUNDLEFOLDER}/etc/
71     scp ${WORKSPACE}/org.apache.karaf.decanter.collector.jmx-others.cfg ${!CONTROLLERIP}:/tmp/${BUNDLEFOLDER}/etc/
72
73     scp ${WORKSPACE}/elasticsearch.yml ${!CONTROLLERIP}:/tmp/
74     ssh ${!CONTROLLERIP} "sudo mv /tmp/elasticsearch.yml /tmp/elasticsearch/elasticsearch-1.7.5/config/"
75     ssh ${!CONTROLLERIP} "cat /tmp/elasticsearch/elasticsearch-1.7.5/config/elasticsearch.yml"
76
77     echo "Copying the elasticsearch_startup script to ${!CONTROLLERIP}"
78     cat ${WORKSPACE}/elasticsearch_startup.sh
79     scp ${WORKSPACE}/elasticsearch_startup.sh ${!CONTROLLERIP}:/tmp
80     ssh ${!CONTROLLERIP} 'bash /tmp/elasticsearch_startup.sh'
81     ssh ${!CONTROLLERIP} 'ps aux | grep elasticsearch'
82 done