How spring-cloud-function-deployer deploy/undeploy function at runtime?

110 views Asked by At

I am trying to build my own faas service.I want to support load the function at runtime.

@SpringBootApplication
@EnableScheduling
public class DeployerApplication {

    FunctionCatalog catalog;

    @Scheduled(cron = "0/5 * * * * ?")
    void loadSomething() {
        String[] args = new String[]{
            "--spring.cloud.function.location=./faas-function/target/faas-function-1.0-SNAPSHOT-boot.jar",
            "--spring.cloud.function.function-class=com.example.Tmp"};

        ApplicationContext context = SpringApplication.run(TmpApplication.class, args);
        catalog = context.getBean(FunctionCatalog.class);
    }

    public static void main(String[] args) {
        SpringApplication.run(DeployerApplication.class, args);
    }

    @SpringBootApplication(proxyBeanMethods = false)
    private static class TmpApplication {

    }
}

but when I run those code, I got those

Caused by: javax.management.InstanceAlreadyExistsException: org.springframework.boot:type=Admin,name=SpringApplication
    at com.sun.jmx.mbeanserver.Repository.addMBean(Repository.java:437) ~[na:1.8.0_201]
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerWithRepository(DefaultMBeanServerInterceptor.java:1898) ~[na:1.8.0_201]
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerDynamicMBean(DefaultMBeanServerInterceptor.java:966) ~[na:1.8.0_201]
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerObject(DefaultMBeanServerInterceptor.java:900) ~[na:1.8.0_201]
    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.registerMBean(DefaultMBeanServerInterceptor.java:324) ~[na:1.8.0_201]
    at com.sun.jmx.mbeanserver.JmxMBeanServer.registerMBean(JmxMBeanServer.java:522) ~[na:1.8.0_201]
    at org.springframework.boot.admin.SpringApplicationAdminMXBeanRegistrar.afterPropertiesSet(SpringApplicationAdminMXBeanRegistrar.java:129) ~[spring-boot-2.4.0.jar:2.4.0]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1847) ~[spring-beans-5.3.1.jar:5.3.1]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1784) ~[spring-beans-5.3.1.jar:5.3.1]
    ... 32 common frames omitted

How spring-cloud-function-deployer deploy/undeploy function at runtime?

1

There are 1 answers

0
Oleg Zhurakousky On

Your question is very broad, so . . . There is an integration test case in the project git repository as well as individual projects demonstrating several supported scenarios (i am sure you'll find the one that fits you), Please have a look and feel free to follow up with more concrete questions.