use of io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlLoadParameters in project strimzi by strimzi.
the class KafkaRebalanceAssemblyOperator method parseLoadStats.
/**
* Converts the supplied before and after broker load arrays into a map linking from broker ID integer to a map linking
* from load parameter to an array of [before, after, difference]. The load paramters included in the map are dictated
* by the values in he {@link CruiseControlLoadParameters} enum.
*
* @param brokerLoadBeforeArray The JSONArray of broker load JSONObjects, for before the optimization proposal is applied,
* returned by the Cruise Control rebalance endpoint.
* @param brokerLoadAfterArray The JSONArray of broker load JSONObjects, for after the optimization proposal is applied,
* returned by the Cruise Control rebalance endpoint.
* @return A JsonObject linking from broker ID integer to a map of load parameter to [before, after, difference] arrays.
*/
protected static JsonObject parseLoadStats(JsonArray brokerLoadBeforeArray, JsonArray brokerLoadAfterArray) {
// There is no guarantee that the brokers are in the same order in both the before and after arrays.
// Therefore we need to convert them into maps indexed by broker ID so we can align them later for the comparison.
Map<Integer, Map<String, Object>> loadBeforeMap = extractLoadParameters(brokerLoadBeforeArray);
Map<Integer, Map<String, Object>> loadAfterMap = extractLoadParameters(brokerLoadAfterArray);
if (loadBeforeMap.size() != loadAfterMap.size()) {
throw new IllegalArgumentException("Broker data was missing from the load before/after information");
}
JsonObject brokersStats = new JsonObject();
for (Map.Entry<Integer, Map<String, Object>> loadBeforeEntry : loadBeforeMap.entrySet()) {
Map<String, Object> brokerBefore = loadBeforeEntry.getValue();
Map<String, Object> brokerAfter = loadAfterMap.get(loadBeforeEntry.getKey());
JsonObject brokerStats = new JsonObject();
for (CruiseControlLoadParameters intLoadParameter : CruiseControlLoadParameters.getIntegerParameters()) {
if (brokerBefore.containsKey(intLoadParameter.getKafkaRebalanceStatusKey()) && brokerAfter.containsKey(intLoadParameter.getKafkaRebalanceStatusKey())) {
int intBeforeStat = (int) brokerBefore.get(intLoadParameter.getKafkaRebalanceStatusKey());
int intAfterStat = (int) brokerAfter.get(intLoadParameter.getKafkaRebalanceStatusKey());
int intDiff = intAfterStat - intBeforeStat;
JsonObject intStats = new JsonObject();
intStats.put("before", intBeforeStat);
intStats.put("after", intAfterStat);
intStats.put("diff", intDiff);
brokerStats.put(intLoadParameter.getKafkaRebalanceStatusKey(), intStats);
} else {
LOGGER.warnOp("{} information was missing from the broker before/after load information", intLoadParameter.getKafkaRebalanceStatusKey());
}
}
for (CruiseControlLoadParameters doubleLoadParameter : CruiseControlLoadParameters.getDoubleParameters()) {
if (brokerBefore.containsKey(doubleLoadParameter.getKafkaRebalanceStatusKey()) && brokerAfter.containsKey(doubleLoadParameter.getKafkaRebalanceStatusKey())) {
double doubleBeforeStat = (double) brokerBefore.get(doubleLoadParameter.getKafkaRebalanceStatusKey());
double doubleAfterStat = (double) brokerAfter.get(doubleLoadParameter.getKafkaRebalanceStatusKey());
double doubleDiff = doubleAfterStat - doubleBeforeStat;
JsonObject doubleStats = new JsonObject();
doubleStats.put("before", doubleBeforeStat);
doubleStats.put("after", doubleAfterStat);
doubleStats.put("diff", doubleDiff);
brokerStats.put(doubleLoadParameter.getKafkaRebalanceStatusKey(), doubleStats);
} else {
LOGGER.warnOp("{} information was missing from the broker before/after load information", doubleLoadParameter.getKafkaRebalanceStatusKey());
}
}
brokersStats.put(String.valueOf(loadBeforeEntry.getKey()), brokerStats);
}
return brokersStats;
}
use of io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlLoadParameters in project strimzi by strimzi.
the class KafkaRebalanceAssemblyOperator method extractLoadParameters.
/**
* Converts the supplied JSONArray containing the load information JSONObject for each broker, into a map linking from
* broker ID to a map linking a more readable version of the load parameters key to their values. The load parameters
* that are extracted and the readable versions of the keys are dictated by the values defined in the
* {@link CruiseControlLoadParameters} enum.
*
* @param brokerLoadArray The JSONArray of broker load JSONObjects returned by the Cruise Control rebalance endpoint.
* @return A map linking from broker ID integer to a map of load parameter to value.
*/
protected static Map<Integer, Map<String, Object>> extractLoadParameters(JsonArray brokerLoadArray) {
Map<Integer, Map<String, Object>> loadMap = new HashMap<>();
for (Object rawBrokerLoad : brokerLoadArray) {
JsonObject brokerLoad = (JsonObject) rawBrokerLoad;
Map<String, Object> brokerLoadMap = new HashMap<>();
for (CruiseControlLoadParameters intParam : CruiseControlLoadParameters.getIntegerParameters()) {
if (brokerLoad.containsKey(intParam.getCruiseControlKey())) {
brokerLoadMap.put(intParam.getKafkaRebalanceStatusKey(), brokerLoad.getInteger(intParam.getCruiseControlKey()));
}
}
for (CruiseControlLoadParameters doubleParam : CruiseControlLoadParameters.getDoubleParameters()) {
if (brokerLoad.containsKey(doubleParam.getCruiseControlKey())) {
brokerLoadMap.put(doubleParam.getKafkaRebalanceStatusKey(), brokerLoad.getDouble(doubleParam.getCruiseControlKey()));
}
}
int brokerID = brokerLoad.getInteger(CruiseControlRebalanceKeys.BROKER_ID.getKey());
loadMap.put(brokerID, brokerLoadMap);
}
return loadMap;
}
use of io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlLoadParameters in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperator method extractLoadParameters.
/**
* Converts the supplied JSONArray containing the load information JSONObject for each broker, into a map linking from
* broker ID to a map linking a more readable version of the load parameters key to their values. The load parameters
* that are extracted and the readable versions of the keys are dictated by the values defined in the
* {@link CruiseControlLoadParameters} enum.
*
* @param brokerLoadArray The JSONArray of broker load JSONObjects returned by the Cruise Control rebalance endpoint.
* @return A map linking from broker ID integer to a map of load parameter to value.
*/
protected static Map<Integer, Map<String, Object>> extractLoadParameters(JsonArray brokerLoadArray) {
Map<Integer, Map<String, Object>> loadMap = new HashMap<>();
for (Object rawBrokerLoad : brokerLoadArray) {
JsonObject brokerLoad = (JsonObject) rawBrokerLoad;
Map<String, Object> brokerLoadMap = new HashMap<>();
for (CruiseControlLoadParameters intParam : CruiseControlLoadParameters.getIntegerParameters()) {
if (brokerLoad.containsKey(intParam.getCruiseControlKey())) {
brokerLoadMap.put(intParam.getKafkaRebalanceStatusKey(), brokerLoad.getInteger(intParam.getCruiseControlKey()));
}
}
for (CruiseControlLoadParameters doubleParam : CruiseControlLoadParameters.getDoubleParameters()) {
if (brokerLoad.containsKey(doubleParam.getCruiseControlKey())) {
brokerLoadMap.put(doubleParam.getKafkaRebalanceStatusKey(), brokerLoad.getDouble(doubleParam.getCruiseControlKey()));
}
}
int brokerID = brokerLoad.getInteger(CruiseControlRebalanceKeys.BROKER_ID.getKey());
loadMap.put(brokerID, brokerLoadMap);
}
return loadMap;
}
use of io.strimzi.operator.cluster.operator.resource.cruisecontrol.CruiseControlLoadParameters in project strimzi-kafka-operator by strimzi.
the class KafkaRebalanceAssemblyOperator method parseLoadStats.
/**
* Converts the supplied before and after broker load arrays into a map linking from broker ID integer to a map linking
* from load parameter to an array of [before, after, difference]. The load paramters included in the map are dictated
* by the values in he {@link CruiseControlLoadParameters} enum.
*
* @param brokerLoadBeforeArray The JSONArray of broker load JSONObjects, for before the optimization proposal is applied,
* returned by the Cruise Control rebalance endpoint.
* @param brokerLoadAfterArray The JSONArray of broker load JSONObjects, for after the optimization proposal is applied,
* returned by the Cruise Control rebalance endpoint.
* @return A JsonObject linking from broker ID integer to a map of load parameter to [before, after, difference] arrays.
*/
protected static JsonObject parseLoadStats(JsonArray brokerLoadBeforeArray, JsonArray brokerLoadAfterArray) {
// There is no guarantee that the brokers are in the same order in both the before and after arrays.
// Therefore we need to convert them into maps indexed by broker ID so we can align them later for the comparison.
Map<Integer, Map<String, Object>> loadBeforeMap = extractLoadParameters(brokerLoadBeforeArray);
Map<Integer, Map<String, Object>> loadAfterMap = extractLoadParameters(brokerLoadAfterArray);
if (loadBeforeMap.size() != loadAfterMap.size()) {
throw new IllegalArgumentException("Broker data was missing from the load before/after information");
}
JsonObject brokersStats = new JsonObject();
for (Map.Entry<Integer, Map<String, Object>> loadBeforeEntry : loadBeforeMap.entrySet()) {
Map<String, Object> brokerBefore = loadBeforeEntry.getValue();
Map<String, Object> brokerAfter = loadAfterMap.get(loadBeforeEntry.getKey());
JsonObject brokerStats = new JsonObject();
for (CruiseControlLoadParameters intLoadParameter : CruiseControlLoadParameters.getIntegerParameters()) {
if (brokerBefore.containsKey(intLoadParameter.getKafkaRebalanceStatusKey()) && brokerAfter.containsKey(intLoadParameter.getKafkaRebalanceStatusKey())) {
int intBeforeStat = (int) brokerBefore.get(intLoadParameter.getKafkaRebalanceStatusKey());
int intAfterStat = (int) brokerAfter.get(intLoadParameter.getKafkaRebalanceStatusKey());
int intDiff = intAfterStat - intBeforeStat;
JsonObject intStats = new JsonObject();
intStats.put("before", intBeforeStat);
intStats.put("after", intAfterStat);
intStats.put("diff", intDiff);
brokerStats.put(intLoadParameter.getKafkaRebalanceStatusKey(), intStats);
} else {
LOGGER.warnOp("{} information was missing from the broker before/after load information", intLoadParameter.getKafkaRebalanceStatusKey());
}
}
for (CruiseControlLoadParameters doubleLoadParameter : CruiseControlLoadParameters.getDoubleParameters()) {
if (brokerBefore.containsKey(doubleLoadParameter.getKafkaRebalanceStatusKey()) && brokerAfter.containsKey(doubleLoadParameter.getKafkaRebalanceStatusKey())) {
double doubleBeforeStat = (double) brokerBefore.get(doubleLoadParameter.getKafkaRebalanceStatusKey());
double doubleAfterStat = (double) brokerAfter.get(doubleLoadParameter.getKafkaRebalanceStatusKey());
double doubleDiff = doubleAfterStat - doubleBeforeStat;
JsonObject doubleStats = new JsonObject();
doubleStats.put("before", doubleBeforeStat);
doubleStats.put("after", doubleAfterStat);
doubleStats.put("diff", doubleDiff);
brokerStats.put(doubleLoadParameter.getKafkaRebalanceStatusKey(), doubleStats);
} else {
LOGGER.warnOp("{} information was missing from the broker before/after load information", doubleLoadParameter.getKafkaRebalanceStatusKey());
}
}
brokersStats.put(String.valueOf(loadBeforeEntry.getKey()), brokerStats);
}
return brokersStats;
}
Aggregations