summaryrefslogtreecommitdiffstats
path: root/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java196
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/database/ConnectionFactory.java2
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/model/ApiError.java32
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java20
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java22
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/AuthorizationFilter.java15
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/BridgeResource.java34
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/DR_NodeResource.java38
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java64
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java70
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/DcaeLocationResource.java64
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/DmaapResource.java19
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/FeedResource.java49
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/InfoResource.java10
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/MR_ClientResource.java36
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResource.java36
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/ResponseBuilder.java85
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java30
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/service/ApiService.java64
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/service/DR_SubService.java4
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/service/TopicService.java29
21 files changed, 522 insertions, 397 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java b/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java
index 441596a..f928a11 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/client/DrProvConnection.java
@@ -48,6 +48,7 @@ public class DrProvConnection extends BaseLoggingClass {
private String behalfHeader;
private String feedContentType;
private String subContentType;
+ private String unit_test;
private HttpsURLConnection uc;
@@ -64,6 +65,7 @@ public class DrProvConnection extends BaseLoggingClass {
subContentType = p.getProperty( "DR.subContentType", "application/vnd.dmaap-dr.subscription");
logger.info( "provURL=" + provURL + " provApi=" + provApi + " behalfHeader=" + behalfHeader
+ " feedContentType=" + feedContentType + " subContentType=" + subContentType );
+ unit_test = p.getProperty( "UnitTest", "No" );
}
@@ -214,15 +216,21 @@ public class DrProvConnection extends BaseLoggingClass {
err.setCode( 500 );
err.setMessage( "Unable to read response from DR");
} catch (Exception e) {
- logger.warn("Unable to read response " );
- e.printStackTrace();
- try {
- err.setCode( uc.getResponseCode());
- err.setMessage(uc.getResponseMessage());
- } catch (Exception e2) {
- err.setCode( 500 );
- err.setMessage("Unable to determine response message");
- }
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doPostFeed because unit_test =" + unit_test );
+ } else {
+ logger.warn("Unable to read response " );
+ e.printStackTrace();
+ try {
+ err.setCode( uc.getResponseCode());
+ err.setMessage(uc.getResponseMessage());
+ } catch (Exception e2) {
+ err.setCode( 500 );
+ err.setMessage("Unable to determine response message");
+ }
+ }
}
finally {
try {
@@ -270,9 +278,16 @@ public class DrProvConnection extends BaseLoggingClass {
err.setMessage(responsemessage);
}
} catch (Exception e) {
- logger.error("Unable to read response " );
- e.printStackTrace();
- } finally {
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doXgressPost because unit_test =" + unit_test );
+ } else {
+ logger.error("Unable to read response " );
+ e.printStackTrace();
+ }
+ }
+ finally {
try {
uc.disconnect();
} catch ( Exception e ) {
@@ -346,9 +361,16 @@ public class DrProvConnection extends BaseLoggingClass {
}
} catch (Exception e) {
- System.err.println("Unable to read response " );
- e.printStackTrace();
- } finally {
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doPostDr_Sub because unit_test =" + unit_test );
+ } else {
+ System.err.println("Unable to read response " );
+ e.printStackTrace();
+ }
+ }
+ finally {
try {
uc.disconnect();
} catch ( Exception e ) {}
@@ -411,7 +433,7 @@ public class DrProvConnection extends BaseLoggingClass {
if (rc >= 200 && rc < 300 ) {
responseBody = bodyToString( uc.getInputStream() );
logger.info( "responseBody=" + responseBody );
-
+ err.setCode( rc );
} else if ( rc == 404 ) {
err.setCode( rc );
err.setFields( "feedid");
@@ -433,8 +455,14 @@ public class DrProvConnection extends BaseLoggingClass {
err.setCode( 500 );
err.setMessage( "Unable to read response from DR");
} catch (Exception e) {
- logger.warn("Unable to read response " );
- e.printStackTrace();
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doPutFeed because unit_test =" + unit_test );
+ } else {
+ logger.warn("Unable to read response " );
+ e.printStackTrace();
+ }
try {
err.setCode( uc.getResponseCode());
err.setMessage(uc.getResponseMessage());
@@ -515,8 +543,14 @@ public class DrProvConnection extends BaseLoggingClass {
err.setCode( 500 );
err.setMessage("Backend connection refused");
} catch (Exception e) {
- logger.error("Unable to read response " );
- logger.error(e.getMessage(), e);
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doPutDr_Sub because unit_test =" + unit_test );
+ } else {
+ logger.error("Unable to read response " );
+ logger.error(e.getMessage(), e);
+ }
} finally {
uc.disconnect();
}
@@ -530,22 +564,19 @@ 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");
int rc = -1;
- logger.info( "templog:doGetNodes at 12.10.14.12" );
+
try {
uc.connect();
- logger.info( "templog:doGetNodes at 12.10.14.13" );
-
+
} 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
@@ -554,16 +585,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);
@@ -575,7 +606,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() );
@@ -584,21 +615,26 @@ 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();
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doGetNodes because unit_test =" + unit_test );
+ } else {
+ System.err.println("Unable to read response " );
+ e.printStackTrace();
+ }
} finally {
- 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;
}
@@ -665,8 +701,14 @@ public class DrProvConnection extends BaseLoggingClass {
}
} catch (Exception e) {
- System.err.println("Unable to read response " + e.getMessage() );
- e.printStackTrace();
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doPutNodes because unit_test =" + unit_test );
+ } else {
+ System.err.println("Unable to read response " + e.getMessage() );
+ e.printStackTrace();
+ }
} finally {
if ( uc != null ) {
uc.disconnect();
@@ -751,15 +793,21 @@ public class DrProvConnection extends BaseLoggingClass {
err.setCode( 500 );
err.setMessage( "Unable to read response from DR");
} catch (Exception e) {
- logger.warn("Unable to read response " );
- e.printStackTrace();
- try {
- err.setCode( uc.getResponseCode());
- err.setMessage(uc.getResponseMessage());
- } catch (Exception e2) {
- err.setCode( 500 );
- err.setMessage("Unable to determine response message");
- }
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doDeleteFeed because unit_test =" + unit_test );
+ } else {
+ logger.warn("Unable to read response " );
+ e.printStackTrace();
+ try {
+ err.setCode( uc.getResponseCode());
+ err.setMessage(uc.getResponseMessage());
+ } catch (Exception e2) {
+ err.setCode( 500 );
+ err.setMessage("Unable to determine response message");
+ }
+ }
} finally {
try {
uc.disconnect();
@@ -829,48 +877,30 @@ public class DrProvConnection extends BaseLoggingClass {
}
} catch (ConnectException ce) {
- errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
- err.setCode( 500 );
- err.setMessage("Backend connection refused");
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doDeleteDr_Sub because unit_test =" + unit_test );
+ } else {
+ errorLogger.error( DmaapbcLogMessageEnum.HTTP_CONNECTION_EXCEPTION, provURL, ce.getMessage() );
+ err.setCode( 500 );
+ err.setMessage("Backend connection refused");
+ }
} catch (Exception e) {
- System.err.println("Unable to read response " );
- e.printStackTrace();
+ if ( unit_test.equals( "Yes" ) ) {
+ err.setCode(200);
+ err.setMessage( "simulated response");
+ logger.info( "artificial 200 response from doDeleteDr_Sub because unit_test =" + unit_test );
+ } else {
+ System.err.println("Unable to read response " );
+ e.printStackTrace();
+ }
} finally {
uc.disconnect();
}
return responseBody;
}
- /*
- public static void main( String[] args ) throws Exception {
- PropertyConfigurator.configure("log4j.properties");
- logger.info("Started.");
-
- RandomInteger ri = new RandomInteger(10000);
- //String postJSON = String.format("{\"name\": \"dgl feed %d\", \"version\": \"v1.0\", \"description\": \"dgl feed N for testing\", \"authorization\": { \"classification\": \"unclassified\", \"endpoint_addrs\": [],\"endpoint_ids\": [{\"password\": \"test\",\"id\": \"test\"}]}}", ri.next()) ;
- int i = ri.next();
- Feed tst = new Feed( "dgl feed " + i,
- "v1.0",
- "dgl feed " + i + "for testing",
- "TEST",
- "unclassified"
- );
- ArrayList<DR_Pub> pubs = new ArrayList<DR_Pub>();
- pubs.add( new DR_Pub( "centralLocation" ) );
- tst.setPubs(pubs);
-
- boolean rc;
- DrProvConnection context = new DrProvConnection();
- rc = context.makeFeedConnection();
- logger.info( "makeFeedConnection returns " + rc);
- ApiError err = new ApiError();
- if ( rc ) {
- String tmp = context.doPostFeed( tst, err );
- logger.info( "doPostFeed returns " + tmp);
- }
-
- }
- */
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/ConnectionFactory.java b/src/main/java/org/onap/dmaap/dbcapi/database/ConnectionFactory.java
index 0f14e60..e32b8e0 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/database/ConnectionFactory.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/database/ConnectionFactory.java
@@ -3,6 +3,7 @@
* org.onap.dmaap
* ================================================================================
* Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2019 IBM.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -108,6 +109,7 @@ public class ConnectionFactory {
TimeUnit.SECONDS.sleep(seconds);
} catch (InterruptedException e) {
logger.debug("Waiting interrupted. ", e);
+ Thread.currentThread().interrupt();
}
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/ApiError.java b/src/main/java/org/onap/dmaap/dbcapi/model/ApiError.java
index 8d8e23f..2e05740 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/model/ApiError.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/model/ApiError.java
@@ -21,13 +21,28 @@
package org.onap.dmaap.dbcapi.model;
import javax.xml.bind.annotation.XmlRootElement;
+import java.util.Objects;
@XmlRootElement
public class ApiError {
private int code;
private String message;
private String fields;
-
+
+ public ApiError() {
+ this(0, null, null);
+ }
+
+ public ApiError(int code, String message) {
+ this(code, message, null);
+ }
+
+ public ApiError(int code, String message, String fields) {
+ this.code = code;
+ this.message = message;
+ this.fields = fields;
+ }
+
public int getCode() {
return code;
}
@@ -58,4 +73,19 @@ public class ApiError {
message = null;
fields = null;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ ApiError apiError = (ApiError) o;
+ return code == apiError.code &&
+ Objects.equals(message, apiError.message) &&
+ Objects.equals(fields, apiError.fields);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(code, message, fields);
+ }
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java
index 06598f7..0d146b7 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Pub.java
@@ -32,6 +32,10 @@ public class DR_Pub extends DmaapObject {
private String userpwd;
private String feedId;
private String pubId;
+
+ // NOTE: the following fields are optional in the API but not stored in the DB
+ private String feedName;
+ private String feedVersion;
public DR_Pub() {
@@ -114,6 +118,22 @@ public class DR_Pub extends DmaapObject {
public void setNextPubId() {
this.pubId = this.feedId + "." + DR_Pub.nextKey();
}
+
+ public String getFeedName() {
+ return feedName;
+ }
+
+ public void setFeedName(String feedName) {
+ this.feedName = feedName;
+ }
+
+ public String getFeedVersion() {
+ return feedVersion;
+ }
+
+ public void setFeedVersion(String feedVersion) {
+ this.feedVersion = feedVersion;
+ }
public DR_Pub setRandomUserName() {
RandomString r = new RandomString(15);
diff --git a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java
index dd0b85d..9b6e2d7 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/model/DR_Sub.java
@@ -45,6 +45,10 @@ public class DR_Sub extends DmaapObject {
private boolean guaranteedDelivery;
private boolean guaranteedSequence;
private boolean privilegedSubscriber;
+
+ // NOTE: the following fields are optional in the API but not stored in the DB
+ private String feedName;
+ private String feedVersion;
public DR_Sub() {
@@ -230,6 +234,24 @@ public class DR_Sub extends DmaapObject {
public void setPrivilegedSubscriber(boolean privilegedSubscriber) {
this.privilegedSubscriber = privilegedSubscriber;
}
+
+
+
+ public String getFeedName() {
+ return feedName;
+ }
+
+ public void setFeedName(String feedName) {
+ this.feedName = feedName;
+ }
+
+ public String getFeedVersion() {
+ return feedVersion;
+ }
+
+ public void setFeedVersion(String feedVersion) {
+ this.feedVersion = feedVersion;
+ }
public byte[] getBytes(String provApi) {
if ( "AT&T".equals(provApi)) {
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/AuthorizationFilter.java b/src/main/java/org/onap/dmaap/dbcapi/resources/AuthorizationFilter.java
index 9dafb55..fd5b4aa 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/AuthorizationFilter.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/AuthorizationFilter.java
@@ -20,8 +20,6 @@
package org.onap.dmaap.dbcapi.resources;
-import java.io.IOException;
-
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
@@ -34,29 +32,26 @@ import org.onap.dmaap.dbcapi.service.ApiService;
public class AuthorizationFilter implements ContainerRequestFilter {
private Logger logger = Logger.getLogger(AuthorizationFilter.class.getName());
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
@Override
- public void filter(ContainerRequestContext requestContext)
- throws IOException {
+ public void filter(ContainerRequestContext requestContext) {
ApiService apiResp = new ApiService()
.setAuth( requestContext.getHeaderString("Authorization") )
.setUriPath(requestContext.getUriInfo().getPath())
.setHttpMethod( requestContext.getMethod() )
.setRequestId( requestContext.getHeaderString("X-ECOMP-RequestID") );
-
+
try {
apiResp.checkAuthorization();
} catch ( AuthenticationErrorException ae ) {
logger.error("Error", ae);
- requestContext.abortWith( apiResp.unauthorized( apiResp.getErr().getMessage() ) );
- return ;
+ requestContext.abortWith( responseBuilder.unauthorized( apiResp.getErr().getMessage() ) );
} catch ( Exception e ) {
logger.error("Error", e);
- requestContext.abortWith( apiResp.unavailable() );
- return;
+ requestContext.abortWith( responseBuilder.unavailable() );
}
-
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/BridgeResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/BridgeResource.java
index 192b63d..299c48f 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/BridgeResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/BridgeResource.java
@@ -32,13 +32,11 @@ import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
import org.onap.dmaap.dbcapi.model.ApiError;
import org.onap.dmaap.dbcapi.model.BrTopic;
import org.onap.dmaap.dbcapi.model.MirrorMaker;
-import org.onap.dmaap.dbcapi.service.ApiService;
import org.onap.dmaap.dbcapi.service.MirrorMakerService;
import io.swagger.annotations.Api;
@@ -46,6 +44,8 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
+import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
+
@Path("/bridge")
@Api( value= "bridge", description = "Endpoint for retreiving MR Bridge metrics" )
@Consumes(MediaType.APPLICATION_JSON)
@@ -54,6 +54,7 @@ import io.swagger.annotations.ApiResponses;
public class BridgeResource extends BaseLoggingClass {
private MirrorMakerService mmService = new MirrorMakerService();
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
@GET
@ApiOperation( value = "return BrTopic details",
@@ -66,10 +67,9 @@ public class BridgeResource extends BaseLoggingClass {
})
public Response getBridgedTopics(@QueryParam("mmagent") String mmagent,
@QueryParam("detail") Boolean detailFlag ){
- ApiService check = new ApiService();
-
+
if ( mmagent == null ) {
- return check.success(getMMcounts(Boolean.TRUE.equals(detailFlag)));
+ return responseBuilder.success(getMMcounts(Boolean.TRUE.equals(detailFlag)));
}
logger.info( "getBridgeTopics():" + " mmagent=" + mmagent);
@@ -81,7 +81,7 @@ public class BridgeResource extends BaseLoggingClass {
MirrorMaker mm = mmService.getMirrorMaker(mmagent);
if ( mm == null ) {
- return check.notFound();
+ return responseBuilder.notFound();
}
brTopic.setTopicCount( mm.getTopicCount() );
@@ -91,16 +91,16 @@ public class BridgeResource extends BaseLoggingClass {
logger.info( "topicCount [2 locations]: " + brTopic.getTopicCount() );
- return check.success(brTopic);
+ return responseBuilder.success(brTopic);
} else {
logger.info( "getBridgeTopics() detail:" + " mmagent=" + mmagent);
// get topics between 2 bridged locations
MirrorMaker mm = mmService.getMirrorMaker(mmagent);
if ( mm == null ) {
- return check.notFound();
+ return responseBuilder.notFound();
}
- return check.success(mm);
+ return responseBuilder.success(mm);
}
}
@@ -156,15 +156,13 @@ public class BridgeResource extends BaseLoggingClass {
@QueryParam("refresh") Boolean refreshFlag,
@QueryParam("split") Boolean splitFlag,
MirrorMaker newBridge ){
- ApiService check = new ApiService();
-
logger.info( "putBridgeTopics() mmagent:" + mmagent );
if ( mmagent != null ) { // put topics between 2 bridged locations
MirrorMaker mm = mmService.getMirrorMaker(mmagent);
if ( mm == null ) {
- return check.notFound();
+ return responseBuilder.notFound();
}
if ( splitFlag != null && splitFlag == true ) {
@@ -173,24 +171,20 @@ public class BridgeResource extends BaseLoggingClass {
logger.info( "setting whitelist from message body containing mmName=" + newBridge.getMmName());
if ( ! mmagent.equals(newBridge.getMmName()) ){
logger.error( "mmagent query param does not match mmName in body");
- check.setCode(Status.BAD_REQUEST.getStatusCode());
- check.setMessage("mmagent query param does not match mmName in body");
- return check.error();
+ return responseBuilder.error(new ApiError(BAD_REQUEST.getStatusCode(),
+ "mmagent query param does not match mmName in body"));
}
mm.setTopics( newBridge.getTopics() );
} else {
logger.info( "refreshing whitelist from memory");
}
mmService.updateMirrorMaker(mm);
- return check.success(mm);
+ return responseBuilder.success(mm);
}
else {
-
logger.error( "mmagent is required for PUT");
- check.setCode(Status.BAD_REQUEST.getStatusCode());
- check.setMessage("mmagent is required for PUT");
- return check.error();
+ return responseBuilder.error(new ApiError(BAD_REQUEST.getStatusCode(), "mmagent is required for PUT"));
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_NodeResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_NodeResource.java
index 8091ac3..029222e 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_NodeResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_NodeResource.java
@@ -38,7 +38,6 @@ import javax.ws.rs.Produces;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
-import javax.ws.rs.core.Response.Status;
import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
import org.onap.dmaap.dbcapi.model.ApiError;
@@ -46,6 +45,9 @@ import org.onap.dmaap.dbcapi.model.DR_Node;
import org.onap.dmaap.dbcapi.service.ApiService;
import org.onap.dmaap.dbcapi.service.DR_NodeService;
+import static javax.ws.rs.core.Response.Status.BAD_REQUEST;
+import static javax.ws.rs.core.Response.Status.NO_CONTENT;
+
@Path("/dr_nodes")
@Api( value= "dr_nodes", description = "Endpoint for a Data Router Node server" )
@Consumes(MediaType.APPLICATION_JSON)
@@ -53,7 +55,8 @@ import org.onap.dmaap.dbcapi.service.DR_NodeService;
@Authorization
public class DR_NodeResource extends BaseLoggingClass {
- DR_NodeService dr_nodeService = new DR_NodeService();
+ private DR_NodeService dr_nodeService = new DR_NodeService();
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
@GET
@ApiOperation( value = "return DR_Node details",
@@ -64,13 +67,11 @@ public class DR_NodeResource extends BaseLoggingClass {
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response getDr_Nodes() {
- ApiService resp = new ApiService();
-
List<DR_Node> nodes = dr_nodeService.getAllDr_Nodes();
GenericEntity<List<DR_Node>> list = new GenericEntity<List<DR_Node>>(nodes) {
};
- return resp.success(list);
+ return responseBuilder.success(list);
}
@POST
@@ -90,17 +91,14 @@ public class DR_NodeResource extends BaseLoggingClass {
resp.required( "dcaeLocation", node.getDcaeLocationName(), "");
resp.required( "fqdn", node.getFqdn(), "");
} catch ( RequiredFieldException rfe ) {
- resp.setCode(Status.BAD_REQUEST.getStatusCode());
- resp.setMessage("missing required field");
- resp.setFields("dcaeLocation, fqdn");
-
- return resp.error();
+ return responseBuilder.error(new ApiError(BAD_REQUEST.getStatusCode(),
+ "missing required field", "dcaeLocation, fqdn"));
}
DR_Node nNode = dr_nodeService.addDr_Node(node, resp.getErr());
if ( resp.getErr().is2xx()) {
- return resp.success(nNode);
+ return responseBuilder.success(nNode);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@PUT
@@ -122,14 +120,14 @@ public class DR_NodeResource extends BaseLoggingClass {
resp.required( "dcaeLocation", name, "");
resp.required( "fqdn", node.getFqdn(), "");
} catch ( RequiredFieldException rfe ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
node.setFqdn(name);
DR_Node nNode = dr_nodeService.updateDr_Node(node, resp.getErr());
if ( resp.getErr().is2xx()) {
- return resp.success(nNode);
+ return responseBuilder.success(nNode);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@DELETE
@@ -151,13 +149,13 @@ public class DR_NodeResource extends BaseLoggingClass {
resp.required( "fqdn", name, "");
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
dr_nodeService.removeDr_Node(name, resp.getErr());
if ( resp.getErr().is2xx() ) {
- return resp.success(Status.NO_CONTENT.getStatusCode(), null);
+ return responseBuilder.success(NO_CONTENT.getStatusCode(), null);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@GET
@@ -176,8 +174,8 @@ public class DR_NodeResource extends BaseLoggingClass {
DR_Node nNode = dr_nodeService.getDr_Node( name, resp.getErr() );
if ( resp.getErr().is2xx() ) {
- return resp.success(nNode);
+ return responseBuilder.success(nNode);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java
index bcdb4b3..9c2ae21 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_PubResource.java
@@ -58,7 +58,8 @@ import org.onap.dmaap.dbcapi.service.FeedService;
@Authorization
public class DR_PubResource extends BaseLoggingClass {
- DR_PubService dr_pubService = new DR_PubService();
+ private DR_PubService dr_pubService = new DR_PubService();
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
@GET
@ApiOperation( value = "return DR_Pub details",
@@ -69,14 +70,12 @@ public class DR_PubResource extends BaseLoggingClass {
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response getDr_Pubs() {
- ApiService resp = new ApiService();
-
logger.info( "Entry: GET /dr_pubs");
List<DR_Pub> pubs = dr_pubService.getAllDr_Pubs();
GenericEntity<List<DR_Pub>> list = new GenericEntity<List<DR_Pub>>(pubs) {
};
- return resp.success(list);
+ return responseBuilder.success(list);
}
@POST
@@ -91,22 +90,43 @@ public class DR_PubResource extends BaseLoggingClass {
DR_Pub pub
) {
ApiService resp = new ApiService();
+ FeedService feeds = new FeedService();
+ Feed fnew = null;
logger.info( "Entry: POST /dr_pubs");
try {
resp.required( "feedId", pub.getFeedId(), "");
+ } catch ( RequiredFieldException rfe ) {
+ try {
+ resp.required( "feedName", pub.getFeedName(), "");
+ }catch ( RequiredFieldException rfe2 ) {
+ logger.debug( resp.toString() );
+ return responseBuilder.error(resp.getErr());
+ }
+ // if we found a FeedName instead of a FeedId then try to look it up.
+ List<Feed> nfeeds = feeds.getAllFeeds( pub.getFeedName(), pub.getFeedVersion(), "equals");
+ if ( nfeeds.size() != 1 ) {
+ logger.debug( "Attempt to match "+ pub.getFeedName() + " ver="+pub.getFeedVersion() + " matched " + nfeeds.size() );
+ return responseBuilder.error(resp.getErr());
+ }
+ fnew = nfeeds.get(0);
+ }
+ try {
resp.required( "dcaeLocationName", pub.getDcaeLocationName(), "");
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.getErr().toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
- FeedService feeds = new FeedService();
- Feed fnew = feeds.getFeed( pub.getFeedId(), resp.getErr() );
+
+ // we may have fnew already if located by FeedName
if ( fnew == null ) {
- logger.info( "Specified feed " + pub.getFeedId() + " not known to Bus Controller");
- return resp.error();
+ fnew = feeds.getFeed( pub.getFeedId(), resp.getErr() );
+ }
+ if ( fnew == null ) {
+ logger.info( "Specified feed " + pub.getFeedId() + " or " + pub.getFeedName() + " not known to Bus Controller");
+ return responseBuilder.error(resp.getErr());
}
ArrayList<DR_Pub> pubs = fnew.getPubs();
@@ -125,13 +145,13 @@ public class DR_PubResource extends BaseLoggingClass {
fnew = feeds.updateFeed( fnew, resp.getErr() );
if ( ! resp.getErr().is2xx()) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
pubs = fnew.getPubs();
logger.info( "num existing pubs after = " + pubs.size() );
DR_Pub pnew = dr_pubService.getDr_Pub(pub.getPubId(), resp.getErr());
- return resp.success(Status.CREATED.getStatusCode(), pnew);
+ return responseBuilder.success(Status.CREATED.getStatusCode(), pnew);
}
@PUT
@@ -147,12 +167,10 @@ public class DR_PubResource extends BaseLoggingClass {
@PathParam("pubId") String name,
DR_Pub pub
) {
- ApiService resp = new ApiService();
-
logger.info( "Entry: PUT /dr_pubs");
pub.setPubId(name);
DR_Pub res = dr_pubService.updateDr_Pub(pub);
- return resp.success(res);
+ return responseBuilder.success(res);
}
@DELETE
@@ -173,24 +191,24 @@ public class DR_PubResource extends BaseLoggingClass {
try {
resp.required( "pubId", id, "");
} catch ( RequiredFieldException rfe ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
DR_Pub pub = dr_pubService.getDr_Pub( id, resp.getErr() );
if ( ! resp.getErr().is2xx()) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
FeedService feeds = new FeedService();
Feed fnew = feeds.getFeed( pub.getFeedId(), resp.getErr() );
if ( fnew == null ) {
logger.info( "Specified feed " + pub.getFeedId() + " not known to Bus Controller");
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
ArrayList<DR_Pub> pubs = fnew.getPubs();
if ( pubs.size() == 1 ) {
resp.setCode(Status.BAD_REQUEST.getStatusCode());
resp.setMessage( "Can't delete the last publisher of a feed");
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
for( Iterator<DR_Pub> i = pubs.iterator(); i.hasNext(); ) {
@@ -202,14 +220,14 @@ public class DR_PubResource extends BaseLoggingClass {
fnew.setPubs(pubs);
fnew = feeds.updateFeed( fnew, resp.getErr() );
if ( ! resp.getErr().is2xx()) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
dr_pubService.removeDr_Pub(id, resp.getErr() );
if ( ! resp.getErr().is2xx()) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
- return resp.success(Status.NO_CONTENT.getStatusCode(), null);
+ return responseBuilder.success(Status.NO_CONTENT.getStatusCode(), null);
}
@GET
@@ -229,13 +247,13 @@ public class DR_PubResource extends BaseLoggingClass {
try {
resp.required( "feedId", id, "");
} catch ( RequiredFieldException rfe ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
DR_Pub pub = dr_pubService.getDr_Pub( id, resp.getErr() );
if ( ! resp.getErr().is2xx()) {
resp.getErr();
}
- return resp.success(Status.OK.getStatusCode(), pub);
+ return responseBuilder.success(Status.OK.getStatusCode(), pub);
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java
index 28bfdc5..01ac059 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/DR_SubResource.java
@@ -51,6 +51,8 @@ import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
+import static javax.ws.rs.core.Response.Status.CREATED;
+
@Path("/dr_subs")
@Api( value= "dr_subs", description = "Endpoint for a Data Router client that implements a Subscriber" )
@@ -58,6 +60,8 @@ import io.swagger.annotations.ApiResponses;
@Produces(MediaType.APPLICATION_JSON)
@Authorization
public class DR_SubResource extends BaseLoggingClass {
+
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
@GET
@ApiOperation( value = "return DR_Sub details",
@@ -68,15 +72,12 @@ public class DR_SubResource extends BaseLoggingClass {
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response getDr_Subs() {
-
- ApiService resp = new ApiService();
-
DR_SubService dr_subService = new DR_SubService();
List<DR_Sub> subs = dr_subService.getAllDr_Subs();
GenericEntity<List<DR_Sub>> list = new GenericEntity<List<DR_Sub>>(subs) {
};
- return resp.success(list);
+ return responseBuilder.success(list);
}
@POST
@@ -92,37 +93,54 @@ public class DR_SubResource extends BaseLoggingClass {
) {
ApiService resp = new ApiService();
-
+ FeedService feeds = new FeedService();
+ Feed fnew = null;
try {
resp.required( "feedId", sub.getFeedId(), "");
+ } catch ( RequiredFieldException rfe ) {
+ try {
+ resp.required( "feedName", sub.getFeedName(), "");
+ }catch ( RequiredFieldException rfe2 ) {
+ logger.debug( resp.toString() );
+ return responseBuilder.error(resp.getErr());
+ }
+ // if we found a FeedName instead of a FeedId then try to look it up.
+ List<Feed> nfeeds = feeds.getAllFeeds( sub.getFeedName(), sub.getFeedVersion(), "equals");
+ if ( nfeeds.size() != 1 ) {
+ logger.debug( "Attempt to match "+ sub.getFeedName() + " ver="+sub.getFeedVersion() + " matched " + nfeeds.size() );
+ return responseBuilder.error(resp.getErr());
+ }
+ fnew = nfeeds.get(0);
+ }
+
+ try {
resp.required( "dcaeLocationName", sub.getDcaeLocationName(), "");
-
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
-
- FeedService feeds = new FeedService();
- Feed fnew = feeds.getFeed( sub.getFeedId(), resp.getErr() );
+ // we may have fnew already if located by FeedName
if ( fnew == null ) {
- logger.warn( "Specified feed " + sub.getFeedId() + " not known to Bus Controller");
+ fnew = feeds.getFeed( sub.getFeedId(), resp.getErr() );
+ }
+ if ( fnew == null ) {
+ logger.warn( "Specified feed " + sub.getFeedId() + " or " + sub.getFeedName() + " not known to Bus Controller");
resp.setCode(Status.NOT_FOUND.getStatusCode());
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
-
DR_SubService dr_subService = new DR_SubService( fnew.getSubscribeURL());
ArrayList<DR_Sub> subs = fnew.getSubs();
logger.info( "num existing subs before = " + subs.size() );
DR_Sub snew = dr_subService.addDr_Sub(sub, resp.getErr() );
if ( ! resp.getErr().is2xx() ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
subs.add( snew );
logger.info( "num existing subs after = " + subs.size() );
fnew.setSubs(subs);
logger.info( "update feed");
- return resp.success(Status.CREATED.getStatusCode(), snew);
+ return responseBuilder.success(CREATED.getStatusCode(), snew);
}
@@ -149,22 +167,22 @@ public class DR_SubResource extends BaseLoggingClass {
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
FeedService feeds = new FeedService();
Feed fnew = feeds.getFeed( sub.getFeedId(), resp.getErr() );
if ( fnew == null ) {
logger.warn( "Specified feed " + sub.getFeedId() + " not known to Bus Controller");
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
-
+
DR_SubService dr_subService = new DR_SubService();
sub.setSubId(name);
DR_Sub nsub = dr_subService.updateDr_Sub(sub, resp.getErr() );
if ( nsub != null && nsub.isStatusValid() ) {
- return resp.success(nsub);
+ return responseBuilder.success(nsub);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@DELETE
@@ -186,14 +204,14 @@ public class DR_SubResource extends BaseLoggingClass {
resp.required( "subId", id, "");
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
DR_SubService dr_subService = new DR_SubService();
dr_subService.removeDr_Sub(id, resp.getErr() );
if ( ! resp.getErr().is2xx() ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
- return resp.success(Status.NO_CONTENT.getStatusCode(), null );
+ return responseBuilder.success(Status.NO_CONTENT.getStatusCode(), null );
}
@GET
@@ -214,13 +232,13 @@ public class DR_SubResource extends BaseLoggingClass {
resp.required( "subId", id, "");
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
DR_SubService dr_subService = new DR_SubService();
DR_Sub sub = dr_subService.getDr_Sub( id, resp.getErr() );
if ( sub != null && sub.isStatusValid() ) {
- return resp.success(sub);
+ return responseBuilder.success(sub);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/DcaeLocationResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/DcaeLocationResource.java
index 8cb5336..89c9b49 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/DcaeLocationResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/DcaeLocationResource.java
@@ -41,13 +41,14 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
-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.DcaeLocation;
-import org.onap.dmaap.dbcapi.service.ApiService;
import org.onap.dmaap.dbcapi.service.DcaeLocationService;
+import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+import static javax.ws.rs.core.Response.Status.NO_CONTENT;
+
@Path("/dcaeLocations")
@Api( value= "dcaeLocations", description = "an OpenStack tenant purposed for OpenDCAE (i.e. where OpenDCAE components might be deployed)" )
@@ -55,8 +56,8 @@ import org.onap.dmaap.dbcapi.service.DcaeLocationService;
@Produces(MediaType.APPLICATION_JSON)
@Authorization
public class DcaeLocationResource extends BaseLoggingClass {
- static final Logger logger = Logger.getLogger(DcaeLocationResource.class);
- DcaeLocationService locationService = new DcaeLocationService();
+ private DcaeLocationService locationService = new DcaeLocationService();
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
@GET
@ApiOperation( value = "return dcaeLocation details",
@@ -67,13 +68,10 @@ public class DcaeLocationResource extends BaseLoggingClass {
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response getDcaeLocations() {
- ApiService check = new ApiService();
-
List<DcaeLocation> locs = locationService.getAllDcaeLocations();
- GenericEntity<List<DcaeLocation>> list = new GenericEntity<List<DcaeLocation>>(locs) {
- };
- return check.success(list);
+ GenericEntity<List<DcaeLocation>> list = new GenericEntity<List<DcaeLocation>>(locs) {};
+ return responseBuilder.success(list);
}
@POST
@@ -84,22 +82,14 @@ public class DcaeLocationResource extends BaseLoggingClass {
@ApiResponse( code = 200, message = "Success", response = DcaeLocation.class),
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
- public Response addDcaeLocation(
- DcaeLocation location
- ) {
- ApiService check = new ApiService();
+ public Response addDcaeLocation(DcaeLocation location) {
if ( locationService.getDcaeLocation(location.getDcaeLocationName()) != null ) {
-
- check.setCode(Status.CONFLICT.getStatusCode());
- check.setMessage("dcaeLocation already exists");
- check.setFields("dcaeLocation");
-
- return check.error();
-
+ return responseBuilder.error(new ApiError(Status.CONFLICT.getStatusCode(),
+ "dcaeLocation already exists", "dcaeLocation"));
}
DcaeLocation loc = locationService.addDcaeLocation(location);
- return check.success(Status.CREATED.getStatusCode(), loc);
+ return responseBuilder.success(Status.CREATED.getStatusCode(), loc);
}
@PUT
@@ -112,25 +102,15 @@ public class DcaeLocationResource extends BaseLoggingClass {
})
@Path("/{locationName}")
public Response updateDcaeLocation(
- @PathParam("locationName") String name,
- DcaeLocation location
- ) {
- ApiService check = new ApiService();
+ @PathParam("locationName") String name, DcaeLocation location) {
location.setDcaeLocationName(name);
if ( locationService.getDcaeLocation(location.getDcaeLocationName()) == null ) {
- ApiError err = new ApiError();
-
- err.setCode(Status.NOT_FOUND.getStatusCode());
- err.setMessage("dcaeLocation does not exist");
- err.setFields("dcaeLocation");
-
- return check.notFound();
-
+ return responseBuilder.notFound();
}
DcaeLocation loc = locationService.updateDcaeLocation(location);
- return check.success(Status.CREATED.getStatusCode(), loc );
+ return responseBuilder.success(Status.CREATED.getStatusCode(), loc );
}
@DELETE
@@ -143,10 +123,8 @@ public class DcaeLocationResource extends BaseLoggingClass {
public Response deleteDcaeLocation(
@PathParam("locationName") String name
){
- ApiService check = new ApiService();
-
locationService.removeDcaeLocation(name);
- return check.success(Status.NO_CONTENT.getStatusCode(), null);
+ return responseBuilder.success(NO_CONTENT.getStatusCode(), null);
}
@GET
@@ -157,23 +135,19 @@ public class DcaeLocationResource extends BaseLoggingClass {
})
@Path("/{locationName}")
public Response getDcaeLocation(
- @PathParam("locationName") String name
- ) {
- ApiService check = new ApiService();
+ @PathParam("locationName") String name) {
DcaeLocation loc = locationService.getDcaeLocation( name );
if ( loc == null ) {
ApiError err = new ApiError();
- err.setCode(Status.NOT_FOUND.getStatusCode());
+ err.setCode(NOT_FOUND.getStatusCode());
err.setMessage("dcaeLocation does not exist");
err.setFields("dcaeLocation");
- return check.error();
-
-
+ return responseBuilder.error(err);
}
- return check.success(loc);
+ return responseBuilder.success(loc);
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/DmaapResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/DmaapResource.java
index bd30055..d7fb507 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/DmaapResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/DmaapResource.java
@@ -57,7 +57,8 @@ import org.onap.dmaap.dbcapi.service.DmaapService;
public class DmaapResource extends BaseLoggingClass {
- DmaapService dmaapService = new DmaapService();
+ private DmaapService dmaapService = new DmaapService();
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
@GET
@ApiOperation( value = "return dmaap details", notes = "returns the `dmaap` object, which contains system wide configuration settings", response = Dmaap.class)
@@ -67,10 +68,8 @@ public class DmaapResource extends BaseLoggingClass {
})
public Response getDmaap(@Context UriInfo uriInfo) {
- ApiService check = new ApiService();
-
Dmaap d = dmaapService.getDmaap();
- return check.success(d);
+ return responseBuilder.success(d);
}
@POST
@@ -88,16 +87,16 @@ public class DmaapResource extends BaseLoggingClass {
check.required( "topicNsRoot", obj.getTopicNsRoot(), "" );
check.required( "bridgeAdminTopic", obj.getBridgeAdminTopic(), "" );
} catch( RequiredFieldException rfe ) {
- return check.error();
+ return responseBuilder.error(check.getErr());
}
Dmaap d = dmaapService.addDmaap(obj);
if ( d == null ) {
- return check.notFound();
+ return responseBuilder.notFound();
}
- return check.success(d);
+ return responseBuilder.success(d);
}
@PUT
@@ -115,13 +114,13 @@ public class DmaapResource extends BaseLoggingClass {
check.required( "topicNsRoot", obj.getTopicNsRoot(), "" );
check.required( "bridgeAdminTopic", obj.getBridgeAdminTopic(), "" );
} catch( RequiredFieldException rfe ) {
- return check.error();
+ return responseBuilder.error(check.getErr());
}
Dmaap d = dmaapService.updateDmaap(obj);
if ( d != null ) {
- return check.success(d);
+ return responseBuilder.success(d);
} else {
- return check.notFound();
+ return responseBuilder.notFound();
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/FeedResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/FeedResource.java
index a7b4f73..382d88c 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/FeedResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/FeedResource.java
@@ -56,7 +56,9 @@ import org.onap.dmaap.dbcapi.service.FeedService;
@Produces(MediaType.APPLICATION_JSON)
@Authorization
public class FeedResource extends BaseLoggingClass {
-
+
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
+
@GET
@ApiOperation( value = "return Feed details",
notes = "Returns array of `Feed` objects.",
@@ -68,16 +70,13 @@ public class FeedResource extends BaseLoggingClass {
public Response getFeeds(
@QueryParam("feedName") String feedName,
@QueryParam("version") String version,
- @QueryParam("match") String match
- ) {
-
- ApiService resp = new ApiService();
+ @QueryParam("match") String match) {
FeedService feedService = new FeedService();
List<Feed> nfeeds = feedService.getAllFeeds( feedName, version, match );
GenericEntity<List<Feed>> list = new GenericEntity<List<Feed>>(nfeeds) {
};
- return resp.success(list);
+ return responseBuilder.success(list);
}
@@ -92,8 +91,7 @@ public class FeedResource extends BaseLoggingClass {
})
public Response addFeed(
@WebParam(name = "feed") Feed feed,
- @QueryParam("useExisting") String useExisting
- ) {
+ @QueryParam("useExisting") String useExisting) {
ApiService resp = new ApiService();
@@ -104,7 +102,7 @@ public class FeedResource extends BaseLoggingClass {
resp.required( "asprClassification", feed.getAsprClassification(), "" );
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@@ -113,28 +111,28 @@ public class FeedResource extends BaseLoggingClass {
if ( nfeed == null ) {
nfeed = feedService.addFeed( feed, resp.getErr() );
if ( nfeed != null ) {
- return resp.success(nfeed);
+ return responseBuilder.success(nfeed);
} else {
logger.error( "Unable to create: " + feed.getFeedName() + ":" + feed.getFeedVersion());
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
} else if ( nfeed.getStatus() == DmaapObject_Status.DELETED ) {
feed.setFeedId( nfeed.getFeedId());
nfeed = feedService.updateFeed(feed, resp.getErr());
if ( nfeed != null ) {
- return resp.success(nfeed);
+ return responseBuilder.success(nfeed);
} else {
logger.info( "Unable to update: " + feed.getFeedName() + ":" + feed.getFeedVersion());
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
} else if ( (useExisting != null) && ("true".compareToIgnoreCase( useExisting ) == 0)) {
- return resp.success(nfeed);
+ return responseBuilder.success(nfeed);
}
resp.setCode(Status.CONFLICT.getStatusCode());
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@PUT
@@ -148,8 +146,7 @@ public class FeedResource extends BaseLoggingClass {
@Path("/{id}")
public Response updateFeed(
@PathParam("id") String id,
- @WebParam(name = "feed") Feed feed
- ) {
+ @WebParam(name = "feed") Feed feed) {
FeedService feedService = new FeedService();
ApiService resp = new ApiService();
@@ -158,12 +155,12 @@ public class FeedResource extends BaseLoggingClass {
resp.required( "feedId", id, "");
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
Feed nfeed = feedService.getFeed( id, resp.getErr() );
if ( nfeed == null || nfeed.getStatus() == DmaapObject_Status.DELETED ) {
- return resp.notFound();
+ return responseBuilder.notFound();
}
// we assume there is no updates allowed for pubs and subs objects via this api...
@@ -174,11 +171,11 @@ public class FeedResource extends BaseLoggingClass {
nfeed = feedService.updateFeed(nfeed, resp.getErr());
if ( nfeed != null ) {
- return resp.success(nfeed);
+ return responseBuilder.success(nfeed);
} else {
logger.info( "Unable to update: " + feed.getFeedName() + ":" + feed.getFeedVersion());
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
}
@@ -201,15 +198,15 @@ public class FeedResource extends BaseLoggingClass {
Feed nfeed = feedService.getFeed( id, resp.getErr() );
if ( nfeed == null ) {
resp.setCode(Status.NOT_FOUND.getStatusCode());
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
nfeed = feedService.removeFeed( nfeed, resp.getErr() );
if ( nfeed == null || nfeed.getStatus() == DmaapObject_Status.DELETED ) {
- return resp.success(Status.NO_CONTENT.getStatusCode(), null);
+ return responseBuilder.success(Status.NO_CONTENT.getStatusCode(), null);
}
logger.info( "Unable to delete: " + id + ":" + nfeed.getFeedVersion());
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@GET
@@ -230,8 +227,8 @@ public class FeedResource extends BaseLoggingClass {
Feed nfeed = feedService.getFeed( id, resp.getErr() );
if ( nfeed == null ) {
resp.setCode(Status.NOT_FOUND.getStatusCode());
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
- return resp.success(nfeed);
+ return responseBuilder.success(nfeed);
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/InfoResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/InfoResource.java
index 31c22ba..bcb7ed2 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/InfoResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/InfoResource.java
@@ -32,8 +32,6 @@ import io.swagger.annotations.ApiResponses;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
-import javax.ws.rs.POST;
-import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
@@ -44,8 +42,6 @@ import javax.ws.rs.core.UriInfo;
import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
import org.onap.dmaap.dbcapi.model.ApiError;
import org.onap.dmaap.dbcapi.model.Dmaap;
-import org.onap.dmaap.dbcapi.service.ApiService;
-import org.onap.dmaap.dbcapi.service.DmaapService;
@@ -57,7 +53,7 @@ import org.onap.dmaap.dbcapi.service.DmaapService;
public class InfoResource extends BaseLoggingClass {
- DmaapService dmaapService = new DmaapService();
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
@GET
@ApiOperation( value = "return info details", notes = "returns the `info` object", response = Dmaap.class)
@@ -67,9 +63,7 @@ public class InfoResource extends BaseLoggingClass {
})
public Response getInfo(@Context UriInfo uriInfo) {
- ApiService check = new ApiService();
-
- return check.success(204, null);
+ return responseBuilder.success(204, null);
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/MR_ClientResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/MR_ClientResource.java
index a621338..a67ac8f 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/MR_ClientResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/MR_ClientResource.java
@@ -50,6 +50,8 @@ import org.onap.dmaap.dbcapi.service.MR_ClientService;
import org.onap.dmaap.dbcapi.service.MR_ClusterService;
import org.onap.dmaap.dbcapi.service.TopicService;
+import static javax.ws.rs.core.Response.Status.NO_CONTENT;
+
@Path("/mr_clients")
@Api( value= "MR_Clients", description = "Endpoint for a Message Router Client that implements a Publisher or a Subscriber" )
@@ -59,6 +61,7 @@ import org.onap.dmaap.dbcapi.service.TopicService;
public class MR_ClientResource extends BaseLoggingClass {
private MR_ClientService mr_clientService = new MR_ClientService();
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
@GET
@ApiOperation( value = "return MR_Client details",
@@ -69,13 +72,11 @@ public class MR_ClientResource extends BaseLoggingClass {
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response getMr_Clients() {
- ApiService resp = new ApiService();
-
List<MR_Client> clients = mr_clientService.getAllMr_Clients();
GenericEntity<List<MR_Client>> list = new GenericEntity<List<MR_Client>>(clients) {
};
- return resp.success(list);
+ return responseBuilder.success(list);
}
@POST
@@ -90,8 +91,7 @@ public class MR_ClientResource extends BaseLoggingClass {
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response addMr_Client(
- MR_Client client
- ) {
+ MR_Client client) {
ApiService resp = new ApiService();
try {
@@ -106,7 +106,7 @@ public class MR_ClientResource extends BaseLoggingClass {
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
MR_ClusterService clusters = new MR_ClusterService();
@@ -117,7 +117,7 @@ public class MR_ClientResource extends BaseLoggingClass {
resp.setMessage( "MR_Cluster alias not found for dcaeLocation: " + client.getDcaeLocationName());
resp.setFields("dcaeLocationName");
logger.warn( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
String url = cluster.getFqdn();
if ( url == null || url.isEmpty() ) {
@@ -126,22 +126,22 @@ public class MR_ClientResource extends BaseLoggingClass {
resp.setMessage("FQDN not set for dcaeLocation " + client.getDcaeLocationName() );
resp.setFields("fqdn");
logger.warn( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
TopicService topics = new TopicService();
Topic t = topics.getTopic(client.getFqtn(), resp.getErr() );
if ( t == null ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
MR_Client nClient = mr_clientService.addMr_Client(client, t, resp.getErr());
if ( resp.getErr().is2xx()) {
t = topics.getTopic(client.getFqtn(), resp.getErr());
topics.checkForBridge(t, resp.getErr());
- return resp.success(nClient);
+ return responseBuilder.success(nClient);
}
else {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
}
@@ -168,7 +168,7 @@ public class MR_ClientResource extends BaseLoggingClass {
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
client.setMrClientId(clientId);
MR_Client nClient = mr_clientService.updateMr_Client(client, resp.getErr() );
@@ -199,14 +199,14 @@ public class MR_ClientResource extends BaseLoggingClass {
resp.required( "clientId", id, "");
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
mr_clientService.removeMr_Client(id, true, resp.getErr() );
if ( resp.getErr().is2xx()) {
- return resp.success(Status.NO_CONTENT.getStatusCode(), null);
+ return responseBuilder.success(NO_CONTENT.getStatusCode(), null);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@GET
@@ -227,12 +227,12 @@ public class MR_ClientResource extends BaseLoggingClass {
resp.required( "clientId", id, "");
} catch ( RequiredFieldException rfe ) {
logger.debug( resp.toString() );
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
MR_Client nClient = mr_clientService.getMr_Client( id, resp.getErr() );
if ( resp.getErr().is2xx()) {
- return resp.success(nClient);
+ return responseBuilder.success(nClient);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResource.java
index 50ab4db..5d2d379 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/MR_ClusterResource.java
@@ -44,7 +44,6 @@ 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.service.ApiService;
-import org.onap.dmaap.dbcapi.service.MR_ClientService;
import org.onap.dmaap.dbcapi.service.MR_ClusterService;
@@ -55,8 +54,8 @@ import org.onap.dmaap.dbcapi.service.MR_ClusterService;
@Authorization
public class MR_ClusterResource extends BaseLoggingClass {
- MR_ClusterService mr_clusterService = new MR_ClusterService();
- MR_ClientService mr_clients = new MR_ClientService();
+ private MR_ClusterService mr_clusterService = new MR_ClusterService();
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
@GET
@ApiOperation( value = "return MR_Cluster details",
@@ -67,13 +66,11 @@ public class MR_ClusterResource extends BaseLoggingClass {
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response getMr_Clusters() {
- ApiService resp = new ApiService();
-
List<MR_Cluster> clusters = mr_clusterService.getAllMr_Clusters();
GenericEntity<List<MR_Cluster>> list = new GenericEntity<List<MR_Cluster>>(clusters) {
};
- return resp.success(list);
+ return responseBuilder.success(list);
}
@POST
@@ -85,21 +82,20 @@ public class MR_ClusterResource extends BaseLoggingClass {
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response addMr_Cluster(
- MR_Cluster cluster
- ) {
+ MR_Cluster cluster) {
ApiService resp = new ApiService();
try {
resp.required( "dcaeLocationName", cluster.getDcaeLocationName(), "" );
resp.required( "fqdn", cluster.getFqdn(), "" );
} catch( RequiredFieldException rfe ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
MR_Cluster mrc = mr_clusterService.addMr_Cluster(cluster, resp.getErr() );
if ( mrc != null && mrc.isStatusValid() ) {
- return resp.success(Status.CREATED.getStatusCode(), mrc);
+ return responseBuilder.success(Status.CREATED.getStatusCode(), mrc);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@@ -122,14 +118,14 @@ public class MR_ClusterResource extends BaseLoggingClass {
resp.required( "fqdn", clusterId, "" );
resp.required( "dcaeLocationName", cluster.getDcaeLocationName(), "" );
} catch( RequiredFieldException rfe ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
cluster.setDcaeLocationName(clusterId);
MR_Cluster mrc = mr_clusterService.updateMr_Cluster(cluster, resp.getErr() );
if ( mrc != null && mrc.isStatusValid() ) {
- return resp.success(Status.CREATED.getStatusCode(), mrc);
+ return responseBuilder.success(Status.CREATED.getStatusCode(), mrc);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@DELETE
@@ -149,13 +145,13 @@ public class MR_ClusterResource extends BaseLoggingClass {
try {
resp.required( "fqdn", id, "" );
} catch( RequiredFieldException rfe ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
mr_clusterService.removeMr_Cluster(id, resp.getErr() );
if ( resp.getErr().is2xx()) {
- return resp.success(Status.NO_CONTENT.getStatusCode(), null);
+ return responseBuilder.success(Status.NO_CONTENT.getStatusCode(), null);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
@GET
@@ -175,12 +171,12 @@ public class MR_ClusterResource extends BaseLoggingClass {
try {
resp.required( "dcaeLocationName", id, "" );
} catch( RequiredFieldException rfe ) {
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
MR_Cluster mrc = mr_clusterService.getMr_Cluster( id, resp.getErr() );
if ( mrc != null && mrc.isStatusValid() ) {
- return resp.success(Status.CREATED.getStatusCode(), mrc);
+ return responseBuilder.success(Status.CREATED.getStatusCode(), mrc);
}
- return resp.error();
+ return responseBuilder.error(resp.getErr());
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/ResponseBuilder.java b/src/main/java/org/onap/dmaap/dbcapi/resources/ResponseBuilder.java
new file mode 100644
index 0000000..5d78aaf
--- /dev/null
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/ResponseBuilder.java
@@ -0,0 +1,85 @@
+/*
+ * ============LICENSE_START=======================================================
+ * PNF-REGISTRATION-HANDLER
+ * ================================================================================
+ * Copyright (C) 2019 NOKIA Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+
+package org.onap.dmaap.dbcapi.resources;
+
+import org.onap.dmaap.dbcapi.logging.BaseLoggingClass;
+import org.onap.dmaap.dbcapi.model.ApiError;
+import org.slf4j.MDC;
+
+import javax.ws.rs.core.Response;
+
+import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_CODE;
+import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_DESC;
+import static com.att.eelf.configuration.Configuration.MDC_STATUS_CODE;
+import static javax.ws.rs.core.Response.Status.NOT_FOUND;
+import static javax.ws.rs.core.Response.Status.SERVICE_UNAVAILABLE;
+import static javax.ws.rs.core.Response.Status.UNAUTHORIZED;
+
+public class ResponseBuilder extends BaseLoggingClass {
+
+ Response success(Object d) {
+ return buildSuccessResponse(d, Response.Status.OK.getStatusCode());
+ }
+
+ Response success(int code, Object d) {
+ return buildSuccessResponse(d, code);
+ }
+
+ Response error(ApiError err) {
+ return buildErrResponse(err);
+ }
+
+ Response unauthorized(String msg) {
+ return buildErrResponse(new ApiError(UNAUTHORIZED.getStatusCode(), msg, "Authorization"));
+ }
+
+ Response unavailable() {
+ return buildErrResponse(new ApiError(SERVICE_UNAVAILABLE.getStatusCode(),
+ "Request is unavailable due to unexpected condition"));
+ }
+
+ Response notFound() {
+ return buildErrResponse(new ApiError(NOT_FOUND.getStatusCode(),"Requested object not found"));
+ }
+
+ private Response buildSuccessResponse(Object d, int code) {
+ MDC.put(MDC_STATUS_CODE, "COMPLETE");
+ MDC.put(MDC_RESPONSE_DESC, "");
+ return buildResponse(d, code);
+ }
+
+ private Response buildErrResponse(ApiError err) {
+ MDC.put(MDC_STATUS_CODE, "ERROR");
+ MDC.put(MDC_RESPONSE_DESC, err.getMessage());
+
+ return buildResponse(err, err.getCode());
+ }
+
+ private Response buildResponse(Object obj, int code) {
+ MDC.put(MDC_RESPONSE_CODE, String.valueOf(code));
+
+ auditLogger.auditEvent("");
+ return Response.status(code)
+ .entity(obj)
+ .build();
+ }
+}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java b/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java
index be1b3ac..4f442c9 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/resources/TopicResource.java
@@ -50,6 +50,8 @@ import org.onap.dmaap.dbcapi.service.ApiService;
import org.onap.dmaap.dbcapi.service.TopicService;
import org.onap.dmaap.dbcapi.util.DmaapConfig;
+import static javax.ws.rs.core.Response.Status.CREATED;
+
@Path("/topics")
@Api( value= "topics", description = "Endpoint for retreiving MR Topics" )
@Consumes(MediaType.APPLICATION_JSON)
@@ -59,7 +61,8 @@ public class TopicResource extends BaseLoggingClass {
private static FqtnType defaultTopicStyle;
private static String defaultPartitionCount;
private static String defaultReplicationCount;
- TopicService mr_topicService = new TopicService();
+ private TopicService mr_topicService = new TopicService();
+ private ResponseBuilder responseBuilder = new ResponseBuilder();
public TopicResource() {
DmaapConfig p = (DmaapConfig)DmaapConfig.getConfig();
@@ -79,14 +82,11 @@ public class TopicResource extends BaseLoggingClass {
@ApiResponse( code = 400, message = "Error", response = ApiError.class )
})
public Response getTopics() {
-
- ApiService check = new ApiService();
-
List<Topic> allTopics = mr_topicService.getAllTopics();
GenericEntity<List<Topic>> list = new GenericEntity<List<Topic>>(allTopics) {
};
- return check.success(list);
+ return responseBuilder.success(list);
}
@@ -114,7 +114,7 @@ public class TopicResource extends BaseLoggingClass {
check.required( "owner", topic.getOwner(), "" );
} catch( RequiredFieldException rfe ) {
logger.error("Error", rfe);
- return check.error();
+ return responseBuilder.error(check.getErr());
}
ReplicationType t = topic.getReplicationCase();
@@ -142,9 +142,9 @@ public class TopicResource extends BaseLoggingClass {
Topic mrc = mr_topicService.addTopic(topic, check.getErr(), flag);
if ( mrc != null && check.getErr().is2xx() ) {
- return check.success(Status.CREATED.getStatusCode(), mrc);
+ return responseBuilder.success(CREATED.getStatusCode(), mrc);
}
- return check.error();
+ return responseBuilder.error(check.getErr());
}
@PUT
@@ -164,7 +164,7 @@ public class TopicResource extends BaseLoggingClass {
check.setCode(Status.BAD_REQUEST.getStatusCode());
check.setMessage( "Method /PUT not supported for /topics");
- return check.error();
+ return responseBuilder.error(check.getErr());
}
@DELETE
@@ -185,14 +185,14 @@ public class TopicResource extends BaseLoggingClass {
check.required( "fqtn", id, "" );
} catch( RequiredFieldException rfe ) {
logger.error("Error", rfe);
- return check.error();
+ return responseBuilder.error(check.getErr());
}
mr_topicService.removeTopic(id, check.getErr());
if ( check.getErr().is2xx()) {
- return check.success(Status.NO_CONTENT.getStatusCode(), null);
+ return responseBuilder.success(Status.NO_CONTENT.getStatusCode(), null);
}
- return check.error();
+ return responseBuilder.error(check.getErr());
}
@@ -215,12 +215,12 @@ public class TopicResource extends BaseLoggingClass {
check.required( "topicName", id, "^\\S+$" ); //no white space allowed in topicName
} catch( RequiredFieldException rfe ) {
logger.error("Error", rfe);
- return check.error();
+ return responseBuilder.error(check.getErr());
}
Topic mrc = mr_topicService.getTopic( id, check.getErr() );
if ( mrc == null ) {
- return check.error();
+ return responseBuilder.error(check.getErr());
}
- return check.success(mrc);
+ return responseBuilder.success(mrc);
}
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/ApiService.java b/src/main/java/org/onap/dmaap/dbcapi/service/ApiService.java
index 6ae639d..23f4fef 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/service/ApiService.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/service/ApiService.java
@@ -25,10 +25,7 @@ import static com.att.eelf.configuration.Configuration.MDC_ELAPSED_TIME;
import static com.att.eelf.configuration.Configuration.MDC_END_TIMESTAMP;
import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
import static com.att.eelf.configuration.Configuration.MDC_PARTNER_NAME;
-import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_CODE;
-import static com.att.eelf.configuration.Configuration.MDC_RESPONSE_DESC;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
-import static com.att.eelf.configuration.Configuration.MDC_STATUS_CODE;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -36,7 +33,6 @@ import java.util.TimeZone;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
-import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;
import javax.xml.bind.DatatypeConverter;
@@ -165,6 +161,7 @@ public class ApiService extends BaseLoggingClass {
// test for presence of a required field
public void required( String name, Object val, String expr ) throws RequiredFieldException {
+ err.setCode(0);
if ( val == null ) {
err.setCode(Status.BAD_REQUEST.getStatusCode());
err.setMessage("missing required field");
@@ -190,7 +187,7 @@ public class ApiService extends BaseLoggingClass {
public void setCode(int statusCode) {
- err.setCode(statusCode);
+ err.setCode(statusCode);
}
@@ -202,63 +199,6 @@ public class ApiService extends BaseLoggingClass {
public void setFields(String string) {
err.setFields(string);
}
-
- private Response buildResponse( Object obj ) {
- stopwatch.stop();
- MDC.put( MDC_RESPONSE_CODE, String.valueOf(err.getCode()) );
-
- auditLogger.auditEvent( "" );
- return Response.status( err.getCode())
- .entity(obj)
- .build();
- }
- private Response buildSuccessResponse(Object d) {
- MDC.put( MDC_STATUS_CODE, "COMPLETE");
- MDC.put( MDC_RESPONSE_DESC, "");
- return buildResponse( d );
- }
- private Response buildErrResponse() {
-
- MDC.put( MDC_STATUS_CODE, "ERROR");
- MDC.put( MDC_RESPONSE_DESC, err.getMessage());
-
- return buildResponse(getErr());
- }
- public Response success( Object d ) {
- err.setCode(Status.OK.getStatusCode());
- return buildSuccessResponse(d);
-
- }
- public Response success( int code, Object d ) {
- err.setCode(code);
- return buildSuccessResponse(d);
- }
-
- public Response unauthorized( String msg ) {
- err.setCode(Status.UNAUTHORIZED.getStatusCode());
- err.setFields( "Authorization");
- err.setMessage( msg );
- return buildErrResponse();
- }
- public Response unauthorized() {
- err.setCode(Status.UNAUTHORIZED.getStatusCode());
- err.setFields( "Authorization");
- err.setMessage( "User credentials in HTTP Header field Authorization are not authorized for the requested action");
- return buildErrResponse();
- }
- public Response unavailable() {
- err.setCode(Status.SERVICE_UNAVAILABLE.getStatusCode());
- err.setMessage( "Request is unavailable due to unexpected condition");
- return buildErrResponse();
- }
- public Response notFound() {
- err.setCode(Status.NOT_FOUND.getStatusCode());
- err.setMessage( "Requested object not found");
- return buildErrResponse();
- }
- public Response error() {
- return buildErrResponse();
- }
public void checkAuthorization( String auth, String uriPath, String httpMethod ) throws AuthenticationErrorException, Exception {
authorization = auth;
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 99c8f31..9d233a5 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
@@ -98,7 +98,7 @@ public class DR_SubService extends BaseLoggingClass {
String resp = prov.doPostDr_Sub( sub, apiError );
if ( "Yes".equals(unit_test) ) {
resp = simulateResp( sub, "POST" );
- apiError.setCode(200);
+ apiError.setCode(201);
}
logger.debug( "addDr_Sub resp=" + resp );
@@ -110,7 +110,7 @@ public class DR_SubService extends BaseLoggingClass {
snew.setLastMod();
addEgressRoute( snew, apiError );
dr_subs.put( snew.getSubId(), snew );
- apiError.setCode(200);
+ apiError.setCode(201);
} else {
apiError.setCode(400);
}
diff --git a/src/main/java/org/onap/dmaap/dbcapi/service/TopicService.java b/src/main/java/org/onap/dmaap/dbcapi/service/TopicService.java
index eeffa5b..c5937f4 100644
--- a/src/main/java/org/onap/dmaap/dbcapi/service/TopicService.java
+++ b/src/main/java/org/onap/dmaap/dbcapi/service/TopicService.java
@@ -42,7 +42,6 @@ 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.DcaeLocation;
-import org.onap.dmaap.dbcapi.model.Dmaap;
import org.onap.dmaap.dbcapi.model.DmaapObject.DmaapObject_Status;
import org.onap.dmaap.dbcapi.model.MR_Client;
import org.onap.dmaap.dbcapi.model.MR_Cluster;
@@ -70,6 +69,7 @@ public class TopicService extends BaseLoggingClass {
private static String centralCname;
private static boolean createTopicRoles;
+ private boolean strictGraph = true;
public TopicService(){
@@ -77,8 +77,10 @@ public class TopicService extends BaseLoggingClass {
defaultGlobalMrHost = p.getProperty("MR.globalHost", "global.host.not.set");
centralCname = p.getProperty("MR.CentralCname");
createTopicRoles = "true".equalsIgnoreCase(p.getProperty("aaf.CreateTopicRoles", "true"));
-
-
+ String unit_test = p.getProperty( "UnitTest", "No" );
+ if ( unit_test.equals( "Yes" ) ) {
+ strictGraph = false;
+ }
logger.info( "TopicService properties: CentralCname=" + centralCname +
" defaultGlobarlMrHost=" + defaultGlobalMrHost +
" createTopicRoles=" + createTopicRoles );
@@ -299,10 +301,13 @@ public class TopicService extends BaseLoggingClass {
public Topic updateTopic( Topic topic, ApiError err ) {
- logger.info( "Entry: updateTopic");
+ logger.info( "updateTopic: entry");
+ logger.info( "updateTopic: topic=" + topic);
+ logger.info( "updateTopic: fqtn=" + topic.getFqtn() );
if ( topic.getFqtn().isEmpty()) {
return null;
}
+ logger.info( "updateTopic: call checkForBridge");
Topic ntopic = checkForBridge( topic, err );
if ( ntopic == null ) {
topic.setStatus( DmaapObject_Status.INVALID);
@@ -311,6 +316,7 @@ public class TopicService extends BaseLoggingClass {
}
}
if(ntopic != null) {
+ logger.info( "updateTopic: call put");
mr_topics.put( ntopic.getFqtn(), ntopic );
}
err.setCode(Status.OK.getStatusCode());
@@ -374,7 +380,8 @@ public class TopicService extends BaseLoggingClass {
public Topic checkForBridge( Topic topic, ApiError err ) {
-
+ logger.info( "checkForBridge: entry");
+ logger.info( "fqtn=" + topic.getFqtn() + "replicatonType=" + topic.getReplicationCase());
if ( topic.getReplicationCase() == ReplicationType.REPLICATION_NONE ) {
topic.setStatus( DmaapObject_Status.VALID);
return topic;
@@ -384,6 +391,7 @@ public class TopicService extends BaseLoggingClass {
Set<String> groups = clusters.getGroups();
for ( String g : groups ) {
+ logger.info( "buildBridge for " + topic.getFqtn() + " on group" + g);
anythingWrong |= buildBridge( topic, err, g );
}
if ( anythingWrong ) {
@@ -398,19 +406,24 @@ public class TopicService extends BaseLoggingClass {
}
private boolean buildBridge( Topic topic, ApiError err, String group ) {
-
+ logger.info( "buildBridge: entry");
boolean anythingWrong = false;
Graph graph;
+ logger.info( "buildBridge: strictGraph=" + strictGraph );
if ( group == null || group.isEmpty() ) {
- graph = new Graph( topic.getClients(), true );
+ graph = new Graph( topic.getClients(), strictGraph );
} else {
- graph = new Graph( topic.getClients(), true, group );
+ graph = new Graph( topic.getClients(), strictGraph, group );
}
+ logger.info( "buildBridge: graph=" + graph );
MR_Cluster groupCentralCluster = null;
+
if ( graph.isEmpty() ) {
+ logger.info( "buildBridge: graph is empty. return false" );
return false;
} else if ( group == null && topic.getReplicationCase().involvesFQDN() ) {
+ logger.info( "buildBridge: group is null and replicationCaseInvolvesFQDN. return false" );
return false;
} else if ( ! graph.hasCentral() ) {
logger.warn( "Topic " + topic.getFqtn() + " wants to be " + topic.getReplicationCase() + " but has no central clients");