Search in sources :

Example 6 with BLangListConstructorExpr

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

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

the class KnativeSecretAnnotationProcesser method processSecret.

private void processSecret(IdentifierNode nodeID, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    Set<SecretModel> secrets = 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) {
            SecretModel secretModel = new SecretModel();
            List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
            for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
                SecretMountConfig secretMountConfig = SecretMountConfig.valueOf(annotation.getKey().toString());
                switch(secretMountConfig) {
                    case name:
                        secretModel.setName(getValidName(getStringValue(annotation.getValue())));
                        break;
                    case labels:
                        secretModel.setLabels(getMap(keyValue.getValue()));
                        break;
                    case annotations:
                        secretModel.setAnnotations(getMap(keyValue.getValue()));
                        break;
                    case mountPath:
                        secretModel.setMountPath(getStringValue(annotation.getValue()));
                        break;
                    case data:
                        List<BLangExpression> data = ((BLangListConstructorExpr) annotation.valueExpr).exprs;
                        secretModel.setData(getDataForSecret(data));
                        break;
                    case readOnly:
                        secretModel.setReadOnly(getBooleanValue(annotation.getValue()));
                        break;
                    default:
                        break;
                }
            }
            if (isBlank(secretModel.getName())) {
                secretModel.setName(getValidName(nodeID.getValue()) + SECRET_POSTFIX);
            }
            secrets.add(secretModel);
        }
    }
    KnativeContext.getInstance().getDataHolder().addSecrets(secrets);
}
Also used : BLangAnnotationAttachment(org.wso2.ballerinalang.compiler.tree.BLangAnnotationAttachment) BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) SecretModel(org.ballerinax.kubernetes.models.knative.SecretModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Example 8 with BLangListConstructorExpr

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

the class KnativeUtils method getExternalFileMap.

/**
 * Get the set of external files to copy to docker image.
 *
 * @param keyValue Value of copyFiles field of Job annotation.
 * @return A set of external files
 * @throws KubernetesPluginException if an error occur while getting the paths
 */
public static Set<CopyFileModel> getExternalFileMap(BLangRecordLiteral.BLangRecordKeyValueField keyValue) throws KubernetesPluginException {
    Set<CopyFileModel> externalFiles = new HashSet<>();
    List<BLangExpression> configAnnotation = ((BLangListConstructorExpr) keyValue.valueExpr).exprs;
    for (BLangExpression bLangExpression : configAnnotation) {
        List<BLangRecordLiteral.BLangRecordKeyValueField> annotationValues = convertRecordFields(((BLangRecordLiteral) bLangExpression).getFields());
        CopyFileModel externalFileModel = new CopyFileModel();
        for (BLangRecordLiteral.BLangRecordKeyValueField annotation : annotationValues) {
            switch(annotation.getKey().toString()) {
                case "sourceFile":
                    externalFileModel.setSource(getStringValue(annotation.getValue()));
                    break;
                case "target":
                    externalFileModel.setTarget(getStringValue(annotation.getValue()));
                    break;
                default:
                    break;
            }
        }
        if (isBlank(externalFileModel.getSource())) {
            throw new KubernetesPluginException("@kubernetes:Deployment copyFiles source cannot be empty.");
        }
        if (isBlank(externalFileModel.getTarget())) {
            throw new KubernetesPluginException("@kubernetes:Deployment copyFiles target cannot be empty.");
        }
        externalFiles.add(externalFileModel);
    }
    return externalFiles;
}
Also used : BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) CopyFileModel(org.ballerinax.docker.generator.models.CopyFileModel) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Example 9 with BLangListConstructorExpr

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

the class KubernetesUtils method getList.

/**
 * Generate array of string using a {@link BLangListConstructorExpr}.
 *
 * @param expr Array literal.
 * @return Convert string.
 */
public static List<String> getList(BLangExpression expr) throws KubernetesPluginException {
    if (expr.getKind() != NodeKind.LIST_CONSTRUCTOR_EXPR) {
        throw new KubernetesPluginException("unable to parse value: " + expr.toString());
    } else {
        BLangListConstructorExpr array = (BLangListConstructorExpr) expr;
        List<String> scopeSet = new LinkedList<>();
        for (ExpressionNode bLangExpression : array.getExpressions()) {
            scopeSet.add(getStringValue((BLangExpression) bLangExpression));
        }
        return scopeSet;
    }
}
Also used : ExpressionNode(org.ballerinalang.model.tree.expressions.ExpressionNode) BLangListConstructorExpr(org.wso2.ballerinalang.compiler.tree.expressions.BLangListConstructorExpr) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) LinkedList(java.util.LinkedList)

Example 10 with BLangListConstructorExpr

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

the class DeploymentAnnotationProcessor 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) IntOrString(io.fabric8.kubernetes.api.model.IntOrString) 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