dimanche 30 janvier 2011

Unleash the control system

The control system
Tango is more and more used in big scientific facilities.
It 's based on the middleware CORBA (the ancestor of web services). It allows to exchange resources and to call function between several servers and client.

Tango is just an high level over CORBA more easy to use because it constraints the shared object to define the same interface. This interface was tailored to fit elements found on a control system. Every elements is called a device next to the Object principle. For example, a motor has an attribute position and some commands as stop() ...
more about tango

Why unleashed ?
CORBA is maybe an old technology but it works for this kind of system because it's often a private network (I mean intranet, ...). Due to its internal constraints, CORBA and Internet are not very friendly.
Today, CORBA is no more used by the company because we are in the age of internet.

HTTP vs CORBA
HTTP is also a protocol to exchange information in a distributed network. But HTTP become more and more used thanks to WEB browsing. This protocol is famous for reading data (GET) but it can do other actions (PUT, POST, DELETE)
So CORBA and HTTP protocols are very closed but HTTP is the most used of both. So it's very easy to found piece of software for HTTP. In this way all network are very closed to Internet. I mean you have just to compare software for DNS and Name Service lookup (it's an evidence if you don't know what it is)

For the human resources, it's the same fight. The market place is overloaded of Web developers. Few month ago, I was in the first DevOps Paris meeting and I was the only who works with CORBA.

It's time to change ... First steps
A gateway to keep the philosophy of Tango we need Client/Server communication capable to read and write some attributes, to launch commands. In the same time, we need a structure for the data.
Tango was design to machine to machine communication. Clients can transform the data to be human visible but it's not native in the protocol.
HTTP can replace the middle ware because :
- Every resource is identified by an unique URI (equivalent to IOR in CORBA). A device in Tango is accessible by an address "domain/family/device"
- It manage the read (GET), the write (PUT), add properties (POST), delete properties (DELETE), execute commands (GET with parameters).
- Exchange Data should be structured. Tango Attribute and Command also.

OK, I see ... but I don't want to see only a device in a web browser. HTTP is not only to transfer HTML pages. Have you ever heard about Web Services ? XML-RPC, SOAP use it to transfer structured data as XML. So a client has the capacity to have the state and change it.

Think easy and light
What I like in Tango, it's easy and modular.
Do these HTTP commands remind you something ? Yes, the commands of a REST architecture. While the HTTP and HTML is usefull for human, REST architecture is focused on distributed application (B2B). REST is not a protocol as HTTP it used. REST is an architecture which defines component, verbs and resources identified by an URI in stateless session.
A device could be read like this : http://tangobd/device/sys/tg_test/1
A device attribute like this : http://tangobd/device/sys/tg_test/1/string_scalar

The client doesn't need to maintain a session. A Tango device has an unique state for
all clients (I mean all client see the same thing at the same time)

Lighten the data
HTTP is not known to lighten the data. But if each resource can have a URI, we'll be possible to focus on a little part and to reduced the overhead.  It's also possible to tune the request to obtain a sub tree of the root element.
In REST, data are commonly exchanged in XML format. But as a ProActive (pompous word for Geek ;-), I want some more light structure. YAML is good but I 've just discovered JSON which are very simple and understandable by most of new languages. Is able to represent concrete data by 2 elements :
- as a dictionary
- as a list

For example Tango device could give :
{ "info": {
"alias": "testme",
"attributes": ["double_scalar", "boolean_scalar", "string_scalar"]
"commands": ["devdouble", "devboolean"]
"class":"TangoTest",
"server":"TangoTest/test"
},
"values": {
"attributes":{
"double_scalar":{
"value":20.0,
"unit":"m"
},
"boolean_scalar":{
"value":false,
"unit":"bit"
},
"string_scalar":{
"value":20.0,
"unit":"m"
}
},
"state":"STANDBY",
"status":"Ready to accept request",
}
}
}
Cerise sur le gateau
A big problem with Tango is to manage a cache to workaround the time to response from a device. Because REST is only based on HTTP, we already have this functionality with web proxy.
Security question, no problem with HTTPS
Performance is crucial for major web site like Twitter, Google ... (Load balancing Virtual Server)
There are already several language that provide API for HTTP and not for CORBA. I think about Apple Objective-C. It would be usefull to create iPhone Application to monitor Control System.
Edit : I've just found adORB http://adorb.sourceforge.net/ for Objective-C (iOS compatible)

Conclusion
Maybe CORBA is not dead but it's no more on top of the chart. So I'll try to use the latest technology like a true geek but also as a reality of 2011.
My thought finish on a delicious idea : make it possible. Certainly, I'll try to implements my idea with groovy my favorite language to prototype.

HTTP : http://fr.wikipedia.org/wiki/Hypertext_Transfer_Protocol
CORBA : http://en.wikipedia.org/wiki/CORBA
REST : http://fr.wikipedia.org/wiki/REST
JSON : http://fr.wikipedia.org/wiki/JavaScript_Object_Notation

samedi 29 janvier 2011

Do you know Spock ?

Spock is a very interesting testing framework. It integrates several
features like Mocking, a special testing language and it keeps
compatibility with xUnit.

Imagine you want test Energy of a beamline through a Control System

class Device{
  Device(def name){}
  static def energy=0
//private def gap
  def getGap(){-0.25*energy+11.5}
}

class EnergyProcess extends spock.lang.Specification {
  def beamline = new Device("I06-C-C00/EX/BeamlineEnergy")
  def undulator = new Device("ANS-C06/EI/C-U20")

  def "check the energy of my beamline"() {

     when: "a user change energy of beamline"
      beamline.energy = energy
     then: "the undulator should be in correct position"
      undulator.gap == gap

     where:
      energy | gap
          24 | 5.5
          22 | 6
          20 | 6.5
 }
}
I'm interesting in groovy language for few months (maybe years now) and
I think it would be a real candidate to create a testing environment for
Tango.

dimanche 10 octobre 2010

Imagine a new ... HMI

It's just a proof of concept with groovy capabilities for Tango Controls.

Groovy is a dynamic language over a Java Virtual Machine.
So it works every where, where java runs.
The language is a mix between python, ruby and java.

In the example below, I use the same capacity of python to create property and method dynamically 

// Download and use gotan
  @Grab(group='org.tango', module='gotan', version='0.0.1-SNAPSHOT')

  // Create a new Tango Server with gotan
  def server = new DeviceServer()
  server.integer = 20
  server.random = { Math.random() }
  server.randomize() { max -> Math.random(max) }

  server.start("test/test/test")

In the client part, I use also the dynamic behaviour of groovy to access directly the attribute or command.
 
// And create a client with gotan 
  def client = new DeviceServerProxy("test/test/test")
  println client.integer
  println client.random
  println client.randomize(100) 

The code speaks by itself, isn't it ;-)

 It's just a resume of the capacities of groovy.

PS : The Grab command is great solution to reduce deployment.
It downloads modules from an apache maven repository and loads it.
And do you know that a tango java repository exists !!!