Exemplo n.º 1
0
  @BeforeClass
  public static void createTribes() throws NodeValidationException {
    Settings baseSettings =
        Settings.builder()
            .put(NetworkModule.HTTP_ENABLED.getKey(), false)
            .put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
            .put(DiscoveryModule.DISCOVERY_TYPE_SETTING.getKey(), "local")
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
            .put(NodeEnvironment.MAX_LOCAL_STORAGE_NODES_SETTING.getKey(), 2)
            .build();

    tribe1 =
        new TribeClientNode(
                Settings.builder()
                    .put(baseSettings)
                    .put("cluster.name", "tribe1")
                    .put("node.name", "tribe1_node")
                    .put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong())
                    .build(),
                Collections.singleton(MockTcpTransportPlugin.class))
            .start();
    tribe2 =
        new TribeClientNode(
                Settings.builder()
                    .put(baseSettings)
                    .put("cluster.name", "tribe2")
                    .put("node.name", "tribe2_node")
                    .put(NodeEnvironment.NODE_ID_SEED_SETTING.getKey(), random().nextLong())
                    .build(),
                Collections.singleton(MockTcpTransportPlugin.class))
            .start();
  }
Exemplo n.º 2
0
 @Override
 protected Settings nodeSettings(int nodeOrdinal) {
   return Settings.builder()
       .put(NetworkModule.HTTP_ENABLED.getKey(), true)
       .put(super.nodeSettings(nodeOrdinal))
       .build();
 }
Exemplo n.º 3
0
 @Override
 protected Settings nodeSettings(int nodeOrdinal) {
   return Settings.builder()
       .put(super.nodeSettings(nodeOrdinal))
       .put(SETTING_CORS_ALLOW_ORIGIN.getKey(), "/https?:\\/\\/localhost(:[0-9]+)?/")
       .put(SETTING_CORS_ALLOW_CREDENTIALS.getKey(), true)
       .put(SETTING_CORS_ALLOW_METHODS.getKey(), "get, options, post")
       .put(SETTING_CORS_ENABLED.getKey(), true)
       .put(NetworkModule.HTTP_ENABLED.getKey(), true)
       .build();
 }
Exemplo n.º 4
0
 @Override
 protected Client createClient() {
   StopWatch watch = new StopWatch();
   try {
     Settings.Builder settings = Settings.builder();
     settings
         .put(NetworkModule.TRANSPORT_TYPE_SETTING.getKey(), NetworkModule.LOCAL_TRANSPORT)
         .put(NetworkModule.HTTP_ENABLED.getKey(), false)
         .put(Environment.PATH_HOME_SETTING.getKey(), dataPath);
     Node node = new Node(settings.build());
     node.start();
     return node.client();
   } catch (NodeValidationException e) {
     throw new Error(e);
   } finally {
     logger.info(
         "create local elasticsearch node, dataPath={}, elapsedTime={}",
         dataPath,
         watch.elapsedTime());
   }
 }
Exemplo n.º 5
0
  private static void assertTribeNodeSuccessfullyCreated(Settings extraSettings) throws Exception {
    // The tribe clients do need it to make sure they can find their corresponding tribes using the
    // proper transport
    Settings settings =
        Settings.builder()
            .put(NetworkModule.HTTP_ENABLED.getKey(), false)
            .put("node.name", "tribe_node")
            .put("transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
            .put("discovery.type", "local")
            .put("tribe.t1.transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
            .put("tribe.t2.transport.type", MockTcpTransportPlugin.MOCK_TCP_TRANSPORT_NAME)
            .put("tribe.t1.discovery.type", "local")
            .put("tribe.t2.discovery.type", "local")
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir())
            .put(extraSettings)
            .build();

    try (Node node =
        new MockNode(settings, Collections.singleton(MockTcpTransportPlugin.class)).start()) {
      try (Client client = node.client()) {
        assertBusy(
            () -> {
              ClusterState state =
                  client.admin().cluster().prepareState().clear().setNodes(true).get().getState();
              assertThat(state.getClusterName().value(), equalTo("tribe_node_cluster"));
              assertThat(state.getNodes().getSize(), equalTo(5));
              for (DiscoveryNode discoveryNode : state.getNodes()) {
                assertThat(
                    discoveryNode.getName(),
                    either(equalTo("tribe1_node"))
                        .or(equalTo("tribe2_node"))
                        .or(equalTo("tribe_node"))
                        .or(equalTo("tribe_node/t1"))
                        .or(equalTo("tribe_node/t2")));
              }
            });
      }
    }
  }