aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/dmaapbc/service/DR_SubService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openecomp/dmaapbc/service/DR_SubService.java')
-rw-r--r--src/main/java/org/openecomp/dmaapbc/service/DR_SubService.java96
1 files changed, 64 insertions, 32 deletions
diff --git a/src/main/java/org/openecomp/dmaapbc/service/DR_SubService.java b/src/main/java/org/openecomp/dmaapbc/service/DR_SubService.java
index a360cff..f2fc99d 100644
--- a/src/main/java/org/openecomp/dmaapbc/service/DR_SubService.java
+++ b/src/main/java/org/openecomp/dmaapbc/service/DR_SubService.java
@@ -26,38 +26,36 @@ import java.util.Map;
import javax.ws.rs.core.Response.Status;
-import org.apache.log4j.Logger;
import org.openecomp.dmaapbc.client.DrProvConnection;
import org.openecomp.dmaapbc.database.DatabaseClass;
+import org.openecomp.dmaapbc.logging.BaseLoggingClass;
+import org.openecomp.dmaapbc.logging.DmaapbcLogMessageEnum;
import org.openecomp.dmaapbc.model.ApiError;
-import org.openecomp.dmaapbc.model.DR_Pub;
import org.openecomp.dmaapbc.model.DR_Sub;
-import org.openecomp.dmaapbc.model.Feed;
-public class DR_SubService {
- static final Logger logger = Logger.getLogger(DR_SubService.class);
+public class DR_SubService extends BaseLoggingClass {
+
private Map<String, DR_Sub> dr_subs = DatabaseClass.getDr_subs();
+ private DR_NodeService nodeService = new DR_NodeService();
private String provURL;
- //private DrProvConnection prov;
+ private static DrProvConnection prov;
+
public DR_SubService( ) {
- logger.info( "Entry: DR_SubService (with no args)" );
-// prov = new DrProvConnection();
+ logger.debug( "Entry: DR_SubService (with no args)" );
}
public DR_SubService( String subURL ) {
- logger.info( "Entry: DR_SubService " + subURL );
+ logger.debug( "Entry: DR_SubService " + subURL );
provURL = subURL;
-// prov = new DrProvConnection();
-// prov.makeSubConnection( subURL );
}
public Map<String, DR_Sub> getDR_Subs() {
- logger.info( "enter getDR_Subs()");
+ logger.debug( "enter getDR_Subs()");
return dr_subs;
}
public List<DR_Sub> getAllDr_Subs() {
- logger.info( "enter getAllDR_Subs()");
+ logger.debug( "enter getAllDR_Subs()");
return new ArrayList<DR_Sub>(dr_subs.values());
}
@@ -72,7 +70,7 @@ public class DR_SubService {
return someSubs;
}
public DR_Sub getDr_Sub( String key, ApiError apiError ) {
- logger.info( "enter getDR_Sub()");
+ logger.debug( "enter getDR_Sub()");
DR_Sub sub = dr_subs.get( key );
if ( sub == null ) {
apiError.setCode(Status.NOT_FOUND.getStatusCode());
@@ -85,11 +83,11 @@ public class DR_SubService {
}
public DR_Sub addDr_Sub( DR_Sub sub, ApiError apiError ) {
- logger.info( "enter addDR_Subs()");
- DrProvConnection prov = new DrProvConnection();
- prov.makeSubConnection( provURL );
- String resp = prov.doPostDr_Sub( sub );
- logger.info( "resp=" + resp );
+ logger.debug( "enter addDR_Subs()");
+ prov = new DrProvConnection();
+ prov.makeSubPostConnection( provURL );
+ String resp = prov.doPostDr_Sub( sub, apiError );
+ logger.debug( "resp=" + resp );
DR_Sub snew = null;
@@ -97,6 +95,7 @@ public class DR_SubService {
snew = new DR_Sub( resp );
snew.setDcaeLocationName(sub.getDcaeLocationName());
snew.setLastMod();
+ addEgressRoute( snew, apiError );
dr_subs.put( snew.getSubId(), snew );
apiError.setCode(200);
} else {
@@ -106,25 +105,58 @@ public class DR_SubService {
return snew;
}
+ private void addEgressRoute( DR_Sub sub, ApiError err ) {
+ String nodePattern = nodeService.getNodePatternAtLocation( sub.getDcaeLocationName(), false );
+ if ( nodePattern != null && nodePattern.length() > 0 ) {
+ logger.info( "creating egress rule: sub " + sub.getSubId() + " on feed " + sub.getFeedId() + " to " + nodePattern);
+ prov.makeEgressConnection( sub.getSubId(), nodePattern);
+ int rc = prov.doXgressPost(err);
+ logger.info( "rc=" + rc + " error code=" + err.getCode() );
+
+ if ( rc != 200 ) {
+ switch( rc ) {
+ case 403:
+ logger.error( "Not authorized for DR egress API");
+ err.setCode(500);
+ err.setMessage("API deployment/configuration error - contact support");
+ err.setFields( "PROV_AUTH_ADDRESSES");
+ break;
+
+ default:
+ logger.info( DmaapbcLogMessageEnum.EGRESS_CREATE_ERROR, Integer.toString(rc), sub.getSubId(), sub.getFeedId(), nodePattern);
+ }
+ }
+
+ }
+ }
+
public DR_Sub updateDr_Sub( DR_Sub obj, ApiError apiError ) {
- logger.info( "enter updateDR_Subs()");
+ logger.debug( "enter updateDR_Subs()");
- DR_Sub sub = dr_subs.get( obj.getSubId() );
- if ( sub == null ) {
- apiError.setCode(Status.NOT_FOUND.getStatusCode());
- apiError.setFields( "subId");
- apiError.setMessage("subId " + obj.getSubId() + " not found");
- return null;
- }
- sub.setLastMod();
- dr_subs.put( sub.getSubId(), sub );
- apiError.setCode(200);
- return sub;
+ DrProvConnection prov = new DrProvConnection();
+ prov.makeSubPutConnection( obj.getSubId() );
+ String resp = prov.doPutDr_Sub( obj, apiError );
+ logger.debug( "resp=" + resp );
+
+ DR_Sub snew = null;
+
+ if ( resp != null ) {
+ snew = new DR_Sub( resp );
+ snew.setDcaeLocationName(obj.getDcaeLocationName());
+ snew.setLastMod();
+ dr_subs.put( snew.getSubId(), snew );
+ apiError.setCode(200);
+ } else if ( apiError.is2xx()) {
+ apiError.setCode(400);
+ apiError.setMessage("unexpected empty response from DR Prov");
+ }
+
+ return snew;
}
public void removeDr_Sub( String key, ApiError apiError ) {
- logger.info( "enter removeDR_Subs()");
+ logger.debug( "enter removeDR_Subs()");
DR_Sub sub = dr_subs.get( key );
if ( sub == null ) {
apiError.setCode(Status.NOT_FOUND.getStatusCode());