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