Author: andre Date: 2010-05-30 12:20:41 +0200 (Sun, 30 May 2010) New Revision: 42309
Modified: mmbase/branches/MMBase-1_9/applications/streams/src/main/config/components/streams.xml mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/CreateCachesFunction.java Log: MMB-1954 Modified: mmbase/branches/MMBase-1_9/applications/streams/src/main/config/components/streams.xml =================================================================== --- mmbase/branches/MMBase-1_9/applications/streams/src/main/config/components/streams.xml 2010-05-30 10:19:16 UTC (rev 42308) +++ mmbase/branches/MMBase-1_9/applications/streams/src/main/config/components/streams.xml 2010-05-30 10:20:41 UTC (rev 42309) @@ -20,7 +20,7 @@ </action> <action name="retrigger_jobs" rank="administrator"> - <description xml:lang="en">Whether you may cancel jobs</description> + <description xml:lang="en">Whether you may (re)trigger jobs</description> </action> <block name="recent" @@ -44,9 +44,10 @@ <description xml:lang="nl">Configuratie van streams applicatie, huidige streams en caches</description> <body jsp="admin.jspx"> <param name="trigger" /> + <param name="all" type="java.lang.Boolean" /> <param name="interrupt" /> <param name="recache" /> - <param name="page" type="java.lang.Integer" /> + <param name="page" type="java.lang.Integer" /> </body> </block> @@ -55,10 +56,11 @@ mimetype="text/html"> <title xml:lang="en">My fragments</title> <title xml:lang="nl">Mijn fragmenten</title> - <description xml:lang="en">Streams of current users</description> + <description xml:lang="en">Streams of current user</description> <description xml:lang="nl">Streams van huidige user</description> <body jsp="myfragments.jspx"> <param name="trigger" /> + <param name="all" /> <param name="interrupt" /> <param name="recache" /> <param name="page" type="java.lang.Integer" /> @@ -74,7 +76,7 @@ Displays your current, running media transcodings to other formats. </description> <description xml:lang="nl"> - Toont jouw huidige, lopende transcoderingen van media naar andere formaten. + Toont je huidige, lopende transcoderingen van media naar andere formaten. </description> <body jsp="myjobs.jspx"> <param name="cancel" /> @@ -87,10 +89,10 @@ <title xml:lang="en">All jobs</title> <title xml:lang="nl">Alle jobs</title> <description xml:lang="en"> - Displays current, running media transcodings to other formats. + Displays all current, running media transcodings to other formats. </description> <description xml:lang="nl"> - Toont huidige, lopende transcoderingen van media naar andere formaten. + Toont alle huidige, lopende transcoderingen van media naar andere formaten. </description> <body jsp="alljobs.jspx"> <param name="cancel" /> Modified: mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/CreateCachesFunction.java =================================================================== --- mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/CreateCachesFunction.java 2010-05-30 10:19:16 UTC (rev 42308) +++ mmbase/branches/MMBase-1_9/applications/streams/src/main/java/org/mmbase/streams/CreateCachesFunction.java 2010-05-30 10:20:41 UTC (rev 42309) @@ -21,8 +21,14 @@ package org.mmbase.streams; +import java.util.*; + +import org.mmbase.streams.createcaches.Stage; import org.mmbase.streams.createcaches.Processor; +import org.mmbase.streams.createcaches.JobDefinition; +import org.mmbase.streams.transcoders.*; +import org.mmbase.util.MimeType; import org.mmbase.util.functions.*; import org.mmbase.bridge.*; import org.mmbase.bridge.util.*; @@ -31,7 +37,9 @@ import org.mmbase.util.logging.*; /** - * Retriggers creation of (all) caches of a source node. + * Triggers (re)creation of caches (streamsourcescaches) of a source node + * (streamsources). The parameter 'all' determines whether to recreate all caches + * or just to transcode newly configured streams. * * @author Michiel Meeuwissen * @version $Id$ @@ -40,8 +48,10 @@ public class CreateCachesFunction extends NodeFunction<Boolean> { private static final Logger LOG = Logging.getLoggerInstance(CreateCachesFunction.class); + + public final static Parameter[] CACHE_PARAMETERS = { new Parameter("all", java.lang.Boolean.class) }; public CreateCachesFunction() { - super("createcaches"); + super("createcaches", CACHE_PARAMETERS); } /** @@ -71,9 +81,12 @@ @Override protected Boolean getFunctionValue(final Node node, final Parameters parameters) { + LOG.debug("params: " + parameters); if (node.getNumber() > 0 && node.getCloud().may(ActionRepository.getInstance().get("streams", "retrigger_jobs"), null)) { - LOG.info("Recreating caches for #" + node.getNumber()); + + Boolean all = (Boolean) parameters.get("all"); + LOG.info("Recreating caches for #" + node.getNumber() + ", doing all: " + all); final Field url = node.getNodeManager().getField("url"); { @@ -89,18 +102,16 @@ list = SearchUtil.findRelatedNodeList(mediafragment, "videostreamsourcescaches", "related"); } } + + final Processor cc = getCacheCreator(url); + Map<String, JobDefinition> jdlist = cc.getCreatecachesList(); + if ( list.size() > 0 && ! all ) { + jdlist = newJobList(list, jdlist); + } - for (Node cache : list) { - cache.delete(true); - LOG.service("deleted streamsourcescaches #" + cache.getNumber()); - } - } - - { - final Processor cc = getCacheCreator(url); if (cc != null) { LOG.service("Calling " + cc); - cc.createCaches(node.getCloud().getNonTransactionalCloud(), node.getNumber()); + cc.createCaches(node.getCloud().getNonTransactionalCloud(), node.getNumber(), jdlist); return true; } else { LOG.error("No CreateCachesProcessor in " + url); @@ -111,5 +122,76 @@ return false; } } - + + private Map<String, JobDefinition> newJobList(NodeList list, Map<String, JobDefinition> jdlist) { + Map<String, JobDefinition> new_jdlist = new LinkedHashMap<String, JobDefinition>(); + // make keys from current config entries + Map<String, String> config = new HashMap<String, String>(); + for (Map.Entry<String, JobDefinition> entry : jdlist.entrySet()) { + String id = entry.getKey(); + JobDefinition jd = entry.getValue(); + String key = jd.getTranscoder().getKey(); + if (key != null && !"".equals(key)) { // not recognizers + config.put(id, key); + } + } + // for convenience make a map of caches keys + Map<String, String> caches = new HashMap<String, String>(); + for (Node cache : list) { + caches.put("" + cache.getNumber(), cache.getStringValue("key")); + } + + // iterate over config keys + Iterator<Map.Entry<String,String>> it = config.entrySet().iterator(); + while (it.hasNext()) { + Map.Entry<String,String> e = it.next(); + String config_id = e.getKey(); + String config_key = e.getValue(); + + if (config_key != null && !caches.containsValue(config_key)) { + // not in caches, must be new config + LOG.info("@ (new config) not in caches : " + config_id + " [" + config_key + "]"); + + JobDefinition jd = jdlist.get(config_id); + Transcoder tr = jd.getTranscoder(); + String label = jd.getLabel(); + MimeType mt = jd.getMimeType(); + + String inId = jd.getInId(); + String inKey = config.get(inId); + + // check if it's inId is already a cached node + if (caches.containsValue(inKey)) { + LOG.info("@ in new_jdlist: " + inId + " [" + inKey + "]"); + String in = ""; + for (Node n : list) { + if (n.getStringValue("key").equals(inKey)) { + in = "" + n.getNumber(); + LOG.info("@ cache as source node #" + in); + break; + } + } + + jd = new JobDefinition(config_id, in, label, tr, mt, Stage.TRANSCODER); + if (! new_jdlist.containsKey(config_id)) { + new_jdlist.put(config_id, jd); + LOG.info("@ put in new_jdlist: " + config_id); + } + + } else { + // inId not yet cached + if (! new_jdlist.containsKey(inId)) { + new_jdlist.put(inId, jdlist.get(inId) ); + LOG.info("@ inId in new_jdlist: " + inId); + } + + if (! new_jdlist.containsKey(config_id)) { + new_jdlist.put(config_id, jdlist.get(config_id) ); + LOG.info("@ config_id in new_jdlist: " + config_id); + } + } + } + } + return new_jdlist; + } } _______________________________________________ Cvs mailing list Cvs@lists.mmbase.org http://lists.mmbase.org/mailman/listinfo/cvs