Apigee : Deploy proxy with Maven


Hello All,
As you all know, there are are so many ways to construct a structure for modular project in Information Technology. We can create our application in any of the following ways,

  • Monolithic Architecture,
  • Microservice Based Architecture

When the architecture is microservice based, some API platform has to be used to maintain the performance measurements of the microservices. With the API platform software, we can track the request as well as the responses coming to a microservice route URL and how many calls are made to this at a given period of time.

In this blog, we are going to use Apigee as the API platform. Apigee follows a proxy based architecture and deployment of the Proxy can be made via various ways.

What is Apigee Maven plugin ?

Apigee maven plugin maven bundle is a plugin provided by Apigee which is used to create aproxy as same as created on Apigee. The proxy bundle is a collection of the following contents,

  • Proxies,
  • Policies,
  • Resources

In the proxy bundle project, we are going to show a hello message to the user. And every time the proxy is deployed, it will have a new revision.

Creating a Proxy Bundle

Create a maven project containing an Apigee module as below,

z

In the above project structure,

  • apigee module defines the proxies we are a user wish to deploy on Apigee,
  • HelloWorld is the proxy bundle which contains all the required policies and resources for proxy creation,
  • shared-pom file is an xml file which defines the plugins for Apigee and the deployment environment information.

First we include the shared-pom file in the parent pom of the project, as a relative path as below,

<parent>
   <groupId>apigee</groupId>
   <artifactId>apigee-deploy-parent</artifactId>
   <version>1.1</version>
   <relativePath>../shared-pom.xml</relativePath>
</parent>

Now we provide the plugins provided by Apigee in the shared-pom.xml and include a profile. A profile contains the following information,

  • Environment name – It is test in our project. It can be anything prod, test or any custome generated by a paid account on Apigee,
  • Organization name – It is the name of the organization on which the proxy bundle has to be deployed,
  • Host URL – It is the host URL of the apigee account,
  • Api version – It is the name of the version a user need to put for the bundle,
  • Credentials – It defines the username and password of the user account if it required by the Apigee.

According to above information, Profile is defined in our project as below,

<profiles>
   <profile>
      <id>test</id> //Deployment environment
      <properties>
         <org>organizationName</org>
<options>validate</options>
         <apigee.profile>test</apigee.profile>
         <apigee.env>test</apigee.env>
         <apigee.hosturl>https://api.enterprise.apigee.com</apigee.hosturl>
         <apigee.apiversion>v1</apigee.apiversion>
         <apigee.org>${org}</apigee.org>
         <apigee.username>${username}</apigee.username>
         <apigee.password>${password}</apigee.password>
         <apigee.options>${options}</apigee.options>
      </properties>
   </profile>
</profiles>

Now to include Apigee plugin we need to define the plugins as below,

<plugins>
   <plugin>
      <artifactId>maven-resources-plugin</artifactId>
      <version>2.6</version>
      <executions>
         <execution>
            <phase>package</phase>
            <goals>
               <goal>copy-resources</goal>
            </goals>
            <configuration>
               <overwrite>true</overwrite>
               <encoding>UTF-8</encoding>
               <echo message="basedir parent : ${basedir}" />
               <outputDirectory>${basedir}/target/apiproxy</outputDirectory>
               <resources>
                  <resource>
                     <directory>apiproxy</directory>
                  </resource>
               </resources>
            </configuration>
         </execution>
      </executions>
   </plugin>
   <plugin>
      <groupId>io.apigee.build-tools.enterprise4g</groupId>
      <artifactId>apigee-edge-maven-plugin</artifactId>
      <version>1.1.5</version>
      <executions>
         <execution>
            <id>configure-bundle</id>
            <phase>package</phase>
            <goals>
               <goal>configure</goal>
            </goals>
         </execution>
         <execution>
            <id>deploy-bundle</id>
            <phase>install</phase>
            <goals>
               <goal>deploy</goal>
            </goals>
         </execution>
      </executions>
   </plugin>
</plugins>

Deployment to Apigee Environment

Open the terminal and go to directory ..ApigeeMavenDemo/apigee/HelloWorld$ and use the following command,

mvn install -P<environmentName> -Dusername=<username> -Dpassword=<password> -Dorg=<organizationName>

Above command defines the following properties,

  • Environment Name on which the proxy has to be deployed,
  • Username of the user’s account on Apigee,
  • Password of the user’s account on Apigee,
  • Organization Name of the user’s account on Apigee

Note : We need to use the following command in case a paid account has been created and an official environment has been setup for deployment,

mvn apigee-enterprise:deploy -P<environmentName> -Dusername=<username> -Dpassword=<password> -Dorg=<organizationName>

After we execute this command successfully, following output will be shown in the terminal,

y

In the final output it shows the Build Success along with the Deployed Revision number as 5 in our deployment. In the project we have created, we set up environment to create a new Revision every time the deployment is done.

As we notice, following tag,

<overwrite>true</overwrite>

 defines the behavior of the deployment Revision. If it is set to true, then new revision will be created, otherwise revision will not be created and we need to update the existing revision.

Proxy Execution

In our proxy, we are showing the hello message to the user and then stores the message into Cache of the Apigee 60 seconds.

Following is the way we are executing the proxy endpoint on Apigee Environment,

a

Following is the output after we execute it thorough the Apigee Environment,

s

 

 

 

 

 

 

 

 

Now as we can see first request executed with in 362 milliseconds because it generated a response and inserted the response into Cache for 60 seconds. After that all the request except the request number 8, took the minimum time for their execution, as they are reading the response from the Cache.

That’s how you deploy the Apigee Proxy with maven on Apigee.

You can find the complete project here.

Keep learning,

Thank You !!

About Harsh Sharma Khandal

Harsh is a Sr. Software Consultant at Knoldus Software LLP with 4 year of experience. He is a fan of programming standards and conventions. He has good knowledge of Scala, Java, 3D Modeling and 3D animation. His current passions include utilizing the power of Scala, Akka and Play to make reactive applications. He is a technologist and is never too far away from the keyboard. He believes in standard coding practices. His focus always remains on practical work. He has Master's in Computer Applications from Rajasthan Technical University, Kota. His hobbies include reading books and writing the code in multiple ways to find the best way it can be represented.
This entry was posted in Scala. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s