Giter Club home page Giter Club logo

module-ballerinax-azure.functions's Introduction

Ballerina Azure Functions Extension

Annotation based Azure Functions extension implementation for Ballerina.

Daily build Ballerina Azure Functions Build License codecov

Azure Function App Setup

  • An Azure "Function App" needs to be created in a given resource group with the following requirements
    • Runtime stack - "Java 17"
    • Hosting operating system - "Windows" (default; Linux is not supported in Azure for custom handlers at the moment)

Supported Triggers and bindings:

An Azure Function consists of a trigger and optional bindings. A trigger defines how a function is invoked. A binding is an approach in which you can declaratively connect other resources to the function. There are input and output bindings. An input binding is a source of data into the function. An output binding allows outputting data from the function to an external resource. For more information, go to Azure Functions triggers and bindings concepts.

  • HTTP - Trigger and Output Binding
  • Queue - Trigger and Output Binding
  • Blob - Trigger, Input and Output Binding
  • Twilio - Output Binding
  • CosmosDB - Trigger, Input and Output Binding
  • Timer - Trigger

Sample Code:

In Ballerina, Triggers are represented with listeners. When the af:HttpListener gets attached to the service, it implies that the function is a HTTP Trigger. The resource function behaves exactly the same as a service written from ballerina/http. It supports http:Payload, http:Header annotations for parameters. Input binding annotations can be used to annotate parameters to make use of external services in azure. if no annotations are specified for a parameter, it's identified as a query parameter.

Output bindings are defined in the return type definition. For services with the HttpListener attachment, HttpOutput is the default Output binding. Of course, you can override the default behavior by specifying them explicitly in the return type.

import ballerinax/azure.functions as af;

service / on new af:HttpListener() {
    resource function get hello(string name) returns string {
        return "Hello, " + name + "!";
    }
}

In the code sample shown above, it has an empty service path and resource path named hello. The accessor is get. It expects a request with a query parameter for the field name. The required artifact generation and data binding will be handled by ballerinax/azure.functions package automatically.

The Azure Functions functionality is implemented as a compiler extension. Thus, artifact generation happens automatically when you build a Ballerina module. Let's see how this works by building the above code.

$ bal build
Compiling source
        wso2/azure_functions_deployment:0.1.0

Generating executable
        @azure.functions:Function: get-hello

        Execute the below command to deploy the function locally:
        func start --script-root target/azure_functions --java

        Execute the below command to deploy Ballerina Azure Functions:
        func azure functionapp publish <function_app_name> --script-root target/azure_functions 

        target/bin/azure_functions_deployment.jar

Build from the source

Set Up the prerequisites

  1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations).
  • Oracle

  • OpenJDK

    Note: Set the JAVA_HOME environment variable to the path name of the directory into which you installed JDK.

  1. Export GitHub Personal access token with read package permissions as follows,

     export packageUser=<Username>
     export packagePAT=<Personal access token>
    
  2. Download and install Docker.

Build the source

Execute the commands below to build from source.

  1. To build the library:

    ./gradlew clean build
    
  2. To run the integration tests:

    ./gradlew clean test
    
  3. To run a group of tests

    ./gradlew clean test -Pgroups=<test_group_names>
    
  4. To build the package without the tests:

    ./gradlew clean build -x test
    
  5. To debug the tests:

    ./gradlew clean test -Pdebug=<port>
    
  6. To debug with Ballerina language:

    ./gradlew clean build -PbalJavaDebug=<port>
    
  7. Publish the generated artifacts to the local Ballerina central repository:

    ./gradlew clean build -PpublishToLocalCentral=true
    
  8. Publish the generated artifacts to the Ballerina central repository:

    ./gradlew clean build -PpublishToCentral=true
    

Contribute to Ballerina

As an open source project, Ballerina welcomes contributions from the community.

For more information, go to the contribution guidelines.

Code of conduct

All contributors are encouraged to read the Ballerina Code of Conduct.

Useful links

module-ballerinax-azure.functions's People

Contributors

anupama-pathirage avatar anuruddhal avatar azinneera avatar ballerina-bot avatar buddhiwathsala avatar gabilang avatar hemikak avatar hevayo avatar keizer619 avatar kishanthan avatar lafernando avatar maheshika avatar manuranga avatar mohamedsabthar avatar nadeeshan96 avatar nipunaranasinghe avatar niveathika avatar pubudu91 avatar thevakumar-luheerathan avatar thisaruguruge avatar warunalakshitha avatar xlight05 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

module-ballerinax-azure.functions's Issues

Migrate to new service syntax

Description:

  • Migrate to new Ballerina service syntax

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

Update BBE with httpTriggerBlobOutput example

Description:
Update the BBE to include the following scenario.

@af:Function
public function httpTriggerBlobOutput2(@af:HTTPTrigger { } af:HTTPRequest req, 
        @af:BlobOutput { path: "bpath1/{Query.name}" } af:BytesOutputBinding bb)
        returns @af:HTTPOutput string|error {
    bb.value = [65, 66, 67, 97, 98];
    return "Blob: " + req.query["name"].toString() + " Content: " + 
            bb?.value.toString();
}

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

Ensure Faas functions are isolated

Description:

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

Design the new API for service based azure functions

Description:
$Subject. Explore the possible api design and look into the implementation details of the approaches.

Describe your task(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

Evaluate a Testing story for azure functions

Description:
Currently, we don't have a proper way of testing the azure functions users has written. we need to evaluate a a way to provide this functionality for the user.

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

Bump Gradle Version

Description:
$Subject. We need to migrate to gradle 7.2 as its used in http and other modules.

Describe your problem(s)

Describe your solution(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

Convert to Github packages

Description:
Convert the current jenkins based artifacts to Github packages.

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

Break azure functions BBE into smaller scenarios

Description:
Currently, The BBEs contains all the scenarios supported from the module. BBEs should be small and focused at one specific use case. We need to break the existing BBEs into smaller scenarios and introduce more organized BBE.

Describe your task(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

Pure HTTP Functions Not Working

The following code:

import ballerina/http;
import ballerinax/azure.functions as af;

@af:Function
public function hello(@af:HTTPTrigger { authLevel: "anonymous" } http:Request req) 
                      returns @af:HTTPOutput string|error {
    return "Hello, " + check <@untainted> req.getTextPayload() + "!";
}

The execution of the above function fails with the below error:

2020-08-05T03:24:00.722 [Information] Executing 'Functions.hello' (Reason='This function was programmatically called via the host APIs.', Id=c9287ccd-3d0f-4285-b4ba-3ae4f7ec1287)
2020-08-05T03:24:00.836 [Error] Executed 'Functions.hello' (Failed, Id=c9287ccd-3d0f-4285-b4ba-3ae4f7ec1287, Duration=88ms)
No MediaTypeFormatter is available to read an object of type 'HttpScriptInvocationResult' from content with media type 'text/plain'.

This issue is due to a functionality change that is done in Azure Functions. This issue can be tracked from here: Azure/azure-functions-host#6462

An immediate workaround for this is to edit the generated host.json file inside the jar file, and replace "customHandler" name with "httpWorker".

Affected versions: Ballerina v1.2.7 and slp3.

[Service Based Implementation] Implement Input bindings

Description:
Since input bindings are not supported for http or queues, we need to look into another input binding like blobs to get the architecture right.

Describe your problem(s)

Describe your solution(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

Disallow using Azure Functions in Submodules

Description:
As discussed, it does not make sense to have public faas functions in submodules as they are public and should belong in the default module.

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

Disallow having main function in Azure Functions module

Description:
As Azure Functiosn are executed in a different way, having main method does not make sense in azure functions. Having an intermediate azure function solves initializing logic problem. Therefore disable having main function in the default module.

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

[Service Based Implementation] Implement Queue Trigger Listener Implementation

Description:
$Subject

listener af:QueueTrigger afL = @af:SomeAnnotation { somestuff } new();

service af:QueueTriggerService NameForAF on afL {
  remote function onMessage(string data, @af:BlobInput {} byte[] input) returns @af:BlobOut {} byte[] {
  }
}
  • Routing and invoking the user defined function
  • Payload data binding

Describe your task(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

Handle Isolated status for generated functions

Description:
$Subject. As code generator gives warningWARNING [az-func-generated_1.bal:(73:2,73:2)] concurrent calls will not be made to this method since the method is not an 'isolated' method.

Describe your problem(s)

Describe your solution(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

Migrate Azure Functions to use New Compiler API

Description:
Currently, Azure functions works by modifying the AST using PackageNode block in compiler extensions. We need to migrate this using codeAnylaze(Project project) block with new compiler apis.

Improve Code Coverage of the azf module

Description:
$Subject

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

Make Azure Function deployment context serializable.

Description:
We need to explore if we can make context serializable, As a temp solution for ballerina-platform/ballerina-lang#34296 . I've got stackoverflow error when i tried to do this.
Current we store multiple syntax tree nodes here, we need to avoid this only store required fields in the context.

Describe your task(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

[Service Based Implementation] Implement Output bindings

Description:
$Subject. compiler extension and runtime should be able to generate outputs accordinly. it should support automatic data binding as well.

Describe your problem(s)

Describe your solution(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

Azure Function payload returns Url

Description:
$Subject.
Consider the reproduce steps below. After invoking the function we get the hello response but as the payload it gives the url of the function. Ex - Hello, https://sl-alpha.azurewebsites.net/api/hello!%

Affected Product Version:
alpha

OS, DB, other environment details and versions:

Steps to reproduce:
Copy the code from below repo readme
https://github.com/ballerina-platform/module-ballerinax-azure.functions

Create the App function in azure porttal
Build the bal file and deploy in azure.
Invoke the function using
curl -d "Jack" https://sl-alpha.azurewebsites.net/api/hello

Disallow single file projects for azure functions

Description:
$Subject. as the new compiler ext does not single file project codegen.

Describe your problem(s)

Describe your solution(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

Generate resource functions for azure functions

Description:
In the current implementation service is located in code.bal and we use function pointer map for route between functions. Instead of this, compiler extension should generate a service that has resource functions for each function.

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

Migrate Azure functions module to Java 11

Description:

  • Migrate Azure functions module to Java 11

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

Queue Input Parameters with JSON Values Not Properly Unescaped

Currently if we set a JSON content to a queue entry, when it's read by an Azure function as a parameter in Ballerina, it's representation is still in a JSON string escaped representation. This should be properly unescaped, so the value will be the same as it was put in.

Implement data binding according to http:Payload spec

Description:
https://github.com/ballerina-platform/module-ballerina-http/blob/master/docs/spec/spec.md#2344-payload-parameter

Above document defines set of rules based on the content type header and the types available. We need to reuse http libs if possible or implement the data binding according to this specification.

Describe your problem(s)

Describe your solution(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

[Service Based Implementation] Implement HTTP Trigger Listener Implementation

Description:

import ballerinax/azure.functions as af;

listener af:HttpTrigger afL = @af:SomeAnnotation { somestuff } new();

service /foo on afL {
  resource function get f1/[string s](int id, @af:payload  json pl) {
  }
  resource function post bar(@http:Payload json pl,
                             @af:Input{MSSQL: “select * from ..” table<Person> tp) {
  }
}

The http trigger should align with http resource methods design. It should support these following features

  • Routing and invoking the user written function.
  • Payload automatic data binding
  • Query Parameters
  • Path Parameters

Describe your task(s)

Related Issues (optional):

Suggested Labels (optional):

Suggested Assignees (optional):

Push Azure functions module to ballerina central

Description:
We need to make new-extension branch master before doing this.
Pushing azure functions to ballerina central is required to remove ballerinax repos from distribution.

Suggested Labels:

Suggested Assignees:

Affected Product Version:

OS, DB, other environment details and versions:

Steps to reproduce:

Related Issues:

Improve Error Logging for Functions

Currently, when an error situation happens inside a function, the Azure tracing logs simply mentions, it's an HTTP 500, and it does not show the actual error. We need these errors to be properly shown in the function logs, and also possibly provide the input request details in order to debug the situation.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.