Search in sources :

Example 1 with Tenant

use of com.linkedin.pinot.common.config.Tenant in project pinot by linkedin.

the class PinotTenantRestletResource method post.

/*
   * For tenant creation
   */
@Override
@Post("json")
public Representation post(Representation entity) {
    StringRepresentation presentation;
    try {
        final Tenant tenant = _objectMapper.readValue(entity.getText(), Tenant.class);
        presentation = createTenant(tenant);
    } catch (final Exception e) {
        presentation = exceptionToStringRepresentation(e);
        LOGGER.error("Caught exception while creating tenant ", e);
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_TENANT_CREATE_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
    }
    return presentation;
}
Also used : Tenant(com.linkedin.pinot.common.config.Tenant) StringRepresentation(org.restlet.representation.StringRepresentation) JSONException(org.json.JSONException) Post(org.restlet.resource.Post)

Example 2 with Tenant

use of com.linkedin.pinot.common.config.Tenant in project pinot by linkedin.

the class PinotTenantRestletResource method put.

/*
   * For tenant update
   */
@Override
@Put("json")
public Representation put(Representation entity) {
    StringRepresentation presentation;
    try {
        final Tenant tenant = _objectMapper.readValue(ByteStreams.toByteArray(entity.getStream()), Tenant.class);
        presentation = updateTenant(tenant);
    } catch (final Exception e) {
        presentation = exceptionToStringRepresentation(e);
        LOGGER.error("Caught exception while updating tenant ", e);
        ControllerRestApplication.getControllerMetrics().addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_TENANT_UPDATE_ERROR, 1L);
        setStatus(Status.SERVER_ERROR_INTERNAL);
    }
    return presentation;
}
Also used : Tenant(com.linkedin.pinot.common.config.Tenant) StringRepresentation(org.restlet.representation.StringRepresentation) JSONException(org.json.JSONException) Put(org.restlet.resource.Put)

Example 3 with Tenant

use of com.linkedin.pinot.common.config.Tenant in project pinot by linkedin.

the class PinotHelixResourceManagerTest method testRebuildBrokerResourceFromHelixTags.

@Test
public void testRebuildBrokerResourceFromHelixTags() throws Exception {
    AbstractTableConfig tableConfig = AbstractTableConfig.init(ControllerRequestBuilderUtil.buildCreateOfflineTableJSON("faketable", "serverTenant", "brokerTenant", 3).toString());
    Tenant tenant = new Tenant();
    tenant.setTenantName("brokerTenant");
    tenant.setTenantRole("BROKER");
    tenant.setNumberOfInstances(3);
    pinotHelixResourceManager.createBrokerTenant(tenant);
    pinotHelixResourceManager.addTable(tableConfig);
    // Check that the broker ideal state has 3 brokers assigned to it for faketable_OFFLINE
    IdealState idealState = pinotHelixResourceManager.getHelixAdmin().getResourceIdealState(HELIX_CLUSTER_NAME, CommonConstants.Helix.BROKER_RESOURCE_INSTANCE);
    Assert.assertEquals(idealState.getInstanceStateMap("faketable_OFFLINE").size(), 3);
    // Retag all instances current assigned to brokerTenant to be unassigned
    Set<String> brokerInstances = pinotHelixResourceManager.getAllInstancesForBrokerTenant("brokerTenant");
    for (String brokerInstance : brokerInstances) {
        pinotHelixResourceManager.getHelixAdmin().removeInstanceTag(HELIX_CLUSTER_NAME, brokerInstance, "brokerTenant_BROKER");
        pinotHelixResourceManager.getHelixAdmin().addInstanceTag(HELIX_CLUSTER_NAME, brokerInstance, CommonConstants.Helix.UNTAGGED_BROKER_INSTANCE);
    }
    // Rebuilding the broker tenant should update the ideal state size
    pinotHelixResourceManager.rebuildBrokerResourceFromHelixTags("faketable_OFFLINE");
    idealState = pinotHelixResourceManager.getHelixAdmin().getResourceIdealState(HELIX_CLUSTER_NAME, CommonConstants.Helix.BROKER_RESOURCE_INSTANCE);
    Assert.assertEquals(idealState.getInstanceStateMap("faketable_OFFLINE").size(), 0);
    // Tag five instances
    int instancesRemainingToTag = 5;
    List<String> instances = pinotHelixResourceManager.getAllInstanceNames();
    for (String instance : instances) {
        if (instance.startsWith(CommonConstants.Helix.PREFIX_OF_BROKER_INSTANCE)) {
            pinotHelixResourceManager.getHelixAdmin().removeInstanceTag(HELIX_CLUSTER_NAME, instance, CommonConstants.Helix.UNTAGGED_BROKER_INSTANCE);
            pinotHelixResourceManager.getHelixAdmin().addInstanceTag(HELIX_CLUSTER_NAME, instance, "brokerTenant_BROKER");
            instancesRemainingToTag--;
            if (instancesRemainingToTag == 0) {
                break;
            }
        }
    }
    // Rebuilding the broker tenant should update the ideal state size
    pinotHelixResourceManager.rebuildBrokerResourceFromHelixTags("faketable_OFFLINE");
    idealState = pinotHelixResourceManager.getHelixAdmin().getResourceIdealState(HELIX_CLUSTER_NAME, CommonConstants.Helix.BROKER_RESOURCE_INSTANCE);
    Assert.assertEquals(idealState.getInstanceStateMap("faketable_OFFLINE").size(), 5);
    // Untag all instances for other tests
    for (String instance : instances) {
        if (instance.startsWith(CommonConstants.Helix.PREFIX_OF_BROKER_INSTANCE)) {
            pinotHelixResourceManager.getHelixAdmin().removeInstanceTag(HELIX_CLUSTER_NAME, instance, "brokerTenant_BROKER");
            pinotHelixResourceManager.getHelixAdmin().addInstanceTag(HELIX_CLUSTER_NAME, instance, CommonConstants.Helix.UNTAGGED_BROKER_INSTANCE);
        }
    }
    // Delete table
    pinotHelixResourceManager.deleteOfflineTable("faketable");
}
Also used : Tenant(com.linkedin.pinot.common.config.Tenant) AbstractTableConfig(com.linkedin.pinot.common.config.AbstractTableConfig) IdealState(org.apache.helix.model.IdealState) Test(org.testng.annotations.Test)

Example 4 with Tenant

use of com.linkedin.pinot.common.config.Tenant in project pinot by linkedin.

the class ClusterSanityTest method scaleDownBroker.

/**
   * Helper method to reduce the number of brokers to the provided value.
   * Assumes that the number of existing brokers is greater then the desired number.
   *
   * @param newNumBrokers
   * @return
   * @throws Exception
   */
private String scaleDownBroker(int newNumBrokers) throws Exception {
    Tenant tenant = new Tenant.TenantBuilder(tenantName).setRole(TenantRole.BROKER).setTotalInstances(newNumBrokers).setOfflineInstances(newNumBrokers).build();
    // Send the 'put' (instead of 'post') request, that updates the tenants instead of creating.
    JSONObject request = tenant.toJSON();
    sendPutRequest(ControllerRequestURLBuilder.baseUrl(CONTROLLER_BASE_API_URL).forBrokerTenantCreate(), request.toString());
    Thread.sleep(WAIT_TIME_FOR_TENANT_UPDATE);
    return brokerTenant;
}
Also used : Tenant(com.linkedin.pinot.common.config.Tenant) JSONObject(org.json.JSONObject)

Example 5 with Tenant

use of com.linkedin.pinot.common.config.Tenant in project pinot by linkedin.

the class AddTenantCommand method execute.

@Override
public boolean execute() throws Exception {
    if (_controllerAddress == null) {
        if (_controllerHost == null) {
            _controllerHost = NetUtil.getHostAddress();
        }
        _controllerAddress = "http://" + _controllerHost + ":" + _controllerPort;
    }
    if (!_exec) {
        LOGGER.warn("Dry Running Command: " + toString());
        LOGGER.warn("Use the -exec option to actually execute the command.");
        return true;
    }
    LOGGER.info("Executing command: " + toString());
    Tenant t = new Tenant.TenantBuilder(_name).setRole(_role).setTotalInstances(_instanceCount).setOfflineInstances(_offlineInstanceCount).setRealtimeInstances(_realtimeInstanceCount).build();
    String res = AbstractBaseAdminCommand.sendPostRequest(ControllerRequestURLBuilder.baseUrl(_controllerAddress).forTenantCreate(), t.toString());
    LOGGER.info(res);
    System.out.print(res);
    return true;
}
Also used : Tenant(com.linkedin.pinot.common.config.Tenant)

Aggregations

Tenant (com.linkedin.pinot.common.config.Tenant)6 JSONException (org.json.JSONException)2 StringRepresentation (org.restlet.representation.StringRepresentation)2 AbstractTableConfig (com.linkedin.pinot.common.config.AbstractTableConfig)1 TenantBuilder (com.linkedin.pinot.common.config.Tenant.TenantBuilder)1 PinotHelixResourceManager (com.linkedin.pinot.controller.helix.core.PinotHelixResourceManager)1 IdealState (org.apache.helix.model.IdealState)1 JSONObject (org.json.JSONObject)1 Post (org.restlet.resource.Post)1 Put (org.restlet.resource.Put)1 Test (org.testng.annotations.Test)1