416 bug javítva
authorOmar Sweidan <omar.sweidan@userrendszerhaz.hu>
Thu, 9 Jun 2022 09:20:36 +0000 (11:20 +0200)
committerOmar Sweidan <omar.sweidan@userrendszerhaz.hu>
Thu, 9 Jun 2022 09:20:36 +0000 (11:20 +0200)
server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngine.java
server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java

index 9d91156a14b9afdd147382a6dc2b65dd8b1d7510..a8bde92135658e988108fa23d1a56a1ffe0ad11e 100644 (file)
@@ -256,7 +256,8 @@ public class JobEngine implements IJobEngine {
                try {\r
                        Object typeName = jobRuntime.popFromStack();\r
                        if (typeName == null)\r
-                               throw new Exception(jobRuntime.toString() + " illegal execution state detected: executor name is null.");\r
+                               throw new Exception(\r
+                                               jobRuntime.toString() + " illegal execution state detected: executor name is null.");\r
                        String executorName = String.valueOf(typeName);\r
                        if (!jobEngineConfiguration.getExecutors().containsKey(executorName))\r
                                throw new Exception(jobRuntime.toString() + " executor is unavailable: " + executorName);\r
@@ -344,9 +345,11 @@ public class JobEngine implements IJobEngine {
        private void closeSessionLog(IJobRuntime jobRuntime) {\r
                if (!jobRuntime.isService() && jobRuntime.getParentJobId() == 0) {\r
                        if (JobStatus.FINISHED.equals(jobRuntime.getStatus()))\r
-                               logger.info(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása sikeresen véget ért.", jobRuntime.getName());\r
+                               logger.info(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása sikeresen véget ért.",\r
+                                               jobRuntime.getName());\r
                        else\r
-                               logger.error(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása megszakadt.", jobRuntime.getName());\r
+                               logger.error(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása megszakadt.",\r
+                                               jobRuntime.getName());\r
                }\r
        }\r
 \r
@@ -591,8 +594,10 @@ public class JobEngine implements IJobEngine {
                                continue;\r
 \r
                        // 'EXECUTING', 'WAIT_EXECUTOR', 'WAIT_SUSPEND', 'RUNNABLE'\r
-                       if (runtime.isExecuting() || runtime.isRunnable() || runtime.isWaitingSuspend() || runtime.isWaitingExecutor())\r
-                               throw new JobEngineException(String.format("Can not submit job. Job with %s.%s already running", template.getFileName(), template.getName()));\r
+                       if (runtime.isExecuting() || runtime.isRunnable() || runtime.isWaitingSuspend()\r
+                                       || runtime.isWaitingExecutor())\r
+                               throw new JobEngineException(String.format("Can not submit job. Job with %s.%s already running",\r
+                                               template.getFileName(), template.getName()));\r
                }\r
                /*\r
                 * List<Job> runningJobs = itemManager.getRunningJobs(template.getFileName());\r
@@ -782,7 +787,8 @@ public class JobEngine implements IJobEngine {
                List<Long> removeId = new ArrayList<>();\r
                for (Long id : submittedJobs.keySet()) {\r
                        IJobRuntime runtime = submittedJobs.get(id);\r
-                       if (runtime != null && (JobStatus.SUSPENDED.equals(runtime.getStatus()) || JobStatus.CANCELED.equals(runtime.getStatus())))\r
+                       if (runtime != null && (JobStatus.SUSPENDED.equals(runtime.getStatus())\r
+                                       || JobStatus.CANCELED.equals(runtime.getStatus())))\r
                                removeId.add(id);\r
                }\r
                for (Long id : removeId)\r
@@ -1011,8 +1017,8 @@ public class JobEngine implements IJobEngine {
        }\r
 \r
        @Override\r
-       public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, String name, int priority, String owner,\r
-                       Map<String, Object> parameters) throws JobEngineException {\r
+       public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template,\r
+                       String name, int priority, String owner, Map<String, Object> parameters) throws JobEngineException {\r
                IJobRuntime result = null;\r
                IProgram program = getProgram(template);\r
                if (program != null) {\r
@@ -1037,15 +1043,16 @@ public class JobEngine implements IJobEngine {
        }\r
 \r
        @Override\r
-       public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, String name, Map<String, Object> parameters)\r
-                       throws JobEngineException {\r
+       public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template,\r
+                       String name, Map<String, Object> parameters) throws JobEngineException {\r
                IJobRuntime result = null;\r
                result = submit(parent, statusListener, template, name, 0, DEFAULT_OWNER, parameters);\r
                return result;\r
        }\r
 \r
        @Override\r
-       public IJobRuntime submit(IJobRuntime parent, String template, String name, int priority, Map<String, Object> parameters) throws JobEngineException {\r
+       public IJobRuntime submit(IJobRuntime parent, String template, String name, int priority,\r
+                       Map<String, Object> parameters) throws JobEngineException {\r
                IJobRuntime result = null;\r
                result = submit(parent, null, template, name, 0, DEFAULT_OWNER, parameters);\r
                return result;\r
@@ -1067,12 +1074,14 @@ public class JobEngine implements IJobEngine {
                }\r
                IJobRuntime result = null;\r
                IProgram program = getProgram(template);\r
-               result = submit(null, null, template, name == null ? program.getTemplate().getName() : name, 0, DEFAULT_OWNER, parameters);\r
+               result = submit(null, null, template, name == null ? program.getTemplate().getName() : name, 0, DEFAULT_OWNER,\r
+                               parameters);\r
                return result;\r
        }\r
 \r
        @Override\r
-       public IJobRuntime submit(String template, String name, Map<String, Object> parameters, String owner) throws JobEngineException {\r
+       public IJobRuntime submit(String template, String name, Map<String, Object> parameters, String owner)\r
+                       throws JobEngineException {\r
                IJobRuntime result = null;\r
                result = submit(null, null, template, name, 0, owner, parameters);\r
                return result;\r
index 7580b32b0e9ce37cec52820c428f2aefdc1097e1..34f3f9b82828a5c46df156d005df5aa7cbc430de 100644 (file)
@@ -43,6 +43,7 @@ import com.ibm.nosql.json.api.BasicDBObject;
 import groovy.lang.GroovyClassLoader;\r
 import user.commons.configuration.IConfiguration;\r
 import user.commons.nosql.NoSQLUtils;\r
+import user.jobengine.server.ast.Encoder;\r
 import user.jobengine.server.ast.JSONEncoder;\r
 import user.jobengine.server.ast.JobTemplate;\r
 import user.jobengine.server.ast.Parser;\r
@@ -135,7 +136,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                        stepClass = (Class<IJobStep>) stepsClassLoader.loadClass(stepUnitName);\r
 \r
                if (stepClass == null)\r
-                       throw new Exception("Cant load " + stepUnitName);\r
+                       throw new Exception("Can't load " + stepUnitName);\r
 \r
                result = stepClass.newInstance();\r
                logger.info("Class for step {} successfully created", stepUnitName);\r
@@ -320,13 +321,15 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                                String xml = loadTemplateXml(template);\r
                                j.put("xml", xml);\r
 \r
+                               loadProgram(Paths.get(template));\r
+\r
                                JobTemplate jobTemplate = loadTemplate(Paths.get(template));\r
                                JSONEncoder jsonEncoder = new JSONEncoder();\r
-                               BasicDBObject program = (BasicDBObject) jsonEncoder.visitJobTemplate(jobTemplate, null);\r
-                               if (program != null) {\r
-                                       j.put("program", program);\r
+                               BasicDBObject flowchartData = (BasicDBObject) jsonEncoder.visitJobTemplate(jobTemplate, null);\r
+                               if (flowchartData != null) {\r
+                                       j.put("program", flowchartData);\r
                                } else {\r
-                                       logger.info("program {} is null!");\r
+                                       logger.info("flowchartData {} is null!", flowchartData);\r
                                }\r
 \r
                                schedules.add(new SimpleEntry<String, BasicDBObject>(template, j));\r
@@ -336,6 +339,40 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                });\r
        }\r
 \r
+       private void loadProgram(Path config) {\r
+               InputStream stream = null;\r
+               Path templatesPath = null;\r
+               String fileName = null;\r
+               try {\r
+                       templatesPath = Paths.get(systemConfig.getConfig(DIR_TEMPLATES));\r
+                       if (!templatesPath.toFile().isDirectory())\r
+                               throw new FileNotFoundException(templatesPath + " is not directory!");\r
+                       stream = Files.newInputStream(Paths.get(templatesPath.toString(), config.toString()));\r
+                       fileName = config.getFileName().toString();\r
+                       Parser parser = new Parser(stream);\r
+                       JobTemplate template = parser.parse();\r
+                       template.validate();\r
+                       template.setFileName(fileName);\r
+\r
+                       Encoder encoder = new Encoder();\r
+                       IProgram program = (IProgram) encoder.visitJobTemplate(template, null);\r
+                       programs.put(fileName, program);\r
+                       logger.info("Job template loaded {}", fileName);\r
+               } catch (FileNotFoundException e) {\r
+                       logger.error("Fájl nem található: {}", fileName);\r
+               } catch (IOException e) {\r
+                       logger.error("Inputstream nem nyitható meg: {}", e.getMessage());\r
+               } catch (Exception e) {\r
+                       logger.error("{} compile error: {}", config, e.getMessage());\r
+               } finally {\r
+                       try {\r
+                               if (stream != null)\r
+                                       stream.close();\r
+                       } catch (IOException e) {\r
+                       }\r
+               }\r
+       }\r
+\r
        private JobTemplate loadTemplate(Path templateName) {\r
                Path templatesPath = null;\r
                InputStream stream = null;\r