Skip to content

Commit

Permalink
cleaned up TODOs and changed job scheduler name
Browse files Browse the repository at this point in the history
Signed-off-by: Joanne Wang <[email protected]>
  • Loading branch information
jowg-amazon committed Oct 19, 2023
1 parent 56d4aba commit f72443e
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ public class SecurityAnalyticsPlugin extends Plugin implements ActionPlugin, Map
public static final String CORRELATION_RULES_BASE_URI = PLUGINS_BASE_URI + "/correlation/rules";

public static final String CUSTOM_LOG_TYPE_URI = PLUGINS_BASE_URI + "/logtype";
public static final String JOB_INDEX_NAME = ".scheduler-sap-threatintel-job";
public static final Map<String, Object> INDEX_SETTING = Map.of("index.number_of_shards", 1, "index.auto_expand_replicas", "0-all", "index.hidden", true);
public static final String JOB_INDEX_NAME = ".opensearch-sap-threatintel-job";
public static final Map<String, Object> TIF_JOB_INDEX_SETTING = Map.of("index.number_of_shards", 1, "index.auto_expand_replicas", "0-all", "index.hidden", true);

private CorrelationRuleIndices correlationRuleIndices;

Expand Down Expand Up @@ -210,7 +210,7 @@ public List<RestHandler> getRestHandlers(Settings settings,

@Override
public String getJobType() {
return "scheduler_sap_threatintel_job";
return "opensearch_sap_threatintel_job";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ protected void doExecute(final Task task, final DeleteTIFJobRequest request, fin
return;
}
try {
// TODO: makes every sub-methods as async call to avoid using a thread in generic pool
threadPool.generic().submit(() -> {
try {
deleteTIFJob(request.getName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public class TIFJobParameter implements Writeable, ScheduledJobParameter {
public static final String THREAT_INTEL_DATA_INDEX_NAME_PREFIX = ".opensearch-sap-threatintel";


/**
* String fields for job scheduling parameters used for ParseField
*/
private static final String name_field = "name";
private static final String enabled_field = "update_enabled";
private static final String last_update_time_field = "last_update_time";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void createJobIndexIfNotExists(final StepListener<Void> stepListener) {
return;
}
final CreateIndexRequest createIndexRequest = new CreateIndexRequest(SecurityAnalyticsPlugin.JOB_INDEX_NAME).mapping(getIndexMapping())
.settings(SecurityAnalyticsPlugin.INDEX_SETTING);
.settings(SecurityAnalyticsPlugin.TIF_JOB_INDEX_SETTING);
StashedThreadContext.run(client, () -> client.admin().indices().create(createIndexRequest, new ActionListener<>() {
@Override
public void onResponse(final CreateIndexResponse createIndexResponse) {
Expand Down Expand Up @@ -98,7 +98,7 @@ private String getIndexMapping() {
}
} catch (IOException e) {
log.error("Runtime exception", e);
throw new SecurityAnalyticsException("Runtime exception", RestStatus.INTERNAL_SERVER_ERROR, e); //TODO
throw new SecurityAnalyticsException("Runtime exception", RestStatus.INTERNAL_SERVER_ERROR, e);
}
}

Expand All @@ -119,7 +119,7 @@ public IndexResponse updateJobSchedulerParameter(final TIFJobParameter jobSchedu
.execute()
.actionGet(clusterSettings.get(SecurityAnalyticsSettings.THREAT_INTEL_TIMEOUT));
} catch (IOException e) {
throw new SecurityAnalyticsException("Runtime exception", RestStatus.INTERNAL_SERVER_ERROR, e); //TODO
throw new SecurityAnalyticsException("Runtime exception", RestStatus.INTERNAL_SERVER_ERROR, e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ protected void waitUntilAllShardsStarted(final String indexName, final int timeo
);
} catch (InterruptedException e) {
log.error("runtime exception", e);
throw new SecurityAnalyticsException("Runtime exception", RestStatus.INTERNAL_SERVER_ERROR, e); //TODO
throw new SecurityAnalyticsException("Runtime exception", RestStatus.INTERNAL_SERVER_ERROR, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ public void testCreateDetector_threatIntelEnabled_testJobRunner() throws IOExcep
List<TIFJobParameter> newJobMetaDataList = getJobSchedulerParameter();
assertEquals(1, newJobMetaDataList.size());
TIFJobParameter newJobMetaData = newJobMetaDataList.get(0);
Instant newUpdatedTime = newJobMetaData.getLastUpdateTime();
assertNotEquals(firstUpdatedTime.toString(), newUpdatedTime.toString());
Instant lastUpdatedTime = newJobMetaData.getLastUpdateTime();
assertNotEquals(firstUpdatedTime.toString(), lastUpdatedTime.toString());

// verify new threat intel feed timestamp is different
List<Instant> newFeedTimestamp = getThreatIntelFeedsTime();
Expand Down Expand Up @@ -187,7 +187,7 @@ private List<Instant> getThreatIntelFeedsTime() throws IOException {

private List<TIFJobParameter> getJobSchedulerParameter() throws IOException {
String request = getMatchAllSearchRequestString();
SearchResponse res = executeSearchAndGetResponse(".scheduler-sap-threatintel-job*", request, false);
SearchResponse res = executeSearchAndGetResponse(".opensearch-sap-threatintel-job*", request, false);
return getTIFJobParameterList(res, xContentRegistry()).stream().collect(Collectors.toList());
}
public static List<TIFJobParameter> getTIFJobParameterList(SearchResponse searchResponse, NamedXContentRegistry xContentRegistry) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void testParser_whenAllValueIsFilled_thenSucceed() throws IOException {

}

public void testParser_whenNullForOptionalFields_thenSucceed() throws IOException { // TODO: same issue
public void testParser_whenNullForOptionalFields_thenSucceed() throws IOException {
String id = TestHelpers.randomLowerCaseString();
IntervalSchedule schedule = new IntervalSchedule(Instant.now().truncatedTo(ChronoUnit.MILLIS), 1, ChronoUnit.DAYS);
TIFJobParameter tifJobParameter = new TIFJobParameter(id, schedule);
Expand Down

0 comments on commit f72443e

Please sign in to comment.