Updated SDC listener and dependent bundles
[appc.git] / appc-sdc-listener / appc-sdc-listener-bundle / src / main / java / org / onap / appc / sdc / listener / SdcConfig.java
index 86ba9e1..2acb2e6 100644 (file)
@@ -34,6 +34,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Properties;
+import org.apache.commons.lang.StringUtils;
 
 public class SdcConfig implements IConfiguration {
 
@@ -50,11 +51,8 @@ public class SdcConfig implements IConfiguration {
     private List<String> types = new ArrayList<>();
     private String user;
     private String pass;
-
     private URI storeOp;
-
     private Properties props;
-
     private final EELFLogger logger = EELFManager.getInstance().getLogger(SdcConfig.class);
 
     SdcConfig(Properties props) throws Exception {
@@ -67,7 +65,6 @@ public class SdcConfig implements IConfiguration {
             logger.error("SdcConfig init is skipped due to properties is null");
             return;
         }
-
         // Keystore for ca cert
         keystorePath = props.getProperty("appc.sdc.keystore.path");
         keystorePass = props.getProperty("appc.sdc.keystore.pass");
@@ -181,6 +178,31 @@ public class SdcConfig implements IConfiguration {
         return  true;
     }
 
+    @Override
+    public  List <String> getMsgBusAddress() {
+        return (getMsgBusProperties());
+    }
+
+    public List<String> getMsgBusProperties() {
+        List<String> uebAddresses = new ArrayList<String>();
+        String uebAddressesList=null;
+        if (null != this.props)
+            uebAddressesList = this.props.getProperty("appc.ClosedLoop.poolMembers");
+        else {
+            logger.info("SdcConfig:SdcConfig:getMsgBusProperties()::props is null for SdcConfig");
+            return null;
+        }
+        if (null == uebAddressesList) {
+            logger.info("SdcConfig:SdcConfig:getMsgBusProperties()::uebAddressesList is null for SdcConfig");
+            return null;
+        }
+        logger.debug("SdcConfig:SdcConfig:getMsgBusProperties()::uebAddressesList is="+ uebAddressesList);
+        String[] sList = uebAddressesList.split(",");
+        uebAddresses= formatAddresses(sList);
+        logger.debug("SdcConfig:getMsgBusProperties:::Returning addresses as "+uebAddresses.toString());
+        return uebAddresses;
+    }
+
     URI getStoreOpURI() {
         return storeOp;
     }
@@ -199,4 +221,19 @@ public class SdcConfig implements IConfiguration {
 
         logger.info(String.format("SDC Params: %s", params));
     }
+
+    protected List<String> formatAddresses(String[] sList) {
+        List<String> uebAddresses = new ArrayList<String>();
+        for (String fqdnPort:sList) {
+            if (fqdnPort.startsWith("http")) {
+                fqdnPort=StringUtils.substringAfter(fqdnPort, "://");
+            }
+            if (null != fqdnPort && fqdnPort.contains(":")) {
+                fqdnPort=StringUtils.substringBefore(fqdnPort,":");
+            }
+            logger.debug("SdcConfig:formatAddresses:: "+fqdnPort);
+            uebAddresses.add(fqdnPort);
+        }
+        return uebAddresses;
+    }
 }