Search in sources :

Example 6 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project anomaly-detection by opensearch-project.

the class AbstractProfileRunnerTests method setUpOnce.

@BeforeClass
public static void setUpOnce() {
    stateOnly = new HashSet<DetectorProfileName>();
    stateOnly.add(DetectorProfileName.STATE);
    stateNError = new HashSet<DetectorProfileName>();
    stateNError.add(DetectorProfileName.ERROR);
    stateNError.add(DetectorProfileName.STATE);
    stateInitProgress = new HashSet<DetectorProfileName>();
    stateInitProgress.add(DetectorProfileName.INIT_PROGRESS);
    stateInitProgress.add(DetectorProfileName.STATE);
    modelProfile = new HashSet<DetectorProfileName>(Arrays.asList(DetectorProfileName.SHINGLE_SIZE, DetectorProfileName.MODELS, DetectorProfileName.COORDINATING_NODE, DetectorProfileName.TOTAL_SIZE_IN_BYTES));
    totalInitProgress = new HashSet<DetectorProfileName>(Arrays.asList(DetectorProfileName.TOTAL_ENTITIES, DetectorProfileName.INIT_PROGRESS));
    initProgressErrorProfile = new HashSet<DetectorProfileName>(Arrays.asList(DetectorProfileName.INIT_PROGRESS, DetectorProfileName.ERROR));
    clusterName = "test-cluster-name";
    discoveryNode1 = new DiscoveryNode("nodeName1", "node1", new TransportAddress(TransportAddress.META_ADDRESS, 9300), emptyMap(), emptySet(), Version.CURRENT);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) DetectorProfileName(org.opensearch.ad.model.DetectorProfileName) TransportAddress(org.opensearch.common.transport.TransportAddress) BeforeClass(org.junit.BeforeClass)

Example 7 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project anomaly-detection by opensearch-project.

the class ProfileTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    clusterName = "test-cluster-name";
    node1 = "node1";
    nodeName1 = "nodename1";
    discoveryNode1 = new DiscoveryNode(nodeName1, node1, new TransportAddress(TransportAddress.META_ADDRESS, 9300), emptyMap(), emptySet(), Version.CURRENT);
    node2 = "node2";
    nodeName2 = "nodename2";
    discoveryNode2 = new DiscoveryNode(nodeName2, node2, new TransportAddress(TransportAddress.META_ADDRESS, 9301), emptyMap(), emptySet(), Version.CURRENT);
    clusterStats = new HashMap<>();
    modelSize = 4456448L;
    model1Id = "Pl536HEBnXkDrah03glg_model_rcf_1";
    model0Id = "Pl536HEBnXkDrah03glg_model_rcf_0";
    detectorId = "123";
    shingleSize = 6;
    modelSizeMap1 = new HashMap<String, Long>() {

        {
            put(model1Id, modelSize);
        }
    };
    modelSizeMap2 = new HashMap<String, Long>() {

        {
            put(model0Id, modelSize);
        }
    };
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) TransportAddress(org.opensearch.common.transport.TransportAddress) Before(org.junit.Before)

Example 8 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project anomaly-detection by opensearch-project.

the class RCFPollingTests method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    clusterService = mock(ClusterService.class);
    hashRing = mock(HashRing.class);
    transportAddress1 = new TransportAddress(new InetSocketAddress(InetAddress.getByName("1.2.3.4"), 9300));
    manager = mock(ModelManager.class);
    transportService = new TransportService(Settings.EMPTY, mock(Transport.class), null, TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> null, null, Collections.emptySet());
    future = new PlainActionFuture<>();
    request = new RCFPollingRequest(detectorId);
    model0Id = SingleStreamModelIdMapper.getRcfModelId(detectorId, 0);
    doAnswer(invocation -> {
        Object[] args = invocation.getArguments();
        @SuppressWarnings("unchecked") ActionListener<Long> listener = (ActionListener<Long>) args[2];
        listener.onResponse(totalUpdates);
        return null;
    }).when(manager).getTotalUpdates(any(String.class), any(String.class), any());
    normalTransportInterceptor = new TransportInterceptor() {

        @Override
        public AsyncSender interceptSender(AsyncSender sender) {
            return new AsyncSender() {

                @Override
                public <T extends TransportResponse> void sendRequest(Transport.Connection connection, String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler) {
                    if (RCFPollingAction.NAME.equals(action)) {
                        sender.sendRequest(connection, action, request, options, rcfRollingHandler(handler));
                    } else {
                        sender.sendRequest(connection, action, request, options, handler);
                    }
                }
            };
        }
    };
    failureTransportInterceptor = new TransportInterceptor() {

        @Override
        public AsyncSender interceptSender(AsyncSender sender) {
            return new AsyncSender() {

                @Override
                public <T extends TransportResponse> void sendRequest(Transport.Connection connection, String action, TransportRequest request, TransportRequestOptions options, TransportResponseHandler<T> handler) {
                    if (RCFPollingAction.NAME.equals(action)) {
                        sender.sendRequest(connection, action, request, options, rcfFailureRollingHandler(handler));
                    } else {
                        sender.sendRequest(connection, action, request, options, handler);
                    }
                }
            };
        }
    };
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JsonDeserializer(test.org.opensearch.ad.util.JsonDeserializer) BeforeClass(org.junit.BeforeClass) ModelManager(org.opensearch.ad.ml.ModelManager) HashRing(org.opensearch.ad.cluster.HashRing) ToXContent(org.opensearch.common.xcontent.ToXContent) TransportInterceptor(org.opensearch.transport.TransportInterceptor) AbstractADTest(org.opensearch.ad.AbstractADTest) Version(org.opensearch.Version) JsonPathNotFoundException(org.opensearch.ad.common.exception.JsonPathNotFoundException) GsonBuilder(com.google.gson.GsonBuilder) AnomalyDetectionException(org.opensearch.ad.common.exception.AnomalyDetectionException) InetAddress(java.net.InetAddress) Transport(org.opensearch.transport.Transport) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) PlainActionFuture(org.opensearch.action.support.PlainActionFuture) Gson(com.google.gson.Gson) Mockito.doAnswer(org.mockito.Mockito.doAnswer) ActionListener(org.opensearch.action.ActionListener) Before(org.junit.Before) StreamInput(org.opensearch.common.io.stream.StreamInput) AfterClass(org.junit.AfterClass) CommonName(org.opensearch.ad.constant.CommonName) TransportRequest(org.opensearch.transport.TransportRequest) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) TransportResponseHandler(org.opensearch.transport.TransportResponseHandler) IOException(java.io.IOException) Settings(org.opensearch.common.settings.Settings) Mockito.when(org.mockito.Mockito.when) Task(org.opensearch.tasks.Task) TransportResponse(org.opensearch.transport.TransportResponse) InetSocketAddress(java.net.InetSocketAddress) TransportService(org.opensearch.transport.TransportService) TransportAddress(org.opensearch.common.transport.TransportAddress) ActionFilters(org.opensearch.action.support.ActionFilters) TestHelpers(org.opensearch.ad.TestHelpers) FakeNode(test.org.opensearch.ad.util.FakeNode) ClusterService(org.opensearch.cluster.service.ClusterService) Optional(java.util.Optional) SingleStreamModelIdMapper(org.opensearch.ad.ml.SingleStreamModelIdMapper) ConnectTransportException(org.opensearch.transport.ConnectTransportException) Collections(java.util.Collections) TransportException(org.opensearch.transport.TransportException) Mockito.mock(org.mockito.Mockito.mock) TransportInterceptor(org.opensearch.transport.TransportInterceptor) TransportAddress(org.opensearch.common.transport.TransportAddress) InetSocketAddress(java.net.InetSocketAddress) HashRing(org.opensearch.ad.cluster.HashRing) TransportRequestOptions(org.opensearch.transport.TransportRequestOptions) TransportRequest(org.opensearch.transport.TransportRequest) ModelManager(org.opensearch.ad.ml.ModelManager) ClusterService(org.opensearch.cluster.service.ClusterService) ActionListener(org.opensearch.action.ActionListener) TransportService(org.opensearch.transport.TransportService) Transport(org.opensearch.transport.Transport) Before(org.junit.Before)

Example 9 with TransportAddress

use of org.opensearch.common.transport.TransportAddress 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);
}
Also used : DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) Task(org.opensearch.tasks.Task) TransportAddress(org.opensearch.common.transport.TransportAddress) ArrayList(java.util.ArrayList) ThreadPool(org.opensearch.threadpool.ThreadPool) ActionFilters(org.opensearch.action.support.ActionFilters) ClusterService(org.opensearch.cluster.service.ClusterService) TransportService(org.opensearch.transport.TransportService) ClusterName(org.opensearch.cluster.ClusterName) FailedNodeException(org.opensearch.action.FailedNodeException) OpenSearchException(org.opensearch.OpenSearchException) Client(org.opensearch.client.Client) Settings(org.opensearch.common.settings.Settings) Before(org.junit.Before)

Example 10 with TransportAddress

use of org.opensearch.common.transport.TransportAddress in project OpenSearch by opensearch-project.

the class ClusterFormationFailureHelperTests method testDescriptionOnMasterIneligibleNodes.

public void testDescriptionOnMasterIneligibleNodes() {
    final DiscoveryNode localNode = new DiscoveryNode("local", buildNewFakeTransportAddress(), emptyMap(), emptySet(), Version.CURRENT);
    final ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT).version(12L).metadata(Metadata.builder().coordinationMetadata(CoordinationMetadata.builder().term(4L).build())).nodes(DiscoveryNodes.builder().add(localNode).localNodeId(localNode.getId())).build();
    assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), emptyList(), 15L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered yet: have discovered []; discovery will continue using [] from hosts providers " + "and [] from last-known cluster state; node term 15, last-accepted version 12 in term 4"));
    final TransportAddress otherAddress = buildNewFakeTransportAddress();
    assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, singletonList(otherAddress), emptyList(), 16L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered yet: have discovered []; discovery will continue using [" + otherAddress + "] from hosts providers and [] from last-known cluster state; node term 16, last-accepted version 12 in term 4"));
    final DiscoveryNode otherNode = new DiscoveryNode("other", buildNewFakeTransportAddress(), Version.CURRENT);
    assertThat(new ClusterFormationState(Settings.EMPTY, clusterState, emptyList(), singletonList(otherNode), 17L, electionStrategy, new StatusInfo(HEALTHY, "healthy-info")).getDescription(), is("master not discovered yet: have discovered [" + otherNode + "]; discovery will continue using [] from hosts providers " + "and [] from last-known cluster state; node term 17, last-accepted version 12 in term 4"));
}
Also used : ClusterState(org.opensearch.cluster.ClusterState) DiscoveryNode(org.opensearch.cluster.node.DiscoveryNode) StatusInfo(org.opensearch.monitor.StatusInfo) TransportAddress(org.opensearch.common.transport.TransportAddress) ClusterFormationState(org.opensearch.cluster.coordination.ClusterFormationFailureHelper.ClusterFormationState)

Aggregations

TransportAddress (org.opensearch.common.transport.TransportAddress)175 DiscoveryNode (org.opensearch.cluster.node.DiscoveryNode)61 Settings (org.opensearch.common.settings.Settings)57 IOException (java.io.IOException)32 BoundTransportAddress (org.opensearch.common.transport.BoundTransportAddress)31 ArrayList (java.util.ArrayList)28 Version (org.opensearch.Version)28 HashSet (java.util.HashSet)25 List (java.util.List)25 InetAddress (java.net.InetAddress)24 CountDownLatch (java.util.concurrent.CountDownLatch)21 ThreadPool (org.opensearch.threadpool.ThreadPool)21 ClusterSettings (org.opensearch.common.settings.ClusterSettings)20 ClusterName (org.opensearch.cluster.ClusterName)17 Set (java.util.Set)16 TimeUnit (java.util.concurrent.TimeUnit)16 PlainActionFuture (org.opensearch.action.support.PlainActionFuture)16 HttpServerTransport (org.opensearch.http.HttpServerTransport)16 InetSocketAddress (java.net.InetSocketAddress)15 OpenSearchTestCase (org.opensearch.test.OpenSearchTestCase)15