diff --git a/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupService.java b/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupService.java index 605bc2f..1f4b6a2 100644 --- a/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupService.java +++ b/imixs-archive-backup/src/main/java/org/imixs/archive/backup/BackupService.java @@ -69,7 +69,6 @@ * @version 1.0 * @author rsoika */ - @Singleton @Startup public class BackupService { @@ -354,6 +353,7 @@ public void restartScheduler() throws BackupException { */ public void startScheduler(boolean clearLog) throws BackupException { try { + restClientHelper.reset(); if (clearLog) { // clear log in case of a normal start logController.reset(BackupApi.TOPIC_BACKUP); diff --git a/imixs-archive-backup/src/main/java/org/imixs/archive/backup/RestoreService.java b/imixs-archive-backup/src/main/java/org/imixs/archive/backup/RestoreService.java index 03387bb..ae1fff0 100644 --- a/imixs-archive-backup/src/main/java/org/imixs/archive/backup/RestoreService.java +++ b/imixs-archive-backup/src/main/java/org/imixs/archive/backup/RestoreService.java @@ -341,7 +341,7 @@ private void restoreSnapshot(DocumentClient documentClient, ItemCollection snaps */ public void startScheduler() throws BackupException { try { - + restClientHelper.reset(); logController.reset(BackupApi.TOPIC_RESTORE); logController.info(BackupApi.TOPIC_RESTORE, "Starting restore scheduler - initalDelay=0ms inverval=" + interval + "ms ...."); diff --git a/imixs-archive-backup/src/main/java/org/imixs/archive/backup/util/RestClientHelper.java b/imixs-archive-backup/src/main/java/org/imixs/archive/backup/util/RestClientHelper.java index 0ff876a..e9e4928 100644 --- a/imixs-archive-backup/src/main/java/org/imixs/archive/backup/util/RestClientHelper.java +++ b/imixs-archive-backup/src/main/java/org/imixs/archive/backup/util/RestClientHelper.java @@ -140,4 +140,12 @@ public EventLogClient createEventLogClient(DocumentClient documentClient) { } } + /** + * This method invalidates the rest clients + */ + public void reset() { + documentClient = null; + eventLogClient = null; + } + } \ No newline at end of file diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/ImixsArchiveApp.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/ImixsArchiveApp.java index 17a1aea..46f774f 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/ImixsArchiveApp.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/ImixsArchiveApp.java @@ -27,21 +27,15 @@ package org.imixs.archive.service; -import jakarta.annotation.PostConstruct; -import jakarta.inject.Inject; import jakarta.ws.rs.ApplicationPath; import jakarta.ws.rs.core.Application; -import org.imixs.archive.service.resync.ResyncService; -import org.imixs.archive.service.util.MessageService; - /** * The Imixs-Archive-Service application setup * * @author rsoika * */ - @ApplicationPath("api") public class ImixsArchiveApp extends Application { @@ -49,7 +43,6 @@ public class ImixsArchiveApp extends Application { public static final String EVENTLOG_TOPIC_ADD = "snapshot.add"; public static final String EVENTLOG_TOPIC_REMOVE = "snapshot.remove"; public static final String EVENTLOG_TOPIC_BACKUP = "snapshot.backup"; - public static final String ITEM_BACKUPRESTORE = "$backuprestore"; // rest service endpoint @@ -62,28 +55,8 @@ public class ImixsArchiveApp extends Application { public static final String WORKFLOW_SYNC_DEADLOCK = "workflow.sync.deadlock"; public static final String BACKUP_SERVICE_ENDPOINT = "backup.service.endpoint"; - @Inject - ResyncService syncService; - - @Inject - MessageService messageService; - public ImixsArchiveApp() { super(); } - /** - * Initialize the web application - */ - @PostConstruct - public void initialize() { - if (syncService != null) { - try { - syncService.start(); - } catch (ArchiveException e) { - messageService.logMessage(ResyncService.MESSAGE_TOPIC, "Failed to start scheduler - " + e.getMessage()); - e.printStackTrace(); - } - } - } } diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/RemoteAPIService.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/RemoteAPIService.java index db45e26..19e1309 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/RemoteAPIService.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/RemoteAPIService.java @@ -27,9 +27,7 @@ import org.eclipse.microprofile.config.inject.ConfigProperty; import org.imixs.archive.service.cassandra.ClusterService; -import org.imixs.melman.BasicAuthenticator; import org.imixs.melman.DocumentClient; -import org.imixs.melman.FormAuthenticator; import org.imixs.melman.RestAPIException; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.xml.XMLDataCollection; @@ -83,12 +81,11 @@ public class RemoteAPIService { * @throws ArchiveException * */ - public XMLDataCollection readSyncData(long syncPoint) throws ArchiveException { + public XMLDataCollection readSyncData(long syncPoint, DocumentClient documentClient) throws ArchiveException { XMLDataCollection result = null; // load next document String url = ""; try { - DocumentClient documentClient = initWorkflowClient(); url = SNAPSHOT_SYNCPOINT_RESOURCE + syncPoint; logger.finest("...... read data: " + url + "...."); @@ -115,11 +112,10 @@ public XMLDataCollection readSyncData(long syncPoint) throws ArchiveException { * @throws ArchiveException * */ - public String readSnapshotIDByUniqueID(String uniqueid) throws ArchiveException { + public String readSnapshotIDByUniqueID(String uniqueid, DocumentClient documentClient) throws ArchiveException { String result = null; try { // load single document - DocumentClient documentClient = initWorkflowClient(); String url = DOCUMENTS_RESOURCE + uniqueid + "?items=$snapshotid"; logger.finest("...... read snapshotid: " + url + "...."); @@ -137,9 +133,8 @@ public String readSnapshotIDByUniqueID(String uniqueid) throws ArchiveException return result; } - public void restoreSnapshot(ItemCollection snapshot) throws ArchiveException { + public void restoreSnapshot(ItemCollection snapshot, DocumentClient documentClient) throws ArchiveException { try { - DocumentClient documentClient = initWorkflowClient(); String url = SNAPSHOT_RESOURCE; logger.finest("...... post data: " + url + "...."); // documentClient.postDocument(url, snapshot); @@ -151,9 +146,8 @@ public void restoreSnapshot(ItemCollection snapshot) throws ArchiveException { } - public void deleteSnapshot(String id) throws ArchiveException { + public void deleteSnapshot(String id, DocumentClient documentClient) throws ArchiveException { try { - DocumentClient documentClient = initWorkflowClient(); String url = SNAPSHOT_RESOURCE; logger.finest("...... delete data: " + url + "...."); documentClient.deleteDocument(id); @@ -170,27 +164,31 @@ public void deleteSnapshot(String id) throws ArchiveException { * * @throws RestAPIException */ - DocumentClient initWorkflowClient() throws RestAPIException { - - logger.finest("...... WORKFLOW_SERVICE_ENDPOINT = " + workflowServiceEndpoint); - - DocumentClient documentClient = new DocumentClient(workflowServiceEndpoint.get()); - - // Test authentication method - if ("Form".equalsIgnoreCase(workflowServiceAuthMethod.get())) { - // default basic authenticator - FormAuthenticator formAuth = new FormAuthenticator(workflowServiceEndpoint.get(), workflowServiceUser.get(), - workflowServicePassword.get()); - // register the authenticator - documentClient.registerClientRequestFilter(formAuth); - - } else { - // default basic authenticator - BasicAuthenticator basicAuth = new BasicAuthenticator(workflowServiceUser.get(), - workflowServicePassword.get()); - // register the authenticator - documentClient.registerClientRequestFilter(basicAuth); - } - return documentClient; - } + // DocumentClient initWorkflowClient() throws RestAPIException { + + // logger.finest("...... WORKFLOW_SERVICE_ENDPOINT = " + + // workflowServiceEndpoint); + + // DocumentClient documentClient = new + // DocumentClient(workflowServiceEndpoint.get()); + + // // Test authentication method + // if ("Form".equalsIgnoreCase(workflowServiceAuthMethod.get())) { + // // default basic authenticator + // FormAuthenticator formAuth = new + // FormAuthenticator(workflowServiceEndpoint.get(), workflowServiceUser.get(), + // workflowServicePassword.get()); + // // register the authenticator + // documentClient.registerClientRequestFilter(formAuth); + + // } else { + // // default basic authenticator + // BasicAuthenticator basicAuth = new + // BasicAuthenticator(workflowServiceUser.get(), + // workflowServicePassword.get()); + // // register the authenticator + // documentClient.registerClientRequestFilter(basicAuth); + // } + // return documentClient; + // } } diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/SyncScheduler.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/SyncScheduler.java index 64ca169..dd2d2e4 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/SyncScheduler.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/SyncScheduler.java @@ -106,7 +106,6 @@ public void init() { public void run(Timer timer) { DocumentClient documentClient = null; EventLogClient eventLogClient = null; - // ClientRequestFilter authenticator = null; logger.fine("--- run timeout.... timerInfo= " + timer.getInfo()); try { @@ -183,6 +182,7 @@ public void run(Timer timer) { } catch (NotFoundException | RestAPIException e) { logger.warning("unable to process event log: " + e.getMessage()); // we need to reset the timer and discard the current JSESSIONID + restClientHelper.reset(); timer.cancel(); final TimerConfig timerConfig = new TimerConfig(); timerConfig.setInfo(""); // empty info string indicates no JSESSIONID! diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/SyncService.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/SyncService.java index 914ec38..0452d6b 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/SyncService.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/SyncService.java @@ -85,7 +85,7 @@ public void processEventLog(EventLogClient eventLogClient, DocumentClient docume if (documentClient == null || eventLogClient == null) { // no client object - logger.fine("...no eventLogClient available!"); + logger.warning("...no eventLogClient available!"); return; } @@ -149,7 +149,7 @@ public void processEventLog(EventLogClient eventLogClient, DocumentClient docume public void releaseDeadLocks(EventLogClient eventLogClient) throws RestAPIException { if (eventLogClient == null) { // no client object - logger.fine("...no eventLogClient available!"); + logger.warning("...no eventLogClient available!"); return; } eventLogClient.releaseDeadLocks(deadLockInterval, ImixsArchiveApp.EVENTLOG_TOPIC_ADD, diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/cassandra/DataService.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/cassandra/DataService.java index 88eae91..f3b7b63 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/cassandra/DataService.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/cassandra/DataService.java @@ -15,7 +15,6 @@ import java.util.logging.Logger; import org.imixs.archive.service.ArchiveException; -import org.imixs.archive.service.resync.ResyncService; import org.imixs.workflow.FileData; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.WorkflowKernel; @@ -95,9 +94,6 @@ public class DataService { @Inject ClusterService clusterService; - @Inject - ResyncService schedulerService; - @Inject protected Event events; diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/restore/RestoreService.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/restore/RestoreScheduler.java similarity index 93% rename from imixs-archive-service/src/main/java/org/imixs/archive/service/restore/RestoreService.java rename to imixs-archive-service/src/main/java/org/imixs/archive/service/restore/RestoreScheduler.java index bb79e9a..dad53f2 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/restore/RestoreService.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/restore/RestoreScheduler.java @@ -36,8 +36,9 @@ import org.imixs.archive.service.RemoteAPIService; import org.imixs.archive.service.cassandra.ClusterService; import org.imixs.archive.service.cassandra.DataService; -import org.imixs.archive.service.resync.ResyncService; import org.imixs.archive.service.util.MessageService; +import org.imixs.archive.service.util.RestClientHelper; +import org.imixs.melman.DocumentClient; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.exceptions.QueryException; import org.imixs.workflow.xml.XMLDocumentAdapter; @@ -48,7 +49,11 @@ import com.datastax.driver.core.Session; import jakarta.annotation.Resource; -import jakarta.ejb.Stateless; +import jakarta.annotation.security.DeclareRoles; +import jakarta.annotation.security.RunAs; +import jakarta.ejb.LocalBean; +import jakarta.ejb.Singleton; +import jakarta.ejb.Startup; import jakarta.ejb.Timeout; import jakarta.ejb.Timer; import jakarta.inject.Inject; @@ -80,9 +85,12 @@ * @version 1.0 * @author rsoika */ - -@Stateless -public class RestoreService { +@Startup +@Singleton +@LocalBean +@DeclareRoles({ "org.imixs.ACCESSLEVEL.MANAGERACCESS" }) +@RunAs("org.imixs.ACCESSLEVEL.MANAGERACCESS") +public class RestoreScheduler { public final static String TIMER_ID_RESTORESERVICE = "IMIXS_ARCHIVE_RESTORE_TIMER"; public final static long TIMER_INTERVAL_DURATION = 60000; @@ -97,7 +105,7 @@ public class RestoreService { public final static String MESSAGE_TOPIC = "restore"; - private static Logger logger = Logger.getLogger(RestoreService.class.getName()); + private static Logger logger = Logger.getLogger(RestoreScheduler.class.getName()); @Inject DataService dataService; @@ -114,6 +122,9 @@ public class RestoreService { @Resource jakarta.ejb.TimerService timerService; + @Inject + RestClientHelper restClientHelper; + /** * Starts a new restore process with a EJB TimerService *

@@ -143,7 +154,7 @@ public void start(long restoreFrom, long restoreTo, List options) throws Ar timer = null; } catch (Exception e) { messageService.logMessage(MESSAGE_TOPIC, "Failed to stop existing timer - " + e.getMessage()); - throw new ArchiveException(ResyncService.class.getName(), ArchiveException.INVALID_WORKITEM, + throw new ArchiveException(RestoreScheduler.class.getName(), ArchiveException.INVALID_WORKITEM, " failed to cancle existing timer!"); } } @@ -233,6 +244,7 @@ private void stop(Timer timer) throws ArchiveException { */ @Timeout void onTimeout(jakarta.ejb.Timer timer) throws Exception { + DocumentClient documentClient = null; Session session = null; Cluster cluster = null; ItemCollection metadata = null; @@ -244,6 +256,9 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { long startTime = System.currentTimeMillis(); try { + // init rest clients.... + documentClient = restClientHelper.createDocumentClient(); + // read the metadata metadata = dataService.loadMetadata(); // read last restore stat.... @@ -280,7 +295,8 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { // yes, lets see if this snapshot is already restored or synced? try { remoteSnapshotID = remoteAPIService - .readSnapshotIDByUniqueID(dataService.getUniqueID(latestSnapshot)); + .readSnapshotIDByUniqueID(dataService.getUniqueID(latestSnapshot), + documentClient); } catch (ArchiveException ae) { // expected if not found } @@ -295,7 +311,7 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { snapshot = dataService.loadSnapshot(latestSnapshot); _tmpSize = dataService.calculateSize(XMLDocumentAdapter.getDocument(snapshot)); logger.finest("......size=: " + _tmpSize); - remoteAPIService.restoreSnapshot(snapshot); + remoteAPIService.restoreSnapshot(snapshot, documentClient); restoreSize = restoreSize + _tmpSize; restoreCount++; snapshot = null; @@ -464,7 +480,7 @@ public Timer findTimer() { public List getOptions(ItemCollection metaData) { // convert current list of options into a list of ItemCollection elements ArrayList result = new ArrayList(); - List mapOrderItems = metaData.getItemValue(RestoreService.ITEM_RESTORE_OPTIONS); + List mapOrderItems = metaData.getItemValue(RestoreScheduler.ITEM_RESTORE_OPTIONS); for (Object mapOderItem : mapOrderItems) { if (mapOderItem instanceof Map) { ItemCollection itemCol = new ItemCollection((Map) mapOderItem); @@ -490,7 +506,7 @@ public void setOptions(List options, ItemCollection metaData) { for (ItemCollection orderItem : options) { mapOrderItems.add(orderItem.getAllItems()); } - metaData.replaceItemValue(RestoreService.ITEM_RESTORE_OPTIONS, mapOrderItems); + metaData.replaceItemValue(RestoreScheduler.ITEM_RESTORE_OPTIONS, mapOrderItems); } } diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/resync/ResyncService.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/resync/ResyncService.java index 29ee000..6a0a84d 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/resync/ResyncService.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/resync/ResyncService.java @@ -32,6 +32,8 @@ import org.imixs.archive.service.cassandra.ClusterService; import org.imixs.archive.service.cassandra.DataService; import org.imixs.archive.service.util.MessageService; +import org.imixs.archive.service.util.RestClientHelper; +import org.imixs.melman.DocumentClient; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.exceptions.QueryException; import org.imixs.workflow.xml.XMLDataCollection; @@ -71,7 +73,7 @@ public class ResyncService { public final static String DEFAULT_SCHEDULER_DEFINITION = "hour=*"; public final static String MESSAGE_TOPIC = "sync"; - private final static int MAX_COUNT = 100; + private final static int MAX_COUNT = 500; @Resource jakarta.ejb.TimerService timerService; @@ -91,6 +93,9 @@ public class ResyncService { @Inject ResyncStatusHandler syncStatusHandler; + @Inject + RestClientHelper restClientHelper; + private static Logger logger = Logger.getLogger(ResyncService.class.getName()); /** @@ -204,8 +209,9 @@ private Timer findTimer() { @Timeout void onTimeout(jakarta.ejb.Timer timer) throws Exception { long syncPoint = 0; - int syncupdate = 0; - int syncread = 0; + int syncUpdates = 0; + int syncBlockRead = 0; + int syncTotalRead = 0; long totalCount = 0; long totalSize = 0; ItemCollection metaData = null; @@ -215,7 +221,8 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { long lProfiler = System.currentTimeMillis(); try { - + // init rest clients.... + DocumentClient documentClient = restClientHelper.createDocumentClient(); // load metadata and get last syncpoint metaData = dataService.loadMetadata(); syncPoint = metaData.getItemValueLong(ITEM_SYNCPOINT); @@ -237,12 +244,11 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { while (true) { long lReadTime = System.currentTimeMillis(); long lTotalTime = System.currentTimeMillis(); - XMLDataCollection xmlDataCollection = remoteAPIService.readSyncData(syncPoint); + XMLDataCollection xmlDataCollection = remoteAPIService.readSyncData(syncPoint, documentClient); if (xmlDataCollection != null) { logger.info("...found " + xmlDataCollection.getDocument().length + " snapshots at syncpoint " + new Date(syncPoint) + " in " + (System.currentTimeMillis() - lReadTime) + "ms"); List snapshotList = Arrays.asList(xmlDataCollection.getDocument()); - for (XMLDocument xmlDocument : snapshotList) { long lSyncTime = System.currentTimeMillis(); ItemCollection snapshot = XMLDocumentAdapter.putDocument(xmlDocument); @@ -251,7 +257,6 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { Date syncpointdate = snapshot.getItemValueDate("$modified"); syncPoint = syncpointdate.getTime(); logger.fine("......data found - new syncpoint=" + syncPoint); - // verify if this snapshot is already stored - if so, we do not overwrite // the origin data if (!dataService.existSnapshot(snapshot.getUniqueID())) { @@ -259,7 +264,7 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { try { lastUniqueID = snapshot.getUniqueID(); dataService.saveSnapshot(snapshot); - syncupdate++; + syncUpdates++; totalCount++; totalSize = totalSize + dataService.calculateSize(xmlDocument); } catch (RuntimeException e) { @@ -270,7 +275,6 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { logger.info( "...snapshot '" + snapshot.getUniqueID() + "' written in " + (System.currentTimeMillis() - lSyncTime) + "ms"); - } else { // This is because in case of a restore, the same snapshot takes a new $modified // item. And we do not want to re-import the snapshot in the next sync cycle. @@ -279,17 +283,15 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { "...snapshot '" + snapshot.getUniqueID() + "' already exits - verification took " + (System.currentTimeMillis() - lSyncTime) + "ms"); } - - syncread++; + syncBlockRead++; + syncTotalRead++; // update metadata metaData.setItemValue(ITEM_SYNCPOINT, syncPoint); metaData.setItemValue(ITEM_SYNCCOUNT, totalCount); - metaData.setItemValue(ITEM_SYNCSIZE, totalSize); lastUniqueID = "0"; dataService.saveMetadata(metaData); - logger.info( "...snapshot '" + snapshot.getUniqueID() + "' synchronized in " + (System.currentTimeMillis() - lTotalTime) + "ms"); @@ -300,13 +302,14 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { } // print log message if data was synced - if (syncread > MAX_COUNT) { + if (syncBlockRead >= MAX_COUNT) { messageService.logMessage(MESSAGE_TOPIC, - "... " + syncread + " snapshots verified (" + syncupdate + " updates) in: " - + ((System.currentTimeMillis()) - lProfiler) + " ms, next syncpoint " + "... " + syncTotalRead + " snapshots verified (" + syncUpdates + " updates) in: " + + formatDuration((System.currentTimeMillis()) - lProfiler) + + " , next syncpoint " + new Date(syncPoint)); // reset count - syncread = 0; + syncBlockRead = 0; } if (syncStatusHandler.getStatus() == ResyncStatusHandler.STAUS_CANCELED) { @@ -335,4 +338,26 @@ void onTimeout(jakarta.ejb.Timer timer) throws Exception { } } + private static String formatDuration(long durationInMillis) { + long durationInSeconds = durationInMillis / 1000; + long durationInMinutes = durationInSeconds / 60; + long durationInHours = durationInMinutes / 60; + + String formattedDuration; + + if (durationInHours > 0) { + formattedDuration = String.format("%d hours, %d minutes und %d seconds", + durationInHours, + durationInMinutes % 60, + durationInSeconds % 60); + } else if (durationInMinutes > 0) { + formattedDuration = String.format("%d minutes and %d seconds", + durationInMinutes, + durationInSeconds % 60); + } else { + formattedDuration = String.format("%d seconds", durationInSeconds); + } + + return formattedDuration; + } } diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/InspectController.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/InspectController.java index 8b92bbf..3ebf452 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/InspectController.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/InspectController.java @@ -6,18 +6,21 @@ import java.util.List; import java.util.logging.Logger; -import jakarta.enterprise.context.SessionScoped; -import jakarta.inject.Inject; -import jakarta.inject.Named; - import org.imixs.archive.service.ArchiveException; import org.imixs.archive.service.RemoteAPIService; import org.imixs.archive.service.cassandra.ClusterService; import org.imixs.archive.service.cassandra.DataService; import org.imixs.archive.service.resync.ResyncService; import org.imixs.archive.service.util.MessageService; +import org.imixs.archive.service.util.RestClientHelper; +import org.imixs.melman.DocumentClient; +import org.imixs.melman.RestAPIException; import org.imixs.workflow.ItemCollection; +import jakarta.enterprise.context.SessionScoped; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * CID Bean to inspect a single process instance. *

@@ -45,7 +48,7 @@ public class InspectController implements Serializable { DataService dataService; @Inject - ResyncService syncService; + ResyncService resyncService; @Inject MessageService messageService; @@ -53,6 +56,9 @@ public class InspectController implements Serializable { @Inject RemoteAPIService remoteAPIService; + @Inject + RestClientHelper restClientHelper; + public InspectController() { super(); } @@ -118,14 +124,14 @@ public String getTime(String id) { public void loadSnapshotIDs() { try { logger.finest("......load snapshots for " + uniqueid + "..."); - + DocumentClient documentClient = restClientHelper.createDocumentClient(); // max count 100, reverse order snapshotIDs = dataService.loadSnapshotsByUnqiueID(uniqueid, 100, true); // test the current snapshot from the live system! - setCurrentSnapshotID(remoteAPIService.readSnapshotIDByUniqueID(uniqueid)); + setCurrentSnapshotID(remoteAPIService.readSnapshotIDByUniqueID(uniqueid, documentClient)); - } catch (ArchiveException e) { + } catch (ArchiveException | RestAPIException e) { logger.severe("failed to load snapshot ids: " + e.getMessage()); } } @@ -137,11 +143,12 @@ public void loadSnapshotIDs() { public void restoreSnapshot(String id) { try { logger.info("......restore snapshotID " + uniqueid + "..."); + DocumentClient documentClient = restClientHelper.createDocumentClient(); ItemCollection snapshot = dataService.loadSnapshot(id); - remoteAPIService.restoreSnapshot(snapshot); + remoteAPIService.restoreSnapshot(snapshot, documentClient); // refresh snapshot list.... loadSnapshotIDs(); - } catch (ArchiveException e) { + } catch (ArchiveException | RestAPIException e) { logger.severe("failed to load snapshot ids: " + e.getMessage()); } } diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/RestoreController.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/RestoreController.java index a2bc240..c32a1be 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/RestoreController.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/RestoreController.java @@ -8,21 +8,20 @@ import java.util.List; import java.util.logging.Logger; -import jakarta.annotation.PostConstruct; -import jakarta.ejb.Timer; -import jakarta.enterprise.context.RequestScoped; -import jakarta.enterprise.context.SessionScoped; -import jakarta.inject.Inject; -import jakarta.inject.Named; - import org.imixs.archive.service.ArchiveException; import org.imixs.archive.service.cassandra.ClusterService; import org.imixs.archive.service.cassandra.DataService; -import org.imixs.archive.service.restore.RestoreService; +import org.imixs.archive.service.restore.RestoreScheduler; import org.imixs.archive.service.resync.ResyncService; import org.imixs.archive.service.util.MessageService; import org.imixs.workflow.ItemCollection; +import jakarta.annotation.PostConstruct; +import jakarta.ejb.Timer; +import jakarta.enterprise.context.SessionScoped; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * CID Bean for the resync service. *

@@ -56,7 +55,7 @@ public class RestoreController implements Serializable { DataService dataService; @Inject - RestoreService restoreService; + RestoreScheduler restoreService; @Inject MessageService messageService; @@ -73,7 +72,7 @@ public RestoreController() { void init() { reset(); } - + /** * This method initializes the default sync date * @@ -143,21 +142,21 @@ public void setRestoreTo(String restorePoint) { */ public Date getRestoreSyncPoint() { long lsyncPoint; - lsyncPoint = metaData.getItemValueLong(RestoreService.ITEM_RESTORE_SYNCPOINT); + lsyncPoint = metaData.getItemValueLong(RestoreScheduler.ITEM_RESTORE_SYNCPOINT); Date syncPoint = new Date(lsyncPoint); return syncPoint; } public long getRestoreCount() { - return metaData.getItemValueLong(RestoreService.ITEM_RESTORE_SYNCCOUNT); + return metaData.getItemValueLong(RestoreScheduler.ITEM_RESTORE_SYNCCOUNT); } public long getRestoreErrors() { - return metaData.getItemValueLong(RestoreService.ITEM_RESTORE_SYNCERRORS); + return metaData.getItemValueLong(RestoreScheduler.ITEM_RESTORE_SYNCERRORS); } public String getRestoreSize() { - long l = metaData.getItemValueLong(RestoreService.ITEM_RESTORE_SYNCSIZE); + long l = metaData.getItemValueLong(RestoreScheduler.ITEM_RESTORE_SYNCSIZE); String result = messageService.userFriendlyBytes(l); String[] parts = result.split(" "); restoreSizeUnit = parts[1]; @@ -199,7 +198,7 @@ public void startRestore() { logger.info("......init restore process: " + this.getRestoreFrom() + " to " + this.getRestoreTo()); restoreService.setOptions(options, metaData); restoreService.start(restoreDateFrom, restoreDateTo, - metaData.getItemValue(RestoreService.ITEM_RESTORE_OPTIONS)); + metaData.getItemValue(RestoreScheduler.ITEM_RESTORE_OPTIONS)); } catch (ArchiveException e) { logger.severe("failed to start restore process: " + e.getMessage()); } @@ -213,14 +212,12 @@ public void startRestore() { */ public void stopRestore() { try { - restoreService.cancel(); + restoreService.cancel(); } catch (ArchiveException e) { e.printStackTrace(); } - } - /** * Returns true if a restore is running. * @@ -232,7 +229,7 @@ public boolean isRunning() { } public List getMessages() { - return messageService.getMessages(RestoreService.MESSAGE_TOPIC); + return messageService.getMessages(RestoreScheduler.MESSAGE_TOPIC); } /** diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/ResyncController.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/ResyncController.java index f5fa38a..d74fede 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/ResyncController.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/ui/ResyncController.java @@ -6,11 +6,6 @@ import java.util.Date; import java.util.logging.Logger; -import jakarta.annotation.PostConstruct; -import jakarta.enterprise.context.RequestScoped; -import jakarta.inject.Inject; -import jakarta.inject.Named; - import org.imixs.archive.service.ArchiveException; import org.imixs.archive.service.cassandra.ClusterService; import org.imixs.archive.service.cassandra.DataService; @@ -18,6 +13,11 @@ import org.imixs.archive.service.util.MessageService; import org.imixs.workflow.ItemCollection; +import jakarta.annotation.PostConstruct; +import jakarta.enterprise.context.RequestScoped; +import jakarta.inject.Inject; +import jakarta.inject.Named; + /** * CID Bean for the resync service. *

@@ -122,13 +122,14 @@ public void updateSyncPoint() { } } catch (ArchiveException | ParseException e) { - logger.severe("failed to set new syncpoint: " + e.getMessage()); + logger.severe("failed to set new SyncPoint: " + e.getMessage()); } } - + /** * Returns true if the sync service is actually running + * * @return */ public boolean isRunning() { @@ -149,5 +150,4 @@ public void cancel() { } - } \ No newline at end of file diff --git a/imixs-archive-service/src/main/java/org/imixs/archive/service/util/RestClientHelper.java b/imixs-archive-service/src/main/java/org/imixs/archive/service/util/RestClientHelper.java index 23b890f..a60d037 100644 --- a/imixs-archive-service/src/main/java/org/imixs/archive/service/util/RestClientHelper.java +++ b/imixs-archive-service/src/main/java/org/imixs/archive/service/util/RestClientHelper.java @@ -140,4 +140,12 @@ public EventLogClient createEventLogClient(DocumentClient documentClient) { } } + /** + * This method invalidates the rest clients + */ + public void reset() { + documentClient = null; + eventLogClient = null; + } + } \ No newline at end of file