Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

[W.I.P.] Use events feed #30

Closed
wants to merge 3 commits into from

1 participant

@Kami

No description provided.

Kami added some commits
@Kami

Closing in favor of #33.

@Kami Kami closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 26, 2013
  1. @Kami
  2. @Kami
Commits on Mar 27, 2013
  1. @Kami

    Merge branch 'master' into use_events_feed

    Kami authored
    Conflicts:
    	service-registry-archaius/src/main/java/com/netflix/config/sources/ServiceRegistryClientProvider.java
This page is out of date. Refresh to see the latest.
View
3  service-registry-archaius/src/main/java/com/netflix/config/sources/ServiceRegistryClient.java
@@ -1,12 +1,13 @@
package com.netflix.config.sources;
import com.rackspacecloud.client.service_registry.objects.ConfigurationValue;
+import com.rackspacecloud.client.service_registry.objects.Event;
import com.rackspacecloud.client.service_registry.objects.Service;
import java.util.List;
public interface ServiceRegistryClient {
List<Service> getServices(String tag) throws Exception;
-
List<ConfigurationValue> getConfiguration() throws Exception;
+ List<Event> getEvents(String nextMarker) throws Exception;
}
View
6 service-registry-archaius/src/main/java/com/netflix/config/sources/ServiceRegistryClientProvider.java
@@ -2,6 +2,7 @@
import com.rackspacecloud.client.service_registry.Client;
import com.rackspacecloud.client.service_registry.objects.ConfigurationValue;
+import com.rackspacecloud.client.service_registry.objects.Event;
import com.rackspacecloud.client.service_registry.objects.Service;
import java.util.List;
@@ -22,4 +23,9 @@ public ServiceRegistryClientProvider(String user, String key, String region) {
public List<ConfigurationValue> getConfiguration() throws Exception {
return client.getConfigurationClient().list(null);
}
+
+ @Override
+ public List<Event> getEvents(String marker) throws Exception {
+ return client.getEventsClient().list(null);
+ }
}
View
44 ...ice-registry-archaius/src/main/java/com/netflix/config/sources/ServiceRegistryConfigurationProvider.java
@@ -4,7 +4,11 @@
import com.netflix.config.DynamicStringProperty;
import com.netflix.config.PollResult;
import com.netflix.config.PolledConfigurationSource;
+import com.rackspacecloud.client.service_registry.events.server.BaseEvent;
+import com.rackspacecloud.client.service_registry.events.server.ConfigurationValueRemovedEvent;
+import com.rackspacecloud.client.service_registry.events.server.ConfigurationValueUpdatedEvent;
import com.rackspacecloud.client.service_registry.objects.ConfigurationValue;
+import com.rackspacecloud.client.service_registry.objects.Event;
import com.rackspacecloud.client.service_registry.objects.Service;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
@@ -17,12 +21,15 @@
private static Logger logger = LoggerFactory.getLogger(ServiceRegistryConfigurationProvider.class);
- private static final String DELIMITER =".";
+ private static final String DELIMITER = ".";
public static final String PREFIX = "serverset";
public static final String INTEREST = PREFIX + DELIMITER + "interest";
private static final String SEPARATOR = ",";
private static final String SUFFIX = "addresses";
+ private Long lastPollTs = null;
+ private String lastMarker = null;
+
public static final DynamicStringProperty dynamicServiceTags = DynamicPropertyFactory.getInstance().getStringProperty(INTEREST, "");
private final ServiceRegistryClient client;
@@ -36,13 +43,44 @@ public PollResult poll(boolean initial, Object checkPoint)
throws Exception {
Map<String, Object> map = new HashMap<String, Object>();
- for (ConfigurationValue value : client.getConfiguration()) {
- map.put(value.getId(), value.getValue());
+
+ if (this.lastPollTs == null) {
+ // First poll, can't use events feed yet. Just retrieve all the
+ // configuration values
+ for (ConfigurationValue value : client.getConfiguration()) {
+ map.put(value.getId(), value.getValue());
+ }
+ }
+ else {
+ List<BaseEvent> events = client.getEvents(this.lastMarker);
+ ConfigurationValue oldValue, newValue;
+
+ for (BaseEvent event : events) {
+ // TODO: skip first event
+ if (event instanceof ConfigurationValueUpdatedEvent) {
+ newValue = ((ConfigurationValueUpdatedEvent) event).getNewValue();
+ String configurationId = newValue.getId();
+
+ map.put(configurationId, newValue);
+
+ }
+ else if (event instanceof ConfigurationValueRemovedEvent) {
+ oldValue = ((ConfigurationValueRemovedEvent) event).getOldValue();
+ String configurationId = oldValue.getId();
+
+ if (map.containsKey(configurationId)) {
+ map.remove(configurationId);
+ }
+ }
+ }
}
+ this.lastPollTs = (new Date().getTime() / 1000);
+
// Do a query to get all the service tags we're interested in,
// once we have that we'll namespace the parameters
String tags = dynamicServiceTags.get();
+
if (!tags.isEmpty()) {
Set<String> serviceTags = new HashSet<String>(Arrays.asList(tags.split(SEPARATOR)));
for (String tag: serviceTags) {
View
1  ...try-archaius/src/test/java/com/netflix/config/sources/test/TestServiceRegistryConfigurationProvider.java
@@ -2,6 +2,7 @@
import com.netflix.config.sources.ServiceRegistryClient;
import com.rackspacecloud.client.service_registry.objects.ConfigurationValue;
+import com.rackspacecloud.client.service_registry.objects.Event;
import com.rackspacecloud.client.service_registry.objects.Service;
import java.util.*;
View
1  service-registry-client/src/main/java/com/rackspacecloud/client/service_registry/clients/EventsClient.java
@@ -43,6 +43,7 @@ public EventsClient(AuthClient authClient, String apiUrl) {
super(authClient, apiUrl);
}
+ // TODO: return container object with marker and other data
public List<BaseEvent> list(PaginationOptions paginationOptions) throws Exception {
String url = "/events";
Type type = new TypeToken<EventsContainer>() {}.getType();
Something went wrong with that request. Please try again.