/*
 * Copyright 2015 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.springframework.cloud.dataflow.yarn.container;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.concurrent.Future;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.stream.module.launcher.ModuleLaunchRequest;
import org.springframework.cloud.stream.module.launcher.ModuleLauncher;
import org.springframework.cloud.stream.module.launcher.ModuleLauncherConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.util.concurrent.SettableListenableFuture;
import org.springframework.yarn.annotation.OnContainerStart;
import org.springframework.yarn.annotation.YarnComponent;
import org.springframework.yarn.annotation.YarnParameter;
import org.springframework.yarn.annotation.YarnParameters;
import org.springframework.yarn.container.YarnContainerSupport;

/**
 * Yarn application bootstrapping container and running modules.
 *
 * @author Janne Valkealahti
 *
 */
@SpringBootApplication
@Import(ModuleLauncherConfiguration.class)
@YarnComponent
public class ContainerApplication extends YarnContainerSupport {

	private final static Log log = LogFactory.getLog(ContainerApplication.class);

	@Autowired
	private ModuleLauncher moduleLauncher;

	@OnContainerStart
	public Future<Boolean> runModule(@YarnParameters Properties properties, @YarnParameter("containerModules") String module) {
		log.info("runModule module=" + module);
		log.info("runModule properties=" + properties);
		log.info("moduleLauncher=" + moduleLauncher);

		Map<String, String> args = new HashMap<String, String>();

		for (Entry<Object, Object> entry : properties.entrySet()) {
			String key = entry.getKey().toString();
			String value = entry.getValue().toString();
			if (!key.startsWith("containerModules")) {
				args.put(key, value);
			}
		}

		log.info("Passing args to moduleLauncher: " + args);

		// we should somehow get status back from module
		// launcher when it fails or finishes to set future
		// indicating we're done. Naturally exception will
		// terminate execution chain and container will exit.
		SettableListenableFuture<Boolean> status = new SettableListenableFuture<Boolean>();
		moduleLauncher.launch(Arrays.asList(new ModuleLaunchRequest(module, args)));
		return status;
	}

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

}

@@ -2297,16 +2297,49 @@
 le) %7B%0A%09%09
+%0A%09%09if (log.isInfoEnabled()) %7B%0A%09%09%09
 log.info
@@ -2370,16 +2370,17 @@
 odule);%0A
+%09
 %09%09log.in
@@ -2421,16 +2421,17 @@
 rties);%0A
+%09
 %09%09log.in
@@ -2470,16 +2470,22 @@
 ncher);%0A
+%09%09%7D%0A%09%09
 %0A%09%09Map%3CS
@@ -2518,30 +2518,16 @@
 HashMap%3C
-String, String
 %3E();%0A%0A%09%09
@@ -2757,17 +2757,49 @@
 %09%09%7D%0A%09%09%7D%0A
-%0A
+%09%09%0A%09%09if (log.isInfoEnabled()) %7B%0A%09
 %09%09log.in
@@ -2845,16 +2845,22 @@
  args);%0A
+%09%09%7D%0A%09%09
 %0A%09%09// we
@@ -3140,23 +3140,16 @@
 eFuture%3C
-Boolean
 %3E();%0A%09%09m

Add isInfoEnabled() for logging operations