git-tfs-id: [http://tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube...
authorvasary.daniel <TFS\vasary.daniel>
Thu, 15 Apr 2021 12:28:59 +0000 (12:28 +0000)
committervasary.daniel <TFS\vasary.daniel>
Thu, 15 Apr 2021 12:28:59 +0000 (12:28 +0000)
server/-product/production/LOCAL/jobs/steps/CancelableStep.java
server/-product/production/LOCAL/jobs/steps/PathItemsCollectorStep.java
server/-product/production/LOCAL/jobs/steps/TestLib.java [new file with mode: 0644]
server/hu.user.mediacube.executors.tests/META-INF/MANIFEST.MF
server/hu.user.mediacube.executors.tests/data/hu/user/mediacube/executors/tests/data/TestChild.java
server/hu.user.mediacube.executors.tests/data/hu/user/mediacube/executors/tests/data/TestLib.java [new file with mode: 0644]
server/hu.user.mediacube.executors.tests/src/hu/user/mediacube/executors/tests/SmallTests.java
server/user.jobengine.osgi.server/src/user/jobengine/server/JobEngineConfiguration.java
server/user.jobengine.osgi.server/src/user/jobengine/server/JobStepExecutor.java

index 0ff5eca43b9e3aff35b08df44ec7c7a56667acbf..bee93c649807530b099f9aa778a7f8fe9013b6c5 100644 (file)
@@ -10,6 +10,10 @@ import user.commons.StoreUri;
 import user.commons.remotestore.FtpDirectoryLister;\r
 import user.commons.remotestore.RemoteStoreProtocol;\r
 \r
+\r
+/* DO NOT REMOVE!\r
+import user.jobengine.server.steps.TestLib;\r
+*/\r
 public class CancelableStep extends JobStep {\r
        private static final Logger logger = LogManager.getLogger();\r
        int count = 10;\r
@@ -17,6 +21,7 @@ public class CancelableStep extends JobStep {
        @StepEntry\r
        public Object[] execute(int param) throws Exception {\r
                try {\r
+                       TestLib t = new TestLib();\r
 \r
                        Marker marker = MarkerManager.getMarker("MEDIAPROFILE");\r
                        getJobRuntime().setRelated("TESZT" + param);\r
index 69ca5d02a8b0a8622445d82d30ac12aa3acc28de..de1ae3a9efea02a07d3816c71bdab1add594429a 100644 (file)
@@ -18,7 +18,7 @@ import com.ibm.nosql.json.api.BasicDBObject;
 \r
 /* DO NOT REMOVE!\r
 import user.jobengine.server.steps.FileSearchFilterOptions;\r
- */\r
+*/\r
 \r
 public class PathItemsCollectorStep extends JobStep {\r
        private static final Logger logger = LogManager.getLogger();\r
@@ -41,9 +41,10 @@ public class PathItemsCollectorStep extends JobStep {
 \r
                        @Override\r
                        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {\r
-                               if (filterOptions.acceptFile(file))\r
+                               if (filterOptions.acceptFile(file)) {\r
                                        files.add(file.toString());\r
-                               logger.info(file);\r
+                                       logger.info(file.getFileName());\r
+                               }\r
                                return FileVisitResult.CONTINUE;\r
                        }\r
 \r
diff --git a/server/-product/production/LOCAL/jobs/steps/TestLib.java b/server/-product/production/LOCAL/jobs/steps/TestLib.java
new file mode 100644 (file)
index 0000000..040153e
--- /dev/null
@@ -0,0 +1,8 @@
+package user.jobengine.server.steps;\r
+\r
+public class TestLib {\r
+\r
+       public void hello() {\r
+               System.out.println("Hello from lib");\r
+       }\r
+}\r
index 4e8b0cfa91a25006aded56b5b2d5a870dc80898a..35b0ee222853b9ea995eb3f9bbea243eb8a91df3 100644 (file)
@@ -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
index 382ff4a350a21bcb96b0237dbd7bad864e6343f9..49e6cc6f17b72aab0d30e88d25658396246e0c29 100644 (file)
@@ -1,10 +1,14 @@
 package hu.user.mediacube.executors.tests.data;\r
 \r
+\r
 public class TestChild extends TestParent {\r
 \r
        @Override\r
        public void hello() {\r
                super.hello();\r
                System.out.println("Hello from child");\r
+               \r
+               TestLib lib = new TestLib();\r
+               lib.hello();\r
        }\r
 }\r
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 (file)
index 0000000..36adb50
--- /dev/null
@@ -0,0 +1,8 @@
+package hu.user.mediacube.executors.tests.data;\r
+\r
+public class TestLib {\r
+\r
+       public void hello() {\r
+               System.out.println("Hello from lib");\r
+       }\r
+}\r
index 46e13d60351ca3b10daf65c31d528cde15351346..8bc9adad22c5b6d08218b9dfe1dd2836e8fd0578 100644 (file)
@@ -983,25 +983,25 @@ public class SmallTests {
 \r
        @Test\r
        public void test9995() throws Exception {\r
-               String file = "/opt/test/TestChild.java";\r
-\r
-                \r
                GroovyClassLoader cl = new GroovyClassLoader(this.getClass().getClassLoader()) {\r
-                       \r
+\r
                        @Override\r
                        public Class loadClass(String name, boolean lookupScriptFiles, boolean preferClassOverScript, boolean resolve)\r
                                        throws ClassNotFoundException, CompilationFailedException {\r
-                               // TODO Auto-generated method stub\r
                                return super.loadClass(name, lookupScriptFiles, preferClassOverScript, resolve);\r
                        }\r
-                       \r
+\r
                };\r
 \r
                try {\r
+                       cl.parseClass(new File("/opt/test/TestParent.java"));\r
 \r
-                       Class<?> myClass = cl.parseClass(new File(file));\r
+                       cl.parseClass(new File("/opt/test/TestLib.java"));\r
+\r
+                       Class[] loadedClasses = cl.getLoadedClasses();\r
+                       Class<?> myClass = cl.parseClass(new File("/opt/test/TestChild.java"));\r
                        System.out.println(myClass.getCanonicalName());\r
-                       Method method = myClass.getMethod("execute");\r
+                       Method method = myClass.getMethod("hello");\r
                        method.invoke(myClass.newInstance());\r
                        System.out.println("done");\r
                } catch (Throwable e) {\r
index 1bcc931fa8cd9a4bbd19d60574bb45ecd7de8e51..f3649b34fecf6b26f5615e9d2286e4030848d74b 100644 (file)
@@ -26,7 +26,6 @@ import com.ibm.nosql.json.api.BasicDBList;
 import com.ibm.nosql.json.api.BasicDBObject;\r
 \r
 import groovy.lang.GroovyClassLoader;\r
-import groovy.lang.GroovyCodeSource;\r
 import user.commons.configuration.IConfiguration;\r
 import user.commons.nosql.NoSQLUtils;\r
 import user.jobengine.server.ast.Encoder;\r
@@ -51,8 +50,6 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
        private final List<JobTemplate> templates = Collections.synchronizedList(new ArrayList<JobTemplate>());\r
        private final Map<String, BasicDBObject> schedules = new LinkedHashMap<String, BasicDBObject>();\r
 \r
-       private URLClassLoader stepsClassLoader = null;\r
-\r
        public synchronized void bindSystemConfiguration(Object service) {\r
                if (service instanceof IConfiguration) {\r
                        systemConfig = (IConfiguration) service;\r
@@ -67,17 +64,16 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
 \r
                boolean isGroovyClass = stepUnitName.toLowerCase().endsWith(".java") || stepUnitName.toLowerCase().endsWith(".groovy");\r
 \r
-               if (stepsClassLoader == null) {\r
-                       String stepClassesDir = systemConfig.getConfig(DIR_CLASSES);\r
-                       Path path = Paths.get(stepClassesDir);\r
-                       URL[] urls = { path.toUri().toURL() };\r
-                       stepsClassLoader = URLClassLoader.newInstance(urls, getClass().getClassLoader());\r
-               }\r
+               String stepClassesDir = systemConfig.getConfig(DIR_CLASSES);\r
+               Path path = Paths.get(stepClassesDir);\r
+               URL[] urls = { path.toUri().toURL() };\r
+               URLClassLoader stepsClassLoader = URLClassLoader.newInstance(urls, Thread.currentThread().getContextClassLoader());\r
 \r
                Class<IJobStep> stepClass = null;\r
 \r
                if (isGroovyClass) {\r
-                       try (GroovyClassLoader gcl = new GroovyClassLoader(stepsClassLoader)) {\r
+                       try {\r
+                               GroovyClassLoader gcl = new GroovyClassLoader(stepsClassLoader);\r
                                String stepsDir = systemConfig.getConfig(DIR_STEPS);\r
                                stepClass = (Class<IJobStep>) parseClassHierarchy(gcl, stepsDir, stepUnitName);\r
                        } catch (Exception e) {\r
@@ -291,10 +287,15 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                        return result;\r
                List<String> lines = Files.readAllLines(path);\r
 \r
+               String packageName = null;\r
                for (String line : lines) {\r
                        String trimmedLine = line.trim();\r
+                       if (trimmedLine.startsWith("package")) {\r
+                               String[] tokens = trimmedLine.split(" ");\r
+                               packageName = tokens[1].trim().replace(";", "");\r
+                       }\r
 \r
-                       if (trimmedLine.startsWith("import")) {\r
+                       if (trimmedLine.startsWith("import") && trimmedLine.contains(packageName)) {\r
                                String[] tokens = trimmedLine.split("\\.");\r
                                String name = tokens[tokens.length - 1];\r
                                name = name.replace(";", "");\r
@@ -312,8 +313,7 @@ public class JobEngineConfiguration implements IJobEngineConfiguration {
                                break;\r
                        }\r
                }\r
-               GroovyCodeSource x = new GroovyCodeSource(path.toFile());\r
-               result = cl.parseClass(x, true);\r
+               result = cl.parseClass(path.toFile());\r
                return result;\r
        }\r
 }\r
index cebc500bfc2c795f53374fd912dc20c355653388..f1b4f7fe68d6c827fd833d4ead01f1008c73399b 100644 (file)
@@ -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