Skip to content
Snippets Groups Projects
Commit f4cdd773 authored by Constantin Jucovschi's avatar Constantin Jucovschi
Browse files

more progress

parent 84987bb7
No related branches found
No related tags found
No related merge requests found
Showing with 118 additions and 79 deletions
package info.kwarc.sally4.mathhubworker;
import info.kwarc.sally4.docmanager.SallyDoc;
public interface LMHClient {
SallyDoc getLMHDoc();
}
......@@ -2,8 +2,10 @@ package info.kwarc.sally4.mathhubworker;
import info.kwarc.sally.comm.planetaryclient.NewService;
import info.kwarc.sally.comm.planetaryclient.RemoveService;
import info.kwarc.sally4.docmanager.SallyDoc;
public interface PlanetaryClient {
void newService(NewService service);
void stopService(RemoveService service);
void stopService(RemoveService service);
SallyDoc getPlanetaryDoc();
}
......@@ -4,17 +4,20 @@ import info.kwarc.sally4.core.CamelContextProvider;
import info.kwarc.sally4.core.SallyInteraction;
import info.kwarc.sally4.docmanager.SallyDoc;
import info.kwarc.sally4.marshalling.CommUtils;
import info.kwarc.sally4.mathhubworker.LMHClient;
import info.kwarc.sally4.planetary.PlanetaryConnection;
import info.kwarc.sally4.servlet.SallyServlet;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.spi.DataFormat;
import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.Validate;
@Component(name="LMHWorkflowInstance")
public class LMHWorkflowInstance extends RouteBuilder {
@Provides(specifications=LMHClient.class)
public class LMHWorkflowInstance extends RouteBuilder implements LMHClient{
String planetaryClientNamespace = "http://kwarc.info/sally/comm/planetaryclient";
@Requires
......@@ -49,4 +52,9 @@ public class LMHWorkflowInstance extends RouteBuilder {
.to("direct:requestAuthKey");
}
@Override
public SallyDoc getLMHDoc() {
return route;
}
}
package info.kwarc.sally4.mathhubworker.impl;
import java.util.ArrayList;
import java.util.List;
import info.kwarc.sally4.mathhubworker.LMHClient;
import info.kwarc.sally4.mathhubworker.PlanetaryClient;
public class MathHubEnvironment {
List<String> services;
PlanetaryClient planetaryClient;
LMHClient lmhClient;
public MathHubEnvironment() {
services = new ArrayList<String>();
}
public void addService(String serviceName) {
}
public PlanetaryClient getPlanetaryClient() {
return planetaryClient;
}
public void setPlanetaryClient(PlanetaryClient planetaryClient) {
this.planetaryClient = planetaryClient;
}
public LMHClient getLmhClient() {
return lmhClient;
}
public void setLmhClient(LMHClient lmhClient) {
this.lmhClient = lmhClient;
}
public String getDescription() {
StringBuilder desc = new StringBuilder();
if (lmhClient !=null)
desc.append("LMH");
return desc.toString();
}
}
package info.kwarc.sally4.mathhubworker.impl;
import info.kwarc.sally4.docmanager.DocumentManager;
import java.util.HashMap;
/**
* Manages the connection between documents and MathHubWorker environments
* @author Constantin Jucovschi
*
*/
public class MathHubManagerModel {
// mapping between a document alex route and an environment
HashMap<String, String> docEnvMapping;
DocumentManager docManager;
public MathHubManagerModel(DocumentManager docManager) {
docEnvMapping = new HashMap<String, String>();
this.docManager = docManager;
}
public HashMap<String, MathHubEnvironment> getAvailableWorkersForRoute(String docQueue) {
HashMap<String, MathHubEnvironment> environments= new HashMap<String, MathHubEnvironment>();
if (docQueue == null)
return environments;
/*
for (IDocWorkflowInstance instance : docManager.getDocWorkflowInstances(new String[]{"lmhworker"})) {
String envID = instance.getRoute().getEnvironmentID();
if (!environments.containsKey(envID))
environments.put(envID, new MathHubEnvironment());
environments.get(envID).add(new MathHubService(instance, "LMH"));
}
*/
return environments;
}
public void connect(String docQueue, String environment) {
this.docEnvMapping.put(docQueue, environment);
}
}
......@@ -3,6 +3,7 @@ package info.kwarc.sally4.mathhubworker.impl;
import info.kwarc.sally.comm.planetaryclient.NewService;
import info.kwarc.sally.comm.planetaryclient.RemoveService;
import info.kwarc.sally4.core.CamelContextProvider;
import info.kwarc.sally4.mathhubworker.LMHClient;
import info.kwarc.sally4.mathhubworker.PlanetaryClient;
import info.kwarc.sally4.processors.FileServeProcessor;
import info.kwarc.sally4.servlet.utils.QueryParser;
......@@ -28,13 +29,36 @@ import org.slf4j.LoggerFactory;
@Instantiate
public class MathHubWorkerSelectorService extends RouteBuilder {
Logger log;
@Requires
CamelContextProvider camelContextProvider;
@Requires
PlanetaryClient [] planetaryClients;
HashMap<String, MathHubEnvironment> environments;
@Bind(aggregate=true)
public void bindLMHClient(LMHClient lmhClient) {
String envid = lmhClient.getLMHDoc().getEnvironmentID();
if (!environments.containsKey(lmhClient.getLMHDoc().getEnvironmentID())) {
environments.put(envid, new MathHubEnvironment());
}
log.info(">>>> Adding LMHClient "+envid);
environments.get(envid).setLmhClient(lmhClient);
}
@Unbind(aggregate=true)
public void unbindLMHClient(LMHClient lmhClient) {
String envid = lmhClient.getLMHDoc().getEnvironmentID();
if (!environments.containsKey(lmhClient.getLMHDoc().getEnvironmentID())) {
return;
}
log.info(">>>> Removing LMHClient "+envid);
environments.get(envid).setLmhClient(null);
}
@Bind(aggregate=true)
public void addPlanetaryClient(PlanetaryClient planetaryClients) {
NewService serv = new NewService();
......@@ -43,33 +67,43 @@ public class MathHubWorkerSelectorService extends RouteBuilder {
serv.setId("mhwsettings");
serv.setName("Math Hub Worker Settings");
serv.setType("toolbar");
serv.setUrl(host+"/planetary/mhwsettings?id=123");//+route.getDocQueue());
serv.setUrl(host+"/planetary/mhwsettings?id="+planetaryClients.getPlanetaryDoc().getDocQueue());
planetaryClients.newService(serv);
}
@Unbind(aggregate=true)
public void removePlanetaryClient(PlanetaryClient planetaryClients) {
}
HashMap<String, MathHubEnvironment> environments;
public MathHubWorkerSelectorService() {
log = LoggerFactory.getLogger(getClass());
environments = new HashMap<String, MathHubEnvironment>();
}
public HashMap<String, Object> getSettings(@Header(QueryParser.QueryMapHeader) HashMap<String, String> query) {
HashMap<String, Object> data = new HashMap<String, Object>();
String id = query.get("id");
//data.put("env", model.getAvailableWorkersForRoute());
data.put("env", environments);
data.put("doc_queue_id", id);
return data;
}
public HashMap<String, Object> setMHW(@Header(QueryParser.QueryMapHeader) HashMap<String, String> query) {
HashMap<String, Object> data = new HashMap<String, Object>();
String id = query.get("id");
String envid = query.get("envid");
data.put("env", environments);
data.put("doc_queue_id", id);
return data;
}
CamelContext resourceContext;
@Validate
public void start() {
resourceContext = new DefaultCamelContext();
......@@ -81,7 +115,7 @@ public class MathHubWorkerSelectorService extends RouteBuilder {
e.printStackTrace();
}
}
@Invalidate
public void stop() {
try {
......@@ -99,15 +133,20 @@ public class MathHubWorkerSelectorService extends RouteBuilder {
@Override
public void configure() throws Exception {
// getContext().addComponent("freemarker", new TemplatingComponent("templates/", getClass().getClassLoader()));
// getContext().addComponent("freemarker", new TemplatingComponent("templates/", getClass().getClassLoader()));
getContext().addComponent("freemarker", new FreemarkerComponent());
from("sallyservlet:///planetary/libs?matchOnUriPrefix=true")
.process(new FileServeProcessor("libs", getClass().getClassLoader() ));
.process(new FileServeProcessor("libs", getClass().getClassLoader() ));
from("sallyservlet:///planetary/mhwsettings")
.process(new QueryParser())
.bean(method(this, "getSettings"))
.to("freemarker:file:///home/costea/workspace_sally4/sally4.git/MathHubWorker/src/main/resources/templates/mhwsettings.html")
.to("mock:result");
.process(new QueryParser())
.bean(method(this, "getSettings"))
.to("freemarker:file:///home/costea/workspace_sally4/sally4.git/MathHubWorker/src/main/resources/templates/mhwsettings.html");
from("sallyservlet:///planetary/setmhw")
.process(new QueryParser())
.bean(method(this, "getSettings"))
.to("freemarker:file:///home/costea/workspace_sally4/sally4.git/MathHubWorker/src/main/resources/templates/mhwsettings.html");
}
}
......@@ -140,4 +140,9 @@ public class PlanetaryClientWorkflowInstance extends RouteBuilder implements Pla
context.createProducerTemplate().sendBody("direct:sendToPlanetaryClient", service);
}
@Override
public SallyDoc getPlanetaryDoc() {
return route;
}
}
......@@ -13,18 +13,18 @@
</div>
</div>
<#list body.env?keys as e>
<form action="setmhw">
<div class="row-fluid">
<div class="span1">${e_index+1}.</div>
<div class="span11 btn">
<#list body.env[e] as workflowInstances>
${workflowInstances.getServiceName()}
</#list>
</div>
<button class="span11 btn">
${body.env[e].getDescription()}
</button>
<input type="hidden" name="envid" value="${e}" />
<input type="hidden" name="id" value="${body.doc_queue_id}" />
</div>
</form>
</#list>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment