-
Notifications
You must be signed in to change notification settings - Fork 720
Create a ServiceRegistry interface. #119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
aa8318e
Create a ServiceRegistry interface.
spencergibb 2996c2f
remove Registration interface
spencergibb 60896a3
update some javadocs
spencergibb 8d10450
Rolled AbstractDiscoveryLifecycle back and deprecated.
spencergibb 2c95bd2
Adds ServiceRegistryEndpoint
spencergibb 802dd8f
Add boolean autoRegister() to EnableDiscoveryClient
spencergibb 81993a4
Adds AutoServiceRegistrationProperties
spencergibb 0558fc6
document `@EnableDiscoveryClient` and `ServiceRegistry`
spencergibb 20eaeae
polish
spencergibb dd39bfb
Adds tests
spencergibb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Adds ServiceRegistryEndpoint
- Loading branch information
commit 2c95bd26f6eb60fb897dd7da103833ba01f9d509
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...-commons/src/main/java/org/springframework/cloud/client/serviceregistry/Registration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| package org.springframework.cloud.client.serviceregistry; | ||
|
|
||
| /** | ||
| * @author Spencer Gibb | ||
| */ | ||
| public interface Registration { | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,11 +4,16 @@ | |
| * TODO: write javadoc | ||
| * @author Spencer Gibb | ||
| */ | ||
| public interface ServiceRegistry<R> { | ||
| public interface ServiceRegistry<R extends Registration> { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here or somewhere else, we should qualify with an example of what a registration might be |
||
| void register(R registration); | ||
|
|
||
| void deregister(R registration); | ||
|
|
||
| void close(); | ||
|
|
||
| // TODO: return value for success? | ||
| void setStatus(R registration, String status); | ||
|
|
||
| // TODO: concrete return value? Interface? | ||
| Object getStatus(R registration); | ||
| } | ||
28 changes: 28 additions & 0 deletions
28
...va/org/springframework/cloud/client/serviceregistry/ServiceRegistryAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.springframework.cloud.client.serviceregistry; | ||
|
|
||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.actuate.endpoint.Endpoint; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
| import org.springframework.cloud.client.serviceregistry.endpoint.ServiceRegistryEndpoint; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| /** | ||
| * @author Spencer Gibb | ||
| */ | ||
| @ConditionalOnBean(ServiceRegistry.class) | ||
| @Configuration | ||
| public class ServiceRegistryAutoConfiguration { | ||
|
|
||
| @Autowired(required = false) | ||
| private Registration registration; | ||
|
|
||
| @ConditionalOnClass(Endpoint.class) | ||
| @Bean | ||
| public ServiceRegistryEndpoint serviceRegistryEndpoint(ServiceRegistry serviceRegistry) { | ||
| ServiceRegistryEndpoint endpoint = new ServiceRegistryEndpoint(serviceRegistry); | ||
| endpoint.setRegistration(registration); | ||
| return endpoint; | ||
| } | ||
| } |
98 changes: 98 additions & 0 deletions
98
...va/org/springframework/cloud/client/serviceregistry/endpoint/ServiceRegistryEndpoint.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| /* | ||
| * Copyright 2013-2016 the original author or authors. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.springframework.cloud.client.serviceregistry.endpoint; | ||
|
|
||
| import org.springframework.boot.actuate.endpoint.Endpoint; | ||
| import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint; | ||
| import org.springframework.cloud.client.serviceregistry.Registration; | ||
| import org.springframework.cloud.client.serviceregistry.ServiceRegistry; | ||
| import org.springframework.http.HttpStatus; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.jmx.export.annotation.ManagedAttribute; | ||
| import org.springframework.jmx.export.annotation.ManagedOperation; | ||
| import org.springframework.jmx.export.annotation.ManagedResource; | ||
| import org.springframework.util.Assert; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestMethod; | ||
| import org.springframework.web.bind.annotation.ResponseBody; | ||
|
|
||
| /** | ||
| * Endpoint to display and set the service instance status using the service registry. | ||
| * | ||
| * @author Spencer Gibb | ||
| */ | ||
| @ManagedResource(description = "Can be used to display and set the service instance status using the service registry") | ||
| @SuppressWarnings("unchecked") | ||
| public class ServiceRegistryEndpoint implements MvcEndpoint { | ||
|
|
||
| private final ServiceRegistry serviceRegistry; | ||
|
|
||
| private Registration registration; | ||
|
|
||
| public ServiceRegistryEndpoint(ServiceRegistry<?> serviceRegistry) { | ||
| this.serviceRegistry = serviceRegistry; | ||
| } | ||
|
|
||
| public void setRegistration(Registration registration) { | ||
| this.registration = registration; | ||
| } | ||
|
|
||
| @RequestMapping(path = "instance-status", method = RequestMethod.POST) | ||
| @ResponseBody | ||
| @ManagedOperation | ||
| public ResponseEntity<?> setStatus(@RequestBody String status) { | ||
| Assert.notNull(status, "status may not by null"); | ||
|
|
||
| if (this.registration == null) { | ||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).body("no registration found"); | ||
| } | ||
|
|
||
| this.serviceRegistry.setStatus(this.registration, status); | ||
| // getEurekaClient().setStatus(status.getStatus()); | ||
| // getEurekaClient().cancelOverrideStatus(); | ||
| return ResponseEntity.ok().build(); | ||
| } | ||
|
|
||
| @RequestMapping(path = "instance-status", method = RequestMethod.GET) | ||
| @ResponseBody | ||
| @ManagedAttribute | ||
| public ResponseEntity getStatus() { | ||
| if (this.registration == null) { | ||
| return ResponseEntity.status(HttpStatus.NOT_FOUND).body("no registration found"); | ||
| } | ||
|
|
||
| // return new Status(this.infoManager.getInfo().getStatus(), this.infoManager.getInfo().getOverriddenStatus()); | ||
| return ResponseEntity.ok().body(this.serviceRegistry.getStatus(this.registration)); | ||
| } | ||
|
|
||
| @Override | ||
| public String getPath() { | ||
| return "/service-registry"; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSensitive() { | ||
| return true; | ||
| } | ||
|
|
||
| @Override | ||
| public Class<? extends Endpoint<?>> getEndpointType() { | ||
| return null; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is a marker interface needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, cause looking at the test I don't really see any benefit of having this
Registrationinterface. Can you explain that?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, leftover from a refactor where this interface had a method and I removed it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ended up putting this back in, because I needed to lookup the registration in the spring context without knowing the implementation.