Skip to content

Commit

Permalink
removed delete job scheduler code and cleaned up (#678)
Browse files Browse the repository at this point in the history
Signed-off-by: Joanne Wang <[email protected]>
  • Loading branch information
jowg-amazon authored Oct 20, 2023
1 parent 74a7440 commit 4dd4190
Show file tree
Hide file tree
Showing 10 changed files with 2 additions and 562 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ public List<RestHandler> getRestHandlers(Settings settings,
new RestSearchCorrelationRuleAction(),
new RestIndexCustomLogTypeAction(),
new RestSearchCustomLogTypeAction(),
new RestDeleteCustomLogTypeAction(),
new RestPutTIFJobHandler(clusterSettings)
new RestDeleteCustomLogTypeAction()
);
}

Expand Down Expand Up @@ -321,10 +320,7 @@ public List<Setting<?>> getSettings() {
new ActionHandler<>(IndexCustomLogTypeAction.INSTANCE, TransportIndexCustomLogTypeAction.class),
new ActionHandler<>(SearchCustomLogTypeAction.INSTANCE, TransportSearchCustomLogTypeAction.class),
new ActionHandler<>(DeleteCustomLogTypeAction.INSTANCE, TransportDeleteCustomLogTypeAction.class),

new ActionHandler<>(PutTIFJobAction.INSTANCE, TransportPutTIFJobAction.class),
new ActionHandler<>(DeleteTIFJobAction.INSTANCE, TransportDeleteTIFJobAction.class)

new ActionHandler<>(PutTIFJobAction.INSTANCE, TransportPutTIFJobAction.class)
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ public class ThreatIntelFeedDataService {
private final Client client;
private final IndexNameExpressionResolver indexNameExpressionResolver;
public static final String SETTING_INDEX_REFRESH_INTERVAL = "index.refresh_interval";
public static final String SETTING_INDEX_BLOCKS_WRITE = "index.blocks.write";

private static final Map<String, Object> INDEX_SETTING_TO_CREATE = Map.of(
IndexMetadata.SETTING_NUMBER_OF_SHARDS,
1,
Expand All @@ -78,12 +76,6 @@ public class ThreatIntelFeedDataService {
IndexMetadata.SETTING_INDEX_HIDDEN,
true
);
private static final Map<String, Object> INDEX_SETTING_TO_FREEZE = Map.of(
IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS,
"0-all",
SETTING_INDEX_BLOCKS_WRITE,
true
);
private final ClusterService clusterService;
private final ClusterSettings clusterSettings;
private final NamedXContentRegistry xContentRegistry;
Expand Down Expand Up @@ -202,7 +194,6 @@ public void parseAndSaveThreatIntelFeedDataCSV(
}
saveTifds(bulkRequest, timeout);
renewLock.run();
setIndexReadOnly(indexName);
}

public static boolean isValidIp(String ip) {
Expand Down Expand Up @@ -280,23 +271,4 @@ private String getIndexMapping() {
throw new SecurityAnalyticsException("Runtime exception when getting the threat intel index mapping", RestStatus.INTERNAL_SERVER_ERROR, e);
}
}

/**
* Sets the TIFData index as read only to prevent further writing to it
* When index needs to be updated, all TIFData indices will be deleted then repopulated
* @param indexName
*/
private void setIndexReadOnly(final String indexName) {
TimeValue timeout = clusterSettings.get(SecurityAnalyticsSettings.THREAT_INTEL_TIMEOUT);
StashedThreadContext.run(client, () -> {
client.admin().indices().prepareForceMerge(indexName).setMaxNumSegments(1).execute().actionGet(timeout);
client.admin().indices().prepareRefresh(indexName).execute().actionGet(timeout);
client.admin()
.indices()
.prepareUpdateSettings(indexName)
.setSettings(INDEX_SETTING_TO_FREEZE)
.execute()
.actionGet(clusterSettings.get(SecurityAnalyticsSettings.THREAT_INTEL_TIMEOUT));
});
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -173,27 +173,4 @@ public void saveTIFJobParameter(final TIFJobParameter tifJobParameter, final Act
}
});
}

/**
* Delete tifJobParameter in an index {@code TIFJobExtension.JOB_INDEX_NAME}
*
* @param tifJobParameter the tifJobParameter
*
*/
public void deleteTIFJobParameter(final TIFJobParameter tifJobParameter) {
DeleteResponse response = client.prepareDelete()
.setIndex(SecurityAnalyticsPlugin.JOB_INDEX_NAME)
.setId(tifJobParameter.getName())
.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE)
.execute()
.actionGet(clusterSettings.get(SecurityAnalyticsSettings.THREAT_INTEL_TIMEOUT));

if (response.status().equals(RestStatus.OK)) {
log.info("deleted tifJobParameter[{}] successfully", tifJobParameter.getName());
} else if (response.status().equals(RestStatus.NOT_FOUND)) {
throw new ResourceNotFoundException("tifJobParameter[{}] does not exist", tifJobParameter.getName());
} else {
throw new OpenSearchException("failed to delete tifJobParameter[{}] with status[{}]", tifJobParameter.getName(), response.status());
}
}
}
Loading

0 comments on commit 4dd4190

Please sign in to comment.