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;
}
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;
}
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");
}
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;
}
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;
}
Aggregations