Search in sources :

Example 1 with IstioDestination

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;
}
Also used : IstioDestination(org.ballerinax.kubernetes.models.istio.IstioDestination) IstioDestinationWeight(org.ballerinax.kubernetes.models.istio.IstioDestinationWeight) ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)1 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)1 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)1 IstioDestination (org.ballerinax.kubernetes.models.istio.IstioDestination)1 IstioDestinationWeight (org.ballerinax.kubernetes.models.istio.IstioDestinationWeight)1 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)1