[DMAAP-48] Initial code import
[dmaap/datarouter.git] / datarouter-prov / src / main / java / com / att / research / datarouter / provisioning / utils / URLUtilities.java
1 /*******************************************************************************\r
2  * ============LICENSE_START==================================================\r
3  * * org.onap.dmaap\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * ===========================================================================\r
7  * * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * * you may not use this file except in compliance with the License.\r
9  * * You may obtain a copy of the License at\r
10  * * \r
11  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * * \r
13  *  * Unless required by applicable law or agreed to in writing, software\r
14  * * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * * See the License for the specific language governing permissions and\r
17  * * limitations under the License.\r
18  * * ============LICENSE_END====================================================\r
19  * *\r
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
21  * *\r
22  ******************************************************************************/\r
23 \r
24 \r
25 package com.att.research.datarouter.provisioning.utils;\r
26 \r
27 import java.net.InetAddress;\r
28 import java.net.UnknownHostException;\r
29 import java.util.Arrays;\r
30 \r
31 import com.att.research.datarouter.provisioning.BaseServlet;\r
32 \r
33 /**\r
34  * Utility functions used to generate the different URLs used by the Data Router.\r
35  *\r
36  * @author Robert Eby\r
37  * @version $Id: URLUtilities.java,v 1.2 2014/03/12 19:45:41 eby Exp $\r
38  */\r
39 public class URLUtilities {\r
40         /**\r
41          * Generate the URL used to access a feed.\r
42          * @param feedid the feed id\r
43          * @return the URL\r
44          */\r
45         public static String generateFeedURL(int feedid) {\r
46                 return "https://" + BaseServlet.prov_name + "/feed/" + feedid;\r
47         }\r
48         /**\r
49          * Generate the URL used to publish to a feed.\r
50          * @param feedid the feed id\r
51          * @return the URL\r
52          */\r
53         public static String generatePublishURL(int feedid) {\r
54                 return "https://" + BaseServlet.prov_name + "/publish/" + feedid;\r
55         }\r
56         /**\r
57          * Generate the URL used to subscribe to a feed.\r
58          * @param feedid the feed id\r
59          * @return the URL\r
60          */\r
61         public static String generateSubscribeURL(int feedid) {\r
62                 return "https://" + BaseServlet.prov_name + "/subscribe/" + feedid;\r
63         }\r
64         /**\r
65          * Generate the URL used to access a feed's logs.\r
66          * @param feedid the feed id\r
67          * @return the URL\r
68          */\r
69         public static String generateFeedLogURL(int feedid) {\r
70                 return "https://" + BaseServlet.prov_name + "/feedlog/" + feedid;\r
71         }\r
72         /**\r
73          * Generate the URL used to access a subscription.\r
74          * @param subid the subscription id\r
75          * @return the URL\r
76          */\r
77         public static String generateSubscriptionURL(int subid) {\r
78                 return "https://" + BaseServlet.prov_name + "/subs/" + subid;\r
79         }\r
80         /**\r
81          * Generate the URL used to access a subscription's logs.\r
82          * @param subid the subscription id\r
83          * @return the URL\r
84          */\r
85         public static String generateSubLogURL(int subid) {\r
86                 return "https://" + BaseServlet.prov_name + "/sublog/" + subid;\r
87         }\r
88         /**\r
89          * Generate the URL used to access the provisioning data on the peer POD.\r
90          * @return the URL\r
91          */\r
92         public static String generatePeerProvURL() {\r
93                 return "https://" + getPeerPodName() + "/internal/prov";\r
94         }\r
95         /**\r
96          * Generate the URL used to access the logfile data on the peer POD.\r
97          * @return the URL\r
98          */\r
99         public static String generatePeerLogsURL() {\r
100                 //Fixes for Itrack ticket - DATARTR-4#Fixing if only one Prov is configured, not to give exception to fill logs.\r
101                 String peerPodUrl = getPeerPodName();\r
102                 if(peerPodUrl.equals("") || peerPodUrl.equals(null)){\r
103                         return "";\r
104                 }\r
105                                 \r
106                 return "https://" + peerPodUrl + "/internal/drlogs/";\r
107         }\r
108         /**\r
109          * Return the real (non CNAME) version of the peer POD's DNS name.\r
110          * @return the name\r
111          */\r
112         public static String getPeerPodName() {\r
113                 if (other_pod == null) {\r
114                         String this_pod = "";\r
115                         try {\r
116                                 this_pod = InetAddress.getLocalHost().getHostName();\r
117                                 System.out.println("this_pod: "+this_pod);\r
118                         } catch (UnknownHostException e) {\r
119                                 this_pod = "";\r
120                         }\r
121                         System.out.println("ALL PODS: "+Arrays.asList(BaseServlet.getPods()));\r
122                         for (String pod : BaseServlet.getPods()) {\r
123                                 if (!pod.equals(this_pod))\r
124                                         other_pod = pod;\r
125                         }\r
126                 }\r
127                 return other_pod;\r
128         }\r
129         private static String other_pod;\r
130 }\r