Revision 37397
Added by Michele Artini almost 9 years ago
modules/dnet-components/trunk/src/main/java/eu/dnetlib/rmi/soap/ManagerWorkerService.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.rmi.soap; |
2 | 2 |
|
3 |
import java.awt.Image; |
|
4 |
|
|
5 | 3 |
import javax.jws.WebParam; |
6 | 4 |
import javax.jws.WebService; |
7 | 5 |
|
6 |
import eu.dnetlib.rmi.object.manager.ProcessImageDesc; |
|
7 |
|
|
8 | 8 |
@WebService(targetNamespace = "http://services.dnetlib.eu/") |
9 | 9 |
public interface ManagerWorkerService extends BaseService { |
10 | 10 |
|
11 |
Image getProcessImage(@WebParam(name = "procId") String procId);
|
|
11 |
ProcessImageDesc getProcessImageDesc(@WebParam(name = "procId") String procId);
|
|
12 | 12 |
|
13 |
String getProcessImageMap(@WebParam(name = "procId") String procId); |
|
14 |
|
|
15 | 13 |
} |
modules/dnet-components/trunk/src/main/java/eu/dnetlib/rmi/object/manager/ProcessImageDesc.java | ||
---|---|---|
1 |
package eu.dnetlib.rmi.object.manager; |
|
2 |
|
|
3 |
import javax.xml.bind.annotation.XmlRootElement; |
|
4 |
|
|
5 |
@XmlRootElement |
|
6 |
public class ProcessImageDesc { |
|
7 |
|
|
8 |
private String format; |
|
9 |
private String base64; |
|
10 |
private String imageMap; |
|
11 |
|
|
12 |
public ProcessImageDesc() {} |
|
13 |
|
|
14 |
public ProcessImageDesc(final String format, final String base64, final String imageMap) { |
|
15 |
this.format = format; |
|
16 |
this.base64 = base64; |
|
17 |
this.imageMap = imageMap; |
|
18 |
} |
|
19 |
|
|
20 |
public final String getFormat() { |
|
21 |
return format; |
|
22 |
} |
|
23 |
|
|
24 |
public final void setFormat(final String format) { |
|
25 |
this.format = format; |
|
26 |
} |
|
27 |
|
|
28 |
public final String getBase64() { |
|
29 |
return base64; |
|
30 |
} |
|
31 |
|
|
32 |
public final void setBase64(final String base64) { |
|
33 |
this.base64 = base64; |
|
34 |
} |
|
35 |
|
|
36 |
public final String getImageMap() { |
|
37 |
return imageMap; |
|
38 |
} |
|
39 |
|
|
40 |
public final void setImageMap(final String imageMap) { |
|
41 |
this.imageMap = imageMap; |
|
42 |
} |
|
43 |
} |
modules/dnet-node-services/trunk/src/main/java/eu/dnetlib/msro/worker/ManagerWorkerServiceImpl.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.msro.worker; |
2 | 2 |
|
3 |
import java.awt.Image; |
|
3 |
import java.awt.image.BufferedImage; |
|
4 |
import java.io.ByteArrayOutputStream; |
|
4 | 5 |
import java.io.IOException; |
5 | 6 |
|
6 | 7 |
import javax.imageio.ImageIO; |
7 |
import javax.xml.ws.soap.MTOM; |
|
8 | 8 |
|
9 |
import org.apache.commons.codec.binary.Base64; |
|
10 |
import org.apache.commons.io.IOUtils; |
|
9 | 11 |
import org.apache.commons.logging.Log; |
10 | 12 |
import org.apache.commons.logging.LogFactory; |
11 | 13 |
import org.springframework.beans.factory.annotation.Autowired; |
... | ... | |
15 | 17 |
|
16 | 18 |
import eu.dnetlib.common.services.AbstractBaseService; |
17 | 19 |
import eu.dnetlib.msro.worker.ui.ProcessToImageMapHelper; |
20 |
import eu.dnetlib.rmi.object.manager.ProcessImageDesc; |
|
18 | 21 |
import eu.dnetlib.rmi.soap.ManagerWorkerService; |
19 | 22 |
|
20 |
@MTOM |
|
21 | 23 |
public class ManagerWorkerServiceImpl extends AbstractBaseService implements ManagerWorkerService { |
22 | 24 |
|
23 | 25 |
@Autowired |
... | ... | |
25 | 27 |
private static final Log log = LogFactory.getLog(ManagerWorkerServiceImpl.class); |
26 | 28 |
|
27 | 29 |
@Override |
28 |
public Image getProcessImage(final String procId) {
|
|
30 |
public ProcessImageDesc getProcessImageDesc(final String procId) {
|
|
29 | 31 |
final GraphProcess proc = registry.findProcess(procId); |
32 |
byte[] imgBytes; |
|
33 |
String mapContent = ""; |
|
30 | 34 |
try { |
31 | 35 |
if (proc != null) { |
36 |
final ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
|
32 | 37 |
try { |
33 | 38 |
final ProcessImageMapCreator imageMapCreator = new ProcessImageMapCreator(proc, new ProcessToImageMapHelper(procId)); |
34 |
return imageMapCreator.getImage(); |
|
39 |
final BufferedImage image = imageMapCreator.getImage(); |
|
40 |
ImageIO.write(image, "png", bos); |
|
41 |
imgBytes = bos.toByteArray(); |
|
42 |
mapContent = imageMapCreator.getMapContents(); |
|
35 | 43 |
} catch (Throwable e) { |
36 |
return ImageIO.read(getClass().getResourceAsStream("/eu/dnetlib/msro/worker/ui/wf_problem.png")); |
|
44 |
imgBytes = IOUtils.toByteArray(getClass().getResourceAsStream("/eu/dnetlib/msro/worker/ui/wf_problem.png")); |
|
45 |
} finally { |
|
46 |
bos.close(); |
|
37 | 47 |
} |
38 | 48 |
} else { |
39 |
return ImageIO.read(getClass().getResourceAsStream("/eu/dnetlib/msro/worker/ui/wf_not_found.png"));
|
|
49 |
imgBytes = IOUtils.toByteArray(getClass().getResourceAsStream("/eu/dnetlib/msro/worker/ui/wf_not_found.png"));
|
|
40 | 50 |
} |
41 | 51 |
} catch (IOException e) { |
42 | 52 |
log.error("Error generating wf image for process: " + procId, e); |
43 | 53 |
return null; |
44 | 54 |
} |
55 |
return new ProcessImageDesc("image/png", new String(Base64.encodeBase64(imgBytes)), mapContent); |
|
45 | 56 |
} |
46 | 57 |
|
47 |
@Override |
|
48 |
public String getProcessImageMap(final String procId) { |
|
49 |
final GraphProcess proc = registry.findProcess(procId); |
|
50 |
if (proc != null) { |
|
51 |
try { |
|
52 |
final ProcessImageMapCreator imageMapCreator = new ProcessImageMapCreator(proc, new ProcessToImageMapHelper(procId)); |
|
53 |
return imageMapCreator.getMapContents(); |
|
54 |
} catch (Throwable e) {} |
|
55 |
} |
|
56 |
return ""; |
|
57 |
} |
|
58 | 58 |
} |
modules/dnet-modular-workflows-ui/branches/newManagerService/src/main/java/eu/dnetlib/functionality/modular/ui/workflows/controllers/WorkflowsController.java | ||
---|---|---|
55 | 55 |
import eu.dnetlib.msro.dispatcher.WorkflowDispatcher; |
56 | 56 |
import eu.dnetlib.msro.dispatcher.WorkflowRegistry; |
57 | 57 |
import eu.dnetlib.msro.worker.WorkflowConstants; |
58 |
import eu.dnetlib.rmi.object.manager.ProcessImageDesc; |
|
58 | 59 |
import eu.dnetlib.rmi.objects.is.BlackboardActionStatus; |
59 | 60 |
import eu.dnetlib.rmi.objects.is.DnetDataStructure; |
60 | 61 |
import eu.dnetlib.rmi.soap.exceptions.InformationServiceException; |
... | ... | |
242 | 243 |
* if (process != null) { for (Node node : process.getGraph().getNodes()) { if (node.getId() == nid) { return node.getName(); } } } |
243 | 244 |
* return "-"; } |
244 | 245 |
*/ |
245 |
@RequestMapping("/ui/wf_proc.img") |
|
246 |
public void showProcessWorkflow(final HttpServletResponse response, @RequestParam(value = "id", required = true) final String id) throws Exception { |
|
247 |
BufferedImage image = processGraphGenerator.getProcessImage(id); |
|
248 |
sendImage(response, image); |
|
249 |
} |
|
250 | 246 |
|
251 | 247 |
@RequestMapping("/ui/wf_proc.kill") |
252 | 248 |
public @ResponseBody |
... | ... | |
322 | 318 |
|
323 | 319 |
@RequestMapping("/ui/wf_journal.get") |
324 | 320 |
public @ResponseBody |
325 |
Map<String, Object> getWfJournalLog(@RequestParam(value = "id", required = true) final String id) throws Exception {
|
|
321 |
Map<String, Object> getWfJournalLog(@RequestParam(value = "proc", required = true) final String procId) throws Exception {
|
|
326 | 322 |
final Map<String, Object> res = Maps.newHashMap(); |
327 | 323 |
|
328 |
final Map<String, String> logs = dnetLogger.findOne("system:processId", id);
|
|
324 |
final Map<String, String> logs = dnetLogger.findOne("system:processId", procId);
|
|
329 | 325 |
|
330 | 326 |
if (logs != null && !logs.isEmpty()) { |
331 | 327 |
final List<String> keys = Lists.newArrayList(logs.keySet()); |
... | ... | |
341 | 337 |
res.put("journal", journalEntry); |
342 | 338 |
} |
343 | 339 |
|
344 |
final ProcessInfo process = wfRegistry.findProcess(id);
|
|
340 |
final ProcessInfo process = wfRegistry.findProcess(procId);
|
|
345 | 341 |
|
346 | 342 |
if (process != null) { |
347 |
/* |
|
348 |
* final String mapContent = process.getState() == ProcessState.Created ? "" : processGraphGenerator.getProcessImageMap(id); |
|
349 |
* |
|
350 |
* String status = ""; if (!process.isComplete()) { status = process.getState().toString().toUpperCase(); } else if |
|
351 |
* ("true".equals(process.getEnv().getAttribute(WorkflowConstants.SYSTEM_COMPLETED_SUCCESSFULLY))) { status = "SUCCESS"; } else |
|
352 |
* { status = "FAILURE"; } |
|
353 |
* |
|
354 |
* final String img = process.getState() == ProcessState.Created ? "../resources/img/notStarted.gif" : "wf_proc.img?id=" + id + |
|
355 |
* "&t=" + DateUtils.now(); |
|
356 |
* |
|
357 |
* final String name = process.getGraph().getName(); |
|
358 |
* |
|
359 |
* final long startDate = NumberUtils.toLong(process.getEnv().getAttribute(WorkflowConstants.SYSTEM_START_DATE), 0); final long |
|
360 |
* endDate = NumberUtils.toLong(process.getEnv().getAttribute(WorkflowConstants.SYSTEM_END_DATE), 0); |
|
361 |
* |
|
362 |
* final AtomicWorkflowDescriptor wf = new AtomicWorkflowDescriptor(id, name, status, mapContent, img, true, "auto", "RUNNING", |
|
363 |
* startDate, endDate); |
|
364 |
* |
|
365 |
* res.put("graph", wf); |
|
366 |
*/ |
|
367 |
// TODO |
|
343 |
if (process.getStatus() != BlackboardActionStatus.ASSIGNED) { |
|
344 |
final ProcessImageDesc desc = processGraphGenerator.getProcessImageDesc(procId); |
|
345 |
if (desc != null) { |
|
346 |
res.put("WF_IMAGE_BASE64", desc.getBase64()); |
|
347 |
res.put("WF_IMAGE_MAP", desc.getImageMap()); |
|
348 |
res.put("WF_IMAGE_FORMAT", desc.getFormat()); |
|
349 |
} |
|
350 |
} |
|
368 | 351 |
} |
369 | 352 |
|
370 | 353 |
return res; |
modules/dnet-modular-workflows-ui/branches/newManagerService/src/main/java/eu/dnetlib/functionality/modular/ui/workflows/sarasvati/viewer/ProcessGraphGenerator.java | ||
---|---|---|
1 | 1 |
package eu.dnetlib.functionality.modular.ui.workflows.sarasvati.viewer; |
2 | 2 |
|
3 |
import java.awt.Graphics2D; |
|
4 |
import java.awt.Image; |
|
5 | 3 |
import java.awt.image.BufferedImage; |
6 | 4 |
import java.io.File; |
7 | 5 |
import java.io.FileOutputStream; |
... | ... | |
20 | 18 |
import eu.dnetlib.msro.dispatcher.ProcessInfo; |
21 | 19 |
import eu.dnetlib.msro.dispatcher.SarasvatiUtils; |
22 | 20 |
import eu.dnetlib.msro.dispatcher.WorkflowRegistry; |
21 |
import eu.dnetlib.rmi.object.manager.ProcessImageDesc; |
|
23 | 22 |
import eu.dnetlib.rmi.soap.ManagerWorkerService; |
24 |
import eu.dnetlib.rmi.soap.exceptions.ManagerServiceException; |
|
25 | 23 |
|
26 | 24 |
public class ProcessGraphGenerator { |
27 | 25 |
|
... | ... | |
33 | 31 |
|
34 | 32 |
private MemEngine engine = new MemEngine(); |
35 | 33 |
|
36 |
public BufferedImage getProcessImage(final String procId) throws Exception {
|
|
34 |
public ProcessImageDesc getProcessImageDesc(final String procId) throws Exception {
|
|
37 | 35 |
final ProcessInfo proc = wfRegistry.findProcess(procId); |
38 | 36 |
final ManagerWorkerService mws = serviceLocator.getService(ManagerWorkerService.class, proc.getWorkerId()); |
39 |
final Image image = mws.getProcessImage(procId); |
|
40 |
return toBufferedImage(image); |
|
41 |
|
|
37 |
return mws.getProcessImageDesc(procId); |
|
42 | 38 |
} |
43 | 39 |
|
44 |
public String getProcessImageMap(final String procId) throws Exception { |
|
45 |
final ProcessInfo proc = wfRegistry.findProcess(procId); |
|
46 |
final ManagerWorkerService mws = serviceLocator.getService(ManagerWorkerService.class, proc.getWorkerId()); |
|
47 |
final String map = mws.getProcessImageMap(procId); |
|
48 |
return map; |
|
49 |
} |
|
50 |
|
|
51 | 40 |
public BufferedImage getWfDescImage(final String id, final String name, final String xml) throws Exception { |
52 | 41 |
final Graph graph = loadGraph(name, xml); |
53 | 42 |
final GraphImageMapCreator creator = new GraphImageMapCreator(graph, new GraphToImageMapHelper(id)); |
... | ... | |
75 | 64 |
} |
76 | 65 |
} |
77 | 66 |
|
78 |
private BufferedImage toBufferedImage(final Image img) throws ManagerServiceException { |
|
79 |
if (img == null) { |
|
80 |
throw new ManagerServiceException("Fetched image is null"); |
|
81 |
} else if (img instanceof BufferedImage) { |
|
82 |
return (BufferedImage) img; |
|
83 |
} else { |
|
84 |
final BufferedImage bimg = new BufferedImage(img.getWidth(null), img.getHeight(null), BufferedImage.TYPE_INT_ARGB); |
|
85 |
final Graphics2D bGr = bimg.createGraphics(); |
|
86 |
bGr.drawImage(img, 0, 0, null); |
|
87 |
bGr.dispose(); |
|
88 |
return bimg; |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 | 67 |
public MemEngine getEngine() { |
93 | 68 |
return engine; |
94 | 69 |
} |
modules/dnet-modular-workflows-ui/branches/newManagerService/src/main/resources/eu/dnetlib/functionality/modular/ui/views/ui/workflows/common/wf_monitor_proc.st | ||
---|---|---|
25 | 25 |
</div> |
26 | 26 |
|
27 | 27 |
<div class="row"> |
28 |
<div class="col-xs-12" style="margin-top: 20px; overflow-x: auto;" ng-show="currentProc.imageUrl">
|
|
29 |
<map name="processMap" id="processMap" ng-bind-html="to_trusted(currentProc.mapContent)"></map>
|
|
30 |
<img style="border:2px black solid" ng-src="{{currentProc.imageUrl}}" usemap="#processMap"/>
|
|
28 |
<div class="col-xs-12" style="margin-top: 20px; overflow-x: auto;" ng-show="currentProc.WF_IMAGE_BASE64">
|
|
29 |
<map name="processMap" id="processMap" ng-bind-html="to_trusted(currentProc.WF_IMAGE_MAP)"></map>
|
|
30 |
<img style="border:2px black solid" ng-src="data:{{currentProc.WF_IMAGE_FORMAT}};base64,{{currentProc.WF_IMAGE_BASE64}}" usemap="#processMap"/>
|
|
31 | 31 |
</div> |
32 | 32 |
</div> |
33 | 33 |
</div> |
modules/dnet-modular-workflows-ui/branches/newManagerService/src/main/resources/eu/dnetlib/web/resources/js/dnet_workflows_common.js | ||
---|---|---|
201 | 201 |
$scope.currentValue = row; |
202 | 202 |
} |
203 | 203 |
|
204 |
$scope.showProcess = function(id) {
|
|
204 |
$scope.showProcess = function(procId) {
|
|
205 | 205 |
$('#journalWfModal').modal('hide'); |
206 | 206 |
$('#monitorWfModal').modal('hide'); |
207 | 207 |
|
... | ... | |
218 | 218 |
$scope.currentProc = null; |
219 | 219 |
} |
220 | 220 |
|
221 |
$http.get('wf_journal.get?id=' + id).success(function(data) { |
|
222 |
if (data.graph) { |
|
223 |
$scope.currentProc = data.graph; |
|
224 |
} |
|
225 |
|
|
221 |
$http.get('wf_journal.get?proc=' + procId).success(function(data) { |
|
222 |
$scope.currentProc = data; |
|
223 |
|
|
226 | 224 |
if (!$('#monitorProcWfModal').hasClass('in')) { |
227 |
if (data.journal) { |
|
225 |
if (data['WF_IMAGE_BASE64']) { |
|
226 |
$('#monitorProcWfModal').modal('show'); |
|
227 |
} else { |
|
228 | 228 |
$scope.currentAdvancedLog = data.journal; |
229 | 229 |
$scope.currentSimpleLog = []; |
230 | 230 |
|
... | ... | |
243 | 243 |
|
244 | 244 |
$('#currentLogDetailsModal').modal('show'); |
245 | 245 |
|
246 |
} else if ($scope.currentProc) { |
|
247 |
$('#monitorProcWfModal').modal('show'); |
|
248 | 246 |
} |
249 | 247 |
} |
250 | 248 |
|
Also available in: Unified diff
process graph image