From: vasary.daniel Date: Thu, 15 Apr 2021 12:28:59 +0000 (+0000) Subject: git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube... X-Git-Url: http://git.useribm.hu/?a=commitdiff_plain;h=0b3787e6bfc0508ab38d1373e56b9388578119f2;p=mediacube.git git-tfs-id: [tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C32208 --- diff --git a/server/-product/production/LOCAL/jobs/steps/CancelableStep.java b/server/-product/production/LOCAL/jobs/steps/CancelableStep.java index 0ff5eca4..bee93c64 100644 --- a/server/-product/production/LOCAL/jobs/steps/CancelableStep.java +++ b/server/-product/production/LOCAL/jobs/steps/CancelableStep.java @@ -10,6 +10,10 @@ import user.commons.StoreUri; import user.commons.remotestore.FtpDirectoryLister; import user.commons.remotestore.RemoteStoreProtocol; + +/* DO NOT REMOVE! +import user.jobengine.server.steps.TestLib; +*/ public class CancelableStep extends JobStep { private static final Logger logger = LogManager.getLogger(); int count = 10; @@ -17,6 +21,7 @@ public class CancelableStep extends JobStep { @StepEntry public Object[] execute(int param) throws Exception { try { + TestLib t = new TestLib(); Marker marker = MarkerManager.getMarker("MEDIAPROFILE"); getJobRuntime().setRelated("TESZT" + param); diff --git a/server/-product/production/LOCAL/jobs/steps/PathItemsCollectorStep.java b/server/-product/production/LOCAL/jobs/steps/PathItemsCollectorStep.java index 69ca5d02..de1ae3a9 100644 --- a/server/-product/production/LOCAL/jobs/steps/PathItemsCollectorStep.java +++ b/server/-product/production/LOCAL/jobs/steps/PathItemsCollectorStep.java @@ -18,7 +18,7 @@ import com.ibm.nosql.json.api.BasicDBObject; /* DO NOT REMOVE! import user.jobengine.server.steps.FileSearchFilterOptions; - */ +*/ public class PathItemsCollectorStep extends JobStep { private static final Logger logger = LogManager.getLogger(); @@ -41,9 +41,10 @@ public class PathItemsCollectorStep extends JobStep { @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { - if (filterOptions.acceptFile(file)) + if (filterOptions.acceptFile(file)) { files.add(file.toString()); - logger.info(file); + logger.info(file.getFileName()); + } return FileVisitResult.CONTINUE; } diff --git a/server/-product/production/LOCAL/jobs/steps/TestLib.java b/server/-product/production/LOCAL/jobs/steps/TestLib.java new file mode 100644 index 00000000..040153ec --- /dev/null +++ b/server/-product/production/LOCAL/jobs/steps/TestLib.java @@ -0,0 +1,8 @@ +package user.jobengine.server.steps; + +public class TestLib { + + public void hello() { + System.out.println("Hello from lib"); + } +} diff --git a/server/hu.user.mediacube.executors.tests/META-INF/MANIFEST.MF b/server/hu.user.mediacube.executors.tests/META-INF/MANIFEST.MF index 4e8b0cfa..35b0ee22 100644 --- a/server/hu.user.mediacube.executors.tests/META-INF/MANIFEST.MF +++ b/server/hu.user.mediacube.executors.tests/META-INF/MANIFEST.MF @@ -8,4 +8,5 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8 Import-Package: org.apache.commons.io.filefilter;version="2.2.0", org.apache.commons.io.output;version="2.2.0", org.apache.ibatis.jdbc;version="3.5.2", + org.codehaus.groovy.control;version="3.0.3", org.junit diff --git a/server/hu.user.mediacube.executors.tests/data/hu/user/mediacube/executors/tests/data/TestChild.java b/server/hu.user.mediacube.executors.tests/data/hu/user/mediacube/executors/tests/data/TestChild.java index 382ff4a3..49e6cc6f 100644 --- a/server/hu.user.mediacube.executors.tests/data/hu/user/mediacube/executors/tests/data/TestChild.java +++ b/server/hu.user.mediacube.executors.tests/data/hu/user/mediacube/executors/tests/data/TestChild.java @@ -1,10 +1,14 @@ package hu.user.mediacube.executors.tests.data; + public class TestChild extends TestParent { @Override public void hello() { super.hello(); System.out.println("Hello from child"); + + TestLib lib = new TestLib(); + lib.hello(); } } diff --git a/server/hu.user.mediacube.executors.tests/data/hu/user/mediacube/executors/tests/data/TestLib.java b/server/hu.user.mediacube.executors.tests/data/hu/user/mediacube/executors/tests/data/TestLib.java new file mode 100644 index 00000000..36adb505 --- /dev/null +++ b/server/hu.user.mediacube.executors.tests/data/hu/user/mediacube/executors/tests/data/TestLib.java @@ -0,0 +1,8 @@ +package hu.user.mediacube.executors.tests.data; + +public class TestLib { + + public void hello() { + System.out.println("Hello from lib"); + } +} diff --git a/server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/SmallTests.java b/server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/SmallTests.java index 46e13d60..8bc9adad 100644 --- a/server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/SmallTests.java +++ b/server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/SmallTests.java @@ -983,25 +983,25 @@ public class SmallTests { @Test public void test9995() throws Exception { - String file = "/opt/test/TestChild.java"; - - GroovyClassLoader cl = new GroovyClassLoader(this.getClass().getClassLoader()) { - + @Override public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve) throws ClassNotFoundException, CompilationFailedException { - // TODO Auto-generated method stub return super.loadClass(name, lookupScriptFiles, preferClassOverScript, resolve); } - + }; try { + cl.parseClass(new File("/opt/test/TestParent.java")); - Class myClass = cl.parseClass(new File(file)); + cl.parseClass(new File("/opt/test/TestLib.java")); + + Class[] loadedClasses = cl.getLoadedClasses(); + Class myClass = cl.parseClass(new File("/opt/test/TestChild.java")); System.out.println(myClass.getCanonicalName()); - Method method = myClass.getMethod("execute"); + Method method = myClass.getMethod("hello"); method.invoke(myClass.newInstance()); System.out.println("done"); } catch (Throwable e) { 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 1bcc931f..f3649b34 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 @@ -26,7 +26,6 @@ import com.ibm.nosql.json.api.BasicDBList; import com.ibm.nosql.json.api.BasicDBObject; import groovy.lang.GroovyClassLoader; -import groovy.lang.GroovyCodeSource; import user.commons.configuration.IConfiguration; import user.commons.nosql.NoSQLUtils; import user.jobengine.server.ast.Encoder; @@ -51,8 +50,6 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { private final List templates = Collections.synchronizedList(new ArrayList()); private final Map schedules = new LinkedHashMap(); - private URLClassLoader stepsClassLoader = null; - public synchronized void bindSystemConfiguration(Object service) { if (service instanceof IConfiguration) { systemConfig = (IConfiguration) service; @@ -67,17 +64,16 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { boolean isGroovyClass = stepUnitName.toLowerCase().endsWith(".java") || stepUnitName.toLowerCase().endsWith(".groovy"); - if (stepsClassLoader == null) { - String stepClassesDir = systemConfig.getConfig(DIR_CLASSES); - Path path = Paths.get(stepClassesDir); - URL[] urls = { path.toUri().toURL() }; - stepsClassLoader = URLClassLoader.newInstance(urls, getClass().getClassLoader()); - } + String stepClassesDir = systemConfig.getConfig(DIR_CLASSES); + Path path = Paths.get(stepClassesDir); + URL[] urls = { path.toUri().toURL() }; + URLClassLoader stepsClassLoader = URLClassLoader.newInstance(urls, Thread.currentThread().getContextClassLoader()); Class stepClass = null; if (isGroovyClass) { - try (GroovyClassLoader gcl = new GroovyClassLoader(stepsClassLoader)) { + try { + GroovyClassLoader gcl = new GroovyClassLoader(stepsClassLoader); String stepsDir = systemConfig.getConfig(DIR_STEPS); stepClass = (Class) parseClassHierarchy(gcl, stepsDir, stepUnitName); } catch (Exception e) { @@ -291,10 +287,15 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { return result; List lines = Files.readAllLines(path); + String packageName = null; for (String line : lines) { String trimmedLine = line.trim(); + if (trimmedLine.startsWith("package")) { + String[] tokens = trimmedLine.split(" "); + packageName = tokens[1].trim().replace(";", ""); + } - if (trimmedLine.startsWith("import")) { + if (trimmedLine.startsWith("import") && trimmedLine.contains(packageName)) { String[] tokens = trimmedLine.split("\\."); String name = tokens[tokens.length - 1]; name = name.replace(";", ""); @@ -312,8 +313,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration { break; } } - GroovyCodeSource x = new GroovyCodeSource(path.toFile()); - result = cl.parseClass(x, true); + result = cl.parseClass(path.toFile()); return result; } } diff --git a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobStepExecutor.java b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobStepExecutor.java index cebc500b..f1b4f7fe 100644 --- a/server/user.jobengine.osgi.server/src/user/jobengine/server/JobStepExecutor.java +++ b/server/user.jobengine.osgi.server/src/user/jobengine/server/JobStepExecutor.java @@ -1,5 +1,6 @@ package user.jobengine.server; +import java.net.URLClassLoader; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -11,6 +12,7 @@ import org.apache.commons.lang.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import groovy.lang.GroovyClassLoader; import user.commons.JobStatus; import user.commons.cluster.ClusteredJob; import user.jobengine.server.messages.JobStepCompletedMessage; @@ -132,11 +134,22 @@ public class JobStepExecutor implements IJobStepExecutor { jobRuntime.setStatus(JobStatus.EXECUTING); jobRuntime.NotifyUpdate(); - - step = createStep(); - jobRuntime.incrementPriority(); - Object[] outputs = step.run(jobEngine, jobRuntime, inputs); + Object[] outputs = null; + try { + step = createStep(); + outputs = step.run(jobEngine, jobRuntime, inputs); + } finally { + if (step != null) { + ClassLoader cl = step.getClass().getClassLoader(); + if (cl instanceof GroovyClassLoader) { + URLClassLoader parentCl = (URLClassLoader) cl.getParent(); + GroovyClassLoader groovyCl = (GroovyClassLoader) cl; + groovyCl.close(); + parentCl.close(); + } + } + } //TODO itt lekezelni a remote notification-t