Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Functions]Generate function.json with only properties mentioned in annotations #466

Closed
ZhengJun003 opened this issue Nov 2, 2018 · 9 comments

Comments

@ZhengJun003
Copy link

Plugin name and version

Archetypes: 1.17-SNAPSHOT
Maven Plugin for Azure Functions: 1.00-beta-8-SNAPSHOT
Function core tools: 2.0.3
OS: Win10/Mac

Plugin configuration in your pom.xml

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <azure.functions.maven.plugin.version>1.0.0-beta-8-SNAPSHOT</azure.functions.maven.plugin.version>
        <azure.functions.java.library.version>1.0.0-beta-7-SNAPSHOT</azure.functions.java.library.version>
        <functionAppName>demo7-20181102104335824</functionAppName>
        <functionAppRegion>westus</functionAppRegion>
        <stagingDirectory>${project.build.directory}/azure-functions/${functionAppName}</stagingDirectory>
        <functionResourceGroup>java-functions-group</functionResourceGroup>
    </properties>
            <plugin>
                <groupId>com.microsoft.azure</groupId>
                <artifactId>azure-functions-maven-plugin</artifactId>
                <configuration>
                    <resourceGroup>${functionResourceGroup}</resourceGroup>
                    <appName>${functionAppName}</appName>                   
                    <region>${functionAppRegion}</region>
                    <appSettings>
                        <!-- Run Azure Function from package file by default -->
                        <property>
                            <name>WEBSITE_RUN_FROM_PACKAGE</name>
                            <value>1</value>
                        </property>
                        <property>
                            <name>FUNCTIONS_EXTENSION_VERSION</name>
                            <value>~2</value>
                        </property>
                        <property>
                            <name>FUNCTIONS_WORKER_RUNTIME</name>
                            <value>java</value>
                        </property>
                        <property>
                            <name>connection</name>
                            <value>xxxx</value>
                        </property>
                    </appSettings>
                </configuration>
                <executions>
                    <execution>
                        <id>package-functions</id>
                        <goals>
                            <goal>package</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Actual behavior

Run Cosmos DB Trigger function, report an error.
image
Can't trigger CosmosDB function in cloud after deployment.

Steps to reproduce the problem

  1. Generate a Azure Functions archetype
  2. Add following in pom.xml to get the latest azure-function-maven plugin
    <pluginRepositories>
        <pluginRepository>
            <id>maven.snapshots</id>
            <name>Maven Central Snapshot Repository</name>
            <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </pluginRepository>
    </pluginRepositories>
  1. please set<azure.functions.maven.plugin.version>1.0.0-beta-8-SNAPSHOT</azure.functions.maven.plugin.version>in pom.
  2. Add Cosmos DB Trigger function, use follow settings.
    image
@Flanker32
Copy link
Member

Maven plugin will put all attributes of CosmosDBTrigger annotations to function.json, the default value of leaseDatabaseName and leaseConnectionStringSetting are both empty and function will not work when deployed function.json contains the two empty attribtues above.

@pragnagopa Please have a view.

@pragnagopa
Copy link
Member

pragnagopa commented Nov 5, 2018

@brettsam - should we specify defaults for leaseDataBase and leaseConnection?
@Flanker32 -Can you try setting values for leaseDatabaseName and leaseConnectionString? Also share generated function.json

@Flanker32
Copy link
Member

When leaseDatabaseName and leaseCollectionName refers to an existing cosmos db collection, the trigger could work or it will break even createLeaseCollectionIfNotExists is true. (It will create an empty cosmos db but no collection)
When i set leaseConnectionString equals to connectionStringSetting, the function could work well, but the function seems break down when i want to do more experiment, it just shows can't start function host.

Here is the function.json

{
  "scriptFile" : "..\\cosmostriggertest-1.0-SNAPSHOT.jar",
  "entryPoint" : "com.ms.CosmosDBTest.run",
  "bindings" : [ {
    "type" : "cosmosDBTrigger",
    "name" : "items",
    "direction" : "in",
    "databaseName" : "ToDoList",
    "collectionName" : "Items",
    "dataType": "stream",
    "leaseCollectionName" : "FamilyCollection",
    "connectionStringSetting" : "CONNECTION_STRING",
    "createLeaseCollectionIfNotExists" : true,
    "leasesCollectionThroughput" : -1,
    "checkpointInterval" : -1,
    "checkpointDocumentCount" : -1,
    "feedPollDelay" : 5000,
    "leaseRenewInterval" : 17000,
    "leaseAcquireInterval" : 13000,
    "leaseExpirationInterval" : 60000,
    "maxItemsPerInvocation" : -1,
    "startFromBeginning" : false,
    "preferredLocations" : "",
    "leaseCollectionPrefix" : ""
    } ]
}

@pragnagopa
Copy link
Member

@ZhengJun003 - I cannot repro this issue.
@Flanker32 - Generated function.json does not look right. function.json should only contain values set by annotations. For example, following should never be part of generated function.json

"checkpointInterval" : -1

@pragnagopa pragnagopa changed the title Can't create leasecollection in database, can't trigger CosmosDB function when running function locally and deploy to portal. [Functions]Generate function.json with only properties mentioned in annotations Nov 5, 2018
@pragnagopa
Copy link
Member

Java function signature

public void CosmosTriggerAndOutput(
            @CosmosDBTrigger(name = "itemIn", databaseName = "%CosmosDBDatabaseName%", collectionName = "ItemCollectionIn", leaseCollectionName = "leases", connectionStringSetting = "AzureWebJobsCosmosDBConnectionString", createLeaseCollectionIfNotExists = true) Object inputItem,
            @CosmosDBOutput(name = "itemOut", databaseName = "%CosmosDBDatabaseName%", collectionName = "ItemCollectionOut", connectionStringSetting = "AzureWebJobsCosmosDBConnectionString") OutputBinding<Document> outPutItem,
            final ExecutionContext context)

should generate following bindings in function.json

"bindings" : [ {
    "type" : "cosmosDBTrigger",
    "name" : "itemIn",
    "direction" : "in",
    "databaseName" : "%CosmosDBDatabaseName%",
    "collectionName" : "ItemCollectionIn",
    "leaseCollectionName" : "leases",
    "connectionStringSetting" : "AzureWebJobsCosmosDBConnectionString",
    "createLeaseCollectionIfNotExists" : true
  }, {
    "type" : "cosmosdb",
    "name" : "itemOut",
    "direction" : "out",
    "databaseName" : "%CosmosDBDatabaseName%",
    "collectionName" : "ItemCollectionOut",
    "connectionStringSetting" : "AzureWebJobsCosmosDBConnectionString"
  } ]

but following is generated with all the properties on the trigger

"bindings" : [ {
    "type" : "cosmosDBTrigger",
    "name" : "itemIn",
    "direction" : "in",
    "dataType" : "",
    "databaseName" : "%CosmosDBDatabaseName%",
    "collectionName" : "ItemCollectionIn",
    "leaseCollectionName" : "leases",
    "connectionStringSetting" : "AzureWebJobsCosmosDBConnectionString",
    "createLeaseCollectionIfNotExists" : true,
    "preferredLocations" : "",
    "leasesCollectionThroughput" : -1,
    "leaseCollectionPrefix" : "",
    "checkpointInterval" : -1,
    "checkpointDocumentCount" : -1,
    "feedPollDelay" : 5000,
    "leaseRenewInterval" : 17000,
    "leaseAcquireInterval" : 13000,
    "leaseExpirationInterval" : 60000,
    "maxItemsPerInvocation" : -1,
    "startFromBeginning" : false,
    "leaseDatabaseName" : "",
    "leaseConnectionStringSetting" : ""
  }, {
    "type" : "cosmosDB",
    "name" : "itemOut",
    "direction" : "out",
    "dataType" : "",
    "collectionThroughput" : -1,
    "databaseName" : "%CosmosDBDatabaseName%",
    "collectionName" : "ItemCollectionOut",
    "connectionStringSetting" : "AzureWebJobsCosmosDBConnectionString",
    "partitionKey" : "",
    "createIfNotExists" : false,
    "useMultipleWriteLocations" : false,
    "preferredLocations" : ""
  } ]

Most of the properties are optional properties and should not be included unless explicitly provided by in the annotation

@pragnagopa
Copy link
Member

@jdneo / @Flanker32 - Updated the title to reflect the issue.

@pragnagopa
Copy link
Member

@asavaritayal FYI as this is a blocking issue.

@pragnagopa
Copy link
Member

@Flanker32 - I just tried the snapshot version, function.json now has

"dataType" : "",

even though it is not specified in the annotation. Can you take a look?

@Flanker32
Copy link
Member

@pragnagopa Fix in the latest snapshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants