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;
}
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;
}
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;
}
Aggregations