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
    Modifier and Type
    Field
    Description
    static final String
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    LockServiceImpl(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 Type
    Method
    Description
    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.
    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.
    void
    deleteLock(String lockId, org.opensearch.core.action.ActionListener<Boolean> listener)
    Attempt to delete lock.
    void
    findLock(String lockId, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener)
     
    boolean
     
    void
    release(org.opensearch.jobscheduler.spi.LockModel lock, org.opensearch.core.action.ActionListener<Boolean> listener)
    Attempt to release the lock.
    void
    renewLock(org.opensearch.jobscheduler.spi.LockModel lock, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener)
    Attempt to renew a lock.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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:
      acquireLock in interface org.opensearch.jobscheduler.spi.utils.LockService
      Parameters:
      jobParameter - a ScheduledJobParameter containing the lock duration.
      context - a JobExecutionContext containing job index name and job id.
      listener - an ActionListener that has onResponse and onFailure that is used to return the lock if it was acquired or else null. Passes IllegalArgumentException to onFailure if the ScheduledJobParameter does not have LockDurationSeconds.
    • 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:
      acquireLockWithId in interface org.opensearch.jobscheduler.spi.utils.LockService
      Parameters:
      jobIndexName - a non-null job index name.
      lockDurationSeconds - the amount of time in seconds that the lock should exist
      lockId - 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 - an ActionListener that has onResponse and onFailure that is used to return the lock if it was acquired or else null. Passes IllegalArgumentException to onFailure if the ScheduledJobParameter does not have LockDurationSeconds.
    • findLock

      public void findLock(String lockId, org.opensearch.core.action.ActionListener<org.opensearch.jobscheduler.spi.LockModel> listener)
      Specified by:
      findLock in interface org.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 to lock.seqNo and lock.primaryTerm not matching with the existing document.
      Specified by:
      release in interface org.opensearch.jobscheduler.spi.utils.LockService
      Parameters:
      lock - a LockModel to be released.
      listener - a ActionListener that has onResponse and onFailure that is used to return whether or not the release was successful
    • deleteLock

      public void deleteLock(String lockId, org.opensearch.core.action.ActionListener<Boolean> listener)
      Attempt to delete lock. This should be called as part of clean up when the job for corresponding lock is deleted.
      Specified by:
      deleteLock in interface org.opensearch.jobscheduler.spi.utils.LockService
      Parameters:
      lockId - a String to be deleted.
      listener - an ActionListener that 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:
      renewLock in interface org.opensearch.jobscheduler.spi.utils.LockService
      Parameters:
      lock - a LockModel to be renewed.
      listener - a ActionListener that has onResponse and onFailure that is used to return the renewed lock if renewal succeed, otherwise return null.