美文网首页
fission on k8s,小总结&自己写个函数试试

fission on k8s,小总结&自己写个函数试试

作者: dracula337435 | 来源:发表于2019-01-01 23:22 被阅读0次

在之前《初探》之后

小总结

其实可以看出,无论是解释型,如nodejs,或者编译型,如java,都要用package来创建函数
nodejs的例子中,源码->函数,前已述及

$ fission function create --name hello --env nodejs --code hello.js

java的例子中,源码->package->函数

$ fission package create --env java --src java-src-pkg.zip
$ fission fn create --name javatest --pkg  java-src-pkg-zip-bqzg --env java --entrypoint io.fission.HelloWorld --executortype newdeploy --minscale 1 --maxscale 1

java还可以把编译完的jar直接做成一个function,见fisson的github例子,java部分

$ fission fn create --name hello --deploy target/hello-world-1.0-SNAPSHOT-jar-with-dependencies.jar --env jvm --entrypoint io.fission.HelloWorld

通过fission fn create命令回显或fission package list,可知function的前提是package

$ fission fn create --name hello-java --deploy test-fission-1.0-SNAPSHOT-jar-with-dependencies.jar --env java --entrypoint org.dracula.test.fission.TestEntryPoint
Package 'test-fission-1-0-snapshot-jar-with-dependencies-jar-zr9y' created
package 'test-fission-1-0-snapshot-jar-with-dependencies-jar-zr9y' created
function 'hello-java' created
$ fission fn list
NAME       UID                                  ENV  EXECUTORTYPE MINSCALE MAXSCALE MINCPU MAXCPU MINMEMORY MAXMEMORY TARGETCPU
hello-java 773c6be5-0e76-11e9-abd7-a0c589fcac3d java poolmgr      0        0        0      0      0         0         0
$ fission package list
NAME                                                     BUILD_STATUS ENV
test-fission-1-0-snapshot-jar-with-dependencies-jar-zr9y succeeded    java

自己写个函数试试

参考fission的github上的java例子官网上java例子,写了自己的试验项目git
maven工程下,pom.xml中增加repository,如下

<repository>
    <id>fission-java-core</id>
    <name>fission-java-core-snapshot</name>
    <url>https://oss.sonatype.org/content/repositories/snapshots/</url>
</repository>

引入依赖spring-boot-starter-webfission-java-core,如下

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.0.1.RELEASE</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>io.fission</groupId>
    <artifactId>fission-java-core</artifactId>
    <version>0.0.2-SNAPSHOT</version>
    <scope>provided</scope>
</dependency>

确定entrypoint,是一个java类,实现io.fission.Function,其中仅包括一个方法ResponseEntity call(RequestEntity, Context),如下:

public class TestEntryPoint implements Function {

    @Override
    public ResponseEntity call(RequestEntity requestEntity, Context context) {
        return ResponseEntity.ok("Hello World!");
    }

}

在pom.xml中增加assembly插件,让打出的jar包带有with-dependencies后缀,如下

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
        <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
        </descriptorRefs>
    </configuration>
    <executions>
        <execution>
            <id>make-assembly</id> <!-- this is used for inheritance merges -->
            <phase>package</phase> <!-- bind to the packaging phase -->
            <goals>
                <goal>single</goal>
            </goals>
        </execution>
    </executions>
</plugin>

踩坑

打包

构建好的jar包应该以with-dependencies结尾,否则pod builder日志中有入下报错

cp: cannot stat '/packages/java-src-pkg-zip-birc-fmxrpp/target/*with-dependencies.jar': No such file or directory
Error waiting for cmd 'build': exit status 1
2019/01/02 04:15:47 Error building source package: Error waiting for cmd 'build': exit status 1

相关文章

网友评论

      本文标题:fission on k8s,小总结&自己写个函数试试

      本文链接:https://www.haomeiwen.com/subject/lwtalqtx.html