Skip to content

Getting Started

Fabien Hermenier edited this page Mar 20, 2013 · 95 revisions

Getting started

[Associated source code] (https://github.com/fhermeni/btrplace-solver/blob/develop/examples/src/main/java/btrplace/examples/GettingStarted.java)

Btrplace is a flexible algorithm to place Virtual Machines (VMs) on servers in a hosting platforms. Basically, it manages VMs with respect to constraints that are stated by the users. As a user of the algorithm, you only have to declare the constraints you want to have satisfied. This tutorial presents the fundaments of BtrPlace.

BtrPlace is articulated around 4 primitives:

  • The model depicts the current state of a virtualized hosting platforms. It is usually generated from monitoring data

  • A reconfiguration plan. A plan consists of a scheduled set of actions to execute. A plan allows to transit from a source model to a destination model.

  • A set of Satisfaction Oriented Constraints ( SatConstraints). A SatConstraint imposes a restriction on a model or a reconfiguration plan. On a model, it provides a discrete restriction. On a plan, it imposes a continuous restriction, i.e a restriction over the time. In practice, a constraint allows to control the state of the elements (VMs, servers), the resource allocation, the VMs placement, ...

  • A reconfiguration algorithm is an algorithm that takes a model and a set of constraints as a parameter. It checks if the model is consistent with regards to the states constraints. If not, it computes a plan to reach a model that satisfies all the constraints simultaneously.

Defining a model

A model is composed of several elements:

In this tutorial, we will reproduce the model that is depicted by the figure on the left. It represents a model composed by 4 online servers hosting 6 running VMs.

The mapping

In Btrplace, as in many hypervisors, elements such as servers and VMs are identified by a UUID. The next snippet creates a mapping that declare the online node n1 and place VMs vm2 and vm3 on it. Next it creates a model:

Mapping m = new DefaultMapping();

UUID n1 = UUID.randomUUID();
UUID vm2 = UUID.randomUUID();
UUID vm3 = UUID.randomUUID();
//n1 is online
map.addOnlineNode(n1);

//vm3 and vm2 runs on n1
map.addRunningVM(vm3, n1);
map.addRunningVM(vm2, n1);

Model mo = new DefaultModel(map);

Describing the current resource usage with Views##

In Btrplace, a resource is defined using a special view called ShareableResource. This allows to specify the physical resource capacity of the nodes and the virtual resource usage of the VMs.

Below is the snippet to declare a resource called "cpu" and attach it to the model mo. For this example, itindicates the number of physical CPUs available on n1, and the number of virtual CPUs that are allocated to vm2 and vm3.

        ShareableResource rcCPU = new ShareableResource("cpu");
        //n1 has 8 physical CPUs
        rcCPU.set(n1, 8);
        
        //vm2 has 3 virtual CPUs
        rcCPU.set(vm2, 3);
        //vm3 has 3 virtual CPUs
        rcCPU.set(vm3, 4);
        
        //the rcCPU view is attached to the model
        mo.attach(rcCPU);

Stating constraints

A Satisfaction Oriented Constraint (SatConstraint) imposes a restriction on a model or a reconfiguration plan. On a model, it provides a discrete restriction. On a plan, it imposes a continuous restriction, i.e a restriction over the time. The type of the restriction depends on the constraint semantics and a constraint may support the both type of restriction.

The following code creates 5 constraints:

  //We disallow CPU overbooking, so each unit of
  //virtual resource consumes one unit of physical
  //resource on every node
  Set<UUID> allNodes = new HashSet<UUID>(Arrays.asList(n1, n2, n3, n4));
  Overbook cpuOverbook = new Overbook(allNodes, "cpu", 1);      

  //VM2 and VM3 must be running on distinct nodes
  Spread s = new Spread(new HashSet<UUID>(Arrays.asList(vm2, vm3)));

  //VM1 must have at least 3 virtual CPU dedicated to it
  Preserve cpu4vm1 = new Preserve(Collections.singleton(vm1), "cpu", 3);

  //node N4 must be offline
  Offline offN4 = new Offline(Collections.singleton(n4));
  
  Set<SatConstraint> cstrs = new HashSet<SatConstraint>(Arrays.asList(spread, cpuOverbook, cpu4vm1, offN4));

Clone this wiki locally