• Aucun résultat trouvé

Service Composition Deployment and Execution

There are typically two types of agents incorporated into the service composition deployment. One is the MA, the other is the EA. Every optimal service composition plan is submitted to the MA by the DA. The MA will create and dispatch an EA to

execute the plan, and then the EA with the plan information will visit the service nodes according to a certain scheduling algorithm.

3.6.1 How to Manage the EA to Implement the Composite Plan for the MA

The MA is responsible for creating and deploying the EA to implement the compo-sition plan online. The major function of the MA includes:

• Preparing Agent: Because a composite service plan has a unique entry node, the MA only needs to prepare an EA for one plan and the EA with the whole plan will start to migrate from the entry node of the composite plan.

• Dispatching Agent: The entry node of the composite plan is the first site of the EA’s migrating itinerary, so the EA is firstly dispatched by the MA to the entry node of the plan.

• Monitoring Agent: If an exception happens during plan execution and the EA is destroyed, it is desired to recover the EA to continue service processing. If the executing time of one plan surpasses the defined threshold, the MA will dispatch a new EA to execute the plan again.

3.6.2 The Plan Scheduling Algorithm of the EA

Every composite service plan transmitted to the EA is a Directed Acyclic Graph (DAG), which has a unique entry node and a unique end node. Every node in the graph corresponds to one service node and the service processing flow is the EA’s migrating itinerary from the entry node to the end node.

Definition 7: Given two nodesT1andT2, if there is an edge fromT1toT2, thenT1 is the predecessor ofT2andT2is the successor ofT1.

Definition 8: Given two nodesT1andT2, if there is a path fromT1toT2, thenT1is an ancestor ofT2andT2is a descendant ofT1.

3.6.2.1 Basic Execution Patterns

In the DAG of the composite plan, every service node can be executed after all of its predecessors have been finished. As shown in Figure 3.7, there are four basic execution patterns for the EA and any complex execution process can be divided into these patterns.

• Sequential Pattern. IfST1is the unique predecessor ofST2, then one EA is allo-cated toST1andST2to invoke services on them sequentially.

• Branched Pattern. IfST1is a predecessor ofST2andST3, then one EA is allo-cated toST1. After EA reachesST1and finishes the subtask, it will clone itself to dispatch the new EA toST3, and then move toST2.

• Joined Pattern. IfST1andST2are the predecessors ofST3, then two EAs are allo-cated toST1andST2respectively. After the two EAs reachST3and communicate with each other, one of them destroys itself.

• Double Sequential Pattern. IfST1andST2are the predecessors ofST3andST1is also the predecessor ofST2, namely there are two paths fromST1toST3, and then one EA is dispatched to invoke services onST1,ST2andST3.

ST1

ST2

ST3

ST1 ST2

ST1

ST2

ST3

ST1

ST2

ST3

(a) Sequential Pattern (b) Branched Pattern

(c) Joined Pattern (d) Double Sequential Pattern Fig. 3.7 Basic execution patterns for EA

Input:DAG of the Composite Plan (G) Output:The Marked DAG (G0) W: the working queue;

L: integer (layer number);

1. W= null,L= 1;

2. The entry node ofGis marked withLand added intoW; 3. whileWis not emptydo

L:=L+1;

Select the head nodePfromW;

for eachsuccessorSofPinGdo

ifthere is only one path fromPtoSthen Sis marked withL;

AddSinto the tail ofW;

end if end for

DeletePfromW;

end while

Algorithm 1: Using Breadth First Search algorithm to traverse the DAG to mark every node with the layer number.

Input:The Marked DAG (G0)

Output:Executing Report (Agent Message) S: the work node;

1. S= the entry node of G’;L= the layer number ofS;

2. EA executesmigrate(S);

3. function migrate(S);

1. EA migrates toS;

2.ifShas more than one predecessor in the(L1)layerthen EA waits for other cloned EAs and gets their outputs;

Other cloned EAs are destroyed by themselves;

end if

3.ifthe service onSis availablethen

EA invokes the service onSand takes the output of the service;

elseEA sends a fail message to MA and the algorithm is ended;

end if

4.U= the successors nodes ofSin the(L+1)layer;m=the length ofU;

5.ifm=0then

EA sends the final result to MA and the algorithm is ended;

else(m−1)EAs are cloned;

end if

6.for eachnodeNinUdo One EA executesmigrate(N);

end for end function

Algorithm 2: The EA will start to work from the entry node of the marked DAG according to the four basic execution patterns mentioned above. Multiple EAs may be created to perform the tasks in parallel during the course of scheduling.

3.6.2.2 Scheduling Algorithm of the EA

Along with the DAG, the EA will execute the task according to the basic execu-tion patterns menexecu-tioned above, and the directed edges in the DAG direct the EAs migration. The scheduling algorithm of EA is divided into two parts: Algorithm 1 and Algorithm 2. Algorithm 1 makes the nodes of the DAG with the layer number and Algorithm 2 gives the method of scheduling the EA, such as cloning a new EA, disposing oneself, communicating with each other and so on.

3.6.3 An Example for the Scheduling Algorithm of the EA

To describe the algorithm controlling the behavior of the EA explicitly, an example of the composite plan (shown in Figure 3.8) and its execution process are given respectively.

When the MA receives the composite plan, Algorithm 1 is firstly executed to mark every node in DAG with the layer number. The execution result is shown in Figure 3.9. Then, the MA creates an EA namedA1with the marked DAG andA1

ST1 ST3

ST2

ST6 ST4

ST5

ST7

ST8 ST10

ST9 Fig. 3.8 An example of the composite plan

migrates to ST1 to invoke the service onST1. After A1finishes the task, it clones itself to dispatch a new EA namedA2toST3, and then itself moves toST2. AfterA1 reachesST2and finishes the task, it clones itself to dispatch a new EA namedA3to ST5again, and then itself moves toST4. WhenA1,A2andA3all reachST10,A2and A3transfer their outputs toA1and then are destroyed by themselves. BecauseST10 is the end node,A1reports the final result to MA after it invokes the service onST10.

ST1 ST3

ST2

ST6 ST4

ST5

ST7

ST8 ST10

ST9

Layer 1 Layer 2 Layer 3 Layer 4 Layer 5

Fig. 3.9 The marked DAG

As shown in Figure 3.10, it is known there are three paths betweenST1andST10. They are(ST1,ST2,ST4,ST7,ST10),(ST1,ST2,ST5,ST8,ST10)and(ST1,ST3,ST6,ST9, ST10)respectively. These three paths can be traveled byA1,A2andA3in parallel.

This menas that the composite service can be implemented with the most flexibility by agents.

ST1 ST3

ST2

ST6 ST4

ST5

ST7

ST8 ST10

ST9

Layer 1 Layer 2 Layer 3 Layer 4 Layer 5

Agent cloning

Agent disposing

Fig. 3.10 The execution process for EA