001/* 002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021package org.nuxeo.ecm.admin.monitoring; 022 023import java.io.Serializable; 024import java.util.ArrayList; 025import java.util.List; 026 027import org.apache.commons.logging.Log; 028import org.apache.commons.logging.LogFactory; 029import org.jboss.seam.ScopeType; 030import org.jboss.seam.annotations.Factory; 031import org.jboss.seam.annotations.In; 032import org.jboss.seam.annotations.Name; 033import org.jboss.seam.annotations.Scope; 034import org.jboss.seam.annotations.web.RequestParameter; 035import org.nuxeo.ecm.core.api.NuxeoPrincipal; 036import org.nuxeo.ecm.core.management.api.AdministrativeStatus; 037import org.nuxeo.ecm.core.management.api.AdministrativeStatusManager; 038import org.nuxeo.ecm.core.management.api.GlobalAdministrativeStatusManager; 039import org.nuxeo.ecm.core.management.api.ProbeInfo; 040import org.nuxeo.ecm.core.management.api.ProbeManager; 041import org.nuxeo.runtime.api.Framework; 042 043/** 044 * Seam Bean that wraps {@link AdministrativeStatusManager} and {@link ProbeManager} services to provide a JSF UI. 045 * 046 * @author tiry 047 */ 048@Name("monitoringAction") 049@Scope(ScopeType.PAGE) 050public class MonitoringActionBean implements Serializable { 051 052 public static final String NUXEO_SERVER_IS_ACTIVE = "nuxeoServiceIsActive"; 053 054 public static final String NUXEO_SERVER_MESSAGE = "org.nuxeo.ecm.deactivatedServerMessage"; 055 056 protected static final Log log = LogFactory.getLog(MonitoringActionBean.class); 057 058 private static final long serialVersionUID = 1L; 059 060 @In(create = true) 061 protected NuxeoPrincipal currentNuxeoPrincipal; 062 063 @RequestParameter("serviceIdentifier") 064 protected String statusIdentifierToEdit; 065 066 @RequestParameter("probeName") 067 protected String probeName; 068 069 protected String newStatusMessage; 070 071 protected String newStatusValue; 072 073 protected AdministrativeStatus editableStatus; 074 075 public AdministrativeStatus getEditableStatus() { 076 return editableStatus; 077 } 078 079 protected AdministrativeStatusManager getStatusManager() { 080 return Framework.getLocalService(AdministrativeStatusManager.class); 081 } 082 083 public List<String> listNuxeoInstances() { 084 return Framework.getLocalService(GlobalAdministrativeStatusManager.class).listInstanceIds(); 085 } 086 087 @Factory(value = "isMultiServerInstallation", scope = ScopeType.EVENT) 088 public boolean isMultiServerInstallation() { 089 return listNuxeoInstances().size() > 1; 090 } 091 092 public List<AdministrativeStatus> getAdministrativeStatuses() { 093 List<AdministrativeStatus> statuses = getStatusManager().getAllStatuses(); 094 for (AdministrativeStatus status : statuses) { 095 log.info("Status : " + status.getLabel() + "=>" + status.getState()); 096 } 097 return statuses; 098 } 099 100 public void editStatus() { 101 editableStatus = getStatusManager().getStatus(statusIdentifierToEdit); 102 newStatusMessage = editableStatus.getMessage(); 103 if (editableStatus.isActive()) { 104 newStatusValue = AdministrativeStatus.PASSIVE; 105 } else { 106 newStatusValue = AdministrativeStatus.ACTIVE; 107 } 108 } 109 110 public void saveStatus() { 111 if (editableStatus != null) { 112 String serviceId = editableStatus.getServiceIdentifier(); 113 changeStatus(serviceId, newStatusMessage, newStatusValue); 114 resetEdit(); 115 } 116 } 117 118 public void cancelEdit() { 119 resetEdit(); 120 } 121 122 public void resetEdit() { 123 editableStatus = null; 124 newStatusMessage = null; 125 newStatusValue = null; 126 } 127 128 public void changeStatus(String serviceId, String message, String state) { 129 getStatusManager().setStatus(serviceId, state, message, currentNuxeoPrincipal.getName()); 130 } 131 132 public List<ProbeInfo> getProbeInfos() { 133 List<ProbeInfo> infos = new ArrayList<ProbeInfo>(); 134 ProbeManager pm = Framework.getLocalService(ProbeManager.class); 135 infos.addAll(pm.getAllProbeInfos()); 136 return infos; 137 } 138 139 public void runProbe() { 140 ProbeManager pm = Framework.getLocalService(ProbeManager.class); 141 pm.runProbe(probeName); 142 } 143 144 public void runAllProbes() { 145 ProbeManager pm = Framework.getLocalService(ProbeManager.class); 146 pm.runAllProbes(); 147 } 148 149 public String getNewStatusMessage() { 150 return newStatusMessage; 151 } 152 153 public void setNewStatusMessage(String newStatusMessage) { 154 this.newStatusMessage = newStatusMessage; 155 } 156 157 public String getNewStatusValue() { 158 return newStatusValue; 159 } 160 161 public void setNewStatusValue(String newStatusValue) { 162 this.newStatusValue = newStatusValue; 163 } 164 165}