-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4150 from Coduz/feat-jobInstanceDataJobEndCallback
✨ [Job Engine] Added JobDataCleanupJobEndCallback to delete JobInstanceData after JobExecution has ended
- Loading branch information
Showing
8 changed files
with
641 additions
and
496 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
.../org/eclipse/kapua/job/engine/jbatch/overrides/callback/JobDataCleanupJobEndCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024, 2024 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.job.engine.jbatch.overrides.callback; | ||
|
||
import com.ibm.jbatch.container.callback.JobEndCallback; | ||
import com.ibm.jbatch.container.servicesmanager.ServicesManager; | ||
import com.ibm.jbatch.container.servicesmanager.ServicesManagerImpl; | ||
import org.eclipse.kapua.job.engine.jbatch.driver.JbatchDriver; | ||
import org.eclipse.kapua.job.engine.jbatch.persistence.JPAPersistenceManagerImpl; | ||
import org.eclipse.kapua.job.engine.jbatch.persistence.jpa.JpaJobInstanceData; | ||
import org.eclipse.kapua.model.id.KapuaId; | ||
import org.eclipse.kapua.service.job.Job; | ||
import org.eclipse.kapua.service.job.execution.JobExecution; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
/** | ||
* {@link JpaJobInstanceData} cleanup {@link JobEndCallback}. | ||
* <p> | ||
* This {@link JobEndCallback} removes {@link JpaJobInstanceData} after the {@link JobExecution} ends it execution. | ||
* This is done to avoid that {@link Job}s that run a lot of times (thousands or more) fill up the {@link JpaJobInstanceData} | ||
* table making {@link JbatchDriver#isRunningJob(KapuaId, KapuaId)} tanking a lot of time to execute. | ||
* <p> | ||
* {@link JpaJobInstanceData} aren't required nor useful once the {@link JobExecution} ends its processing so they can be safely deleted. | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
public class JobDataCleanupJobEndCallback implements JobEndCallback { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(JobDataCleanupJobEndCallback.class); | ||
|
||
private final JPAPersistenceManagerImpl persistenceService; | ||
private long jobExecutionId; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
public JobDataCleanupJobEndCallback() { | ||
ServicesManager servicesManager = ServicesManagerImpl.getInstance(); | ||
persistenceService = (JPAPersistenceManagerImpl) servicesManager.getPersistenceManagerService(); | ||
} | ||
|
||
@Override | ||
public void setExecutionId(long jobExecutionId) { | ||
this.jobExecutionId = jobExecutionId; | ||
} | ||
|
||
@Override | ||
public void done(long jobExecutionId) { | ||
try { | ||
long jobInstanceId = persistenceService.getJobInstanceIdByExecutionId(jobExecutionId); | ||
|
||
LOG.info("Deleting JobInstanceData {} after JobExecution {} has completed...", jobInstanceId, jobExecutionId); | ||
persistenceService.deleteJobInstanceData(jobInstanceId); | ||
LOG.info("Deleting JobInstanceData {} after JobExecution {} has completed... DONE!", jobInstanceId, jobExecutionId); | ||
} | ||
catch (Exception e) { | ||
LOG.error("Deleting JobInstanceData for JobExecution {} has completed... ERROR! This will leave JobInstanceData in the DB until the Job gets deleted", jobExecutionId, e); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...rg/eclipse/kapua/job/engine/jbatch/overrides/callback/KapuaJobEndCallbackManagerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2024, 2024 Eurotech and/or its affiliates and others | ||
* | ||
* This program and the accompanying materials are made | ||
* available under the terms of the Eclipse Public License 2.0 | ||
* which is available at https://www.eclipse.org/legal/epl-2.0/ | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Contributors: | ||
* Eurotech - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.kapua.job.engine.jbatch.overrides.callback; | ||
|
||
import com.ibm.jbatch.container.callback.IJobEndCallbackService; | ||
import com.ibm.jbatch.container.callback.JobEndCallback; | ||
import com.ibm.jbatch.container.callback.JobEndCallbackManagerImpl; | ||
|
||
/** | ||
* Kapua {@link IJobEndCallbackService} which extends default {@link JobEndCallbackManagerImpl} to register custom {@link JobEndCallback}s | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
public class KapuaJobEndCallbackManagerImpl extends JobEndCallbackManagerImpl implements IJobEndCallbackService { | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @since 2.1.0 | ||
*/ | ||
public KapuaJobEndCallbackManagerImpl() { | ||
super(); | ||
|
||
// Required to delete JobInstanceData after JobExecution ends | ||
registerJobEndCallback(new JobDataCleanupJobEndCallback()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
job-engine/jbatch/src/main/resources/META-INF/services/batch-services.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
J2SE_MODE=true | ||
JOBXML_LOADER_SERVICE=com.ibm.jbatch.container.services.impl.DirectoryJobXMLLoaderServiceImpl | ||
CONTAINER_ARTIFACT_FACTORY_SERVICE=org.eclipse.kapua.job.engine.jbatch.KapuaDelegatingBatchArtifactFactoryImpl | ||
# com.ibm.jbatch.container.services.impl.DelegatingBatchArtifactFactoryImpl | ||
CALLBACK_SERVICE=org.eclipse.kapua.job.engine.jbatch.overrides.callback.KapuaJobEndCallbackManagerImpl | ||
BATCH_THREADPOOL_SERVICE=com.ibm.jbatch.container.services.impl.GrowableThreadPoolServiceImpl | ||
PERSISTENCE_MANAGEMENT_SERVICE=org.eclipse.kapua.job.engine.jbatch.persistence.JPAPersistenceManagerImpl |
Oops, something went wrong.