use of org.opensearch.transport.TransportService in project anomaly-detection by opensearch-project.
the class DeleteModelTransportActionTests method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
ThreadPool threadPool = mock(ThreadPool.class);
ClusterService clusterService = mock(ClusterService.class);
localNodeID = "foo";
when(clusterService.localNode()).thenReturn(new DiscoveryNode(localNodeID, buildNewFakeTransportAddress(), Version.CURRENT));
when(clusterService.getClusterName()).thenReturn(new ClusterName("test"));
TransportService transportService = mock(TransportService.class);
ActionFilters actionFilters = mock(ActionFilters.class);
NodeStateManager nodeStateManager = mock(NodeStateManager.class);
ModelManager modelManager = mock(ModelManager.class);
FeatureManager featureManager = mock(FeatureManager.class);
CacheProvider cacheProvider = mock(CacheProvider.class);
EntityCache entityCache = mock(EntityCache.class);
when(cacheProvider.get()).thenReturn(entityCache);
ADTaskCacheManager adTaskCacheManager = mock(ADTaskCacheManager.class);
NodeStateManager stateManager = mock(NodeStateManager.class);
action = new DeleteModelTransportAction(threadPool, clusterService, transportService, actionFilters, nodeStateManager, modelManager, featureManager, cacheProvider, adTaskCacheManager);
}
use of org.opensearch.transport.TransportService in project anomaly-detection by opensearch-project.
the class DeleteTests method setUp.
@Override
@Before
public void setUp() throws Exception {
super.setUp();
node1 = "node1";
node2 = "node2";
nodename1 = "nodename1";
nodename2 = "nodename2";
DiscoveryNode discoveryNode1 = new DiscoveryNode(nodename1, node1, new TransportAddress(TransportAddress.META_ADDRESS, 9300), emptyMap(), emptySet(), Version.CURRENT);
DiscoveryNode discoveryNode2 = new DiscoveryNode(nodename2, node2, new TransportAddress(TransportAddress.META_ADDRESS, 9301), emptyMap(), emptySet(), Version.CURRENT);
List<DiscoveryNode> discoveryNodes = new ArrayList<DiscoveryNode>(2);
discoveryNodes.add(discoveryNode1);
discoveryNodes.add(discoveryNode2);
DeleteModelNodeResponse nodeResponse1 = new DeleteModelNodeResponse(discoveryNode1);
DeleteModelNodeResponse nodeResponse2 = new DeleteModelNodeResponse(discoveryNode2);
deleteModelResponse = new ArrayList<>();
deleteModelResponse.add(nodeResponse1);
deleteModelResponse.add(nodeResponse2);
failures = new ArrayList<>();
failures.add(new FailedNodeException("node3", "blah", new OpenSearchException("foo")));
response = new DeleteModelResponse(new ClusterName("Cluster"), deleteModelResponse, failures);
clusterService = mock(ClusterService.class);
when(clusterService.localNode()).thenReturn(discoveryNode1);
when(clusterService.state()).thenReturn(ClusterCreation.state(new ClusterName("test"), discoveryNode2, discoveryNode1, discoveryNodes));
transportService = mock(TransportService.class);
threadPool = mock(ThreadPool.class);
actionFilters = mock(ActionFilters.class);
Settings settings = Settings.builder().put("plugins.anomaly_detection.request_timeout", TimeValue.timeValueSeconds(10)).build();
task = mock(Task.class);
when(task.getId()).thenReturn(1000L);
client = mock(Client.class);
when(client.settings()).thenReturn(settings);
when(client.threadPool()).thenReturn(threadPool);
}
use of org.opensearch.transport.TransportService in project anomaly-detection by opensearch-project.
the class GetAnomalyDetectorTests method setUp.
@Override
public void setUp() throws Exception {
super.setUp();
ClusterService clusterService = mock(ClusterService.class);
ClusterSettings clusterSettings = new ClusterSettings(Settings.EMPTY, Collections.unmodifiableSet(new HashSet<>(Arrays.asList(AnomalyDetectorSettings.FILTER_BY_BACKEND_ROLES))));
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
transportService = new TransportService(Settings.EMPTY, mock(Transport.class), null, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null, Collections.emptySet());
nodeFilter = mock(DiscoveryNodeFilterer.class);
actionFilters = mock(ActionFilters.class);
client = mock(Client.class);
when(client.threadPool()).thenReturn(threadPool);
adTaskManager = mock(ADTaskManager.class);
action = new GetAnomalyDetectorTransportAction(transportService, nodeFilter, actionFilters, clusterService, client, Settings.EMPTY, xContentRegistry(), adTaskManager);
entity = Entity.createSingleAttributeEntity(categoryField, entityValue);
}
use of org.opensearch.transport.TransportService in project asynchronous-search by opensearch-project.
the class AsynchronousSearchManagementServiceTests method testSchedulesResponseCleanupAtRefreshIntervals.
public void testSchedulesResponseCleanupAtRefreshIntervals() {
long refreshInterval = randomLongBetween(60000, 120000);
final Settings settings = Settings.builder().put(AsynchronousSearchManagementService.PERSISTED_RESPONSE_CLEAN_UP_INTERVAL_SETTING.getKey(), refreshInterval + "ms").build();
DiscoveryNode localNode = new DiscoveryNode("local-node", buildNewFakeTransportAddress(), Collections.singletonMap("asynchronous_search_enabled", "true"), Sets.newHashSet(DiscoveryNodeRole.DATA_ROLE), Version.CURRENT);
ClusterService mockClusterService = ClusterServiceUtils.createClusterService(deterministicTaskQueue.getThreadPool(), localNode);
final MockTransport mockTransport = new MockTransport() {
@Override
protected void onSendRequest(long requestId, String action, TransportRequest request, DiscoveryNode node) {
final boolean successResponse = randomBoolean();
if (successResponse) {
handleResponse(requestId, new AcknowledgedResponse(true));
} else {
handleRemoteError(requestId, new OpenSearchException("simulated error"));
}
}
};
final TransportService transportService = mockTransport.createTransportService(settings, deterministicTaskQueue.getThreadPool(), NOOP_TRANSPORT_INTERCEPTOR, boundTransportAddress -> new DiscoveryNode("local-node", buildNewFakeTransportAddress(), Version.CURRENT), null, emptySet());
transportService.start();
transportService.acceptIncomingRequests();
AsynchronousSearchManagementService managementService = new AsynchronousSearchManagementService(settings, mockClusterService, deterministicTaskQueue.getThreadPool(), Mockito.mock(AsynchronousSearchService.class), transportService, Mockito.mock(AsynchronousSearchPersistenceService.class));
final long startTimeMillis = deterministicTaskQueue.getCurrentTimeMillis();
final int numNodesInCluster = 3;
ClusterState previousState = createSimpleClusterState();
ClusterState newState = createState(numNodesInCluster, true, initialIndices);
managementService.clusterChanged(new ClusterChangedEvent("_na_", newState, previousState));
assertTrue(deterministicTaskQueue.hasRunnableTasks());
assertTrue(deterministicTaskQueue.hasDeferredTasks());
int rescheduledCount = 0;
for (int i = 1; i <= randomIntBetween(5, 10); i++) {
if (deterministicTaskQueue.hasRunnableTasks()) {
deterministicTaskQueue.runRandomTask();
} else {
assertThat(deterministicTaskQueue.getLatestDeferredExecutionTime(), is(refreshInterval * (rescheduledCount + 1)));
deterministicTaskQueue.advanceTime();
rescheduledCount++;
}
assertThat(deterministicTaskQueue.getCurrentTimeMillis() - startTimeMillis, is(refreshInterval * rescheduledCount));
}
managementService.clusterChanged(new ClusterChangedEvent("_na_", createState(numNodesInCluster, false, initialIndices), newState));
deterministicTaskQueue.runAllTasksInTimeOrder();
assertFalse(deterministicTaskQueue.hasRunnableTasks());
assertFalse(deterministicTaskQueue.hasDeferredTasks());
}
use of org.opensearch.transport.TransportService in project asynchronous-search by opensearch-project.
the class AsynchronousSearchPersistenceServiceIT method testGetAndDeleteNonExistentId.
public void testGetAndDeleteNonExistentId() throws InterruptedException, IOException, ExecutionException {
AsynchronousSearchPersistenceService persistenceService = getInstanceFromNode(AsynchronousSearchPersistenceService.class);
TransportService transportService = getInstanceFromNode(TransportService.class);
SearchResponse searchResponse = client().search(new SearchRequest(TEST_INDEX)).get();
User user1 = TestClientUtils.randomUser();
User user2 = TestClientUtils.randomUser();
for (User originalUser : Arrays.asList(user1, null)) {
AsynchronousSearchId asId = generateNewAsynchronousSearchId(transportService);
AsynchronousSearchPersistenceModel model1 = new AsynchronousSearchPersistenceModel(System.currentTimeMillis(), System.currentTimeMillis() + new TimeValue(10, TimeUnit.DAYS).getMillis(), searchResponse, null, originalUser);
CountDownLatch createLatch = new CountDownLatch(1);
String id = AsynchronousSearchIdConverter.buildAsyncId(asId);
persistenceService.storeResponse(id, model1, new LatchedActionListener<>(ActionListener.wrap(r -> assertSuccessfulResponseCreation(id, r), e -> {
logger.debug("expect successful create, got", e);
fail("Expected successful create, got " + e.getMessage());
}), createLatch));
createLatch.await();
for (User currentuser : Arrays.asList(originalUser, user2)) {
CountDownLatch latch = new CountDownLatch(2);
// assert failure
persistenceService.getResponse("id", currentuser, new LatchedActionListener<>(ActionListener.wrap((AsynchronousSearchPersistenceModel r) -> fail("Excepted resource_not_found_exception, got " + r), exception -> assertTrue("Expected resource_not_found expection, got " + exception.getClass().toString(), exception instanceof ResourceNotFoundException)), latch));
// assert failure
ActionListener<Boolean> wrap = ActionListener.wrap(r -> fail("Expected resource_not_found expection on delete, got acknowledgement " + r), ex -> assertTrue("Expected resource_not_found expection, got " + ex.getClass().toString(), ex instanceof ResourceNotFoundException));
persistenceService.deleteResponse("id", currentuser, new LatchedActionListener<>(wrap, latch));
latch.await();
}
}
}
Aggregations