2 * ============LICENSE_START==========================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 * ============LICENSE_END=============================================
20 * ====================================================================
22 package org.onap.music.e2eTests;
24 import java.io.IOException;
25 import java.net.InetAddress;
26 import java.net.UnknownHostException;
27 import java.util.Random;
29 public class MusicConnector {
31 // change this to point to relevant cluster
32 public String[] musicNodes;
34 public MusicConnector(String[] musicNodes) {
35 this.musicNodes = musicNodes;
38 private String getMusicNodeIp() {
39 Random r = new Random();
40 int index = r.nextInt(musicNodes.length);
41 return musicNodes[index];
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; }
52 public String getMusicNodeURL() {
53 String musicurl = "http://" + getMusicNodeIp() + ":8080/MUSIC/rest";
54 System.out.println(musicurl);
58 public boolean isHostUp(String serverAddress) {
61 InetAddress inet = InetAddress.getByName(serverAddress);
62 isUp = inet.isReachable(1000);
63 } catch (UnknownHostException e) {
64 // TODO Auto-generated catch block
66 } catch (IOException e) {
67 // TODO Auto-generated catch block
74 * private static String getMusicNodeIp(){
76 * //return "54.224.168.13"; return bigSiteMusicNode; String serverAddress; serverAddress =
77 * agaveMusicNode; while(isHostUp(serverAddress) != true) serverAddress = toggle(serverAddress);
78 * return serverAddress; }