| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.rice.ksb.messaging.web; |
| 17 | |
|
| 18 | |
import org.apache.commons.lang.StringUtils; |
| 19 | |
import org.apache.log4j.Logger; |
| 20 | |
import org.apache.struts.action.ActionForm; |
| 21 | |
import org.apache.struts.action.ActionForward; |
| 22 | |
import org.apache.struts.action.ActionMapping; |
| 23 | |
import org.apache.struts.action.ActionMessages; |
| 24 | |
import org.kuali.rice.core.api.config.CoreConfigHelper; |
| 25 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
| 26 | |
import org.kuali.rice.core.api.util.RiceUtilities; |
| 27 | |
import org.kuali.rice.ksb.api.KsbApiServiceLocator; |
| 28 | |
import org.kuali.rice.ksb.api.bus.Endpoint; |
| 29 | |
import org.kuali.rice.ksb.api.bus.ServiceBus; |
| 30 | |
import org.kuali.rice.ksb.api.bus.ServiceConfiguration; |
| 31 | |
import org.kuali.rice.ksb.api.registry.ServiceInfo; |
| 32 | |
import org.kuali.rice.ksb.api.registry.ServiceRegistry; |
| 33 | |
|
| 34 | |
import javax.servlet.ServletException; |
| 35 | |
import javax.servlet.http.HttpServletRequest; |
| 36 | |
import javax.servlet.http.HttpServletResponse; |
| 37 | |
import javax.xml.namespace.QName; |
| 38 | |
import java.io.IOException; |
| 39 | |
import java.util.ArrayList; |
| 40 | |
import java.util.List; |
| 41 | |
import java.util.Map; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 49 | 0 | public class ServiceRegistryAction extends KSBAction { |
| 50 | |
|
| 51 | |
private static final String REMOVED_APPLICATION_ID_PARAM = "removedApplicationId"; |
| 52 | 0 | private static final Logger LOG = Logger.getLogger(ServiceRegistryAction.class); |
| 53 | |
|
| 54 | |
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, |
| 55 | |
HttpServletResponse response) throws IOException, ServletException { |
| 56 | 0 | return mapping.findForward("basic"); |
| 57 | |
} |
| 58 | |
|
| 59 | |
public ActionForward refreshServiceRegistry(ActionMapping mapping, ActionForm form, HttpServletRequest request, |
| 60 | |
HttpServletResponse response) throws IOException, ServletException { |
| 61 | |
|
| 62 | 0 | KsbApiServiceLocator.getServiceBus().synchronize(); |
| 63 | 0 | return mapping.findForward("basic"); |
| 64 | |
} |
| 65 | |
|
| 66 | |
|
| 67 | |
|
| 68 | |
|
| 69 | |
public ActionForward deleteLocalhostEntries(ActionMapping mapping, ActionForm form, HttpServletRequest request, |
| 70 | |
HttpServletResponse response) throws IOException, ServletException { |
| 71 | 0 | ServiceRegistry serviceRegistry = KsbApiServiceLocator.getServiceRegistry(); |
| 72 | 0 | List<ServiceInfo> serviceInfos = serviceRegistry.getAllOnlineServices(); |
| 73 | 0 | List<String> serviceEndpointsToDelete = new ArrayList<String>(); |
| 74 | 0 | for (ServiceInfo serviceInfo : serviceInfos) { |
| 75 | 0 | if (serviceInfo.getServerIpAddress().equals("localhost")) { |
| 76 | 0 | serviceEndpointsToDelete.add(serviceInfo.getServiceId()); |
| 77 | |
} |
| 78 | |
} |
| 79 | 0 | serviceRegistry.removeServiceEndpoints(serviceEndpointsToDelete); |
| 80 | 0 | KsbApiServiceLocator.getServiceBus().synchronize(); |
| 81 | 0 | return mapping.findForward("basic"); |
| 82 | |
} |
| 83 | |
|
| 84 | |
public ActionForward deleteApplicationIdEntries(ActionMapping mapping, ActionForm form, HttpServletRequest request, |
| 85 | |
HttpServletResponse response) throws IOException, ServletException { |
| 86 | |
|
| 87 | 0 | final String applicationId = request.getParameter(REMOVED_APPLICATION_ID_PARAM); |
| 88 | 0 | if(StringUtils.isNotBlank(applicationId)) { |
| 89 | 0 | ServiceRegistry serviceRegistry = KsbApiServiceLocator.getServiceRegistry(); |
| 90 | 0 | List<ServiceInfo> serviceInfos = serviceRegistry.getAllOnlineServices(); |
| 91 | 0 | List<String> serviceEndpointsToDelete = new ArrayList<String>(); |
| 92 | 0 | for (ServiceInfo serviceInfo : serviceInfos) { |
| 93 | 0 | if (serviceInfo.getApplicationId().equals(applicationId)) { |
| 94 | 0 | serviceEndpointsToDelete.add(serviceInfo.getServiceId()); |
| 95 | |
} |
| 96 | |
} |
| 97 | 0 | serviceRegistry.removeServiceEndpoints(serviceEndpointsToDelete); |
| 98 | 0 | KsbApiServiceLocator.getServiceBus().synchronize(); |
| 99 | 0 | } else { |
| 100 | 0 | LOG.info("No rows were deleted from the KRSB_SVC_DEF_T table because the application ID was null or blank."); |
| 101 | |
} |
| 102 | |
|
| 103 | 0 | return mapping.findForward("basic"); |
| 104 | |
} |
| 105 | |
|
| 106 | |
public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm actionForm) throws Exception { |
| 107 | 0 | ServiceRegistryForm form = (ServiceRegistryForm)actionForm; |
| 108 | 0 | form.setMyIpAddress(RiceUtilities.getIpNumber()); |
| 109 | 0 | form.setMyApplicationId(CoreConfigHelper.getApplicationId()); |
| 110 | 0 | form.setDevMode(ConfigContext.getCurrentContextConfig().getDevMode()); |
| 111 | 0 | ServiceBus serviceBus = KsbApiServiceLocator.getServiceBus(); |
| 112 | 0 | form.setMyInstanceId(serviceBus.getInstanceId()); |
| 113 | 0 | form.setPublishedServices(getPublishedServices(serviceBus)); |
| 114 | 0 | ServiceRegistry serviceRegistry = KsbApiServiceLocator.getServiceRegistry(); |
| 115 | 0 | form.setGlobalRegistryServices(getGlobalRegistryServices(serviceRegistry)); |
| 116 | |
|
| 117 | 0 | return null; |
| 118 | |
} |
| 119 | |
|
| 120 | |
private List<ServiceConfiguration> getPublishedServices(ServiceBus serviceBus) { |
| 121 | 0 | Map<QName, Endpoint> localEndpoints = serviceBus.getLocalEndpoints(); |
| 122 | 0 | List<ServiceConfiguration> publishedServices = new ArrayList<ServiceConfiguration>(); |
| 123 | 0 | for (Endpoint endpoint : localEndpoints.values()) { |
| 124 | 0 | publishedServices.add(endpoint.getServiceConfiguration()); |
| 125 | |
} |
| 126 | 0 | return publishedServices; |
| 127 | |
} |
| 128 | |
|
| 129 | |
private List<ServiceInfo> getGlobalRegistryServices(ServiceRegistry serviceRegistry) { |
| 130 | 0 | return serviceRegistry.getAllServices(); |
| 131 | |
} |
| 132 | |
|
| 133 | |
} |