Browse files

Update `configureService` and call sites to new service format.

The `configure` callback now gets called with a list of endpoints for the
service instead of a Services document.
  • Loading branch information...
1 parent b196ba4 commit 2ed30c5387cb276c8a91d6fcddc56c3a1ab0a46c @estark37 estark37 committed Dec 23, 2013
Showing with 58 additions and 20 deletions.
  1. +40 −5 packages/application-configuration/config.js
  2. +14 −12 packages/ctl-helper/ctl-helper.js
  3. +4 −3 packages/webapp/webapp_server.js
View
45 packages/application-configuration/config.js
@@ -149,15 +149,50 @@ AppConfig.configurePackage = function (packageName, configure) {
};
};
-AppConfig.configureService = function (serviceName, configure) {
+AppConfig.configureService = function (serviceName, version, configure) {
+
+ // Collect all the endpoints for this service, from both old- and new-format
+ // documents, and call the `configure` callback with all the service endpoints
+ // that we know about.
+ var callConfigure = function (doc) {
+ var serviceDocs = Services.find({
+ name: serviceName,
+ version: version
+ });
+ var endpoints = [];
+ serviceDocs.forEach(function (serviceDoc) {
+ if (serviceDoc.providers) {
+ _.each(serviceDoc.providers, function (endpoint, app) {
+ endpoints.push(endpoint);
+ });
+ } else {
+ endpoints.push(serviceDoc.endpoint);
+ }
+ });
+ configure(endpoints);
+ };
+
if (ultra) {
// there's a Meteor.startup() that produces the various collections, make
// sure it runs first before we continue.
collectionFuture.wait();
- ultra.subscribe('servicesByName', serviceName);
- return Services.find({name: serviceName}).observe({
- added: configure,
- changed: configure
+ // First try to subscribe to the new format service registrations; if that
+ // sub doesn't exist, then ultraworld hasn't updated to the new format yet,
+ // so try the old format `servicesByName` sub instead.
+ ultra.subscribe('services', serviceName, version, {
+ onError: function (err) {
+ if (err.error === 404) {
+ ultra.subscribe('servicesByName', serviceName);
+ }
+ }
+ });
+ return Services.find({
+ name: serviceName,
+ version: version
+ }).observe({
+ added: callConfigure,
+ changed: callConfigure,
+ removed: callConfigure
});
}
View
26 packages/ctl-helper/ctl-helper.js
@@ -139,18 +139,20 @@ _.extend(Ctl, {
updateProxyActiveTags: function (tags) {
var proxy;
var proxyTagSwitchFuture = new Future;
- AppConfig.configureService('proxy', function (proxyService) {
- try {
- proxy = Follower.connect(proxyService.providers.proxy, {
- group: "proxy"
- });
- proxy.call('updateTags', Ctl.myAppName(), tags);
- proxy.disconnect();
- if (!proxyTagSwitchFuture.isResolved())
- proxyTagSwitchFuture['return']();
- } catch (e) {
- if (!proxyTagSwitchFuture.isResolved())
- proxyTagSwitchFuture['throw'](e);
+ AppConfig.configureService('proxy', 'pre0', function (proxyService) {
+ if (proxyService && ! _.isEmpty(proxyService)) {
+ try {
+ proxy = Follower.connect(proxyService, {
+ group: "proxy"
+ });
+ proxy.call('updateTags', Ctl.myAppName(), tags);
+ proxy.disconnect();
+ if (!proxyTagSwitchFuture.isResolved())
+ proxyTagSwitchFuture['return']();
+ } catch (e) {
+ if (!proxyTagSwitchFuture.isResolved())
+ proxyTagSwitchFuture['throw'](e);
+ }
}
});
View
7 packages/webapp/webapp_server.js
@@ -580,8 +580,9 @@ var runWebAppServer = function () {
// on a per-job basis. Discuss w/ teammates.
proxyBinding = AppConfig.configureService(
"proxy",
+ "pre0",
function (proxyService) {
- if (proxyService.providers.proxy) {
+ if (proxyService && ! _.isEmpty(proxyService)) {
var proxyConf;
// XXX Figure out a per-job way to specify bind location
// (besides hardcoding the location for ADMIN_APP jobs).
@@ -602,9 +603,9 @@ var runWebAppServer = function () {
proxyConf = configuration.proxy;
}
Log("Attempting to bind to proxy at " +
- proxyService.providers.proxy);
+ proxyService);
WebAppInternals.bindToProxy(_.extend({
- proxyEndpoint: proxyService.providers.proxy
+ proxyEndpoint: proxyService
}, proxyConf));
}
}

0 comments on commit 2ed30c5

Please sign in to comment.