From: vasary.daniel Date: Fri, 4 Dec 2020 07:56:43 +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=684636825a218e934198a50e7c522cd0f1c09243;p=mediacube.git git-tfs-id: [tfs.userrendszerhaz.hu:8080/tfs/DefaultCollection]$/MediaCube;C32087 --- diff --git a/server/-configuration/jetty-test.zip b/server/-configuration/jetty-test.zip new file mode 100644 index 00000000..25d7bc90 Binary files /dev/null and b/server/-configuration/jetty-test.zip differ diff --git a/server/-configuration/log4j2.xml b/server/-configuration/log4j2.xml index 0d07d26f..c83c6774 100644 --- a/server/-configuration/log4j2.xml +++ b/server/-configuration/log4j2.xml @@ -1,10 +1,10 @@ - log/mediacube.log - log/$${date:yyyy-MM}/mediacube-%d{MM-dd-yyyy}-%i.log.gz - log/mediacube-err.log - log/$${date:yyyy-MM}/mediacube-err-%d{MM-dd-yyyy}-%i.log.gz + /opt/log/mediacube.log + /opt/log/$${date:yyyy-MM}/mediacube-%d{MM-dd-yyyy}-%i.log.gz + /opt/log/mediacube-err.log + /opt/log/$${date:yyyy-MM}/mediacube-err-%d{MM-dd-yyyy}-%i.log.gz @@ -13,6 +13,14 @@ + + + + + + + + @@ -57,6 +65,7 @@ + diff --git a/server/-configuration/run-mediacube-server-mv.launch b/server/-configuration/run-mediacube-server-mv.launch index 598c1d71..dd2d677b 100644 --- a/server/-configuration/run-mediacube-server-mv.launch +++ b/server/-configuration/run-mediacube-server-mv.launch @@ -19,7 +19,7 @@ - + diff --git a/server/-configuration/run-mediacube-server-user (1).launch b/server/-configuration/run-mediacube-server-user (1).launch index 2099db01..eeebbda6 100644 --- a/server/-configuration/run-mediacube-server-user (1).launch +++ b/server/-configuration/run-mediacube-server-user (1).launch @@ -22,7 +22,7 @@ - + diff --git a/server/-configuration/run-mediacube-server-user (2).launch b/server/-configuration/run-mediacube-server-user (2).launch new file mode 100644 index 00000000..b818cae9 --- /dev/null +++ b/server/-configuration/run-mediacube-server-user (2).launch @@ -0,0 +1,30 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/-configuration/scheduledjobs.json b/server/-configuration/scheduledjobs.json index 8a4caaa7..d429ad34 100644 --- a/server/-configuration/scheduledjobs.json +++ b/server/-configuration/scheduledjobs.json @@ -13,6 +13,10 @@ "parameters": [ {"name": "itemID", "value": 1, "type": "java.lang.Long"} ] }, { + "template": "cancelable.xml", + "parameters": [ {"name": "param", "value": 1, "type": "java.lang.Integer"} ] + }, + { "active": false, "executeimmediate": false, "cronexpression": "0/10 * * * * ? *", diff --git a/server/-dependencies/jobengine.target b/server/-dependencies/jobengine.target index c133865f..5b106430 100644 --- a/server/-dependencies/jobengine.target +++ b/server/-dependencies/jobengine.target @@ -1,5 +1,5 @@ - + @@ -51,6 +51,7 @@ + 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 1f524f2f..6fb7c300 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 @@ -31,8 +31,6 @@ import java.util.Set; import java.util.TreeMap; import java.util.TreeSet; -import javax.sql.DataSource; - import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang.StringUtils; import org.apache.ibatis.jdbc.SQL; @@ -41,7 +39,7 @@ import org.junit.Test; import com.ibm.nosql.json.api.BasicDBList; import com.ibm.nosql.json.api.BasicDBObject; -import user.commons.MediaCubeDataSourceFactory; +import groovy.lang.GroovyClassLoader; import user.jobengine.db.Media; import user.jobengine.server.steps.ArchiveItem; import user.jobengine.server.steps.EscortFiles; @@ -934,8 +932,29 @@ public class SmallTests { @Test public void test9995() throws Exception { - MediaCubeDataSourceFactory.create(); - DataSource dataSource = MediaCubeDataSourceFactory.getDataSource(); + String className = "TestStep1"; + String root = "/opt/steps"; + try (GroovyClassLoader cl = new GroovyClassLoader(this.getClass().getClassLoader())) { + List lines = Files.readAllLines(Paths.get(root, className + ".java")); + String packageName = null; + for (String line : lines) { + String trimedLine = line.trim(); + if (trimedLine.startsWith("package")) { + packageName = trimedLine.replace("package", "").replace(";", "."); + } + + if (packageName != null && trimedLine.startsWith("import") && trimedLine.contains(packageName)) { + System.out.println(trimedLine); + } + } + + // Class myClass = cl.parseClass(Paths.get("/opt/steps/TestStep1.java").toFile()); + // System.out.println(myClass.getCanonicalName()); + // Method method = myClass.getMethod("execute"); + // method.invoke(myClass.newInstance()); + } catch (Exception e) { + throw e; + } } } diff --git a/server/user.jobengine.executors/amc/user/jobengine/server/steps/PASAPOOLTransferToStep.java b/server/user.jobengine.executors/amc/user/jobengine/server/steps/PASAPOOLTransferToStep.java index cd505402..f404fcf1 100644 --- a/server/user.jobengine.executors/amc/user/jobengine/server/steps/PASAPOOLTransferToStep.java +++ b/server/user.jobengine.executors/amc/user/jobengine/server/steps/PASAPOOLTransferToStep.java @@ -5,6 +5,8 @@ import java.nio.file.Paths; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; import user.commons.StoreUri; import user.commons.mediatool.MediaInfo; @@ -23,42 +25,43 @@ public class PASAPOOLTransferToStep extends TransferStep { public Object[] execute(StoreUri sourceStoreUri, String sourceFileName, StoreUri targetStoreUri, String targetFileName) throws Exception { this.sourceStoreUri = sourceStoreUri; this.sourceFileName = sourceFileName; + logMediaProfile(); return super.execute(sourceStoreUri, sourceFileName, targetStoreUri, targetFileName); } - @Override - protected StoreUri getTargetStoreUri() { - StoreUri result = null; - try { - Path filePath = Paths.get(sourceStoreUri.toString(true), sourceFileName); - MediaInfo mi = new MediaInfo(filePath); - mi.process(); - - if (isHD(mi)) { - result = getManager().getStoreUri("PEABLEBEACH", targetStoreUri.getProtocol()); - return result; - } - - if (isSD_HIGH_16_9(mi)) { - result = getManager().getStoreUri("SELENIOPOOL_16_9", targetStoreUri.getProtocol()); - return result; - } - - if (isSD_HIGH_4_3(mi)) { - result = getManager().getStoreUri("SELENIOPOOL_4_3", targetStoreUri.getProtocol()); - return result; - } - - if (isSD_MAIN_422(mi)) { - result = getManager().getStoreUri("PEABLEBEACH", targetStoreUri.getProtocol()); - return result; - } - } catch (Exception e) { - logger.error(getSessionMarker(), e.getMessage()); - result = targetStoreUri; - } - return result; - } + // @Override + // protected StoreUri getTargetStoreUri() { + // StoreUri result = null; + // try { + // Path filePath = Paths.get(sourceStoreUri.toString(true), sourceFileName); + // MediaInfo mi = new MediaInfo(filePath); + // mi.process(); + // + // if (isHD(mi)) { + // result = getManager().getStoreUri("PEABLEBEACH", targetStoreUri.getProtocol()); + // return result; + // } + // + // if (isSD_HIGH_16_9(mi)) { + // result = getManager().getStoreUri("SELENIOPOOL_16_9", targetStoreUri.getProtocol()); + // return result; + // } + // + // if (isSD_HIGH_4_3(mi)) { + // result = getManager().getStoreUri("SELENIOPOOL_4_3", targetStoreUri.getProtocol()); + // return result; + // } + // + // if (isSD_MAIN_422(mi)) { + // result = getManager().getStoreUri("PEABLEBEACH", targetStoreUri.getProtocol()); + // return result; + // } + // } catch (Exception e) { + // logger.error(getSessionMarker(), e.getMessage()); + // result = targetStoreUri; + // } + // return result; + // } // HD // height = 1080 @@ -93,4 +96,35 @@ public class PASAPOOLTransferToStep extends TransferStep { return mi.getHeight() < 650 && (CODEC_PROFILE_HIGH.equals(mi.getCodecProfileName()) || CODEC_PROFILE_422.equals(mi.getCodecProfileName())); } + protected void logMediaProfile() { + Marker marker = MarkerManager.getMarker("MEDIAPROFILE"); + try { + Path filePath = Paths.get(sourceStoreUri.toString(true), sourceFileName); + MediaInfo mi = new MediaInfo(filePath); + mi.process(); + + if (isHD(mi)) { + logger.info(marker, "%s is HD", sourceFileName); + return; + } + + if (isSD_HIGH_16_9(mi)) { + logger.info(marker, "%s is SD_HIGH_16_9", sourceFileName); + return; + } + + if (isSD_HIGH_4_3(mi)) { + logger.info(marker, "%s is SD_HIGH_4_3", sourceFileName); + return; + } + + if (isSD_MAIN_422(mi)) { + logger.info(marker, "%s is SD_MAIN_422", sourceFileName); + return; + } + } catch (Exception e) { + logger.error(marker, e.getMessage()); + } + } + } diff --git a/server/user.jobengine.executors/config/config-mv.xml b/server/user.jobengine.executors/config/config-mv.xml new file mode 100644 index 00000000..8599ec6f --- /dev/null +++ b/server/user.jobengine.executors/config/config-mv.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/archive-limited.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/archive-limited.xml new file mode 100644 index 00000000..8353b0c6 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/archive-limited.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/archive-material.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/archive-material.xml new file mode 100644 index 00000000..d2fe5e93 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/archive-material.xml @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/archive-ondemand.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/archive-ondemand.xml new file mode 100644 index 00000000..9ef32997 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/archive-ondemand.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/batch-retrieve-ondemand.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/batch-retrieve-ondemand.xml new file mode 100644 index 00000000..c1170b02 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/batch-retrieve-ondemand.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/cancelable.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/cancelable.xml new file mode 100644 index 00000000..2be289b3 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/cancelable.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/common-copy.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/common-copy.xml new file mode 100644 index 00000000..52c5b3f7 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/common-copy.xml @@ -0,0 +1,41 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/create-lowres-ondemand.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/create-lowres-ondemand.xml new file mode 100644 index 00000000..db6e88ff --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/create-lowres-ondemand.xml @@ -0,0 +1,106 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/delete-materials.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/delete-materials.xml new file mode 100644 index 00000000..29a18e00 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/delete-materials.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/fake-concurrent.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/fake-concurrent.xml new file mode 100644 index 00000000..88995ffb --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/fake-concurrent.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/fake-noparams.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/fake-noparams.xml new file mode 100644 index 00000000..a118f43f --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/fake-noparams.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/fake-spawn.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/fake-spawn.xml new file mode 100644 index 00000000..4a7fb850 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/fake-spawn.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/fake.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/fake.xml new file mode 100644 index 00000000..1eb2ea44 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/fake.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/migrate-hsm.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/migrate-hsm.xml new file mode 100644 index 00000000..650f125d --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/migrate-hsm.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/retrieve-ondemand.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/retrieve-ondemand.xml new file mode 100644 index 00000000..f42cde97 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/retrieve-ondemand.xml @@ -0,0 +1,150 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/retrieve.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/retrieve.xml new file mode 100644 index 00000000..d8ffd62f --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/retrieve.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/jobtemplates/mediavivantis/sys-recreate-lowres.xml b/server/user.jobengine.executors/jobtemplates/mediavivantis/sys-recreate-lowres.xml new file mode 100644 index 00000000..92c90084 --- /dev/null +++ b/server/user.jobengine.executors/jobtemplates/mediavivantis/sys-recreate-lowres.xml @@ -0,0 +1,118 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/server/user.jobengine.executors/mediavivantis/user/jobengine/server/steps/TSMSimpleRestoreStep.java b/server/user.jobengine.executors/mediavivantis/user/jobengine/server/steps/TSMSimpleRestoreStep.java new file mode 100644 index 00000000..f8c2eebc --- /dev/null +++ b/server/user.jobengine.executors/mediavivantis/user/jobengine/server/steps/TSMSimpleRestoreStep.java @@ -0,0 +1,54 @@ +package user.jobengine.server.steps; + +import java.nio.file.Files; +import java.nio.file.Paths; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +import user.commons.StoreUri; +import user.commons.remotestore.IProgressEventListener; +import user.commons.remotestore.IStatusEventListener; +import user.commons.remotestore.ProgressEvent; +import user.commons.remotestore.RemoteStoreProtocol; +import user.commons.remotestore.StatusEvent; +import user.jobengine.db.Media; +import user.jobengine.db.MediaFile; +import user.jobengine.db.Store; + +public class TSMSimpleRestoreStep extends JobStep { + private static final Logger logger = LogManager.getLogger(); + + @StepEntry + public Object[] execute(long mediaId, String targetPath) throws Exception { + String fileName = null; + try { + Media media = getManager().getMedia(mediaId); + MediaFile mediaFile = getManager().getSystemMediaFile(media); + fileName = mediaFile.getRelativePath(); + getJobRuntime().setDescription(String.format("%s (%d frames)", fileName, media.getLength())); + Store tsmStore = getManager().getSystemStore(false); + StoreUri sourceStoreUri = getManager().getStoreUri(tsmStore.getName(), RemoteStoreProtocol.TSM); + sourceStoreUri.addProgressListener(new IProgressEventListener() { + @Override + public void progressChanged(ProgressEvent evt) { + setProgress(evt.getProgress()); + } + }); + sourceStoreUri.addStatusListener(new IStatusEventListener() { + @Override + public void statusChanged(StatusEvent evt) { + evt.setCancel(!canContinue()); + } + }); + StoreUri targetStoreUri = getManager().createStoreUri(RemoteStoreProtocol.LOCAL, targetPath); + sourceStoreUri.transferFrom(targetStoreUri, fileName, fileName + ".part"); + Files.move(Paths.get(targetPath, fileName + ".part"), Paths.get(targetPath, fileName)); + } catch (Exception e) { + logger.error("Az '{}' állomány visszatöltése sikertelen. A rendszer üzenete: {}", fileName, e.getMessage()); + throw e; + } + + return null; + } +} diff --git a/server/user.jobengine.executors/amc/user/jobengine/server/steps/CancelableStep.java b/server/user.jobengine.executors/src/user/jobengine/server/steps/CancelableStep.java similarity index 86% rename from server/user.jobengine.executors/amc/user/jobengine/server/steps/CancelableStep.java rename to server/user.jobengine.executors/src/user/jobengine/server/steps/CancelableStep.java index 6648866f..bcf29f2c 100644 --- a/server/user.jobengine.executors/amc/user/jobengine/server/steps/CancelableStep.java +++ b/server/user.jobengine.executors/src/user/jobengine/server/steps/CancelableStep.java @@ -3,6 +3,8 @@ package user.jobengine.server.steps; import org.apache.commons.net.ftp.FTPClient; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.apache.logging.log4j.Marker; +import org.apache.logging.log4j.MarkerManager; import user.commons.StoreUri; import user.commons.remotestore.FtpDirectoryLister; @@ -19,14 +21,15 @@ public class CancelableStep extends JobStep { // ftpTest(); + Marker marker = MarkerManager.getMarker("MEDIAPROFILE"); + for (int i = 0; i < count; i++) { if (getJobRuntime().isWaitingCancel()) break; Thread.sleep(500); int progress = (i + 1) * 100 / count; setProgress(progress); - if (i == 1) - throw new Exception("xxx"); + logger.info(marker, "{}", i); } } catch (Exception e) { e.printStackTrace(); diff --git a/server/user.jobengine.executors/src/user/jobengine/server/steps/CreateMissingLowresStep.java b/server/user.jobengine.executors/src/user/jobengine/server/steps/CreateMissingLowresStep.java index 832b4df8..0128e099 100644 --- a/server/user.jobengine.executors/src/user/jobengine/server/steps/CreateMissingLowresStep.java +++ b/server/user.jobengine.executors/src/user/jobengine/server/steps/CreateMissingLowresStep.java @@ -58,7 +58,7 @@ public class CreateMissingLowresStep extends JobStep { private Media getFirstUntranscodedMedia(IItemManager manager, DBCollection collection) { Media[] result = { null }; - String query = "SELECT mediaid FROM VW_MISSING_PROXY_IDS WHERE LCASE(HOUSEID) LIKE '%.mxf' OR LCASE(HOUSEID) LIKE '%.mov' ORDER BY modified DESC FETCH FIRST ROW ONLY"; + String query = "SELECT mediaid FROM VW_MISSING_PROXY_IDS WHERE HOUSEID like 'M%' or HOUSEID like 'P%' or HOUSEID like 'R%' ORDER BY modified DESC FETCH FIRST ROW ONLY"; manager.executeQuery(query, rs -> { try { long mediaId = rs.getLong(1); diff --git a/server/user.jobengine.executors/src/user/jobengine/server/steps/TestForkCancelableStep.java b/server/user.jobengine.executors/src/user/jobengine/server/steps/TestForkCancelableStep.java index 39e39270..91d00a8d 100644 --- a/server/user.jobengine.executors/src/user/jobengine/server/steps/TestForkCancelableStep.java +++ b/server/user.jobengine.executors/src/user/jobengine/server/steps/TestForkCancelableStep.java @@ -14,7 +14,7 @@ public class TestForkCancelableStep extends JobStep { // private static final String CHILD_TEMPLATE = "fake-concurrent.xml"; private static final String CHILD_TEMPLATE = "cancelable.xml"; private static final Logger logger = LogManager.getLogger(); - int count = 20; + int count = 5; @StepEntry public Object[] execute(IJobEngine jobEngine, IJobRuntime jobRuntime) throws Exception { diff --git a/server/user.jobengine.osgi.commons/META-INF/MANIFEST.MF b/server/user.jobengine.osgi.commons/META-INF/MANIFEST.MF index 2c39e4bf..fb7783e4 100644 --- a/server/user.jobengine.osgi.commons/META-INF/MANIFEST.MF +++ b/server/user.jobengine.osgi.commons/META-INF/MANIFEST.MF @@ -55,7 +55,6 @@ Require-Bundle: org.apache.commons.lang;bundle-version="2.4.0", joda-time;bundle-version="2.2.0", javax.ws.rs-api;bundle-version="2.0.1", com.microsoft.sqlserver.sqljdbc;bundle-version="6.0.8112", - javax.annotation-api;bundle-version="1.2.0", org.apache.httpcomponents.httpclient;bundle-version="4.2.6", org.apache.httpcomponents.httpcore;bundle-version="4.2.5", org.apache.commons.logging;bundle-version="1.1.1", diff --git a/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java b/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java index bbcd9d86..95f05ce8 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/nosql/NoSQLUtils.java @@ -1,9 +1,12 @@ package user.commons.nosql; +import java.sql.Connection; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import javax.sql.DataSource; + import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -15,15 +18,10 @@ import com.ibm.nosql.json.api.DBCursor; import com.ibm.nosql.json.api.DBObject; import com.ibm.nosql.json.api.NoSQLClient; +import user.commons.MediaCubeDataSourceFactory; + public class NoSQLUtils { private static final Logger logger = LogManager.getLogger(); - public static final String Url, User, Pass; - public static DB noSQLClient = null; - static { - Url = System.getProperty("jobengine.nosql.db.url"); - User = System.getProperty("jobengine.nosql.db.user"); - Pass = System.getProperty("jobengine.nosql.db.password"); - } public static void addLong(BasicDBObject obj, String name, long value) { long current = asLong(obj, name); @@ -139,14 +137,15 @@ public class NoSQLUtils { } public static DB getNoSQLDB() { - // try { - // // if (noSQLClient == null) - // noSQLClient = NoSQLClient.getDB(NoSQLUtils.Url, NoSQLUtils.User, NoSQLUtils.Pass); - // } catch (Exception e) { - // logger.catching(e); - // } - // return noSQLClient; - - return NoSQLClient.getDB(NoSQLUtils.Url, NoSQLUtils.User, NoSQLUtils.Pass); + DB result = null; + try { + DataSource dataSource = MediaCubeDataSourceFactory.getNoSQLDatasource(); + Connection connection = dataSource.getConnection(); + result = NoSQLClient.getDB(connection); + } catch (Exception e) { + logger.error(e); + } + + return result; } } diff --git a/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusAPI.java b/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusAPI.java index cefb2483..9183daa5 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusAPI.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/octopus/OctopusAPI.java @@ -23,7 +23,7 @@ public class OctopusAPI implements IOctopusAPI { private DB db; public OctopusAPI() throws SQLException { - db = NoSQLUtils.getNoSQLDB(); + } private void addReferences(List result) { @@ -42,6 +42,11 @@ public class OctopusAPI implements IOctopusAPI { } } + private void ensureDB() { + if (db == null) + db = NoSQLUtils.getNoSQLDB(); + } + private List getReferencedObjects(List stories, String referenceCollectionName, String referenceField) { List ids = null; for (DBObject story : stories) { @@ -62,6 +67,7 @@ public class OctopusAPI implements IOctopusAPI { if (ids == null) return null; List result = null; + ensureDB(); DBCollection rundownCollection = db.getCollection(referenceCollectionName); BasicDBObject query = (BasicDBObject) QueryBuilder.start().put(ID).in(ids).get(); DBCursor findParents = rundownCollection.find(query); @@ -74,6 +80,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public DBObject getRundown(Date scheduledDate) { DBObject result = null; + ensureDB(); DBCollection collection = db.getCollection(RUNDOWN_COLLECTION); DBCursor find = collection.find(new BasicDBObject(SCHEDULED_START, scheduledDate)); if (find.hasNext()) @@ -84,6 +91,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public DBObject getRundownByID(long rundownID) { DBObject result = null; + ensureDB(); DBCollection collection = db.getCollection(RUNDOWN_COLLECTION); DBCursor find = collection.find(new BasicDBObject(ID, rundownID)); if (find.hasNext()) @@ -126,8 +134,13 @@ public class OctopusAPI implements IOctopusAPI { @Override public String getRundownContent(long id) { - BasicDBObject fields = new BasicDBObject(ID, 1).append(PARENT_STORY_ID, 1).append(NAME, 1).append(MODIFIED, 1).append(REF_RUNDOWN, 1).append(FORMAT, 1) - .append(MOS_OBJECTS, 1).append(SCRIPT_CONTENT, 1); + BasicDBObject fields = new BasicDBObject(ID, 1).append(PARENT_STORY_ID, 1) + .append(NAME, 1) + .append(MODIFIED, 1) + .append(REF_RUNDOWN, 1) + .append(FORMAT, 1) + .append(MOS_OBJECTS, 1) + .append(SCRIPT_CONTENT, 1); List stories = getRundownStories(id, fields); return getRundownContent(stories); } @@ -135,6 +148,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getRundownFullStories(long id) { List result = null; + ensureDB(); DBCollection collection = db.getCollection(STORY_COLLECTION); DBCursor find = collection.find(new BasicDBObject(REF_RUNDOWN, new BasicDBObject($ELEMMATCH, new BasicDBObject(ID, id)))) .sort(new BasicDBObject("name", 1)); @@ -161,6 +175,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getRundowns(Date scheduledDate) { List result = null; + ensureDB(); DBCollection collection = db.getCollection(RUNDOWN_COLLECTION); Calendar calStart = CalendarUtils.createZeroCalendar(scheduledDate); Calendar calStop = CalendarUtils.createZeroCalendar(scheduledDate); @@ -184,6 +199,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getRundownsByParentStoryID(String id) { + ensureDB(); DBCollection storyCollection = db.getCollection(STORY_COLLECTION); DBCursor find = storyCollection.find(new BasicDBObject(PARENT_STORY_ID, id), new BasicDBObject(REF_RUNDOWN, 1)); if (!find.hasNext()) @@ -194,6 +210,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getRundownsByPlaceHolderID(String id) { //db.testStoryCollection.find({"mosObjects": {$elemMatch: {"globalId": "OCTOPUS-ECHOTV-2429902"}}}) + ensureDB(); DBCollection storyCollection = db.getCollection(STORY_COLLECTION); BasicDBObject criteria = new BasicDBObject(MOS_OBJECTS, new BasicDBObject($ELEMMATCH, new BasicDBObject(OBJ_ID, id))); DBCursor find = storyCollection.find(criteria, new BasicDBObject(REF_RUNDOWN, 1)); @@ -212,10 +229,16 @@ public class OctopusAPI implements IOctopusAPI { // db.stories.find({ rundown: { $elemMatch: { id: 92950867 } }}) // { rundown: { $elemMatch: { id: 44622396 } }} List result = null; + ensureDB(); DBCollection collection = db.getCollection(STORY_COLLECTION); DBCursor find = collection - .find(new BasicDBObject(REF_RUNDOWN, new BasicDBObject($ELEMMATCH, new BasicDBObject(ID, id))), new BasicDBObject(ID, 1) - .append(PARENT_STORY_ID, 1).append(NAME, 1).append(MODIFIED, 1).append(REF_RUNDOWN, 1).append(FORMAT, 1).append(MOS_OBJECTS, 1)) + .find(new BasicDBObject(REF_RUNDOWN, new BasicDBObject($ELEMMATCH, new BasicDBObject(ID, id))), + new BasicDBObject(ID, 1).append(PARENT_STORY_ID, 1) + .append(NAME, 1) + .append(MODIFIED, 1) + .append(REF_RUNDOWN, 1) + .append(FORMAT, 1) + .append(MOS_OBJECTS, 1)) .sort(new BasicDBObject("name", 1)); if (find.hasNext()) result = find.toArray(); @@ -226,6 +249,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getRundownStories(long id, BasicDBObject fields) { List result = null; + ensureDB(); DBCollection collection = db.getCollection(STORY_COLLECTION); DBCursor find = collection.find(new BasicDBObject(REF_RUNDOWN, new BasicDBObject($ELEMMATCH, new BasicDBObject(ID, id)))) .sort(new BasicDBObject("name", 1)); @@ -259,6 +283,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getStories() { List result = null; + ensureDB(); DBCollection collection = db.getCollection(STORY_COLLECTION); DBCursor find = collection.find(new BasicDBObject(), new BasicDBObject("mosObjects", 1).append("_id", 0)).limit(1000); if (find.hasNext()) @@ -269,6 +294,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getStoriesByID(String id) { List result = null; + ensureDB(); DBCollection collection = db.getCollection(STORY_COLLECTION); DBCursor find = collection.find(new BasicDBObject(ID, id)); if (find.hasNext()) { @@ -283,6 +309,7 @@ public class OctopusAPI implements IOctopusAPI { //Pattern regex = Pattern.compile(id, Pattern.CASE_INSENSITIVE); //BasicDBObject query = new BasicDBObject("id", Pattern.compile(id)); List result = null; + ensureDB(); DBCollection collection = db.getCollection(STORY_COLLECTION); DBCursor find = collection.find(new BasicDBObject(PARENT_STORY_ID, id)); if (find.hasNext()) { @@ -295,6 +322,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getStoriesByPlaceHolderID(String id) { List result = new ArrayList<>(); + ensureDB(); DBCollection storyCollection = db.getCollection(STORY_COLLECTION); BasicDBObject criteria = new BasicDBObject(MOS_OBJECTS, new BasicDBObject($ELEMMATCH, new BasicDBObject(OBJ_ID, id))); DBCursor find = storyCollection.find(criteria); @@ -308,6 +336,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getStoryFolders() { List result = null; + ensureDB(); DBCollection collection = db.getCollection(FOLDER_COLLECTION); DBCursor find = collection.find(); if (find.hasNext()) @@ -317,6 +346,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getStoryFoldersByParentStoryID(String id) { + ensureDB(); DBCollection storyCollection = db.getCollection(STORY_COLLECTION); DBCursor find = storyCollection.find(new BasicDBObject(PARENT_STORY_ID, id), new BasicDBObject(REF_STORYFOLDER, 1)); if (!find.hasNext()) @@ -326,6 +356,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getStoryFoldersByPlaceHolderID(String id) { + ensureDB(); DBCollection storyCollection = db.getCollection(STORY_COLLECTION); BasicDBObject criteria = new BasicDBObject(MOS_OBJECTS, new BasicDBObject($ELEMMATCH, new BasicDBObject(OBJ_ID, id))); DBCursor find = storyCollection.find(criteria, new BasicDBObject(REF_STORYFOLDER, 1)); @@ -337,10 +368,16 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getStoryFolderStories(long storyFolderId) { List result = null; + ensureDB(); DBCollection collection = db.getCollection(STORY_COLLECTION); DBCursor find = collection - .find(new BasicDBObject(REF_STORYFOLDER, new BasicDBObject($ELEMMATCH, new BasicDBObject(ID, storyFolderId))), new BasicDBObject(ID, 1) - .append(PARENT_STORY_ID, 1).append(NAME, 1).append(MODIFIED, 1).append(REF_STORYFOLDER, 1).append(FORMAT, 1).append(MOS_OBJECTS, 1)) + .find(new BasicDBObject(REF_STORYFOLDER, new BasicDBObject($ELEMMATCH, new BasicDBObject(ID, storyFolderId))), + new BasicDBObject(ID, 1).append(PARENT_STORY_ID, 1) + .append(NAME, 1) + .append(MODIFIED, 1) + .append(REF_STORYFOLDER, 1) + .append(FORMAT, 1) + .append(MOS_OBJECTS, 1)) .sort(new BasicDBObject(NAME, 1)); if (find.hasNext()) result = find.toArray(); @@ -350,6 +387,7 @@ public class OctopusAPI implements IOctopusAPI { @Override public List getStoryFolderStories(long storyFolderId, BasicDBObject fields) { List result = null; + ensureDB(); DBCollection collection = db.getCollection(STORY_COLLECTION); DBCursor find = collection.find(new BasicDBObject(REF_STORYFOLDER, new BasicDBObject($ELEMMATCH, new BasicDBObject(ID, storyFolderId))), fields) .sort(new BasicDBObject(NAME, 1)); diff --git a/server/user.jobengine.osgi.commons/src/user/commons/remotestore/TSMOutputStream.java b/server/user.jobengine.osgi.commons/src/user/commons/remotestore/TSMOutputStream.java index 469dd2fc..046ad35d 100644 --- a/server/user.jobengine.osgi.commons/src/user/commons/remotestore/TSMOutputStream.java +++ b/server/user.jobengine.osgi.commons/src/user/commons/remotestore/TSMOutputStream.java @@ -38,9 +38,11 @@ public class TSMOutputStream extends OutputStream { logger.info("Closing stream"); try { //ha nem sikerult az iras, mar volt abort - if (success) + if (success) { client.commit(); - logger.info("Commit at close completed"); + logger.info("Commit at close completed"); + } else + logger.info("Skipping commit at close, session probaly terminated"); } catch (Exception e) { throw new IOException(e); } finally { diff --git a/server/user.jobengine.osgi.db/src/user/commons/pool/ContextPool.java b/server/user.jobengine.osgi.db/src/user/commons/pool/ContextPool.java index ef6ac7a5..e270456d 100644 --- a/server/user.jobengine.osgi.db/src/user/commons/pool/ContextPool.java +++ b/server/user.jobengine.osgi.db/src/user/commons/pool/ContextPool.java @@ -3,8 +3,7 @@ package user.commons.pool; import java.lang.reflect.InvocationTargetException; import java.sql.Connection; import java.sql.DriverManager; -import java.sql.ResultSet; -import java.sql.Statement; +import java.sql.SQLException; import java.util.Properties; import org.apache.logging.log4j.LogManager; @@ -33,33 +32,40 @@ public class ContextPool extends ResourcePool { @Override protected boolean checkObject(Object resourceObject) { DefaultContext context = (DefaultContext) resourceObject; - boolean result = false; - String sql = "SELECT 1 FROM SYSIBM.SYSDUMMY1"; - Statement stmt = null; - ResultSet rs = null; - try { - stmt = context.getConnection().createStatement(); - rs = stmt.executeQuery(sql); - while (rs.next()) - rs.getInt(1); - result = true; - } catch (Exception e1) { - logger.catching(e1); - if (rs != null) - try { - rs.close(); - } catch (Exception e) { - logger.catching(e); - } - if (stmt != null) - try { - stmt.close(); - } catch (Exception e) { - logger.catching(e); - } + boolean result = false; + try { + result = !context.getConnection().isClosed(); + } catch (SQLException e) { } + logger.info("Context check {}", result); + // String sql = "SELECT 1 FROM SYSIBM.SYSDUMMY1"; + // Statement stmt = null; + // ResultSet rs = null; + // try { + // stmt = context.getConnection().createStatement(); + // rs = stmt.executeQuery(sql); + // while (rs.next()) + // rs.getInt(1); + // + // result = true; + // } catch (Exception e1) { + // logger.catching(e1); + // if (rs != null) + // try { + // rs.close(); + // } catch (Exception e) { + // logger.catching(e); + // } + // if (stmt != null) + // try { + // stmt.close(); + // } catch (Exception e) { + // logger.catching(e); + // } + // + // } return result; } 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 fdb40335..4578e940 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 @@ -584,8 +584,8 @@ public class JobEngine implements IJobEngine { for (Job job : runningJobs) { Job runningJob = getJob(job.getId()); if (runningJob != null && runningJob.getStatus() != JobStatus.SUSPENDED) - throw new JobEngineException( - String.format("Can not submit job. Job with %s.%s already running", template.getFileName(), template.getName())); + throw new JobEngineException(String.format("Can not submit job. Job with %s.%s already running", template.getFileName(), + template.getName())); } } } @@ -849,6 +849,18 @@ public class JobEngine implements IJobEngine { runQueue.remove(jobRuntime); } + @Override + public void removeGarbage() { + 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()))) + removeId.add(id); + } + for (Long id : removeId) + submittedJobs.remove(id); + } + @Override public void removeJob(long id) { if (submittedJobs.containsKey(id)) { @@ -877,18 +889,6 @@ public class JobEngine implements IJobEngine { } - @Override - public void removeGarbage() { - 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()))) - removeId.add(id); - } - for (Long id : removeId) - submittedJobs.remove(id); - } - @Override public ClusteredJob requestJob(String className) throws Exception { if (!executors.containsKey(className)) @@ -1053,7 +1053,8 @@ public class JobEngine implements IJobEngine { result.addEventListener(statusListener); submit(result); } else { - logger.error("Unknown template: " + template); + logger.error("Unknown template {}", template); + throw new JobEngineException("Unknown template " + template); } 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 8f32f175..23e19ad5 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,7 +1,6 @@ package user.jobengine.server; import java.net.URLClassLoader; -import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -229,11 +228,23 @@ public class JobStepExecutor implements IJobStepExecutor { IJobStep result = null; if (isGroovyStep()) { - GroovyClassLoader gcl = new GroovyClassLoader(parentLoader); - Path stepRoot = Paths.get(System.getProperty("jobengine.jobsteps.groovy.root", "")); - gcl.addClasspath(stepRoot.toString()); - Class myClass = gcl.parseClass(Paths.get(stepRoot.toString(), stepUnitName).toFile()); - result = (IJobStep) myClass.newInstance(); + try (GroovyClassLoader gcl = new GroovyClassLoader(parentLoader)) { + String stepsDir = System.getProperty("jobengine.jobsteps.groovy.root", ""); + for (String executorName : jobEngine.getExecutors().keySet()) { + if (!executorName.endsWith(".java")) + continue; + + Class myClass = gcl.parseClass(Paths.get(stepsDir, executorName).toFile()); + if (stepUnitName.equals(executorName)) { + result = (IJobStep) myClass.newInstance(); + break; + } + } + } catch (Exception e) { + logger.error(e.getMessage()); + throw e; + } + } else result = stepClass.newInstance(); return result; diff --git a/server/user.jobengine.osgi.services/META-INF/MANIFEST.MF b/server/user.jobengine.osgi.services/META-INF/MANIFEST.MF index 09fcc754..0f81ddb9 100644 --- a/server/user.jobengine.osgi.services/META-INF/MANIFEST.MF +++ b/server/user.jobengine.osgi.services/META-INF/MANIFEST.MF @@ -17,6 +17,7 @@ Import-Package: com.fasterxml.jackson.annotation;version="2.4.5", com.ibm.nosql.bson, com.ibm.nosql.json, com.ibm.nosql.json.api, + com.ibm.nosql.json.util, javax.annotation;version="1.2.0", javax.servlet;version="3.1.0", javax.servlet.http;version="3.1.0", diff --git a/server/user.jobengine.osgi.services/src/user/jobengine/osgi/mediacube/MediaCubeService.java b/server/user.jobengine.osgi.services/src/user/jobengine/osgi/mediacube/MediaCubeService.java index 83d41f00..92c8a3ea 100644 --- a/server/user.jobengine.osgi.services/src/user/jobengine/osgi/mediacube/MediaCubeService.java +++ b/server/user.jobengine.osgi.services/src/user/jobengine/osgi/mediacube/MediaCubeService.java @@ -1,13 +1,16 @@ package user.jobengine.osgi.mediacube; import java.util.Set; +import java.util.stream.Collectors; +import javax.servlet.http.HttpServletRequest; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -15,6 +18,9 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.eclipse.core.runtime.adaptor.EclipseStarter; +import com.ibm.nosql.json.api.BasicDBObject; +import com.ibm.nosql.json.util.JSON; + import user.commons.MediaCubeMarker; import user.jobengine.db.IItemManager; import user.jobengine.db.IResultSetConsumer; @@ -24,13 +30,13 @@ import user.jobengine.db.JSONBase; import user.jobengine.db.Media; import user.jobengine.osgi.rest.ComponentBinder; import user.jobengine.server.IJobEngine; +import user.jobengine.server.IJobRuntime; @Path("/jobengine") @SuppressWarnings("restriction") public class MediaCubeService { private static final Logger logger = LogManager.getLogger(); - private IItemManager itemManager = ComponentBinder.getItemManager(); public MediaCubeService() { logger.info("Created"); @@ -50,6 +56,51 @@ public class MediaCubeService { return result; } + @GET + @Path("/checkmediafile") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public Response checkMediaFile(@QueryParam("mediaFileHouseId") String mediaFileHouseId, @QueryParam("store") String store) { + Response result = null; + try { + IItemManager itemManager = ComponentBinder.getItemManager(); + if (itemManager == null) + throw new Exception("No ItemManager found"); + if (mediaFileHouseId == null || mediaFileHouseId.trim().length() == 0) + throw new Exception("The 'mediaFileHouseId' parameter is not provided!"); + if (store == null || store.trim().length() == 0) + throw new Exception("The 'store' parameter is not provided!"); + BasicDBObject id[] = { new BasicDBObject() }; + String sql = String.format( + "select mf.mediaid, mf.houseId, mf.relativepath from MEDIAFILE mf, STORE s where mf.storeid = s.id and s.name='%s' and houseid LIKE '%s.%%'", + store, mediaFileHouseId); + IResultSetConsumer consumer = rs -> { + String origName = rs.getString("houseId"); + String tsmName = rs.getString("relativePath"); + long mediaId = rs.getLong("mediaId"); + if (origName.toUpperCase().endsWith(".MXF")) { + + id[0].put("origName", origName); + id[0].put("tsmName", tsmName); + id[0].put("mediaId", mediaId); + return false; + } + + if (origName.toUpperCase().endsWith(".MOV")) { + id[0].put("origName", origName); + id[0].put("tsmName", tsmName); + id[0].put("mediaId", mediaId); + } + return true; + }; + itemManager.executeQuery(sql, consumer, null); + result = Response.ok(id[0]).build(); + } catch (Exception e) { + result = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); + } + return result; + } + @POST @Path("/create") @Consumes({ MediaType.APPLICATION_JSON }) @@ -57,6 +108,7 @@ public class MediaCubeService { public Response create(JSONBase entity) { Response result = null; try { + IItemManager itemManager = ComponentBinder.getItemManager(); if (itemManager == null) throw new Exception("No ItemManager found"); itemManager.add(entity); @@ -74,6 +126,7 @@ public class MediaCubeService { public Response getItem() { Response result = null; try { + IItemManager itemManager = ComponentBinder.getItemManager(); if (itemManager == null) throw new Exception("No ItemManager found"); Item item = itemManager.createItem("xxx", "yyyy", "111"); @@ -91,6 +144,7 @@ public class MediaCubeService { public Response getMedia(@QueryParam("mediaHouseId") String mediaHouseId) { Response result = null; try { + IItemManager itemManager = ComponentBinder.getItemManager(); if (itemManager == null) throw new Exception("No ItemManager found"); @@ -137,6 +191,7 @@ public class MediaCubeService { public Response getTags() { Response result = null; try { + IItemManager itemManager = ComponentBinder.getItemManager(); if (itemManager == null) throw new Exception("No ItemManager found"); Set tags = itemManager.getAllTags().keySet(); @@ -175,6 +230,32 @@ public class MediaCubeService { return result; } + @GET + @Path("/jobstatus") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public Response jobStatus(@QueryParam("jobId") long jobId) { + Response result = null; + try { + IItemManager itemManager = ComponentBinder.getItemManager(); + if (itemManager == null) + throw new Exception("No ItemManager found"); + if (jobId == 0) + throw new Exception("The 'jobId' parameter is not provided!"); + String status[] = { null }; + String sql = String.format("select status from JOB where id=%d", jobId); + IResultSetConsumer consumer = rs -> { + status[0] = rs.getString("status"); + return false; + }; + itemManager.executeQuery(sql, consumer, null); + result = Response.ok(status[0]).build(); + } catch (Exception e) { + result = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); + } + return result; + } + @GET @Path("/notify") @Consumes({ MediaType.APPLICATION_JSON }) @@ -206,4 +287,34 @@ public class MediaCubeService { } return result; } + + @POST + @Path("/startjob") + @Consumes({ MediaType.APPLICATION_JSON }) + @Produces({ MediaType.APPLICATION_JSON }) + public Response startJob(@QueryParam("template") String template, @QueryParam("name") String name, @Context HttpServletRequest request) { + + Response result = null; + try { + Object jsStr = request.getReader().lines().collect(Collectors.joining(System.lineSeparator())); + BasicDBObject jobParameters = (BasicDBObject) JSON.parse(String.valueOf(jsStr)); + + IJobEngine jobEngine = ComponentBinder.getJobengine(); + if (jobEngine == null) + throw new Exception("No JobEngine found"); + if (template == null || template.trim().length() == 0) + throw new Exception("The 'template' parameter is not provided!"); + if (name == null || name.trim().length() == 0) + throw new Exception("The 'name' parameter is not provided!"); + + IJobRuntime jobRuntime = jobEngine.submit(template, name, jobParameters); + if (jobRuntime == null) + throw new NullPointerException("Job submit error!"); + result = Response.ok(jobRuntime.getId()).build(); + } catch (Exception e) { + result = Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); + } + return result; + } + } diff --git a/server/user.mediacube.gui/pages/searchitems.zul b/server/user.mediacube.gui/pages/searchitems.zul index 19a5b215..4be9d565 100644 --- a/server/user.mediacube.gui/pages/searchitems.zul +++ b/server/user.mediacube.gui/pages/searchitems.zul @@ -35,7 +35,7 @@
- +
diff --git a/server/user.mediacube.gui/src/user/jobengine/zk/model/SearchModel.java b/server/user.mediacube.gui/src/user/jobengine/zk/model/SearchModel.java index 1a8e6c43..e610c70a 100644 --- a/server/user.mediacube.gui/src/user/jobengine/zk/model/SearchModel.java +++ b/server/user.mediacube.gui/src/user/jobengine/zk/model/SearchModel.java @@ -543,7 +543,10 @@ public class SearchModel extends AsyncBaseModel { } private void handleSearchError(Exception e) { - Clients.showNotification(e.getMessage(), "error", search, "start_center", 3000); + if (e instanceof NullPointerException) + Clients.showNotification("Database query error!", "error", search, "start_center", 3000); + else + Clients.showNotification(e.getMessage(), "error", search, "start_center", 3000); logger.error(e); } diff --git a/server/user.tsm.client/src/user/tsm/client/TSMBufferedClient.java b/server/user.tsm.client/src/user/tsm/client/TSMBufferedClient.java index aaaffac8..88754909 100644 --- a/server/user.tsm.client/src/user/tsm/client/TSMBufferedClient.java +++ b/server/user.tsm.client/src/user/tsm/client/TSMBufferedClient.java @@ -159,14 +159,17 @@ public class TSMBufferedClient extends TSMClient { object.bytesWorked(byteCount); } catch (Exception e) { - logger.error("Catched error in send. System messahe is: {}", e.getMessage()); - vote(TSMAPIConstants.DSM_VOTE_ABORT); + logger.error("Catched error in send. System message is: {}", e.getMessage()); + try { + vote(TSMAPIConstants.DSM_VOTE_ABORT); + } catch (Exception e2) { + } throw e; } } private short vote(byte vote) throws TSMException { - logger.info("Vote"); + logger.info("Vote {}", vote); short result = TSMAPIConstants.DSM_RC_OK; DsmEndTxnExIn endTxnExIn = new DsmEndTxnExIn(); @@ -179,15 +182,15 @@ public class TSMBufferedClient extends TSMClient { logger.catching(e); } - // if (result == TSMAPIConstants.DSM_RC_CHECK_REASON_CODE) { - // logger.error("dsmEndTxnEx error, reason code {}", endTxnExOut.getReason()); - // } else { - // if (result != TSMAPIConstants.DSM_RC_OK) - // throw new TSMException(dsmHandle, rc, endTxnExOut.getReason()); - // } - - if (result != TSMAPIConstants.DSM_RC_OK) - throw new TSMException(dsmHandle, rc, endTxnExOut.getReason()); + if (vote != TSMAPIConstants.DSM_VOTE_ABORT) { + if (result == TSMAPIConstants.DSM_RC_CHECK_REASON_CODE) + logger.warn("DSM_VOTE_ABORT warning, reason code {}", endTxnExOut.getReason()); + } else { + if (result != TSMAPIConstants.DSM_RC_OK) { + logger.warn("DSM_VOTE_COMMIT error"); + throw new TSMException(dsmHandle, rc, endTxnExOut.getReason()); + } + } logger.info("Vote completed"); return result;