use of org.ballerinax.kubernetes.models.istio.IstioDestinationWeight in project kubernetes by ballerinax.
the class IstioVirtualServiceHandler method populateRouteList.
/**
* Parse an route list to a yaml map.
*
* @param serviceName The name of the service.
* @param routeModels The list of destination weights
* @return A list of yaml maps.
*/
private List<HTTPRouteDestination> populateRouteList(String serviceName, List<IstioDestinationWeight> routeModels) {
if (routeModels == null) {
routeModels = new LinkedList<>();
}
if (routeModels.size() == 0) {
routeModels.add(new IstioDestinationWeight());
}
List<HTTPRouteDestination> destinationWeightList = new LinkedList<>();
for (IstioDestinationWeight destinationWeightModel : routeModels) {
HTTPRouteDestination routeDestination = new HTTPRouteDestinationBuilder().withWeight(destinationWeightModel.getWeight()).withDestination(populateDestination(serviceName, destinationWeightModel.getDestination())).build();
destinationWeightList.add(routeDestination);
}
return destinationWeightList;
}
use of org.ballerinax.kubernetes.models.istio.IstioDestinationWeight in project kubernetes by ballerinax.
the class IstioVirtualServiceAnnotationProcessor method processRoutesAnnotation.
/**
* Process routes of http annotation to a model.
*
* @param routeArray The list of routes.
* @return A list of istio destination weight models.
* @throws KubernetesPluginException When an unknown field is found.
*/
private List<IstioDestinationWeight> processRoutesAnnotation(BLangListConstructorExpr routeArray) throws KubernetesPluginException {
List<IstioDestinationWeight> destinationWeights = new LinkedList<>();
for (ExpressionNode expression : routeArray.getExpressions()) {
BLangRecordLiteral routeFields = (BLangRecordLiteral) expression;
IstioDestinationWeight destinationWeight = new IstioDestinationWeight();
for (BLangRecordLiteral.BLangRecordKeyValueField routeField : convertRecordFields(routeFields.getFields())) {
switch(DestinationWeightConfig.valueOf(routeField.getKey().toString())) {
case destination:
BLangRecordLiteral destinationFields = (BLangRecordLiteral) routeField.getValue();
IstioDestination destination = processDestinationAnnotation(destinationFields);
destinationWeight.setDestination(destination);
break;
case weight:
destinationWeight.setWeight(getIntValue(routeField.getValue()));
break;
default:
throw new KubernetesPluginException("unknown field found for istio virtual service: " + routeField.getKey().toString());
}
}
destinationWeights.add(destinationWeight);
}
return destinationWeights;
}
Aggregations