private static void generateModel(String kevScript, String storageModel) { try { ByteArrayOutputStream stream = new ByteArrayOutputStream(); BufferedReader fileStream = new BufferedReader(new FileReader(new File(kevScript))); KevScriptEngine kengine = new KevScriptOfflineEngine( defaultKevoreeFactory.createContainerRoot(), new NodeTypeBootstrapHelper()); String line = fileStream.readLine(); while (line != null) { kengine.append(line).append("\n"); line = fileStream.readLine(); } /*System.out.println("starting to generate model: " + System.currentTimeMillis()); KevoreeXmiHelper.instance$.save(storageModel, kengine.interpret()); System.out.println("finishing to generate model: " + System.currentTimeMillis());*/ JSONModelSerializer serializer = new JSONModelSerializer(); File fp = new File(storageModel); FileOutputStream fop = new FileOutputStream(fp); serializer.serializeToStream(kengine.interpret(), fop); fop.flush(); fop.close(); System.out.println(fp.getAbsolutePath()); } catch (KevScriptEngineException e) { System.err.println("Unable to save the generated model"); e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
@Start public void start() throws Exception { InetSocketAddress address = new InetSocketAddress(HOST, PORT); peer = new PastryPeer(address); peer.bootsrap(); // peer.createPast(); KevScriptEngine kengine = getKevScriptEngineFactory().createKevScriptEngine(); kengine.addVariable("nodeName", getNodeName()); kengine.addVariable("name", getName()); kengine.addVariable("host", HOST.getHostName()); kengine.append("updateDictionary {name}@{nodeName} { address='{host}' }"); kengine.interpretDeploy(); }
private void apply(KevScriptEngine kengine, int tries) { if (tries < 5) { try { mainSite.getModelService().unregisterModelListener(this); kengine.atomicInterpretDeploy(); mainSite.getModelService().registerModelListener(this); buildCache(); String pattern = mainSite.getDictionary().get("urlpattern").toString(); if (pattern.endsWith("**")) { pattern = pattern.replace("**", ""); } if (!pattern.endsWith("/")) { pattern = pattern + "/"; } mainSite.invalidateCacheResponse(pattern + "talks"); } catch (Exception ignored) { org.kevoree.log.Log.debug("Unable to define talks.", ignored); } } else { org.kevoree.log.Log.warn("Unable to define talks (see debug logs for more info"); } }
private static void generateKevScript( String storageModel, int nbNode, int nbComponent, boolean defineParentNode) { System.out.println("Building model..."); KevScriptEngine kengine = new KevScriptOfflineEngine( defaultKevoreeFactory.createContainerRoot(), new NodeTypeBootstrapHelper()); kengine.append( "merge 'mvn:org.kevoree.corelibrary.sky/org.kevoree.library.sky.jails/2.0.6-SNAPSHOT'"); kengine.append( "merge 'mvn:org.kevoree.corelibrary.javase/org.kevoree.library.javase.basicGossiper/2.0.6-SNAPSHOT'"); kengine.append( "merge 'mvn:org.kevoree.corelibrary.javase/org.kevoree.library.javase.defaultChannels/2.0.6-SNAPSHOT'"); kengine.append( "merge 'mvn:org.kevoree.corelibrary.javase/org.kevoree.library.javase.p2pSock/2.0.6-SNAPSHOT'"); kengine.append( "merge 'mvn:org.kevoree.corelibrary.javase/org.kevoree.library.javase.nioChannels/2.0.6-SNAPSHOT'"); kengine.append( "merge 'mvn:org.kevoree.corelibrary.javase/org.kevoree.library.javase.webserver.api/2.0.6-SNAPSHOT'"); kengine.append( "merge 'mvn:org.kevoree.corelibrary.javase/org.kevoree.library.javase.webserver.tjws/2.0.6-SNAPSHOT'"); // kengine.append("merge // 'mvn:org.kevoree.corelibrary.sky/org.kevoree.library.sky.provider/2.0.6-SNAPSHOT'"); // kengine.append("merge // 'mvn:org.kevoree.corelibrary.sky/org.kevoree.library.sky.provider.web/2.0.6-SNAPSHOT'"); // kengine.append("merge // 'mvn:org.kevoree.corelibrary.sky/org.kevoree.library.sky.minicloud/2.0.6-SNAPSHOT'"); kengine.append("addNode atmosphere : JavaSENode"); // kengine.append("network atmosphere => atmosphere { 'KEVOREE.remote.node.ip'= // '127.0.0.1'}"); kengine.append("addNode atmosphere : JavaSENode"); // {role='host/container', VMARGS = '-Xmx1024m -XX:MaxPermSize=512m', logLevel='INFO'} kengine.append( "addNode fog1 : JailNode {inet='alc0', subnet='10.0.1.0', mask='24', logLevel='INFO'}"); kengine.append( "addNode fog2 : JailNode {inet='alc0', subnet='10.0.2.0', mask='24', logLevel='INFO'}"); kengine.append( "addNode fog3 : JailNode {inet='alc0', subnet='10.0.3.0', mask='24', logLevel='INFO'}"); kengine.append( "addNode fog4 : JailNode {inet='alc0', subnet='10.0.4.0', mask='24', logLevel='INFO'}"); kengine.append( "addNode fog5 : JailNode {inet='alc0', subnet='10.0.5.0', mask='24', logLevel='INFO'}"); kengine.append( "addNode fog6 : JailNode {inet='alc0', subnet='10.0.6.0', mask='24', logLevel='INFO'}"); kengine.append( "addNode fog7 : JailNode {inet='alc0', subnet='10.0.7.0', mask='24', logLevel='INFO'}"); kengine.append( "addNode fog8 : JailNode {inet='alc0', subnet='10.0.8.0', mask='24', logLevel='INFO'}"); kengine.append( "addNode fog9 : JailNode {inet='alc0', subnet='10.0.9.0', mask='24', logLevel='INFO'}"); kengine.append( "addNode fog10 : JailNode {inet='alc0', subnet='10.0.10.0', mask='24', logLevel='INFO'}"); kengine.append("network atmosphere => atmosphere { 'KEVOREE.remote.node.ip'= '127.0.0.1'}"); kengine.append("network fog1 => fog1 { 'KEVOREE.remote.node.ip'= '10.0.1.1'}"); kengine.append("network fog2 => fog2 { 'KEVOREE.remote.node.ip'= '10.0.2.1'}"); kengine.append("network fog3 => fog3 { 'KEVOREE.remote.node.ip'= '10.0.3.1'}"); kengine.append("network fog4 => fog4 { 'KEVOREE.remote.node.ip'= '10.0.4.1'}"); kengine.append("network fog5 => fog5 { 'KEVOREE.remote.node.ip'= '10.0.5.1'}"); kengine.append("network fog6 => fog6 { 'KEVOREE.remote.node.ip'= '10.0.6.1'}"); kengine.append("network fog7 => fog7 { 'KEVOREE.remote.node.ip'= '10.0.7.1'}"); kengine.append("network fog8 => fog8 { 'KEVOREE.remote.node.ip'= '10.0.8.1'}"); kengine.append("network fog9 => fog9 { 'KEVOREE.remote.node.ip'= '10.0.9.1'}"); kengine.append("network fog10 => fog10 { 'KEVOREE.remote.node.ip'= '10.0.10.1'}"); kengine.append("addGroup sync : BasicGossiperGroup"); kengine.append("addToGroup sync atmosphere"); /* kengine.append("addComponent webServer@atmosphere :KTinyWebServer {port = '8080', timeout = '5000'}"); kengine.append("addComponent iaasPage@atmosphere : IaaSKloudResourceManagerPage { urlpattern='/iaas'}"); kengine.append("addComponent iaasManager@atmosphere :IaaSKloudManager"); kengine.append("addChannel iaasDelegateChannel : defSERVICE"); kengine.append("addChannel requestChannel : defMSG"); kengine.append("addChannel responseChannel : defMSG"); kengine.append("bind webServer.handler@atmosphere => requestChannel"); kengine.append("bind iaasPage.request@atmosphere => requestChannel"); kengine.append("bind webServer.response@atmosphere => responseChannel"); kengine.append("bind iaasPage.content@atmosphere => responseChannel"); kengine.append("bind iaasManager.submit@atmosphere => iaasDelegateChannel"); kengine.append("bind iaasPage.delegate@atmosphere => iaasDelegateChannel"); kengine.append("addComponent ws@atmosphere : KTinyWebServer {port = '8081', timeout = '5000'}"); kengine.append("addChannel chan1 : NioChannel"); kengine.append("addChannel chan2 : NioChannel"); kengine.append("bind ws.response@atmosphere => chan1"); kengine.append("bind ws.handler@atmosphere => chan2"); kengine.append("updateDictionary chan1 { port = '9000'}@atmosphere"); kengine.append("updateDictionary chan2 { port = '16000'}@atmosphere"); kengine.append("merge 'mvn:org.kevoree.thesis/org.kevoree.thesis/1.0'"); kengine.append("addComponent modelSubmitter@atmosphere :ThesisModelSubmitter");*/ for (int i = 0; i < nbNode; i++) { kengine.addVariable("childName", "childNode" + i); kengine.addVariable("parentNodeName", "fog" + (i % 10 + 1)); kengine.append("addNode {childName} : PJavaSENode"); if (defineParentNode) { kengine.append("addChild {childName} @ {parentNodeName}"); } } System.out.println("Nodes are built."); int chanPort1 = 9000; int chanPort2 = 16000; for (int i = 0; i < nbComponent; i++) { kengine.addVariable("componentName", "c" + i); kengine.addVariable("nodeName", "childNode" + ((i % nbNode))); kengine.append("addComponent {componentName}@{nodeName} :HelloWorldPage"); // kengine.append("bind {componentName}.content@{nodeName} => chan1"); // kengine.append("bind {componentName}.request@{nodeName} => chan2"); } System.out.println("Components are built."); /* if (nbComponent > 0) { for (int i = 0; i < nbNode; i++) { chanPort1++; chanPort2++; kengine.addVariable("nodeName", "childNode" + i); kengine.addVariable("chanPort1", "" + chanPort1); kengine.addVariable("chanPort2", "" + chanPort2); kengine.append("updateDictionary chan1 { port = '{chanPort1}'}@{nodeName}"); kengine.append("updateDictionary chan2 { port = '{chanPort2}'}@{nodeName}"); } System.out.println("Channels are updated."); }*/ try { byte[] bytes = kengine.getScript().getBytes("UTF-8"); File f = new File(storageModel); FileOutputStream outputStream = new FileOutputStream(f); outputStream.write(bytes); outputStream.flush(); outputStream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }