What are Functions:
"Oracle Functions is based on Fn Project. Fn project is an open source, container native, serverless platform that can be run anywhere, It's easy to use, supports every programming languages, and is extensible and performant"
These functions can be written in a variety of languages - Java , Python, Node etc. You write and deploy the code, Oracle takes care of provisioning, scaling etc.
How do Oracle Functions enhance the OIC experience?
Suppose you are porting SOA composites to OIC and you want to use of Java embedding in your BPEL process. Where we shall the code in OIC? Functions can be leveraged to implement business logic that can not be defined using standard OIC actions. We can use javascript feature but that to have its limitation upto a level.
Function Creation Steps:
Step1: Create an application
Sign into the OCI console >> Navigation menu >> Developer Services >> Functions >> Applications >> choose the compartment >> Click Create Application
Provide Application name like
helloworld-app. Select VCN and subnet in which to run the function.
Here , Selected a public subnet. >> click create.
Note: a Public subnet requires an Internet gateway in the VCN and a private subnet requires a service gateway in the VCN.
Step2 : Setup your Cloud Shell dev Environment.
On the applications page >> click your app , here, helloworld-app. >> click Getting started link >> click Cloud Shell Setup.
Step3: setup Fn CLI on Cloud Shell
Most of all details we will get in the getting started page steps. So dont worry of the <> bracket details.
A. Use the context for your region
fn list context
fn use context <region-context>
My case region-context = us-ashburn-1
B. Update the context with the functions compartment ID
fn update context oracle.compartment-id <compartment-ocid>
C. Provide a unique repository name prefix to distinguish your function images from other people's.
fn update context registry <region-key>.ocir.io/<tenancy-namespace>/<repo-name-prefix>
Example:
fn update context registry iad.ocir.io/idsvxxxxxxxx/test-repo
D. Generate an Auth Token : click Generate an Auth token to display the Auth token pages >> click Generate Token >> Enter a meaningful auth token name and generate token >> copy the auth token >> close.
E. Log into the Registry using retrieved Auth Token as your password.
docker login -u '<tenancy-namespace>/<user-name>' <region-key>.ocir.io
For example:
docker login -u 'idsvxxxxxxxx/cloudconsole/xxxxx' iad.ocir.io
F. Verify your setup by listing applications in the compartment
fn list apps
Step4: Create , Deploy and Invoke your function
G. Generate a hello- world function
fn init --runtime java hello-java
This will create the following in the hello-java directory:
- func.yaml: function definition file
- /src directory: Contains source files and directories for the helloworld function
- pom.xml : a Maven config file that specifies the dependencies required to compile the function.
H. Switch into the generated directory
cd hello-java
Traverse following folders to see the created deafult java helloworld code:
src >> main >> java >> com >> example >> fn >> HelloFunction.java
cat HelloFunction.java
package com.example.fn;
public class HelloFunction {
public String handleRequest(String input){
String name = (input == null || input.isEmpty()) ? "world" : input;
System.out.println("Inside Java Hello World function");
return "Hello, " + name + "!";
}
}
I. Deploy your fucntion
fn -v deploy --app helloworld-app
J. INVOKE or Test your function
fn invoke helloworld-app hello-java
Note: Suppose you want to create custom java code , then you have to modify the entry in the func.yaml and pom.xml files accordingly.
Step5: click the Functions >> see the created the hello-java function and invoke endpoint details.
Step6: Enable the logging:
References:
https://docs.oracle.com/en-us/iaas/Content/Functions/Tasks/functionsquickstartcloudshell.htm#