Search in sources :

Example 16 with AnnotationAttachmentNode

use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project kubernetes by ballerinax.

the class KubernetesPlugin method process.

@Override
public void process(EndpointNode endpointNode, List<AnnotationAttachmentNode> annotations) {
    String endpointName = endpointNode.getName().getValue();
    ServiceModel serviceModel = null;
    setCanProcess(true);
    for (AnnotationAttachmentNode attachmentNode : annotations) {
        String annotationKey = attachmentNode.getAnnotationName().getValue();
        try {
            switch(annotationKey) {
                case "Service":
                    serviceModel = kubernetesAnnotationProcessor.processServiceAnnotation(endpointName, attachmentNode);
                    kubernetesDataHolder.addServiceModel(endpointName, serviceModel);
                    break;
                case "Deployment":
                    kubernetesDataHolder.setDeploymentModel(kubernetesAnnotationProcessor.processDeployment(attachmentNode));
                    break;
                default:
                    break;
            }
        } catch (KubernetesPluginException e) {
            dlog.logDiagnostic(Diagnostic.Kind.ERROR, endpointNode.getPosition(), e.getMessage());
        }
    }
    List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangEndpoint) endpointNode).configurationExpr).getKeyValuePairs();
    for (BLangRecordLiteral.BLangRecordKeyValue keyValue : keyValues) {
        String key = keyValue.getKey().toString();
        switch(key) {
            case "port":
                int port = Integer.parseInt(keyValue.getValue().toString());
                kubernetesDataHolder.addPort(port);
                if (serviceModel != null) {
                    serviceModel.setPort(port);
                }
                break;
            case "secureSocket":
                List<BLangRecordLiteral.BLangRecordKeyValue> sslKeyValues = ((BLangRecordLiteral) keyValue.valueExpr).getKeyValuePairs();
                try {
                    Set<SecretModel> secretModels = kubernetesAnnotationProcessor.processSecureSocketAnnotation(endpointName, sslKeyValues);
                    kubernetesDataHolder.addEndpointSecret(endpointName, secretModels);
                    kubernetesDataHolder.addSecrets(secretModels);
                } catch (KubernetesPluginException e) {
                    dlog.logDiagnostic(Diagnostic.Kind.ERROR, null, e.getMessage());
                }
                break;
            default:
                break;
        }
    }
}
Also used : ServiceModel(org.ballerinax.kubernetes.models.ServiceModel) KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) SecretModel(org.ballerinax.kubernetes.models.SecretModel) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 17 with AnnotationAttachmentNode

use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project kubernetes by ballerinax.

the class KubernetesPlugin method process.

@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
    setCanProcess(true);
    Set<String> endpoints = extractEndpointName(serviceNode);
    for (AnnotationAttachmentNode attachmentNode : annotations) {
        String annotationKey = attachmentNode.getAnnotationName().getValue();
        try {
            switch(annotationKey) {
                case "Ingress":
                    kubernetesDataHolder.addIngressModel(kubernetesAnnotationProcessor.processIngressAnnotation(serviceNode.getName().getValue(), attachmentNode), endpoints);
                    break;
                case "HPA":
                    kubernetesDataHolder.setPodAutoscalerModel(kubernetesAnnotationProcessor.processPodAutoscalerAnnotation(attachmentNode));
                    break;
                case "Deployment":
                    kubernetesDataHolder.setDeploymentModel(kubernetesAnnotationProcessor.processDeployment(attachmentNode));
                    break;
                case "Secret":
                    kubernetesDataHolder.addSecrets(kubernetesAnnotationProcessor.processSecrets(attachmentNode));
                    break;
                case "ConfigMap":
                    try {
                        kubernetesDataHolder.addConfigMaps(kubernetesAnnotationProcessor.processConfigMap(attachmentNode));
                    } catch (KubernetesPluginException e) {
                        dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), e.getMessage());
                    }
                    break;
                case "PersistentVolumeClaim":
                    try {
                        kubernetesDataHolder.addPersistentVolumeClaims(kubernetesAnnotationProcessor.processPersistentVolumeClaim(attachmentNode));
                    } catch (KubernetesPluginException e) {
                        dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), e.getMessage());
                    }
                    break;
                default:
                    break;
            }
        } catch (KubernetesPluginException e) {
            dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), e.getMessage());
        }
    }
}
Also used : KubernetesPluginException(org.ballerinax.kubernetes.exceptions.KubernetesPluginException) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 18 with AnnotationAttachmentNode

use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.

the class HTTPServiceCompilerPlugin method process.

@Override
public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) {
    for (AnnotationAttachmentNode annotation : annotations) {
        if (!PROTOCOL_PACKAGE_HTTP.equals(((BLangAnnotationAttachment) annotation).annotationSymbol.pkgID.name.value)) {
            continue;
        }
        if (annotation.getAnnotationName().getValue().equals(ANN_NAME_HTTP_SERVICE_CONFIG) || annotation.getAnnotationName().getValue().equals(WebSocketConstants.WEBSOCKET_ANNOTATION_CONFIGURATION)) {
            handleServiceConfigAnnotation(serviceNode, (BLangAnnotationAttachment) annotation);
        }
    }
    if (HttpConstants.HTTP_SERVICE_TYPE.equals(serviceNode.getServiceTypeStruct().getTypeName().getValue())) {
        List<BLangResource> resources = (List<BLangResource>) serviceNode.getResources();
        resources.forEach(resource -> ResourceSignatureValidator.validate(resource.getParameters()));
    }
}
Also used : BLangResource(org.wso2.ballerinalang.compiler.tree.BLangResource) List(java.util.List) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 19 with AnnotationAttachmentNode

use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.

the class ServiceProtoUtils method isServerStreaming.

private static boolean isServerStreaming(ResourceNode resourceNode) {
    boolean serverStreaming = false;
    for (AnnotationAttachmentNode annotationNode : resourceNode.getAnnotationAttachments()) {
        if (!ANN_RESOURCE_CONFIG.equals(annotationNode.getAnnotationName().getValue())) {
            continue;
        }
        if (annotationNode.getExpression() instanceof BLangRecordLiteral) {
            List<BLangRecordLiteral.BLangRecordKeyValue> attributes = ((BLangRecordLiteral) annotationNode.getExpression()).getKeyValuePairs();
            for (BLangRecordLiteral.BLangRecordKeyValue attributeNode : attributes) {
                String attributeName = attributeNode.getKey().toString();
                String attributeValue = attributeNode.getValue() != null ? attributeNode.getValue().toString() : null;
                if (ANN_ATTR_RESOURCE_SERVER_STREAM.equals(attributeName)) {
                    serverStreaming = attributeValue != null && Boolean.parseBoolean(attributeValue);
                }
            }
        }
    }
    return serverStreaming;
}
Also used : BLangRecordLiteral(org.wso2.ballerinalang.compiler.tree.expressions.BLangRecordLiteral) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Example 20 with AnnotationAttachmentNode

use of org.ballerinalang.model.tree.AnnotationAttachmentNode in project ballerina by ballerina-lang.

the class AnnotationDesugar method generateAnnotations.

private void generateAnnotations(AnnotatableNode node, String key, BLangFunction target, BLangVariable annMapVar) {
    if (node.getAnnotationAttachments().size() == 0) {
        return;
    }
    BLangVariable entryVar = createAnnotationMapEntryVar(key, annMapVar, target.body, target.symbol);
    int annCount = 0;
    for (AnnotationAttachmentNode attachment : node.getAnnotationAttachments()) {
        initAnnotation((BLangAnnotationAttachment) attachment, entryVar, target.body, target.symbol, annCount++);
    }
}
Also used : BLangVariable(org.wso2.ballerinalang.compiler.tree.BLangVariable) BLangEndpoint(org.wso2.ballerinalang.compiler.tree.BLangEndpoint) AnnotationAttachmentNode(org.ballerinalang.model.tree.AnnotationAttachmentNode)

Aggregations

AnnotationAttachmentNode (org.ballerinalang.model.tree.AnnotationAttachmentNode)35 AnnotationAttachmentAttributeValueNode (org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeValueNode)18 HashMap (java.util.HashMap)12 List (java.util.List)12 LinkedList (java.util.LinkedList)11 ExternalDocs (io.swagger.models.ExternalDocs)10 Map (java.util.Map)9 Collectors (java.util.stream.Collectors)9 Lists (com.google.common.collect.Lists)8 Scheme (io.swagger.models.Scheme)8 Swagger (io.swagger.models.Swagger)8 ArrayList (java.util.ArrayList)8 Optional (java.util.Optional)8 AnnotationAttachmentAttributeNode (org.ballerinalang.model.tree.expressions.AnnotationAttachmentAttributeNode)7 LiteralNode (org.ballerinalang.model.tree.expressions.LiteralNode)7 ArrayProperty (io.swagger.models.properties.ArrayProperty)6 BooleanProperty (io.swagger.models.properties.BooleanProperty)6 IntegerProperty (io.swagger.models.properties.IntegerProperty)6 Property (io.swagger.models.properties.Property)6 StringProperty (io.swagger.models.properties.StringProperty)6