@Override public void process(SimpleVariableNode variableNode, List<AnnotationAttachmentNode> annotations) { if (!variableNode.getFlags().contains(Flag.LISTENER)) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, variableNode.getPosition(), "@kubernetes annotations are only " + "supported with listeners."); return; } for (AnnotationAttachmentNode attachmentNode : annotations) { String annotationKey = attachmentNode.getAnnotationName().getValue(); try { AnnotationProcessorFactory.getAnnotationProcessorInstance(annotationKey).processAnnotation (variableNode, attachmentNode); } catch (KubernetesPluginException e) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, variableNode.getPosition(), e.getMessage()); } } }
@Override public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs(); IstioVirtualServiceModel vsModel = this.processIstioVSAnnotation(keyValues); if (isBlank(vsModel.getName())) { vsModel.setName(getValidName(variableNode.getName().getValue()) + ISTIO_VIRTUAL_SERVICE_POSTFIX); } setDefaultValues(vsModel); KubernetesContext.getInstance().getDataHolder().addIstioVirtualServiceModel(variableNode.getName().getValue(), vsModel); }
private static DocAttachmentInfo getTypeNodeDocumentation(BLangTypeDefinition typeNode) { List<String> attributes = new ArrayList<>(); DiagnosticPos typeNodePos = CommonUtil.toZeroBasedPosition(typeNode.getPosition()); int offset = typeNodePos.getStartColumn(); List<BLangAnnotationAttachment> annotations = typeNode.getAnnotationAttachments(); Position docStart = getDocumentationStartPosition(typeNode.getPosition(), annotations); List<VariableNode> publicFields = new ArrayList<>(); if (typeNode.symbol.kind == SymbolKind.OBJECT) { publicFields.addAll(((BLangObjectTypeNode) typeNode.typeNode).getFields() .stream() .filter(field -> field.getFlags().contains(Flag.PUBLIC)) .collect(Collectors.toList())); } else if (typeNode.symbol.kind == SymbolKind.RECORD) { publicFields.addAll(((BLangRecordTypeNode) typeNode.typeNode).getFields()); } publicFields.forEach(variableNode -> attributes.add(getDocAttributeFromBLangVariable((BLangSimpleVariable) variableNode, offset))); return new DocAttachmentInfo(getDocumentationAttachment(attributes, offset), docStart); }
dlog.logDiagnostic(Diagnostic.Kind.ERROR, variableNode.getPosition(), e.getMessage());
@Override public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { List<BLangRecordLiteral.BLangRecordKeyValue> keyValues = ((BLangRecordLiteral) ((BLangAnnotationAttachment) attachmentNode).expr).getKeyValuePairs(); IstioGatewayModel gwModel = this.processIstioGatewayAnnotation(keyValues); if (isBlank(gwModel.getName())) { gwModel.setName(getValidName(variableNode.getName().getValue()) + ISTIO_GATEWAY_POSTFIX); } setDefaultValues(gwModel); KubernetesContext.getInstance().getDataHolder().addIstioGatewayModel(variableNode.getName().getValue(), gwModel); }
String name = parameter.getName().getValue();
@Override public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { ServiceModel serviceModel = getServiceModelFromAnnotation(attachmentNode); if (isBlank(serviceModel.getName())) { serviceModel.setName(getValidName(variableNode.getName().getValue()) + SVC_POSTFIX); } // If service annotation port is not empty, then listener port is used for the k8s svc target port while // service annotation port is used for k8s port. // If service annotation port is empty, then listener port is used for both port and target port of the k8s // svc. BLangTypeInit bListener = (BLangTypeInit) ((BLangSimpleVariable) variableNode).expr; if (serviceModel.getPort() == -1) { serviceModel.setPort(extractPort(bListener)); } serviceModel.setTargetPort(extractPort(bListener)); KubernetesContext.getInstance().getDataHolder().addBListenerToK8sServiceMap(variableNode.getName().getValue() , serviceModel); }
@Override public void processAnnotation(SimpleVariableNode variableNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { IngressModel ingressModel = getIngressModelFromAnnotation(attachmentNode); String listenerName = variableNode.getName().getValue(); if (isBlank(ingressModel.getName())) { ingressModel.setName(getValidName(listenerName) + INGRESS_POSTFIX); } if (isBlank(ingressModel.getHostname())) { ingressModel.setHostname(getValidName(listenerName) + INGRESS_HOSTNAME_POSTFIX); } ingressModel.setListenerName(listenerName); BLangTypeInit bListener = (BLangTypeInit) ((BLangSimpleVariable) variableNode).expr; if (bListener.argsExpr.size() == 2) { if (bListener.argsExpr.get(1) instanceof BLangNamedArgsExpression) { BLangNamedArgsExpression configArg = (BLangNamedArgsExpression) bListener.argsExpr.get(1); BLangRecordLiteral bConfigRecordLiteral = (BLangRecordLiteral) configArg.expr; List<BLangRecordLiteral.BLangRecordKeyValue> listenerConfig = bConfigRecordLiteral.getKeyValuePairs(); processListener(listenerName, listenerConfig); } } KubernetesContext.getInstance().getDataHolder().addIngressModel(ingressModel); }