aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
authordglFromAtt <dgl@research.att.com>2018-04-18 16:54:19 -0400
committerdglFromAtt <dgl@research.att.com>2018-04-18 16:54:27 -0400
commitac03a4b32eae987019cec2cd39d6d252fb320c2f (patch)
tree23f4a2bedfae2b29a7f7e2869d614e2139397547 /src/main/java/org
parentfb8a36eeec10b389a3ccc79c5f31ee925243c1b8 (diff)
Improve support for http to MR
Change-Id: I9f15ae30f61964295903be41631e4a47b87e0c9c Signed-off-by: dglFromAtt <dgl@research.att.com> Issue-ID: DMAAP-295
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java27
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java24
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java23
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java16
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java13
5 files changed, 90 insertions, 13 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java b/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
index 91ed1bb..a8ace78 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/client/MrProvConnection.java
@@ -26,6 +26,7 @@ import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ConnectException;
+import java.net.HttpURLConnection;
import java.net.ProtocolException;
import java.net.URL;
import java.net.UnknownHostException;
@@ -49,7 +50,7 @@ public class MrProvConnection extends BaseLoggingClass{
private String provURL;
- private HttpsURLConnection uc;
+ private HttpURLConnection uc;
private String topicMgrCred;
@@ -90,10 +91,13 @@ public class MrProvConnection extends BaseLoggingClass{
provURL = cluster.getTopicProtocol() + "://" + cluster.getFqdn() + ":" + cluster.getTopicPort() + "/topics/create";
+ if ( cluster.getTopicProtocol().equals( "https" ) ) {
+ return makeSecureConnection( provURL );
+ }
return makeConnection( provURL );
}
- private boolean makeConnection( String pURL ) {
+ private boolean makeSecureConnection( String pURL ) {
logger.info( "makeConnection to " + pURL );
try {
@@ -112,6 +116,25 @@ public class MrProvConnection extends BaseLoggingClass{
}
}
+ private boolean makeConnection( String pURL ) {
+ logger.info( "makeConnection to " + pURL );
+
+ try {
+ URL u = new URL( pURL );
+ uc = (HttpURLConnection) u.openConnection();
+ uc.setInstanceFollowRedirects(false);
+ logger.info( "open connect to " + pURL );
+ return(true);
+ } catch( UnknownHostException uhe ){
+ logger.error( "Caught UnknownHostException for " + pURL);
+ return(false);
+ } catch (Exception e) {
+ logger.error("Unexpected error during openConnection of " + pURL );
+ e.printStackTrace();
+ return(false);
+ }
+
+ }
static String bodyToString( InputStream is ) {
StringBuilder sb = new StringBuilder();
diff --git a/src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java b/src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java
index b79b33a..e1ea955 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/client/MrTopicConnection.java
@@ -27,6 +27,7 @@ import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.ProtocolException;
import java.net.URL;
+import java.net.HttpURLConnection;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLException;
@@ -41,7 +42,7 @@ import org.onap.dmaap.dbcapi.util.DmaapConfig;
public class MrTopicConnection extends BaseLoggingClass {
private String topicURL;
- private HttpsURLConnection uc;
+ private HttpURLConnection uc;
private String mmProvCred;
@@ -62,10 +63,13 @@ public class MrTopicConnection extends BaseLoggingClass {
topicURL = cluster.getTopicProtocol() + "://" + fqdn + ":" + cluster.getTopicPort() + "/events/" + topic ;
+ if ( cluster.getTopicProtocol().equals( "https")) {
+ return makeSecureConnection( topicURL );
+ }
return makeConnection( topicURL );
}
- private boolean makeConnection( String pURL ) {
+ private boolean makeSecureConnection( String pURL ) {
logger.info( "makeConnection to " + pURL );
try {
@@ -81,6 +85,22 @@ public class MrTopicConnection extends BaseLoggingClass {
}
}
+ private boolean makeConnection( String pURL ) {
+ logger.info( "makeConnection to " + pURL );
+
+ try {
+ URL u = new URL( pURL );
+ uc = (HttpURLConnection) u.openConnection();
+ uc.setInstanceFollowRedirects(false);
+ logger.info( "open connection to " + pURL );
+ return(true);
+ } catch (Exception e) {
+ logger.error("Unexpected error during openConnection of " + pURL );
+ e.printStackTrace();
+ return(false);
+ }
+
+ }
static String bodyToString( InputStream is ) {
StringBuilder sb = new StringBuilder();
diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java b/src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java
index 79de9ba..8185083 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/model/MR_Cluster.java
@@ -55,6 +55,7 @@ public class MR_Cluster extends DmaapObject {
}
+ // Deprecate this constructor
public MR_Cluster( String dLN,
String f,
String a,
@@ -70,9 +71,27 @@ public class MR_Cluster extends DmaapObject {
this.lastMod = new DmaapTimestamp();
this.lastMod.mark();
- debugLogger.debug( "MR_Cluster constructor w initialization complete" + this.lastMod.getVal() );
+ debugLogger.debug( "depracated MR_Cluster constructor w initialization complete" + this.lastMod.getVal() );
}
-
+
+ // new style constructor
+ public MR_Cluster( String dLN,
+ String f,
+ String prot,
+ String port ) {
+ this.dcaeLocationName = dLN;
+ this.fqdn = f;
+ this.hosts = new String[3];
+ this.hosts[0] = fqdn;
+ this.hosts[1] = fqdn;
+ this.hosts[2] = fqdn;
+ this.topicProtocol = prot;
+ this.topicPort = port;
+ this.lastMod = new DmaapTimestamp();
+ this.lastMod.mark();
+
+ debugLogger.debug( "MR_Cluster constructor w initialization complete" + this.lastMod.getVal() );
+}
public String getDcaeLocationName() {
return dcaeLocationName;
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java b/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java
index 03410f3..e7d4e04 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java
@@ -52,12 +52,11 @@ public class DmaapService extends BaseLoggingClass {
private Singleton<Dmaap> dmaapholder = DatabaseClass.getDmaap();
- // TODO put these in properties file
+
String topicFactory; // = "org.openecomp.dcae.dmaap.topicFactory";
String topicMgrRole; // = "org.openecomp.dmaapBC.TopicMgr";
-
- // TODO confirm this is equivalent to dmaap.getTopicNsRoot() so we can retire it
String dcaeTopicNs; // = "org.openecomp.dcae.dmaap";
+ private boolean multiSite;
public DmaapService() {
@@ -65,6 +64,7 @@ public class DmaapService extends BaseLoggingClass {
topicFactory = p.getProperty("MR.TopicFactoryNS", "MR.topicFactoryNS.not.set");
topicMgrRole = p.getProperty("MR.TopicMgrRole", "MR.TopicMgrRole.not.set" );
dcaeTopicNs = dmaapholder.get().getTopicNsRoot();
+ multiSite = "true".equalsIgnoreCase(p.getProperty("MR.multisite", "true"));
}
@@ -85,7 +85,11 @@ public class DmaapService extends BaseLoggingClass {
AafService aaf = new AafService( ServiceType.AAF_Admin);
ApiPerms p = new ApiPerms();
p.setEnvMap();
- boolean anythingWrong = setTopicMgtPerms( nd, aaf ) || createMmaTopic();
+ boolean anythingWrong = false;
+
+ if ( multiSite ) {
+ anythingWrong = setTopicMgtPerms( nd, aaf ) || createMmaTopic();
+ }
if ( anythingWrong ) {
dmaap.setStatus(DmaapObject_Status.INVALID);
@@ -121,7 +125,9 @@ public class DmaapService extends BaseLoggingClass {
ApiPerms p = new ApiPerms();
p.setEnvMap();
AafService aaf = new AafService( ServiceType.AAF_Admin);
- anythingWrong = setTopicMgtPerms( nd, aaf ) || createMmaTopic();
+ if ( multiSite ) {
+ anythingWrong = setTopicMgtPerms( nd, aaf ) || createMmaTopic();
+ }
}
if ( anythingWrong ) {
diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java b/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java
index 529723e..2dae579 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/service/MR_ClusterService.java
@@ -32,10 +32,19 @@ import org.onap.dmaap.dbcapi.model.ApiError;
import org.onap.dmaap.dbcapi.model.DcaeLocation;
import org.onap.dmaap.dbcapi.model.MR_Cluster;
import org.onap.dmaap.dbcapi.model.DmaapObject.DmaapObject_Status;
+import org.onap.dmaap.dbcapi.util.DmaapConfig;
public class MR_ClusterService extends BaseLoggingClass {
private Map<String, MR_Cluster> mr_clusters = DatabaseClass.getMr_clusters();
+ private boolean multiSite;
+
+ public MR_ClusterService() {
+ logger.info( "new ClusterService");
+ DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
+ multiSite = "true".equalsIgnoreCase(p.getProperty("MR.multisite", "true"));
+
+ }
public Map<String, MR_Cluster> getMR_Clusters() {
return mr_clusters;
@@ -89,7 +98,7 @@ public class MR_ClusterService extends BaseLoggingClass {
mr_clusters.put( cluster.getDcaeLocationName(), cluster );
DcaeLocationService svc = new DcaeLocationService();
DcaeLocation loc = svc.getDcaeLocation( cluster.getDcaeLocationName() );
- if ( loc != null && loc.isCentral() ) {
+ if ( loc != null && loc.isCentral() && multiSite ) {
ApiError resp = TopicService.setBridgeClientPerms( cluster );
if ( ! resp.is2xx() ) {
logger.error( "Unable to provision Bridge to " + cluster.getDcaeLocationName() );
@@ -119,7 +128,7 @@ public class MR_ClusterService extends BaseLoggingClass {
cluster.setLastMod();
cluster.setStatus(DmaapObject_Status.INVALID);
mr_clusters.put( cluster.getDcaeLocationName(), cluster );
- } else if ( loc.isCentral() ) {
+ } else if ( loc.isCentral() & multiSite ) {
ApiError resp = TopicService.setBridgeClientPerms( cluster );
if ( ! resp.is2xx() ) {
logger.error( "Unable to provision Bridge to " + cluster.getDcaeLocationName() );