Search in sources :

Example 16 with BLangListConstructorExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.

the class VolumeClaimAnnotationProcessor method processVolumeClaims.

/**
 * Process PersistentVolumeClaim annotations.
 *
 * @param attachmentNode Annotation node.
 * @throws KubernetesPluginException When error occurs while parsing the annotations.
 */
private void processVolumeClaims(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    Set<PersistentVolumeClaimModel> volumeClaimModels = new HashSet<>();
    List<BLangRecordLiteral.BLangRecordKeyValueField> keyValues = convertRecordFields(((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getFields());
    for (BLangRecordLiteral.BLangRecordKeyValueField keyValue : keyValues) {
        List<BLangExpression> secretAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
        for (BLangExpression bLangExpression : secretAnnotation) {
            PersistentVolumeClaimModel claimModel = new PersistentVolumeClaimModel();
            List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
            for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
                VolumeClaimConfig volumeMountConfig = VolumeClaimConfig.valueOf(annotation.getKey().toString());
                switch(volumeMountConfig) {
                    case name:
                        claimModel.setName(getValidName(getStringValue(annotation.getValue())));
                        break;
                    case labels:
                        claimModel.setLabels(getMap(keyValue.getValue()));
                        break;
                    case annotations:
                        claimModel.setAnnotations(getMap(keyValue.getValue()));
                        break;
                    case mountPath:
                        claimModel.setMountPath(getStringValue(annotation.getValue()));
                        break;
                    case accessMode:
                        claimModel.setAccessMode(getStringValue(annotation.getValue()));
                        break;
                    case volumeClaimSize:
                        String amount = getStringValue(annotation.getValue()).replaceAll("\\D+", "");
                        String format = getStringValue(annotation.getValue()).replace(amount, "");
                        claimModel.setVolumeClaimSizeAmount(amount);
                        claimModel.setVolumeClaimSizeFormat(format);
                        break;
                    case readOnly:
                        claimModel.setReadOnly(getBooleanValue(annotation.getValue()));
                        break;
                    default:
                        break;
                }
            }
            volumeClaimModels.add(claimModel);
        }
    }
    KubernetesContext.getInstance().getDataHolder().addPersistentVolumeClaims(volumeClaimModels);
}
Also used : BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) PersistentVolumeClaimModel(org.ballerinax.kubernetes.models.PersistentVolumeClaimModel) BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Example 17 with BLangListConstructorExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr 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)

Example 18 with BLangListConstructorExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr 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)

Example 19 with BLangListConstructorExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.

the class KnativeServiceAnnotationProcessor method parsePodTolerationConfiguration.

/**
 * Parse pod toleration configurations from a record array.
 *
 * @param podTolerationValues Pod toleration configuration records.
 * @return Pod toleration models.
 * @throws KubernetesPluginException When an unknown field is found.
 */
private List<PodTolerationModel> parsePodTolerationConfiguration(BLangExpression podTolerationValues) throws KubernetesPluginException {
    List<PodTolerationModel> podTolerationModels = new LinkedList<>();
    List<BLangExpression> podTolerations = ((BLangListConstructorExpr) podTolerationValues).exprs;
    for (BLangExpression podTolerationFieldsAsExpression : podTolerations) {
        List<BLangRecordLiteral.BLangRecordKeyValueField> podTolerationFields = convertRecordFields(((BLangRecordLiteral) podTolerationFieldsAsExpression).getFields());
        PodTolerationModel podTolerationModel = new PodTolerationModel();
        for (BLangRecordLiteral.BLangRecordKeyValueField podTolerationField : podTolerationFields) {
            PodTolerationConfiguration podTolerationFieldName = PodTolerationConfiguration.valueOf(podTolerationField.getKey().toString());
            switch(podTolerationFieldName) {
                case key:
                    podTolerationModel.setKey(getStringValue(podTolerationField.getValue()));
                    break;
                case operator:
                    podTolerationModel.setOperator(getStringValue(podTolerationField.getValue()));
                    break;
                case value:
                    podTolerationModel.setValue(getStringValue(podTolerationField.getValue()));
                    break;
                case effect:
                    podTolerationModel.setEffect(getStringValue(podTolerationField.getValue()));
                    break;
                case tolerationSeconds:
                    podTolerationModel.setTolerationSeconds(getIntValue(podTolerationField.getValue()));
                    break;
                default:
                    throw new KubernetesPluginException("unknown pod toleration field found: " + podTolerationField.getKey().toString());
            }
        }
        podTolerationModels.add(podTolerationModel);
    }
    return podTolerationModels;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) PodTolerationModel(org.ballerinax.kubernetes.models.knative.PodTolerationModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) LinkedList(java.util.LinkedList)

Example 20 with BLangListConstructorExpr

use of org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr in project kubernetes by ballerinax.

the class KnativeServiceAnnotationProcessor method getDependsOn.

private Set<String> getDependsOn(BLangRecordLiteral.BLangRecordKeyValueField keyValue) {
    Set<String> dependsOnList = new HashSet<>();
    List<BLangExpression> configAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
    for (BLangExpression bLangExpression : configAnnotation) {
        dependsOnList.add(bLangExpression.toString());
    }
    return dependsOnList;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Aggregations

BLangListConstructorExpr (org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr)18 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)16 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)15 KubernetesPluginException (org.ballerinax.kubernetes.exceptions.KubernetesPluginException)13 HashSet (java.util.HashSet)12 LinkedList (java.util.LinkedList)7 BLangAnnotationAttachment (org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment)5 ExpressionNode (org.ballerinalang.model.tree.expressions.ExpressionNode)4 Path (java.nio.file.Path)3 CopyFileModel (org.ballerinax.docker.generator.models.CopyFileModel)2 IstioHttpRoute (org.ballerinax.kubernetes.models.istio.IstioHttpRoute)2 IntOrString (io.fabric8.kubernetes.api.model.IntOrString)1 ConfigMapModel (org.ballerinax.kubernetes.models.ConfigMapModel)1 PersistentVolumeClaimModel (org.ballerinax.kubernetes.models.PersistentVolumeClaimModel)1 PodTolerationModel (org.ballerinax.kubernetes.models.PodTolerationModel)1 ResourceQuotaModel (org.ballerinax.kubernetes.models.ResourceQuotaModel)1 SecretModel (org.ballerinax.kubernetes.models.SecretModel)1 ServiceAccountTokenModel (org.ballerinax.kubernetes.models.ServiceAccountTokenModel)1 IstioDestination (org.ballerinax.kubernetes.models.istio.IstioDestination)1 IstioDestinationWeight (org.ballerinax.kubernetes.models.istio.IstioDestinationWeight)1