0

When I create a custom app for SCDF I can, according to the reference define relevant properties that are visible through the dashboard when creating a new stream/task. I created a spring-configuration-metadata-whitelist.properties file like this:

configuration-properties.classes=com.example.MySourceProperties
configuration-properties.names=my.prop1,my.prop2

When I create a new stream definition through the dashboard all properties defined in com.example.MySourceProperties are displayed in the properties dialog, but my.prop1 and my.prop2 are not. Both properties aren't optional and must always be set by the user. How can I include them in the properties dialog?

  • could you do it properly? I tried and couldn't make it working cf https://stackoverflow.com/questions/59412806/spring-cloud-data-flow-custom-application-properties – marie Dec 23 '19 at 16:32

1 Answers1

0

This tells it which class to pull these properties from Task1 properties class That we can use with "@EnableConfigurationProperties(Task1Properties.class) declaration

configuration-properties.classes=com.shifthunter.tasks.Task1Properties

Task1Properties.java

package com.shifthunter.tasks;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties("pulldata-task")
public class Task1Properties {

    /**
     * The path to get the source doc from
     */
    private String sourceFilePath;

    /**
     * The path to put the destination doc 
     */
    private String destinationFilePath;

    /**
     * Property to drive the exit code
     */
    private String controlMessage;

    public String getSourceFilePath() {
        return sourceFilePath;
    }

    public void setSourceFilePath(String sourceFilePath) {
        this.sourceFilePath = sourceFilePath;
    }

    public String getDestinationFilePath() {
        return destinationFilePath;
    }

    public void setDestinationFilePath(String destinationFilePath) {
        this.destinationFilePath = destinationFilePath;
    }

    public String getControlMessage() {
        return controlMessage;
    }

    public void setControlMessage(String controlMessage) {
        this.controlMessage = controlMessage;
    }
}

ShiftHunterTaskPullDataApp.java

package com.shifthunter.tasks;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.cloud.task.configuration.EnableTask;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@EnableTask
@EnableConfigurationProperties(Task1Properties.class)
@SpringBootApplication
public class ShiftHunterTaskPullDataApp {

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

    @Bean
    public Task1 task1() {
        return new Task1();
    }

    public class Task1 implements CommandLineRunner {

        @Autowired
        private Task1Properties config;

        @Override
        public void run(String... strings) throws Exception {

            System.out.println("source: " + config.getSourceFilePath());
            System.out.println("destination: " + config.getDestinationFilePath());
            System.out.println("control message: " + config.getControlMessage());

            if(config.getControlMessage().equals("fail")) {
                System.out.println("throwing an exception ...");
                throw new Exception("I'm ANGRY");
            }

            System.out.println("pulldata-task complete!");

        }
    }
}

Sream Dataflow task-pull-data

 app register --name task-pull-data --type task --uri maven://com.shifthunter.tasks:shifthunter-task-pulldata:jar:0.0.1-SNAPSHOT

task-pull-data - Details