From 7c102cf212d067aee458274a8a4f0a8969d55594 Mon Sep 17 00:00:00 2001 From: Omar Sweidan Date: Thu, 9 Jun 2022 11:20:36 +0200 Subject: [PATCH] =?utf8?q?416=20bug=20jav=C3=ADtva?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../src/user/jobengine/server/JobEngine.java | 35 +++++++++----- .../server/JobEngineConfiguration.java | 47 +++++++++++++++++-- 2 files changed, 64 insertions(+), 18 deletions(-) diff --git a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngine.java b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngine.java index 9d91156a..a8bde921 100644 --- a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngine.java +++ b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngine.java @@ -256,7 +256,8 @@ public class JobEngine implements IJobEngine { try { Object typeName = jobRuntime.popFromStack(); if (typeName == null) - throw new Exception(jobRuntime.toString() + " illegal execution state detected: executor name is null."); + throw new Exception( + jobRuntime.toString() + " illegal execution state detected: executor name is null."); String executorName = String.valueOf(typeName); if (!jobEngineConfiguration.getExecutors().containsKey(executorName)) throw new Exception(jobRuntime.toString() + " executor is unavailable: " + executorName); @@ -344,9 +345,11 @@ public class JobEngine implements IJobEngine { private void closeSessionLog(IJobRuntime jobRuntime) { if (!jobRuntime.isService() && jobRuntime.getParentJobId() == 0) { if (JobStatus.FINISHED.equals(jobRuntime.getStatus())) - logger.info(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása sikeresen véget ért.", jobRuntime.getName()); + logger.info(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása sikeresen véget ért.", + jobRuntime.getName()); else - logger.error(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása megszakadt.", jobRuntime.getName()); + logger.error(jobRuntime.getFinishMarker(), "A(z) '{}' folyamat futása megszakadt.", + jobRuntime.getName()); } } @@ -591,8 +594,10 @@ public class JobEngine implements IJobEngine { continue; // 'EXECUTING', 'WAIT_EXECUTOR', 'WAIT_SUSPEND', 'RUNNABLE' - if (runtime.isExecuting() || runtime.isRunnable() || runtime.isWaitingSuspend() || runtime.isWaitingExecutor()) - throw new JobEngineException(String.format("Can not submit job. Job with %s.%s already running", template.getFileName(), template.getName())); + if (runtime.isExecuting() || runtime.isRunnable() || runtime.isWaitingSuspend() + || runtime.isWaitingExecutor()) + throw new JobEngineException(String.format("Can not submit job. Job with %s.%s already running", + template.getFileName(), template.getName())); } /* * List runningJobs = itemManager.getRunningJobs(template.getFileName()); @@ -782,7 +787,8 @@ public class JobEngine implements IJobEngine { List removeId = new ArrayList<>(); for (Long id : submittedJobs.keySet()) { IJobRuntime runtime = submittedJobs.get(id); - if (runtime != null && (JobStatus.SUSPENDED.equals(runtime.getStatus()) || JobStatus.CANCELED.equals(runtime.getStatus()))) + if (runtime != null && (JobStatus.SUSPENDED.equals(runtime.getStatus()) + || JobStatus.CANCELED.equals(runtime.getStatus()))) removeId.add(id); } for (Long id : removeId) @@ -1011,8 +1017,8 @@ public class JobEngine implements IJobEngine { } @Override - public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, String name, int priority, String owner, - Map parameters) throws JobEngineException { + public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, + String name, int priority, String owner, Map parameters) throws JobEngineException { IJobRuntime result = null; IProgram program = getProgram(template); if (program != null) { @@ -1037,15 +1043,16 @@ public class JobEngine implements IJobEngine { } @Override - public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, String name, Map parameters) - throws JobEngineException { + public IJobRuntime submit(IJobRuntime parent, IJobStatusChangedListener statusListener, String template, + String name, Map parameters) throws JobEngineException { IJobRuntime result = null; result = submit(parent, statusListener, template, name, 0, DEFAULT_OWNER, parameters); return result; } @Override - public IJobRuntime submit(IJobRuntime parent, String template, String name, int priority, Map parameters) throws JobEngineException { + public IJobRuntime submit(IJobRuntime parent, String template, String name, int priority, + Map parameters) throws JobEngineException { IJobRuntime result = null; result = submit(parent, null, template, name, 0, DEFAULT_OWNER, parameters); return result; @@ -1067,12 +1074,14 @@ public class JobEngine implements IJobEngine { } IJobRuntime result = null; IProgram program = getProgram(template); - result = submit(null, null, template, name == null ? program.getTemplate().getName() : name, 0, DEFAULT_OWNER, parameters); + result = submit(null, null, template, name == null ? program.getTemplate().getName() : name, 0, DEFAULT_OWNER, + parameters); return result; } @Override - public IJobRuntime submit(String template, String name, Map parameters, String owner) throws JobEngineException { + public IJobRuntime submit(String template, String name, Map parameters, String owner) + throws JobEngineException { IJobRuntime result = null; result = submit(null, null, template, name, 0, owner, parameters); return result; diff --git a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java index 7580b32b..34f3f9b8 100644 --- a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java +++ b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java @@ -43,6 +43,7 @@ import com.ibm.nosql.json.api.BasicDBObject; import groovy.lang.GroovyClassLoader; import user.commons.configuration.IConfiguration; import user.commons.nosql.NoSQLUtils; +import user.jobengine.server.ast.Encoder; import user.jobengine.server.ast.JSONEncoder; import user.jobengine.server.ast.JobTemplate; import user.jobengine.server.ast.Parser; @@ -135,7 +136,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { stepClass = (Class) stepsClassLoader.loadClass(stepUnitName); if (stepClass == null) - throw new Exception("Cant load " + stepUnitName); + throw new Exception("Can't load " + stepUnitName); result = stepClass.newInstance(); logger.info("Class for step {} successfully created", stepUnitName); @@ -320,13 +321,15 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { String xml = loadTemplateXml(template); j.put("xml", xml); + loadProgram(Paths.get(template)); + JobTemplate jobTemplate = loadTemplate(Paths.get(template)); JSONEncoder jsonEncoder = new JSONEncoder(); - BasicDBObject program = (BasicDBObject) jsonEncoder.visitJobTemplate(jobTemplate, null); - if (program != null) { - j.put("program", program); + BasicDBObject flowchartData = (BasicDBObject) jsonEncoder.visitJobTemplate(jobTemplate, null); + if (flowchartData != null) { + j.put("program", flowchartData); } else { - logger.info("program {} is null!"); + logger.info("flowchartData {} is null!", flowchartData); } schedules.add(new SimpleEntry(template, j)); @@ -336,6 +339,40 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { }); } + private void loadProgram(Path config) { + InputStream stream = null; + Path templatesPath = null; + String fileName = null; + try { + templatesPath = Paths.get(systemConfig.getConfig(DIR_TEMPLATES)); + if (!templatesPath.toFile().isDirectory()) + throw new FileNotFoundException(templatesPath + " is not directory!"); + stream = Files.newInputStream(Paths.get(templatesPath.toString(), config.toString())); + fileName = config.getFileName().toString(); + Parser parser = new Parser(stream); + JobTemplate template = parser.parse(); + template.validate(); + template.setFileName(fileName); + + Encoder encoder = new Encoder(); + IProgram program = (IProgram) encoder.visitJobTemplate(template, null); + programs.put(fileName, program); + logger.info("Job template loaded {}", fileName); + } catch (FileNotFoundException e) { + logger.error("Fájl nem található: {}", fileName); + } catch (IOException e) { + logger.error("Inputstream nem nyitható meg: {}", e.getMessage()); + } catch (Exception e) { + logger.error("{} compile error: {}", config, e.getMessage()); + } finally { + try { + if (stream != null) + stream.close(); + } catch (IOException e) { + } + } + } + private JobTemplate loadTemplate(Path templateName) { Path templatesPath = null; InputStream stream = null; -- 2.54.0