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 com.att.eelf.configuration.EELFLogger;
\r
28 import com.att.eelf.configuration.EELFManager;
\r
29 import java.net.InetAddress;
\r
30 import java.net.UnknownHostException;
\r
32 import org.onap.dmaap.datarouter.provisioning.BaseServlet;
\r
35 * Utility functions used to generate the different URLs used by the Data Router.
\r
37 * @author Robert Eby
\r
38 * @version $Id: URLUtilities.java,v 1.2 2014/03/12 19:45:41 eby Exp $
\r
40 public class URLUtilities {
\r
43 private static final EELFLogger utilsLogger = EELFManager.getInstance().getLogger("UtilsLog");
\r
44 private static final String HTTPS = "https://";
\r
45 private static String otherPod;
\r
47 private URLUtilities() {
\r
51 * Generate the URL used to access a feed.
\r
53 * @param feedid the feed id
\r
56 public static String generateFeedURL(int feedid) {
\r
57 return HTTPS + BaseServlet.getProvName() + "/feed/" + feedid;
\r
61 * Generate the URL used to publish to a feed.
\r
63 * @param feedid the feed id
\r
66 public static String generatePublishURL(int feedid) {
\r
67 return HTTPS + BaseServlet.getProvName() + "/publish/" + feedid;
\r
71 * Generate the URL used to subscribe to a feed.
\r
73 * @param feedid the feed id
\r
76 public static String generateSubscribeURL(int feedid) {
\r
77 return HTTPS + BaseServlet.getProvName() + "/subscribe/" + feedid;
\r
81 * Generate the URL used to access a feed's logs.
\r
83 * @param feedid the feed id
\r
86 public static String generateFeedLogURL(int feedid) {
\r
87 return HTTPS + BaseServlet.getProvName() + "/feedlog/" + feedid;
\r
91 * Generate the URL used to access a subscription.
\r
93 * @param subid the subscription id
\r
96 public static String generateSubscriptionURL(int subid) {
\r
97 return HTTPS + BaseServlet.getProvName() + "/subs/" + subid;
\r
101 * Generate the URL used to access a subscription's logs.
\r
103 * @param subid the subscription id
\r
106 public static String generateSubLogURL(int subid) {
\r
107 return HTTPS + BaseServlet.getProvName() + "/sublog/" + subid;
\r
111 * Generate the URL used to access the provisioning data on the peer POD.
\r
115 public static String generatePeerProvURL() {
\r
116 return HTTPS + getPeerPodName() + "/internal/prov";
\r
120 * Generate the URL used to access the logfile data on the peer POD.
\r
124 public static String generatePeerLogsURL() {
\r
125 //Fixes for Itrack ticket - DATARTR-4#Fixing if only one Prov is configured, not to give exception to fill logs.
\r
126 String peerPodUrl = getPeerPodName();
\r
127 if (peerPodUrl == null || "".equals(peerPodUrl)) {
\r
131 return HTTPS + peerPodUrl + "/internal/drlogs/";
\r
135 * Return the real (non CNAME) version of the peer POD's DNS name.
\r
139 public static String getPeerPodName() {
\r
140 if (otherPod == null) {
\r
143 thisPod = InetAddress.getLocalHost().getHostName();
\r
144 } catch (UnknownHostException e) {
\r
145 utilsLogger.trace("UnkownHostException: " + e.getMessage(), e);
\r
148 for (String pod : BaseServlet.getPods()) {
\r
149 if (!pod.equals(thisPod)) {
\r