001 package org.kuali.common.deploy;
002
003 import java.util.List;
004
005 import org.kuali.common.util.Assert;
006 import org.kuali.common.util.FormatUtils;
007 import org.kuali.common.util.execute.Executable;
008 import org.kuali.common.util.secure.channel.SecureChannel;
009 import org.slf4j.Logger;
010 import org.slf4j.LoggerFactory;
011
012 import com.google.common.collect.ImmutableList;
013
014 public class SysAdminExecutable implements Executable {
015
016 private static final Logger logger = LoggerFactory.getLogger(SysAdminExecutable.class);
017
018 public SysAdminExecutable(SecureChannel channel, List<String> commands, boolean skip) {
019 Assert.noNulls(channel, commands);
020 this.channel = channel;
021 this.commands = ImmutableList.copyOf(commands);
022 this.skip = skip;
023 }
024
025 private final SecureChannel channel;
026 private final List<String> commands;
027 private final boolean skip;
028
029 @Override
030 public void execute() {
031 if (skip) {
032 logger.info("[sysadmin:skipped]");
033 return;
034 }
035 long start = System.currentTimeMillis();
036 logger.info("[sysadmin:begin]");
037 logger.info(" executing {} commands", commands.size());
038 for (String command : commands) {
039 logger.debug(command);
040 channel.executeCommand(command);
041 }
042 logger.info("[sysadmin:complete] - {}", FormatUtils.getTime(System.currentTimeMillis() - start));
043 }
044
045 public SecureChannel getChannel() {
046 return channel;
047 }
048
049 public List<String> getCommands() {
050 return commands;
051 }
052
053 public boolean isSkip() {
054 return skip;
055 }
056
057 }