Friday, October 20, 2017

How To Configure Multiple Sub Domain in NGINX?

While creating my own Virtual Box CI/CD which include Jenkins, Artifactory and Git, I noticed that I need to have multiple ports for each application, so I decided to use NGINX to be my proxy server.

First, I set my DNS or in my local machine, I added an alias into my local (MacOS) /etc/hosts file

myadmin@myHostOS$: sudo nano /etc/hosts
# Add the following host aliases

192.168.1.101 interface101.vbox
192.168.1.101 artifactory.interface101.vbox
192.168.1.101 jenkins.interface101.vbox
192.168.1.101 git.interface101.vbox

# Save

I login to my Virtual Box instance that has the nginx in it.

You can have one file for all the configuration or you can have one for each sub-domain-configuration. I prefer one for each:


Step 1) Lets create the git configuration

admin@myGuestOS:$ sudo nano /etc/nginx/site-available/git-interface101-vbox.conf
# Add the following config
server {
  listen 80:
  server_name git.interface101.vbox;
  location / {
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Host $http_host;
     proxy_pass http://127.0.0.1:10112/; # Note: 10112 is the Git port
  }
}  
# Save

After saving the file, let's create a soft link in sites-enabled
admin@myGuestOS:$ ln -sf /etc/nginx/site-available/git-interface101-vbox.conf /etc/nginx/site-enabled/git-interface101-vbox.conf

Step 2) Lets create the artifactory configuration:

admin@myGuestOS:$ sudo nano /etc/nginx/site-available/artifactory-interface101-vbox.conf
# Add the following config
server {
  listen 80:
  server_name artifactory.interface101.vbox;
  location / {
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Host $http_host;
     proxy_pass http://127.0.0.1:8081/; # Note: 8081 is the Artifactory port
  }
}  
# Save 

After saving the file, let's create a soft link in sites-enabled
admin@myGuestOS:$ ln -sf /etc/nginx/site-available/artifactory-interface101-vbox.conf /etc/nginx/site-enabled/artifactory-interface101-vbox.conf

Step 3) Lets create the Jenkins configuration:

admin@myGuestOS:$ sudo nano /etc/nginx/site-available/jenkins-interface101-vbox.conf
# Add the following config
server {
  listen 80:
  server_name jenkins.interface101.vbox;
  location / {
     proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
     proxy_set_header Host $http_host;
     proxy_pass http://127.0.0.1:8080/; # Note: 8080 is the Jenkins port
  }
}
# Save 

After saving the file, let's create a soft link in sites-enabled
admin@myGuestOS:$ ln -sf /etc/nginx/site-available/jenkins-interface101-vbox.conf /etc/nginx/site-enabled/jenkins-interface101-vbox.conf

Step 4) Lets restart the nginx service
admin@myGuestOS:$ sudo service nginx restart

Step 5) Lets verify the URL now.

From your Host OS, open a browser and visit the following URL:

http://artifactory.interface101.vbox for Artifactory
http://jenkins.interface101.vbox for Jenkins
http://git.interface101.vbox for Git

Note: Make sure Artifactory, Jenkins and Git are running before you visit their URL

Have fun and enjoy!

Cheers!

Thursday, April 13, 2017

DataWeave 101!

DataWeave! DataWeave! DataWeave! It's fun to do dataweaving....

How to create a lookup function in DataWeave?

%var gendertable = { "Male": "M", "Female": "F", "Unknown": "U"}
- - -
...
genderCode: gendertable[payload.inputGender]
...

How to display a data with a valid xml descriptor?

Input:
<root>
    <Address>
        <country>USA</country>
        <type>
            <reference descriptor="Home">nvm</reference>
        </type>
    </Address>
    <Address>
        <country>PH</country>
        <type>
            <reference descriptor="Work">nvm</reference>
        </type>
    </Address>
</root>

Transform:

Option 1 =

%dw 1.0
%output application/json
---
payload.root.*Address map (
      { homeCountry: $.country } when $.type.reference.@descriptor == "Home" otherwise { homeCountry: "" }
)

Option 2 =

(
  payload.root.*Address 
    filter $.type.reference.@descriptor == 'Home' 
    map {
      homeCountry: $.country
    }
)[0]

Output:

{
    "homeCountry" : "USA"
}


How to use the value to be the key?

Input:

<ns6:ProductListResponse xmlns:ns5="http://www.twcable.com/common/types/v1x0"
  xmlns:ns6="http://www.twcable.com/soa/types/csg/v2x21">
         <ns6:Business>
            <ns6:BusinessUnit>815020000070</ns6:BusinessUnit>
         </ns6:Business>
         <ns6:ProductList>
            <ns6:Count>2</ns6:Count>
            <ns6:Product>
               <ns6:Code>$F</ns6:Code>
               <ns6:AvailableCatalogIdentifier>60060840415</ns6:AvailableCatalogIdentifier>
               <ns6:CatalogIdentifier>600606044</ns6:CatalogIdentifier>
               <ns6:ChildCount>2</ns6:ChildCount>
               <ns6:ParameterCount>1</ns6:ParameterCount>
               <ns6:Parameter>
                  <ns6:Identifier>6006060093417</ns6:Identifier>
                  <ns6:Name>FROM_REFERENCE_NAME</ns6:Name>
                  <ns6:DomainDefinition>N</ns6:DomainDefinition>
               </ns6:Parameter>
            </ns6:Product>
            <ns6:Product>
               <ns6:Code>$H</ns6:Code>
               <ns6:AvailableCatalogIdentifier>60060840416</ns6:AvailableCatalogIdentifier>
               <ns6:CatalogIdentifier>600606045</ns6:CatalogIdentifier>
               <ns6:ParameterCount>2</ns6:ParameterCount>
               <ns6:Parameter>
                  <ns6:Identifier>6006060093453</ns6:Identifier>
                  <ns6:Name>RSTRCT CALLER ID</ns6:Name>
               </ns6:Parameter>
               <ns6:Parameter>
                  <ns6:Identifier>6006060093446</ns6:Identifier>
                  <ns6:Name>BLOCK 900/976</ns6:Name>
                </ns6:Parameter>
           </ns6:Product>
       </ns6:ProductList>
</ns6:ProductListResponse>

Transform:

%dw 1.0
%output application/java
%var products = payload.ProductListResponse.ProductList.*Product
---
{
  Status:"Success",
  Response: {(
    products map {
      ($.CatalogIdentifier): {($.*Parameter map {
          ($.Name): $.Identifier
        }
      )}
    }
  )}
}

Output:

Status:"Success",
Response:{
  600606044 : {
    "FROM_REFERENCE_NAME","6006060093417"
  },
  600606045 : {
    "RSTRCT CALLER ID":"6006060093453",
    "BLOCK 900/976":"6006060093446"
  }
}



How can I filter the objects where "UniqueId": "0"

{
    Header: {
        MsgId: flowVars.msgCId,
        Key: flowVars.key
    },
    Data: {
        Addresses: 
payload.ns0#GetCustomerDataResponse.ns0#OCust.*ns0#OCadRecord[?($.ns0#OCAddrId != "0")]
 map ((oCadRecord , indexOfOCadRecord) -> {
            Type: oCadRecord.ns0#OCAddrUsageCd,
            DescriptionOfOther: oCadRecord.ns0#OCAddrDesc,
            CountryCd: oCadRecord.ns0#OCCntryCd,
            Line1: oCadRecord.ns0#OCStAddrTx,
            Line2: oCadRecord.ns0#OCStAddr2Tx,
            Line3: oCadRecord.ns0#OCStAddr3Tx,
            City: oCadRecord.ns0#OCAddrCityNm,
            State: oCadRecord.ns0#OCAddrStateCd,
            Zip: oCadRecord.ns0#OCPostalCd,
            Zip4: oCadRecord.ns0#OCUsZipSuffCd,
            UniqueId: oCadRecord.ns0#OCAddrId
        })
    }
}




MuleSoft MUnit Cheatsheet!

MUnit!

How to Set Inbound Parameter?

<munit:set payload="#[]" doc:name="Set Message">
   <munit:inbound-properties>
       <munit:inbound-property key="http.query.params" value="#[['param':'a-param']]"/>
   </munit:inbound-properties>
</munit:set>



Sunday, January 1, 2017

Dreamweaver CS 6 not able to run in MacOS using latest JDK 1.7

I have updated my JDK on my MacOS using JDK 1.8.x, unfortunately, my Dreamweaver CS 6 stopped working, but, I found a solution,

Just download and install the patch from Apple

https://support.apple.com/kb/DL1572?locale=en_US

Good luck and happy dreamweavering!