diff options
Diffstat (limited to 'src/main')
13 files changed, 228 insertions, 22 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java index 2e91ca5..01d103d 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java +++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/AafConnection.java @@ -32,6 +32,7 @@ import java.io.OutputStream; import java.net.ProtocolException; import java.net.URL; import java.net.UnknownHostException; +import java.net.ConnectException; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLHandshakeException; @@ -40,6 +41,7 @@ import org.apache.commons.codec.binary.Base64; import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum; import org.onap.dmaap.dbcapi.service.DmaapService; +import org.onap.dmaap.dbcapi.util.DmaapConfig; public class AafConnection extends BaseLoggingClass { @@ -49,6 +51,7 @@ public class AafConnection extends BaseLoggingClass { private String aafCred; + private String unit_test; private HttpsURLConnection uc; @@ -56,6 +59,9 @@ public class AafConnection extends BaseLoggingClass { public AafConnection( String cred ) { aafCred = cred; + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + unit_test = p.getProperty( "UnitTest", "No" ); + } @@ -144,7 +150,15 @@ public class AafConnection extends BaseLoggingClass { errorLogger.error(DmaapbcLogMessageEnum.UNKNOWN_HOST_EXCEPTION, pURL, uhe.getMessage() ); rc = 500; return rc; - } + } catch ( ConnectException ce ) { + if ( unit_test.equals( "Yes" ) ) { + rc = 201; + return rc; + } + errorLogger.error(DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, pURL, ce.getMessage() ); + rc = 500; + return rc; + } try { rc = uc.getResponseCode(); } catch ( SSLHandshakeException she ) { diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnection.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnection.java index 2d2ca8f..c744021 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnection.java +++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/DrProvConnection.java @@ -123,7 +123,7 @@ public class DrProvConnection extends BaseLoggingClass { } - private String bodyToString( InputStream is ) { + public String bodyToString( InputStream is ) { logger.info( "is=" + is ); StringBuilder sb = new StringBuilder(); BufferedReader br = new BufferedReader( new InputStreamReader(is)); @@ -531,8 +531,10 @@ public class DrProvConnection extends BaseLoggingClass { //logger.info( "get fields=" + postData ); String responsemessage = null; String responseBody = null; + logger.info( "templog:doGetNodes at 12.10.14.10" ); try { + logger.info( "templog:doGetNodes at 12.10.14.11" ); uc.setRequestMethod("GET"); @@ -545,12 +547,15 @@ public class DrProvConnection extends BaseLoggingClass { OutputStream os = null; int rc = -1; + logger.info( "templog:doGetNodes at 12.10.14.12" ); try { uc.connect(); + logger.info( "templog:doGetNodes at 12.10.14.13" ); //os = uc.getOutputStream(); //os.write( postData ); } catch (ProtocolException pe) { + logger.info( "templog:doGetNodes at 12.10.14.14" ); // Rcvd error instead of 100-Continue try { // work around glitch in Java 1.7.0.21 and likely others @@ -559,13 +564,16 @@ public class DrProvConnection extends BaseLoggingClass { } catch (Exception e) { } } + logger.info( "templog:doGetNodes at 12.10.14.15" ); rc = uc.getResponseCode(); logger.info( "http response code:" + rc ); responsemessage = uc.getResponseMessage(); logger.info( "responsemessage=" + responsemessage ); + logger.info( "templog:doGetNodes at 12.10.14.16" ); if (responsemessage == null) { + logger.info( "templog:doGetNodes at 12.10.14.17" ); // work around for glitch in Java 1.7.0.21 and likely others // When Expect: 100 is set and a non-100 response is received, the response message is not set but the response code is String h0 = uc.getHeaderField(0); @@ -577,6 +585,7 @@ public class DrProvConnection extends BaseLoggingClass { } } } + logger.info( "templog:doGetNodes at 12.10.14.18" ); err.setCode(rc); // may not really be an error, but we save rc if (rc == 200 ) { responseBody = bodyToString( uc.getInputStream() ); @@ -585,16 +594,21 @@ public class DrProvConnection extends BaseLoggingClass { err.setMessage(responsemessage); } + logger.info( "templog:doGetNodes at 12.10.14.19" ); } catch (ConnectException ce) { + logger.info( "templog:doGetNodes at 12.10.14.20" ); errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() ); err.setCode( 500 ); err.setMessage("Backend connection refused"); } catch (Exception e) { + logger.info( "templog:doGetNodes at 12.10.14.21" ); System.err.println("Unable to read response " ); e.printStackTrace(); } finally { - uc.disconnect(); + logger.info( "templog:doGetNodes at 12.10.14.22" ); + if ( uc != null ) uc.disconnect(); } + logger.info( "templog:doGetNodes at 12.10.14.23" ); return responseBody; } @@ -661,10 +675,12 @@ public class DrProvConnection extends BaseLoggingClass { } } catch (Exception e) { - System.err.println("Unable to read response " ); + System.err.println("Unable to read response " + e.getMessage() ); e.printStackTrace(); } finally { - uc.disconnect(); + if ( uc != null ) { + uc.disconnect(); + } } return responseBody; diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnection.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnection.java index 420f10e..529cbf0 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnection.java +++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrProvConnection.java @@ -58,14 +58,19 @@ public class MrProvConnection extends BaseLoggingClass{ String mechIdProperty = "aaf.TopicMgrUser"; String pwdProperty = "aaf.TopicMgrPassword"; DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + logger.info( "templog:getCred: 10"); String user = p.getProperty( mechIdProperty, "noMechId@domain.netset.com" ); + logger.info( "templog:getCred: 20"); String pwd = ""; String encPwd = p.getProperty( pwdProperty, "notSet" ); + logger.info( "templog:getCred: 30"); AafDecrypt decryptor = new AafDecrypt(); + logger.info( "templog:getCred: 40"); pwd = decryptor.decrypt(encPwd); + logger.info( "templog:getCred: 50"); return user + ":" + pwd; diff --git a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnection.java b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnection.java index 0b49379..bfbe826 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnection.java +++ b/src/main/java/org/onap/dmaap/dbcapi/aaf/client/MrTopicConnection.java @@ -36,6 +36,7 @@ import org.apache.log4j.Logger; import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.model.ApiError; import org.onap.dmaap.dbcapi.model.MR_Cluster; +import org.onap.dmaap.dbcapi.util.DmaapConfig; public class MrTopicConnection extends BaseLoggingClass { private String topicURL; @@ -44,12 +45,14 @@ public class MrTopicConnection extends BaseLoggingClass { private String mmProvCred; + private String unit_test; public MrTopicConnection(String user, String pwd ) { mmProvCred = new String( user + ":" + pwd ); - + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + unit_test = p.getProperty( "UnitTest", "No" ); } public boolean makeTopicConnection( MR_Cluster cluster, String topic, String overrideFqdn ) { @@ -159,10 +162,17 @@ public class MrTopicConnection extends BaseLoggingClass { } } catch (Exception e) { - response.setCode(500); - response.setMessage( "Unable to read response"); - logger.warn( response.getMessage() ); - e.printStackTrace(); + if ( unit_test.equals( "Yes" ) ) { + response.setCode(200); + response.setMessage( "simulated response"); + logger.info( "artificial 200 response from doPostMessage because unit_test =" + unit_test ); + } else { + + response.setCode(500); + response.setMessage( "Unable to read response"); + logger.warn( response.getMessage() ); + e.printStackTrace(); + } } finally { try { diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java b/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java index 9f7b3fc..b327f3a 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java +++ b/src/main/java/org/onap/dmaap/dbcapi/model/Feed.java @@ -96,7 +96,7 @@ public class Feed extends DmaapObject { public Feed ( String json ) { JSONParser parser = new JSONParser(); JSONObject jsonObj; - + logger.info( "templog:Feed at 10" ); try { jsonObj = (JSONObject) parser.parse( json ); } catch ( ParseException pe ) { @@ -104,30 +104,50 @@ public class Feed extends DmaapObject { this.setStatus( DmaapObject_Status.INVALID ); return; } + logger.info( "templog:Feed at 11" ); this.setFeedName( (String) jsonObj.get("name")); + logger.info( "templog:Feed at 12" ); this.setFeedVersion( (String) jsonObj.get("version")); + logger.info( "templog:Feed at 13" ); this.setFeedDescription( (String) jsonObj.get("description")); + logger.info( "templog:Feed at 14" ); this.setOwner( (String) jsonObj.get("publisher")); + logger.info( "templog:Feed at 15" ); this.setSuspended( (boolean) jsonObj.get("suspend")); + logger.info( "templog:Feed at 16" ); JSONObject links = (JSONObject) jsonObj.get("links"); + logger.info( "templog:Feed at 17" ); String url = (String) links.get("publish"); + logger.info( "templog:Feed at 18" ); this.setPublishURL( url ); + logger.info( "templog:Feed at 19" ); this.setFeedId( url.substring( url.lastIndexOf('/')+1, url.length() )); + logger.info( "templog:Feed at 20" ); logger.info( "feedid="+ this.getFeedId() ); + logger.info( "templog:Feed at 21" ); this.setSubscribeURL( (String) links.get("subscribe") ); + logger.info( "templog:Feed at 22" ); this.setLogURL( (String) links.get("log") ); + logger.info( "templog:Feed at 23" ); JSONObject auth = (JSONObject) jsonObj.get("authorization"); + logger.info( "templog:Feed at 24" ); this.setAsprClassification( (String) auth.get("classification")); + logger.info( "templog:Feed at 25" ); JSONArray pubs = (JSONArray) auth.get( "endpoint_ids"); + logger.info( "templog:Feed at 26" ); int i; + logger.info( "templog:Feed at 27" ); ArrayList<DR_Pub> dr_pub = new ArrayList<DR_Pub>(); + logger.info( "templog:Feed at 28" ); this.subs = new ArrayList<DR_Sub>(); for( i = 0; i < pubs.size(); i++ ) { + logger.info( "templog:Feed at 29 " + i ); JSONObject entry = (JSONObject) pubs.get(i); + logger.info( "templog:Feed at 30" ); dr_pub.add( new DR_Pub( "someLocation", (String) entry.get("id"), (String) entry.get("password"), @@ -135,9 +155,12 @@ public class Feed extends DmaapObject { this.getFeedId() + "." + DR_Pub.nextKey() )); } + logger.info( "templog:Feed at 31" ); this.setPubs( dr_pub ); + logger.info( "templog:Feed at 32" ); this.setStatus( DmaapObject_Status.VALID ); + logger.info( "templog:Feed at 33" ); } 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 d8ebc8b..46279ee 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 @@ -24,6 +24,8 @@ import java.util.Date; import javax.xml.bind.annotation.XmlRootElement; +import org.onap.dmaap.dbcapi.util.DmaapTimestamp; + @XmlRootElement @@ -32,7 +34,7 @@ public class MR_Cluster extends DmaapObject { private String dcaeLocationName; private String fqdn; private String[] hosts; - //private DmaapTimestamp lastMod; + private DmaapTimestamp lastMod; private String topicProtocol; private String topicPort; @@ -47,7 +49,9 @@ public class MR_Cluster extends DmaapObject { public MR_Cluster() { this.topicProtocol = defaultTopicProtocol; this.topicPort = defaultTopicPort; - this.lastMod = new Date(); + this.hosts = new String[3]; + this.lastMod = new DmaapTimestamp(); + this.lastMod.mark(); debugLogger.debug( "MR_Cluster constructor " + this.lastMod ); @@ -59,13 +63,22 @@ public class MR_Cluster extends DmaapObject { String[] h ) { this.dcaeLocationName = dLN; this.fqdn = f; +logger.info( "templog:MR_Cluster at 10" ); + this.hosts = new String[3]; this.hosts[0] = h[0]; +logger.info( "templog:MR_Cluster at 20" ); this.hosts[1] = h[1]; +logger.info( "templog:MR_Cluster at 30" ); this.hosts[2] = h[2]; +logger.info( "templog:MR_Cluster at 40" ); this.topicProtocol = defaultTopicProtocol; +logger.info( "templog:MR_Cluster at 50" ); this.topicPort = defaultTopicPort; + this.lastMod = new DmaapTimestamp(); + this.lastMod.mark(); - debugLogger.debug( "MR_Cluster constructor w initialization complete" + this.lastMod ); + debugLogger.debug( "MR_Cluster constructor w initialization complete" + this.lastMod.getVal() ); +logger.info( "templog:MR_Cluster at 60" ); } public String getDcaeLocationName() { diff --git a/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java b/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java index 4d06310..c0699d5 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java +++ b/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java @@ -54,10 +54,16 @@ import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; * - static html pages (for documentation). */ public class JettyServer extends BaseLoggingClass { + private Server server; + + + public Server getServer() { + return server; + } public JettyServer( Properties params ) throws Exception { - Server server = new Server(); + server = new Server(); int httpPort = Integer.valueOf(params.getProperty("IntHttpPort", "80" )); int sslPort = Integer.valueOf(params.getProperty("IntHttpsPort", "443" )); boolean allowHttp = Boolean.valueOf(params.getProperty("HttpAllowed", "false")); @@ -136,9 +142,13 @@ public class JettyServer extends BaseLoggingClass { try { serverLogger.info("Starting jetty server"); - server.start(); - server.dumpStdErr(); - server.join(); + String unit_test = params.getProperty("UnitTest", "No"); + serverLogger.info("UnitTest=" + unit_test); + if ( unit_test.equals( "No" ) ) { + server.start(); + server.dumpStdErr(); + server.join(); + } } catch ( Exception e ) { errorLogger.error( "Exception " + e ); errorLogger.error( "possibly unable to use keystore " + keystore + " with passwords " + keystorePwd + " and " + keyPwd ); diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/DR_NodeService.java b/src/main/java/org/onap/dmaap/dbcapi/service/DR_NodeService.java index e80b531..f2476a8 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/DR_NodeService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/DR_NodeService.java @@ -41,10 +41,15 @@ public class DR_NodeService extends BaseLoggingClass { private String getX( String X, ApiError apiError ) { + logger.info( "templog:getX at" + " 12.10.10" ); DrProvConnection prov = new DrProvConnection(); + logger.info( "templog:getX at" + " 12.10.12" ); prov.makeNodesConnection( X ); + logger.info( "templog:getX at" + " 12.10.14" ); String resp = prov.doGetNodes( apiError ); + logger.info( "templog:getX at" + " 12.10.16" ); logger.info( "rc=" + apiError.getCode() ); + logger.info( "templog:getX at" + " 12.10.18" ); return resp; } @@ -72,15 +77,21 @@ public class DR_NodeService extends BaseLoggingClass { boolean containsNode( String aNode , ApiError apiError ){ + logger.info( "templog:containsNode at" + " 12.10" ); //DrProvConnection prov = new DrProvConnection(); //prov.makeNodesConnection(); currentNodes = getX( "NODES", apiError ); + logger.info( "templog:containsNode at" + " 12.12" ); if ( ! apiError.is2xx() || currentNodes == null ) { + logger.info( "templog:containsNode at" + " 12.14" ); return false; } + logger.info( "templog:containsNode at" + " 12.16" ); logger.info( "NODES now=" + currentNodes ); String[] nodeList = currentNodes.split("\\|"); + logger.info( "templog:containsNode at" + " 12.17" ); for( String n: nodeList ) { + logger.info( "templog:containsNode at" + " 12.18" ); logger.info( "compare existing node " + n + " vs " + aNode ); if ( n.equals(aNode) ) { return true; @@ -161,28 +172,36 @@ public class DR_NodeService extends BaseLoggingClass { apiError.setMessage( "Node " + fqdn + " already exists"); return null; } + logger.info( "templog:addDr_Node at" + " 10" ); DrProv drProv = new DrProv(); + logger.info( "templog:addDr_Node at" + " 12" ); if ( ! drProv.containsNode( node.getFqdn(), apiError ) && apiError.is2xx() ) { + logger.info( "templog:addDr_Node at" + " 15" ); drProv.addNode( node.getFqdn(), apiError ); } + logger.info( "templog:addDr_Node at" + " 20" ); if ( ! apiError.is2xx()) { return null; } + logger.info( "templog:addDr_Node at" + " 30" ); DcaeLocationService locService = new DcaeLocationService(); if ( locService.isEdgeLocation( node.getDcaeLocationName()) && ! drProv.containsStaticNode( node.getFqdn(), apiError ) ) { if ( apiError.is2xx() ) { drProv.addStaticNode( node.getFqdn(), apiError ); } } + logger.info( "templog:addDr_Node at" + " 40" ); if ( ! apiError.is2xx()) { return null; } + logger.info( "templog:addDr_Node at" + " 50" ); node.setLastMod(); node.setStatus(DmaapObject_Status.VALID); dr_nodes.put( node.getFqdn(), node ); + logger.info( "templog:addDr_Node at" + " 60" ); apiError.setCode(200); return node; } diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java b/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java index 09bf8fd..c3f8c9c 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java @@ -32,6 +32,8 @@ import org.onap.dmaap.dbcapi.logging.BaseLoggingClass; import org.onap.dmaap.dbcapi.logging.DmaapbcLogMessageEnum; import org.onap.dmaap.dbcapi.model.ApiError; import org.onap.dmaap.dbcapi.model.DR_Sub; +import org.onap.dmaap.dbcapi.util.DmaapConfig; +import org.onap.dmaap.dbcapi.util.RandomInteger; public class DR_SubService extends BaseLoggingClass { @@ -40,14 +42,19 @@ public class DR_SubService extends BaseLoggingClass { private String provURL; private static DrProvConnection prov; + private String unit_test; + public DR_SubService( ) { logger.debug( "Entry: DR_SubService (with no args)" ); - + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + unit_test = p.getProperty( "UnitTest", "No" ); } public DR_SubService( String subURL ) { logger.debug( "Entry: DR_SubService " + subURL ); provURL = subURL; + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + unit_test = p.getProperty( "UnitTest", "No" ); } public Map<String, DR_Sub> getDR_Subs() { logger.debug( "enter getDR_Subs()"); @@ -87,7 +94,10 @@ public class DR_SubService extends BaseLoggingClass { prov = new DrProvConnection(); prov.makeSubPostConnection( provURL ); String resp = prov.doPostDr_Sub( sub, apiError ); - logger.debug( "resp=" + resp ); + if ( unit_test.equals( "Yes" ) ) { + resp = simulateResp( sub, "POST" ); + } + logger.debug( "addDr_Sub resp=" + resp ); DR_Sub snew = null; @@ -170,4 +180,20 @@ public class DR_SubService extends BaseLoggingClass { return; } + private String simulateResp( DR_Sub sub, String action ){ + String server = "subscriber.onap.org"; + String subid; + if ( action.equals( "POST" ) ) { + RandomInteger ran = new RandomInteger(10000); + subid = Integer.toString( ran.next() ); + } else if ( action.equals( "PUT" ) ) { + subid = sub.getSubId(); + } else { + subid = "99"; + } + String ret = String.format("{\"delivery\": {\"url\": \"https://%s/delivery/%s\", \"user\": \"joe\", \"password\": \"secret\", \"use100\": true}, \"metadataOnly\": false, \"groupid\": \"0\" , \"follow_redirect\": true }", + server, subid ); + + return ret; + } } 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 8436820..6f1294a 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/DmaapService.java @@ -204,6 +204,16 @@ public class DmaapService extends BaseLoggingClass { } return false; } + + public boolean testCreateMmaTopic() { + + DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); + String unit_test = p.getProperty( "UnitTest", "No" ); + if ( unit_test.equals( "Yes" ) ) { + return createMmaTopic(); + } + return false; + } // create the special topic for MMA provisioning. // return true indicating a problem in topic creation, diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/FeedService.java b/src/main/java/org/onap/dmaap/dbcapi/service/FeedService.java index d36adc4..d11dcb9 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/service/FeedService.java +++ b/src/main/java/org/onap/dmaap/dbcapi/service/FeedService.java @@ -20,6 +20,8 @@ package org.onap.dmaap.dbcapi.service; +import org.onap.dmaap.dbcapi.util.RandomInteger; + import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -44,11 +46,13 @@ public class FeedService extends BaseLoggingClass { private DR_SubService subService = new DR_SubService(); private DcaeLocationService dcaeLocations = new DcaeLocationService(); private String deleteHandling; + private String unit_test; public FeedService() { logger.info( "new FeedService"); DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig(); deleteHandling = p.getProperty("Feed.deleteHandling", "DeleteOnDR"); + unit_test = p.getProperty( "UnitTest", "No" ); } @@ -230,6 +234,10 @@ public class FeedService extends BaseLoggingClass { DrProvConnection prov = new DrProvConnection(); prov.makeFeedConnection(); String resp = prov.doPostFeed( req, err ); + if ( unit_test.equals( "Yes" ) ) { + // assume resp is null, so need to simulate it + resp = simulateResp( req, "POST" ); + } logger.info( "resp=" + resp ); if ( resp == null ) { switch( err.getCode() ) { @@ -288,6 +296,10 @@ public class FeedService extends BaseLoggingClass { DrProvConnection prov = new DrProvConnection(); prov.makeFeedConnection( req.getFeedId() ); String resp = prov.doPutFeed( req, err ); + if ( unit_test.equals( "Yes" ) ) { + // assume resp is null, so need to simulate it + resp = simulateResp( req, "PUT" ); + } logger.info( "resp=" + resp ); if ( resp == null ) { switch( err.getCode() ) { @@ -357,6 +369,10 @@ public class FeedService extends BaseLoggingClass { DrProvConnection prov = new DrProvConnection(); prov.makeFeedConnection( req.getFeedId() ); String resp = prov.doDeleteFeed( req, err ); + if ( unit_test.equals( "Yes" ) ) { + // assume resp is null, so need to simulate it + resp = simulateDelResp( req ); + } logger.info( "resp=" + resp ); if ( resp == null ) { switch( err.getCode() ) { @@ -388,4 +404,42 @@ public class FeedService extends BaseLoggingClass { } + private String simulateResp( Feed f, String action ){ + String server = "drps.onap.org"; + String feedid; + if ( action.equals( "POST" ) ) { + RandomInteger ran = new RandomInteger(10000); + feedid = Integer.toString( ran.next() ); + } else if ( action.equals( "PUT" ) ) { + feedid = f.getFeedId(); + } else { + feedid = "99"; + } + String ret = String.format( +"{\"suspend\":false,\"groupid\":0,\"description\":\"%s\",\"version\":\"1.0\",\"authorization\":{\"endpoint_addrs\":[],\"classification\":\"unclassified\",\"endpoint_ids\":[{\"password\":\"topSecret123\",\"id\":\"sim\"}]},\"name\":\"%s\",\"business_description\":\"\",\"publisher\":\"sim\",\"links\":{\"subscribe\":\"https://%s/subscribe/%s\",\"log\":\"https://%s/feedlog/%s\",\"publish\":\"https://%s/publish/%s\",\"self\":\"https://%s/feed/%s\"}}", + f.getFeedDescription(), + f.getFeedName(), + server, feedid, + server, feedid, + server, feedid, + server, feedid + + ); + return ret; + } + private String simulateDelResp( Feed f ){ + String server = "drps.onap.org"; + String feedid = f.getFeedId(); + String ret = String.format( +"{\"suspend\":true,\"groupid\":0,\"description\":\"%s\",\"version\":\"1.0\",\"authorization\":{\"endpoint_addrs\":[],\"classification\":\"unclassified\",\"endpoint_ids\":[{\"password\":\"topSecret123\",\"id\":\"sim\"}]},\"name\":\"%s\",\"business_description\":\"\",\"publisher\":\"sim\",\"links\":{\"subscribe\":\"https://%s/subscribe/%s\",\"log\":\"https://%s/feedlog/%s\",\"publish\":\"https://%s/publish/%s\",\"self\":\"https://%s/feed/%s\"}}", + f.getFeedDescription(), + f.getFeedName(), + server, feedid, + server, feedid, + server, feedid, + server, feedid + + ); + return ret; + } } 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 977288b..d8eb91d 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 @@ -120,7 +120,12 @@ public class MR_ClusterService extends BaseLoggingClass { mr_clusters.put( cluster.getDcaeLocationName(), cluster ); DcaeLocationService svc = new DcaeLocationService(); DcaeLocation loc = svc.getDcaeLocation( cluster.getDcaeLocationName() ); - if ( loc.isCentral() ) { + if ( loc == null ) { + logger.error( "DcaeLocation not found for cluster in " + cluster.getDcaeLocationName() ); + cluster.setLastMod(); + cluster.setStatus(DmaapObject_Status.INVALID); + mr_clusters.put( cluster.getDcaeLocationName(), cluster ); + } else if ( loc.isCentral() ) { ApiError resp = TopicService.setBridgeClientPerms( cluster ); if ( ! resp.is2xx() ) { logger.error( "Unable to provision Bridge to " + cluster.getDcaeLocationName() ); diff --git a/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java b/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java index 2909419..ea8483f 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java +++ b/src/main/java/org/onap/dmaap/dbcapi/util/RandomInteger.java @@ -40,7 +40,7 @@ public final class RandomInteger { return randomGenerator.nextInt(range); } - /** Generate 10 random integers in the range 0..99. */ +/** Generate 10 random integers in the range 0..99. public static final void main(String... aArgs){ log("Generating 10 random integers in range 0..99."); RandomInteger ri = new RandomInteger(100); @@ -57,5 +57,6 @@ public final class RandomInteger { private static void log(String aMessage){ System.out.println(aMessage); } +*/ } |