Search in sources :

Example 66 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project siddhi by wso2.

the class SiddhiQLBaseVisitorImpl method visitSiddhi_app.

/**
 * {@inheritDoc}
 * <p>The default implementation returns the result of calling
 * {@link #visitChildren} on {@code ctx}.</p>
 *
 * @param ctx
 */
@Override
public SiddhiApp visitSiddhi_app(@NotNull SiddhiQLParser.Siddhi_appContext ctx) {
    SiddhiApp siddhiApp = SiddhiApp.siddhiApp();
    for (SiddhiQLParser.App_annotationContext annotationContext : ctx.app_annotation()) {
        siddhiApp.annotation((Annotation) visit(annotationContext));
    }
    for (SiddhiQLParser.Definition_streamContext streamContext : ctx.definition_stream()) {
        siddhiApp.defineStream((StreamDefinition) visit(streamContext));
    }
    for (SiddhiQLParser.Definition_tableContext tableContext : ctx.definition_table()) {
        siddhiApp.defineTable((TableDefinition) visit(tableContext));
    }
    for (SiddhiQLParser.Definition_functionContext functionContext : ctx.definition_function()) {
        siddhiApp.defineFunction((FunctionDefinition) visit(functionContext));
    }
    for (SiddhiQLParser.Definition_windowContext windowContext : ctx.definition_window()) {
        siddhiApp.defineWindow((WindowDefinition) visit(windowContext));
    }
    for (SiddhiQLParser.Definition_aggregationContext aggregationContext : ctx.definition_aggregation()) {
        siddhiApp.defineAggregation((AggregationDefinition) visit(aggregationContext));
    }
    for (SiddhiQLParser.Execution_elementContext executionElementContext : ctx.execution_element()) {
        ExecutionElement executionElement = (ExecutionElement) visit(executionElementContext);
        if (executionElement instanceof Partition) {
            siddhiApp.addPartition((Partition) executionElement);
        } else if (executionElement instanceof Query) {
            siddhiApp.addQuery((Query) executionElement);
        } else {
            throw newSiddhiParserException(ctx);
        }
    }
    for (SiddhiQLParser.Definition_triggerContext triggerContext : ctx.definition_trigger()) {
        siddhiApp.defineTrigger((TriggerDefinition) visit(triggerContext));
    }
    populateQueryContext(siddhiApp, ctx);
    return siddhiApp;
}
Also used : SiddhiQLParser(org.wso2.siddhi.query.compiler.SiddhiQLParser) Partition(org.wso2.siddhi.query.api.execution.partition.Partition) SiddhiApp(org.wso2.siddhi.query.api.SiddhiApp) StoreQuery(org.wso2.siddhi.query.api.execution.query.StoreQuery) Query(org.wso2.siddhi.query.api.execution.query.Query) ExecutionElement(org.wso2.siddhi.query.api.execution.ExecutionElement)

Example 67 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation in project kubernetes by ballerinax.

the class KubernetesAnnotationProcessor method processDeployment.

/**
 * Process annotations and create deployment model object.
 *
 * @param attachmentNode annotation attachment node.
 * @return Deployment model object
 */
DeploymentModel processDeployment(AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException {
    DeploymentModel deploymentModel = new DeploymentModel();
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        DeploymentConfiguration deploymentConfiguration = DeploymentConfiguration.valueOf(keyValue.getKey().toString());
        String annotationValue = resolveValue(keyValue.getValue().toString());
        switch(deploymentConfiguration) {
            case name:
                deploymentModel.setName(getValidName(annotationValue));
                break;
            case labels:
                deploymentModel.setLabels(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
                break;
            case enableLiveness:
                deploymentModel.setEnableLiveness(annotationValue);
                break;
            case livenessPort:
                deploymentModel.setLivenessPort(Integer.parseInt(annotationValue));
                break;
            case initialDelaySeconds:
                deploymentModel.setInitialDelaySeconds(Integer.parseInt(annotationValue));
                break;
            case periodSeconds:
                deploymentModel.setPeriodSeconds(Integer.parseInt(annotationValue));
                break;
            case username:
                deploymentModel.setUsername(annotationValue);
                break;
            case env:
                deploymentModel.setEnv(getMap(((BLangRecordLiteral) keyValue.valueExpr).keyValuePairs));
                break;
            case password:
                deploymentModel.setPassword(annotationValue);
                break;
            case baseImage:
                deploymentModel.setBaseImage(annotationValue);
                break;
            case push:
                deploymentModel.setPush(Boolean.valueOf(annotationValue));
                break;
            case buildImage:
                deploymentModel.setBuildImage(Boolean.valueOf(annotationValue));
                break;
            case image:
                deploymentModel.setImage(annotationValue);
                break;
            case dockerHost:
                deploymentModel.setDockerHost(annotationValue);
                break;
            case dockerCertPath:
                deploymentModel.setDockerCertPath(annotationValue);
                break;
            case imagePullPolicy:
                deploymentModel.setImagePullPolicy(annotationValue);
                break;
            case replicas:
                deploymentModel.setReplicas(Integer.parseInt(annotationValue));
                break;
            default:
                break;
        }
    }
    return deploymentModel;
}
Also used : DeploymentModel(org.ballerinax.kubernetes.models.DeploymentModel) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)

Example 68 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation 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 69 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation 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 70 with Annotation

use of org.wso2.siddhi.query.api.annotation.Annotation 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)

Aggregations

Test (org.testng.annotations.Test)29 ArrayList (java.util.ArrayList)14 BLangRecordLiteral (org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral)12 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)11 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)11 HashMap (java.util.HashMap)9 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)9 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)9 List (java.util.List)8 SymbolEnv (org.wso2.ballerinalang.compiler.semantics.model.SymbolEnv)8 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)8 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)8 Annotation (org.wso2.siddhi.query.api.annotation.Annotation)8 BLangConnector (org.wso2.ballerinalang.compiler.tree.BLangConnector)7 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)7 BLangResource (org.wso2.ballerinalang.compiler.tree.BLangResource)7 BLangService (org.wso2.ballerinalang.compiler.tree.BLangService)7 StreamCallback (org.wso2.siddhi.core.stream.output.StreamCallback)7 StreamDefinition (org.wso2.siddhi.query.api.definition.StreamDefinition)7 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)7