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; }
@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)); }
if (servicepkg instanceof ServiceNode) { ServiceNode pkg = ((ServiceNode) servicepkg); services.add(pkg.getName().getValue());
/** * 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(); 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); }
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 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); }
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(); }
@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 }
@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); }
String listenerName = serviceNode.getName().getValue(); if (isBlank(ingressModel.getName())) { ingressModel.setName(getValidName(listenerName) + ANONYMOUS_POSTFIX + INGRESS_POSTFIX);
secretModel.setName(getValidName(serviceNode.getName().getValue()) + SECRET_POSTFIX);
private static Service getStreamingServiceDefinition(ServiceNode serviceNode, ServiceConfiguration serviceConfig, File.Builder fileBuilder) throws GrpcServerException { Service.Builder serviceBuilder = Service.newBuilder(serviceNode.getName().getValue()); Message requestMessage = null; Message responseMessage = null;
private static Service getUnaryServiceDefinition(ServiceNode serviceNode, File.Builder fileBuilder) throws GrpcServerException { Service.Builder serviceBuilder = Service.newBuilder(serviceNode.getName().getValue());