@Override public void process(ServiceNode serviceData, List<AnnotationAttachmentNode> annotations) { List<BLangFunction> resources = (List<BLangFunction>) serviceData.getResources(); resources.forEach(res -> validate(serviceData.getName().getValue(), res, this.dlog)); }
@SuppressWarnings("unchecked") @Override public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) { int serviceConfigCount = 0; for (AnnotationAttachmentNode annotation : annotations) { if (annotation.getAnnotationName().getValue().equals(ANN_NAME_HTTP_SERVICE_CONFIG)) { handleServiceConfigAnnotation(serviceNode, (BLangAnnotationAttachment) annotation); serviceConfigCount++; } } if (serviceConfigCount > 1) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), "multiple service configuration annotations found in service : " + serviceNode.getName().getValue()); } // final UserDefinedTypeNode serviceType = serviceNode.getServiceTypeStruct(); // if (serviceType != null && HttpConstants.HTTP_SERVICE_TYPE.equals(serviceType.getTypeName() // .getValue())) { List<BLangFunction> resources = (List<BLangFunction>) serviceNode.getResources(); resources.forEach(res -> { ResourceSignatureValidator.validateAnnotation(res, dlog); ResourceSignatureValidator.validate(res.getParameters(), dlog, res.pos); ResourceSignatureValidator.validateResourceReturnType(isResourceReturnsErrorOrNil(res), dlog, res.pos); }); // } // get value from endpoint. // ((BLangSimpleVarRef) serviceNode.getBoundEndpoints().get(0)).varSymbol.getType().tsymbol.name.value }
private static boolean validateAnnotation(ServiceNode serviceNode, DiagnosticLog dlog) { List<AnnotationAttachmentNode> annotations = (List<AnnotationAttachmentNode>) serviceNode.getAnnotationAttachments(); List<BLangRecordLiteral.BLangRecordKeyValue> annVals = new ArrayList<>(); int count = 0; dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), "There cannot be more than one service annotations"); return false;
private String getOutputFilePath(ServiceNode serviceNode) { String cUnit = serviceNode.getPosition().getSource().getCompilationUnitName(); String dir = cUnit.substring(0, cUnit.lastIndexOf(File.separator) + 1); String file = serviceNode.getName().getValue().toLowerCase(Locale.ENGLISH) + "_client.bal"; return dir + file; }
@SuppressWarnings("unchecked") @Override public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) { if (annotations.size() > 1) { int count = 0; for (AnnotationAttachmentNode annotation : annotations) { if (annotation.getAnnotationName().getValue().equals(WEBSOCKET_ANNOTATION_CONFIGURATION)) { count++; } } if (count > 1) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), "There cannot be more than one " + WEBSOCKET_SERVICE + " annotations"); } } List<BLangFunction> resources = (List<BLangFunction>) serviceNode.getResources(); resources.forEach( res -> WebSocketResourceValidator.validate(res, dlog, isResourceReturnsErrorOrNil(res), false)); } }
if (servicepkg instanceof ServiceNode) { ServiceNode pkg = ((ServiceNode) servicepkg); services.add(pkg.getName().getValue());
service.getAnnotationAttachments()); Info info = new Info().version("1.0.0").title(service.getName().getValue()); if (annotation != null) { BLangRecordLiteral bLiteral = ((BLangRecordLiteral) ((BLangAnnotationAttachment) annotation)
@Override public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) { for (AnnotationAttachmentNode attachmentNode : annotations) { String annotationKey = attachmentNode.getAnnotationName().getValue(); try { AnnotationProcessorFactory.getAnnotationProcessorInstance(annotationKey).processAnnotation (serviceNode, attachmentNode); } catch (KubernetesPluginException e) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), e.getMessage()); } } }
@SuppressWarnings("unchecked") @Override public void process(ServiceNode serviceNode, List<AnnotationAttachmentNode> annotations) { List<BLangFunction> resources = (List<BLangFunction>) serviceNode.getResources(); resources.forEach( res -> WebSocketResourceValidator.validate(res, dlog, isResourceReturnsErrorOrNil(res), true)); } }
/** * Build a parsable object model for a service endpoint. {@code ep} must be bound to the {@code service} * inorder to extract its details. If {@code ep} is not bound to the {@code service} null * will be returned * * @param service service with bound endpoints * @param ep {@link EndpointNode} which to extract details from * @return if {@code ep} is bound to the {@code service}, endpoint context will be returned. * otherwise empty null will be returned */ public static EndpointContextHolder buildContext(ServiceNode service, EndpointNode ep) { EndpointContextHolder endpoint = null; for (SimpleVariableReferenceNode node : service.getBoundEndpoints()) { if (node.getVariableName().equals(ep.getName())) { endpoint = new EndpointContextHolder(); AnnotationAttachmentNode ann = GeneratorUtils .getAnnotationFromList("ServiceConfig", GeneratorConstants.HTTP_PKG_ALIAS, service.getAnnotationAttachments()); endpoint.extractDetails(ep, ann); break; } } return endpoint; }
private void addDescriptorAnnotation(ServiceNode serviceNode, String rootDescriptor) { for (AnnotationAttachmentNode annonNodes : serviceNode.getAnnotationAttachments()) { if (ANN_SERVICE_DESCRIPTOR.equals(annonNodes.getAnnotationName().getValue())) { return; serviceNode.addAnnotationAttachment(annoAttachment); final SymbolEnv pkgEnv = symTable.pkgEnvMap.get(service.symbol.getEnclosingSymbol()); BSymbol annSymbol = symResolver.lookupSymbolInPackage(service.pos, pkgEnv, names.fromString
/** * Parses the ballerina/http@config annotation and builds swagger definition. Also create the consumes and * produces annotations. * * @param service The ballerina service which has the annotation. * @param swagger The swagger to build up. */ private void parseConfigAnnotationAttachment(ServiceNode service, Swagger swagger) { AnnotationAttachmentNode annotation = ConverterUtils .getAnnotationFromList(HttpConstants.ANN_NAME_HTTP_SERVICE_CONFIG, httpAlias, service.getAnnotationAttachments()); if (annotation != null) { BLangRecordLiteral bLiteral = ((BLangRecordLiteral) ((BLangAnnotationAttachment) annotation) .getExpression()); List<BLangRecordKeyValue> list = bLiteral.getKeyValuePairs(); Map<String, BLangExpression> attributes = ConverterUtils.listToMap(list); if (attributes.containsKey(HttpConstants.ANN_CONFIG_ATTR_BASE_PATH)) { swagger.setBasePath( ConverterUtils.getStringLiteralValue(attributes.get(HttpConstants.ANN_CONFIG_ATTR_BASE_PATH))); } } }
@Override public void processAnnotation(ServiceNode serviceNode, 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(serviceNode.getName().getValue()) + ISTIO_VIRTUAL_SERVICE_POSTFIX); } setDefaultValues(vsModel); KubernetesContext.getInstance().getDataHolder().addIstioVirtualServiceModel(serviceNode.getName().getValue(), vsModel); }
static File generateProtoDefinition(ServiceNode serviceNode) throws GrpcServerException { // Protobuf file definition builder. String packageName = serviceNode.getPosition().getSource().getPackageName(); File.Builder fileBuilder; if (!NO_PACKAGE_PATH.equals(packageName)) { fileBuilder = File.newBuilder(serviceNode.getName() + ServiceProtoConstants.PROTO_FILE_EXTENSION) .setSyntax(ServiceProtoConstants.PROTOCOL_SYNTAX).setPackage(serviceNode.getPosition().getSource() .getPackageName()); } else { fileBuilder = File.newBuilder(serviceNode.getName() + ServiceProtoConstants.PROTO_FILE_EXTENSION) .setSyntax(ServiceProtoConstants.PROTOCOL_SYNTAX); } ServiceConfiguration serviceConfig = getServiceConfiguration(serviceNode); Service serviceDefinition; if (serviceConfig.getRpcEndpoint() != null && (serviceConfig.isClientStreaming())) { serviceDefinition = getStreamingServiceDefinition(serviceNode, serviceConfig, fileBuilder); } else { serviceDefinition = getUnaryServiceDefinition(serviceNode, fileBuilder); } fileBuilder.setService(serviceDefinition); return fileBuilder.build(); }
private static boolean validateResource(ServiceNode serviceNode, DiagnosticLog dlog) { List<BLangFunction> resources = (List<BLangFunction>) serviceNode.getResources(); ServiceConfiguration serviceConfig = getServiceConfiguration(serviceNode); if (serviceConfig.getRpcEndpoint() != null && (serviceConfig.isClientStreaming())) { if (resources.size() != 4) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), "There should be four resources defined in client/bidirectional streaming services"); return false; return true; } else { dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), "One or more resources(onOpen/onMessage/onError/onComplete) is not implemented in " + "client/bidirectional streaming service");
dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), "Invalid multiple configurations for compression"); return; MimeUtil.validateContentType(contentType); } catch (MimeTypeParseException e) { dlog.logDiagnostic(Diagnostic.Kind.ERROR, serviceNode.getPosition(), "Invalid Content-Type value for compression: '" + contentType + "'"); return;
boolean serverStreaming = false; for (AnnotationAttachmentNode annotationNode : serviceNode.getAnnotationAttachments()) { if (!ServiceProtoConstants.ANN_SERVICE_CONFIG.equals(annotationNode.getAnnotationName().getValue())) { continue;
/** * Build a parsable context from a Ballerina {@link ServiceNode}. * * @param service {@code ServiceNode} for a valid ballerina source file * @param endpoints list of endpoints to be used as service endpoints for generated client * @return A parsable data model for provided ballerina {@code service} * @throws CodeGeneratorException when there are generation exceptions */ public static ClientContextHolder buildContext(ServiceNode service, List<EndpointNode> endpoints) throws CodeGeneratorException { ClientContextHolder context = new ClientContextHolder(); context.name = service.getName().getValue(); context.resources = new ArrayList<>(); context.endpoints = new ArrayList<>(); // Extract bound endpoint details for (EndpointNode ep : endpoints) { EndpointContextHolder epContext = EndpointContextHolder.buildContext(service, ep); if (epContext != null) { context.endpoints.add(EndpointContextHolder.buildContext(service, ep)); } } // Extract ballerina resource nodes as parsable resources for (ResourceNode resource: service.getResources()) { ResourceContextHolder operation = ResourceContextHolder.buildContext(resource); context.resources.add(operation); } return context; }
@Override public void processAnnotation(ServiceNode serviceNode, 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(serviceNode.getName().getValue()) + ISTIO_GATEWAY_POSTFIX); } setDefaultValues(gwModel); KubernetesContext.getInstance().getDataHolder().addIstioGatewayModel(serviceNode.getName().getValue(), gwModel); }
dlog.logDiagnostic(Diagnostic.Kind.ERROR, service.getPosition(), e.getMessage());