com.pszymczyk.consul.ConsulStarterBuilder Java Examples

The following examples show how to use com.pszymczyk.consul.ConsulStarterBuilder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ConsulDataSourceTest.java    From Sentinel with Apache License 2.0 6 votes vote down vote up
@Before
public void init() {
    this.consul = ConsulStarterBuilder.consulStarter()
        .build()
        .start();
    int port = consul.getHttpPort();
    String host = "127.0.0.1";
    client = new ConsulClient(host, port);
    Converter<String, List<FlowRule>> flowConfigParser = buildFlowConfigParser();
    String flowRulesJson =
        "[{\"resource\":\"test\", \"limitApp\":\"default\", \"grade\":1, \"count\":\"0.0\", \"strategy\":0, "
            + "\"refResource\":null, "
            +
            "\"controlBehavior\":0, \"warmUpPeriodSec\":10, \"maxQueueingTimeMs\":500, \"controller\":null}]";
    initConsulRuleData(flowRulesJson);
    rules = flowConfigParser.convert(flowRulesJson);
    consulDataSource = new ConsulDataSource<>(host, port, ruleKey, waitTimeoutInSecond, flowConfigParser);
    FlowRuleManager.register2Property(consulDataSource.getProperty());
}
 
Example #2
Source File: ConsulClientTest.java    From consul-api with Apache License 2.0 6 votes vote down vote up
@BeforeEach
public void setup() {
    String path = "src/test/resources/ssl";
    String certRootPath = new File(path).getAbsolutePath();
    //language=JSON
    String customConfiguration =
            "{\n" +
            "  \"datacenter\": \"dc-test\",\n" +
            "  \"log_level\": \"info\",\n" +
            "  \"ports\": {\n" +
            "    \"https\": "+ randomHttpsPort+ "\n" +
            "  },\n" +
            "  \"ca_file\": \"" + certRootPath + "/ca.cert\",\n" +
            "  \"key_file\": \"" + certRootPath + "/key.key\",\n" +
            "  \"cert_file\": \"" + certRootPath + "/key.crt\"\n" +
            "}\n";

    consul = ConsulStarterBuilder.consulStarter()
            .withConsulVersion(ConsulTestConstants.CONSUL_VERSION)
            .withCustomConfig(customConfiguration)
            .build()
            .start();
}
 
Example #3
Source File: ConsulNamingServiceTest.java    From brpc-java with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void setUp() throws Exception {
    final String customConfiguration =
            "{\n" +
                    "  \"datacenter\": \"dc-test\",\n" +
                    "  \"log_level\": \"info\"\n" +
                    "}\n";
    consul = ConsulStarterBuilder.consulStarter()
            .withConsulVersion("1.4.2")
            .withCustomConfig(customConfiguration)
            .build()
            .start();
    namingUrl = new BrpcURL("consul://127.0.0.1:" + consul.getHttpPort());
    consulNamingService = new ConsulNamingService(namingUrl);
}
 
Example #4
Source File: ConsulRegistryTest.java    From sofa-rpc with Apache License 2.0 5 votes vote down vote up
@Before
public void setup() {
    consul = ConsulStarterBuilder.consulStarter()
        .withConsulVersion("1.4.0")
        .build()
        .start();

    registryConfig = new RegistryConfig()
        .setProtocol("consul")
        .setAddress("127.0.0.1:" + consul.getHttpPort())
        .setRegister(true);

    registry = (ConsulRegistry) RegistryFactory.getRegistry(registryConfig);
    registry.init();
}
 
Example #5
Source File: ConsulApplication.java    From spring-cloud-zuul-ratelimit with Apache License 2.0 5 votes vote down vote up
@Bean
public ConsulProcess consulProcess() {
    if (consulProcess == null) {
        consulProcess = ConsulStarterBuilder.consulStarter().withHttpPort(8500).build().start();
    }
    return consulProcess;
}
 
Example #6
Source File: ConsulConfigStoreTest.java    From vertx-config with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void consulUp() {
  consulProcess = ConsulStarterBuilder.consulStarter()
    .withLogLevel(LogLevel.ERR)
    .withConsulVersion(CONSUL_VERSION)
    .build()
    .start();
}
 
Example #7
Source File: ConsulHostsSupplierTest.java    From dyno with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeEach() {
    String config = "{" +
            "\"datacenter\": \"test-dc\"," +
            "\"log_level\": \"INFO\"," +
            "\"node_name\": \"foobar\"" +
            "}";
    consulServer = ConsulStarterBuilder.consulStarter().withCustomConfig(config).build().start();
    consulClient = new ConsulClient("127.0.0.1", consulServer.getHttpPort());
}
 
Example #8
Source File: AclConsulClientTest.java    From consul-api with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void setup() {
    String customConfiguration =
            "{ \"acl_master_token\": \"" + ACL_MASTER_TOKEN + "\"" +
            ", \"acl_datacenter\": \"dc-test\"" +
            ", \"datacenter\": \"dc-test\" }";

    consul = ConsulStarterBuilder.consulStarter()
            .withConsulVersion(ConsulTestConstants.CONSUL_VERSION)
            .withHttpPort(port)
            .withCustomConfig(customConfiguration)
            .build()
            .start();
}
 
Example #9
Source File: CatalogConsulClientTest.java    From consul-api with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
	consul = ConsulStarterBuilder.consulStarter()
		.withConsulVersion(ConsulTestConstants.CONSUL_VERSION)
		.withHttpPort(port)
		.build()
		.start();
}
 
Example #10
Source File: KeyValueConsulClientTest.java    From consul-api with Apache License 2.0 5 votes vote down vote up
@BeforeEach
void setUp() {
	consul = ConsulStarterBuilder.consulStarter()
		.withConsulVersion(ConsulTestConstants.CONSUL_VERSION)
		.withHttpPort(port)
		.build()
		.start();
}
 
Example #11
Source File: ConsulAgent.java    From vertx-consul-client with Apache License 2.0 4 votes vote down vote up
ConsulAgent(ConsulDatacenter dc, ConsulAgentOptions options) {
  JsonObject cfg = new JsonObject()
    .put("server", true)
    .put("advertise_addr", options.getAddress())
    .put("client_addr", options.getAddress())
    .put("leave_on_terminate", true)
    .put("datacenter", dc.getName())
    .put("node_name", options.getNodeName())
    .put("node_id", options.getNodeId());
  if (options.getConsulVersion().compareTo("1.4.0") >= 0) {
    cfg.put("acl", new JsonObject()
        .put("enabled", true)
        .put("default_policy", "deny")
        .put("tokens", new JsonObject().put("master", dc.getMasterToken()))
      )
      .put("primary_datacenter", dc.getName());
  } else {
    cfg.put("acl_default_policy", "deny")
      .put("acl_master_token", dc.getMasterToken())
      .put("acl_datacenter", dc.getName());
  }
  if (options.getConsulVersion().compareTo("0.8.0") < 0) {
    cfg.put("ports", new JsonObject().put("rpc", getFreePort()));
  }
  if (options.getConsulVersion().compareTo("0.8.0") >= 0) {
    cfg.put("acl_enforce_version_8", false);
  }
  if (options.getConsulVersion().compareTo("0.9.0") >= 0) {
    cfg.put("enable_script_checks", true);
  }
  int sslCnt = 0;
  if (options.getKeyFile() != null) {
    cfg.put("key_file", options.getKeyFile());
    sslCnt++;
  }
  if (options.getCertFile() != null) {
    cfg.put("cert_file", options.getCertFile());
    sslCnt++;
  }
  if (options.getCaFile() != null) {
    cfg.put("ca_file", options.getCaFile());
    sslCnt++;
  }
  if (sslCnt == 3) {
    httpsPort = getFreePort();
    JsonObject ports = cfg.getJsonObject("ports", new JsonObject());
    ports.put("https", httpsPort);
    cfg.put("ports", ports).put("addresses", new JsonObject().put("https", "0.0.0.0"));
  } else {
    httpsPort = -1;
  }
  List<ConsulAgent> existingAgents = dc.getAgents();
  if (!existingAgents.isEmpty()) {
    cfg.put("start_join", existingAgents.stream()
      .map(agent -> "127.0.0.1:" + agent.getSerfLanPort())
      .collect(Collector.of(JsonArray::new, JsonArray::add, JsonArray::addAll)));
  }
  consulVersion = options.getConsulVersion();
  host = options.getAddress();
  name = options.getNodeName();
  masterToken = dc.getMasterToken();
  process = ConsulStarterBuilder.consulStarter()
    .withLogLevel(LogLevel.ERR)
    .withConsulVersion(options.getConsulVersion())
    .withCustomConfig(cfg.encode())
    .build()
    .start();
}