Search in sources :

Example 1 with ControllerRequestURLBuilder

use of com.linkedin.pinot.controller.helix.ControllerRequestURLBuilder in project pinot by linkedin.

the class PinotTableRestletResourceTest method testUpdateTableConfig.

@Test
public void testUpdateTableConfig() throws IOException, JSONException {
    String tableName = "updateTC";
    JSONObject request = ControllerRequestBuilder.buildCreateOfflineTableJSON(tableName, "default", "default", "potato", "DAYS", "DAYS", "5", 2, "BalanceNumSegmentAssignmentStrategy", Collections.<String>emptyList(), "MMAP", "v3");
    ControllerRequestURLBuilder controllerUrlBuilder = ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL);
    sendPostRequest(controllerUrlBuilder.forTableCreate(), request.toString());
    // table creation should succeed
    AbstractTableConfig tableConfig = getTableConfig(tableName, "OFFLINE");
    Assert.assertEquals(tableConfig.getValidationConfig().getRetentionTimeValue(), "5");
    Assert.assertEquals(tableConfig.getValidationConfig().getRetentionTimeUnit(), "DAYS");
    tableConfig.getValidationConfig().setRetentionTimeUnit("HOURS");
    tableConfig.getValidationConfig().setRetentionTimeValue("10");
    String output = sendPutRequest(controllerUrlBuilder.forUpdateTableConfig(tableName), tableConfig.toJSON().toString());
    JSONObject jsonResponse = new JSONObject(output);
    Assert.assertTrue(jsonResponse.has("status"));
    Assert.assertEquals(jsonResponse.getString("status"), "Success");
    AbstractTableConfig modifiedConfig = getTableConfig(tableName, "OFFLINE");
    Assert.assertEquals(modifiedConfig.getValidationConfig().getRetentionTimeUnit(), "HOURS");
    Assert.assertEquals(modifiedConfig.getValidationConfig().getRetentionTimeValue(), "10");
    // Realtime
    JSONObject metadata = new JSONObject();
    metadata.put("streamType", "kafka");
    metadata.put(DataSource.STREAM_PREFIX + "." + Kafka.CONSUMER_TYPE, Kafka.ConsumerType.highLevel.toString());
    metadata.put(DataSource.STREAM_PREFIX + "." + Kafka.TOPIC_NAME, "fakeTopic");
    metadata.put(DataSource.STREAM_PREFIX + "." + Kafka.DECODER_CLASS, "fakeClass");
    metadata.put(DataSource.STREAM_PREFIX + "." + Kafka.ZK_BROKER_URL, "fakeUrl");
    metadata.put(DataSource.STREAM_PREFIX + "." + Kafka.HighLevelConsumer.ZK_CONNECTION_STRING, "potato");
    metadata.put(DataSource.Realtime.REALTIME_SEGMENT_FLUSH_SIZE, Integer.toString(1234));
    metadata.put(DataSource.STREAM_PREFIX + "." + Kafka.KAFKA_CONSUMER_PROPS_PREFIX + "." + Kafka.AUTO_OFFSET_RESET, "smallest");
    request = ControllerRequestBuilder.buildCreateRealtimeTableJSON(tableName, "default", "default", "potato", "DAYS", "DAYS", "5", 2, "BalanceNumSegmentAssignmentStrategy", metadata, "fakeSchema", "fakeColumn", Collections.<String>emptyList(), "MMAP", false);
    sendPostRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forTableCreate(), request.toString());
    tableConfig = getTableConfig(tableName, "REALTIME");
    Assert.assertEquals(tableConfig.getValidationConfig().getRetentionTimeValue(), "5");
    Assert.assertEquals(tableConfig.getValidationConfig().getRetentionTimeUnit(), "DAYS");
    Assert.assertNull(tableConfig.getQuotaConfig());
    QuotaConfig quota = new QuotaConfig();
    quota.setStorage("10G");
    tableConfig.setQuotaConfig(quota);
    sendPutRequest(controllerUrlBuilder.forUpdateTableConfig(tableName), tableConfig.toJSON().toString());
    modifiedConfig = getTableConfig(tableName, "REALTIME");
    Assert.assertEquals(modifiedConfig.getQuotaConfig().getStorage(), "10G");
}
Also used : JSONObject(org.json.JSONObject) ControllerRequestURLBuilder(com.linkedin.pinot.controller.helix.ControllerRequestURLBuilder) QuotaConfig(com.linkedin.pinot.common.config.QuotaConfig) AbstractTableConfig(com.linkedin.pinot.common.config.AbstractTableConfig) Test(org.testng.annotations.Test) ControllerTest(com.linkedin.pinot.controller.helix.ControllerTest)

Example 2 with ControllerRequestURLBuilder

use of com.linkedin.pinot.controller.helix.ControllerRequestURLBuilder in project pinot by linkedin.

the class TableViewsTest method testTableNotFound.

@Test(dataProvider = "stateProvider")
public void testTableNotFound(String state) throws IOException, JSONException {
    ControllerRequestURLBuilder requestBuilder = ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL);
    String url = requestBuilder.forTableView("UNKNOWN_TABLE", state, null);
    HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
    assertEquals(connection.getResponseCode(), 404);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ControllerRequestURLBuilder(com.linkedin.pinot.controller.helix.ControllerRequestURLBuilder) URL(java.net.URL) Test(org.testng.annotations.Test) ControllerTest(com.linkedin.pinot.controller.helix.ControllerTest)

Example 3 with ControllerRequestURLBuilder

use of com.linkedin.pinot.controller.helix.ControllerRequestURLBuilder in project pinot by linkedin.

the class PinotInstanceRestletResourceTest method testInstanceListingAndCreation.

@Test
public void testInstanceListingAndCreation() throws Exception {
    ControllerRequestURLBuilder urlBuilder = ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL);
    // Check that there are no instances
    JSONObject instanceList = new JSONObject(sendGetRequest(urlBuilder.forInstanceList()));
    assertEquals(instanceList.getJSONArray("instances").length(), 0, "Expected empty instance list at beginning of test");
    // Create untagged broker and server instances
    JSONObject brokerInstance = new JSONObject("{\"host\":\"1.2.3.4\", \"type\":\"broker\", \"port\":\"1234\"}");
    sendPostRequest(urlBuilder.forInstanceCreate(), brokerInstance.toString());
    JSONObject serverInstance = new JSONObject("{\"host\":\"1.2.3.4\", \"type\":\"server\", \"port\":\"2345\"}");
    sendPostRequest(urlBuilder.forInstanceCreate(), serverInstance.toString());
    // Check that there are two instances
    instanceList = new JSONObject(sendGetRequest(urlBuilder.forInstanceList()));
    assertEquals(instanceList.getJSONArray("instances").length(), 2, "Expected two instances after creation of untagged instances");
    // Create tagged broker and server instances
    brokerInstance.put("tag", "someTag");
    brokerInstance.put("host", "2.3.4.5");
    sendPostRequest(urlBuilder.forInstanceCreate(), brokerInstance.toString());
    serverInstance.put("tag", "someTag");
    serverInstance.put("host", "2.3.4.5");
    sendPostRequest(urlBuilder.forInstanceCreate(), serverInstance.toString());
    // Check that there are four instances
    instanceList = new JSONObject(sendGetRequest(urlBuilder.forInstanceList()));
    assertEquals(instanceList.getJSONArray("instances").length(), 4, "Expected two instances after creation of tagged instances");
    // Create duplicate broker and server instances (both calls should fail)
    try {
        sendPostRequest(urlBuilder.forInstanceCreate(), brokerInstance.toString());
        fail("Duplicate broker instance creation did not fail");
    } catch (IOException e) {
    // Expected
    }
    try {
        sendPostRequest(urlBuilder.forInstanceCreate(), serverInstance.toString());
        fail("Duplicate server instance creation did not fail");
    } catch (IOException e) {
    // Expected
    }
    // Check that there are four instances
    instanceList = new JSONObject(sendGetRequest(urlBuilder.forInstanceList()));
    assertEquals(instanceList.getJSONArray("instances").length(), 4, "Expected two instances after creation of duplicate instances");
    // Check that the instances are properly created
    JSONObject instance = new JSONObject(sendGetRequest(urlBuilder.forInstanceInformation("Broker_1.2.3.4_1234")));
    assertEquals(instance.get("instanceName"), "Broker_1.2.3.4_1234");
    assertEquals(instance.get("hostName"), "1.2.3.4");
    assertEquals(instance.get("port"), "1234");
    assertEquals(instance.get("enabled"), true);
    assertEquals(instance.getJSONArray("tags").length(), 1);
    assertEquals(instance.getJSONArray("tags").get(0), CommonConstants.Helix.UNTAGGED_BROKER_INSTANCE);
    instance = new JSONObject(sendGetRequest(urlBuilder.forInstanceInformation("Server_1.2.3.4_2345")));
    assertEquals(instance.get("instanceName"), "Server_1.2.3.4_2345");
    assertEquals(instance.get("hostName"), "1.2.3.4");
    assertEquals(instance.get("port"), "2345");
    assertEquals(instance.get("enabled"), true);
    assertEquals(instance.getJSONArray("tags").length(), 1);
    assertEquals(instance.getJSONArray("tags").get(0), CommonConstants.Helix.UNTAGGED_SERVER_INSTANCE);
    instance = new JSONObject(sendGetRequest(urlBuilder.forInstanceInformation("Broker_2.3.4.5_1234")));
    assertEquals(instance.get("instanceName"), "Broker_2.3.4.5_1234");
    assertEquals(instance.get("hostName"), "2.3.4.5");
    assertEquals(instance.get("port"), "1234");
    assertEquals(instance.get("enabled"), true);
    assertEquals(instance.getJSONArray("tags").length(), 1);
    assertEquals(instance.getJSONArray("tags").get(0), "someTag");
    instance = new JSONObject(sendGetRequest(urlBuilder.forInstanceInformation("Server_2.3.4.5_2345")));
    assertEquals(instance.get("instanceName"), "Server_2.3.4.5_2345");
    assertEquals(instance.get("hostName"), "2.3.4.5");
    assertEquals(instance.get("port"), "2345");
    assertEquals(instance.get("enabled"), true);
    assertEquals(instance.getJSONArray("tags").length(), 1);
    assertEquals(instance.getJSONArray("tags").get(0), "someTag");
    // Check that an error is given for an instance that does not exist
    try {
        sendGetRequest(urlBuilder.forInstanceInformation("Server_potato_8126"));
        fail("Request to get instance information for an instance that does not exist did not fail");
    } catch (IOException e) {
    // Expected
    }
}
Also used : JSONObject(org.json.JSONObject) ControllerRequestURLBuilder(com.linkedin.pinot.controller.helix.ControllerRequestURLBuilder) IOException(java.io.IOException) Test(org.testng.annotations.Test) ControllerTest(com.linkedin.pinot.controller.helix.ControllerTest)

Example 4 with ControllerRequestURLBuilder

use of com.linkedin.pinot.controller.helix.ControllerRequestURLBuilder in project pinot by linkedin.

the class TableViewsTest method testBadRequest.

@Test(dataProvider = "stateProvider")
public void testBadRequest(String state) throws IOException {
    ControllerRequestURLBuilder requestURLBuilder = ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL);
    String url = requestURLBuilder.forTableView("UNKNOWN_TABLE", state, "no_such_type");
    HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection();
    assertEquals(connection.getResponseCode(), 400);
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ControllerRequestURLBuilder(com.linkedin.pinot.controller.helix.ControllerRequestURLBuilder) URL(java.net.URL) Test(org.testng.annotations.Test) ControllerTest(com.linkedin.pinot.controller.helix.ControllerTest)

Aggregations

ControllerRequestURLBuilder (com.linkedin.pinot.controller.helix.ControllerRequestURLBuilder)4 ControllerTest (com.linkedin.pinot.controller.helix.ControllerTest)4 Test (org.testng.annotations.Test)4 HttpURLConnection (java.net.HttpURLConnection)2 URL (java.net.URL)2 JSONObject (org.json.JSONObject)2 AbstractTableConfig (com.linkedin.pinot.common.config.AbstractTableConfig)1 QuotaConfig (com.linkedin.pinot.common.config.QuotaConfig)1 IOException (java.io.IOException)1