Saturday, July 30, 2016

[WSO2 DAS] How to Control Spark Log File Generation.


When Spark scripts are executing in the DAS server, you can be see several Spark log files in <DAS_HOME>/work directory. If you execute number of spark scripts often, you might face a disk space issue as there will be a lots of log files.

If you want to allocate a disk space of predefined size for Spark log files, add below configuration to <DAS_home>/repository/conf/analytics/spark/spark-defaults.conf
   
   spark.executor.logs.rolling.strategy size  
   spark.executor.logs.rolling.maxSize 10000000  
   spark.executor.logs.rolling.maxRetainedFiles 10  
   


spark.executor.logs.rolling.maxSize contains the maximum size of disk space (in bytes) allocated for log directory. Older log files are deleted when new logs are generated so that the specified maximum size is not exceeded.

spark.executor.logs.rolling.maxRetainedFiles contains the maximum number of log files allowed to be kept in log directory at any give time.

spark.executor.logs.rolling.strategy contains the strategy used to control the log files. From above configuration, the amount of log files is restricted based on the size of log directory. 

For other related configuration, you can see Spark docs

If you want to change the default log directory location, change spark.worker.dir config of <DAS_home>/repository/conf/analytics/spark/spark-defaults.conf like below.
   
   spark.worker.dir /home/ubuntu/sparkout  
   
Make sure to restart the server to apply above configuration to the server.


Friday, July 29, 2016

How to Change WSO2 App Manager Store and Webapp Favicons

If you want to use WSO2 App Manager as the app store of your organization, it is very important to know how to replace default favicon of WSO2 App Manager by your organization logo. Here are the steps to do it.

How to Change Store Favicon


If you want to change the Store favicon, replace favicon.png in <APPM_HOME>/repository/deployment/server/jaggeryapps/store/themes/store/libs/theme-wso2_1.0/images by the logo you want to have.

Then, Store will be like below. You will see the new favicon.



How to Change Webapp Favicons


If you want to change the favicon of all webapps, you need to do some code changes. Here's how to do it.

1. Clone wso2 carbon-mediation code from here. Make you sure to use correct branch as per your App Manager version. For example, you need to get release-4.6.1 version for App Manager 1.2.0.

2. Go to carbon-mediation/components/mediation-initializer/org.wso2.carbon.mediation.transport.handlers directory.

3. Change the icon location of favicon icon in here like this.
   
   response.addHeader("Location", "http://wso2.org/favicon.ico");  
   
4. Build org.wso2.carbon.mediation.transport.handlers component. Then there will be org.wso2.carbon.mediation.transport.handlers-4.6.1.jar in the target folder.

5. Add org.wso2.carbon.mediation.transport.handlers-4.6.1.jar as a patch to App Manager server. For that, create a directory "patch0900" inside <APPM_HOME>/repository/component/patches/ and copy the jar into it.

6. Restart the server.

Favicon of Gateway response will be displayed as below.


Thursday, July 28, 2016

Start Multiple WSO2 App Manager Instances on the Same Computer

If you want to run multiple WSO2 App Manager servers on the same machine, you have to change the default ports with an offset value to avoid port conflicts. The default HTTP and HTTPS ports (without offset) of a WSO2 product are 9763 and 9443 respectively.

Here are the steps to offset ports. Let's assume you want to increase all ports by 1.

1.  Set Offset value to 1 in <APPM_HOME>/repository/conf/carbon.xml
   
   <Offset>1</Offset>  
   
2.  Change ports in AssertionConsumerServiceURL of each ServiceProvider  in <APPM_HOME>/repository/conf/identity/sso-idp-config.xml.
   
   https://localhost:9444/store/acs  
   https://localhost:9444/publisher/acs  
   https://localhost:9444/social/acs  
   
3. Change the port of address uri in <APPM_HOME>/repository/deployment/server/synapse-configs/default/proxy-services/WorkflowCallbackService.xml.
   
 <address uri="https://localhost:9444/store/site/blocks/workflow/workflow-listener/ajax/workflow-listener.jag" format="rest"/>  
   
4. Change the port of endpoint address in <APPM_HOME>/repository/deployment/server/synapse-configs/default/api/_AuthorizeAPI_.xml
   
   <address uri="https://localhost:9444/oauth2/authorize"/>   
   
5. Change  the port of endpoint address in <APPM_HOME>/repository/deployment/server/synapse-configs/default/api/_RevokeAPI_.xml
   
   <address uri="https://localhost:9444/oauth2/revoke"/>   
   
6. Change  the port of endpoint address in <APPM_HOME>/repository/deployment/server/synapse-configs/default/api/_TokenAPI_.xml
   
   <address uri="https://localhost:9444/appmoauth2/token"/>   
   
7. Start the server.

Sunday, July 24, 2016

[WSO2 App Manager] How to add a custom field to a web app

In WSO2 App Manager, when you create a new web app, you have to fill a set of predefined values (eg: Name, Version, Context etc.). If you want to add any custom fields to an app, you can easily do it.

First, Let's see how to add a custom field to UI (Jaggery APIs).

For example,  let's take "Price" as the custom field.

1. Modify <APPM_HOME>/repository/resources/rxt/webapp.rxt. If you want to add "Price" as a mandatory field, add below code to the overview section of rxt file.

   
   <field type="text" required="true">  
     <name>Price</name>  
   </field>  
   

Note : If you don't want add the custom field as mandatory, required="true" part is not necessary.

2. Login to Management console and navigate to Home > Extensions > Configure > Artifact Types and delete "webapp.rxt"

3. Add following block under "fieldProperties" of <APPM_HOME>/repository/deployment/server/jageeryapps/publisher/config/ext/webapp.json

   
   {  
       "field": "overview.price",  
       "name": "editable",  
       "value": true  
   }  
   


4. Add below line to both <APPM_HOME>repository/deployment/server/jageeryapps/publisher/themes/appm/partials/add-asset.hbs
and
<APPM_HOME>repository/deployment/server/jageeryapps/publisher/themes/appm/partials/edit-asset.hbs
files.

   
   {{{ form_render "overview_price" data.fields }}}  
   


Now, Let's see how to add customized fields to the REST APIs.

5. Go to Main -> Browse -> in Management console and navigate to   /_system/governance/appmgt/applicationdata/custom-property-definitions/webapp.json and click on "Edit As Text". Add the custom fields which you want to add.

   
   {  
    "customPropertyDefinitions":  
    [  
     {"name":"overview_price"}  
    ]  
   }  
   

6. Restart App Manager.

7. Sample curl command with custom properties to create a web app is shown in below.

   
 curl -X POST -H "Authorization: Bearer c4cdc394-931f-3e3f-9a91-f2be09fab1de" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{"name":"sampleApp","version":"1.0.0","banner":"36d35be6-1847-4d22-b885-16c653486a77/241eb51a2fdb683b.jpg","thumbnailUrl":"85229347-fcdf-4548-993e-1509dd4242df/dd24c0d2ea4a5697.png","displayName":"sampleApp","description":  
 "description","isSite":"false","context":"sampleContext","appUrL":"http://wso2.com",  
 "transport":"http", "customProperties":[  
   {  
     "name":"overview_price",  
     "value":"10"  
   }  
 ]}' "http://localhost:9763/api/appm/publisher/v1.1/apps/webapp"  
   

8. Web app create page with the newly added custom field(i.e. Price) will be shown as below.



Thursday, July 21, 2016

[WSO2 App Manager] How to create a web app with a thumbnail and banner using REST APIs.

From WSO2 App Manager 1.2.0, most of functionalities are exposed through REST APIs. By this post, let's see how to create a web app with an uploaded thumbnail and banner using REST APIs.

  1. Obtain the consumer key/secret key pair by calling below curl command.

    sample curl command :

    > curl -X POST -H "Authorization: Basic YWRtaW46YWRtaW4=" -H "Content-Type: application/json" -H "Cache-Control: no-cache"  -d '{ "callbackUrl": "www.google.lk", "clientName": "app_11_04_0013121", "tokenScope": "Production", "owner": "admin", "grantType": "password refresh_token", "saasApp": true }' "http://localhost:9763/api/appm/oauth/v1.0/register"

    You will get the response as :

    >  {  "clientId": "dd06pbCzyzN7Ud1onZCb6SoCXA8a",
      "clientName": "app_11_04_0013122",
      "callBackURL": "www.google.lk",
      "clientSecret": "GL56h00WQVMdv1Lx8UGivcMcDqUa"
    }
  2. Generate the access token using the already created OAuth application.

    sample curl command :

    > curl -X POST -H "Content-Type: application/x-www-form-urlencoded" -H "Authorization: Basic ZGQwNnBiQ3p5ek43VWQxb25aQ2I2U29DWEE4YTpHTDU2aDAwV1FWTWR2MUx4OFVHaXZjTWNEcVVh" -H "Cache-Control: no-cache" -H "Postman-Token: b418193e-fe30-5f91-fc3c-e41231201a7f" -d 'username=admin&amp;password=admin&amp;grant_type=password&amp;scope=appm:read appm:administration appm:create' "http://localhost:9763/oauth2/token"

    You will get the response as :
    {
     "scope": "appm:administration appm:create appm:read",   "token_type": "Bearer",   "expires_in": 3600,   "refresh_token": "6bda08b3-f44a-31be-988b-6630347357c3",   "access_token": "c4cdc394-931f-3e3f-9a91-f2be09fab1de"
    }
  3. Upload images which you want to upload.

    URL
    http://apis.wso2.com/api/appm/publisher/v1.1/apps/static-contents
    HTTP Method
    POST
    Scope
    appm:create

    sample curl command :


     > curl -X POST -H "Authorization: Bearer 03de85fc-6009-3831-b7b3-206aa7cef885" -H "Content-Type: multipart/form-data" -F "file=@/home/lakshani/Downloads/wso2.png" "http://localhost:9763/api/appm/publisher/v1.1/apps/static-contents?appType=webapp"

    You will get the response as :

    > {"id":"85229347-fcdf-4548-993e-1509dd4242df/dd24c0d2ea4a5697.png"}

  4. Create the web app with the uploaded images. For thumbnailUrl and banner of app create request, you can use "id" in the 3rd step's response.

    URL
    http://apis.wso2.com/api/appm/publisher/v1.1/apps/{appType}
    HTTP Method
    POST
    Scope
    appm:create
sample curl command :

>  curl -X POST -H "Authorization: Bearer 03de85fc-6009-3831-b7b3-206aa7cef885" -H "Content-Type: application/json" -H "Cache-Control: no-cache" -d '{"name":"testApp","version":"1.0.0","banner":"36d35be6-1847-4d22-b885-16c653486a77/241eb51a2fdb683b.jpg","thumbnailUrl":"85229347-fcdf-4548-993e-1509dd4242df/dd24c0d2ea4a5697.png","displayName":"testApp","description":"description","isSite":"false","context":"sampleContext","appUrL":"http://wso2.com","transport":"http"}' "http://localhost:9763/api/appm/publisher/v1.1/apps/webapp"

You will get the response as :

> {"AppId":"7ab144d1-a6da-4dbf-b361-1f5b62c2cdf7"}

You can go to the publisher UI and verify whether app creation with Images is succeed or not.
That's all :)




Monday, July 18, 2016

[WSO2 App Manager] How to add a Business Owner to a web app?

WSO2 App Manager introduces concept of business owner from 1.2.0 onward. There are few steps to attach a business owner to a web app.

First let's see how to create a new business owner.

  1. Start App Manager.
  2. Login to Admin-dashboard of WSO2 App Manager using admin/admin credentials by https://localhost:9443/admin-dashboard
  3. Go to Business Owners > Add Business Owner

  4. Add business owner information like below.


  5. If you want to add more details about business owner (ex: Telephone number, Organization etc.), you can click on "Add New Property" button and add more information.



    If the business owner wants to show/hide some information from the public(store), he can tick/untick "Show In Store" property to the property. 
  6. If you want to edit or delete an exiting business owner, you can find edit and delete buttons to a relevant business owner from Business Owners > List Owners


  7.  Then let's see how to set a business owner to a web app. Select a business owner by clicking on the business owners drop down list in web app create page.


  8. You can see more details of a business owner from web app overview page in publisher.


  9. If the app is in published state you can see the business owner details from the store as well. (Note : In store, it will show only the attributes that are allowed to show in store.)


  10. If someone wants to get all webapps of a given business owner, you can do it from the store search as well.

Friday, July 15, 2016

How to enable Solr Indexing logs in WSO2 Products

Just add following two lines to <CARBON_HOME>/repository/config/log4j.properties 

log4j.logger.org.wso2.carbon.registry.indexing.solr.SolrClient=DEBUG
log4j.logger.org.wso2.carbon.registry.indexing.ResourceSubmitter=DEBUG

Then Restart the server.

You will see debug logs in console while registry resources are indexing like below.

How to Set up WSO2 App Manager with Oracle

These steps can be used to configure App Manager standalone with Oracle.
  1. Login to Oracle server and create following tables.
  2. Edit master-datasource.xml in <AppM_HOME>/repository/conf/datasources as follow.
    Note: <defaultautocommit>false</defaultautocommit> property is mandatory for "jdbc/WSO2AM_DB" datasource.
  3. Edit social.xml in <AppM_HOME>/repository/conf as follow.
  4. Copy the Oracle JDBC driver, which compatible to your Oracle database, to <AppM_HOME>/repository/components/lib
  5. Start the server with -Dsetup sh
    wso2server.sh -Dsetup

Monday, July 11, 2016

How to connect WSO2 App Manager with WSO2 DAS

Configuring MYSQL

  1. Create new database called APPM_STATS_DB in MYSQL server.
  2. Create tables inside the created database by executing script.

Configuring WSO2 DAS

  1. Download WSO2 DAS 3.0.1
  2. If App Manager and DAS are running on the same machine, follow this step.
    Set Offset value to 3 in <DAS_HOME>/repository/conf/carbon.xml

  3. Specify the datasource definition  in the  <DAS_HOME>/repository/conf/datasources/master-datasources.xml
     to connect early created APPM_STATS_DB database.

    <datasource> <name>WSO2AM_STATS_DB</name> <description>The datasource used for setting statistics to APP Manager</description> <jndiConfig> <name>jdbc/WSO2AM_STATS_DB</name> </jndiConfig> <definition type="RDBMS"> <configuration> <url>jdbc:mysql://localhost:3306/APPM_STATS_DB?autoReconnect=true</url> <username>db_username</username> <password>db_password</password> <driverClassName>com.mysql.jdbc.Driver</driverClassName> <maxActive>50</maxActive> <maxWait>60000</maxWait> <testOnBorrow>true</testOnBorrow> <defaultAutoCommit>false</defaultAutoCommit> <validationQuery>SELECT 1</validationQuery> <validationInterval>30000</validationInterval> </configuration> </definition> </datasource>

    Note : Auto Commit option should be disable when working with DAS.
  4. Copy the database driver to <DAS_HOME>/repository/components/lib folders.
  5. Restart DAS server.
  6. Login to DAS Admin console.
  7. Navigate to Home > Manage > Carbon Applications > Add and upload the .car file

Configuring WSO2 App Manager


  1. Change following configurations in <APPM_HOME>/repository/conf/app-manager.xml
  2. Specify the datasource definition  in the  <APPM_HOME>/repository/conf/datasources/master-datasources.xml
    <datasource> <name>WSO2AM_STATS_DB</name> <description>The datasource used for setting statistics to APP Manager</description> <jndiConfig> <name>jdbc/WSO2AM_STATS_DB</name> </jndiConfig> <definition type="RDBMS"> <configuration> <url>jdbc:mysql://localhost:3306/APPM_STATS_DB?autoReconnect=true</url> <username>db_username</username> <password>db_password</password> <driverClassName>com.mysql.jdbc.Driver</driverClassName> <maxActive>50</maxActive> <maxWait>60000</maxWait> <testOnBorrow>true</testOnBorrow> <defaultAutoCommit>false</defaultAutoCommit> <validationQuery>SELECT 1</validationQuery> <validationInterval>30000</validationInterval> </configuration> </definition> </datasource>
  3. Copy the database driver to <APPM_HOME>/repository/components/lib folders.
  4. Restart App manager.

Saturday, July 2, 2016

How to Enable SSL between WSO2 DSS and Cassandra

1. Connect WSO2 DSS with cassandra using this doc
2. Enable client-node encryption from cassandra.yaml  in <cassandra_home>/conf
client_encryption_options:
    enabled: true
    keystore: [Key store path]
    keystore_password: [Key store password]
    cipher_suites: [TLS_RSA_WITH_AES_128_CBC_SHA]
2. Restart Cassandra.
3. Please add following tag under <config> tag in dataservice.
<property name="enableSSL">true</property>
4. Install Cassandra certificate to ESB client-truststore.
keytool -import -v -trustcacerts -alias <cert_alias> -file <cert_file> -keystore <ESB_HOME>/repository/resources/security/client-truststore.jks
5. In <ESB_HOME>/bin/wso2server.sh add the following system properties.
    -Dssl.protocol=TLS
    -Dssl.cipher.suites=TLS_RSA_WITH_AES_128_CBC_SHA
    -Dssl.store.type=JKS
    -Dssl.truststore=[Trust store path]
    -Dssl.truststore.password=[Trust store password]
6. Restart the DSS.