Tuesday, August 23, 2016

 

Ngnix Settings for two pubstore instances on the same openstack cloud .......

 

1. Access your openstack cloud instance using ssh commands.

2. Navigate to /etc/nginx/conf.d/xx.conf file.

3. Add the below configuration.

upstream pubstore {
  server 192.168.61.xx:9443;
  server 192.168.61.yy:9443;
  ip_hash;
}

server {

        listen 443 ssl;
        server_name apim.cloud.wso2.com;

        ssl on;
        ssl_certificate /etc/nginx/ssl/ssl.crt;
        ssl_certificate_key /etc/nginx/ssl/ssl.key;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection 'upgrade';
        proxy_http_version 1.1;
        client_max_body_size 20M;

        location / {
                proxy_set_header Host $http_host;
                proxy_read_timeout 5m;
                proxy_send_timeout 5m;

                index index.html;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass https://pubstore;
        }
}


** For ngnix community edition use ip_hash.
** For ngnix plus add sticky session configurations as below.


 sticky learn create=$upstream_cookie_jsessionid
 lookup=$cookie_jsessionid
 zone=client_sessions:1m;


--------------------------------------------------------------------------------------------------------------------------
                ------------- XXXXXXXXXXXXXXXXXXXXXXXXXXX ---------------
--------------------------------------------------------------------------------------------------------------------------

WSO2IS-5.2.0 Testing Proxy Context Path 

1. Open sudo vim sites-enabled/default  and add below. 


server {
listen 443;
    server_name wso2test.com;
    client_max_body_size 100M;

    root /usr/share/nginx/www;
    index index.html index.htm;

    ssl on;
    ssl_certificate /etc/nginx/ssl/nginx.crt;
    ssl_certificate_key /etc/nginx/ssl/nginx.key;

    location /is/ {
        proxy_pass https://is.wso2test.com:9443/;
    }


}


* Now Restart the nginx server. 

sudo service nginx restart



2.  Change [Product_Home]/repository/conf/carbon.xml

    <HostName>wso2test.com</HostName>

    <!--
    Host name to be used for the Carbon management console
    -->

    <MgtHostName>is.wso2test.com</MgtHostName>


    <MgtProxyContextPath>is</MgtProxyContextPath>

    <ProxyContextPath>is</ProxyContextPath>


3.  Add proxy port to [Product_Home]/repository/conf/tomcat/catalina-server.xml

<Connector protocol="org.apache.coyote.http11.Http11NioProtocol"
                   port="9443"
                   proxyPort="443"              
                   bindOnInit="false"
                   sslProtocol="TLS"
                   sslEnabledProtocols="TLSv1,TLSv1.1,TLSv1.2"
                   maxHttpHeaderSize="8192"
                   acceptorThreadCount="2"
                   maxThreads="250"
                   minSpareThreads="50"
                   disableUploadTimeout="false"
                   enableLookups="false"
                   connectionUploadTimeout="120000"
                   maxKeepAliveRequests="200"
                   acceptCount="200"
                   server="WSO2 Carbon Server"
                   clientAuth="want"
                   compression="on"
                   scheme="https"
                   secure="true"
                   SSLEnabled="true"
                   compressionMinSize="2048"
                   noCompressionUserAgents="gozilla, traviata"
                   compressableMimeType="text/html,text/javascript,application/x-javascript,application/javascript,application/xml,text/css,application/xslt+xml,text/xsl,image/gif,image/jpg,image/jpeg"
                   keystoreFile="${carbon.home}/repository/resources/security/wso2carbon.jks"
                   keystorePass="wso2carbon"

                   URIEncoding="UTF-8"/>


* Do the same to  port="9763" aswell.


4. Add below to etc/hosts

127.0.0.1        wso2test.com

127.0.0.1        is.wso2test.com





Tuesday, August 2, 2016


Getting Thraed dumps from Wso2 Servers ....


1. Download and extract wso2esb on to your Desktop.

2. Run ESB server by navigating to [WSO2_ESB_HOME]/bin directory and issue the command to run the server. (./wso2server.sh)

3. If you are running wso2 server on ubuntu/linux platform follow these command sequences.

     - ps -ef|grep wso2                   - This will give you the PID of the current
   
     - pgrep java                             - Confirm the PID for server is correct

4. Imagine your server PID is 19785 , for saving threaddump.txt - thread dump info to a txt file - issue this command.

   jstack 19785 > threadump.txt
   

Friday, June 3, 2016

Sample UI test for gerg LifeCycle scenarios

Refer :

[1]

https://github.com/wso2/product-greg/blob/master/modules/integration/tests-ui-integration/tests-es-ui/src/test/java/org/wso2/carbon/greg/ui/test/lifecycle/LifeCycleSmokeUITestCase.java


/*
*Copyright (c) 2005-2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
*WSO2 Inc. 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.wso2.carbon.greg.ui.test.lifecycle;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.automation.engine.context.TestUserMode;
import org.wso2.carbon.automation.engine.context.beans.User;
import org.wso2.carbon.automation.extensions.selenium.BrowserManager;

import org.wso2.greg.integration.common.ui.page.LoginPage;
import org.wso2.greg.integration.common.ui.page.lifecycle.LifeCycleHomePage;
import org.wso2.greg.integration.common.ui.page.lifecycle.LifeCyclesPage;
import org.wso2.greg.integration.common.ui.page.publisher.PublisherHomePage;
import org.wso2.greg.integration.common.ui.page.publisher.PublisherLoginPage;
import org.wso2.greg.integration.common.ui.page.store.StoreLoginPage;
import org.wso2.greg.integration.common.ui.page.util.UIElementMapper;
import org.wso2.greg.integration.common.utils.GREGIntegrationUIBaseTest;

import static org.testng.Assert.assertTrue;

/**
 * This UI test class covers a full testing scenario of,
 *
 *  1. Uploading a LC to greg,
 *  2. Implementation of rest service,
 *  3. Adding the LC to rest service,
 *  4. Attaching of LC for rest service
 *  5. Promoting of rest service
 *  6. Store related operations - JIRA STORE-1156
 *
 */
public class LifeCycleSmokeUITestCase extends GREGIntegrationUIBaseTest {

    private WebDriver driver;
    private User userInfo;

    private String restServiceName = "DimuthuD";
    private UIElementMapper uiElementMapper;

    @BeforeClass(alwaysRun = true)
    public void setUp() throws Exception {

        super.init(TestUserMode.SUPER_TENANT_ADMIN);
        userInfo = automationContext.getContextTenant().getContextUser();
        driver = BrowserManager.getWebDriver();
        this.uiElementMapper = UIElementMapper.getInstance();
    }

    @AfterClass(alwaysRun = true)
    public void tearDown() throws Exception {
        driver.quit();
    }

    @Test(groups = "wso2.greg", description = "verify login to governance registry")
    public void performingLoginToManagementConsole() throws Exception {

        driver.get(getLoginURL());
        LoginPage test = new LoginPage(driver);
        test.loginAs(automationContext.getContextTenant().getContextUser().getUserName(),
                automationContext.getContextTenant().getContextUser().getPassword());

        driver.get(getLoginURL() + "admin/index.jsp?loginStatus=true");
        LifeCycleHomePage lifeCycleHomePage = new LifeCycleHomePage(driver);


        String lifeCycle = "<aspect name=\"SampleLifeCycle\" class=\"org.wso2.carbon.governance.registry.extensions.aspects.DefaultLifeCycle\">\n" +
                "    <configuration type=\"literal\">\n" +
                "        <lifecycle>\n" +
                "            <scxml xmlns=\"http://www.w3.org/2005/07/scxml\"\n" +
                "                   version=\"1.0\"\n" +
                "                   initialstate=\"Development\">\n" +
                "                <state id=\"Development\">\n" +
                "                    <datamodel>\n" +
                "                        <data name=\"checkItems\">\n" +
                "                            <item name=\"Code Completed\" forEvent=\"\">\n" +
                "                            </item>\n" +
                "                            <item name=\"WSDL, Schema Created\" forEvent=\"\">\n" +
                "                            </item>\n" +
                "                            <item name=\"QoS Created\" forEvent=\"\">\n" +
                "                            </item>\n" +
                "                        </data>\n" +
                "                    </datamodel>\n" +
                "                    <transition event=\"Promote\" target=\"Tested\"/>\n" +
                "                    <checkpoints>\n" +
                "                        <checkpoint id=\"DevelopmentOne\" durationColour=\"green\">\n" +
                "                            <boundary min=\"0d:0h:0m:0s\" max=\"1d:0h:00m:20s\"/>\n" +
                "                        </checkpoint>\n" +
                "                        <checkpoint id=\"DevelopmentTwo\" durationColour=\"red\">\n" +
                "                            <boundary min=\"1d:0h:00m:20s\" max=\"23d:2h:5m:52s\"/>\n" +
                "                        </checkpoint>\n" +
                "                    </checkpoints>\n" +
                "                </state>\n" +
                "                <state id=\"Tested\">\n" +
                "                    <datamodel>\n" +
                "                        <data name=\"checkItems\">\n" +
                "                            <item name=\"Effective Inspection Completed\" forEvent=\"\">\n" +
                "                            </item>\n" +
                "                            <item name=\"Test Cases Passed\" forEvent=\"\">\n" +
                "                            </item>\n" +
                "                            <item name=\"Smoke Test Passed\" forEvent=\"\">\n" +
                "                            </item>\n" +
                "                        </data>\n" +
                "                    </datamodel>\n" +
                "                    <transition event=\"Promote\" target=\"Production\"/>\n" +
                "                    <transition event=\"Demote\" target=\"Development\"/>\n" +
                "                </state>\n" +
                "                <state id=\"Production\">\n" +
                "                    <transition event=\"Demote\" target=\"Tested\"/>\n" +
                "                </state>\n" +
                "            </scxml>\n" +
                "        </lifecycle>\n" +
                "    </configuration>\n" +
                "</aspect>\n";


        lifeCycleHomePage.addNewLifeCycle(lifeCycle);

        driver.get(getLoginURL() + "lcm/lcm.jsp?region=region3&item=governance_lcm_menu");
        LifeCyclesPage lifeCyclesPage = new LifeCyclesPage(driver);

        assertTrue(lifeCyclesPage.checkOnUploadedLifeCycle("SampleLifeCycle"), "Sample Life Cycle Could Not Be Found");

        Thread.sleep(6000);

        driver.findElement(By.linkText("Sign-out")).click();

        log.info("Login test case is completed ");
    }

    @Test(groups = "wso2.greg", description = "logging to publisher",
            dependsOnMethods = "performingLoginToManagementConsole")
    public void performingLoginToPublisher() throws Exception {

        // Setting publisher home page
        driver.get(getPublisherUrl().split("\\/apis")[0]);

        PublisherLoginPage test = new PublisherLoginPage(driver);

        // performing login to publisher
        test.loginAs(userInfo.getUserName(), userInfo.getPassword());

        driver.get(getPublisherUrl().split("/apis")[0] + "/pages/gc-landing");

        PublisherHomePage publisherHomePage = new PublisherHomePage(driver);

        //adding rest service
        publisherHomePage.createRestService(restServiceName, "/lana", "1.2.5");

        driver.findElement(By.cssSelector("div.auth-img")).click();
        driver.findElement(By.linkText("Sign out")).click();

        Thread.sleep(3000);
    }


    @Test(groups = "wso2.greg", description = "Adding of LC to the rest service",
            dependsOnMethods = "performingLoginToPublisher")
    public void addingLCToRestService() throws Exception {

        driver.get(getLoginURL());

        LoginPage loginPage = new LoginPage(driver);
        loginPage.loginAs(automationContext.getContextTenant().getContextUser().getUserName(),
                automationContext.getContextTenant().getContextUser().getPassword());

        loginPage.assignLCToRestService(restServiceName);

        driver.findElement(By.linkText("Sign-out")).click();

        Thread.sleep(3000);
    }

    @Test(groups = "wso2.greg", description = "Promoting of rest service with the LC",
            dependsOnMethods = "addingLCToRestService")
    public void lifeCycleEventsOfRestService() throws Exception {

        // Setting publisher home page
        driver.get(getPublisherUrl().split("/apis")[0]);

        PublisherLoginPage publisherLoginPage = new PublisherLoginPage(driver);

        // performing login to publisher
        publisherLoginPage.loginAs(userInfo.getUserName(), userInfo.getPassword());

        driver.get(getPublisherUrl().split("/apis")[0] + "/pages/gc-landing");

        driver.findElement(By.cssSelector("span.btn-asset")).click();
        driver.findElement(By.linkText("REST Services")).click();
        driver.findElement(By.linkText(restServiceName)).click();

        driver.findElement(By.id("Lifecycle")).click();

        driver.findElement(By.linkText("Other lifecycles")).click();
        driver.findElement(By.linkText("SampleLifeCycle")).click();

        driver.findElement(By.xpath(uiElementMapper.getElement("publisher.promote.checkbox1.xpath"))).click();
        Thread.sleep(2000);
        driver.findElement(By.xpath(uiElementMapper.getElement("publisher.promote.checkbox2.xpath"))).click();
        Thread.sleep(2000);
        driver.findElement(By.xpath(uiElementMapper.getElement("publisher.promote.checkbox3.xpath"))).click();
        Thread.sleep(2000);
        driver.findElement(By.id("lcActionPromote")).click();
        Thread.sleep(2000);
        driver.findElement(By.xpath(uiElementMapper.getElement("publisher.promote.checkbox1.xpath"))).click();
        Thread.sleep(2000);
        driver.findElement(By.xpath(uiElementMapper.getElement("publisher.promote.checkbox2.xpath"))).click();
        Thread.sleep(2000);
        driver.findElement(By.xpath(uiElementMapper.getElement("publisher.promote.checkbox3.xpath"))).click();
        Thread.sleep(2000);
        driver.findElement(By.id("lcActionPromote")).click();

        // removal of added rest service
        driver.findElement(By.id("Edit")).click();
        driver.findElement(By.id("Delete")).click();
        driver.findElement(By.id("btn-delete-con")).click();
    }

}

Thursday, June 2, 2016






[1] Docker + Java 

Below code segment can be used for pushing your Docker images to public docker registry / hub.


  private StringBuffer output = new StringBuffer();

  private String gitPush(String command) {

      Process process;
      try {
          process = Runtime.getRuntime().exec(command);
          process.waitFor();
          BufferedReader reader =
                  new BufferedReader(new InputStreamReader(process.getInputStream()));


          String line = "";
          while ((line = reader.readLine()) != null) {
              output.append(line + "\n");
          }

      } catch (Exception e) {
          e.printStackTrace();
      }

      return output.toString();

  }


Build Doker image using fabric8
---------------------------------------

public static boolean buildDockerImage(String dockerUrl, String image, String imageFolder)
            throws InterruptedException, IOException {

        Config config = new ConfigBuilder()
                .withDockerUrl(dockerUrl)
                .build();

        DockerClient client = new DefaultDockerClient(config);
        final CountDownLatch buildDone = new CountDownLatch(1);


        OutputHandle handle = client.image().build()
                .withRepositoryName(image)
                .usingListener(new EventListener() {
                    @Override
                    public void onSuccess(String message) {
                        log.info("Success:" + message);
                        buildDone.countDown();
                    }

                    @Override
                    public void onError(String messsage) {
                        log.error("Failure:" + messsage);
                        buildDone.countDown();
                    }

                    @Override
                    public void onEvent(String event) {
                        log.info("Success:" + event);
                    }
                })
                .fromFolder(imageFolder);

        buildDone.await();
        handle.close();
        client.close();
        return true;
    }

Thursday, May 12, 2016

Troubleshooting Wso2 TAF
=====================


This is series of super important clues to overcome such bugs we would encounter while working with Wso2 TAF - Automation Framework ....


1. Errror 

when building wso2 TAF if you get something like this on the console .......

diamond operator is not supported in -source 1.6
  (use -source 7 or higher to enable diamond operator)
  
  Solution 
Add the maven source plugin to the pom.xml file. 


            <plugin>
                   <artifactId>maven-compiler-plugin</artifactId>
                   <version>2.3.1</version>
                   <inherited>true</inherited>
                       <configuration>
                               <source>1.8</source>
                               <target>1.8</target>
                       </configuration>
            </plugin>