You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@stratos.apache.org by supunr <gi...@git.apache.org> on 2015/01/28 11:25:17 UTC

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

GitHub user supunr opened a pull request:

    https://github.com/apache/stratos/pull/192

    Added new files to parse thrift-client-config.xml

    Created 3 new classes to parse thrift-client-config.xml values and changed the hard coded fields in WSO2CEPStatisticsPublisher class. 

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/supunr/stratos master

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/stratos/pull/192.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #192
    
----
commit 2b6d53b730d0a0bf29735823ac0f24e1294f4c4d
Author: Supun <su...@puppet.test.org>
Date:   2015-01-28T10:01:13Z

    Added new files to parse thrift-client-config.xml

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/stratos/pull/192


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on the pull request:

    https://github.com/apache/stratos/pull/192#issuecomment-72323492
  
    This pull request was closed since #200 was submitted with corrections.
    Thanks


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by supunr <gi...@git.apache.org>.
Github user supunr commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/192#discussion_r23686360
  
    --- Diff: products/stratos/conf/data-bridge/thrift-client-config.xml ---
    @@ -0,0 +1,23 @@
    +<!--
    +  ~ Copyright 2005-2011 WSO2, Inc. (http://wso2.com)
    +  ~
    +  ~ 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.
    +  -->
    +
    +<!--Fields to be read and parsed into WSO2CEPStatisticsPublisher-->
    +<thriftClientConfiguration>
    +    <username>test User</username>
    --- End diff --
    
    @chamilad The values have been used temporarily to check the usage of a configuration file, in order to pass the necessary credentials required for WSO2CEPStatisticsPublisher. Next step is to make these values secure, therefore I also think these should be replaceable strings. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by supunr <gi...@git.apache.org>.
Github user supunr commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/192#discussion_r23700279
  
    --- Diff: components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/publisher/ThriftClientConfigParserTest.java ---
    @@ -0,0 +1,50 @@
    +/*
    +* Licensed to the Apache Software Foundation (ASF) under one
    +* or more contributor license agreements.  See the NOTICE file
    +* distributed with this work for additional information
    +* regarding copyright ownership.  The ASF licenses this file
    +* to you 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.
    +*/
    +
    +package org.apache.stratos.common.test.publisher;
    +
    +import junit.framework.TestCase;
    +import org.apache.stratos.common.statistics.publisher.ThriftClientConfig;
    +import org.junit.Test;
    +
    +/**
    + * Thrift Client configuration.
    + *
    + * @author  supunr
    + * @contact supunr@wso2.com
    + * @date    1/27/15
    + */
    +public class ThriftClientConfigParserTest extends TestCase {
    +    /**
    +     * Test ThriftClientConfigParser parse method to check whether it
    +     * reads the correct xml filed values.
    +     *
    +     * @throws Exception
    +     */
    +    @Test
    +    public void testName() throws Exception{
    --- End diff --
    
    @imesh Yes using the default values to test this. I will make the changes 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/192#discussion_r23697533
  
    --- Diff: components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfig.java ---
    @@ -0,0 +1,88 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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.
    + */
    +
    +package org.apache.stratos.common.statistics.publisher;
    +
    +/**
    + * Thrift Client configuration.
    + *
    + * @author  supunr
    + * @contact supunr@wso2.com
    + * @date    1/27/15
    --- End diff --
    
    As a practice we do not add author in Stratos Java files.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/192#discussion_r23697450
  
    --- Diff: components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfig.java ---
    @@ -0,0 +1,88 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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.
    + */
    +
    +package org.apache.stratos.common.statistics.publisher;
    +
    +/**
    + * Thrift Client configuration.
    + *
    + * @author  supunr
    + * @contact supunr@wso2.com
    + * @date    1/27/15
    + */
    +public class ThriftClientConfig {
    +
    +    /**
    +     * Setting the relative path to thrift-client-config.xml file
    +     */
    +    public static final String THRIFT_CLIENT_CONFIG_FILE_PATH = "thrift.client.config.file.path";
    +    private static final String THRIFT_CLIENT_CONFIG_FILE_NAME = "thrift-client-config.xml";
    +
    +    // here "user.dir" has been used instead of "carbon.home"
    +    // since "carbon.home" returned a null value in this instance
    +    private static final String CARBON_HOME = "user.dir";
    +    private static final String REPOSITORY_CONF = "/products/stratos/conf/data-bridge/";
    +
    +    private static volatile ThriftClientConfig instance;
    +    private ThriftClientInfo thriftClientInfo;
    +
    +    /*
    +    * A private Constructor prevents any other
    +    * class from instantiating.
    +    */
    +    ThriftClientConfig(){}
    +
    +    public static ThriftClientConfig getInstance() {
    +        if (instance == null) {
    +            synchronized (ThriftClientConfig.class) {
    +                if (instance == null) {
    +                    String defaultConfigFilePath = System.getProperty(CARBON_HOME) + REPOSITORY_CONF +
    +                            THRIFT_CLIENT_CONFIG_FILE_NAME;
    --- End diff --
    
    I think its better to use org.wso2.carbon.utils.CarbonUtils.getCarbonHome() here.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by supunr <gi...@git.apache.org>.
Github user supunr commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/192#discussion_r23886649
  
    --- Diff: components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfig.java ---
    @@ -0,0 +1,88 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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.
    + */
    +
    +package org.apache.stratos.common.statistics.publisher;
    +
    +/**
    + * Thrift Client configuration.
    + *
    + * @author  supunr
    + * @contact supunr@wso2.com
    + * @date    1/27/15
    + */
    +public class ThriftClientConfig {
    +
    +    /**
    +     * Setting the relative path to thrift-client-config.xml file
    +     */
    +    public static final String THRIFT_CLIENT_CONFIG_FILE_PATH = "thrift.client.config.file.path";
    +    private static final String THRIFT_CLIENT_CONFIG_FILE_NAME = "thrift-client-config.xml";
    +
    +    // here "user.dir" has been used instead of "carbon.home"
    +    // since "carbon.home" returned a null value in this instance
    +    private static final String CARBON_HOME = "user.dir";
    +    private static final String REPOSITORY_CONF = "/products/stratos/conf/data-bridge/";
    +
    +    private static volatile ThriftClientConfig instance;
    +    private ThriftClientInfo thriftClientInfo;
    +
    +    /*
    +    * A private Constructor prevents any other
    +    * class from instantiating.
    +    */
    +    ThriftClientConfig(){}
    +
    +    public static ThriftClientConfig getInstance() {
    +        if (instance == null) {
    +            synchronized (ThriftClientConfig.class) {
    +                if (instance == null) {
    +                    String defaultConfigFilePath = System.getProperty(CARBON_HOME) + REPOSITORY_CONF +
    +                            THRIFT_CLIENT_CONFIG_FILE_NAME;
    --- End diff --
    
    When using org.wso2.carbon.utils.CarbonUtils.getCarbonHome() it still returns a null values? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/192#discussion_r23697818
  
    --- Diff: components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/publisher/ThriftClientConfigParserTest.java ---
    @@ -0,0 +1,50 @@
    +/*
    +* Licensed to the Apache Software Foundation (ASF) under one
    +* or more contributor license agreements.  See the NOTICE file
    +* distributed with this work for additional information
    +* regarding copyright ownership.  The ASF licenses this file
    +* to you 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.
    +*/
    +
    +package org.apache.stratos.common.test.publisher;
    +
    +import junit.framework.TestCase;
    +import org.apache.stratos.common.statistics.publisher.ThriftClientConfig;
    +import org.junit.Test;
    +
    +/**
    + * Thrift Client configuration.
    + *
    + * @author  supunr
    + * @contact supunr@wso2.com
    + * @date    1/27/15
    + */
    +public class ThriftClientConfigParserTest extends TestCase {
    +    /**
    +     * Test ThriftClientConfigParser parse method to check whether it
    +     * reads the correct xml filed values.
    +     *
    +     * @throws Exception
    +     */
    +    @Test
    +    public void testName() throws Exception{
    --- End diff --
    
    May be we need to use a sample configuration file to write the unit test. Are we using the default values here?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by chamilad <gi...@git.apache.org>.
Github user chamilad commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/192#discussion_r23680853
  
    --- Diff: products/stratos/conf/data-bridge/thrift-client-config.xml ---
    @@ -0,0 +1,23 @@
    +<!--
    +  ~ Copyright 2005-2011 WSO2, Inc. (http://wso2.com)
    +  ~
    +  ~ 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.
    +  -->
    +
    +<!--Fields to be read and parsed into WSO2CEPStatisticsPublisher-->
    +<thriftClientConfiguration>
    +    <username>test User</username>
    --- End diff --
    
    @supunr I'm not entirely sure, however as far as I understand these values (username, password, ip and port) would be set using Puppet or a shell script (for Docker containers) right? If that is the case wouldn't using replaceable strings (ex: USERNAME, PASSWORD, IP, PORT) instead of "test user" be more suitable? 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/192#discussion_r23747677
  
    --- Diff: products/stratos/conf/data-bridge/thrift-client-config.xml ---
    @@ -0,0 +1,23 @@
    +<!--
    +  ~ Copyright 2005-2011 WSO2, Inc. (http://wso2.com)
    +  ~
    +  ~ 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.
    +  -->
    +
    +<!--Fields to be read and parsed into WSO2CEPStatisticsPublisher-->
    +<thriftClientConfiguration>
    +    <username>test User</username>
    --- End diff --
    
    IMO we will need to keep default values here to be able to make the default distribution work. We can introduce a template file in the installer with place holders.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] stratos pull request: Added new files to parse thrift-client-confi...

Posted by imesh <gi...@git.apache.org>.
Github user imesh commented on a diff in the pull request:

    https://github.com/apache/stratos/pull/192#discussion_r23697651
  
    --- Diff: components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/statistics/publisher/ThriftClientConfigParser.java ---
    @@ -0,0 +1,117 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you 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.
    + */
    +
    +package org.apache.stratos.common.statistics.publisher;
    +
    +import org.apache.axiom.om.OMElement;
    +import org.apache.stratos.common.util.AxiomXpathParserUtil;
    +
    +import java.io.File;
    +import java.util.Iterator;
    +
    +/**
    + * Thrift Client config parser.
    + *
    + * @author  supunr
    + * @contact supunr@wso2.com
    + * @date    1/27/15
    + */
    +public class ThriftClientConfigParser {
    +    /**
    +     * Fields to be read from the thrift-client-config.xml file
    +     */
    +    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";
    +
    +    /**
    +     * This method reads thrift-client-config.xml file and assign necessary credential
    +     * values into thriftClientInfo object.  A singleton design has been implemented
    +     * with the use of thriftClientIConfig class.
    +     * <p>
    +     * The filePath argument is the path to thrift-client-config.xml file
    +     *
    +     * @param filePath the path to thrift-client-config.xml file
    +     * @return         ThriftClientConfig object
    +     */
    +    public static ThriftClientConfig parse(String filePath) {
    +        try {
    +            ThriftClientConfig thriftClientIConfig = new ThriftClientConfig();
    +            ThriftClientInfo thriftClientInfo = new ThriftClientInfo();
    +            thriftClientIConfig.setThriftClientInfo(thriftClientInfo);
    +
    +            OMElement document = AxiomXpathParserUtil.parse(new File(filePath));
    +            Iterator thriftClientIterator = document.getChildElements();
    +
    +            String userNameValuesStr = null;
    +            String passwordValueStr = null;
    +            String ipValuesStr = null;
    +            String portValueStr = null;
    +
    +            // Iterate the thrift-client-config.xml file and read child element
    +            // consists of credential information necessary for WSO2CEPStatisticsPublisher
    +            while (thriftClientIterator.hasNext()) {
    +                OMElement thriftClientElement = (OMElement) thriftClientIterator.next();
    +
    +                if (USERNAME_ELEMENT.equals(thriftClientElement.getQName().getLocalPart())) {
    +                    userNameValuesStr = thriftClientElement.getText();
    +                    thriftClientInfo.setUsername(userNameValuesStr);
    +                }
    +
    +                if (PASSWORD_ELEMENT.equals(thriftClientElement.getQName().getLocalPart())) {
    +                    passwordValueStr = thriftClientElement.getText();
    +                    thriftClientInfo.setPassword(passwordValueStr);
    +                }
    +
    +                if (IP_ELEMENT.equals(thriftClientElement.getQName().getLocalPart())) {
    +                    ipValuesStr = thriftClientElement.getText();
    +                    thriftClientInfo.setIp(ipValuesStr);
    +                }
    +
    +                if (PORT_ELEMENT.equals(thriftClientElement.getQName().getLocalPart())) {
    +                    portValueStr = thriftClientElement.getText();
    +                    thriftClientInfo.setPort(portValueStr);
    +                }
    +            }
    +
    +            if (userNameValuesStr == null) {
    +                throw new RuntimeException("Username value not found in thriftClientConfiguration");
    --- End diff --
    
    Shall we change the text "thriftClientConfiguration" to "thrift client configuration"?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---