Search in sources :

Example 56 with Node

use of org.wso2.charon3.core.utils.codeutils.Node in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processIngressAnnotation.

/**
 * Process annotations and create Ingress model object.
 *
 * @param serviceName    Ballerina service name
 * @param attachmentNode annotation attachment node.
 * @return Ingress model object
 */
IngressModel processIngressAnnotation(String serviceName, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    IngressModel ingressModel = new IngressModel();
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        IngressConfiguration ingressConfiguration = IngressConfiguration.valueOf(keyValue.getKey().toString());
        String annotationValue = resolveValue(keyValue.getValue().toString());
        switch(ingressConfiguration) {
            case name:
                ingressModel.setName(getValidName(annotationValue));
                break;
            case labels:
                ingressModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
                break;
            case path:
                ingressModel.setPath(annotationValue);
                break;
            case targetPath:
                ingressModel.setTargetPath(annotationValue);
                break;
            case hostname:
                ingressModel.setHostname(annotationValue);
                break;
            case ingressClass:
                ingressModel.setIngressClass(annotationValue);
                break;
            case enableTLS:
                ingressModel.setEnableTLS(Boolean.parseBoolean(annotationValue));
                break;
            default:
                break;
        }
    }
    if (ingressModel.getName() == null || ingressModel.getName().length() == 0) {
        ingressModel.setName(getValidName(serviceName) + INGRESS_POSTFIX);
    }
    if (ingressModel.getHostname() == null || ingressModel.getHostname().length() == 0) {
        ingressModel.setHostname(getValidName(serviceName) + INGRESS_HOSTNAME_POSTFIX);
    }
    return ingressModel;
}
Also used : IngressModel(org.ballerinax.kubernetes.models.IngressModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)

Example 57 with Node

use of org.wso2.charon3.core.utils.codeutils.Node in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processSecrets.

/**
 * Process Secrets annotations.
 *
 * @param attachmentNode Attachment Node
 * @return List of @{@link SecretModel} objects
 */
Set<SecretModel> processSecrets(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    Set<SecretModel> secrets = new HashSet<>();
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        List<BLangExpression> secretAnnotation = ((BLangArrayLiteral) keyValue.valueExpr).exprs;
        for (BLangExpression bLangExpression : secretAnnotation) {
            SecretModel secretModel = new SecretModel();
            List<BLangRecordLiteral.BLangRecordKeyValue> annotationValues = ((BLangRecordLiteral) bLangExpression).getKeyValuePairs();
            for (BLangRecordLiteral.BLangRecordKeyValue annotation : annotationValues) {
                VolumeMountConfig volumeMountConfig = VolumeMountConfig.valueOf(annotation.getKey().toString());
                String annotationValue = resolveValue(annotation.getValue().toString());
                switch(volumeMountConfig) {
                    case name:
                        secretModel.setName(getValidName(annotationValue));
                        break;
                    case mountPath:
                        secretModel.setMountPath(annotationValue);
                        break;
                    case data:
                        List<BLangExpression> data = ((BLangArrayLiteral) annotation.valueExpr).exprs;
                        secretModel.setData(getDataForSecret(data));
                        break;
                    case readOnly:
                        secretModel.setReadOnly(Boolean.parseBoolean(annotationValue));
                        break;
                    default:
                        break;
                }
            }
            secrets.add(secretModel);
        }
    }
    return secrets;
}
Also used : BLangArrayLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangArrayLiteral) SecretModel(org.ballerinax.kubernetes.models.SecretModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) BLangExpression(org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression) HashSet(java.util.HashSet)

Example 58 with Node

use of org.wso2.charon3.core.utils.codeutils.Node in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processServiceAnnotation.

/**
 * Process annotations and create service model object.
 *
 * @param endpointName   ballerina service name
 * @param attachmentNode annotation attachment node.
 * @return Service model object
 */
ServiceModel processServiceAnnotation(String endpointName, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    ServiceModel serviceModel = new ServiceModel();
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        ServiceConfiguration serviceConfiguration = ServiceConfiguration.valueOf(keyValue.getKey().toString());
        String annotationValue = resolveValue(keyValue.getValue().toString());
        switch(serviceConfiguration) {
            case name:
                serviceModel.setName(getValidName(annotationValue));
                break;
            case labels:
                serviceModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
                break;
            case serviceType:
                serviceModel.setServiceType(annotationValue);
                break;
            case port:
                serviceModel.setPort(Integer.parseInt(annotationValue));
                break;
            default:
                break;
        }
    }
    if (serviceModel.getName() == null) {
        serviceModel.setName(getValidName(endpointName) + SVC_POSTFIX);
    }
    return serviceModel;
}
Also used : ServiceModel(org.ballerinax.kubernetes.models.ServiceModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)

Example 59 with Node

use of org.wso2.charon3.core.utils.codeutils.Node in project ballerina by ballerina-lang.

the class SymbolEnter method defineNode.

public void defineNode(BLangNode node, SymbolEnv env) {
    SymbolEnv prevEnv = this.env;
    this.env = env;
    node.accept(this);
    this.env = prevEnv;
}
Also used : SymbolEnv(org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)

Example 60 with Node

use of org.wso2.charon3.core.utils.codeutils.Node in project ballerina by ballerina-lang.

the class SymbolEnter method visit.

@Override
public void visit(BLangVariable varNode) {
    // this is a field variable defined for object init function
    if (varNode.isField) {
        Name varName = names.fromIdNode(varNode.name);
        BVarSymbol fieldVar = (BVarSymbol) symResolver.resolveObjectField(varNode.pos, env, varName, env.enclObject.symbol.type.tsymbol);
        varNode.type = fieldVar.type;
        varName = getFieldSymbolName(((BLangFunction) env.enclInvokable).receiver, varNode);
        BVarSymbol varSymbol = defineVarSymbol(varNode.pos, varNode.flagSet, varNode.type, varName, env);
        env.enclObject.initFunction.initFunctionStmts.put(fieldVar, (BLangStatement) createAssignmentStmt(varNode, varSymbol, fieldVar));
        varSymbol.docTag = varNode.docTag;
        varNode.symbol = varSymbol;
        return;
    }
    // assign the type to var type node
    if (varNode.type == null) {
        varNode.type = symResolver.resolveTypeNode(varNode.typeNode, env);
    }
    Name varName = names.fromIdNode(varNode.name);
    if (varName == Names.EMPTY || varName == Names.IGNORE) {
        // e.g. function foo() (int);
        return;
    }
    BVarSymbol varSymbol = defineVarSymbol(varNode.pos, varNode.flagSet, varNode.type, varName, env);
    varSymbol.docTag = varNode.docTag;
    varNode.symbol = varSymbol;
}
Also used : BLangFunction(org.wso2.ballerinalang.compiler.tree.BLangFunction) BVarSymbol(org.wso2.ballerinalang.compiler.semantics.model.symbols.BVarSymbol) BLangXMLQName(org.wso2.ballerinalang.compiler.tree.expressions.BLangXMLQName) Name(org.wso2.ballerinalang.compiler.util.Name)

Aggregations

ArrayList (java.util.ArrayList)19 Node (org.w3c.dom.Node)13 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)13 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)13 List (java.util.List)12 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)11 Map (java.util.Map)10 BLangNode (org.wso2.ballerinalang.compiler.tree.BLangNode)10 DiagnosticPos (org.wso2.ballerinalang.compiler.util.diagnotic.DiagnosticPos)10 QName (javax.xml.namespace.QName)8 NodeList (org.w3c.dom.NodeList)8 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)8 Name (org.wso2.ballerinalang.compiler.util.Name)8 Arrays (java.util.Arrays)7 HashMap (java.util.HashMap)7 AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)7 Node (org.ballerinalang.model.tree.Node)7 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)7 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)7 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)7