diff --git a/src/main/java/org/opensearch/securityanalytics/SecurityAnalyticsPlugin.java b/src/main/java/org/opensearch/securityanalytics/SecurityAnalyticsPlugin.java index 4c9feae3e..6e67c5798 100644 --- a/src/main/java/org/opensearch/securityanalytics/SecurityAnalyticsPlugin.java +++ b/src/main/java/org/opensearch/securityanalytics/SecurityAnalyticsPlugin.java @@ -204,8 +204,7 @@ public List getRestHandlers(Settings settings, new RestSearchCorrelationRuleAction(), new RestIndexCustomLogTypeAction(), new RestSearchCustomLogTypeAction(), - new RestDeleteCustomLogTypeAction(), - new RestPutTIFJobHandler(clusterSettings) + new RestDeleteCustomLogTypeAction() ); } @@ -321,10 +320,7 @@ public List> 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) ); } diff --git a/src/main/java/org/opensearch/securityanalytics/threatIntel/ThreatIntelFeedDataService.java b/src/main/java/org/opensearch/securityanalytics/threatIntel/ThreatIntelFeedDataService.java index d527088a8..25f9de69d 100644 --- a/src/main/java/org/opensearch/securityanalytics/threatIntel/ThreatIntelFeedDataService.java +++ b/src/main/java/org/opensearch/securityanalytics/threatIntel/ThreatIntelFeedDataService.java @@ -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 INDEX_SETTING_TO_CREATE = Map.of( IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1, @@ -78,12 +76,6 @@ public class ThreatIntelFeedDataService { IndexMetadata.SETTING_INDEX_HIDDEN, true ); - private static final Map 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; @@ -202,7 +194,6 @@ public void parseAndSaveThreatIntelFeedDataCSV( } saveTifds(bulkRequest, timeout); renewLock.run(); - setIndexReadOnly(indexName); } public static boolean isValidIp(String ip) { @@ -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)); - }); - } } diff --git a/src/main/java/org/opensearch/securityanalytics/threatIntel/action/DeleteTIFJobAction.java b/src/main/java/org/opensearch/securityanalytics/threatIntel/action/DeleteTIFJobAction.java deleted file mode 100644 index d0fd0bee4..000000000 --- a/src/main/java/org/opensearch/securityanalytics/threatIntel/action/DeleteTIFJobAction.java +++ /dev/null @@ -1,27 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.securityanalytics.threatIntel.action; - -import org.opensearch.action.ActionType; -import org.opensearch.action.support.master.AcknowledgedResponse; - -/** - * Threat intel tif job delete action - */ -public class DeleteTIFJobAction extends ActionType { - /** - * Delete tif job action instance - */ - public static final DeleteTIFJobAction INSTANCE = new DeleteTIFJobAction(); - /** - * Delete tif job action name - */ - public static final String NAME = "cluster:admin/security_analytics/tifjob/delete"; - - private DeleteTIFJobAction() { - super(NAME, AcknowledgedResponse::new); - } -} diff --git a/src/main/java/org/opensearch/securityanalytics/threatIntel/action/DeleteTIFJobRequest.java b/src/main/java/org/opensearch/securityanalytics/threatIntel/action/DeleteTIFJobRequest.java deleted file mode 100644 index e98cfe586..000000000 --- a/src/main/java/org/opensearch/securityanalytics/threatIntel/action/DeleteTIFJobRequest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.securityanalytics.threatIntel.action; - -import org.opensearch.action.ActionRequest; -import org.opensearch.action.ActionRequestValidationException; -import org.opensearch.core.common.io.stream.StreamInput; -import org.opensearch.core.common.io.stream.StreamOutput; -import org.opensearch.securityanalytics.threatIntel.common.ParameterValidator; - -import java.io.IOException; - -/** - * Threat intel feed job delete request - */ - -public class DeleteTIFJobRequest extends ActionRequest { - private static final ParameterValidator VALIDATOR = new ParameterValidator(); - /** - * @param name the TIF job name - * @return the TIF job name - */ - private String name; - - /** - * Constructor - * - * @param in the stream input - * @throws IOException IOException - */ - public DeleteTIFJobRequest(final StreamInput in) throws IOException { - super(in); - this.name = in.readString(); - } - - public DeleteTIFJobRequest(final String name) { - this.name = name; - } - - @Override - public ActionRequestValidationException validate() { - ActionRequestValidationException errors = null; - if (VALIDATOR.validateTIFJobName(name).isEmpty() == false) { - errors = new ActionRequestValidationException(); - errors.addValidationError("no such job exists"); - } - return errors; - } - - @Override - public void writeTo(final StreamOutput out) throws IOException { - super.writeTo(out); - out.writeString(name); - } - - public String getName() { - return name; - } -} diff --git a/src/main/java/org/opensearch/securityanalytics/threatIntel/action/RestPutTIFJobHandler.java b/src/main/java/org/opensearch/securityanalytics/threatIntel/action/RestPutTIFJobHandler.java deleted file mode 100644 index 641445a57..000000000 --- a/src/main/java/org/opensearch/securityanalytics/threatIntel/action/RestPutTIFJobHandler.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.securityanalytics.threatIntel.action; - -import org.opensearch.client.node.NodeClient; -import org.opensearch.common.settings.ClusterSettings; -import org.opensearch.common.unit.TimeValue; -import org.opensearch.core.xcontent.XContentParser; -import org.opensearch.rest.BaseRestHandler; -import org.opensearch.rest.RestRequest; -import org.opensearch.rest.action.RestToXContentListener; -import org.opensearch.securityanalytics.settings.SecurityAnalyticsSettings; - -import java.io.IOException; -import java.util.List; -import java.util.concurrent.TimeUnit; - -import static org.opensearch.rest.RestRequest.Method.GET; -import static org.opensearch.rest.RestRequest.Method.PUT; - -/** - * Rest handler for threat intel TIFjob creation - * - * This handler handles a request of - * PUT /_plugins/security_analytics/threatintel/tifjob/{id} - * { - * "id": {id}, - * "name": {name}, - * "update_interval_in_days": 1 - * } - * - * When request is received, it will create a TIFjob - * After the creation of TIFjob is completed, it will schedule the next update task after update_interval_in_days. - * - */ -public class RestPutTIFJobHandler extends BaseRestHandler { - private static final String ACTION_NAME = "threatintel_tifjob_put"; - private final ClusterSettings clusterSettings; - - public RestPutTIFJobHandler(final ClusterSettings clusterSettings) { - this.clusterSettings = clusterSettings; - } - - @Override - public String getName() { - return ACTION_NAME; - } - - @Override - protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException { - final PutTIFJobRequest putTIFJobRequest = new PutTIFJobRequest("jobname", - new TimeValue(1, TimeUnit.MINUTES)); - - return channel -> client.executeLocally(PutTIFJobAction.INSTANCE, putTIFJobRequest, new RestToXContentListener<>(channel)); - } - - @Override - public List routes() { - String path = "/_p/_s"; - return List.of(new Route(GET, path)); - } -} diff --git a/src/main/java/org/opensearch/securityanalytics/threatIntel/action/TransportDeleteTIFJobAction.java b/src/main/java/org/opensearch/securityanalytics/threatIntel/action/TransportDeleteTIFJobAction.java deleted file mode 100644 index 3a0c68f10..000000000 --- a/src/main/java/org/opensearch/securityanalytics/threatIntel/action/TransportDeleteTIFJobAction.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.securityanalytics.threatIntel.action; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.opensearch.OpenSearchStatusException; -import org.opensearch.ResourceNotFoundException; -import org.opensearch.action.support.ActionFilters; -import org.opensearch.action.support.HandledTransportAction; -import org.opensearch.action.support.master.AcknowledgedResponse; -import org.opensearch.common.inject.Inject; -import org.opensearch.core.action.ActionListener; -import org.opensearch.core.rest.RestStatus; -import org.opensearch.ingest.IngestService; -import org.opensearch.securityanalytics.threatIntel.ThreatIntelFeedDataService; -import org.opensearch.securityanalytics.threatIntel.common.TIFJobState; -import org.opensearch.securityanalytics.threatIntel.common.TIFLockService; -import org.opensearch.securityanalytics.threatIntel.jobscheduler.TIFJobParameter; -import org.opensearch.securityanalytics.threatIntel.jobscheduler.TIFJobParameterService; -import org.opensearch.tasks.Task; -import org.opensearch.threadpool.ThreadPool; -import org.opensearch.transport.TransportService; - -import java.io.IOException; - -/** - * Transport action to delete tif job - */ -public class TransportDeleteTIFJobAction extends HandledTransportAction { - private static final Logger log = LogManager.getLogger(TransportDeleteTIFJobAction.class); - - private static final long LOCK_DURATION_IN_SECONDS = 300l; - private final TIFLockService lockService; - private final IngestService ingestService; - private final TIFJobParameterService tifJobParameterService; - private final ThreatIntelFeedDataService threatIntelFeedDataService; - private final ThreadPool threadPool; - - /** - * Constructor - * @param transportService the transport service - * @param actionFilters the action filters - * @param lockService the lock service - * @param ingestService the ingest service - * @param tifJobParameterService the tif job parameter service facade - */ - @Inject - public TransportDeleteTIFJobAction( - final TransportService transportService, - final ActionFilters actionFilters, - final TIFLockService lockService, - final IngestService ingestService, - final TIFJobParameterService tifJobParameterService, - final ThreatIntelFeedDataService threatIntelFeedDataService, - final ThreadPool threadPool - ) { - super(DeleteTIFJobAction.NAME, transportService, actionFilters, DeleteTIFJobRequest::new); - this.lockService = lockService; - this.ingestService = ingestService; - this.tifJobParameterService = tifJobParameterService; - this.threatIntelFeedDataService = threatIntelFeedDataService; - this.threadPool = threadPool; - } - - /** - * We delete TIF job regardless of its state as long as we can acquire a lock - * - * @param task the task - * @param request the request - * @param listener the listener - */ - @Override - protected void doExecute(final Task task, final DeleteTIFJobRequest request, final ActionListener listener) { - lockService.acquireLock(request.getName(), LOCK_DURATION_IN_SECONDS, ActionListener.wrap(lock -> { - if (lock == null) { - listener.onFailure( - new OpenSearchStatusException("Another processor is holding a lock on the resource. Try again later", RestStatus.BAD_REQUEST) - ); - log.error("Another processor is holding lock, BAD_REQUEST exception", RestStatus.BAD_REQUEST); - - return; - } - try { - threadPool.generic().submit(() -> { - try { - deleteTIFJob(request.getName()); - lockService.releaseLock(lock); - listener.onResponse(new AcknowledgedResponse(true)); - } catch (Exception e) { - lockService.releaseLock(lock); - listener.onFailure(e); - log.error("delete tif job failed",e); - } - }); - } catch (Exception e) { - lockService.releaseLock(lock); - listener.onFailure(e); - log.error("Internal server error", e); - } - }, exception -> { listener.onFailure(exception); })); - } - - protected void deleteTIFJob(final String tifJobName) throws IOException { - TIFJobParameter tifJobParameter = tifJobParameterService.getJobParameter(tifJobName); - if (tifJobParameter == null) { - throw new ResourceNotFoundException("no such tifJobParameter exist"); - } - TIFJobState previousState = tifJobParameter.getState(); - tifJobParameter.setState(TIFJobState.DELETING); - tifJobParameterService.updateJobSchedulerParameter(tifJobParameter); - - try { - threatIntelFeedDataService.deleteThreatIntelDataIndex(tifJobParameter.getIndices()); - } catch (Exception e) { - if (previousState.equals(tifJobParameter.getState()) == false) { - tifJobParameter.setState(previousState); - tifJobParameterService.updateJobSchedulerParameter(tifJobParameter); - } - throw e; - } - tifJobParameterService.deleteTIFJobParameter(tifJobParameter); - } -} diff --git a/src/main/java/org/opensearch/securityanalytics/threatIntel/jobscheduler/TIFJobParameterService.java b/src/main/java/org/opensearch/securityanalytics/threatIntel/jobscheduler/TIFJobParameterService.java index b977cb4ba..640b3874b 100644 --- a/src/main/java/org/opensearch/securityanalytics/threatIntel/jobscheduler/TIFJobParameterService.java +++ b/src/main/java/org/opensearch/securityanalytics/threatIntel/jobscheduler/TIFJobParameterService.java @@ -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()); - } - } } diff --git a/src/test/java/org/opensearch/securityanalytics/threatIntel/action/DeleteTIFJobRequestTests.java b/src/test/java/org/opensearch/securityanalytics/threatIntel/action/DeleteTIFJobRequestTests.java deleted file mode 100644 index 2ecd7369b..000000000 --- a/src/test/java/org/opensearch/securityanalytics/threatIntel/action/DeleteTIFJobRequestTests.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.securityanalytics.threatIntel.action; - -import org.opensearch.action.ActionRequestValidationException; -import org.opensearch.common.io.stream.BytesStreamOutput; -import org.opensearch.core.common.io.stream.BytesStreamInput; -import org.opensearch.securityanalytics.TestHelpers; -import org.opensearch.securityanalytics.threatIntel.ThreatIntelTestCase; - -import java.io.IOException; - -public class DeleteTIFJobRequestTests extends ThreatIntelTestCase { - - public void testStreamInOut_whenValidInput_thenSucceed() throws IOException { - String tifJobParameterName = TestHelpers.randomLowerCaseString(); - DeleteTIFJobRequest request = new DeleteTIFJobRequest(tifJobParameterName); - - // Run - BytesStreamOutput output = new BytesStreamOutput(); - request.writeTo(output); - BytesStreamInput input = new BytesStreamInput(output.bytes().toBytesRef().bytes); - DeleteTIFJobRequest copiedRequest = new DeleteTIFJobRequest(input); - - // Verify - assertEquals(request.getName(), copiedRequest.getName()); - } - - public void testValidate_whenNull_thenError() { - DeleteTIFJobRequest request = new DeleteTIFJobRequest((String) null); - - // Run - ActionRequestValidationException error = request.validate(); - - // Verify - assertNotNull(error.validationErrors()); - assertFalse(error.validationErrors().isEmpty()); - } - - public void testValidate_whenBlank_thenError() { - DeleteTIFJobRequest request = new DeleteTIFJobRequest(" "); - - // Run - ActionRequestValidationException error = request.validate(); - - // Verify - assertNotNull(error.validationErrors()); - assertFalse(error.validationErrors().isEmpty()); - } - - public void testValidate_whenInvalidTIFJobParameterName_thenFails() { - String invalidName = "_" + TestHelpers.randomLowerCaseString(); - DeleteTIFJobRequest request = new DeleteTIFJobRequest(invalidName); - - // Run - ActionRequestValidationException exception = request.validate(); - - // Verify - assertEquals(1, exception.validationErrors().size()); - assertTrue(exception.validationErrors().get(0).contains("no such job exists")); - } -} diff --git a/src/test/java/org/opensearch/securityanalytics/threatIntel/action/TransportDeleteTIFJobActionTests.java b/src/test/java/org/opensearch/securityanalytics/threatIntel/action/TransportDeleteTIFJobActionTests.java deleted file mode 100644 index 7d15d7710..000000000 --- a/src/test/java/org/opensearch/securityanalytics/threatIntel/action/TransportDeleteTIFJobActionTests.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.opensearch.securityanalytics.threatIntel.action; - -import org.junit.Before; -import org.mockito.ArgumentCaptor; -import org.mockito.InOrder; -import org.mockito.Mockito; -import org.opensearch.OpenSearchException; -import org.opensearch.ResourceNotFoundException; -import org.opensearch.action.support.master.AcknowledgedResponse; -import org.opensearch.core.action.ActionListener; -import org.opensearch.jobscheduler.spi.LockModel; -import org.opensearch.securityanalytics.threatIntel.ThreatIntelTestCase; -import org.opensearch.securityanalytics.threatIntel.common.TIFJobState; -import org.opensearch.securityanalytics.threatIntel.jobscheduler.TIFJobParameter; -import org.opensearch.tasks.Task; -import org.opensearch.securityanalytics.TestHelpers; - - -import java.io.IOException; -import java.time.Instant; - -import static org.mockito.ArgumentMatchers.*; -import static org.mockito.Mockito.*; - -public class TransportDeleteTIFJobActionTests extends ThreatIntelTestCase { - private TransportDeleteTIFJobAction action; - - @Before - public void init() { - action = new TransportDeleteTIFJobAction( - transportService, - actionFilters, - tifLockService, - ingestService, - tifJobParameterService, - threatIntelFeedDataService, - threadPool - ); - } - - public void testDoExecute_whenFailedToAcquireLock_thenError() throws IOException { - validateDoExecute(null, null); - } - - public void testDoExecute_whenValidInput_thenSucceed() throws IOException { - String jobIndexName = TestHelpers.randomLowerCaseString(); - String jobId = TestHelpers.randomLowerCaseString(); - LockModel lockModel = new LockModel(jobIndexName, jobId, Instant.now(), randomPositiveLong(), false); - validateDoExecute(lockModel, null); - } - - public void testDoExecute_whenException_thenError() throws IOException { - validateDoExecute(null, new RuntimeException()); - } - - private void validateDoExecute(final LockModel lockModel, final Exception exception) throws IOException { - Task task = mock(Task.class); - TIFJobParameter tifJobParameter = randomTifJobParameter(); - when(tifJobParameterService.getJobParameter(tifJobParameter.getName())).thenReturn(tifJobParameter); - DeleteTIFJobRequest request = new DeleteTIFJobRequest(tifJobParameter.getName()); - ActionListener listener = mock(ActionListener.class); - - // Run - action.doExecute(task, request, listener); - - // Verify - ArgumentCaptor> captor = ArgumentCaptor.forClass(ActionListener.class); - verify(tifLockService).acquireLock(eq(tifJobParameter.getName()), anyLong(), captor.capture()); - - if (exception == null) { - // Run - captor.getValue().onResponse(lockModel); - - // Verify - if (lockModel == null) { - verify(listener).onFailure(any(OpenSearchException.class)); - } else { - verify(listener).onResponse(new AcknowledgedResponse(true)); - verify(tifLockService).releaseLock(eq(lockModel)); - } - } else { - // Run - captor.getValue().onFailure(exception); - // Verify - verify(listener).onFailure(exception); - } - } - - public void testDeleteTIFJobParameter_whenNull_thenThrowException() { - TIFJobParameter tifJobParameter = randomTifJobParameter(); - expectThrows(ResourceNotFoundException.class, () -> action.deleteTIFJob(tifJobParameter.getName())); - } - - public void testDeleteTIFJobParameter_whenSafeToDelete_thenDelete() throws IOException { - TIFJobParameter tifJobParameter = randomTifJobParameter(); - when(tifJobParameterService.getJobParameter(tifJobParameter.getName())).thenReturn(tifJobParameter); - - // Run - action.deleteTIFJob(tifJobParameter.getName()); - - // Verify - assertEquals(TIFJobState.DELETING, tifJobParameter.getState()); - verify(tifJobParameterService).updateJobSchedulerParameter(tifJobParameter); - InOrder inOrder = Mockito.inOrder(threatIntelFeedDataService, tifJobParameterService); - inOrder.verify(threatIntelFeedDataService).deleteThreatIntelDataIndex(tifJobParameter.getIndices()); - inOrder.verify(tifJobParameterService).deleteTIFJobParameter(tifJobParameter); - } - - public void testDeleteTIFJobParameter_whenDeleteFailsAfterStateIsChanged_thenRevertState() throws IOException { - TIFJobParameter tifJobParameter = randomTifJobParameter(); - tifJobParameter.setState(TIFJobState.AVAILABLE); - when(tifJobParameterService.getJobParameter(tifJobParameter.getName())).thenReturn(tifJobParameter); - doThrow(new RuntimeException()).when(threatIntelFeedDataService).deleteThreatIntelDataIndex(tifJobParameter.getIndices()); - - // Run - expectThrows(RuntimeException.class, () -> action.deleteTIFJob(tifJobParameter.getName())); - - // Verify - verify(tifJobParameterService, times(2)).updateJobSchedulerParameter(tifJobParameter); - assertEquals(TIFJobState.AVAILABLE, tifJobParameter.getState()); - } -} diff --git a/src/test/java/org/opensearch/securityanalytics/threatIntel/jobscheduler/TIFJobParameterServiceTests.java b/src/test/java/org/opensearch/securityanalytics/threatIntel/jobscheduler/TIFJobParameterServiceTests.java index 35fd2450d..6e3b83a78 100644 --- a/src/test/java/org/opensearch/securityanalytics/threatIntel/jobscheduler/TIFJobParameterServiceTests.java +++ b/src/test/java/org/opensearch/securityanalytics/threatIntel/jobscheduler/TIFJobParameterServiceTests.java @@ -185,38 +185,6 @@ private TIFJobParameter setupClientForGetRequest(final boolean isExist, final Ru return tifJobParameter; } - public void testDeleteTifJobParameter_whenValidInput_thenSucceed() { - TIFJobParameter tifJobParameter = randomTifJobParameter(); - verifyingClient.setExecuteVerifier((actionResponse, actionRequest) -> { - // Verify - assertTrue(actionRequest instanceof DeleteRequest); - DeleteRequest request = (DeleteRequest) actionRequest; - assertEquals(SecurityAnalyticsPlugin.JOB_INDEX_NAME, request.index()); - assertEquals(DocWriteRequest.OpType.DELETE, request.opType()); - assertEquals(tifJobParameter.getName(), request.id()); - assertEquals(WriteRequest.RefreshPolicy.IMMEDIATE, request.getRefreshPolicy()); - - DeleteResponse response = mock(DeleteResponse.class); - when(response.status()).thenReturn(RestStatus.OK); - return response; - }); - - // Run - tifJobParameterService.deleteTIFJobParameter(tifJobParameter); - } - - public void testDeleteTifJobParameter_whenIndexNotFound_thenThrowException() { - TIFJobParameter tifJobParameter = randomTifJobParameter(); - verifyingClient.setExecuteVerifier((actionResponse, actionRequest) -> { - DeleteResponse response = mock(DeleteResponse.class); - when(response.status()).thenReturn(RestStatus.NOT_FOUND); - return response; - }); - - // Run - expectThrows(ResourceNotFoundException.class, () -> tifJobParameterService.deleteTIFJobParameter(tifJobParameter)); - } - private GetResponse getMockedGetResponse(TIFJobParameter tifJobParameter) { GetResponse response = mock(GetResponse.class); when(response.isExists()).thenReturn(tifJobParameter != null);