1 /*******************************************************************************
\r
2 * ============LICENSE_START==================================================
\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
11 * * http://www.apache.org/licenses/LICENSE-2.0
\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
20 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
22 ******************************************************************************/
\r
25 package org.onap.dmaap.datarouter.provisioning.utils;
\r
27 import java.net.InetAddress;
\r
28 import java.net.UnknownHostException;
\r
29 import java.util.Arrays;
\r
31 import org.onap.dmaap.datarouter.provisioning.BaseServlet;
\r
34 * Utility functions used to generate the different URLs used by the Data Router.
\r
36 * @author Robert Eby
\r
37 * @version $Id: URLUtilities.java,v 1.2 2014/03/12 19:45:41 eby Exp $
\r
39 public class URLUtilities {
\r
42 * Generate the URL used to access a feed.
\r
44 * @param feedid the feed id
\r
47 public static String generateFeedURL(int feedid) {
\r
48 return "https://" + BaseServlet.provName + "/feed/" + feedid;
\r
52 * Generate the URL used to publish to a feed.
\r
54 * @param feedid the feed id
\r
57 public static String generatePublishURL(int feedid) {
\r
58 return "https://" + BaseServlet.provName + "/publish/" + feedid;
\r
62 * Generate the URL used to subscribe to a feed.
\r
64 * @param feedid the feed id
\r
67 public static String generateSubscribeURL(int feedid) {
\r
68 return "https://" + BaseServlet.provName + "/subscribe/" + feedid;
\r
72 * Generate the URL used to access a feed's logs.
\r
74 * @param feedid the feed id
\r
77 public static String generateFeedLogURL(int feedid) {
\r
78 return "https://" + BaseServlet.provName + "/feedlog/" + feedid;
\r
82 * Generate the URL used to access a subscription.
\r
84 * @param subid the subscription id
\r
87 public static String generateSubscriptionURL(int subid) {
\r
88 return "https://" + BaseServlet.provName + "/subs/" + subid;
\r
92 * Generate the URL used to access a subscription's logs.
\r
94 * @param subid the subscription id
\r
97 public static String generateSubLogURL(int subid) {
\r
98 return "https://" + BaseServlet.provName + "/sublog/" + subid;
\r
102 * Generate the URL used to access the provisioning data on the peer POD.
\r
106 public static String generatePeerProvURL() {
\r
107 return "https://" + getPeerPodName() + "/internal/prov";
\r
111 * Generate the URL used to access the logfile data on the peer POD.
\r
115 public static String generatePeerLogsURL() {
\r
116 //Fixes for Itrack ticket - DATARTR-4#Fixing if only one Prov is configured, not to give exception to fill logs.
\r
117 String peerPodUrl = getPeerPodName();
\r
118 if (peerPodUrl.equals("") || peerPodUrl.equals(null)) {
\r
122 return "https://" + peerPodUrl + "/internal/drlogs/";
\r
126 * Return the real (non CNAME) version of the peer POD's DNS name.
\r
130 public static String getPeerPodName() {
\r
131 if (other_pod == null) {
\r
132 String this_pod = "";
\r
134 this_pod = InetAddress.getLocalHost().getHostName();
\r
135 System.out.println("this_pod: " + this_pod);
\r
136 } catch (UnknownHostException e) {
\r
139 System.out.println("ALL PODS: " + Arrays.asList(BaseServlet.getPods()));
\r
140 for (String pod : BaseServlet.getPods()) {
\r
141 if (!pod.equals(this_pod)) {
\r
149 private static String other_pod;
\r