mardi 13 mai 2014

Factory Pattern with .Net technology

I didn’t write about .Net for a long time and it’s always excited to be back.

 I design and write software solution for a living, and I do that with different technologies(PHP Symfony, Python, Javascript…) but regardless of the technology I always try to respect the S.O.L.I.D principals(http://en.wikipedia.org/wiki/SOLID_(object-oriented_design)) because violating one of those cause a great collateral damage in your code.


In this article I wanted to share one of my method to write a respectful code (respectful to me, you can have another opinion) using .Net technology.
Let us start with a case study:

The Straw hats pirates (the pirate crew in the one piece anime) contact my company and they want to write a piece of software to automate pizza preparation for them.

Sanji(the cook of the pirate crew) explained to me that in order to prepare pizza we need to
          1)      Prepare the Pizza Dough
          2)      Prepare the sauce
          3)      Add pizza sauce and pizza ingredients to the pizza dough
          4)      Put the pizza in the oven

My company assigned this job to me and I wrote this class.

namespace PizzaExample
{
    public class PizzaMaker
    {
        public void preparePizza()
        {
            this.MakeDough();
            this.PrepareSauce();
            this.AddIngredientsAndSauce();
            this.PutInOven();
        }

        private void PutInOven()
        {
            Console.WriteLine("Pizza in Oven");
        }

        private void AddIngredientsAndSauce()
        {
            Console.WriteLine("Adding sauce, cheese,olives and meat");
        }

        private void PrepareSauce()
        {
            Console.WriteLine("Making sauce");
        }

        private void MakeDough()
        {
            Console.WriteLine("Making daugh");
        }
    }
}

I was happy about my work but only when Sanji come back to me and told that not all of his crew members like the same ingredients and he claimed that Nami is vegetarian and she don’t like to have meat, Chopper another crew member don’t like olives. So I had to rewrite the method AddIngredientsAndSauce  to full fit my costumers needs, I refactor it into two methods  and it look like this now:

    private void AddIngredientsAndSauce(String membername="Any")
        {
           
            if(membername=="Nami")
                Console.WriteLine("Adding cheese and olives");
            else if(membername=="Chpper")
                Console.WriteLine("Adding cheese and meat");
            else
                Console.WriteLine("Adding cheese,olives and meat");
        }

       private void addSauce()
        {
            Console.WriteLine("Adding sauce");
        }

Things are good for sometimes, but after a while Sanji come back to me claiming that the Mugiwara(straw hats) pirates have made an alliance with some new big pirate named Law and this pirate want to have sea king fish(a great imaginary fish in one piece) in his pizza.
So I have to add this into my code, the simple thing to do is to go and add a new if statement in the method AddIngredients and it will look like this:

private void AddIngredients(String membername="Any")
        {
           
            if(membername=="Nami")
                Console.WriteLine("Adding cheese and olives");
            else if(membername=="Chpper")
                Console.WriteLine("Adding cheese and meat");
            else if(membername=="Chpper")
                Console.WriteLine("Adding cheese,olives, meat and see king fish");
            else
                Console.WriteLine("Adding cheese,olives and meat");
        }

But this a huge violation to the open close principal, the open close principal suggest that a class should be open for extension and close for  changes(http://en.wikipedia.org/wiki/Open/closed_principle).
This is why we should use the power of object oriented paradigm to overcome this problem. For that I’m going to use abstraction, inheritance and polymorphism to come up with a good solution.
First thing to come to our mind is to create a class responsible for making pizza for each member; each of those classes will inherit from the mother class PizzaMaker. The PizzaMaker class will implement the general implementation for the AddIngredient method and the each of the other child class will override this method to add the suitable ingredients for the member. So we have this new class diagram

This is the new AddIngredientPizza of the Pizzamaker class
protected virtual void AddIngredients()
        {
           
                Console.WriteLine("Adding cheese,olives and meat");
        }
This is the NamiPizzaMaker class:
namespace PizzaExample
{
    public class NamiPizzaMaker:PizzaMaker
    {
        protected override void AddIngredients()
        {
            Console.WriteLine("Adding cheese and olives");
        }
    }
}


Now the question is how and where to know which class to instantiate (PizzaMaker, NamiPizzaMaker, ChopperPizzaMaker or LawPizzaMaker). Well the first option is to give that responsibility to higher layer (UI layer) but this way you will create a dependency between layers and violate the Dependency injection principal. So the best way is to go and create a factory class that will be responsible for knowing how to instantiate the class.
The  factory class will look like that :

namespace PizzaExample
{
    public class PizzaFactory
    {
        public static PizzaMaker getPizzaMaker(String member)
        {
            if (member == "Nami")
                return new NamiPizzaMaker();
            if (member == "Chopper")
                return new ChopperPizzaMaker();
            if (member == "Law")
                return new LawPizzaMaker();
            else
                return new PizzaMaker();
        }
    }
}

Well now we protected our AddIngredient Method from violating the open close principals, also we reduce the dependency by adding the factory class that will be responsible for creating the suitable class.
But still if we analyze the static method getPizzaMaker of the PizzaFactory class we will notice couple of bad design smell
         1)      We have to deal with hardcoded strings “Nami”,”Low” and ”Chopper”(hardcoded strings are the root of huge bugs and design problems)
        2)      Each time we add new child class of PizzaMaker we need to modify the getPizzaMaker method again that violate the Open/Close principal
       3)      The method is static(I will explain why this is bad in another article about testing)

Well my solution to 1 and 2 problem is to create an xml configuration file that knows for each member what class to instantiate.This XML structure will hold xml elements, each element will have two properties, one is the name of the member and two the name of the class to instantiate.
Example for the team member Nami we have the class NamiPizzaMaker class that know how to make pizza for Nami(Single responsibility principal), for the factory class to able to return an instance of the NamiPizzaMaker class we have to add this xml element

 <add member=”Nami” classname=”NamiPizzaMaker”/>

The getPizzaMaker method of the PizzaFactory class will look into the xml file, get all the elements, iterate them and when the name of the member equals the “member” property in the xml element the method will get the “classname” property from that same xml element as string and create an instance of the class from string using the Activator.CreateInstance(“nameoftheclass”).

So each time we have a new pizza maker all you have to do is to create a new class that is a subclass of PizzaMaker class and add a new xml element to the configuration file, like that <add member=”new member” classname=”NewSubsclassofPizzaMaker”/>.

To create this xml configuration file you have two solutions, one solution will creating a new xml file called pizzamakers.xml and all your xml elements in it, but with this solution  will have at least 3 or 4 xml files that should be maintained and this is not very productive.

Second solution will be using App.config or web.config, .Net offer many build in classes in the namespace System.Configuration that helps you get access to this configuration file. So I will use this file to put my custom configuration and in the next section I will describe how to do it.

NB: All the previous concepts are general concepts that are valid with any technology that use object oriented architecture, but the next section is .Net specific section because we going to use .Net built in features.

First step is to add a new configuration file to your project and you should get a new file called App.config .


Second Step: Create a custom section

.Net framework has a built in classes to access configuration file all those classes are under the namespace System.Configuration.
And with the ConfigurationManager class you can access the elements of any section in your configuration file including your custom sections using the GetSection method.
ConfigurationManager.GetSection("nameofthesection");

But before add any custom sections to the xml config file and in order for the ConfigurationManager class to be able to recognize your custom section you need to create a subclass of the class ConfigurationSection.
I won’t get in the details of how to create a custom configuration section,  you can look into it in the internet.

We need this class in order to get a custom section called PizzaMakerSection

namespace PizzaExample
{
    public class PizzaMakersSection:ConfigurationSection
    {
        [ConfigurationProperty("", IsRequired=true, IsDefaultCollection=true)]
        public PizzaMakerElementCollection PizzaMaker
        {
            get
            {
                return (PizzaMakerElementCollection)this[""];
            }
            set
            { this[""] = value; }
        }


    }
    public class PizzaMakerElementCollection: ConfigurationElementCollection{
        protected override ConfigurationElement  CreateNewElement()
        {
            return new PizzMakerElement();
        }

        protected override object  GetElementKey(ConfigurationElement element)
        {
            return ((PizzMakerElement)element).className;
        }
        }

    public class PizzMakerElement : ConfigurationElement
    {
        [ConfigurationProperty("member",IsRequired=true)]
        public String Memeber { get { return (string)this["member"]; } set { this["member"] = value; } }
        [ConfigurationProperty("classname",IsRequired=true)]
        public string className
        {
            get
            {
                return (string)this["classname"];
            }
            set
            {
                this["classname"] = value;
            }
        }
    }
}

and the App.config file will look something like that:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
   
      <section
        name="pizzaMakerSection"
        type="PizzaExample.PizzaMakersSection,PizzaExample"
      />
   
   
  
  </configSections>
 
    <pizzaMakerSection>
      <add member="Nami" classname="PizzaExample.NamiPizzaMaker"/>
      <add member="Chopper" classname="PizzaExample.ChopperPizzaMaker"/>
      <add member="Law" classname="PizzaExample.LawPizzaMaker"/>
<add member="Any" classname="PizzaExample.PizzaMaker"/>
    </pizzaMakerSection>
 
</configuration>

Third Step: Modify the factory to be able to read from App.config file and instantiate the appropriate class

namespace PizzaExample
{
    public class PizzaFactory
    {
        public static PizzaMaker getPizzaMaker(String member)
        {
         
            PizzaMakersSection config = (PizzaMakersSection)ConfigurationManager.GetSection("pizzaMakerSection");
            foreach (PizzMakerElement element in config.PizzaMaker)
            {
                if(element.Memeber.Equals(member))
                {
                    try
                    {
                        var type = Type.GetType(element.className);
                        PizzaMaker instance = (PizzaMaker)Activator.CreateInstance(type);
                        return instance;
                    }
                    catch (Exception ex)
                    {
                        //log exception
                        return null;
                    }
                }
            }
            return null;
        }
    }
}

Note that you can add PizzaMaker subclasses for each new member without having to change anything in the code of the method getPizzaMaker of the PizzaFactory class and without violating the open/close principal, all you have to do is
  1)create a subclass of the PizzaMaker class
  2) Add a new xml element to the pizzaMakerSection in the App.config file that have the member property and the classname property.

Conclusion

This is my method to implement the factory pattern in .Net, I hope that was helping and if you have any better methods or advices please share it with me.

samedi 30 mars 2013

A little vision about the future


I would like to take a pause from writing technical articles and share my vision about the future.

     Well I do have a vision and that vision comes from visiting small businesses, every time I visit a small coffee shop I say to myself this man could really use a software program that going to help him do his job better, the same happens when I visit a small grocery store, a carpenter, a lawyer, and a doctor. 

Then I started thinking if everyone have a little software of his own, we can start connecting those software and literally map the word. I’m not talking about 3D simulation that’s easy and virtual, I’m talking about real data and real objects, where every software becomes a node of exchanging data, a real world that could never be called virtual again. 

After having this nice world, I would like to move to the next and the most exciting step, which is including humans in the system, you see the GUI(Graphical user interfaces (those windows and buttons)) was a great breakthrough but GUI is not very natural, Most of the time you took some time to understand how the GUI of a given software works, and when you have millions of software it’s very bad to understand and use all those GUIs. So let’s eliminate all those graphics, and use no GUI at all. But the question how we are going to interact with those software?

Well by using the most natural way which is the brain. Human brains should be able to upload, download data, also it must be able to command software, imagine you can book your trip just by following this flow:

 You think I need a vacation
 Your brain search for available trips
Your brain download those trips into your memory
Your brain choose the best trip for you and book it

Am’ I talking science fiction? No I’m not, we are doing the same thing right now just we are using different techniques and we are obliged to use our eyes as an information encoder machine (this is all what GUI does it represent the information in understandable format for the eye so it can take the information and convert it to another format understandable by the brain), I’m simply talking about removing this middleware encoder and talk directly with a brain in interconnected system.

I guess you like to ask me now, is it possible to talk directly to the brain? I would like to happily answers you “yes”, I worked on a project that aims to help people command a wheel chair using a combination if eyes and brain, when I worked on the system it was very basic, we just determine the gaze of the person and calculate his concentration rate by amplifying his brain signals then based on the concentration rate we move the chair in the direction of the person’s gaze. But the most exciting part, is that the brain use electric signals just like computers, and internet. So all we have to do is understand brains protocols and code the data in a way the brain can understand it. After that you will never have to use your eyes and go through a complex GUI, so if you like to know all about the middle age history, is easy all you have to do is surfing to Wikipedia using your thoughts and download all the information that you want directly to your brain cells.

I hope that you enjoy reading the article, I know is complex vision but I have this believing that everything is possible and if you have a difficult goal just break it to small steps and finally and most importantly surround yourself with people that going to help you achieve your goal either they know it or not. 

dimanche 24 février 2013

Super developer: The Art of the Start

What to learn? What is the best profile of a developer? How to improve the developing skills? Those are the principal questions that every passionate developer asks.

I interviewed a lot of new fresh developers for recruitment or for training; I read many CVs and what I can say about all of them is that every single one of them is counting the number of framework he know.


“Well I know .Net, I know JEE, I know Symfony and I’m really good with python Django”


Mmm Ok! But can you tell me why we use interfaces in OOP, why we use getters and setters, what the difference between Static method and a non-static method and how the memory handles them what are the four principals of OOP. Do you know what a floating point is? what do you know about parallel programming and monitors?


Those are generally my questions, and sadly only few developers were able to answer them and the reason behind it is because they didn't answer correctly to the above questions. Because you see I don’t really care about how many framework you know, I don’t care how many .Net certificates you have because the real question is do you know how to code.


After all, frameworks are a collection of ready-to-use code, you just google them and you will find the suitable class to use, but if don’t know how to code you will never know what to look for and you still writing crap code even if you know all the available classes.


So what to learn? Personally I suggest starting by c language, have fun programming, look for complex problems (like the 8 queen problem, sorting..) and enjoy yourself solving them, feel the power of algorithms, feel the greatness of creation. No UI no buttons just you and the console displaying green text(nice effect). Why c language is important? Well first of all developers must master data structure and coding(can actually write a good if statement and loops) second c language is arguably a low level programming language so developers will deal with low level details like memory management(pointers) also some other stuff like floating points numbers (check this tutorial http://www.cprogramming.com/tutorial.html#fptutorial), fixing point numbers(check this article http://x86asm.net/articles/fixed-point-arithmetic-and-tricks/) , processor cache and memory and many other low level issues that help developers understand computers and create a better optimize code in the future. Also I suggest writing a tcp/udp c based application to deal with low level sockets and network layers. So stop dragging and dropping UI, stop that android/windows phone application that you are doing and go develop some real shits.


After playing with c language go and learn some oriented object language ( I recommend java) and please instead of goggling every single library try to understand the basic of OOP learn what actually is a static method, why we have public, private and protected key words, learn why we are using getters and setters, try to feel the real power of encapsulation, write basic programs that show the value of OOP. After developing some of your own projects and after making all kind of mistakes start reading other people’s code, fall in love with design patterns and SOLID principals learn them and try the applies them every single time you write a peace of OOP code.

Now you have a nice understanding of OOP, you can change the air by learning concurrency and parallel programming. Study what a mutex is doing, what is a monitor… Implement some fun problems like the traffic problem. Concurrency is fun but hard so learn it. In the same time try to learn about compilation process, learn about state transition diagrams and grammars… And if you have time and effort try to understand operating systems and how they work by implementing one(of course with minimum functionality it can be just a console that displays info about hardware) have a look at SOS(simple operating system) http://www.cs.unm.edu/~crowley/osbook/sos.html


I know that was some hard concept and need a lot of time and efforts to master. But hey you the one who want to be the super developer so work for it.

My final thought will be a developer that really understand programming and have great ability to learn is much better than a developer that knows all the framework classes, know how to use them but write shitty code.



vendredi 13 avril 2012

Android vs Windows phone 7 round one


          I’m a Microsoft Student Partner for three years and I’m starting my start-up which is a Microsoft partner too, so basically I’m a .Net user and in particular I’m developing mobile application for the windows phone 7 operating system, but recently I have been doing some projects for the Android operation system. Anyone with my Microsoft background will start doing  some marketing for Microsoft technologies describing them as the best solutions ever, today I’m not doing that also what I’m not doing is describing android as the shiny white knight that save me from Microsoft hell. I’m just going to talk about my little experience using both technologies.

          To begin with I would like to compare the IDE in other words Visual Studio vs eclipse, eclipse is good for an open source product but VS is great, starting with the design, visual studio have much better user interface than eclipse. Also VS provide better debugging options and tools even the break point are better and clearer, because after 8 hours of programming you don’t really like to fetch for little blue points that eclipse call break points, furthermore visual studio handles better the manipulation of the UI elements drag an drops and provide a nice  property tool box that you can use it to customize the UI element as you like, with android it’s another story where UI elements jumps everywhere in the window taking strange positions all over the place which is really missy, and after spending all that time fixing them sometimes at  runtime you get a view completely  different from what you have at design time.  Also visual studio provides a lot of tools helping developers to increase their productivity like creating code snippets, measuring application performance, managing projects, generating graphs…May be all those tools exist with eclipse but you really need to look for them in the web figuring out how to add them and use them which is not very productive, the visual studio philosophy is delivering an environment that empower  developers and let them  focuses only on the code and the application, Microsoft actually did that very well where eclipse is still have a lot to hit that point so let’s give WP7 one point for the IDE.

          Next I would like to compare the views creation process, I’m not going to compare android xml vs Microsoft XAML because I think they are the same, both are just structured XML but I would like to talk about expression kit for wp7 where by the time I just finished creating all the xml that I need to just change an android button color, with expression blend I already created an animated awesome user interface. Manipulating xml is not easy specially for non-developers witch make creating great user interfaces with android harder, In the other hand using blend for wp7 it’s just like using Photoshop where designers can feel free to do everything basically with the mouse without having to write any XAML, and after creating those views developers can and add all the code they want using visual studio. By the way expression kit is free so I will have to give wp7 another point.

          Now let’s compare the functionalities that both OS provides for developers, I think android is 100 year in advance comparing to wp7. Windows phone 7 provide only some basic functionalities and of course it’s all closed so you have to wait for Microsoft to add any functionality that you may need, but with android you can pretty much find anything you need for your application and even if Google doesn’t provide it, you can easily find someone somewhere figure out how to add that functionality and blog it. Microsoft has announced the new version of wp7 Mango providing better functionalities like the support of sqlite witch it was supported by Android three years ago so even Mango can’t stand in front of android in term of functionalities provided for developers, so let’s give android one point for the functionality.

          So until now wp7 is the winner but let’s talk about android community vs wp7 community, but wait a second do wp7 even have a community besides few Microsoft partners (student or professionals) that are pretty much influenced by the Microsoft marketing. Android community is very big very strong and I think it’s the most powerful thing android have. If you got  any kind of problem that you can’t figure out how to solve it, just google it and you will find thousands of posts dealing with that same problem so even an android beginner like me can easily create great things just by looking for them in the internet, with wp7 you can only find some few posts nothing serious and even in the forums developers end the discussion with that phrase :“I think I’m going back to android” , so not only wp7 doesn’t  have a  large community but they are losing them  right now, to give an example the last time I spent three days fixing a problem  that takes only 2 or 3 hours  if I was using android. The community is very important factor for the success of any technology and to increase the productivity of any developer, because when you are a part of strong community you feel safe and you feel capable of solving any problem. Maybe Microsoft has the best developers but even Microsoft engineers could never much the force of the community. So in this point android will get 100 points and bit up wp7.

          I will finish by comparing the technology owners Microsoft and Google. I can’t trust Microsoft any more even if they have better support and better documentation than Google have. Microsoft has killed four technologies in just four years: windows phone 6, Silverlight (that was announced as the future of the web, many start-ups has been established to create application using that technology and now they have nothing to do anymore),WPF and XNA so it will be no surprise if Microsoft announce next year the death of the wp7.And    I don’t trust Google either but I really trust the community because I think that Google doesn’t own android any more Google is just a part of a big community and the real owner of android is android people this is why it will be there for some time  so let’s give android another point for that. 

          It is obviously that 2012 is android year, and I can’t say anything else otherwise I will be a layer or illusionist, but android community must learn from Microsoft philosophy providing better tools to developers and designer, also Google can provide better documentation and support for android and finally the community must really watch out from those guys at Redmond because they are not letting go that market easily specially after the failure of many projects like(Azure cloud) and they will do anything to be the number one after all no one knows what will happen in 2015.

mercredi 7 mars 2012

Cloud Broker : Compatible one solution


What is cloud broker??

      First I will start by explaining what is cloud brokerage, a cloud broker is an intermediary provide one interface to manage all the complexity behind dealing with different cloud services.
If you are an IT enterprise that uses one cloud (public or private) you don’t need that brokering services, all you have to do is to understand that cloud API and start consuming them. But when organisations start using the cloud seriously the one cloud scenario will be likely the most common scenario. Because cloud offers different services for different use case, it provide infrastructure services, storage services, software as a service, data subscription and so long, having one cloud providing all services perfectly is a hard thing to have, for example let’s consider a software company that uses openstack cloud as private cloud to host intern management applications where security really matters, uses Amazon cloud as test platform to do some different deployment scenarios on different environments and finally they uses windows azure as PAAS. Let’s take a look to what this company must deal with: 

-Mastering all the APIs of different clouds (OpenStack, Amazon and Azure)
-Having different monitoring system for deferent clouds
-Managing the security policies for each cloud
-Managing the billing system for each cloud (for example Amazon and azure have different billing policy)

As you see this company have many challenges to face and must have different teams for different cloud what make using those services very costly and very hard witch make no sense at all because cloud computing supposed to offer simplicity and chip services. So the best solution for this company is to use Cloud Service Brokerage(CSB) that offers one entry point to manage all the cloud providing one API, one security system, one monitoring system…(for more information read The role of a Cloud broker http://www.cio.com.au/article/399699/role_cloud_broker/) so in the future CSB will have a very important role in the world of cloud computing and of course will have an economical influence where company will pay for brokering services. In order to help IT managers, CEO and any decision makers I will present the first open source CSB created by French research group, the project called Compatible one.

What is Compatible one??

      Compatible one is the first open source cloud broker, it’s a collaborative project, the first release was on October 2011 and the final one will be on December 2012, the project members include industry and academics leaders, innovative technology statups and a world-renowned open source community. For more information visit the web site http://compatibleone.org.

Compatible one component
The compatible one is composed of four parts:

Designer: Taking into account the user requirements
Scheduler: Design and construct of the provisioning plan
Broker: Execution of the provisioning plan
Provider: Deliver the request cloud service 






Designer:

     The designer will take user requirements in term of both technical and economic criteria, for example the user want to create an instance that have 3 cpu 16 G of memory and 30 G of hard drive and he want to pay no more than 1$ per hour. The user will put all that in a manifest file (well-structured XML file), the manifest structure is based on the model described by CORDS (CompatibleOne Resource Description Schema). CORDS is a model defined by the CompatibleOne Developers based on OCCI (Open Cloud Computing Interface).

What is OCCI?

      OCCI is a community effort in order to standardize the cloud computing interface, cloud computing standardization is in it’s very early stages and OCCI is an effort that aims in its early start to provide one single interface to manage IAAS, and now it serve many other models like PAAS and SAAS http://occi-wg.org/.

But before continuing with CORDS description I would like to explain how OCCI works:

      OCCI is an intermediary between the client and the provider. The idea is to unify the way how client consume services by providing standard REST APIs called OCCI, OCCI interface will receive the Rest request from the client and then it will mapped to the resource management framework(RMF) of the cloud provider and finally the RMF will create some management resources according the user request and send back information to the RMF, the RMF mapped to the OCCI interface and finally OCCI will send a HTTP response to the user communicating all the information that he need to start using those managed resources.




OCCi Components:

OCCI define the infrastructure model extension witch is an abstraction model to real life resources it defines a Resources class composed of three classes:

Network: the user instantiate this class to define his Network resource needs (vlan, label (Token), state)
Storage: the user instantiate this class to define his storage needs (size, state)
Compute: the user instantiate this class to define his Network needs (Architecture, cores, memory…)
And finally a Link Class, the link class is responsible for associating one resource with another.


      Also OCCI defines Mixin, the Mixins are extensions mechanisms that allow new resources capability to be added dynamically to a collection of resources instances (Mixin can be added to resource instance at creation time or at run-time but Mixin can be added only to instances and not objects).


The only question is how to control Mixin since is all dynamic, that’s mean how the user will now what’s supported and when he must add mixins. Well according to the OCCI the Core model is the solution for all those questions, this a fundamental feature that give the capability to resources to be added and discovered at run-time, OCCI users can connect to OCCI core model without having any idea about available resources and start discovering at run-time the various resources and links supported by that implementation.


But how??

      If we examine the figure bellow will find that the structure of the class diagram become more complex, now Resource and Link both inherit from an abstract class called Entity, each Entity is identified by a unique Kind instance. The Kind type is actually a specialised type of category, Kind add to category Action instances, the Action instance represent an invocable operation applicable to a resource instance (e.g. for Virtual Machine resource Action can be launch). For compliance with OCCI Core, all of the types defined in the OCCI Core Model MUST be implemented.


The core Model assures the identification and classification of Entities (Resources and Links) witch make them discoverable. Because each Entity is associated to a unique identifier(Kind instance) so whatever a resource is added the OCCI will look for new Kind instances and find Entities instances associated to them witch make all the inheritance structure of Entity, Resource and Link is client discoverable. The Kind type must implement all category attributes and all instances of Kind type must follow those rules:


A unique Kind instance Must be assigned to each and every sub type of Entity, including Entity itself.
A Kind instance Must expose the attribute names of the Entity sub-type it identifies.
A Kind instance Must expose the Actions defined for its sub-type.
A Kind instance Must be related directly or indirectly to the Kind instance of Entity
If type B inherits type A, where A is a sub-type of Entity, the Kind instance of B MUST be directly related to the Kind instance of A.




The Figure illustrates the relationship of the Kind instances assigned to the Entity, Resource and Compute types. Compute inherits Resource and therefore the Kind instance assigned to compute is related to the Kind instance of Resource. The same applies to the Resource type which inherits Entity.

Example of simple VM resource creation





We can see that the requested Resources is compute and we added two mixin one associated to the OS(Ubuntu) of the virtual Machine and another one indicate the capacity requested(small machine). So the provider did the job and gives back a HTTP response indicating the URL associated to this managed resource.

So this is a brief explanation of OCCI specifications that help you understand better the CORDS schema. 

Now let’s go back and examine CORDS specifications, CORDS it just an extension of the OCCI specification it adds many new objects like Monitoring, deferent network configurations, some node constraints… but in the same time they keep the compatibility with OCCI by implementing the OCCI core model.



The figure present a logical view of the CORDS, we can see that the implementation of OCCI core model is respected while adding many new objects.




The figure present CORDS virtual instance view. The user can define a contract where he put the profile of the service that he like to get and the list of providers, each service is composed by 1 or many contracts and each plan is composed by one or many services (All the attributes if CORDS are defined in the document CORDS reference Manual http://compatibleone.org/bin/download/Docs/WebHome/CordsReferenceManualV2.03.pdf). Finally after doing all the definition a Manifest must be defined as output to the Design phase.



Manifest version 2 description



Image components: each image has a system and packages to be added example (Ubuntu system + Mysql package)



Infrastructure components: Storage resources(example open stack volumes), Network and computes(small instances, tiny instances…)


CompatibleOne scheduler :

      The User manifest is received by a mechanism called the SLAP Master allocation engine. This engine triggers the gathering of events required for accounting and billing, and then transmits the manifest to the CORDS Parser. The CORDS Parser transforms the XML description of the manifest file into a validated and well-formed provisioning plan. The CORDS Parser performs a syntactic verification of the manifest file prior to engaging the descriptive resources used to represent the resulting architectural plan required to meet the specific requirements (scheduler definition from the web site)

To do the parsing on the Manifest file a command line provided by the compatible one APIs can be used: co-parser manifest, that command line will produce a provisioning plan.


ComaptibleOne broker

      The provisioning plan is transmitted to the CORDS Broker. The CORDS Broker is in charge of executing the provisioning plan for the production of an actual service instance to be delivered to the user. The broker will instantiate a service graph for the control of the contractual components described in the plan. During this operation the CORDS Broker will collaborate with various CompatibleOne service providers as required for the realization of the plan. This will be performed while respecting the different constraints and conditions expressly defined in the plan, such as an carrier selection, optimization, monitoring or accountancy.(broker definition from the web site)

To start the broker: $ broker --config accords.xml BROKER/1.0

To publish a provising plan : $ testcb --publisher http://127.0.0.1:8086 plan_manifest.xml

CompatibleOne services used by the broker:

COES:This component will examine monitoring information in the forms of provisioning alerts which will be used in the elaboration of the scoring information that will be used to influence the selection of particular provider platforms during subsequent placement operations.

CONETS: The CompatibleOne Network Services

COIPS: CompatibleOne Image Production services.

COSACS: CompatibleOne Software Appliance Services this components used to personalize application images during resource deployment startup(example adding requested packages)

PS: All the services used by the broker are standalone OCCI (OCCI implementation) REST servers that must be run before start using the broker.

Broker will produce Contracts for the providers



CompatibleOne Operator

      The CORDS Broker coordinates the activity of the CORDS Procci for the selection of the specific cloud providers for the delivery of the provisioning services required by the consumer. A particular provider's ability to deliver resources is guaranteed by their declaration of presence, and their consequently available resources, to the CORDS Publisher. Providers are selected by the CORDS Procci as directed either by the constraints described in the provisioning plan or specified in the global configuration of an operational instance of the ACCORDS platform. ACCORDS (Advanced Capabilities for CompatibleOne Resources Distribution Services) is actually the Provisioning System for CompatibleOne

Communication with the Provider is performed through standard CORDS OCCI client/server interfaces between the CORDS Procci, on the CompatibleOne side, and the Provider Procci, on the Provider side. In this way a individual and specific Procci service provider is responsible for interfacing with a particular Cloud Provider, e.g. an OpenNebula Procci, an OpenStack Procci, an Amazon Procci or an Azure Procci.

Consequently, in order to be made available for operation and use within ACCORDS, a resource needs only to implement an OCCI client/server Procci interface.

Publisher: the publisher is responsible for publishing service provider collection of categories (OCCI specification) for use by other components.

The publisher is a standlone OCCI REST server and must be started before any of the other components may be used. The publisher is started by the command:

$ publisher --config accords.xml PUBLISHER/1.0

Resolver: The resolver library allows the publisher to be consulted for discovery of the collection of service providers for a particular category of service.

Resolver are C libraries, any category can be inspected by typing this command line

$ testresolver categoryname1 categoryname2

Procci: This component of the ACCORDS platform is responsible for the management of generic provisioning contracts as requested by the service broker during the creation of the service instance control graph. Provider specific contracts will be negotiated here using the provider specific procci components as required by the description of the node to be provisioned.