Skip to content

Commit

Permalink
first darft of indexer java function
Browse files Browse the repository at this point in the history
  • Loading branch information
dantelmomsft committed Jan 3, 2024
1 parent 87f5fb6 commit bd63b26
Show file tree
Hide file tree
Showing 9 changed files with 245 additions and 18 deletions.
6 changes: 6 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"recommendations": [
"ms-azuretools.vscode-azurefunctions",
"vscjava.vscode-java-debug"
]
}
13 changes: 13 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to Java Functions",
"type": "java",
"request": "attach",
"hostName": "127.0.0.1",
"port": 5005,
"preLaunchTask": "func: host start"
}
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"azureFunctions.javaBuildTool": "maven",
"azureFunctions.deploySubpath": "app/indexer/functions/target/azure-functions/indexer-blob-processor",
"azureFunctions.projectLanguage": "Java",
"azureFunctions.projectRuntime": "~4",
"debug.internalConsoleOptions": "neverOpen",
"azureFunctions.projectSubpath": "app/indexer/functions",
"azureFunctions.preDeployTask": "package (functions)"
}
59 changes: 41 additions & 18 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,43 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Start App ",
"type": "shell",
"command": "${workspaceFolder}/app/start.sh",
"windows": {
"command": "pwsh ${workspaceFolder}/app/start.ps1"
},
"presentation": {
"reveal": "always"
},
"options": {
"cwd": "${workspaceFolder}/app"
},
"problemMatcher": []
}
]
"version": "2.0.0",
"tasks": [
{
"label": "Start App ",
"type": "shell",
"command": "${workspaceFolder}/app/start.sh",
"windows": {
"command": "pwsh ${workspaceFolder}/app/start.ps1"
},
"presentation": {
"reveal": "always"
},
"options": {
"cwd": "${workspaceFolder}/app"
},
"problemMatcher": []
},
{
"type": "func",
"label": "func: host start",
"command": "host start",
"problemMatcher": "$func-java-watch",
"isBackground": true,
"options": {
"cwd": "${workspaceFolder}/app/indexer/functions/target/azure-functions/indexer-blob-processor"
},
"dependsOn": "package (functions)"
},
{
"label": "package (functions)",
"command": "mvn clean package",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
"options": {
"cwd": "${workspaceFolder}/app/indexer/functions"
}
}
]
}
39 changes: 39 additions & 0 deletions app/indexer/functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Build output
target/
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

# IDE
.idea/
*.iml
.settings/
.project
.classpath
.vscode/

# macOS
.DS_Store

# Azure Functions
local.settings.json
bin/
obj/
7 changes: 7 additions & 0 deletions app/indexer/functions/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[4.0.0, 5.0.0)"
}
}
101 changes: 101 additions & 0 deletions app/indexer/functions/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8" ?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>


<parent>
<groupId>com.microsoft.openai.samples</groupId>
<artifactId>indexer-parent</artifactId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>


<artifactId>indexer-functions</artifactId>
<version>1.0-SNAPSHOT</version>


<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>17</java.version>
<azure.functions.maven.plugin.version>1.29.0</azure.functions.maven.plugin.version>
<azure.functions.java.library.version>3.0.0</azure.functions.java.library.version>
<functionAppName>indexer-blob-processor</functionAppName>
</properties>

<dependencies>
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library</artifactId>
<version>${azure.functions.java.library.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-functions-maven-plugin</artifactId>
<version>${azure.functions.maven.plugin.version}</version>
<configuration>
<!-- function app name -->
<appName>${functionAppName}</appName>
<!-- function app resource group -->
<resourceGroup>java-functions-group</resourceGroup>
<!-- function app service plan name -->
<appServicePlanName>java-functions-app-service-plan</appServicePlanName>
<!-- function app region-->
<!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details#supported-regions for all valid values -->
<region>westus</region>
<!-- function pricingTier, default to be consumption if not specified -->
<!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details#supported-pricing-tiers for all valid values -->
<!-- <pricingTier></pricingTier> -->
<!-- Whether to disable application insights, default is false -->
<!-- refers https://github.com/microsoft/azure-maven-plugins/wiki/Azure-Functions:-Configuration-Details for all valid configurations for application insights-->
<!-- <disableAppInsights></disableAppInsights> -->
<runtime>
<!-- runtime os, could be windows, linux or docker-->
<os>linux</os>
<javaVersion>17</javaVersion>
</runtime>
<appSettings>
<property>
<name>FUNCTIONS_EXTENSION_VERSION</name>
<value>~4</value>
</property>
</appSettings>
</configuration>
<executions>
<execution>
<id>package-functions</id>
<goals>
<goal>package</goal>
</goals>
</execution>
</executions>
</plugin>
<!--Remove obj folder generated by .NET SDK in maven clean-->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
<configuration>
<filesets>
<fileset>
<directory>obj</directory>
</fileset>
</filesets>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.microsoft.openai.samples.indexer.functions;

import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
import com.microsoft.azure.functions.HttpRequestMessage;
import com.microsoft.azure.functions.HttpResponseMessage;
import com.microsoft.azure.functions.HttpStatus;
import com.microsoft.azure.functions.annotation.*;

import java.util.Optional;

/**
* Azure Functions with Blob Trigger.
*/
public class BlobProcessorFunction {
@FunctionName("BlobEventGridProcessor")
/**
* This function will be invoked when a new or updated blob is detected at the specified path. The blob contents are provided as input to this function.
*/
@StorageAccount("AzureWebJobsStorage")
public void run(
@BlobTrigger(name = "content", path = "content/{filename}", dataType = "binary", source = "EventGrid" ) byte[] content,
@BindingName("filename") String filename,
final ExecutionContext context
) {
context.getLogger().info("Java Blob trigger function processed a blob. Name: " + filename + "\n Size: " + content.length + " Bytes");
}
}
1 change: 1 addition & 0 deletions app/indexer/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<modules>
<module>core</module>
<module>cli</module>
<module>functions</module>
</modules>

<dependencyManagement>
Expand Down

0 comments on commit bd63b26

Please sign in to comment.