git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube...
authorSweidan Omar <TFS\sweidan.omar>
Mon, 13 Dec 2021 14:31:56 +0000 (14:31 +0000)
committerSweidan Omar <TFS\sweidan.omar>
Mon, 13 Dec 2021 14:31:56 +0000 (14:31 +0000)
server/user.jobengine.osgi.server/src/user/jobengine/server/IJobEngine.java
server/user.jobengine.osgi.server/src/user/jobengine/server/IJobEngineConfiguration.java
server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngine.java
server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java
server/user.jobengine.osgi.server/src/user/jobengine/server/scheduler/SchedulerService.java
server/user.mediacube.gui/src/user/jobengine/zk/model/JobSelectorModel.java

index 0e171f2a0d6449dcfab8c66491e1da3541748876..862bf0a53756296c4ef5ac6fd5ec0011fb9582d0 100644 (file)
@@ -62,7 +62,7 @@ public interface IJobEngine {
 
        JobEngineRemote getRemoteEngine();
 
-       ScheduledJob getScheduledJob(String template);
+       ScheduledJob getScheduledJob(String template) throws Exception;
 
        SchedulerService getScheduler();
 
@@ -130,17 +130,19 @@ public interface IJobEngine {
 
        void storeJob(IJobRuntime runtime);
 
-       IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, String name, int priority, String owner,
+       IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, String name,
+                       int priority, String owner, Map<String, Object> parameters) throws JobEngineException;
+
+       IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, String name,
                        Map<String, Object> parameters) throws JobEngineException;
 
-       IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, String name, Map<String, Object> parameters)
+       IJobRuntime submit(IJobRuntime parent, String template, String name, int priority, Map<String, Object> parameters)
                        throws JobEngineException;
 
-       IJobRuntime submit(IJobRuntime parent, String template, String name, int priority, Map<String, Object> parameters) throws JobEngineException;
-
        IJobRuntime submit(String template, String name, Map<String, Object> parameters) throws JobEngineException;
 
-       IJobRuntime submit(String template, String name, Map<String, Object> parameters, String owner) throws JobEngineException;
+       IJobRuntime submit(String template, String name, Map<String, Object> parameters, String owner)
+                       throws JobEngineException;
 
        void suspendExecutingJob(Throwable t, IJobRuntime jobRuntime);
 
index 9c18761ecb35d7db94b2d380af9900cea4d433c8..332896872b2ab34c97a9d0d743a063c7fc8a3de1 100644 (file)
@@ -1,7 +1,9 @@
 package user.jobengine.server;\r
 \r
+import java.util.ArrayList;\r
 import java.util.List;\r
 import java.util.Map;\r
+import java.util.Map.Entry;\r
 \r
 import com.ibm.nosql.json.api.BasicDBObject;\r
 \r
@@ -19,7 +21,7 @@ public interface IJobEngineConfiguration {
 \r
        Map<String, IProgram> getPrograms();\r
 \r
-       Map<String, BasicDBObject> getSchedules();\r
+       ArrayList<Entry<String, BasicDBObject>> getSchedules();\r
 \r
        List<JobTemplate> getTemplates();\r
 \r
index bfd484790587f0264b9d7e8f6050fea12d531124..fa53beed6da42de9678361cc134d286948231207 100644 (file)
@@ -7,6 +7,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 import java.util.Map;
+import java.util.Map.Entry;
 import java.util.Set;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
@@ -531,9 +532,22 @@ public class JobEngine implements IJobEngine {
        }
 
        @Override
-       public ScheduledJob getScheduledJob(String template) {
-               Map<String, BasicDBObject> schedules = jobEngineConfiguration.getSchedules();
-               BasicDBObject schedule = schedules.get(template);
+       public ScheduledJob getScheduledJob(String template) throws Exception {
+               ArrayList<Entry<String, BasicDBObject>> schedules = jobEngineConfiguration.getSchedules();
+               BasicDBObject schedule = null;
+               boolean templateFirstOccurence = false;
+
+               for (int index = 0; index < schedules.size(); index++) {
+                       if (schedules.get(index).getKey().equals(template)) {
+                               if (!templateFirstOccurence) {
+                                       templateFirstOccurence = true;
+                                       schedule = schedules.get(index).getValue();
+                               } else {
+                                       throw new Exception("Key " + template + " is already contained in scheduled jobs!");
+                               }
+                       }
+               }
+
                if (schedule == null)
                        return null;
                return jobEngineConfiguration.createScheduledJob(schedule, this);
index a7bd34ab23040709a73b38aa77a6d6dccb5e10f0..c2f5164f47a51822a50a13cd87f1a1e966b6ac84 100644 (file)
@@ -57,7 +57,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
        private final Map<String, IJobStepExecutor> executors = new LinkedHashMap<String, IJobStepExecutor>();\r
        private final Map<String, IProgram> programs = new LinkedHashMap<String, IProgram>();\r
        private final List<JobTemplate> templates = Collections.synchronizedList(new ArrayList<JobTemplate>());\r
-       private final Map<String, BasicDBObject> schedules = new LinkedHashMap<String, BasicDBObject>();\r
+       private final ArrayList<Entry<String, BasicDBObject>> schedules = new ArrayList<Entry<String, BasicDBObject>>();\r
        private URLClassLoader stepsClassLoader;\r
        private boolean resetStepClassLoader;\r
        private GroovyClassLoader groovyClassLoader;\r
@@ -227,7 +227,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
        }\r
 \r
        @Override\r
-       public Map<String, BasicDBObject> getSchedules() {\r
+       public ArrayList<Entry<String, BasicDBObject>> getSchedules() {\r
                return schedules;\r
        }\r
 \r
@@ -326,34 +326,19 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                String jsonConfig = new String(Files.readAllBytes(Paths.get(configFilePath)));\r
                BasicDBObject dbo = (BasicDBObject) JSONUtil.jsonToDbObject(jsonConfig);\r
                BasicDBList scheduleJobs = NoSQLUtils.asDBList(dbo, "joblist");\r
-               ArrayList<Entry<String, BasicDBObject>> schedulesArraylist = new ArrayList<Entry<String, BasicDBObject>>();\r
 \r
                scheduleJobs.forEach(o -> {\r
                        try {\r
-                               boolean keyAlreadyContained = false;\r
                                BasicDBObject j = (BasicDBObject) o;\r
                                String template = j.getString("template");\r
                                String xml = loadTemplateXml(template);\r
                                j.put("xml", xml);\r
 \r
-                               for (int index = 0; index < schedulesArraylist.size(); index++) {\r
-                                       if (schedulesArraylist.get(index).getKey().equals(template)) {\r
-                                               keyAlreadyContained = true;\r
-                                               throw new Exception("Key " + template + " is already contained in scheduled jobs!");\r
-                                       }\r
-                               }\r
-\r
-                               if (!keyAlreadyContained) {\r
-                                       schedulesArraylist.add(new SimpleEntry<String, BasicDBObject>(template, j));\r
-                               }\r
+                               schedules.add(new SimpleEntry<String, BasicDBObject>(template, j));\r
                        } catch (Exception e) {\r
                                logger.error("Scheduled job error! {}", e.getMessage());\r
                        }\r
                });\r
-\r
-               for (Entry<String, BasicDBObject> entry : schedulesArraylist) {\r
-                       schedules.put(entry.getKey(), entry.getValue());\r
-               }\r
        }\r
 \r
        private Set<File> getJavaFileList(Path path, String excludeFileName) {\r
index 183be469550d1164fd1aac848391bc94e298391b..2d8ebc72e3088d1dd3a2ad8b9a8fde604a3e2fa4 100644 (file)
@@ -1,8 +1,9 @@
 package user.jobengine.server.scheduler;\r
 \r
+import java.util.ArrayList;\r
 import java.util.Arrays;\r
 import java.util.List;\r
-import java.util.Map;\r
+import java.util.Map.Entry;\r
 import java.util.UUID;\r
 \r
 import org.apache.commons.lang.StringUtils;\r
@@ -76,7 +77,8 @@ public class SchedulerService {
                        }\r
 \r
                        @Override\r
-                       public void jobWasExecuted(JobExecutionContext paramJobExecutionContext, JobExecutionException paramJobExecutionException) {\r
+                       public void jobWasExecuted(JobExecutionContext paramJobExecutionContext,\r
+                                       JobExecutionException paramJobExecutionException) {\r
                                listenerManager.removeJobListener(listenerName);\r
                        }\r
                };\r
@@ -173,8 +175,9 @@ public class SchedulerService {
 \r
        private void scheduleJobs() {\r
                IJobEngineConfiguration jobEngineConfiguration = jobEngine.getJobEngineConfiguration();\r
-               Map<String, BasicDBObject> schedules = jobEngineConfiguration.getSchedules();\r
-               for (BasicDBObject job : schedules.values()) {\r
+               ArrayList<Entry<String, BasicDBObject>> schedules = jobEngineConfiguration.getSchedules();\r
+               for (int index = 0; index < schedules.size(); index++) {\r
+                       BasicDBObject job = schedules.get(index).getValue();\r
                        ScheduledJob scheduledJob = null;\r
                        try {\r
                                scheduledJob = jobEngineConfiguration.createScheduledJob(job, jobEngine);\r
index 8318cfaaa98ea2ae522f140b0c5aa0ad1b7f5a56..931ec81fadf9d76256d9d60c52f1bf558e7b58fe 100644 (file)
@@ -54,7 +54,7 @@ public class JobSelectorModel extends BaseModel {
        }\r
 \r
        @Command\r
-       public void execute() {\r
+       public void execute() throws Exception {\r
                if (selectedJob == null)\r
                        return;\r
                String template = selectedJob.getString("template");\r
@@ -92,8 +92,11 @@ public class JobSelectorModel extends BaseModel {
        }\r
 \r
        private void initJobList() {\r
-               List<BasicDBObject> jobsCollection = new ArrayList<>(\r
-                               jobEngine.getJobEngineConfiguration().getSchedules().values());\r
+               List<BasicDBObject> jobsCollection = new ArrayList<BasicDBObject>();\r
+               for (int index = 0; index < jobEngine.getJobEngineConfiguration().getSchedules().size(); index++) {\r
+                       jobsCollection.add(jobEngine.getJobEngineConfiguration().getSchedules().get(index).getValue());\r
+               }\r
+\r
                Collections.sort(jobsCollection, (a, b) -> {\r
                        String aName = a.getString("name");\r
                        if (aName == null)\r