aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openecomp/dmaapbc/service/DR_NodeService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/openecomp/dmaapbc/service/DR_NodeService.java')
-rw-r--r--src/main/java/org/openecomp/dmaapbc/service/DR_NodeService.java139
1 files changed, 135 insertions, 4 deletions
diff --git a/src/main/java/org/openecomp/dmaapbc/service/DR_NodeService.java b/src/main/java/org/openecomp/dmaapbc/service/DR_NodeService.java
index c1e36aa..f791896 100644
--- a/src/main/java/org/openecomp/dmaapbc/service/DR_NodeService.java
+++ b/src/main/java/org/openecomp/dmaapbc/service/DR_NodeService.java
@@ -27,13 +27,109 @@ 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.model.ApiError;
import org.openecomp.dmaapbc.model.DR_Node;
import org.openecomp.dmaapbc.model.DmaapObject.DmaapObject_Status;
-public class DR_NodeService {
- static final Logger logger = Logger.getLogger(DR_NodeService.class);
+public class DR_NodeService extends BaseLoggingClass {
+ private class DrProv {
+ String currentNodes;
+ String currentStaticNodes;
+
+ private String getX( String X, ApiError apiError ) {
+
+ DrProvConnection prov = new DrProvConnection();
+ prov.makeNodesConnection( X );
+ String resp = prov.doGetNodes( apiError );
+ logger.info( "rc=" + apiError.getCode() );
+ return resp;
+ }
+
+ private void setX( String X, String list, ApiError apiError ) {
+ DrProvConnection prov = new DrProvConnection();
+ prov.makeNodesConnection( X, list );
+ String resp = prov.doPutNodes( apiError );
+ }
+
+ private String removeFromList( String aNode, String aList ) {
+ String[] nodeList = aList.split("\\|");
+ StringBuilder res = new StringBuilder();
+ for ( String n: nodeList ) {
+ logger.info( "compare existing node " + n + " vs " + aNode );
+ if ( ! n.equals(aNode)) {
+ if (res.length() > 0 ) {
+ res.append( "|" );
+ }
+ res.append(n);
+ }
+ }
+ logger.info( "result=" + res.toString() );
+ return res.toString();
+ }
+
+ boolean containsNode( String aNode , ApiError apiError ){
+
+ //DrProvConnection prov = new DrProvConnection();
+ //prov.makeNodesConnection();
+ currentNodes = getX( "NODES", apiError );
+ if ( ! apiError.is2xx() || currentNodes == null ) {
+ return false;
+ }
+ logger.info( "NODES now=" + currentNodes );
+ String[] nodeList = currentNodes.split("\\|");
+ for( String n: nodeList ) {
+ logger.info( "compare existing node " + n + " vs " + aNode );
+ if ( n.equals(aNode) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ void addNode( String aNode, ApiError apiError ) {
+
+ currentNodes = currentNodes + "|" + aNode;
+ setX( "NODES", currentNodes, apiError );
+
+
+ }
+ void removeNode( String aNode, ApiError apiError ) {
+ currentNodes = removeFromList( aNode, currentNodes );
+ setX( "NODES", currentNodes, apiError );
+ }
+
+ public boolean containsStaticNode(String aNode, ApiError apiError) {
+
+ //DrProvConnection prov = new DrProvConnection();
+ //prov.makeNodesConnection();
+ currentStaticNodes = getX( "STATIC_ROUTING_NODES", apiError );
+ if (! apiError.is2xx() || currentStaticNodes == null ) {
+ return false;
+ }
+ logger.info( "STATIC_ROUTING_NODES now=" + currentNodes );
+ String[] nodeList = currentStaticNodes.split("\\|");
+ for( String n: nodeList ) {
+ logger.info( "compare existing node " + n + " vs " + aNode );
+ if ( n.equals(aNode) ) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+
+ public void addStaticNode(String aNode, ApiError apiError) {
+ currentStaticNodes = currentStaticNodes + "|" + aNode;
+ setX( "STATIC_ROUTING_NODES", currentStaticNodes, apiError );
+ }
+ void removeStaticNode( String aNode, ApiError apiError ) {
+ currentStaticNodes = removeFromList( aNode, currentStaticNodes );
+ setX( "STATIC_ROUTING_NODES", currentStaticNodes, apiError );
+ }
+ }
private Map<String, DR_Node> dr_nodes = DatabaseClass.getDr_nodes();
public Map<String, DR_Node> getDr_Nodes() {
@@ -65,6 +161,25 @@ public class DR_NodeService {
apiError.setMessage( "Node " + fqdn + " already exists");
return null;
}
+
+ DrProv drProv = new DrProv();
+
+ if ( ! drProv.containsNode( node.getFqdn(), apiError ) && apiError.is2xx() ) {
+ drProv.addNode( node.getFqdn(), apiError );
+ }
+ if ( ! apiError.is2xx()) {
+ return null;
+ }
+ DcaeLocationService locService = new DcaeLocationService();
+ if ( locService.isEdgeLocation( node.getDcaeLocationName()) && ! drProv.containsStaticNode( node.getFqdn(), apiError ) ) {
+ if ( apiError.is2xx() ) {
+ drProv.addStaticNode( node.getFqdn(), apiError );
+ }
+ }
+ if ( ! apiError.is2xx()) {
+ return null;
+ }
+
node.setLastMod();
node.setStatus(DmaapObject_Status.VALID);
dr_nodes.put( node.getFqdn(), node );
@@ -94,11 +209,24 @@ public class DR_NodeService {
apiError.setMessage( "Node " + nodeName + " does not exist");
return null;
}
+
+ DrProv drProv = new DrProv();
+ if ( drProv.containsNode( old.getFqdn(), apiError ) && apiError.is2xx() ) {
+ drProv.removeNode( old.getFqdn(), apiError );
+ }
+ DcaeLocationService locService = new DcaeLocationService();
+ if ( locService.isEdgeLocation( old.getDcaeLocationName()) && drProv.containsStaticNode( old.getFqdn(), apiError ) ) {
+ if ( apiError.is2xx()) {
+ drProv.removeStaticNode( old.getFqdn(), apiError );
+ }
+
+ }
+
apiError.setCode(200);
return dr_nodes.remove(nodeName);
- }
+ }
- public String getNodePatternAtLocation( String loc ) {
+ public String getNodePatternAtLocation( String loc, boolean allowMult ) {
logger.info( "loc=" + loc );
if ( loc == null ) {
return null;
@@ -110,6 +238,9 @@ public class DR_NodeService {
str.append( ",");
}
str.append( node.getFqdn());
+ if ( ! allowMult ) {
+ break;
+ }
}
}
logger.info( "returning " + str.toString() );