@Override public String toString() { return "BLangService: " + flagSet + " " + annAttachments + " " + getName(); } }
@Override public void addAnnotationAttachment(AnnotationAttachmentNode annAttachment) { this.getAnnotationAttachments().add((BLangAnnotationAttachment) annAttachment); }
public static ServiceNode createServiceNode() { return new BLangService(); }
/** * This method will convert ballerina @Service to swaggers @Swagger object. * * @param service ballerina @Service object to be map to swagger definition * @param swagger Swagger model to populate * @return Swagger object which represent current service. */ public Swagger convertServiceToSwagger(BLangService service, Swagger swagger) { // Setting default values. swagger.setBasePath('/' + service.getName().getValue()); this.parseServiceInfoAnnotationAttachment(service, swagger); this.parseConfigAnnotationAttachment(service, swagger); SwaggerResourceMapper resourceMapper = new SwaggerResourceMapper(swagger, this.httpAlias, this.swaggerAlias); swagger.setPaths(resourceMapper.convertResourceToPath(service.getResources())); return swagger; }
BType listenerType; if ((listenerType = serviceListenerMap.get(plugin)) != null) { for (BLangExpression expr : serviceNode.getAttachedExprs()) { if (!types.isSameType(expr.type, listenerType)) { continue; for (FunctionNode function : serviceNode.getResources()) { final BLangFunction resourceNode = (BLangFunction) function; if (resourceNode.symbol.params.stream().filter(varSym -> varSym.type.tsymbol != null)
for (BLangExpression attachedExpr : bService.getAttachedExprs()) { if (attachedExpr instanceof BLangTypeInit) { BLangTypeInit bListener = (BLangTypeInit) attachedExpr;
public HttpServiceTemplate(BLangPackage builtTestFile, BLangService service, BLangTypeInit init, BiConsumer<Integer, Integer> focusLineAcceptor) { super(builtTestFile, focusLineAcceptor); String serviceName = service.name.value; String serviceUriTemp = HTTP + DEFAULT_IP + ":" + DEFAULT_PORT; boolean isSecureTemp = isSecureService(init); String protocol = ((isSecureTemp) ? HTTPS : HTTP); Optional<String> optionalPort = findServicePort(init); serviceUriTemp = optionalPort.map(port -> protocol + DEFAULT_IP + ":" + port).orElse(serviceUriTemp); this.isSecure = isSecureTemp; this.serviceUri = serviceUriTemp; // Retrieve Service base path String tempServiceBasePath = "/" + serviceName; // If service base path overridden by annotations for (BLangAnnotationAttachment annotation : service.annAttachments) { if (annotation.expr instanceof BLangRecordLiteral) { BLangRecordLiteral record = (BLangRecordLiteral) annotation.expr; Optional<String> basePath = searchStringField(HttpConstants.ANN_CONFIG_ATTR_BASE_PATH, record); tempServiceBasePath = basePath.orElse(tempServiceBasePath); } } this.serviceUriStrName = getSafeName(lowerCaseFirstLetter(serviceName) + "Uri"); this.testServiceFunctionName = getSafeName("test" + upperCaseFirstLetter(serviceName)); this.serviceBasePath = tempServiceBasePath; this.resources = service.getResources(); }
private static DocAttachmentInfo getServiceNodeDocumentation(BLangService bLangService) { DiagnosticPos servicePos = CommonUtil.toZeroBasedPosition(bLangService.getPosition()); List<BLangAnnotationAttachment> annotations = bLangService.getAnnotationAttachments(); Position docStart = getDocumentationStartPosition(bLangService.getPosition(), annotations); return new DocAttachmentInfo(getDocumentationAttachment(null, servicePos.getStartColumn()), docStart); }
serviceNode.addWS(ws); serviceNode.isAnonymousServiceValue = isAnonServiceValue; if (serviceName == null) { BLangIdentifier serviceVar = (BLangIdentifier) createIdentifier(serviceName); serviceVar.pos = identifierPos; serviceNode.setName(serviceVar); if (!isAnonServiceValue) { this.exprNodeListStack.pop().forEach(expr -> serviceNode.attachedExprs.add((BLangExpression) expr)); if (this.commaWsStack.size() > 0) { serviceNode.addWS(this.commaWsStack.pop());
@Override public void addFlag(Flag flag) { this.getFlags().add(flag); }
final BLangService serviceNode = (BLangService) service; List<BLangFunction> resources = serviceNode.getResources(); boolean validReturnType = true; for (BLangFunction resourceNode : resources) { addDescriptorAnnotation(serviceNode, bytesToHex(fileDefinition.getFileDescriptorProto().toByteArray())); FileDefinitionHolder.getInstance().addDefinition(serviceNode.getName().getValue(), fileDefinition);
KubernetesPluginException { BLangService bService = (BLangService) serviceNode; for (BLangExpression attachedExpr : bService.getAttachedExprs()) { if (attachedExpr instanceof BLangTypeInit) { throw new KubernetesPluginException("Adding @kubernetes:Ingress{} annotation to a service is only " + for (BLangExpression attachedExpr : bService.getAttachedExprs()) { if (attachedExpr instanceof BLangTypeInit) { BLangTypeInit bListener = (BLangTypeInit) attachedExpr;
@Override public void processAnnotation(ServiceNode serviceNode, AnnotationAttachmentNode attachmentNode) throws KubernetesPluginException { BLangService bService = (BLangService) serviceNode; for (BLangExpression attachedExpr : bService.getAttachedExprs()) { // If not anonymous endpoint throw error. if (attachedExpr instanceof BLangSimpleVarRef) { throw new KubernetesPluginException("Adding @kubernetes:Service{} annotation to a service is only " + "supported when the has an anonymous listener"); } } ServiceModel serviceModel = getServiceModelFromAnnotation(attachmentNode); if (isBlank(serviceModel.getName())) { serviceModel.setName(getValidName(serviceNode.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) bService.getAttachedExprs().get(0); if (serviceModel.getPort() == -1) { serviceModel.setPort(extractPort(bListener)); } serviceModel.setTargetPort(extractPort(bListener)); KubernetesContext.getInstance().getDataHolder().addBListenerToK8sServiceMap(serviceNode.getName().getValue(), serviceModel); }
private static Swagger getSwagger(Swagger swagger, SwaggerServiceMapper swaggerServiceMapper, String serviceName, BLangCompilationUnit topCompilationUnit, List<BLangSimpleVariable> endpoints) { for (TopLevelNode topLevelNode : topCompilationUnit.getTopLevelNodes()) { if (topLevelNode instanceof BLangSimpleVariable && ((BLangSimpleVariable) topLevelNode).getFlags().contains(Flag.LISTENER)) { endpoints.add((BLangSimpleVariable) topLevelNode); } if (topLevelNode instanceof BLangService) { BLangService serviceDefinition = (BLangService) topLevelNode; swagger = new SwaggerEndpointMapper() .convertBoundEndpointsToSwagger(endpoints, serviceDefinition, swagger); // Generate swagger string for the mentioned service name. if (StringUtils.isNotBlank(serviceName)) { if (serviceDefinition.getName().getValue().equals(serviceName)) { swagger = swaggerServiceMapper.convertServiceToSwagger(serviceDefinition, swagger); break; } } else { // If no service name mentioned, then generate swagger definition for the first service. swagger = swaggerServiceMapper.convertServiceToSwagger(serviceDefinition, swagger); break; } } } return swagger; }
public void visit(BLangService serviceNode) { List<BLangAnnotationAttachment> attachmentList = serviceNode.getAnnotationAttachments(); notifyProcessors(attachmentList, (processor, list) -> processor.process(serviceNode, list)); notifyServiceTypeProcessors(serviceNode, attachmentList, (processor, list) -> processor.process(serviceNode, list)); }