View Javadoc

1   package org.kuali.common.deploy;
2   
3   import java.util.List;
4   
5   import org.kuali.common.util.Assert;
6   import org.kuali.common.util.FormatUtils;
7   import org.kuali.common.util.execute.Executable;
8   import org.kuali.common.util.secure.channel.SecureChannel;
9   import org.slf4j.Logger;
10  import org.slf4j.LoggerFactory;
11  
12  import com.google.common.collect.ImmutableList;
13  
14  public class SysAdminExecutable implements Executable {
15  
16  	private static final Logger logger = LoggerFactory.getLogger(SysAdminExecutable.class);
17  
18  	public SysAdminExecutable(SecureChannel channel, List<String> commands, boolean skip) {
19  		Assert.noNulls(channel, commands);
20  		this.channel = channel;
21  		this.commands = ImmutableList.copyOf(commands);
22  		this.skip = skip;
23  	}
24  
25  	private final SecureChannel channel;
26  	private final List<String> commands;
27  	private final boolean skip;
28  
29  	@Override
30  	public void execute() {
31  		if (skip) {
32  			logger.info("[sysadmin:skipped]");
33  			return;
34  		}
35  		long start = System.currentTimeMillis();
36  		logger.info("[sysadmin:begin]");
37  		logger.info("  executing {} commands", commands.size());
38  		for (String command : commands) {
39  			logger.debug(command);
40  			channel.executeCommand(command);
41  		}
42  		logger.info("[sysadmin:complete] - {}", FormatUtils.getTime(System.currentTimeMillis() - start));
43  	}
44  
45  	public SecureChannel getChannel() {
46  		return channel;
47  	}
48  
49  	public List<String> getCommands() {
50  		return commands;
51  	}
52  
53  	public boolean isSkip() {
54  		return skip;
55  	}
56  
57  }