Sei sulla pagina 1di 4

ERLANG/OTP FRAMEWORK FOR COMPLEX MANAGEMENT

APPLICATIONS DEVELOPMENT

Carlos Abalde, Vı́ctor M. Gulı́as, Laura M. Castro, Carlos Varela and J. Santiago Jorge
MADS Group, Department of Computer Science, University of A Coruña, A Coruña, Spain
cabalde@udc.es, gulias@udc.es, lcastro@udc.es, carlosvarela@udc.es, sjorge@udc.es

Keywords: Distributed systems, functional languages, design patterns, cluster computing, client/server architecture.

Abstract: This paper presents our ideas about how to evolve a first and early architecture, which has been used in the
development of a large scale management client/server application, to a more sophisticated one, which could
be reused in other developments, significantly reducing the development life cycles of future versions. We
also expose some problems that arised in the process and suggest some solutions.

1 INTRODUCTION The user side is a lightweight client which only


makes remote procedure calls (RPCs), and has no as-
In this paper, we will elaborate some ideas ex- sociated logic (i.e., there are no business objects in the
plaining how to evolve the first and early architec- user side). The server side supports the model and the
ture used in the development of a large scale man- business logic, and is structured in four tiers:
agement client/server application, using the distrib-
uted functional language Erlang (Armstrong et al., Interface Use case Persistent
adapter facades objects
1996), to a more sophisticated one. The application FACADE WAN FACADE FACADE
layer

(ARMISTICE (Armistice, 2002; Cabrero et al., 2003; UBF UBF VO

Gulı́as et al., 2005; Gulı́as et al., 2006), Advanced


DAO

Risk Management Information System: Tracking In- CALLBACK CALLBACK

surances, Claims and Exposures) is a risk manage-


ment information system (RMIS) designed for a large DB

DB

regional company. The aim of the proposed architec- DB

Distributed DB
DB
DB

ture is to help to reduce the development life cycles, DB

and to be reused in similar projects.


DB DB

DB

The paper is structured as follows. Section 2 gives Client side Server side

an overview of the proposed architecture. Next, some


discussion is provided on section 3, explaining how
Figure 1: Framework architecture overview.
the framework would improve the development, tak-
ing our study case as example. Finally, section 4
shows some conclusions and future work to be done.
• Interface adapter: Receives messages from
clients, deserialises their input and parameters,
and gives them the appropriate format so that the
2 FRAMEWORK OVERVIEW server can process the enquiry, and viceversa.
• Use case facades: Facades of the system, which
Our proposal is a layered client/server architecture, represent the access points to each subsystem.
based on two well-known architectural patterns: Lay- Every facade has methods implementing different
ers and Model-View-Controller (Gamma et al., 1999). use cases, using the persistent objects layer.

422
ERLANG/OTP FRAMEWORK FOR COMPLEX MANAGEMENT APPLICATIONS DEVELOPMENT

• Persistent objects layer: Here, domain trans- • Customer.java, which is an user interface facade
fer objects (TOs) and data access objects to access the service and perform internal tasks.
(DAOs) (Marinescu, 2002) are defined. Each TO
models a domain entity, and the DAO is the mod- 2.2 Access Points and Use Cases
ule that interacts with the persistence layer.
• Persistence: It represents the permanent storage Each access point is described by means of it use
over a relational database. cases. Use case descriptions include names, input pa-
Source code for implementing these layers can be rameter list, and transactional information.
automatically generated from a description of: As in the previous section, two Erlang modules
are built from each access point description:
• The client-server communication format.
<access-point name="customer">
• The use cases. <use-case name="add_customer" trans="yes">
• The domain transfer objects and relationships. <param name="CustomerName"/>
<param name="CustomerDescription"/>
</use-case>
2.1 Client-Server Communication </access-point>

The transport layer needs to be lightweight and easily The Erlang generated black box module for this
integrable with different client applications. There are access point is:
several possibilities to solve this problem. For exam- -module(customer_facade).
ple, interface definition languages like XDR (XDR, -export([add_customer/3]).
2003) or ASN.1 (ASN.1, 2003) or complex frame-
works like CORBA (Corba, 2003), most of them sup- add_customer(Session, CName, CDescription) ->
ConnRef = db_facade:connect(),
ported by Erlang/OTP.
session:set_connection(Session, ConnRef),
The UBF scheme (Universal Binary Format (Arm- R = customer_facade_cb:add_customer(Session,
strong, 2002)) has the expressive power of the XML CName, CDescription),
set of standards, but it is considerably simpler. Thus, db_facade:endtrans(ConnRef),
in our framework, we can see the server as a service R.
whose interface is defined in XML as follows, And the callback module skeleton is:
<method name="add_customer" cache="0">
<input>UBF description</input> -module(customer_facade_cb).
<output>UBF description</output> -export([add_customer/3]).
</method>
add_customer(Session, CName, CDescription) ->
Then, our compiler gets each facade interface de- %% write your code here
finition and builds the following skeletons: not_implemented.
• customer.erl, which is a black box module The parameter Session represents the distributed
(from the programmer’s point of view). database over the deployment cluster, in which client
add_customer(Session, UBFParams) -> session state data is stored, providing fault-tolerance
% unpack UBFParameters features. Database connections are organised within
% callback implementation module
R = customer_cb:add_customer(Session,
a supervision tree, so that automatic rollbacks can be
Param1, performed if necessary.
...,
ParamN), 2.3 Persistent Objects Layer
% pack R in a UBF value
Business logic associated with a complex RMIS usu-
• customer_cb.erl, which is a callback module ally has to deal with a big number of domain entities
skeleton that must be filled in by the programmer. with complex relationships amongst them. The actual
add_customer(Session, P1,..., PN) -> coding of these objects and relationships storage is a
% call domain facade very annoying and repeatable task.
case customer_facade:add_customer(Session, The entities are described with their name, a list
P1,...,
PN) of
of their attributes and their relationships.
{error, Reason} -> % adapt result <entity name="customer">
R -> % adapt result; <primary-key>
end. <attribute name="id" type="integer"/>
</primary-key>

423
WEBIST 2007 - International Conference on Web Information Systems and Technologies

<attribute name="name" type="string"/> • Manage another several accident-related tasks


<relation entity="account" multiplicity="*"/> (payments, invoices, repairs. . . ).
</entity>
ARMISTICE logic is structured in three compo-
Here some ideas from powerful persistence and nents. The risk subsystem models a set of basic con-
object-relational mapping frameworks like Hibernate cepts: risk situations (e.g. a shop), risk situations at-
(Java) (Hibernate, 2006) and Active Object (Ruby on tributes (e.g. merchandise value), risk groups (which
Rails) (Ruby, 2006) are borrowed. classify risk situations), dangers (e.g. a fire),. . . and
From this definition the obtained source code will defines the notion of exposure based upon dangers
be composed by a TO module and a DAO module and risk attributes. The policies subsystem uses those
skeleton. An example of TO source code could be: concepts to define insurance policies based upon ex-
-module(customer_to). posures and applicability constraints. Finally, the
-include("customer_to.hrl"). claims subsystem uses the insurance policy to track
-export([new/2, get_name/1, set_name/2]). an accident affecting one or more of the covered ex-
posures, providing useful guidance to forecast limits
new(Id, Name) -> and franchises and a way to manage the related tasks.
#customer_to{id = Id, name = Name}]}.

get_name(CustomerTO) -> 3.1 Actual Armistice Architecture


State#customer_to.name.
As we said before, ARMISTICE is a three-tier
set_name(CustomerTO, Name) -> client/server application. Client and a server commu-
CustomerTO#customer_to{name = Name}. nicate with each other via XML-RPC, a remote pro-
And the DAO would look like: cedure call protocol which uses HTTP as the transport
and XML as the encoding.
-module(customer_dao). The client, developed in Java, is a thin stand-
-include("customer_to.hrl").
-export([create/2, find/2]). alone client, because the complex interactivity ad-
vised against a web or an Erlang-based solution.
create(ConnRef, CustomerTO) -> Implementing ARMISTICE server using the func-
Id = customer_to:get_id(CustomerTO), tional programming language Erlang has shorten the
Name = customer_to:get_name(CustomerTO), development cycle, allowed its deployment over a
Acc = customer_to:get_account(CustomerTO), low-cost cluster, its scalability, and its configuration
Query = "INSERT INTO customer "
in a supervision tree. Combined with these, storage
"VALUES ( " ++ Id ++ ", ’"
++ Name ++ "’, " of its internal state in a distributed database gives it
++ Acc ++ ")", fault-tolerance and reliability properties.
case db_facade:process(ConnRef, Query) of Last but not least, the use of abstraction in the
... form of both functional and design patterns helped
end. to reduce the programming effort to evolve the pro-
totypes during the iterative development process.
As we can see, the DAO assumes the existence of
a database table named after the entity and columns 3.2 Discussion
after the attributes. Relationships are managed de-
pending on the multiplicity of the participants. A powerful mixture of technologies has been put on
practice with ARMISTICE. But, at the same time,
there are a lot of work which could be automatically
performed, and the ideas presented in section 2 are
3 ARMISTICE: CASE STUDY inspired by this reason.
At the moment of writing this article, implemen-
ARMISTICE is a risk management information sys- tation of ARMISTICE’s TOs and DAOs is done com-
tem for a large company. It is a three-tier client/server pletely by hand, as well as are client/server commu-
vertical application which is able to: nication interfaces, etc. These tasks are very monoto-
• Model contracted policies. nous and repeatable, so our XML-based description
framework will make developer’s life much easier, as
• Select the most suitable warranty to cover re- they will be able to concentrate on the design and im-
sources damaged in an accident. plementation of really important parts (business logic)
• Manage the claims for accidents. and also saving programming errors.

424
ERLANG/OTP FRAMEWORK FOR COMPLEX MANAGEMENT APPLICATIONS DEVELOPMENT

4 CONCLUSIONS AND FUTURE REFERENCES


WORK
Armistice (2002). Armistice, Advanced Risk Management
Information System: Tracking Insurances, Claims and
This paper has presented an innovative framework Exposures. http://www.madsgroup.org/armistice.
based on the evolution of our first experiences de-
Armstrong, J. (2002). Getting Erlang to talk to the outside
veloping a real application on a distributed functional world.
language. The proposed architecture could be reused
Armstrong, J., Virding, R., Wikström, C., and Williams, M.
in other traditional management software develop- (1996). Concurrent Programming in Erlang, Second
ment and it is a step forward in features like main- Edition. Prentice-Hall.
tainability, scalability and availability with regard to Arts, T. and Benac Earle, C. (2002). Verifying Erlang
the early architecture. code: a resource locker case-study. In Int. Symposium
The implementation of management software us- on Formal Methods Europe, volume 2391 of LNCS,
ing a functional language may seem an exotic ap- pages 183–202. Springer-Verlag.
proach. But the adaptation of O.O. concepts to the Arts, T. and Sánchez Penas, J. J. (2002). Global scheduler
functional environment is a key factor for success. properties derived from local restrictions. In Proceed-
Another advantage of using Erlang/OTP as the un- ings of ACM Sigplan Erlang Workshop. ACM.
derlying platform for the system development (in ad- ASN.1 (2003). Introduction to ASN.1.
dition to those common in declarative languages), is http://asn1.elibel.tm.fr/en/introduction/index.htm.
that techniques coming from the formal methods area Cabrero, D., Abalde, C., Varela, C., and Castro, L. (2003).
can be applied in order to improve the system design Armistice: An experience developing management
and performance (Arts and Benac Earle, 2002), and to software with Erlang. Proceedings of the 2003 ACM
ensure (at least partially) the system correctness (Arts SIGPLAN workshop on Erlang, pages 23–28.
and Sánchez Penas, 2002). These techniques can be Corba (2003). Object Management Group.
used more naturally with high level declarative lan- http://www.omg.org.
guages, and their results are specially appreciated in Gamma, E. et al. (1999). Design Patterns. Elements
complex management software. of Reusable Object-Oriented Software. Professional
Also, the design of a full application container Computing Series. Addison-Wesley.
(similar to the available in J2EE (J2EE, 2003)), its de- Gulı́as, V. M., Abalde, C., Castro, L., and Varela, C. (2005).
sign and development could be a future work line, fo- A new risk management approach deployed over a
client/server distributed functional architecture. In
cusing on simpler applications where persistence mat- Proceedings of 18th International Conference on Sys-
ters can be hidden. Particularly interesting would be tems Engineering (ICSEng’05). August 16 - 18, 2005,
the development of a persistence layer following the pages 370–375. IEEE Computer Society.
same philosophy of the Ruby on Rails (RoR) Active Gulı́as, V. M., Abalde, C., Castro, L., and Varela, C. (2006).
Record, for the Erlang platform. The two main design Formalisation of a functional risk management sys-
principles of RoR, “Don’t repeat yourself” and “Con- tem. In Proceedings of 8th International Conference
vention over configuration” have proved themselves on Enterprise Information Systems (ICEIS’06). May
as highly productive in this architecture, taking ad- 23 - 27, 2006, pages 516–519. INSTICC Press.
vantage of the use of simple conventions and metapro- Hibernate (2006). Hibernate homepage.
gramming, which could be applied in the functional http://www.hibernate.org/.
world. J2EE (2003). Enterprise Javabeans 2.0 Specification.
Finally, as far as lightweight-style user interface http://java.sun.com/products/ejb/2.0.html.
development is concerned, we strongly believe that Marinescu, F. (2002). EJB Design Patterns. Advanced Pat-
the integration in the framework of any kind of inter- terns, Processes, and Idioms. John Wiley & Sons, Inc.
face definition language like XUL (XUL, 2003) will Ruby (2006). Ruby on rails project homepage.
alleviate this task, and will improve interface design http://www.rubyonrails.org.
and maintainability. XDR (2003). RFC 1832 - XDR: External Data Representa-
tion Standard. http://www.faqs.org/rfcs/rfc1832.html.
XUL (2003). XML User Interface Language.
ACKNOWLEDGEMENTS http://xul.sourceforge.net.

This work has been partially supported by Span-


ish MEyC TIN2005-08986 (FARMHANDS: Recur-
sos Funcionales para la Construccin de Sistemas Dis-
tribuidos Complejos de Alta Disponibilidad).

425

Potrebbero piacerti anche