Installing VoltDB on Ubuntu 13 (64 bit)

VoltDB is an example of a NewSQL type of database, it’s based on the H-Store DBMS.

This is an example of how to get going with VoltDB on Ubuntu 13 (64 bit only), This is assuming a pre existing installation of Ubuntu 13 64 bit edition.

1) Register and download the software on the VoltDB website, I’ve selected the VoltDB Open Source Edition Download for Linux. There is an Enterprise edition which offers a wider feature set.

The zip archive is named: LINUX-voltdb-3.7.0.4.tar.gz

2) Copy the file to your installation directory, I’ve chosen /opt

Change directory to /opt: cd /opt

3) Inflate the archive file

Use the command: tar zxvf LINUX-voltdb-3.7.0.4.tar.gz

4) Check the prerequisites are installed

Install aptitude

apt-get install aptitude

Install the build essentials package

aptitude install build-essential

Install a Java jdk (openJDK in this instance)

aptitude install openjdk-7-jdk

5) We should be able to run the VoltDB demos, the voter demo in this instance:

Open the file: file:///opt/voltdb-3.7/tools/demo/index.htm in your browser

To run the Voter demo:

Start the Server: sh /opt/voltdb-3.7/examples/voter/run.sh

Start the client: sh /opt/voltdb-3.7/examples/voter/run.sh client

Volt1

Open the performance monitor to view the running demo application: file:///opt/voltdb-3.7/examples/voter/LiveStats.html

Volt2

View the data via SQL queries with the built in studio file:///opt/voltdb-3.7/tools/studio.web/index.htm?startup=query – You can issue SQL queries against the VoltDB database.

Volt3

C# .Net using Autofac in an MVC4 project

Autofac is a popular IoC container, it’s a little more complex to setup than some other containers available. I’ll describe how to do a simple setup to get up and running quickly.

If you’re new to IoC, it’s simply a mechanism for managing dependencies in your application, it’s now a hot topic in application development so it’s worth doing some research to familiarize yourself with the subject.

1) Create a new MVC4 solution in Visual Studio (2012 in this example).

2) Add the Autofac.MVC4 reference to your project, if you’re using nuget from the command line do:

install-package Autofac.MVC4

3) Add a new class AutofacScopeContainer.cs to your solution:

using System;
using System.Collections.Generic;
using  System.Web.Http.Dependencies;
using Autofac;
using Autofac.Integration.Mvc;

namespace CsharpAutofacDemo
{
    /// <summary>
    /// Autofac Scope Container
    /// </summary>
    public class AutofacScopeContainer : IDependencyScope
    {
        /// <summary>
        /// Private _container field
        /// </summary>
        private readonly AutofacDependencyResolver _container;

        /// <summary>
        /// Initializes a new instance of the <see cref="AutofacScopeContainer"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        /// <exception cref="System.ArgumentNullException">container</exception>
        protected AutofacScopeContainer(AutofacDependencyResolver container)
        {
            if (container == null)
            {
                throw new ArgumentNullException("container");
            }
            _container = container;
        }

        /// <summary>
        /// Retrieves a service from the scope.
        /// </summary>
        /// <param name="serviceType">The service to be retrieved.</param>
        /// <returns>
        /// The retrieved service.
        /// </returns>
        public object GetService(Type serviceType)
        {
            return _container.ApplicationContainer.IsRegistered(serviceType) ? _container.GetService(serviceType) : null;
        }

        /// <summary>
        /// Retrieves a collection of services from the scope.
        /// </summary>
        /// <param name="serviceType">The collection of services to be retrieved.</param>
        /// <returns>
        /// The retrieved collection of services.
        /// </returns>
        public IEnumerable<object> GetServices(Type serviceType)
        {
            return _container.ApplicationContainer.IsRegistered(serviceType) ? _container.GetServices(serviceType) : new List<object>();
        }

        /// <summary>
        /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
        /// </summary>
        public void Dispose()
        {
            _container.ApplicationContainer.Dispose();
        }

    }

    /// <summary>
    /// Auto FacContainer
    /// </summary>
    public class AutoFacContainer : AutofacScopeContainer, IDependencyResolver
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="AutoFacContainer"/> class.
        /// </summary>
        /// <param name="container">The container.</param>
        public AutoFacContainer(AutofacDependencyResolver container)
            : base(container)
        {
        }

        /// <summary>
        /// Starts a resolution scope.
        /// </summary>
        /// <returns>
        /// The dependency scope.
        /// </returns>
        public IDependencyScope BeginScope()
        {
            return this;
        }
    }
}

4) Add a new class CustomerModel.cs to your solution:

namespace CsharpAutofacDemo.Models
{
    /// <summary>
    /// Customer class 
    /// </summary>
    public class Customer
    {
        public string CustomerId { get; set; }
        public string CustomerName { get; set; }
        public string CustomerAddress { get; set; }
        public string CustomerPhoneNumber { get; set; }
        public string CustomerEmail { get; set; }
    }
}

5) Add a new class CustomerRepository.cs to your solution:

using System.Collections.Generic;
using CsharpAutofacDemo.Models;

namespace CsharpAutofacDemo
{
    /// <summary>
    /// Customer details repository class
    /// </summary>
    public class CustomerRepository : ICustomerRepository
    {
        /// <summary>
        /// Get customer details.
        /// </summary>
        /// <returns></returns>
        public List<Customer> GetCustomerDetails()
        {
            // This is a simple implementation, others could use an ORM or Web service etc.
            
            var customers = new List<Customer>
                          {
                              new Customer()
                                  {
                                      CustomerId = "1",
                                      CustomerName = "Customer one",
                                      CustomerAddress = "Bristol",
                                      CustomerPhoneNumber = "0845000000",
                                      CustomerEmail = "[email protected]",
                                  },
                              new Customer()
                                  {
                                      CustomerId = "2",
                                      CustomerName = "Customer two",
                                      CustomerAddress = "Bath",
                                      CustomerPhoneNumber = "0845000001",
                                      CustomerEmail = "[email protected]",
                                  },
                              new Customer()
                                  {
                                      CustomerId = "3",
                                      CustomerName = "Customer three",
                                      CustomerAddress = "Swindon",
                                      CustomerPhoneNumber = "0845000003",
                                      CustomerEmail = "[email protected]",
                                  }
                          };

            return customers;
        }
    }
}

6) Add a new class ICustomerRepository.cs to your solution:

using System.Collections.Generic;
using CsharpAutofacDemo.Models;

namespace CsharpAutofacDemo
{
    /// <summary>
    /// ICustomerRepository interface
    /// </summary>
    public interface ICustomerRepository
    {
        List<Customer> GetCustomerDetails();
    }
}

7) Update your Global.asax.cs file:

using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using Autofac;
using Autofac.Integration.Mvc;
using System.Web;

namespace CsharpAutofacDemo
{
    // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
    // visit http://go.microsoft.com/?LinkId=9394801

    public class MvcApplication : HttpApplication
    {
        protected void Application_Start()
        {
            RegisterAutoFac(GlobalConfiguration.Configuration);

            AreaRegistration.RegisterAllAreas();
            WebApiConfig.Register(GlobalConfiguration.Configuration);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            AuthConfig.RegisterAuth();
        }

        void RegisterAutoFac(HttpConfiguration config)
        {
            // Setup the Container Builder
            var builder = new ContainerBuilder();

            // Register the controller in scope 
            builder.RegisterControllers(typeof(MvcApplication).Assembly);

            // Register types
            builder.RegisterType<CustomerRepository>().As<ICustomerRepository>();

            // Build the container
            var container = builder.Build();

            // Setup the dependency resolver
            DependencyResolver.SetResolver(new AutofacDependencyResolver(container));

            config.DependencyResolver = new AutoFacContainer(new AutofacDependencyResolver(container));
        }
    }
}

8) Update your HomeController.cs file:

using System.Web.Mvc;

namespace CsharpAutofacDemo.Controllers
{
    /// <summary>
    /// MVC Controller class
    /// </summary>
    public class HomeController : Controller
    {
        /// <summary>
        /// Private _container field
        /// </summary>
        private readonly ICustomerRepository _customerRepository;

        /// <summary>
        /// Initializes a new instance of the <see cref="HomeController"/> class.
        /// </summary>
        /// <param name="customerRepository">The customer repository.</param>
        public HomeController(ICustomerRepository customerRepository)
        {
            _customerRepository = customerRepository;
        }

        // GET: /Customer/

        /// <summary>
        /// Method for index action.
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            [email protected] AutofacDemo.Customer
            var customer = _customerRepository.GetCustomerDetails();

            // View Index.cshtml
            return View(customer);
        }


    }
}

9) Update your index.cs file:

@model  List<CsharpAutofacDemo.Models.Customer>

@{
    ViewBag.Title = "Index";
}
<h2>Index</h2>

@foreach (var customer in Model)
{
    <fieldset>
        <legend>Customer</legend>

        <div class="display-label">
            @Html.DisplayNameFor(model => customer.CustomerId)
        </div>
        <div class="display-field">
            @Html.DisplayFor(model => customer.CustomerId)
        </div>
        <div class="display-label">
            @Html.DisplayNameFor(model => customer.CustomerName)
        </div>
        <div class="display-field">
            @Html.DisplayFor(model => customer.CustomerName)
        </div>
        <div class="display-label">
            @Html.DisplayNameFor(model => customer.CustomerAddress)
        </div>
        <div class="display-field">
            @Html.DisplayFor(model => customer.CustomerAddress)
        </div>
        <div class="display-label">
            @Html.DisplayNameFor(model => customer.CustomerPhoneNumber)
        </div>
        <div class="display-field">
            @Html.DisplayFor(model => customer.CustomerPhoneNumber)
        </div>

        <div class="display-label">
            @Html.DisplayNameFor(model => customer.CustomerEmail)
        </div>
        <div class="display-field">
            @Html.DisplayFor(model => customer.CustomerEmail)
        </div>
    </fieldset>
    <br />
}

10) Build your project and run, you should see the view page with the customer data displayed.

Using Apache Solr 4.5.0 and .Net C# – part 1 installation and setup

I’m going to spend some time looking at some interesting services that really extend and enhance what’s possible with web applications. Over this series I’ll build up a fully working app with all the source code starting with an enterprise search engine I’ve been interested in for a while.

Apache Solr is an open source enterprise search platform from the Apache Lucene project. It has some useful features that include full-text search, hit highlighting, faceted search, near real-time indexing, dynamic clustering, database integration, rich document handling and geospatial capabilities.

Solr is also highly reliable, scalable and can be setup into fault tolerant modes. It’s heavily used on the Internet as listed on Solr public sites.

The homepage for Solr is: https://lucene.apache.org/solr/.

Before you can run Solr, grab and install the latest Java SE Oracle SE download.

If you don’t want the Oracle version, Solr apparently supports other Java versions according to the Lucene tutorial.

For this installation, the latest Oracle SDK is used. Solr versions greater than 4 require a Java version 1.6 or greater.

Grab the installation files from: http://www.apache.org/dyn/closer.cgi/lucene/solr/4.5.0 and select the most appropriate mirror. This installation on this post is performed on a Windows server.

Grab the conpressed file, decompress it and save the output to a location on your disk.

Navigate to the installation directory and run the following in a command prompt:

D:\Solr\solr-4.5.0\example

Then:

java –jar start.jar

This will present two URIs which you can browse at:

The Apache Solr dashboard: http://localhost:8983/solr/#/

Solr admin screen

And an example search engine: http://localhost:8983/solr/collection1/browse/?

Solr example screen

Once these are running, the next task is to index some content, to do this run the following java:

java -jar post.jar *.xml

This will produce the following output:

D:\Solr\solr-4.5.0\example\exampledocs>java -jar post.jar *.xml
SimplePostTool version 1.5
Posting files to base url http://localhost:8983/solr/update using content-type a
pplication/xml..
POSTing file gb18030-example.xml
POSTing file hd.xml
POSTing file ipod_other.xml
POSTing file ipod_video.xml
POSTing file manufacturers.xml
POSTing file mem.xml
POSTing file money.xml
POSTing file monitor.xml
POSTing file monitor2.xml
POSTing file mp500.xml
POSTing file sd500.xml
POSTing file solr.xml
POSTing file utf8-example.xml
POSTing file vidcard.xml
14 files indexed.
COMMITting Solr index changes to http://localhost:8983/solr/update..
Time spent: 0:00:01.205

If you return the the example search interface, You will find a number of documents have been indexed.

More info on Solr setup can be found at: http://lucene.apache.org/solr/3_6_2/doc-files/tutorial.html.

In part 2, We’ll take a look at some of the more advanced features of Solr.