Skip to content
Snippets Groups Projects
Commit 737dd7eb authored by Sebastian Ebert's avatar Sebastian Ebert
Browse files

bugfixes on topics, services

parent 5f8eff24
No related branches found
No related tags found
No related merge requests found
Showing
with 94 additions and 57 deletions
......@@ -4,7 +4,7 @@ aspect ServiceChannelTransforms {
return this.getStaticTransitionInformation().isServiceTransitionInformation();
}
syn Page DinerosTransition.transformServiceElement() {
syn Page DinerosTransition.transformServiceElement(Map<String, PnObject> addedInstanceObjects) {
Page res = new Page();
Map<String, PnObject> addedObjects = new HashMap<>();
......@@ -17,7 +17,7 @@ aspect ServiceChannelTransforms {
for(ServiceChannel clientChannel: sti.getClientChannels()){
Map<String, Node> clientMap = new HashMap<>();
clientMap.put(TemplateConstants.SERVICE_CAN_CALL_REF_PLACE + "-" + sti.getServiceName() + "-" + sc, petriNet().getPlaceById(clientChannel.getRequestPlaceId()));
clientMap.put(TemplateConstants.SERVICE_CAN_RESP_REF_PLACE + "-" + sti.getServiceName() + "-" + sc, petriNet().getPlaceById(clientChannel.getRequestPlaceId()));
clientMap.put(TemplateConstants.SERVICE_CAN_RESP_REF_PLACE + "-" + sti.getServiceName() + "-" + sc, petriNet().getPlaceById(clientChannel.getResponsePlaceId()));
PetriNet clientNet = ServiceTemplates.getServiceConnectionTemplate(sti.getServiceName() + "-" + sc);
TransformationUtils.includeTemplateInstance(res, petriNet(), clientNet, clientMap, addedObjects);
sc++;
......@@ -43,9 +43,9 @@ aspect ServiceChannelTransforms {
multiplexerMap.put(TemplateConstants.SERVICE_INACTIVE_M_REF_PLACE +
"-" + sti.getServiceName() + "-" + i + "-" + sc2, addedObjects.get(TemplateConstants.SERVICE_INACTIVE_PLACE + "-" + sti.getServiceName() + "-" + i).asNode());
multiplexerMap.put(TemplateConstants.SERVICE_ENTRY_M_REF_PLACE +
"-" + sti.getServiceName() + "-" + i + "-" + sc2, petriNet().getPlaceById(sti.getServerChannel().getRequestPlaceId() + "-" + i + "-" + PnmlConstants.PAGE_SERVER_INSTANCE_SUFFIX));
"-" + sti.getServiceName() + "-" + i + "-" + sc2, addedInstanceObjects.get(sti.getServerChannel().getRequestPlaceId() + "-" + PnmlConstants.PAGE_SERVER_INSTANCE_SUFFIX + "-" + i).asNode());
multiplexerMap.put(TemplateConstants.SERVICE_EXIT_M_REF_PLACE +
"-" + sti.getServiceName() + "-" + i + "-" + sc2, petriNet().getPlaceById(sti.getServerChannel().getResponsePlaceId() + "-" + i + "-" + PnmlConstants.PAGE_SERVER_INSTANCE_SUFFIX));
"-" + sti.getServiceName() + "-" + i + "-" + sc2, addedInstanceObjects.get(sti.getServerChannel().getResponsePlaceId() + "-" + PnmlConstants.PAGE_SERVER_INSTANCE_SUFFIX + "-" + i).asNode());
PetriNet multiplexerNet = ServiceTemplates.getServiceMultiplexerTemplate(sti.getServiceName() + "-" + i + "-" + sc2);
TransformationUtils.includeTemplateInstance(res, petriNet(), multiplexerNet, multiplexerMap, null);
sc2++;
......
import de.tudresden.inf.st.pnml.flatter.transform.*;
import de.tudresden.inf.st.pnml.base.util.ServiceUtils;
aspect ServicePrototypeTransforms {
......@@ -9,20 +10,20 @@ aspect ServicePrototypeTransforms {
}
// apply rule S4
syn Page Page.transformPrototypePage(int detectedCapacity) {
syn Page Page.transformPrototypePage(PetriNet petriNet, int detectedCapacity, Map<String, PnObject> addedObjects) {
int serverCapacity = 0;
String serviceName = this.getServiceName();
DinerosTransition serviceTransition = null;
for(DinerosTransition dt : petriNet().allDinerosTransitions()){
if(detectedCapacity == -1 && dt.getStaticTransitionInformation().isServiceTransitionInformation()){
serverCapacity = dt.getStaticTransitionInformation().asServiceTransitionInformation().getServerChannel().getCapacity();
} else {
serverCapacity = detectedCapacity;
}
if(dt.getStaticTransitionInformation().isServiceTransitionInformation()){
if(dt.getStaticTransitionInformation().asServiceTransitionInformation().getServiceName().equals(serviceName)){
System.out.println("Checking: " + dt.getId());
String dtServiceName = dt.getStaticTransitionInformation().asServiceTransitionInformation().getServiceName();
System.out.println("---- Info: " + dtServiceName + " ---- " + serviceName);
if(dtServiceName.equals(serviceName)){
System.out.println("Matching: " + dt.getId() + " with " + dt.getStaticTransitionInformation().asServiceTransitionInformation().getServerChannel().getCapacity());
serverCapacity = dt.getStaticTransitionInformation().asServiceTransitionInformation().getServerChannel().getCapacity(); //
serviceTransition = dt;
}
}
......@@ -37,13 +38,17 @@ aspect ServicePrototypeTransforms {
Page containerPage = new Page();
containerPage.setId(this.getId() + "-" + PnmlConstants.PAGE_SERVER_CONTAINER_SUFFIX);
System.out.println("Performing for cap: " + serverCapacity);
for( int i = 0; i < serverCapacity; i++){
Page serverInstancePage = this.treeCopyNoTransform();
Page serverInstancePage = ServiceUtils.treeCopyServicePage(petriNet, this, i);
serverInstancePage.setId(serverInstancePage.getId() + "-" + i + "-" + PnmlConstants.PAGE_SERVER_INSTANCE_SUFFIX);
Map<String, PnObject> objects = new HashMap<>();
TransformationUtils.getPnObjectsRecursive(serverInstancePage, objects);
System.out.println("Adding " + objects.size() + " objects for service " + serviceName);
for(PnObject pnObject : serverInstancePage.getObjectList()){
pnObject.setId(pnObject.getId() + "-" + i + "-" + PnmlConstants.PAGE_SERVER_INSTANCE_SUFFIX);
pnObject.getName().setText(pnObject.getId());
for (var entry : objects.entrySet()) {
addedObjects.put(entry.getKey(), entry.getValue());
}
containerPage.addObject(serverInstancePage);
......
......@@ -48,8 +48,8 @@ aspect SignalTransforms {
Transition toTrue = net.getTransitionById(TemplateConstants.INPUT_SIGNAL_TRANSITION_TO_TRUE + "-" + l.getName());
Transition toFalse = net.getTransitionById(TemplateConstants.INPUT_SIGNAL_TRANSITION_TO_FALSE + "-" + l.getName());
System.out.println("toTrue: " + toTrue.getId());
System.out.println("toFalse: " + toFalse.getId());
//System.out.println("toTrue: " + toTrue.getId());
//System.out.println("toFalse: " + toFalse.getId());
// create elements for rule I2 & I3
RefTransition toTrueRt = PrimitiveTemplates.getReferenceTransition(toTrue);
......@@ -70,7 +70,7 @@ aspect SignalTransforms {
TransformationUtils.createAndIncludeArc(res, toFalseRt.getId() + "-to-" + djRefPlace.getId(), toFalseRt, djRefPlace);
TransformationUtils.createAndIncludeArc(res, djRefPlace.getId() + "-to-" + toTrueRt.getId(), djRefPlace, toTrueRt);
if(Boolean.parseBoolean(net.getInputSignalDefinition().get(l.getName()))){
if(!Boolean.parseBoolean(net.getInputSignalDefinition().get(l.getName()))){
pdi.getInitialMarking().setText(pdi.getInitialMarking().getText() + 1);
}
}
......@@ -80,7 +80,7 @@ aspect SignalTransforms {
TransformationUtils.createAndIncludeArc(res, toTrueRt.getId() + "-to-" + djRefPlace.getId(), toTrueRt, djRefPlace);
TransformationUtils.createAndIncludeArc(res, djRefPlace.getId() + "-to-" + toTrueRt.getId(), djRefPlace, toFalseRt);
if(!Boolean.parseBoolean(net.getInputSignalDefinition().get(l.getName()))){
if(Boolean.parseBoolean(net.getInputSignalDefinition().get(l.getName()))){
pdi.getInitialMarking().setText(pdi.getInitialMarking().getText() + 1);
}
}
......
......@@ -16,14 +16,17 @@ import de.tudresden.inf.st.pnml.flatter.tina.NdrioProxy;
import de.tudresden.inf.st.pnml.jastadd.model.PetriNet;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
public class Main {
public static void main(String[] args) throws InvalidIDException, IOException, InterruptedException {
public static void main(String[] args) throws InvalidIDException, InterruptedException, IOException {
String configPath = (args.length > 1) ? args[1] : null;
String pnmlPath = (args.length > 0) ? args[0] : null;
String configPath = null; //((args.length > 1) ? args[1] : null;
String pnmlPath = "/home/sebastian/git/dineros-public/dineros/pnml-relast-apps/" +
"robotic-sorting/rpn-models/sorting-wf-synced-safe-sensor-grpn-minimal-2.pnml"; // (args.length > 0) ? args[0] : null;
if (pnmlPath == null) {
System.out.println("[ERROR] No model found on given input path.");
......@@ -35,13 +38,14 @@ public class Main {
}
// parse the global not flatted petri net
PetriNet petriNet = PnmlParser.parsePnml(pnmlPath).get(0);
PetriNet petriNet = PnmlParser.parsePnml(pnmlPath, false).get(0);
// [STAGE 1] Resolve service prototype pages
ServiceGraph serviceGraph = new ServiceGraph();
serviceGraph.init(petriNet);
TransformationUtils.transformPrototypePagesRecursive(petriNet.getPage(0), null, petriNet, serviceGraph);
Map<String, PnObject> addedInstanceObjects = new HashMap<>();
TransformationUtils.transformPrototypePagesRecursive(petriNet.getPage(0), null, petriNet, serviceGraph, addedInstanceObjects);
petriNet.flushAttrAndCollectionCache();
// [STAGE 2] Transform topic transitions
......@@ -62,7 +66,7 @@ public class Main {
// [STAGE 3] Transform service transitions
for(DinerosTransition dt : petriNet.allDinerosTransitions()){
if(dt.canTransformServiceTransition()){
Page serviceTransformedPage = dt.transformServiceElement();
Page serviceTransformedPage = dt.transformServiceElement(addedInstanceObjects);
for ( int i = 0; i < dt.ContainingPage().getNumObject(); i++ ){
if(dt.ContainingPage().getObject(i).getId().equals(dt.getId())){
dt.ContainingPage().setObject(serviceTransformedPage, i);
......@@ -108,22 +112,23 @@ public class Main {
}
}
printNet(petriNet, true, false);
// [STAGE 7] export flatted net to pnml
// printNet(petriNet, true, false);
System.out.println("[FLATTENER] Exporting to pnml.");
String exportId = UUID.randomUUID().toString();
String pnmlExportPath = PnmlExporter.serializeToPnmlFile(petriNet, "flatted-" + exportId);
String pnmlExportPath = PnmlExporter.serializeToPnmlFile(petriNet, "-flatted-" + exportId);
// convert and add inhibitor arcs
System.out.println("[FLATTENER] Converting to net format.");
NdrioProxy ndrioProxy = new NdrioProxy();
String homeDirectory = System.getProperty("user.dir");
String fid = UUID.randomUUID().toString();
String ndrioTargetPath = homeDirectory + "/temp/net/" + fid + "flatted-" + exportId + ".net";
String ndrioTargetPath = homeDirectory + "/temp/net/" + fid + "-flatted-" + exportId + ".net";
// resolve inhibitor arcs
System.out.println("[FLATTENER] Including inhibitor arcs into net format.");
String inhibitorTargetPath = homeDirectory + "/temp/net/" + fid + "flatted-inh-" + exportId + ".net";
String inhibitorTargetPath = homeDirectory + "/temp/net/" + fid + "-flatted-inh-" + exportId + ".net";
ndrioProxy.pnml2net(pnmlExportPath, ndrioTargetPath);
ndrioProxy.includeInhibitorArcs(petriNet, ndrioTargetPath, inhibitorTargetPath);
......@@ -208,7 +213,7 @@ public class Main {
System.out.println("----------------- REF PLACES -----------------");
for (RefPlace rp : petriNet.allRefPlaces()) {
System.out.println("--- RefPlace: " + rp.getId() + " >> " + rp.getRef().getId());
System.out.println("--- RefPlace: " + rp.getId() + " (" + rp.getName().getText() + ") >> " + rp.getRef().getId());
}
System.out.println("----------------- REF TRANSITIONS -----------------");
......
......@@ -6,7 +6,8 @@ public class PrimitiveTemplates extends PnmlTemplate{
public static DinerosTransition getDinerosTransition(){
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/elements/DinerosTransition.pnml").get(0);
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory +
"/src/main/resources/elements/DinerosTransition.pnml", false).get(0);
for(Transition t : templateNet.allTransitions()){
if(t.getId().equals("DinerosTransition")){
......@@ -19,7 +20,8 @@ public class PrimitiveTemplates extends PnmlTemplate{
public static DinerosPlace getDinerosPlace(){
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/elements/DinerosPlace.pnml").get(0);
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory +
"/src/main/resources/elements/DinerosPlace.pnml", false).get(0);
for(Place p : templateNet.allPlaces()){
if(p.getId().equals("DinerosPlace")){
......@@ -32,7 +34,8 @@ public class PrimitiveTemplates extends PnmlTemplate{
public static RefTransition getReferenceTransition(Transition target){
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/elements/RefTransition.pnml").get(0);
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory +
"/src/main/resources/elements/RefTransition.pnml", false).get(0);
for(RefTransition rt : templateNet.allRefTransitions()){
rt.setRef(target);
......@@ -44,7 +47,8 @@ public class PrimitiveTemplates extends PnmlTemplate{
public static RefPlace getReferencePlace(Place target){
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/elements/RefPlace.pnml").get(0);
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory +
"/src/main/resources/elements/RefPlace.pnml", false).get(0);
for(RefPlace rp : templateNet.allRefPlaces()){
rp.setRef(target);
......
......@@ -21,7 +21,7 @@ public class ServiceTemplates extends PnmlTemplate{
@NotNull
private static PetriNet getPetriNetTemplate(String idSuffix, String netPath) {
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + netPath).get(0);
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + netPath, false).get(0);
for (PnObject po : templateNet.allObjects()) {
updatePnObjectIdAndName(po, idSuffix);
......
......@@ -8,7 +8,8 @@ public class SignalTemplates extends PnmlTemplate{
public static PetriNet getInputSignalTemplate(String idSuffix){
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/templates/InputSignal.pnml").get(0);
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory
+ "/src/main/resources/templates/InputSignal.pnml", false).get(0);
for(PnObject po : templateNet.allObjects()){
updatePnObjectIdAndName(po, idSuffix);
......
......@@ -6,7 +6,8 @@ public class TopicTemplates extends PnmlTemplate {
public static PetriNet getTopicPublisherPetriNet(String idSuffix, int capacity){
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/templates/TopicPublisherTemplate.pnml").get(0);
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory +
"/src/main/resources/templates/TopicPublisherTemplate.pnml", false).get(0);
for(Place p : templateNet.allPlaces()){
if(p.getId().equals(TemplateConstants.PUBLISHER_CAPACITY_PLACE)){
......@@ -27,7 +28,8 @@ public class TopicTemplates extends PnmlTemplate {
System.out.println("New dispatcher with suffix: " + idSuffix);
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/templates/TopicSubDispatcherTemplate.pnml").get(0);
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory
+ "/src/main/resources/templates/TopicSubDispatcherTemplate.pnml", false).get(0);
for(Place p : templateNet.allPlaces()){
if(p.getId().equals(TemplateConstants.DISPATCHER_CAPACITY_PLACE)){
......@@ -46,7 +48,8 @@ public class TopicTemplates extends PnmlTemplate {
public static PetriNet getTopicCallbackQueuePetriNet(String idSuffix, int capacity){
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory + "/src/main/resources/templates/TopicSubCallbackQueueTemplate.pnml").get(0);
PetriNet templateNet = PnmlParser.parsePnml(homeDirectory
+ "/src/main/resources/templates/TopicSubCallbackQueueTemplate.pnml", false).get(0);
for(Place p : templateNet.allPlaces()){
if(p.getId().equals(TemplateConstants.CALLBACK_CAPACITY_PLACE)){
......
......@@ -75,6 +75,8 @@ public class ReferenceFlatter {
for(Transition t : petriNet.allReferencedTransitions()){
System.out.println("Resolving reference on : " + t. getId());
Set<TransitionNode> referencer = new HashSet<>();
Set<Arc> connectedInArcs = new HashSet<>();
Set<Arc> connectedOutArcs = new HashSet<>();
......@@ -83,6 +85,7 @@ public class ReferenceFlatter {
// get all arcs
for(TransitionNode transitionNode : referencer){
System.out.println(">> Detected reference: " + transitionNode.getId());
connectedInArcs.addAll(transitionNode.getInArcs());
connectedOutArcs.addAll(transitionNode.getOutArcs());
nodesToDelete.add(transitionNode);
......
......@@ -153,6 +153,32 @@ public class TransformationUtils {
}
}
/**
* @param page starting point
* @param objects the filled map
* @return
*/
public static void getPnObjectsRecursive(Page page, Map<String, PnObject> objects){
objects.put(page.getId(), page);
Set<Page> subPages = new HashSet<>();
for(PnObject po : page.getObjectsNoTransform()){
objects.put(po.getId(), po);
if(po.isPageNode()){
subPages.add(po.asPage());
}
}
if(subPages.size() == 0){
return;
}
for(Page iterPage : subPages){
getPnObjectsRecursive(iterPage, objects);
}
}
private static DinerosTransition getTransitionByServiceName(PetriNet petriNet, String serviceName){
for(DinerosTransition t : petriNet.allDinerosTransitions()){
......@@ -167,7 +193,7 @@ public class TransformationUtils {
return null;
}
public static void transformPrototypePagesRecursive(Page page, Page parentPage, PetriNet petriNet, ServiceGraph serviceGraph){
public static void transformPrototypePagesRecursive(Page page, Page parentPage, PetriNet petriNet, ServiceGraph serviceGraph, Map<String, PnObject> addedObjects){
if(page.canTransformPrototypePage()){
System.out.println("[INFO] Transforming page: " + page.getId());
......@@ -177,11 +203,13 @@ public class TransformationUtils {
if(serviceGraph.isPotentiallyCyclic(page.getServiceName())){
System.out.println("[WARNING] Detected potentially cyclic service call on: " + page.getServiceName());
System.out.println("[WARNING] Falling back to user defined thread number for: " + page.getServiceName());
transformedPage = page.transformPrototypePage(-1);
System.out.println("#Objects before: " + addedObjects.size());
transformedPage = page.transformPrototypePage(petriNet,-1, addedObjects);
System.out.println("#Objects after: " + addedObjects.size());
} else {
int numInstances = getTransitionByServiceName(petriNet,
page.getServiceName()).getStaticTransitionInformation().asServiceTransitionInformation().getNumClientChannel();
transformedPage = page.transformPrototypePage(numInstances);
transformedPage = page.transformPrototypePage(petriNet, numInstances, addedObjects);
System.out.println("[INFO] Transforming prototype page: " + page.getServiceName() + " to " + numInstances + " instances.");
}
......@@ -212,7 +240,7 @@ public class TransformationUtils {
}
for(Page iterPage : subPages){
transformPrototypePagesRecursive(iterPage, page, petriNet, serviceGraph);
transformPrototypePagesRecursive(iterPage, page, petriNet, serviceGraph, addedObjects);
}
}
......
......@@ -13,7 +13,7 @@
</toolspecific>
</referenceTransition>
<arc id="arc-8" source="CallbackInputRefTransition" target="CallbackConnectorPlace">
<arc id="arc-8" source="CallbackInputRefTransition" target="CallbackInputPlace">
</arc>
<!-- the reference target is just used here, because pnml does not allow dangling refs -->
......
......@@ -19,8 +19,6 @@
<location>none</location>
<subnet>none</subnet>
<type>discretePlaceType</type>
<outputsignalbindings>
</outputsignalbindings>
</toolspecific>
<name>
<text>DispatcherCapacityPlace</text>
......@@ -40,8 +38,6 @@
<location>none</location>
<subnet>none</subnet>
<type>discretePlaceType</type>
<outputsignalbindings>
</outputsignalbindings>
</toolspecific>
<name>
<text>DispatcherConnectorPlace</text>
......@@ -62,8 +58,6 @@
<location>none</location>
<subnet>none</subnet>
<type>discretePlaceType</type>
<outputsignalbindings>
</outputsignalbindings>
</toolspecific>
<name>
<text>DispatcherInputPlace</text>
......@@ -84,8 +78,6 @@
<location>none</location>
<subnet>none</subnet>
<type>discreteTransitionType</type>
<inputsignalbindings>
</inputsignalbindings>
<inputsignalclause></inputsignalclause>
</toolspecific>
<name>
......@@ -103,8 +95,6 @@
<location>none</location>
<subnet>none</subnet>
<type>discreteTransitionType</type>
<inputsignalbindings>
</inputsignalbindings>
<inputsignalclause></inputsignalclause>
</toolspecific>
<name>
......@@ -122,8 +112,6 @@
<location>none</location>
<subnet>none</subnet>
<type>discreteTransitionType</type>
<inputsignalbindings>
</inputsignalbindings>
<inputsignalclause></inputsignalclause>
</toolspecific>
<name>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment