1 17 package org.alfresco.repo.admin.patch; 18 19 import java.util.Date ; 20 import java.util.List ; 21 22 import org.alfresco.error.AlfrescoRuntimeException; 23 import org.alfresco.i18n.I18NUtil; 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.springframework.context.ApplicationEvent; 27 import org.springframework.context.ApplicationListener; 28 import org.springframework.context.event.ContextRefreshedEvent; 29 30 36 public class PatchExecuter implements ApplicationListener 37 { 38 private static final String MSG_CHECKING = "patch.executer.checking"; 39 private static final String MSG_NO_PATCHES_REQUIRED = "patch.executer.no_patches_required"; 40 private static final String MSG_NOT_EXECUTED = "patch.executer.not_executed"; 41 private static final String MSG_EXECUTED = "patch.executer.executed"; 42 private static final String MSG_FAILED = "patch.executer.failed"; 43 44 private static Log logger = LogFactory.getLog(PatchExecuter.class); 45 46 private PatchService patchService; 47 48 51 public void setPatchService(PatchService patchService) 52 { 53 this.patchService = patchService; 54 } 55 56 59 public void applyOutstandingPatches() 60 { 61 logger.info(I18NUtil.getMessage(MSG_CHECKING)); 62 63 Date before = new Date (System.currentTimeMillis() - 20000L); patchService.applyOutstandingPatches(); 65 Date after = new Date (System .currentTimeMillis() + 20000L); 67 List <PatchInfo> appliedPatches = patchService.getPatches(before, after); 69 70 if (appliedPatches.size() == 0) 72 { 73 logger.info(I18NUtil.getMessage(MSG_NO_PATCHES_REQUIRED)); 74 } 75 else 76 { 77 boolean succeeded = true; 78 for (PatchInfo patchInfo : appliedPatches) 80 { 81 if (!patchInfo.getWasExecuted()) 82 { 83 logger.debug(I18NUtil.getMessage(MSG_NOT_EXECUTED, patchInfo.getId(), patchInfo.getReport())); 85 } 86 else if (patchInfo.getSucceeded()) 87 { 88 logger.info(I18NUtil.getMessage(MSG_EXECUTED, patchInfo.getId(), patchInfo.getReport())); 89 } 90 else 91 { 92 succeeded = false; 93 logger.error(I18NUtil.getMessage(MSG_FAILED, patchInfo.getId(), patchInfo.getReport())); 94 } 95 } 96 if (!succeeded) 98 { 99 throw new AlfrescoRuntimeException("Not all patches could be applied"); 100 } 101 } 102 } 103 104 108 public void onApplicationEvent(ApplicationEvent event) 109 { 110 if (event instanceof ContextRefreshedEvent) 111 { 112 applyOutstandingPatches(); 113 } 114 } 115 116 } 117 | Popular Tags |