Repository: stratos Updated Branches: refs/heads/tenant-isolation c2abc57af -> 260f738b5
Adding DAS thrift configuratio to thrift-client-config.xml Project: http://git-wip-us.apache.org/repos/asf/stratos/repo Commit: http://git-wip-us.apache.org/repos/asf/stratos/commit/78da0efa Tree: http://git-wip-us.apache.org/repos/asf/stratos/tree/78da0efa Diff: http://git-wip-us.apache.org/repos/asf/stratos/diff/78da0efa Branch: refs/heads/tenant-isolation Commit: 78da0efa339ae2e7e51857d3196471eb1be4d949 Parents: 02eafdf Author: Thanuja <[email protected]> Authored: Wed Aug 19 10:13:19 2015 +0530 Committer: Thanuja <[email protected]> Committed: Fri Aug 21 16:20:31 2015 +0530 ---------------------------------------------------------------------- .../publisher/ThriftClientConfig.java | 34 +++++++-- .../publisher/ThriftClientConfigParser.java | 77 ++++++++++++++------ .../publisher/ThriftStatisticsPublisher.java | 9 ++- .../cep/WSO2CEPHealthStatisticsPublisher.java | 3 +- .../cep/WSO2CEPInFlightRequestPublisher.java | 3 +- .../test/ThriftClientConfigParserTest.java | 18 +++-- .../src/test/resources/thrift-client-config.xml | 20 +++-- products/stratos/conf/thrift-client-config.xml | 20 +++-- 8 files changed, 133 insertions(+), 51 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/stratos/blob/78da0efa/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfig.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfig.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfig.java index 25ee897..7f6d8c4 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfig.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfig.java @@ -28,9 +28,11 @@ import org.apache.commons.lang.StringUtils; public class ThriftClientConfig { public static final String THRIFT_CLIENT_CONFIG_FILE_PATH = "thrift.client.config.file.path"; + public static final String CEP_THRIFT_CLIENT_NAME = "cep"; + public static final String DAS_THRIFT_CLIENT_NAME = "das"; private static volatile ThriftClientConfig instance; - private ThriftClientInfo thriftClientInfo; + private ThriftClientInfo cepThriftClientInfo, dasThriftClientInfo; /* * A private Constructor prevents any other @@ -63,19 +65,37 @@ public class ThriftClientConfig { * <p/> * This method is used to return the assigned values in ThriftClientInfo Object * + * @param thriftClientName Thrift Client Name * @return ThriftClientInfo object which consists of username,password,ip and port values */ - public ThriftClientInfo getThriftClientInfo() { - return thriftClientInfo; + public ThriftClientInfo getThriftClientInfo(String thriftClientName) { + if (CEP_THRIFT_CLIENT_NAME.equals(thriftClientName)) { + return cepThriftClientInfo; + } else if (DAS_THRIFT_CLIENT_NAME.equals(thriftClientName)) { + return dasThriftClientInfo; + } + return null; } /** - * Parsed values will be assigned to ThriftClientInfo object. Required fields will be taken + * Parsed values will be assigned to dasThriftClientInfo object. Required fields will be taken * from thrift-client-config.xml file. * - * @param thriftClientInfo Object of the ThriftClientInfo + * @param thriftClientInfo DAS Thrift Client Information */ - public void setThriftClientInfo(ThriftClientInfo thriftClientInfo) { - this.thriftClientInfo = thriftClientInfo; + + public void setDASThriftClientInfo(ThriftClientInfo thriftClientInfo) { + this.dasThriftClientInfo = thriftClientInfo; + } + + /** + * Parsed values will be assigned to cepThriftClientInfo object. Required fields will be taken + * from thrift-client-config.xml file. + * + * @param thriftClientInfo CEP Thrift Client Information + */ + + public void setCEPThriftClientInfo(ThriftClientInfo thriftClientInfo) { + this.cepThriftClientInfo = thriftClientInfo; } } http://git-wip-us.apache.org/repos/asf/stratos/blob/78da0efa/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfigParser.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfigParser.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfigParser.java index aa05d6f..e2684ac 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfigParser.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfigParser.java @@ -39,11 +39,15 @@ public class ThriftClientConfigParser { /** * Fields to be read from the thrift-client-config.xml file */ + private static final String NAME_ELEMENT = "name"; private static final String USERNAME_ELEMENT = "username"; private static final String PASSWORD_ELEMENT = "password"; private static final String IP_ELEMENT = "ip"; private static final String PORT_ELEMENT = "port"; + private static final String CEP_NAME_ELEMENT = "cep"; + private static final String DAS_NAME_ELEMENT = "das"; + /** * This method reads thrift-client-config.xml file and assign necessary credential * values into thriftClientInfo object. A singleton design has been implemented @@ -61,8 +65,8 @@ public class ThriftClientConfigParser { } ThriftClientConfig thriftClientIConfig = new ThriftClientConfig(); - ThriftClientInfo thriftClientInfo = new ThriftClientInfo(); - thriftClientIConfig.setThriftClientInfo(thriftClientInfo); + ThriftClientInfo cepThriftClientInfo = new ThriftClientInfo(); + ThriftClientInfo dasThriftClientInfo = new ThriftClientInfo(); File configFile = new File(filePath); if (!configFile.exists()) { @@ -74,6 +78,7 @@ public class ThriftClientConfigParser { //Initialize the SecretResolver providing the configuration element. SecretResolver secretResolver = SecretResolverFactory.create(document, false); + String nameValuesStr = null; String userNameValuesStr = null; String passwordValueStr = null; String ipValuesStr = null; @@ -85,36 +90,57 @@ public class ThriftClientConfigParser { // Iterate the thrift-client-config.xml file and read child element // consists of credential information necessary for ThriftStatisticsPublisher while (thriftClientIterator.hasNext()) { - OMElement thriftClientElement = (OMElement) thriftClientIterator.next(); + OMElement thriftClientConfig = (OMElement) thriftClientIterator.next(); + Iterator thriftClientConfigIterator = thriftClientConfig.getChildElements(); + ThriftClientInfo thriftClientInfo = new ThriftClientInfo(); + log.info("Client Config: " + thriftClientConfigIterator.toString()); + + while (thriftClientConfigIterator.hasNext()) { + OMElement thriftClientConfigElement = (OMElement) thriftClientConfigIterator.next(); + log.info("Client Config Element: " + thriftClientConfigElement); + + if (NAME_ELEMENT.equals(thriftClientConfigElement.getQName().getLocalPart())) { + nameValuesStr = thriftClientConfigElement.getText(); + if (CEP_NAME_ELEMENT.equals(nameValuesStr)) { + cepThriftClientInfo = thriftClientInfo; + } else if (DAS_NAME_ELEMENT.equals(nameValuesStr)) { + dasThriftClientInfo = thriftClientInfo; + } + } - if (USERNAME_ELEMENT.equals(thriftClientElement.getQName().getLocalPart())) { - userNameValuesStr = thriftClientElement.getText(); - thriftClientInfo.setUsername(userNameValuesStr); - } - //password field protected using Secure vault - if (PASSWORD_ELEMENT.equals(thriftClientElement.getQName().getLocalPart())) { - if ((secretResolver != null) && (secretResolver.isInitialized())) { - if (secretResolver.isTokenProtected(secretAlias)) { - passwordValueStr = secretResolver.resolve(secretAlias); + if (USERNAME_ELEMENT.equals(thriftClientConfigElement.getQName().getLocalPart())) { + userNameValuesStr = thriftClientConfigElement.getText(); + thriftClientInfo.setUsername(userNameValuesStr); + } + + //password field protected using Secure vault + if (PASSWORD_ELEMENT.equals(thriftClientConfigElement.getQName().getLocalPart())) { + if ((secretResolver != null) && (secretResolver.isInitialized())) { + if (secretResolver.isTokenProtected(secretAlias)) { + passwordValueStr = secretResolver.resolve(secretAlias); + } else { + passwordValueStr = thriftClientConfigElement.getText(); + } } else { - passwordValueStr = thriftClientElement.getText(); + passwordValueStr = thriftClientConfigElement.getText(); } - } else { - passwordValueStr = thriftClientElement.getText(); + thriftClientInfo.setPassword(passwordValueStr); } - thriftClientInfo.setPassword(passwordValueStr); - } - if (IP_ELEMENT.equals(thriftClientElement.getQName().getLocalPart())) { - ipValuesStr = thriftClientElement.getText(); - thriftClientInfo.setIp(ipValuesStr); - } + if (IP_ELEMENT.equals(thriftClientConfigElement.getQName().getLocalPart())) { + ipValuesStr = thriftClientConfigElement.getText(); + thriftClientInfo.setIp(ipValuesStr); + } - if (PORT_ELEMENT.equals(thriftClientElement.getQName().getLocalPart())) { - portValueStr = thriftClientElement.getText(); - thriftClientInfo.setPort(portValueStr); + if (PORT_ELEMENT.equals(thriftClientConfigElement.getQName().getLocalPart())) { + portValueStr = thriftClientConfigElement.getText(); + thriftClientInfo.setPort(portValueStr); + } } } + if (nameValuesStr == null) { + throw new RuntimeException("Name value not found in thrift client configuration "); + } if (userNameValuesStr == null) { throw new RuntimeException("Username value not found in thrift client configuration"); @@ -131,6 +157,9 @@ public class ThriftClientConfigParser { throw new RuntimeException("Port not found in thrift client configuration "); } + thriftClientIConfig.setCEPThriftClientInfo(cepThriftClientInfo); + thriftClientIConfig.setDASThriftClientInfo(dasThriftClientInfo); + return thriftClientIConfig; } catch (Exception e) { throw new RuntimeException("Could not parse thrift client configuration", e); http://git-wip-us.apache.org/repos/asf/stratos/blob/78da0efa/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftStatisticsPublisher.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftStatisticsPublisher.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftStatisticsPublisher.java index 6a9e955..9242e41 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftStatisticsPublisher.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftStatisticsPublisher.java @@ -49,11 +49,14 @@ public class ThriftStatisticsPublisher implements StatisticsPublisher { * Credential information stored inside thrift-client-config.xml file * is parsed and assigned into ip,port,username and password fields * - * @param streamDefinition Thrift Event Stream Definition + * @param streamDefinition Thrift Event Stream Definition + * @param statsPublisherEnabled Whether thrift statistics publisher is enabled + * @param thriftClientName Thrift Client Name */ - public ThriftStatisticsPublisher(StreamDefinition streamDefinition, String statsPublisherEnabled) { + public ThriftStatisticsPublisher(StreamDefinition streamDefinition, String statsPublisherEnabled, + String thriftClientName) { ThriftClientConfig thriftClientConfig = ThriftClientConfig.getInstance(); - ThriftClientInfo thriftClientInfo = thriftClientConfig.getThriftClientInfo(); + ThriftClientInfo thriftClientInfo = thriftClientConfig.getThriftClientInfo(thriftClientName); this.streamDefinition = streamDefinition; this.ip = thriftClientInfo.getIp(); http://git-wip-us.apache.org/repos/asf/stratos/blob/78da0efa/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/wso2/cep/WSO2CEPHealthStatisticsPublisher.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/wso2/cep/WSO2CEPHealthStatisticsPublisher.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/wso2/cep/WSO2CEPHealthStatisticsPublisher.java index 33cf0b5..6a856c1 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/wso2/cep/WSO2CEPHealthStatisticsPublisher.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/wso2/cep/WSO2CEPHealthStatisticsPublisher.java @@ -40,9 +40,10 @@ public class WSO2CEPHealthStatisticsPublisher extends ThriftStatisticsPublisher private static final String STATS_PUBLISHER_ENABLED = "cep.stats.publisher.enabled"; private static final String DATA_STREAM_NAME = "cartridge_agent_health_stats"; private static final String VERSION = "1.0.0"; + public static final String CEP_THRIFT_CLIENT_NAME = "cep"; public WSO2CEPHealthStatisticsPublisher() { - super(createStreamDefinition(), STATS_PUBLISHER_ENABLED); + super(createStreamDefinition(), STATS_PUBLISHER_ENABLED, CEP_THRIFT_CLIENT_NAME); } private static StreamDefinition createStreamDefinition() { http://git-wip-us.apache.org/repos/asf/stratos/blob/78da0efa/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/wso2/cep/WSO2CEPInFlightRequestPublisher.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/wso2/cep/WSO2CEPInFlightRequestPublisher.java b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/wso2/cep/WSO2CEPInFlightRequestPublisher.java index f853f23..aa64270 100644 --- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/wso2/cep/WSO2CEPInFlightRequestPublisher.java +++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/wso2/cep/WSO2CEPInFlightRequestPublisher.java @@ -42,9 +42,10 @@ public class WSO2CEPInFlightRequestPublisher extends ThriftStatisticsPublisher i private static final String STATS_PUBLISHER_ENABLED = "cep.stats.publisher.enabled"; private static final String DATA_STREAM_NAME = "in_flight_requests"; private static final String VERSION = "1.0.0"; + public static final String CEP_THRIFT_CLIENT_NAME = "cep"; public WSO2CEPInFlightRequestPublisher() { - super(createStreamDefinition(), STATS_PUBLISHER_ENABLED); + super(createStreamDefinition(), STATS_PUBLISHER_ENABLED, CEP_THRIFT_CLIENT_NAME); } private static StreamDefinition createStreamDefinition() { http://git-wip-us.apache.org/repos/asf/stratos/blob/78da0efa/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftClientConfigParserTest.java ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftClientConfigParserTest.java b/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftClientConfigParserTest.java index 352041d..c51fa7e 100644 --- a/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftClientConfigParserTest.java +++ b/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/ThriftClientConfigParserTest.java @@ -42,11 +42,19 @@ public class ThriftClientConfigParserTest extends TestCase { URL configFileUrl = ThriftClientConfigParserTest.class.getResource("/thrift-client-config.xml"); System.setProperty(ThriftClientConfig.THRIFT_CLIENT_CONFIG_FILE_PATH, configFileUrl.getPath()); ThriftClientConfig thriftClientConfig = ThriftClientConfig.getInstance(); - ThriftClientInfo thriftClientInfo = thriftClientConfig.getThriftClientInfo(); + ThriftClientInfo cepThriftClientInfo = thriftClientConfig.getThriftClientInfo( + ThriftClientConfig.CEP_THRIFT_CLIENT_NAME); + ThriftClientInfo dasThriftClientInfo = thriftClientConfig.getThriftClientInfo( + ThriftClientConfig.DAS_THRIFT_CLIENT_NAME); - assertEquals("Incorrect Username", "admin", thriftClientInfo.getUsername()); - assertEquals("Incorrect Password", "1234", thriftClientInfo.getPassword()); - assertEquals("Incorrect IP", "192.168.10.10", thriftClientInfo.getIp()); - assertEquals("Incorrect Port", "9300", thriftClientInfo.getPort()); + assertEquals("Incorrect Username", "admin", cepThriftClientInfo.getUsername()); + assertEquals("Incorrect Password", "1234", cepThriftClientInfo.getPassword()); + assertEquals("Incorrect IP", "192.168.10.10", cepThriftClientInfo.getIp()); + assertEquals("Incorrect Port", "9300", cepThriftClientInfo.getPort()); + + assertEquals("Incorrect Username", "admin1", dasThriftClientInfo.getUsername()); + assertEquals("Incorrect Password", "12345", dasThriftClientInfo.getPassword()); + assertEquals("Incorrect IP", "192.168.10.11", dasThriftClientInfo.getIp()); + assertEquals("Incorrect Port", "9301", dasThriftClientInfo.getPort()); } } http://git-wip-us.apache.org/repos/asf/stratos/blob/78da0efa/components/org.apache.stratos.common/src/test/resources/thrift-client-config.xml ---------------------------------------------------------------------- diff --git a/components/org.apache.stratos.common/src/test/resources/thrift-client-config.xml b/components/org.apache.stratos.common/src/test/resources/thrift-client-config.xml index 7e9ff39..80d5796 100644 --- a/components/org.apache.stratos.common/src/test/resources/thrift-client-config.xml +++ b/components/org.apache.stratos.common/src/test/resources/thrift-client-config.xml @@ -18,10 +18,20 @@ ~ under the License. --> -<!-- Apache thrift client configuration for publishing statistics to WSO2 CEP --> +<!-- Apache thrift client configuration for publishing statistics to WSO2 CEP and WSO2 DAS --> <thriftClientConfiguration> - <username>admin</username> - <password>1234</password> - <ip>192.168.10.10</ip> - <port>9300</port> + <config> + <name>cep</name> + <username>admin</username> + <password>1234</password> + <ip>192.168.10.10</ip> + <port>9300</port> + </config> + <config> + <name>das</name> + <username>admin1</username> + <password>12345</password> + <ip>192.168.10.11</ip> + <port>9301</port> + </config> </thriftClientConfiguration> \ No newline at end of file http://git-wip-us.apache.org/repos/asf/stratos/blob/78da0efa/products/stratos/conf/thrift-client-config.xml ---------------------------------------------------------------------- diff --git a/products/stratos/conf/thrift-client-config.xml b/products/stratos/conf/thrift-client-config.xml index 5cacada..4b3b5b9 100644 --- a/products/stratos/conf/thrift-client-config.xml +++ b/products/stratos/conf/thrift-client-config.xml @@ -18,10 +18,20 @@ ~ under the License. --> -<!-- Apache thrift client configuration for publishing statistics to WSO2 CEP --> +<!-- Apache thrift client configuration for publishing statistics to WSO2 CEP and WSO2 DAS--> <thriftClientConfiguration> - <username>admin</username> - <password>admin</password> - <ip>localhost</ip> - <port>7611</port> + <config> + <name>cep</name> + <username>admin</username> + <password>admin</password> + <ip>localhost</ip> + <port>7611</port> + </config> + <config> + <name>das</name> + <username>admin</username> + <password>admin</password> + <ip>localhost</ip> + <port>7612</port> + </config> </thriftClientConfiguration> \ No newline at end of file
