1 package org.kuali.common.deploy; 2 3 import java.util.Arrays; 4 import java.util.List; 5 6 import org.kuali.common.util.LoggerLevel; 7 import org.kuali.common.util.LoggerUtils; 8 import org.kuali.common.util.SimpleFormatter; 9 import org.kuali.common.util.secure.Result; 10 import org.slf4j.Logger; 11 import org.slf4j.LoggerFactory; 12 13 public class ServiceUtils { 14 15 private static final Logger logger = LoggerFactory.getLogger(ServiceUtils.class); 16 private static final SimpleFormatter SF = new SimpleFormatter(); 17 18 public static void logResult(Result result, Logger logger) { 19 logger.info("[{}] - {}", result.getCommand(), SF.getTime(result.getElapsed())); 20 LoggerUtils.logLines(result.getStdout(), logger, LoggerLevel.INFO); 21 LoggerUtils.logLines(result.getStderr(), logger, LoggerLevel.WARN); 22 if (result.getExitValue() != 0) { 23 logger.warn("Exit value = {}", result.getExitValue()); 24 } 25 } 26 27 public static void validateResult(Result result) { 28 validateResult(result, Arrays.asList(0)); 29 logger.trace("Result is valid"); 30 } 31 32 public static void validateResult(Result result, List<Integer> exitValues) { 33 for (Integer exitValue : exitValues) { 34 if (exitValue.equals(result.getExitValue())) { 35 return; 36 } 37 } 38 throw new IllegalStateException("Exit value " + result.getExitValue() + " is not allowed"); 39 } 40 41 }