Coverage Report - org.kuali.rice.ksb.api.registry.ServiceRegistry
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceRegistry
N/A
N/A
1
 
 1  
 package org.kuali.rice.ksb.api.registry;
 2  
 
 3  
 import org.kuali.rice.core.api.exception.RiceIllegalArgumentException;
 4  
 import org.kuali.rice.core.api.util.jaxb.QNameAsStringAdapter;
 5  
 import org.kuali.rice.ksb.api.KsbApiConstants;
 6  
 
 7  
 import javax.jws.WebMethod;
 8  
 import javax.jws.WebParam;
 9  
 import javax.jws.WebResult;
 10  
 import javax.jws.WebService;
 11  
 import javax.jws.soap.SOAPBinding;
 12  
 import javax.xml.bind.annotation.XmlElement;
 13  
 import javax.xml.bind.annotation.XmlElementWrapper;
 14  
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
 15  
 import javax.xml.namespace.QName;
 16  
 import java.util.List;
 17  
 
 18  
 /**
 19  
  * Defines the interface for a remotely accessible service registry.  Applications
 20  
  * can query for information about available services through the apis provided
 21  
  * as well as publishing their own services.
 22  
  * 
 23  
  * <p>The {@code ServiceRegistry} deals primarily with the concept of a
 24  
  * {@link ServiceEndpoint} which holds a {@link ServiceInfo}
 25  
  * and a {@link ServiceDescriptor}.  These pieces include information about the
 26  
  * service and it's configuration which might be needed by applications wishing to
 27  
  * invoke those services.
 28  
  * 
 29  
  * <p>Many of the operations on the {@code ServiceRegistry} only return the 
 30  
  * {@code ServiceInfo}.  This is because retrieving the full {@code ServiceDescriptor}
 31  
  * is a more expensive operation (since it consists of a serialized XML
 32  
  * representation of the service's configuration which needs to be unmarshaled
 33  
  * and processed) and typically the descriptor is only needed when the client
 34  
  * application actually wants to connect to the service.
 35  
  * 
 36  
  * <p>The {@link ServiceInfo} provides two important pieces of information which
 37  
  * help the registry (and the applications which interact with it) understand
 38  
  * who the owner of a service is.  The first of these is the "application id"
 39  
  * which identifies the application which owns the service.  In terms of
 40  
  * Kuali Rice, an "application" is an abstract concept and consist of multiple
 41  
  * instances of an application which are essentially mirrors of each other and
 42  
  * publish the same set of services.  Each of these individuals instances of
 43  
  * an application is identified by the "instance id" which is also available
 44  
  * from the {@code ServiceInfo}.
 45  
  * 
 46  
  * @see ServiceEndpoint
 47  
  * @see ServiceInfo
 48  
  * @see ServiceDescriptor
 49  
  * 
 50  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 51  
  */
 52  
 @WebService(name = "serviceRegistrySoap", targetNamespace = KsbApiConstants.Namespaces.KSB_NAMESPACE_2_0)
 53  
 @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
 54  
 public interface ServiceRegistry {
 55  
         
 56  
         /**
 57  
          * Returns an unmodifiable list of {@link ServiceInfo} for all services that have a status
 58  
          * of {@link ServiceEndpointStatus#ONLINE} with the given name.  If there
 59  
          * are no services with the given name, this method should return an empty
 60  
          * list.
 61  
          * 
 62  
          * <p>It is typical in clustered environments and other situations that
 63  
          * more than one online service might be available for a given service name.
 64  
          * It is intended that a client of the registry will use an available endpoint
 65  
          * of their choosing to connect to and invoke the service.
 66  
          * 
 67  
          * @param serviceName the name of the service to locate
 68  
          * 
 69  
          * @return an unmodifiable list of {@code ServiceInfo} for online services with the given name.
 70  
          * If no services were found, an empty list will be returned, but this method should never
 71  
          * return null.
 72  
          * 
 73  
          * @throws RiceIllegalArgumentException if serviceName is null
 74  
          */
 75  
         @WebMethod(operationName = "getOnlineServiceByName")
 76  
         @WebResult(name = "serviceInfos")
 77  
         @XmlElementWrapper(name = "serviceInfos", required = true)
 78  
         @XmlElement(name = "serviceInfo", required = false)
 79  
         List<ServiceInfo> getOnlineServicesByName(
 80  
                         @XmlJavaTypeAdapter(QNameAsStringAdapter.class)
 81  
                         @WebParam(name = "serviceName")
 82  
                         QName serviceName) throws RiceIllegalArgumentException;
 83  
         
 84  
         /**
 85  
          * Returns an unmodifiable list of {@link ServiceInfo} for all services in
 86  
          * the registry that have a status of {@link ServiceEndpointStatus#ONLINE}.
 87  
          * If there are no online services in the registry, this method will return
 88  
          * an empty list.
 89  
          * 
 90  
          * @return an unmodifiable list of {@code ServiceInfo} for all online services
 91  
          * in the registry. If no services were found, an empty list will be
 92  
          * returned, but this method should never return null.
 93  
          */
 94  
         @WebMethod(operationName = "getAllOnlineServices")
 95  
         @WebResult(name = "serviceInfo")
 96  
         @XmlElementWrapper(name = "serviceInfos", required = true)
 97  
         @XmlElement(name = "serviceInfo", required = false)
 98  
         List<ServiceInfo> getAllOnlineServices();
 99  
         
 100  
         /**
 101  
          * Returns an unmodifiable list of {@link ServiceInfo} for all services in
 102  
          * the registry.  If there are no services in the registry, this method will
 103  
          * return an empty list.
 104  
          * 
 105  
          * @return an unmodifiable list of {@code ServiceInfo} for all services in the
 106  
          * registry. If no services were found, an empty list will be returned, but
 107  
          * this method should never return null.
 108  
          */
 109  
         @WebMethod(operationName = "getAllServices")
 110  
         @WebResult(name = "serviceInfo")
 111  
         @XmlElementWrapper(name = "serviceInfos", required = true)
 112  
         @XmlElement(name = "serviceInfo", required = false)
 113  
         List<ServiceInfo> getAllServices();
 114  
         
 115  
         /**
 116  
          * Returns an unmodifiable list of {@link ServiceInfo} for all services that
 117  
          * have an instance id which matches the given instance id, regardless of
 118  
          * their status.  If there are no services published for the given instance,
 119  
          * this method should return an empty list.
 120  
          * 
 121  
          * @param instanceId the instance id of the services to locate
 122  
          * 
 123  
          * @return an unmodifiable listof {@code ServiceInfo} for all services in the
 124  
          * registry for the given instance id
 125  
          * 
 126  
          * @throws RiceIllegalArgumentException if instanceId is a null or blank value
 127  
          */
 128  
         @WebMethod(operationName = "getAllServicesForInstance")
 129  
         @WebResult(name = "serviceInfos")
 130  
         @XmlElementWrapper(name = "serviceInfos", required = true)
 131  
         @XmlElement(name = "serviceInfo", required = false)
 132  
         List<ServiceInfo> getAllServicesForInstance(@WebParam(name = "instanceId") String instanceId) throws RiceIllegalArgumentException;
 133  
         
 134  
         /**
 135  
          * Returns the {@link ServiceDescriptor} which has the given id.  If there
 136  
          * is no descriptor for the id, this method will return null.
 137  
          * 
 138  
          * @param serviceDescriptorId
 139  
          * @return
 140  
          * @throws RiceIllegalArgumentException
 141  
          */
 142  
         @WebMethod(operationName = "getServiceDescriptor")
 143  
         @WebResult(name = "serviceDescriptor")
 144  
         @XmlElement(name = "serviceDescriptor", required = false)
 145  
         ServiceDescriptor getServiceDescriptor(@WebParam(name = "serviceDescriptorId") String serviceDescriptorId) throws RiceIllegalArgumentException;
 146  
         
 147  
         /**
 148  
          * Returns an unmodifiable list of {@link ServiceDescriptor} which match the
 149  
          * given list of service descriptor ids.  The list that is returned from this
 150  
          * method may be smaller than the list of ids that were supplied.  This
 151  
          * happens in cases where a service descriptor for a given id in the list
 152  
          * could not be found.
 153  
          * 
 154  
          * @param serviceDescriptorIds the list of service descriptor ids for which to
 155  
          * locate the corresponding service descriptor
 156  
          * 
 157  
          * @return an unmodifiable list of the service descriptors that could be
 158  
          * located for the given list of ids.  This list may be smaller than the
 159  
          * original list of ids that was supplied if the corresponding descriptor
 160  
          * could not be located for a given id in the registry.  If no service
 161  
          * descriptors could be located, this method will return an empty list. It
 162  
          * should never return null. 
 163  
          * 
 164  
          * @throws RiceIllegalArgumentException if serviceDescriptorIds is null
 165  
          */
 166  
         @WebMethod(operationName = "getServiceDescriptors")
 167  
         @WebResult(name = "serviceDescriptors")
 168  
         @XmlElementWrapper(name = "serviceDescriptors", required = true)
 169  
         @XmlElement(name = "serviceDescriptor", required = false)
 170  
         List<ServiceDescriptor> getServiceDescriptors(@WebParam(name = "serviceDescriptorId") List<String> serviceDescriptorIds) throws RiceIllegalArgumentException;
 171  
         
 172  
         /**
 173  
          * Publishes the given {@link ServiceEndpoint} to the registry.  If there
 174  
          * is no service id on the {@code ServiceInfo} then this constitutes a new
 175  
          * registry endpoint, so it will be added to the registry.  If the given
 176  
          * endpoint already has a {@code ServiceInfo} with a service id, then the
 177  
          * corresponding entry in the registry will be updated instead.  
 178  
          * 
 179  
          * @param serviceEndpoint the service endpoint to publish
 180  
          * 
 181  
          * @return the result of publishing the endpoint, if this is a new registry
 182  
          * entry, then the service endpoint that is returned will contain access to
 183  
          * both the service id and service descriptor id that were generated for
 184  
          * this entry in the registry.  This method will never return null.
 185  
          * 
 186  
          * @throws RiceIllegalArgumentException if serviceEndpoint is null
 187  
          */
 188  
         @WebMethod(operationName = "publishService")
 189  
         @WebResult(name = "serviceEndpoint")
 190  
         @XmlElement(name = "serviceEndpoint", required = true)
 191  
         ServiceEndpoint publishService(@WebParam(name = "serviceEndpoint") ServiceEndpoint serviceEndpoint) throws RiceIllegalArgumentException;
 192  
 
 193  
         /**
 194  
          * Publishes the list of {@link ServiceEndpoint}s to the registry.  This
 195  
          * functions the same way as executing {@link #publishService(ServiceEndpoint)}
 196  
          * on each individual {@code ServiceEndpoint}.  However, it performs this as
 197  
          * an atomic operation, so if there is an error when publishing one service
 198  
          * endpoint in the list, then none of the endpoints will be published.
 199  
          * 
 200  
          * @param serviceEndpoints the list of service endpoints to publish
 201  
          * 
 202  
          * @return the result of publishing the endpoints (see {@link #publishService(ServiceEndpoint)}
 203  
          * for details).  This list will always be the same size and in the same
 204  
          * order as the list of service endpoints that were supplied for publshing.
 205  
          * 
 206  
          * @throws RiceIllegalArgumentException if serviceEndpoints is null or if any
 207  
          * {@code ServiceEndpoint} within the list is null
 208  
          */
 209  
         @WebMethod(operationName = "publishServices")
 210  
         @WebResult(name = "serviceEndpoints")
 211  
         @XmlElementWrapper(name = "serviceEndpoints", required = true)
 212  
         @XmlElement(name = "serviceEndpoint", required = false)
 213  
         List<ServiceEndpoint> publishServices(@WebParam(name = "serviceEndpoint") List<ServiceEndpoint> serviceEndpoints) throws RiceIllegalArgumentException;
 214  
         
 215  
         /**
 216  
          * Removes the service from the registry with the given service id if it
 217  
          * exists.  If the service with the given id exists and was successfully
 218  
          * removed, a copy of the removed {@link ServiceEndpoint} entry will be
 219  
          * returned.  Otherwise, this method will return null.
 220  
          * 
 221  
          * @param serviceId the id of the service to remove
 222  
          * 
 223  
          * @return the removed {@link ServiceEndpoint} if a service with the given
 224  
          * id exists in the registry, if no such service exists, this method will
 225  
          * return null
 226  
          * 
 227  
          * @throws RiceIllegalArgumentException if serviceId is null or a blank value
 228  
          */
 229  
         @WebMethod(operationName = "removeServiceEndpoint")
 230  
         @WebResult(name = "serviceEndpoint")
 231  
         @XmlElement(name = "serviceEndpoint", required = false)
 232  
         ServiceEndpoint removeServiceEndpoint(@WebParam(name = "serviceId") String serviceId) throws RiceIllegalArgumentException;
 233  
         
 234  
         /**
 235  
          * As {@link #removeServiceEndpoint(String)} but removes all services that
 236  
          * match the given list of service ids.  It could be the case that some of
 237  
          * the given ids do not match a service in the registry, in this case that
 238  
          * {@link ServiceEndpoint} would not be included in the resulting list of
 239  
          * services that were removed.  Because of this, the list that is returned
 240  
          * from this method may be smaller then the list of ids that were supplied.
 241  
          * 
 242  
          * @param serviceIds the list of service ids to remove from the registry
 243  
          * 
 244  
          * @return a list of all service endpoints that were successfully removed,
 245  
          * if no such endpoints were removed, this list will be empty, but it will
 246  
          * never be null
 247  
          * 
 248  
          * @throws RiceIllegalArgumentException if serviceIds is null or if one of
 249  
          * the ids in the list is null or blank
 250  
          */
 251  
         @WebMethod(operationName = "removeServiceEndpoints")
 252  
         @WebResult(name = "serviceEndpoints")
 253  
         @XmlElementWrapper(name = "serviceEndpoints", required = true)
 254  
         @XmlElement(name = "serviceEndpoint", required = false)
 255  
         List<ServiceEndpoint> removeServiceEndpoints(@WebParam(name = "serviceId") List<String> serviceIds) throws RiceIllegalArgumentException;
 256  
         
 257  
         /**
 258  
          * Performs a single atomic operation of removing and publishing a set of
 259  
          * services in the registry.  This operation is useful in situations where
 260  
          * a client application contains apis to manage the services they are
 261  
          * publishing on the bus and they want to ensure the registry is kept in
 262  
          * a consistent state in terms of what they have published.
 263  
          * 
 264  
          * <p>Behaviorally, this operation is equivalent to performing a
 265  
          * {@link #removeServiceEndpoints(List)} followed by a
 266  
          * {@link #publishServices(List)}, except that a null list is valid for
 267  
          * either {@code removeServiceIds} or {@code publishServiceEndpoints}.  In
 268  
          * the case that a null or empty list is passed for either of these, that
 269  
          * particular portion of the operation will not be performed.
 270  
          * 
 271  
          * <p>This method returns a {@link RemoveAndPublishResult} which contains
 272  
          * a list of the services that were successfully removed as well as those
 273  
          * that were published.
 274  
          * 
 275  
          * @param removeServiceIds the list of ids of the services to remove, if
 276  
          * this parameter is null or an empty list, then no remove operation will
 277  
          * be executed
 278  
          * @param publishServiceEndpoints the list of service endpoints to publish,
 279  
          * if this parameter is null or an empty list, then no publish operation
 280  
          * will be executed
 281  
          * 
 282  
          * @return the result of the operation which contains information on which
 283  
          * services were successfully removed as well as published, this method will
 284  
          * never return null
 285  
          */
 286  
         @WebMethod(operationName = "removeAndPublish")
 287  
         @WebResult(name = "removeAndPublishResult")
 288  
         @XmlElement(name = "removeAndPublishResult", required = true)
 289  
         RemoveAndPublishResult removeAndPublish(@WebParam(name = "removeServiceId") List<String> removeServiceIds,
 290  
                         @WebParam(name = "publishServiceEndpoint") List<ServiceEndpoint> publishServiceEndpoints);
 291  
         
 292  
         /**
 293  
          * Updates the status for the service with the given id to the given
 294  
          * {@link ServiceEndpointStatus}.
 295  
          * 
 296  
          * @param serviceId the id of the service for which to update the status
 297  
          * @param status the status to update this service to
 298  
          * 
 299  
          * @return true if the service with the given id exists in the registry and
 300  
          * was updated, false otherwise
 301  
          * 
 302  
          * @throws RiceIllegalArgumentException if serviceId is null or a blank value
 303  
          * @throws RiceIllegalArgumentException if status is null
 304  
          */
 305  
         @WebMethod(operationName = "updateStatus")
 306  
         @WebResult(name = "statusUpdated")
 307  
         boolean updateStatus(@WebParam(name = "serviceId") String serviceId, @WebParam(name = "status") ServiceEndpointStatus status) throws RiceIllegalArgumentException;
 308  
 
 309  
         /**
 310  
          * As per {@link #updateStatus(String, ServiceEndpointStatus)} but updates
 311  
          * mutliple statuses as part of a single operation.
 312  
          * 
 313  
          * <p>This method returns a List of ids of the services that were updated.
 314  
          * If a given service id does not exist in the registry, that id won't be
 315  
          * included in the result.  So the resuling list of updated ids may be
 316  
          * smaller than the given list of service ids (though it will never be
 317  
          * null).
 318  
          * 
 319  
          * @param serviceIds the list of ids of the services for which to update the status
 320  
          * @param status the status to update the services to
 321  
          * 
 322  
          * @return an unmodifiable list containing the ids of the services that
 323  
          * were successfully updated, since it's possible some of the supplied ids
 324  
          * might not exist in the registry this list could be smaller than the
 325  
          * given serviceIds list
 326  
          * 
 327  
          * @throws RiceIllegalArgumentException if serviceIds is null or if any of
 328  
          * the entries in the list is null or has a blank value
 329  
          * @throws RiceIllegalArgumentException if status is null
 330  
          */
 331  
         @WebMethod(operationName = "updateStatuses")
 332  
         @WebResult(name = "serviceIds")
 333  
         @XmlElementWrapper(name = "serviceIds", required = true)
 334  
         @XmlElement(name = "serviceId", required = false)
 335  
         List<String> updateStatuses(@WebParam(name = "serviceId") List<String> serviceIds, @WebParam(name = "status") ServiceEndpointStatus status) throws RiceIllegalArgumentException;
 336  
         
 337  
         /**
 338  
          * Flips the status of all services that match the given instance id to the
 339  
          * status of {@link ServiceEndpointStatus#OFFLINE.  It is intended that this
 340  
          * operation will be used by a registry client who is going offline for
 341  
          * maintenance or other reasons and wants to ensure that the state of the
 342  
          * registry is consistent with the application's state.
 343  
          * 
 344  
          * @param instanceId the id of the instance for which to set all services to
 345  
          * the offline status
 346  
          * 
 347  
          * @throws RiceIllegalArgumentException if instanceId is null or a blank value
 348  
          */
 349  
         @WebMethod(operationName = "takeInstanceOffline")
 350  
         void takeInstanceOffline(@WebParam(name = "instanceId") String instanceId) throws RiceIllegalArgumentException;
 351  
         
 352  
 }