Server Side Negotiation Example

Server Side Configuration

A WSAG4J factory action called "WSAG4J-SAMPLE" is added and configured in the wsag4j engine configuration file. Please refer to factory actions for further documentation on how to add and configure new actions. This factory action specifies a template creation strategy (SampleGetTemplateAction), a negotiation strategy (SampleNegotiateAction), and an agreement creation strategy (SampleCreateAgreementAction) for the negotiation scenario described in Negotiation Scenario. The SampleGetTemplateAction dynamically creates an agreement template using the Velocity template language with current resource availability (number of free resources for certain time-frame). The SampleNegotiateAction extends the abstract AbstractNegotiationAction that implements the interface INegotiationAction and create counter offers against the offers received from a consumer. The SampleCreateAgreementAction creates an agreement for the the negotiated offer. The monitoring handler SampleSDTMonitor is added to SampleAgreement to monitor the created reservation, updates the target host name which has been reserved for the required time frame and updates the corresponding service term state to COMPLETED once a reservation is finished.

Server Side Implementation

In this implementation of the action we can add or modify negotiation constraints, which are used to define ranges and preferences of the client. The result of a negotiation call to this action is an array of NegotiationOfferType instances, the so called counter offers. In first negotiation iteration we create two negotiation counter offers as under:

CounterOffer_1: 05 resources for 20 minutes duration with a time fame as startTime = current + 5, endTime = startTime + 20

CounterOffer_2: 05 resources for 15 minutes duration with a time fame as startTime = current + 10, endTime = startTime + 30

Please refer to SampleNegotiateAction for detailed implementation. Following we give an example on how to create such a counter offer:

SampleOffer counterOffer = new SampleOffer((NegotiationOfferType) offer.copy());
                        
counterOffer.setOfferId("counterOffer_1_" + offerID);
counterOffer.getNegotiationOfferContext().setCounterOfferTo(offerID);
                        
ResourcesType resources = counterOffer.getResourceDefinition();
                
RangeValueType totalCountRange = RangeValueType.Factory.newInstance();
totalCountRange.addNewExact().setDoubleValue(5); 
resources.setTotalResourceCount(totalCountRange);
                
TimeConstraintType timeConstraint = counterOffer.getTimeConstraint();
                
Calendar startTime = Calendar.getInstance();
startTime.set(Calendar.SECOND, 0);
startTime.set(Calendar.MILLISECOND, 0);
startTime.add(Calendar.MINUTE, 5);
Calendar endTime = (Calendar) startTime.clone();
endTime.add(Calendar.MINUTE, 15);
timeConstraint.setStartTime(startTime);
timeConstraint.setEndTime(endTime);
timeConstraint.setDuration(15);
                
NegotiationConstraintSectionType constraints = addCounterOfferConstraints(1,5,startTime,endTime);
counterOffer.setNegotiationConstraints(constraints);
                
setResourcesSDT(counterOffer, resources);
setTimeConstraintSDT(counterOffer, timeConstraint);
                
return new NegotiationOfferType[] {counterOffer.getXMLObject()};

For each counter offer one or multiple negotiation constraints can be defined. The following snipplet shows the definition of the negotiation constraints for a counter offer that restricts the current availability of the resources for a specified time frame.

NegotiationConstraintSectionType constraints = NegotiationConstraintSectionType.Factory.newInstance();
// add item constraint for resources
NegotiationOfferItemType resourcesItem = constraints.addNewItem();
resourcesItem.setName(RESOURCES_ITEM_NAME);
resourcesItem.setLocation(RESOURCES_XPATH);
        
ItemConstraint resConstraint = resourcesItem.addNewItemConstraint();
XmlDouble minResources = XmlDouble.Factory.newInstance();
minResources.setDoubleValue(minValue);
resConstraint.addNewMinInclusive().setValue(minResources);
XmlDouble maxResources = XmlDouble.Factory.newInstance();
maxResources.setDoubleValue(maxValue);
resConstraint.addNewMaxInclusive().setValue(maxResources);
       
// add item constraint for time frame
NegotiationOfferItemType tcItem = constraints.addNewItem();
tcItem.setName(TC_ITEM_NAME);
tcItem.setLocation(TC_XPATH);
                        
ItemConstraint timeConstraint = tcItem.addNewItemConstraint();
        
timeConstraint.addNewMinInclusive().setValue(XmlDateTime.Factory.newValue(start));
timeConstraint.addNewMaxInclusive().setValue(XmlDateTime.Factory.newValue(end));             

The second negotiation iteration creates only one counter offer as follows:

CounterOffer: 05 resources for 15 minutes duration with a time fame as startTime = current + 5, endTime = startTime + 15

At the end all so created counter offers are returned as an array of counter offers:

return new NegotiationOfferType[] {counterOffer.getXMLObject(),...};