Search in sources :

Example 1 with IstioHttpRoute

use of org.ballerinax.kubernetes.models.istio.IstioHttpRoute in project kubernetes by ballerinax.

the class IstioVirtualServiceAnnotationProcessor method processIstioVSAnnotation.

/**
 * Process @istio:VirtualService annotation.
 *
 * @param vsFields Fields of the virtual service annotation.
 * @throws KubernetesPluginException Unable to process annotations.
 */
private IstioVirtualServiceModel processIstioVSAnnotation(List<BLangRecordLiteral.BLangRecordKeyValueField> vsFields) throws KubernetesPluginException {
    IstioVirtualServiceModel vsModel = new IstioVirtualServiceModel();
    for (BLangRecordLiteral.BLangRecordKeyValueField vsField : vsFields) {
        switch(VSConfig.valueOf(vsField.getKey().toString())) {
            case name:
                vsModel.setName(getValidName(getStringValue(vsField.getValue())));
                break;
            case labels:
                vsModel.setLabels(getMap(vsField.getValue()));
                break;
            case annotations:
                vsModel.setAnnotations(getMap(vsField.getValue()));
                break;
            case hosts:
                vsModel.setHosts(getList(vsField.getValue()));
                break;
            case gateways:
                vsModel.setGateways(getList(vsField.getValue()));
                break;
            case http:
                BLangListConstructorExpr httpFields = (BLangListConstructorExpr) vsField.getValue();
                List<IstioHttpRoute> httpModels = processHttpAnnotation(httpFields);
                vsModel.setHttp(httpModels);
                break;
            default:
                throw new KubernetesPluginException("unknown field found for istio virtual service: " + vsField.getKey().toString());
        }
    }
    return vsModel;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) IstioVirtualServiceModel(org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) IstioHttpRoute(org.ballerinax.kubernetes.models.istio.IstioHttpRoute)

Example 2 with IstioHttpRoute

use of org.ballerinax.kubernetes.models.istio.IstioHttpRoute in project kubernetes by ballerinax.

the class IstioVirtualServiceHandler method populateHttp.

/**
 * Parsing a list of http routes to yaml maps.
 *
 * @param serviceName The name of the service where to route to.
 * @param httpRouteModels        The list of http routes.
 * @return A list of yaml maps.
 */
private List<HTTPRoute> populateHttp(String serviceName, List<IstioHttpRoute> httpRouteModels) {
    if (null == httpRouteModels) {
        httpRouteModels = new LinkedList<>();
    }
    if (httpRouteModels.size() == 0) {
        httpRouteModels.add(new IstioHttpRoute());
    }
    List<HTTPRoute> httpRoutes = new LinkedList<>();
    for (IstioHttpRoute httpRouteModel : httpRouteModels) {
        Duration timoutDuration = null;
        if (-1 != httpRouteModel.getTimeout()) {
            timoutDuration = new DurationBuilder().withSeconds(httpRouteModel.getTimeout()).build();
        }
        HTTPRoute httpRoute = new HTTPRouteBuilder().withRoute(populateRouteList(serviceName, httpRouteModel.getRoute())).withTimeout(timoutDuration).withAppendHeaders(httpRouteModel.getAppendHeaders()).build();
        httpRoutes.add(httpRoute);
    }
    return httpRoutes;
}
Also used : HTTPRoute(me.snowdrop.istio.api.networking.v1alpha3.HTTPRoute) Duration(me.snowdrop.istio.api.Duration) IstioHttpRoute(org.ballerinax.kubernetes.models.istio.IstioHttpRoute) LinkedList(java.util.LinkedList) HTTPRouteBuilder(me.snowdrop.istio.api.networking.v1alpha3.HTTPRouteBuilder) DurationBuilder(me.snowdrop.istio.api.DurationBuilder)

Example 3 with IstioHttpRoute

use of org.ballerinax.kubernetes.models.istio.IstioHttpRoute in project kubernetes by ballerinax.

the class IstioVirtualServiceAnnotationProcessor method processHttpAnnotation.

/**
 * Process http annotation array of the virtual service annotation to a model.
 *
 * @param httpArray The list of http fields.
 * @return Converted list of Istio http routes.
 * @throws KubernetesPluginException When an unknown field is found.
 */
private List<IstioHttpRoute> processHttpAnnotation(BLangListConstructorExpr httpArray) throws KubernetesPluginException {
    List<IstioHttpRoute> httpRoutes = new LinkedList<>();
    for (ExpressionNode expression : httpArray.getExpressions()) {
        BLangRecordLiteral httpFields = (BLangRecordLiteral) expression;
        IstioHttpRoute httpRoute = new IstioHttpRoute();
        for (BLangRecordLiteral.BLangRecordKeyValueField httpField : convertRecordFields(httpFields.getFields())) {
            switch(HttpRouteConfig.valueOf(httpField.getKey().toString())) {
                case route:
                    BLangListConstructorExpr routeFields = (BLangListConstructorExpr) httpField.getValue();
                    httpRoute.setRoute(processRoutesAnnotation(routeFields));
                    break;
                case timeout:
                    httpRoute.setTimeout(getLongValue(httpField.getValue()));
                    break;
                case appendHeaders:
                    httpRoute.setAppendHeaders(getMap(httpField.getValue()));
                    break;
                default:
                    throw new KubernetesPluginException("unknown field found for istio virtual service: " + httpField.getKey().toString());
            }
        }
        httpRoutes.add(httpRoute);
    }
    return httpRoutes;
}
Also used : ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) IstioHttpRoute(org.ballerinax.kubernetes.models.istio.IstioHttpRoute) LinkedList(java.util.LinkedList)

Aggregations

IstioHttpRoute (org.ballerinax.kubernetes.models.istio.IstioHttpRoute)3 LinkedList (java.util.LinkedList)2 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)2 BLangListConstructorExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr)2 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)2 Duration (me.snowdrop.istio.api.Duration)1 DurationBuilder (me.snowdrop.istio.api.DurationBuilder)1 HTTPRoute (me.snowdrop.istio.api.networking.v1alpha3.HTTPRoute)1 HTTPRouteBuilder (me.snowdrop.istio.api.networking.v1alpha3.HTTPRouteBuilder)1 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)1 IstioVirtualServiceModel (org.ballerinax.kubernetes.models.istio.IstioVirtualServiceModel)1