Class LockServiceImpl
java.lang.Object
org.opensearch.jobscheduler.utils.LockServiceImpl
- All Implemented Interfaces:
org.opensearch.jobscheduler.spi.utils.LockService
public class LockServiceImpl
extends Object
implements org.opensearch.jobscheduler.spi.utils.LockService
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionLockServiceImpl(org.opensearch.transport.client.Client client, org.opensearch.cluster.service.ClusterService clusterService) LockServiceImpl(org.opensearch.transport.client.Client client, org.opensearch.cluster.service.ClusterService clusterService, JobHistoryService historyService, Supplier<Boolean> statusHistoryEnabled) -
Method Summary
Modifier and TypeMethodDescriptionvoidacquireLock(org.opensearch.jobscheduler.spi.ScheduledJobParameter jobParameter, org.opensearch.jobscheduler.spi.JobExecutionContext context, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener) Attempts to acquire lock the job.voidacquireLockWithId(String jobIndexName, Long lockDurationSeconds, String lockId, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener) Attempts to acquire a lock with a specific lock Id.voiddeleteLock(String lockId, org.opensearch.core.action.ActionListener<Boolean> listener) Attempt to delete lock.voidfindLock(String lockId, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener) booleanvoidrelease(org.opensearch.jobscheduler.spi.LockModel lock, org.opensearch.core.action.ActionListener<Boolean> listener) Attempt to release the lock.voidrenewLock(org.opensearch.jobscheduler.spi.LockModel lock, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener) Attempt to renew a lock.
-
Field Details
-
LOCK_INDEX_NAME
- See Also:
-
-
Constructor Details
-
LockServiceImpl
public LockServiceImpl(org.opensearch.transport.client.Client client, org.opensearch.cluster.service.ClusterService clusterService, JobHistoryService historyService, Supplier<Boolean> statusHistoryEnabled) -
LockServiceImpl
public LockServiceImpl(org.opensearch.transport.client.Client client, org.opensearch.cluster.service.ClusterService clusterService)
-
-
Method Details
-
lockIndexExist
public boolean lockIndexExist() -
acquireLock
public void acquireLock(org.opensearch.jobscheduler.spi.ScheduledJobParameter jobParameter, org.opensearch.jobscheduler.spi.JobExecutionContext context, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener) Attempts to acquire lock the job. If the lock does not exists it attempts to create the lock document. If the Lock document exists, it will try to update and acquire lock.- Specified by:
acquireLockin interfaceorg.opensearch.jobscheduler.spi.utils.LockService- Parameters:
jobParameter- aScheduledJobParametercontaining the lock duration.context- aJobExecutionContextcontaining job index name and job id.listener- anActionListenerthat has onResponse and onFailure that is used to return the lock if it was acquired or else null. PassesIllegalArgumentExceptionto onFailure if theScheduledJobParameterdoes not haveLockDurationSeconds.
-
acquireLockWithId
public void acquireLockWithId(String jobIndexName, Long lockDurationSeconds, String lockId, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener) Attempts to acquire a lock with a specific lock Id. If the lock does not exist it attempts to create the lock document. If the Lock document exists, it will try to update and acquire the lock.- Specified by:
acquireLockWithIdin interfaceorg.opensearch.jobscheduler.spi.utils.LockService- Parameters:
jobIndexName- a non-null job index name.lockDurationSeconds- the amount of time in seconds that the lock should existlockId- the unique Id for the lock. This should represent the resource that the lock is on, whether it be a job, or some other arbitrary resource. If the lockID matches a jobID, then the lock will be deleted when the job is deleted.listener- anActionListenerthat has onResponse and onFailure that is used to return the lock if it was acquired or else null. PassesIllegalArgumentExceptionto onFailure if theScheduledJobParameterdoes not haveLockDurationSeconds.
-
findLock
public void findLock(String lockId, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener) - Specified by:
findLockin interfaceorg.opensearch.jobscheduler.spi.utils.LockService
-
release
public void release(org.opensearch.jobscheduler.spi.LockModel lock, org.opensearch.core.action.ActionListener<Boolean> listener) Attempt to release the lock. Most failure cases are due tolock.seqNoandlock.primaryTermnot matching with the existing document.- Specified by:
releasein interfaceorg.opensearch.jobscheduler.spi.utils.LockService- Parameters:
lock- aLockModelto be released.listener- aActionListenerthat has onResponse and onFailure that is used to return whether or not the release was successful
-
deleteLock
Attempt to delete lock. This should be called as part of clean up when the job for corresponding lock is deleted.- Specified by:
deleteLockin interfaceorg.opensearch.jobscheduler.spi.utils.LockService- Parameters:
lockId- aStringto be deleted.listener- anActionListenerthat has onResponse and onFailure that is used to return whether or not the delete was successful
-
renewLock
public void renewLock(org.opensearch.jobscheduler.spi.LockModel lock, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener) Attempt to renew a lock. It is used to give an extended valid period to a lock. The start time of the lock will be updated to the current time when the method get called, and the duration of the lock remains. It works as long as the lock is not acquired by others, and no matter if the lock is expired of not.- Specified by:
renewLockin interfaceorg.opensearch.jobscheduler.spi.utils.LockService- Parameters:
lock- aLockModelto be renewed.listener- aActionListenerthat has onResponse and onFailure that is used to return the renewed lock if renewal succeed, otherwise return null.
-