use of org.ballerinax.kubernetes.models.istio.IstioDestination 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