use of com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupUndefinedEvent in project titus-control-plane by Netflix.
the class ResourceConsumptionLog method doLog.
/* Visible for testing */
static String doLog(ResourceConsumptionEvents.ResourceConsumptionEvent event) {
if (event instanceof CapacityGroupAllocationEvent) {
CapacityGroupAllocationEvent changeEvent = (CapacityGroupAllocationEvent) event;
CompositeResourceConsumption consumption = changeEvent.getCapacityGroupConsumption();
StringBuilder sb = new StringBuilder("Resource consumption change: group=");
sb.append(consumption.getConsumerName());
if (consumption.isAboveLimit()) {
sb.append(" [above limit] ");
} else {
sb.append(" [below limit] ");
}
sb.append("actual=");
ResourceDimensions.format(consumption.getCurrentConsumption(), sb);
sb.append(", max=");
ResourceDimensions.format(consumption.getMaxConsumption(), sb);
sb.append(", limit=");
ResourceDimensions.format(consumption.getAllowedConsumption(), sb);
if (consumption.getAttributes().isEmpty()) {
sb.append(", attrs={}");
} else {
sb.append(", attrs={");
consumption.getAttributes().forEach((k, v) -> sb.append(k).append('=').append(v).append(','));
sb.setCharAt(sb.length() - 1, '}');
}
String message = sb.toString();
if (consumption.isAboveLimit()) {
logger.warn(message);
} else {
logger.info(message);
}
return message;
}
if (event instanceof CapacityGroupUndefinedEvent) {
String message = "Capacity group not defined: group=" + event.getCapacityGroup();
logger.warn(message);
return message;
}
if (event instanceof CapacityGroupRemovedEvent) {
String message = "Capacity group no longer defined: group=" + event.getCapacityGroup();
logger.info(message);
return message;
}
String message = "Unrecognized resource consumption event type " + event.getClass();
logger.error(message);
return message;
}
use of com.netflix.titus.master.service.management.ResourceConsumptionEvents.CapacityGroupUndefinedEvent in project titus-control-plane by Netflix.
the class ResourceConsumptionLogTest method testGroupUndefinedEvent.
@Test
public void testGroupUndefinedEvent() throws Exception {
CapacityGroupUndefinedEvent event = new CapacityGroupUndefinedEvent("myCapacityGroup", System.currentTimeMillis());
String result = ResourceConsumptionLog.doLog(event);
String expected = "Capacity group not defined: group=myCapacityGroup";
assertThat(result).isEqualTo(expected);
}
Aggregations