-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
223 additions
and
248 deletions.
There are no files selected for viewing
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
107 changes: 107 additions & 0 deletions
107
plugins/command-manager/src/main/java/com/wazuh/commandmanager/jobscheduler/PointInTime.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,107 @@ | ||
package com.wazuh.commandmanager.jobscheduler; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.opensearch.action.search.CreatePitRequest; | ||
import org.opensearch.action.search.CreatePitResponse; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.common.unit.TimeValue; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.search.builder.PointInTimeBuilder; | ||
|
||
import javax.swing.*; | ||
import java.sql.Time; | ||
|
||
public class PointInTime { | ||
private static final Logger log = LogManager.getLogger(PointInTime.class); | ||
private static PointInTime INSTANCE; | ||
private String id; | ||
private CreatePitRequest createPitRequest; | ||
private PointInTimeBuilder pointInTimeBuilder; | ||
private CreatePitResponse createPitResponse; | ||
private TimeValue keepAlive = TimeValue.timeValueSeconds(60L); | ||
|
||
public PointInTimeBuilder createPit(Client client, String index) { | ||
Boolean allowPartialPitCreation = false; | ||
setCreatePitRequest( | ||
new CreatePitRequest(getKeepAlive(), allowPartialPitCreation, index) | ||
); | ||
client.createPit( | ||
getCreatePitRequest(), | ||
new ActionListener<>() { | ||
@Override | ||
public void onResponse(CreatePitResponse createPitResponse) { | ||
setCreatePitResponse(createPitResponse); | ||
setId(createPitResponse.getId()); | ||
setPointInTimeBuilder( | ||
new PointInTimeBuilder(createPitResponse.getId()) | ||
); | ||
getPointInTimeBuilder().setKeepAlive(getKeepAlive()); | ||
} | ||
|
||
@Override | ||
public void onFailure(Exception e) { | ||
log.error(e); | ||
} | ||
}); | ||
return getPointInTimeBuilder(); | ||
} | ||
|
||
|
||
public CreatePitResponse getCreatePitResponse() { | ||
return createPitResponse; | ||
} | ||
|
||
public void setCreatePitResponse(CreatePitResponse createPitResponse) { | ||
this.createPitResponse = createPitResponse; | ||
} | ||
|
||
public PointInTimeBuilder getPointInTimeBuilder() { | ||
return pointInTimeBuilder; | ||
} | ||
|
||
public void setPointInTimeBuilder(PointInTimeBuilder pointInTimeBuilder) { | ||
this.pointInTimeBuilder = pointInTimeBuilder; | ||
} | ||
|
||
public PointInTime() { | ||
} | ||
|
||
public CreatePitRequest getCreatePitRequest() { | ||
return createPitRequest; | ||
} | ||
|
||
public void setCreatePitRequest(CreatePitRequest createPitRequest) { | ||
this.createPitRequest = createPitRequest; | ||
} | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public TimeValue getKeepAlive() { | ||
return keepAlive; | ||
} | ||
|
||
public void setKeepAlive(TimeValue keepAlive) { | ||
this.keepAlive = keepAlive; | ||
} | ||
|
||
public static PointInTime getInstance() { | ||
log.info("Getting Job Runner Instance"); | ||
if (INSTANCE != null) { | ||
return INSTANCE; | ||
} | ||
synchronized (SearchJob.class) { | ||
if (INSTANCE != null) { | ||
return INSTANCE; | ||
} | ||
INSTANCE = new PointInTime(); | ||
return INSTANCE; | ||
} | ||
} | ||
} |
Oops, something went wrong.