Skip to main content

Create an application in WSO2 App Cloud using Maven Plugins

In Application Development life cycle continuous integration is an important factor. How easy to get something deployed which is built in a build server. You can simply use maven exec plugin to run Curl commands to call rest apis.

Following is an example. Before call the create application api we need to call login api and get created a logged in session. To do that we need to call login api with -c cookies and we need to call create application api with -b cookies.

       <plugin>  
         <groupId>org.codehaus.mojo</groupId>  
         <artifactId>exec-maven-plugin</artifactId>  
         <version>1.2</version>  
         <executions>  
           <execution>  
             <id>login</id>  
             <phase>deploy</phase>  
             <goals>  
               <goal>exec</goal>  
             </goals>  
             <configuration>  
               <executable>curl</executable>  
               <arguments>  
                 <argument>-v</argument>  
                 <argument>-k</argument>  
                 <argument>-c</argument>  
                 <argument>cookies</argument>  
                 <argument>-X</argument>  
                 <argument>POST</argument>  
                 <argument>-F</argument>  
                 <argument>action=login</argument>  
                 <argument>-F</argument>  
                 <argument>userName=<email @ replaced with .>@<tenant domain></argument>  
                 <argument>-F</argument>  
                 <argument>password=<password></argument>  
                 <argument>https://newapps.cloud.wso2.com/appmgt/site/blocks/user/login/ajax/login.jag</argument>  
               </arguments>  
             </configuration>  
           </execution>  
           <execution>  
             <id>create application</id>  
             <phase>deploy</phase>  
             <goals>  
               <goal>exec</goal>  
             </goals>  
             <configuration>  
               <executable>curl</executable>  
               <arguments>  
                 <argument>-v</argument>  
                 <argument>-k</argument>  
                 <argument>-b</argument>  
                 <argument>cookies</argument>  
                 <argument>-X</argument>  
                 <argument>POST</argument>  
                 <argument>https://newapps.cloud.wso2.com/appmgt/site/blocks/application/application.jag</argument>  
                 <argument>-F</argument>  
                 <argument>action=createApplication</argument>  
                 <argument>-F</argument>  
                 <argument>applicationName=Buzzwords&#x20;Backend</argument>  
                 <argument>-F</argument>  
                 <argument>applicationDescription=API&#x20;Producer&#x20;application&#x20;for&#x20;buzzword&#x20;sample</argument>  
                 <argument>-F</argument>  
                 <argument>conSpecMemory=512</argument>  
                 <argument>-F</argument>  
                 <argument>conSpecCpu=300</argument>  
                 <argument>-F</argument>  
                 <argument>runtime=2</argument>  
                 <argument>-F</argument>  
                 <argument>appTypeName=mss</argument>  
                 <argument>-F</argument>  
                 <argument>applicationRevision=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}</argument>  
                 <argument>-F</argument>  
                 <argument>uploadedFileName=${artifactId}-${version}.jar</argument>  
                 <argument>-F</argument>  
                 <argument>runtimeProperties=runtimeProperties=[{"key":"k1","value":"e1"}]</argument>  
                 <argument>-F</argument>  
                 <argument>tags=[{"key":"k1","value":"t1"}]</argument>  
                 <argument>-F</argument>  
                 <argument>fileupload=@${project.build.directory}/${artifactId}-${version}.jar</argument>  
                 <argument>-F</argument>  
                 <argument>isFileAttached=true</argument>  
                 <argument>-F</argument>  
                 <argument>isNewVersion=true</argument>  
               </arguments>  
             </configuration>  
           </execution>  
         </executions>  
       </plugin>  


You don't have to deploy it each time you build it. So you can set the phase of the executions to deploy as above. But it might try to deploy the artifact to nexus. To stop that you can skip deploy by adding following.

       <plugin>  
         <artifactId>maven-deploy-plugin</artifactId>  
         <version>2.7</version>  
         <configuration>  
           <skip>true</skip>  
         </configuration>  
       </plugin>  

In App Cloud to deploy the changes we need to create new version. So to do that we will always need to increase the version name of the create request. You can use helper plugin and replace plugin as a combination. With following configuration I am creating a property and I am replacing them in each deploy with next patch version number.

       <plugin>  
         <groupId>org.codehaus.mojo</groupId>  
         <artifactId>build-helper-maven-plugin</artifactId>  
         <version>1.10</version>  
         <executions>  
           <execution>  
             <phase>deploy</phase>  
             <id>parse-version</id>  
             <goals>  
               <goal>parse-version</goal>  
             </goals>  
             <configuration>  
               <versionString>${appcloud.version}</versionString>  
             </configuration>  
           </execution>  
         </executions>  
       </plugin>  
       <plugin>  
         <groupId>com.google.code.maven-replacer-plugin</groupId>  
         <artifactId>replacer</artifactId>  
         <version>1.5.3</version>  
         <executions>  
           <execution>  
             <phase>deploy</phase>  
             <goals>  
               <goal>replace</goal>  
             </goals>  
           </execution>  
         </executions>  
         <configuration>  
           <file>pom.xml</file>  
           <replacements>  
             <replacement>  
               <token>${appcloud.version}</token>  
               <value>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}</value>  
             </replacement>  
           </replacements>  
         </configuration>  
       </plugin>  


And you need to have a property like below as well.

   <properties>  
     <appcloud.version>1.0.7</appcloud.version>  
   </properties>  

Rest of the details of the apis can be found in [1]. Following is the full build tag and the properties tag in the pom.xml. If you run mvn clean install this would not get triggered. This will only trigger when you run mvn deploy.


 <build>  
     <plugins>  
       <plugin>  
         <groupId>org.codehaus.mojo</groupId>  
         <artifactId>build-helper-maven-plugin</artifactId>  
         <version>1.10</version>  
         <executions>  
           <execution>  
             <phase>deploy</phase>  
             <id>parse-version</id>  
             <goals>  
               <goal>parse-version</goal>  
             </goals>  
             <configuration>  
               <versionString>${appcloud.version}</versionString>  
             </configuration>  
           </execution>  
         </executions>  
       </plugin>  
       <plugin>  
         <groupId>com.google.code.maven-replacer-plugin</groupId>  
         <artifactId>replacer</artifactId>  
         <version>1.5.3</version>  
         <executions>  
           <execution>  
             <phase>deploy</phase>  
             <goals>  
               <goal>replace</goal>  
             </goals>  
           </execution>  
         </executions>  
         <configuration>  
           <file>pom.xml</file>  
           <replacements>  
             <replacement>  
               <token>${appcloud.version}</token>  
               <value>${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}</value>  
             </replacement>  
           </replacements>  
         </configuration>  
       </plugin>  
       <plugin>  
         <groupId>org.codehaus.mojo</groupId>  
         <artifactId>exec-maven-plugin</artifactId>  
         <version>1.2</version>  
         <executions>  
           <execution>  
             <id>login</id>  
             <phase>deploy</phase>  
             <goals>  
               <goal>exec</goal>  
             </goals>  
             <configuration>  
               <executable>curl</executable>  
               <arguments>  
                 <argument>-v</argument>  
                 <argument>-k</argument>  
                 <argument>-c</argument>  
                 <argument>cookies</argument>  
                 <argument>-X</argument>  
                 <argument>POST</argument>  
                 <argument>-F</argument>  
                 <argument>action=login</argument>  
                 <argument>-F</argument>  
                 <argument>userName=<email @ replaced with .>@<tenant domain></argument>  
                 <argument>-F</argument>  
                 <argument>password=<password></argument>  
                 <argument>https://newapps.cloud.wso2.com/appmgt/site/blocks/user/login/ajax/login.jag</argument>  
               </arguments>  
             </configuration>  
           </execution>  
           <execution>  
             <id>create application</id>  
             <phase>deploy</phase>  
             <goals>  
               <goal>exec</goal>  
             </goals>  
             <configuration>  
               <executable>curl</executable>  
               <arguments>  
                 <argument>-v</argument>  
                 <argument>-k</argument>  
                 <argument>-b</argument>  
                 <argument>cookies</argument>  
                 <argument>-X</argument>  
                 <argument>POST</argument>  
                 <argument>https://newapps.cloud.wso2.com/appmgt/site/blocks/application/application.jag</argument>  
                 <argument>-F</argument>  
                 <argument>action=createApplication</argument>  
                 <argument>-F</argument>  
                 <argument>applicationName=Buzzwords&#x20;Backend</argument>  
                 <argument>-F</argument>  
                 <argument>applicationDescription=API&#x20;Producer&#x20;application&#x20;for&#x20;buzzword&#x20;sample</argument>  
                 <argument>-F</argument>  
                 <argument>conSpecMemory=512</argument>  
                 <argument>-F</argument>  
                 <argument>conSpecCpu=300</argument>  
                 <argument>-F</argument>  
                 <argument>runtime=2</argument>  
                 <argument>-F</argument>  
                 <argument>appTypeName=mss</argument>  
                 <argument>-F</argument>  
                 <argument>applicationRevision=${parsedVersion.majorVersion}.${parsedVersion.minorVersion}.${parsedVersion.nextIncrementalVersion}</argument>  
                 <argument>-F</argument>  
                 <argument>uploadedFileName=${artifactId}-${version}.jar</argument>  
                 <argument>-F</argument>  
                 <argument>runtimeProperties=runtimeProperties=[{"key":"k1","value":"e1"}]</argument>  
                 <argument>-F</argument>  
                 <argument>tags=[{"key":"k1","value":"t1"}]</argument>  
                 <argument>-F</argument>  
                 <argument>fileupload=@${project.build.directory}/${artifactId}-${version}.jar</argument>  
                 <argument>-F</argument>  
                 <argument>isFileAttached=true</argument>  
                 <argument>-F</argument>  
                 <argument>isNewVersion=true</argument>  
               </arguments>  
             </configuration>  
           </execution>  
         </executions>  
       </plugin>  
       <plugin>  
         <artifactId>maven-deploy-plugin</artifactId>  
         <version>2.7</version>  
         <configuration>  
           <skip>true</skip>  
         </configuration>  
       </plugin>  
     </plugins>  
   </build>  
   <properties>  
     <microservice.mainClass>org.wso2.carbon.mss.sample.Application</microservice.mainClass>  
     <appcloud.version>1.0.7</appcloud.version>  
   </properties>  


[1] https://docs.wso2.com/display/AppCloud/Published+APIs

Comments

Popular posts from this blog

Consuming File System artifacts from Kubernetes Pods

When you are deploying an application which contains artifacts written on file system dynamically withing kubernetes (k8s), for example a tomcat server exposed to outside to deploy war files, you need to make sure the file system state is preserved always. Otherwise if the pod goes down, you might loose data. So one solution is to mount an external disk. Yes indeed you can do that. But how robust is that solution. Say something happened to the external disk. How can you recover the data? Use several disks and rsync to sync the data. Sounds a robust solution. Say you want to increase the reliability. And what happens if rsync process get killed. How much will it cost to make it's reliability closer to 100%? We have a robust, simple solution. It's using gluster to save data. [1] [2] We install a pod named gluster for each node. There is an additional disk attached to each node which will be used as the data storage for gluster. This disk is formatted in a special forma...

Generate JWT access tokens from WSO2 Identity Server

In Identity Server 5.2.0 we have created an interface to generate access tokens. Using that we have developed a sample to generate JWT tokens. You can find that sample under msf4j samples[1][2]. If you are build it as it is you will need to use Java 8 to build since msf4j is developed on Java 8. So you will need to run Identity Server on Java 8 as well. After building the project[2] please copy the jar inside target directory to $IS_HOME/repository/components/dropins/ directory. And then please add the following configuration to Identity.xml which is placed under $IS_HOME/repository/conf/identity/ folder inside tag OAuth . <IdentityOAuthTokenGenerator>com.wso2.jwt.token.builder.JWTAccessTokenBuilder</IdentityOAuthTokenGenerator> Then go to the database you used to store oauth tokens (This is the database pointed from the datasource you mentioned in the $IS_HOME/repository/conf/identity/identity.xml) and then alter the size of the column ACCESS_TOKEN of the tab...

Integrate New Relic with WSO2 API Manager

In WSO2 API Manager, we have two transports. HTTP servlet transport and Passthru / NIO transport. All the web application requests are handled through HTTP servlet transport which is on 9763 port and 9443 port with ssl and here we are using tomcat inside WSO2 products. All the service requests are served via Passthru / NIO transport which is on 8082 and 8243 with ssl. When we integrate API Manager with new relic in the way discussed in blog posts [5],[6], new relic only detects the calls made to tomcat transports. So we couldn’t get the API calls related data OOTB. But by further analyzing new relic APIs I managed to find a workaround for this problem. New relic supports publishing custom events via their insights api[1]. So what we can do is publish these data via custom API handler[2]. Following is a sample implementation of a handler that I used to test the scenario. I will attach the full project herewith[7]. I have created an osgi bundle with this implementation so after building ...