2

In camel route I am making curl with grep using exec component but grep with ${HOSTNAME} not working,below is my camel route.Please need help on this.

@Component
public class VideoFilesOperationRoute extends RouteBuilder {

    @Value("${scheduler.cronExpression}")
    private String cron;

    @Override
    public void configure() throws Exception {

        from("quartz2://videoFilesOperations/everydayMidnight?cron=" + cron)
                .to("exec:curl?args= --silent http://localhost:4040/ | grep ${HOSTNAME}&useStderrOnEmptyStdout=true")
                .to("bean:videoFilesOperationImpl?method=videoFilesOperation");

    }
}

Tried Below solution but still the same issue:

//Tried this first
List<String> args = new ArrayList<>();
args.add("-c");
args.add("curl --silent http://localhost:4040/ | grep ${HOSTNAME}");
from("quartz2://videoFilesOperations/everydayMidnight?cron=" + cron)
.setHeader(ExecBinding.EXEC_COMMAND_ARGS, constant(args))
.to("exec:/bin/sh")
.to("bean:videoFilesOperationImpl?method=videoFilesOperation");


//Tried this next
from("quartz2://videoFilesOperations/everydayMidnight?cron=" + cron)
.to("exec:scripts/curl.sh")
.to("bean:videoFilesOperationImpl?method=videoFilesOperation");
Gopinath
  • 31
  • 1
  • 6
  • "not working" is not very descriptive, do you get an error, have you verified that HOSTNAME is set, ...? Try to explain your issue a little better – Joakim Danielson Dec 13 '18 at 07:10
  • This route is running in kubernetes cluster,basically Hostname its pod name where the container is running. Yes Hostname is set.When i do grep on hostname I guess its not applying and also its not throwing any error. – Gopinath Dec 13 '18 at 08:16
  • 1)exec:curl?args= --silent http://localhost:4040/ 2)exec:curl?args= --silent http://localhost:4040/ | grep ${HOSTNAME}&useStderrOnEmptyStdout=true above both are returning same result, actually in second case it should apply grep but its not happening – Gopinath Dec 13 '18 at 08:39
  • I don't understand your last comment but have you tried to execute your curl/grep manually ? – Joakim Danielson Dec 13 '18 at 08:45
  • Yes i tried manually its working fine,below command which i tried inside pod: curl --silent http://localhost:4040/ | grep $HOSTNAME – Gopinath Dec 13 '18 at 09:50
  • I mean to say, First scenario without grep: I tried only with 'exec:curl?args= --silent http://localhost:4040/' Second scenario with grep :I tried with 'exec:curl?args= --silent http://localhost:4040/ | grep ${HOSTNAME}' Both first and second scenario returning same result in camel route but when i tried manually in pod returning different result because its applying grep in second scenario but not in camel route Hope this will clarifies you. – Gopinath Dec 13 '18 at 10:01

1 Answers1

1

The problem is that the camel-exec command arguments are whitespace delimited. So your attempt to pipe the output from curl to grep wont work.

Try something like this:

@Override
public void configure() throws Exception {
    List<String> args = new ArrayList<>();
    args.add("-c");
    args.add("curl --silent http://localhost:4040/ | grep ${HOSTNAME}");

    from("quartz2://videoFilesOperations/everydayMidnight?cron=" + cron)
        .setHeader(ExecBinding.EXEC_COMMAND_ARGS, constant(args))
        .to("exec:/bin/sh");
}

Or you could just wrap the curl & grep command in a shell script and have camel-exec invoke that.

James Netherton
  • 1,092
  • 1
  • 7
  • 9