1 / 39

Implementing Web Services and running Orchestrations

Implementing Web Services and running Orchestrations. Mario Caruso Claudio Di Ciccio Vincenzo Forte Ettore Iacomussi Massimo Mecella. From the Offline Synthesis Engine we obtained a composition Now the composition will be orchestrated . System Overview. Onine Phase. Offline Phase.

min
Download Presentation

Implementing Web Services and running Orchestrations

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Implementing Web Servicesand running Orchestrations Mario Caruso Claudio Di Ciccio Vincenzo Forte EttoreIacomussi Massimo Mecella

  2. From the Offline Synthesis Engine we obtained a composition • Now the composition will be orchestrated

  3. System Overview Onine Phase Offline Phase Orchestrator Client OffSen composition composition sdd Context Awareness map Orchestrator Target Service Alarm Service Light Service Bed Service

  4. Orchestrator Client • Its only role is to trigger an orchestration by passing a composition to the Orchestrator Engine

  5. System Overview Onine Phase Offline Phase Orchestrator Client OffSen composition composition sdd Context Awareness map Orchestrator Target Service Alarm Service Light Service Bed Service

  6. Orchestrator engine • Given • a composition • a map of the available services • and the current state of the services (thanks to the Context Awareness) • Produces an orchestration and invokes the proper services operations <transition action="doSwitchOnLight" invoke="BedroomLight"> <target state="lightSwitchedOn"/> <postconditionvariable="lightStatus"> <set-valuevalue="1"/> </postcondition> </transition>

  7. Context Awareness • The Context Awareness is a publish/subscribe component • Services play the role of publishers, they publish events related to their conversational state and their variables whenever an update occurs • Orchestration Engine (and other SM4All components) are subscribers, they are always aware of the service’s changes trough the CA notifications

  8. Context Awareness Orchestrator Engine Context Awareness Orchestrator Engine Context Awareness Service Service

  9. System Overview Onine Phase Offline Phase Orchestrator Client OffSen composition composition sdd Context Awareness map Orchestrator Target Service Alarm Service Light Service Bed Service

  10. The role of the map • In the SM4All project there is a Repository, a system component in charge of dynamically maintain and provide information about the currently available services • For the sake of simplicity such component has been replaced by the map file, a static description of the available services in the form of a dictionary: <service_key, service_endpoint> • It plays the role of a bridge between the offline phase and the online phase • the offline synthesis engine produces compositions containing service’s keys (it doesn’t know where the services are deployed) • the orchestrator engine invokes services by replacing keys with the endpoints where the services are deployed • Example: BedroomLight = http://127.0.0.1:9697/BedroomLight?wsdl Alarm = http://127.0.0.1:9697/Alarm?wsdl Bed = http://127.0.0.1:9697/Bed?wsdl

  11. Sdd -> Cbl -> Map -> Services sdd <home … <service-instance name="BedroomLight" description="Light in the bedroom" type="blightServiceType.sbl.xml" siid="bedroom_light" wsa="BedroomLight"> <properties> <service-property name="room" value="bedroom"/> </properties> </service-instance> <service-instance name="Bed" description="Bed in the bedroom" type="bedServiceType.sbl.xml" siid="bedroom_bed" wsa="Bed"></service-instance> <service-instance name="BedRoomAlarm" description="Alarm in the bedroom" type="alarmServiceType.sbl.xml" siid="bedroom_alarm" wsa="Alarm"></service-instance> </home> cbl <conversational-orchestration-state> <community-state> <service-conversational-state service="Alarm" state="unique"/> <service-conversational-state service="Bed" state="up"/> <service-conversational-state service="BedroomLight" state="on"/> <variable-value name="lightStatus" value="1"/> <variable-valuename="bedStatus" value="1"/> </community-state> ... <transition action="doSwitchOnLight" invoke="BedroomLight"> <target state="lightSwitchedOn"/> <postconditionvariable="lightStatus"> <set-valuevalue="1"/> </postcondition> </transition> map BedroomLight = http://127.0.0.1:9697/BedroomLight?wsdl Alarm = http://127.0.0.1:9697/Alarm?wsdl Bed = http://127.0.0.1:9697/Bed?wsdl

  12. Services • The service has • all the operations defined in its behaviour • twoaditional operations (getState and getValue) used to synchronously retrieve the internal state of the service (the asynchronous way is implemented trough the Context Awareness component) doSwitchOffLight, E2 off doSwitchOnLight, E1 doSwitchOffLight, E2 @WebService @SOAPBinding(style = Style.DOCUMENT, use=Use.LITERAL) publicinterfaceLightServer { /*In this case we specify the operation name to match the name of the operation declared of the sbl*/ @WebMethod(operationName="doSwitchOnLight") booleanturnOn(); @WebMethod(operationName="doSwitchOffLight") booleanturnOff(); /*In this case we don't need to explicitly specify the operation name because the java method has the same name of the operation declared of the sbl*/ @WebMethod String getState(); @WebMethodintgetValue(); } on doSwitchOnLight, E1 • Variables: • lightStatus∈{0.1} • Effects: • E1 : lightStatus = 1 • E2 : lightStatus = 0

  13. Services • The service maintains its internal state by updating a state data member and some variables members according to its behaviour. @WebService(endpointInterface = "it.uniroma1.dis.caruso.light.LightServer") publicclassLightServerImplimplementsLightServer{ ... //The value of the variable privateintvalue; //The conversational state of the service private String state; ...

  14. State and variables blightServiceType.sbl blight_status.vml <involved-variables> <involved-variables> <variable name="lightStatus” .. <state name="off" type="initial-final"> <transition action="doSwitchOnLight"> <target state="on" /> <postconditionvariable="lightStatus"> <set-valuevalue="1" /> </postcondition> </transition> <transition action="doSwitchOffLight"> <target state="off" /> <postconditionvariable="lightStatus"> <set-valuevalue="0" /> </postcondition> </transition> </state> <variable-model .. <valuevalue="0" id="0"/> <valuevalue="1" id="1"/> .. variables.vdd <variable name="lightStatus" type="custom" model="blight_status.vml.xml" /> publicclassLightServerImplimplementsLightServer{ publicstaticfinalString STATE_A = "off"; publicstaticfinalString STATE_B = "on"; publicstaticfinalintvalueOn = 1; publicstaticfinalintvalueOff = 0; staticfinal String variableEventTypeName = "lightStatus";

  15. Operation names @WebService @SOAPBinding(style = Style.DOCUMENT, use=Use.LITERAL) publicinterfaceLightServer { @WebMethod(operationName="doSwitchOnLight") booleanturnOn(); @WebMethod(operationName="doSwitchOffLight") booleanturnOff(); @WebMethod String getState(); @WebMethodintgetValue(); } blightServiceType.sbl <involved-variables> <involved-variables> <variable name="lightStatus” .. <state name="off" type="initial-final"> <transition action="doSwitchOnLight"> <target state="on" /> <postconditionvariable="lightStatus"> <set-valuevalue="1" /> </postcondition> </transition> <transition action="doSwitchOffLight"> <target state="off" /> <postconditionvariable="lightStatus"> <set-valuevalue="0" /> </postcondition> </transition> </state>

  16. Service lifecycle Set initial state and variables values Registereventtypes In CA (state and variables) Register the service as a publisherwrt CA Initialization Publishinitial state and variables values Running Whenever an operationisinvoked, and the state/variableschanges, publisheventsaccordingly Termination Unregistereventtypes (state, variables) Unregister the publisher Gracefullyshutdown: NOTE: do not stop the service abruptly, in case you must restart the CA and consequently the whole system (or manually perform unregistrations)

  17. Service lifecycle @WebService(endpointInterface = "it.uniroma1.dis.caruso.light.LightServer") publicclassLightServerImplimplementsLightServer{ publicLightServerImpl(String name){ state = STATE_A; value = valueOff; System.out.println("Registering events"); eventTypeService.type(MediaType.APPLICATION_XML).put(ClientResponse.class, CopalClient.eventType(stateEventTypeName)); eventTypeService.type(MediaType.APPLICATION_XML).put(ClientResponse.class, CopalClient.eventType(variableEventTypeName)); System.out.println("Setting ttl"); WebResource test = service.path(EVENTS_PATH+"/"+stateEventTypeName+"/ttl"); response = test.type(MediaType.TEXT_PLAIN).put(ClientResponse.class, ""+Integer.MAX_VALUE); test = service.path(EVENTS_PATH+"/"+variableEventTypeName+"/ttl"); response = test.type(MediaType.TEXT_PLAIN).put(ClientResponse.class, ""+Integer.MAX_VALUE); String[] eventNames = {stateEventTypeName, variableEventTypeName}; System.out.println("Registering publisher"); publishersService.type(MediaType.APPLICATION_XML).put(ClientResponse.class, CopalClient.publisher(publisherName,eventNames)); myPublisher.type(MediaType.APPLICATION_XML).post(ClientResponse.class, CopalClient.event(stateEventTypeName,state)); myPublisher.type(MediaType.APPLICATION_XML).post(ClientResponse.class, CopalClient.event(variableEventTypeName,""+value));

  18. Service lifecycle @Override publicbooleanturnOff() { System.out.println(name + " turning off"); state = STATE_A; value = valueOff; ClientResponse response = myPublisher.type(MediaType.APPLICATION_XML).post(ClientResponse.class, CopalClient.event(stateEventTypeName,state)); myPublisher.type(MediaType.APPLICATION_XML).post(ClientResponse.class, CopalClient.event(variableEventTypeName,""+value)); returntrue; } @Override publicbooleanturnOn() { System.out.println(name + " turning on"); state = STATE_B; value = valueOn; myPublisher.type(MediaType.APPLICATION_XML).post(ClientResponse.class, CopalClient.event(stateEventTypeName,state)); myPublisher.type(MediaType.APPLICATION_XML).post(ClientResponse.class, CopalClient.event(variableEventTypeName,""+value)); returntrue; }

  19. Service lifecycle Runtime.getRuntime().addShutdownHook(new Thread() { publicvoidrun() { //Remove publisher System.out.println("Removing publisher"); ClientResponse response = myPublisher.delete(ClientResponse.class); System.out.println(response.toString()); System.out.println(response.getEntity(String.class).toString()); System.out.println("Removing events"); WebResourcewr = service.path(EVENTS_PATH+"/"+stateEventTypeName); response = wr.delete(ClientResponse.class); System.out.println(response.toString()); System.out.println(response.getEntity(String.class).toString()); wr = service.path(EVENTS_PATH+"/"+variableEventTypeName); response = wr.delete(ClientResponse.class); System.out.println(response.toString()); System.out.println(response.getEntity(String.class).toString()); } }); Since we are deploying web services without using any application server we terminate them by sending a termination signal (ctrl + c). It is not possible to catch such signal from the Eclipse environment, that’s why we create a jar to be launched from a console.

  20. Publishing services publicclassServicesPublisher { publicstaticvoidmain(String[ ] args) { if (args.length<2){ System.out.println("usage: java -jar LightServices.jarip-address port\nexample: java -jar LightServices.jar 127.0.0.1 9697"); } else{ String address = args[0]; String port = args[1]; String endpointBase = "http://"+address+":"+port; String endpoint1 = endpointBase+"/BedroomLight"; Endpoint ep = Endpoint.publish(endpoint1, newLightServerImpl("BedroomLight")); System.out.println("Web service published @ " + endpoint1); String endpoint2 = endpointBase+"/Bed"; Endpoint ep2 = Endpoint.publish(endpoint2, newBedServerImpl("Bed")); System.out.println("Web service published @ " + endpoint2); String endpoint3 = endpointBase+"/Alarm"; Endpoint ep3 = Endpoint.publish(endpoint3, newAlarmServerImpl("Alarm")); System.out.println("Web service published @ " + endpoint3); } } }

  21. Endpoint BedroomLight = http://127.0.0.1:9697/BedroomLight?wsdl Alarm = http://127.0.0.1:9697/Alarm?wsdl Bed = http://127.0.0.1:9697/Bed?wsdl Map file String endpointBase = "http://"+address+":"+port; .. String endpoint1 = endpointBase+"/BedroomLight”; Endpoint ep = Endpoint.publish(endpoint1, newLightServerImpl("BedroomLight")); System.out.println("Web service published @ " + endpoint1); Services publisher Services must be published to the endpoints declared in the map file. When the Orchestrator Engine finds a service symbolic name it looks at the map and replaces such name with the corresponding endpoint. <transition action="doSwitchOnLight" invoke="BedroomLight"> <target state="lightSwitchedOn"/> <postconditionvariable="lightStatus"> <set-valuevalue="1"/> </postcondition> </transition> 127.0.0.1:9697/BedroomLight

  22. Contains useful methods to communicate with COPAL through REST services Mainclass in charge of deploying web serviceswithout an application server Differentservicesbelong to differentpackages Light Service Interface Light Service Implementation Libraries needed to implement the communicationwhith the REST Copalservices Thesefilesconstitute the service/variablearchives. They are notneeded to build the project, butthey are useful to continouslycheckthat the service you are implementingcomplies with the specifications.

  23. Inspecting Web Services

  24. Avoid Target Namespace collision Target Namespaces do not collide: http://alarm.caruso.dis.uniroma1.it/ http://bed.caruso.dis.uniroma1.it/ http://light.caruso.dis.uniroma1.it/

  25. Exporting runnable jar

  26. Exporting runnable jar Make sure It is checked

  27. A tool to test WS: SoapUI http://www.soapui.org • A free generic graphical client to test Web services: • Given a web service definition (wsdl) it automatically generates all the request for each operation. • Then you can invoke the operation with just one click The tool is already installed in the Orchestrator Engine Virtual Machine @ /home/sm4all/Desktop/Tools/soapui-3.6.1

  28. Invoking an operation

  29. Context Awareness REST interface • http://localhost:7878/copal/events • return current context event types • http://localhost:7878/copal/events/{name} • return context event type with specified name • http://localhost:8080/copal/events/{name}/schema • return schema in context event type with specified name • http://localhost:8080/copal/publishers • return current context publishers registered • http://localhost:8080/copal/publishers/{sourceID} • return context publisher with specified source ID • http://localhost:8080/copal/publishers/{sourceID}/publishedTypes • return all published types in context publisher with specified source ID

  30. Context Awareness REST via browser

  31. Start the whole system • Starting from the sdd file build your Web Services and export the runnable jar file (e.g. Services.jar) • Start the Orchestrator Engine Virtual Machine (VM) • Copy the composition file obtained from the Offline Composition Engine in any location of the VM (e.g. /home/sm4all/Desktop/OrchestratorClient/mycomposition.xml) • Copy the jar in any location of the VM (e.g. /home/sm4all/ServicesExamples/) • Configure the mapping file /usr/share/jboss-6.0.0.Final/server/default/deploy/Sm4allUorOrchestrator.war/WEB-INF/classes/ServiceRepository.propaccording to the sdd file e.g. BedroomLight = http://127.0.0.1:9697/light?wsdl BedRoomAlarm= http://127.0.0.1:9697/alarm?wsdl Bed = http://127.0.0.1:9697/bed?wsdl

  32. Start the whole system • Start Context Awareness System (COPAL): • open a new console • cd /home/sm4all/OSGI_Copal_0.5.2/ • ./run.sh • wait few seconds until the log will display in the last line something similar to "endpoint.service.id=38}” • COPAL willweavailable @ http://localhost:7878

  33. Start the whole system • [OPTIONAL] set the Orchestration Engine properties that you can find in: /usr/share/jboss-6.0.0.Final/server/default/deploy/Sm4allUorOrchestrator.war/WEB-INF/classes/Orchestrator.prop • change the COPAL base address and the OrchestratorStateManager address; by default they are set to http://localhost:7878 and http://localhost:8081 respectively • [OPTIONAL] set the StateManager properties that you can find in: /usr/share/jboss-6.0.0.Final/server/default/deploy/Sm4allUorOrchestratorStatesManager.war/WEB-INF/classes/OrchestratorStatesManager.prop • change the COPAL base address and the OrchestratorStateManager address; by default they are set to http://localhost:7878 and http://localhost:8081 respectively

  34. Start the whole system • Start the Orchestrator Engine • open a new console • cd /usr/share/jboss-6.0.0.Final/bin • ./run.sh -b 0.0.0.0 • wait few seconds until the log will display in the last line something similar to "Started in 40s:384ms”

  35. Start the whole system • Start the Services • open a new console • move to the directory whereyoucopied the jar (e.g. cd /home/sm4all/ServicesExamples/) • java -jar LightServices.jar address port (e.g. java -jar Services.jar127.0.0.1 9697) • NOTE: the address and the port of the base endpoint must be specified according to the map file: BedroomLight= http://127.0.0.1:9697/BedroomLight?wsdl BedRoomAlarm= http://127.0.0.1:9697/Alarm?wsdl Bed = http://127.0.0.1:9697/Bed?wsdl

  36. Start the whole system • Start the Orchestrator Client • cd ~/Desktop/OrchestratorClient/ • java -jar OrchestratorClient.jar <cblPath> e.g. java -jar OrchestratorClient.jarmycomposition.xml • you may either specify an absolute or relative path • [OPTIONAL] if you want to run a client on a location different from localhost: java -jar OrchestratorClient.jar <cblPath> <orchestratorWsdlLocation>

  37. Orchestration results • The Orchestrator Client passes the composition file to the orchestrator • The Orchestrator Engine start to invoke the operations offered by the services • In the web services console see how services are orchestrated (which operations are invoked)

  38. Context Awareness (COPAL) Web Services Orchestrator Engine Orchestrator Client

  39. Shutdown the whole system You can run the orchestration client as many times as you want … Whenyoufinallywant to stop the wholesystem: • Shutdown the services (ctrl+c) • Shutdown the Orchestrator Engine (ctrl+c) • Shutdown the Context Awareness System (ctrl+c and then Enter)

More Related