Presentation on Infrastructure as a Service

Hi all,

Recently I did a presentation on Infrastructure as a Service for one of my MSc classes. Thought of sharing it here.

Cheers! 🙂

~Rajind Ruparathna

Advertisements

Magic Square – IEEXtreme 8.0

Problem

Johnny designed a magic square (square of numbers with the same sum for all rows, columns and diagonals i.e. both the main diagonal – meaning the diagonal that leads from the top-left corner towards bottom-right corner – and the antidiagonal – meaning the diagonal that leads from top-right corner towards bottom-left corner). Write a program to test it.

Task
Write a program that will check if the given square is magic (i.e. has the same sum for all rows, columns and diagonals).

Continue reading “Magic Square – IEEXtreme 8.0”

Sum It Up – IEEXtreme 8.0

Problem

Minka is very smart kid who recently started learning computer programming.
His coach gave him a cyclic array A having N numbers, and he has to perform Q operations on this array.
In each operation the coach would provide him with a number X. After each operation, every element of the cyclic array would be replaced by the sum of itself and the element lying X positions behind it in the cyclic array. All these replacements take place simultaneously.
For example, if the cyclic array was [a, b, c, d], then after the operation with X = 1, the new array would be [a+d, b+a, c+b, d+c].
He needs to output the sum of the elements of the final array modulus 10^9+7.
He made a program for it but it’s not very efficient. You know he is a beginner, so he wants you to make an efficient program for this task because he doesn’t want to disappoint his coach.

Continue reading “Sum It Up – IEEXtreme 8.0”

Back to Square 1 – IEEEXtreme 8.0

The game “Back to Square 1” is played on a board that has n squares in a row and n-1 probabilities. Players take turns playing. On their first turn, a player advances to square 1.After the first turn, if a player is on square i , the player advances to square i + 1 with probability p(i) , and returns to square 1 with probability 1-p(i) .The player is finished upon reaching square n .

Task


Write a program that determines the expected number of turns needed for a player to reach the final square.For example, consider the board below with n = 3 and p(1) = 0.5 and p(2) = 0.25. A player moves to square 1 on their first turn. With probability p(1) , they move to square 2 on their second turn, but with probability 1- p(1) , they remain on square 1. If they were lucky and made it to square 2 on their second turn, they advance to square 3 on their third turn with probability p(2) , but they would go back to square 1 with probability 1- p(2) . Thus, a really lucky player could finish is 3 turns. However, on average, it would take 13 turns for a player to make it to square 3.

IMAGE 1

Continue reading “Back to Square 1 – IEEEXtreme 8.0”

Configuring Network for Solaris 11 in Virtual Box

Hi all, recently I tried Solaris for some tasks at work. Installing Solaris on VirtualBox was not so difficult and there were quite a few resources in the internet. I used the following. http://thegeekdiary.com/installing-oracle-solaris-11-in-virtualbox/

However for configuring the network it was not the same. So here I will note down a few things which I believe might be useful when configuring network for Solaris 11 in Virtual Box.

In Solaris 11 configuring network is not editing few files, unlike in most other operating systems. There are a set of commands we can to create those configurations for us.

We will go through configuring NAT, HostOnly and Bridged Adaptors. First we have to go to Setting for the Solaris VM in VirtualBox and from there to the Network Tab.
Even though eventually we will add three network adaptors, I suggest we start by enabling only one adaptor as it might be hard to figure out which is which inside Solaris one we enable several network adaptors at once and try to configure them inside Solaris.

Continue reading “Configuring Network for Solaris 11 in Virtual Box”

Implementing an Embedded ElasticSearch Server

Hi all, recently I added an embedded ElasticSearch server for the upcoming release of  AdroitLogic UltraESB. Embedded ES Server will be useful when a large ES cluster is not required and also for ES integration tests. Let’s have a look at the code.

import org.adroitlogic.logging.api.Logger;
import org.adroitlogic.logging.api.LoggerFactory;
import org.adroitlogic.ultraesb.api.monitoring.StatisticsServer;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.node.Node;

import static org.elasticsearch.node.NodeBuilder.nodeBuilder;

/**
 * @author rajind
 * Implementation of embedded elasticsearch server.
 *
 */

public class ElasticSearchStatisticsServer implements StatisticsServer {

    private Node node;
    private static final Logger logger= LoggerFactory.getLogger(ElasticSearchStatisticsServer.class);

    private static final String ES_PROPERTY_PATH_HOME = "path.home";
    private static final String ES_PROPERTY_PATH_CONF = "path.conf";

    /**
     * Create an elasticsearch embedded node with provided default configuration.
     */
    @SuppressWarnings("UnusedDeclaration")
    public ElasticSearchStatisticsServer() {
    }

    @Override
    public void init(String confDir, String homeDir) {
        try {
            logger.info("Embedded Elasticsearch server is initializing");
            Settings elasticsearchSetting = Settings.settingsBuilder()
                    .put(ES_PROPERTY_PATH_HOME, homeDir)
                    .put(ES_PROPERTY_PATH_CONF, confDir)
                    .build();
            node = nodeBuilder().settings(elasticsearchSetting).build().start();
        } catch (Exception e) {
            logger.warn("Could not init embedded elasticsearch node", e);
        }
    }

    public Client getClient() {
        if (node != null) {
            return node.client();
        } else {
            return null;
        }
    }

    @Override
    public void destroy() {
        try {
            logger.info("Stopping embedded elasticsearch server");
            node.close();
        } catch(Exception e) {
            logger.warn("Could not stop embedded elasticsearch node due to {}", e.getMessage());
        }
    }
}

It’s actually very simple. “path.conf” will contain the elasticsearch configuration yaml file “elasticsearch.yml“. Please remember that “path.home” will always have to be set as elasticsearch looks for that by default.

Cheers! 🙂

~Rajind Ruparathna

IntelliJ IDEA Find & Replace using Regex

Recently I had to convert some documents which was on HTML format to Asciidoc format. An awesome tool called Pandoc saved me a lot of work. So after using that tool I was left to do a bit of final touches which included a lot of find and replace kind of work. I had actually set this up as a maven project with AsciiDoctor in IntelliJ IDEA so that is where I got to use this cool feature, find and replace with regex.

Here I’ll show a few examples as some of those are not that well documented.

Say  this here, “image:/download/attachments/983129/address-state-chart.png?version=3&modificationDate=1318249062000&api=v2[image,title=”sometitle”]”
is the string that I want to manipulate.

Continue reading “IntelliJ IDEA Find & Replace using Regex”