Sonar and CLM fixes and Unit test
[music.git] / src / test / java / org / onap / music / e2eTests / MusicConnector.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  *  Copyright (c) 2017 AT&T Intellectual Property
6  * ===================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  * 
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  * 
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22 package org.onap.music.e2eTests;
23
24 import java.io.IOException;
25 import java.net.InetAddress;
26 import java.net.UnknownHostException;
27 import java.util.Random;
28
29 public class MusicConnector {
30
31     // change this to point to relevant cluster
32     public String[] musicNodes;
33
34     public MusicConnector(String[] musicNodes) {
35         this.musicNodes = musicNodes;
36     }
37
38     private String getMusicNodeIp() {
39         Random r = new Random();
40         int index = r.nextInt(musicNodes.length);
41         return musicNodes[index];
42     }
43
44     /*
45      * public static String toggle(String serverAddress){ if(serverAddress.equals(agaveMusicNode)){
46      * System.out.println("Agave is down...connect to Big Site"); serverAddress = bigSiteMusicNode;
47      * }else if(serverAddress.equals(bigSiteMusicNode)){
48      * System.out.println("Big Site is down...connect to Agave"); serverAddress = agaveMusicNode; }
49      * return serverAddress; }
50      */
51
52     public String getMusicNodeURL() {
53         String musicurl = "http://" + getMusicNodeIp() + ":8080/MUSIC/rest";
54         System.out.println(musicurl);
55         return musicurl;
56     }
57
58     public boolean isHostUp(String serverAddress) {
59         Boolean isUp = false;
60         try {
61             InetAddress inet = InetAddress.getByName(serverAddress);
62             isUp = inet.isReachable(1000);
63         } catch (UnknownHostException e) {
64             // TODO Auto-generated catch block
65             e.printStackTrace();
66         } catch (IOException e) {
67             // TODO Auto-generated catch block
68             e.printStackTrace();
69         }
70         return isUp;
71     }
72
73     /*
74      * private static String getMusicNodeIp(){
75      * 
76      * //return "54.224.168.13"; return bigSiteMusicNode; String serverAddress; serverAddress =
77      * agaveMusicNode; while(isHostUp(serverAddress) != true) serverAddress = toggle(serverAddress);
78      * return serverAddress; }
79      */
80 }