<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Vikrant Kandgaonkar on Medium]]></title>
        <description><![CDATA[Stories by Vikrant Kandgaonkar on Medium]]></description>
        <link>https://medium.com/@vikrant.kandgaonkar?source=rss-ff44000f0b31------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*EHMjYe3FhRFsP--Slw0U4Q.jpeg</url>
            <title>Stories by Vikrant Kandgaonkar on Medium</title>
            <link>https://medium.com/@vikrant.kandgaonkar?source=rss-ff44000f0b31------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 21:04:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@vikrant.kandgaonkar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Jenkins last successful build — Quick view from your terminal]]></title>
            <link>https://medium.com/@vikrant.kandgaonkar/jenkins-last-successful-build-quick-view-from-your-terminal-244a00c9d270?source=rss-ff44000f0b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/244a00c9d270</guid>
            <category><![CDATA[shell]]></category>
            <category><![CDATA[jenkins]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[build]]></category>
            <category><![CDATA[script]]></category>
            <dc:creator><![CDATA[Vikrant Kandgaonkar]]></dc:creator>
            <pubDate>Sun, 03 Oct 2021 13:05:54 GMT</pubDate>
            <atom:updated>2021-10-03T13:05:54.686Z</atom:updated>
            <content:encoded><![CDATA[<h3>Jenkins last successful build — Quick view from your terminal</h3><p><a href="https://www.jenkins.io/"><em>Jenkins</em></a> is a popular CI/CD tool. Each build in Jenkins is associate with a build number. Sometimes this is used for versioning the artifacts which can be a jar file or a docker image etc. Often we need to know the build number of the last successful build. To get this, every time you have to go to Jenkins UI and then navigate to the job. It’s a mundane activity. So I thought of writing a script which can give this information right from the terminal.</p><p>For this I used <a href="https://www.jenkins.io/doc/book/using/remote-access-api/"><em>Jenkins REST API</em></a>. It can be invoked using username and an authentication token. We’ll get to the part about how to get this token soon.</p><p>Here is the API for getting last successful build’s information.</p><pre>curl -s <a href="http://localhost:8000/job/test-job-1/lastSuccessfulBuild/api/json">http://localhost:8000/job/test-job-1/lastSuccessfulBuild/api/json</a> --user &lt;your-username&gt;:&lt;authentication-token&gt; |jq</pre><pre>{<br>  &quot;_class&quot;: &quot;hudson.model.FreeStyleBuild&quot;,<br>  &quot;actions&quot;: [<br>    {<br>      &quot;_class&quot;: &quot;hudson.model.CauseAction&quot;,<br>      &quot;causes&quot;: [<br>        {<br>          &quot;_class&quot;: &quot;hudson.model.Cause$UserIdCause&quot;,<br>          &quot;shortDescription&quot;: &quot;Started by user vikrant&quot;,<br>          &quot;userId&quot;: &quot;vikrant&quot;,<br>          &quot;userName&quot;: &quot;vikrant&quot;<br>        }<br>      ]<br>    },<br>    {},<br>    {<br>      &quot;_class&quot;: &quot;org.jenkinsci.plugins.displayurlapi.actions.RunDisplayAction&quot;<br>    }<br>  ],<br>  &quot;artifacts&quot;: [],<br>  &quot;building&quot;: false,<br>  &quot;description&quot;: null,<br>  &quot;displayName&quot;: &quot;#44&quot;,<br>  &quot;duration&quot;: 21,<br>  &quot;estimatedDuration&quot;: 22,<br>  &quot;executor&quot;: null,<br>  &quot;fullDisplayName&quot;: &quot;test-job-1 #44&quot;,<br>  &quot;id&quot;: &quot;44&quot;,<br>  &quot;keepLog&quot;: false,<br>  &quot;number&quot;: 44,<br>  &quot;queueId&quot;: 105,<br>  &quot;result&quot;: &quot;SUCCESS&quot;,<br>  &quot;timestamp&quot;: 1633186202085,<br>  &quot;url&quot;: &quot;<a href="http://localhost:8000/job/test-job-1/44/">http://localhost:8000/job/test-job-1/44/</a>&quot;,<br>  &quot;builtOn&quot;: &quot;&quot;,<br>  &quot;changeSet&quot;: {<br>    &quot;_class&quot;: &quot;hudson.scm.EmptyChangeLogSet&quot;,<br>    &quot;items&quot;: [],<br>    &quot;kind&quot;: null<br>  },<br>  &quot;culprits&quot;: []<br>}</pre><p><strong><em>http://localhost:8000</em></strong> is Jenkins base url where I’ve installed Jenkins and <strong><em>test-job-1</em></strong> is the job name.</p><p>Out of these fields, we are interested in</p><ol><li><strong><em>id</em> — </strong>It is the build number</li><li><strong><em>timestamp</em></strong> — Timestamp when the build ran</li><li><strong><em>url</em> </strong>— URL of the build. (To print hyperlinked build number)</li></ol><p>You can generate an authentication token from Jenkins UI.</p><p><strong><em>http://localhost:8000/user/&lt;your-username&gt;/configure</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*agDjYvvaCtd16ydp4znYXg.png" /></figure><p>You’ll need <a href="https://stedolan.github.io/jq/"><em>jq</em></a> tool installed, for json processing. Here is a good tutorial if you want to learn more about jq — <a href="https://www.baeldung.com/linux/jq-command-json"><em>https://www.baeldung.com/linux/jq-command-json</em></a></p><p>Now that we know the Jenkins API and how to get authentication token, let’s get to the script to get last successful build and timestamp for your most used jobs.</p><p>Here is the script.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35052e59ab046c363f214c9bc616d959/href">https://medium.com/media/35052e59ab046c363f214c9bc616d959/href</a></iframe><p>and the output</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6ZA1l7izg03Ma70Fm4fYQg.png" /></figure><p><em>Hope you found it useful!</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=244a00c9d270" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How we are migrating to Open API 3 at British Gas]]></title>
            <link>https://medium.com/@vikrant.kandgaonkar/how-we-are-migrating-to-open-api-3-at-british-gas-75629564365d?source=rss-ff44000f0b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/75629564365d</guid>
            <category><![CDATA[open-api]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[microservices]]></category>
            <category><![CDATA[swagger]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Vikrant Kandgaonkar]]></dc:creator>
            <pubDate>Mon, 23 Dec 2019 13:13:55 GMT</pubDate>
            <atom:updated>2019-12-23T13:13:55.925Z</atom:updated>
            <content:encoded><![CDATA[<p>API stands for application programming interface which allows one application to communicate with other. e.g. You can use Google maps API in a property rental application to show the location of the property. Increasingly APIs are becoming more ubiquitous and it is opening possibilities for usage of APIs in applications which even API authors didn’t envisage. And it need not be public API. You can have APIs for various business applications to talk to each other within your organisation. Major hindrance in API adoption is the ability to understand and consume an API. Hence there is a need to standardise the way API can be specified and consumed. <a href="https://www.openapis.org/">Open API</a> is one such initiative. It’s a Linux Foundation collaborative project which is community-driven.</p><p>At British Gas, we are in the phase of <strong>Digital Transformation</strong>. As part of it, we are moving towards micro-services. Micro-services architecture throws a different challenge for specifying APIs. Each micro-service has its own API specification. However, all these APIs are generally exposed behind an API gateway which gives a single unified view to the consumer. This creates a need to have a single API specification</p><p>We have used open source tools and created some of our own to achieve this. There are 3 aspects of the whole process.</p><h3>1. Define and Generate API specification</h3><p>Open API 3 specification is a yaml document. This document, for one micro-service, can extend up to thousands of lines. There are tools to do this which provide a nice UI to define and amend the specification. But it’s quite easy to change the API code without changing the documentation or vice-versa. Even a small change can potentially break your consumer applications. Hence we thought it’s best to keep the specification as close to code as possible. Swagger provides excellent tooling for this. In Java (JVM) application, you can put swagger annotations on your resource classes to provide specification for the API.</p><pre>@GET<br>@Operation(summary = &quot;Get single product&quot;,<br>        description = &quot;Retrieve a product for given id&quot;)<br>@ApiResponse(<br>        responseCode = &quot;200&quot;, <br>        description = &quot;Ok&quot;,<br>        content = @Content(<br>                mediaType = &quot;application/json&quot;, <br>                schema = @Schema(implementation = Product.class)))</pre><pre>public Response getProduct<br>        (@Parameter(required = true, description = &quot;ID to uniquely identify a product&quot;)<br>         @QueryParam(&quot;id&quot;) String productId) {<br>    // your code  <br>}</pre><p>and here is an example of model class</p><pre>public class Product {<br>    @Schema(description = &quot;Unique id of the product&quot;, example = &quot;1234&quot;)<br>    private String id;</pre><pre>    @Schema(description = &quot;Description of the product&quot;, example = &quot;Smart phone&quot;)<br>    private String description;<br>    // more fields<br>}</pre><p>We also use a <a href="https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-gradle-plugin">swagger gradle plugin</a> to generate API specification for a micro-service through a gradle build task. And there is another gradle task to verify API specification that is present. This task generates the API specification and validates the the one that is already present, against this. If it doesn’t match, the build fails and developer has to look into it. The idea is not to modify the specification manually. It can only happen in an automated manner. This prevents cases where developer makes a breaking change to the code and misses the change to specification.</p><p>Also we use <a href="https://jsonapi.org/">JsonAPI specification</a> to send a REST response which is a different format than a simple POJO. It has all the relationships specified with it. For this, we customised the response schema generation using <a href="https://github.com/swagger-api/swagger-core/wiki/Swagger-2.X---Extensions#extending-core-resolver">swagger’s model resolver</a>.</p><h3>2. Combine multiple APIs</h3><p>Each micro-service has its own API. As mentioned earlier, we need to provide <strong>a single, unified</strong> API specification to consumers. Hence we need to join the multiple API specifications together to create a single API specification. For this we have created an API joiner tool -&gt; <a href="https://github.com/britishgas-engineering/openapi3-joiner">https://github.com/britishgas-engineering/openapi3-joiner</a></p><h3>3. Publish API</h3><p>Open API 3 specification is in yaml format which in itself is a different DSL. For consumers to be able to quickly understand it, we need to show this specification in a nice web UI. That’s where the <a href="https://github.com/Redocly/redoc">Redoc</a> helps. It allows you to create a static webapp from the Open API specification.</p><p>Here is our workflow</p><ol><li>Developer writes API specification using swagger annotation. and generates API specification for a micro-service using gradle build.</li><li>This gets checked in into github like any other code.</li><li>We have developed an API service which provides an API to publish the API docs. This API pulls the API specification for all the micro-services from github using github APIs and using API joiner tool, creates a single API specification. It then creates a static webapp (Redoc) for the same specification and puts it into AWS S3. This webapp gets rendered via AWS Cloudfront.</li><li>This activity happens once a day through a scheduled job.You can choose how often you want to publish an API based on your needs. Each time, you create a new version of API specification.(not necessarily new version of API)</li></ol><p>Here is a block diagram for this flow</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*SyByl3bbSY4j-tlHz7jmiQ.png" /></figure><p>and a sequence diagram</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rlAxl4RnGJP-PVOjactIaw.png" /></figure><h3>How’s this helping?</h3><ol><li>API specification is often written by developers. It’s easy to write/amend swagger annotations which is a Java Code, than thousands of lines of yaml.</li><li>It keeps specification as close to code as possible so there are less chances of cases where code changes without the change in API specification.</li><li>We can provide single unified view of the entire API to our consumers.</li><li>We can leverage tools that are built for Open API 3.</li></ol><p>Open API specification is proving to be a very useful tool as more and more APIs are being developed. It provides a vendor-neutral standardisation for API specification.</p><h3>Happy Open API!</h3><p>(Hit the clap if you liked this!)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=75629564365d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kotlin Introduction and comparison with Java]]></title>
            <link>https://medium.com/@vikrant.kandgaonkar/kotlin-introduction-and-comparison-with-java-22998d746c8e?source=rss-ff44000f0b31------2</link>
            <guid isPermaLink="false">https://medium.com/p/22998d746c8e</guid>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Vikrant Kandgaonkar]]></dc:creator>
            <pubDate>Sat, 15 Dec 2018 18:55:41 GMT</pubDate>
            <atom:updated>2018-12-17T10:03:25.249Z</atom:updated>
            <content:encoded><![CDATA[<h3>Kotlin Overview and comparison with Java</h3><p>In May 2017, Google announced that it is making Kotlin, a JVM language, a first-class language for Android development. That caught my attention and I started exploring Kotlin. Kotlin is an opensource language developed by JetBrains, the company which develops popular IDEs like Intellij IDEA and Webstorm.</p><p>Here is an overview of some features of the language in contrast with Java.</p><h3>1. Simple, Concise and easy to get started with</h3><p>Ever tried writing a Hello World code in Java?<br>Here is what it looks like</p><pre><br>public class HelloWorld {<br>   public static void main(String[] args) {<br>     System.out.println(“Hello World!”);<br>   }<br>}<br></pre><p>Now this might look simple for an experienced Java developer.<br>But for someone who’s new to the language, it’s too verbose.<br>There is lot of noise here.<br>What is public? What is class? What is static? What is System.out?<br>All this for simply printing “Hello World” ?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*nKL1ELEBuPl03nv052YRgA.jpeg" /></figure><p>And Java is full of such verbosity.</p><p>Here is what Kotlin Hello World looks like</p><pre>fun main() {<br>    println(“Hello World”)<br>}</pre><p>Now there are still some concepts here, like <strong>fun</strong> is function and <strong>main</strong> is a starting point for the application.<br>But that’s just absolute minimum to run an application which any language would have.</p><p>Here is another sample<br>This program parses the text and prints following<br>1. Words that start with vowel<br>2. Words that start with a consonant<br>3. Word count</p><pre>fun main(args: Array&lt;String&gt;) {<br>         val text = &quot;&quot;&quot;<br>            Global warming is a long-term rise in the average        temperature of the Earth&#39;s climate system,<br>            an aspect of climate change shown by temperature measurements and<br>            by multiple effects of the warming.<br>        &quot;&quot;&quot;</pre><pre>        val words = text.trimIndent().split(Regex(&quot;\\s&quot;))<br>        val startsWithAVowel = words.filter { word -&gt;<br>            listOf(&#39;a&#39;, &#39;e&#39;, &#39;i&#39;, &#39;o&#39;, &#39;u&#39;)<br>            .any { word[0].toLowerCase() == it }<br>        }<br>        val startsWithAConsonant = <br>            words.filter { !startsWithAVowel.contains(it) }</pre><pre>        println(&quot;Starts with a vowel =&gt; $startsWithAVowel&quot;)</pre><pre>        println(&quot;Starts with a consonant =&gt; $startsWithAConsonant&quot;)</pre><pre>        val wordCount = words<br>                         .groupBy { it }<br>                         .map { it.key to it.value.count() }<br>        println(&quot;Word count =&gt; $wordCount&quot;)<br>}</pre><p>Try writing the above code in Java and you can see why Kotlin is concise.</p><h3>2. Unopinionated about paradigm</h3><p>In Kotlin, you can write code in both object oriented and functional style.<br>Language doesn’t force you to follow any particular paradigm unlike Java which is purely object oriented.</p><h3>3. Statically Typed</h3><p>Kotlin is statically typed which means type of a variable is determined at the compile time.<br>e.g. Java, Scala are statically typed whereas languages like Javascript, Groovy and Python are dynamically typed.<br>Static typing avoids accidental type bugs.<br>But what prevents static typing from becoming verbose is strong type inference in Kotlin<br>e.g</p><pre>val msg = “Hello”</pre><p>From the above statement, compiler can figure out that <strong>msg</strong> is a string.<br>You cannot, in next line, write</p><pre>msg = 10</pre><p>Compilation fails here.<br>Also compiler will complain if it can’t infer the type of a variable<br>e.g.</p><pre>fun hello(msg) {<br>    println(msg)<br>}</pre><p>which needs to be written as</p><pre>fun hello(msg: String) {<br>    println(msg)<br>}</pre><h3>4. Data Classes</h3><p>Any Java developer would have dealt with default Object class methods<br>like <br><strong>toString()</strong> — gets the string representation of an object<br><strong>equals()</strong> — compares one object of a class with other<br><strong>hashCode()</strong> — gives hashCode of an object in case you need to use it as a key in HashMap (key-value pair)</p><p>All Java IDEs have quick shortcuts to generate these methods for you and there are libraries like lombok which modify the byte code to generate this.</p><p>Here is a Java sample</p><pre>class Person{<br>    String name;<br>    String email;</pre><pre>    @Override<br>    public boolean equals(Object o) {<br>        if (this == o) return true;<br>        if (o == null || getClass() != o.getClass()) return false;<br>        Person person = (Person) o;<br>        return Objects.equals(name, person.name) &amp;&amp;<br>                Objects.equals(email, person.email);<br>    }</pre><pre>    @Override<br>    public int hashCode() {<br>        return Objects.hash(name, email);<br>    }</pre><pre>    @Override<br>    public String toString() {<br>        return &quot;Person{&quot; +<br>                &quot;name=&#39;&quot; + name + &#39;\&#39;&#39; +<br>                &quot;, email=&#39;&quot; + email + &#39;\&#39;&#39; +<br>                &#39;}&#39;;<br>    }<br>}</pre><p>Kotlin has a better way — data classes</p><pre>data class Person(val name: String, val email: String)</pre><p>You might say it’s a trivial code which is given by IDE.<br>But you still have to maintain it and when that code changes it’s not always clear whether it was generated by IDE or modified by another developer.</p><p>Also you can fit multiple data classes in one file instead of having to create one file per such class.</p><h3>5. Singleton Design Pattern</h3><p>Singleton design pattern is used when a class needs to have one and only one instance.</p><p>Here is what Java implementation looks like.</p><pre>public final class MyClass {<br> <br>    private static MyClass INSTANCE;<br>     <br>    private MyClass() {        <br>    }<br>     <br>    public static MyClass getInstance() {<br>        if(INSTANCE == null) {<br>            INSTANCE = new MyClass();<br>        }    <br>        return INSTANCE;<br>    }<br>}</pre><p>In addition to this, you might need <strong>synchronized </strong>for thread safety and some other code to protect against deserialization of an object.</p><p>There is another way using enum as well.<br>And Kotlin code looks like</p><pre>object MyClass{<br>    init{<br>        <br>    }<br>}</pre><p>Simply prefix it with <strong><em>object</em></strong><br>You don’t have to google or stackoverflow to do this!</p><h3>6. Extension functions</h3><p>This is one of coolest features of Kotlin.<br>This allows you to add methods to classes which you cannot modify.</p><p>e.g <strong>String</strong> class in java does not have a method <strong>isACity(), </strong>but using extension function you can add it.</p><pre>fun String.isACity() = arrayListOf(<br>                        &quot;London&quot;,&quot;New York&quot;,&quot;Mumbai&quot;).contains(this)</pre><pre>println(&quot;London&quot;.isACity()) // true<br>println(&quot;xyz&quot;.isACity()) // false</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*NKXj3gVvdCnVEZ4xFszLew.jpeg" /></figure><h3>7. Safety — Null and Immutability</h3><p><strong>Immutability</strong></p><p>Accidental mutability introduces weird bugs and eats up lot of<br>debugging time. Mutability can also make code unnecessarily complex and hard to debug.<br>In Java (and I guess most languages), by default the variable is mutable and if you have to make it immutable, you need to add final before it</p><pre>final String a = &quot;xyz&quot;;</pre><p>Adding final for every variable is verbose and can be easily missed out.</p><p>Kotlin has two keywords<br><strong>val</strong> and <strong>var</strong><br><strong>val</strong> is immutable variable</p><pre>val a = &quot;abc&quot;<br>a = &quot;pqr&quot; // this will fail to compile</pre><p>and var is for mutable variable</p><pre>var b = &quot;abc&quot;<br>b = &quot;pqr&quot; // this compiles fine</pre><p>So you use <strong>val</strong> for most of the cases and <strong>var</strong> when absolutely needed.<br>Method parameters in Kotlin are immutable too.</p><p><strong>Null Pointer</strong></p><p><strong>NullPointerException</strong> is one of the most commonly observed exception<br>in Java production logs. And it can be really frustrating and challenging to debug, depending upon where in code it occurs.<br>It is thrown when you try to derefernce an object which has no reference (or null). Even the person who pioneered the concept has called it a billion dollar mistake.</p><p>Kotlin types fall into 2 categories — <br>Nullable and Non-nullable</p><p>By default types are non-nullable<br>e.g.</p><pre>var a: String = &quot;abc&quot;<br>a = null // compilation error</pre><p>If you want a nullable type, you have to explicitly specify <strong>?</strong> at the end of<br>the type.</p><pre>var b: String? = &quot;abc&quot;<br>b = null // ok</pre><p>This makes it explicit when a variable can or cannot be null and code becomes easier to reason about.</p><h3>8. JVM language</h3><p>As a Java developer you don’t have to leave JVM world.<br>Kotlin is interoperable with Java. It was designed with Java inter-op in mind.<br>You can call Java code from Kotlin and vice versa.</p><p>Also it doesn’t have a big learning curve unlike some of the other JVM languages like Scala.</p><h3>9. Growing Community</h3><p>Kotlin community is ever growing. Also you benefit from abundant java libraries that already exist.<br>Spring boot and Gradle already have added support for Kotlin.<br>More and more android apps are being written using Kotlin.<br>It can be transpiled to Javascript and is also available in native.</p><p>Kotlin is inspired by other programming languages and brings<br>good features from them. e.g. Things like <strong><em>data clasess, val, var, object</em></strong> seem be inspired by Scala.<br>It is truly a general purpose programming language.</p><h4>Happy Kotlin !!!</h4><p>(Hit the clap if you liked this!)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=22998d746c8e" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>