1 23 24 package org.infoglue.cms.applications.managementtool.actions; 25 26 import java.io.IOException ; 27 28 import org.apache.log4j.Logger; 29 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction; 30 import org.infoglue.cms.util.CmsPropertyHandler; 31 32 34 35 public class AdminReleaseAction extends InfoGlueAbstractAction 36 { 37 private static final long serialVersionUID = 1L; 38 39 private final static Logger logger = Logger.getLogger(AdminReleaseAction.class.getName()); 40 41 private String adminCommand = ""; 42 private String output = ""; 43 44 public String doExecute() throws Exception 45 { 46 output = ExecuteCommand(getAdminCommand()); 47 return "success"; 48 } 49 50 private static String executeUnix(String unixCmd) throws IOException 51 { 52 Process pr = Runtime.getRuntime().exec(unixCmd); 53 String str; 54 String op =""; 55 56 try { 57 java.io.InputStream is = pr.getInputStream(); 58 java.io.InputStreamReader isr = new java.io.InputStreamReader (is); 59 java.io.BufferedReader br = new java.io.BufferedReader (isr); 60 while ((str = br.readLine()) != null) { 61 logger.info(str); 62 op+=str +"<br>"; 63 } 64 is.close(); 65 op+="<font color='red'>"; 66 is = pr.getErrorStream(); 67 isr = new java.io.InputStreamReader (is); 68 br = new java.io.BufferedReader (isr); 69 70 while ((str = br.readLine()) != null) { 71 logger.info(str); 72 op+=str +"<br>"; 73 } 74 is.close(); 75 op+="</font>"; 76 77 } 78 catch (Exception e) { 79 logger.info("InterruptedException raised: "+e.getMessage()); 80 op += e.getMessage(); 81 } 82 83 84 return op; 85 86 } 87 88 89 public static String ExecuteCommand (String cmd) throws Exception 90 { 91 String op = "RESULT OF ACTION:<br>"; 92 String buildName = CmsPropertyHandler.getBuildName(); 93 String admin_tools = CmsPropertyHandler.getAdminToolsPath(); 94 String dbRelease = CmsPropertyHandler.getDbRelease(); 95 String dbScriptPath = CmsPropertyHandler.getDbScriptPath(); 96 97 logger.info("admin tools: " + admin_tools); 98 logger.info("cmd: " + cmd); 99 100 if (admin_tools == null) return "error: cant find admintools"; 101 102 if (cmd.compareTo("MAKEDEFAULT")==0) 103 { 104 logger.info("Executing makedefault "); 105 String unixCmd = "sh " + admin_tools + "/makedefaultrelease.sh " + buildName; 106 try { 107 op+=executeUnix(unixCmd); 108 } 109 catch (Exception e) { 110 logger.info("Exception raised: "+e.getMessage()); 111 op += e.getMessage(); 112 } 113 } 114 115 if (cmd.compareTo("RELOADDATA")==0) 116 { 117 String unixCmd = "sh " + admin_tools + "/reloaddata.sh " + dbScriptPath; 119 120 logger.info("Executing reloaddata "); 121 122 try { 123 op+=executeUnix(unixCmd); 124 } 125 catch (Exception e) { 126 logger.info("Exception raised: "+e.getMessage()); 127 op += e.getMessage(); 128 } 129 130 } 131 132 return op; 133 134 } 135 136 137 141 public String getAdminCommand() 142 { 143 return this.adminCommand; 144 } 145 146 150 public void setAdminCommand(String adminCommand) 151 { 152 this.adminCommand = adminCommand; 153 } 154 155 159 public String getOutput() 160 { 161 return output; 162 } 163 164 168 public void setOutput(String output) 169 { 170 this.output = output; 171 } 172 173 } 174 | Popular Tags |