Implementing service runtime event listeners and status updates.
This commit is contained in:
Родитель
8887fd37be
Коммит
e784d7cfc1
|
@ -23,7 +23,7 @@ exports = module.exports = FileInputChannel;
|
|||
function FileInputChannel() { }
|
||||
|
||||
FileInputChannel.prototype.readInputChannel = function (name, parseXml, callback) {
|
||||
this.readData(name, function (error, data) {
|
||||
this._readData(name, function (error, data) {
|
||||
if (!error) {
|
||||
if (parseXml) {
|
||||
var parser = new xml2js.Parser();
|
||||
|
@ -42,7 +42,6 @@ FileInputChannel.prototype.readInputChannel = function (name, parseXml, callback
|
|||
});
|
||||
};
|
||||
|
||||
FileInputChannel.prototype.readData = function(name, callback) {
|
||||
var data = fs.readFileSync(name);
|
||||
callback(undefined, data);
|
||||
FileInputChannel.prototype._readData = function (name, callback) {
|
||||
fs.readFile(name, callback);
|
||||
};
|
|
@ -20,10 +20,12 @@ var xml2js = require('xml2js');
|
|||
// Expose 'NamedPipeInputChannel'.
|
||||
exports = module.exports = NamedPipeInputChannel;
|
||||
|
||||
function NamedPipeInputChannel() { }
|
||||
function NamedPipeInputChannel() {
|
||||
this.closeOnRead = true;
|
||||
}
|
||||
|
||||
NamedPipeInputChannel.prototype.readInputChannel = function (name, parseXml, callback) {
|
||||
this.readData(name, function (error, data) {
|
||||
this._readData(name, function (error, data) {
|
||||
if (!error) {
|
||||
var parts = data.toString().split('\r\n');
|
||||
|
||||
|
@ -46,24 +48,30 @@ NamedPipeInputChannel.prototype.readInputChannel = function (name, parseXml, cal
|
|||
}
|
||||
}
|
||||
|
||||
if (error) {
|
||||
error.fileName = name;
|
||||
}
|
||||
|
||||
callback(error, xml);
|
||||
} else {
|
||||
error.fileName = name;
|
||||
callback(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
NamedPipeInputChannel.prototype.readData = function(name, callback) {
|
||||
NamedPipeInputChannel.prototype._readData = function (name, callback) {
|
||||
var self = this;
|
||||
var client = net.connect(name);
|
||||
var data = '';
|
||||
client.on('data', function(chunk) {
|
||||
data += chunk;
|
||||
client.end();
|
||||
client.on('data', function (data) {
|
||||
if (self.closeOnRead) {
|
||||
client.end();
|
||||
}
|
||||
|
||||
callback(undefined, data);
|
||||
});
|
||||
|
||||
client.on('error', function(error) {
|
||||
client.on('error', function (error) {
|
||||
callback(error);
|
||||
});
|
||||
};
|
|
@ -14,7 +14,7 @@
|
|||
*/
|
||||
|
||||
// Module dependencies.
|
||||
var net = require("net");
|
||||
var net = require('net');
|
||||
|
||||
// Expose 'NamedPipeOutputChannel'.
|
||||
exports = module.exports = NamedPipeOutputChannel;
|
||||
|
|
|
@ -37,17 +37,28 @@ function Protocol1RuntimeClient(goalStateClient, currentStateClient, endpoint) {
|
|||
util.inherits(Protocol1RuntimeClient, EventEmitter);
|
||||
|
||||
Protocol1RuntimeClient.prototype.getCurrentGoalState = function (callback) {
|
||||
return this.goalStateClient.getCurrentGoalState(callback);
|
||||
this._addListeners();
|
||||
|
||||
this.goalStateClient.getCurrentGoalState(callback);
|
||||
};
|
||||
|
||||
Protocol1RuntimeClient.prototype.getRoleEnvironmentData = function (callback) {
|
||||
this.goalStateClient.on(ServiceRuntimeConstants.CHANGED, function (currentGoalState) {
|
||||
self.emit(ServiceRuntimeConstants.CHANGED, currentGoalState);
|
||||
});
|
||||
this._addListeners();
|
||||
|
||||
return this.goalStateClient.getRoleEnvironmentData(callback);
|
||||
this.goalStateClient.getRoleEnvironmentData(callback);
|
||||
};
|
||||
|
||||
Protocol1RuntimeClient.prototype.setCurrentState = function (state, callback) {
|
||||
this._addListeners();
|
||||
|
||||
this.currentStateClient.setCurrentState(state, callback);
|
||||
};
|
||||
|
||||
Protocol1RuntimeClient.prototype._addListeners = function () {
|
||||
var self = this;
|
||||
if (this.goalStateClient.listeners(ServiceRuntimeConstants.CHANGED).length === 0) {
|
||||
this.goalStateClient.on(ServiceRuntimeConstants.CHANGED, function (currentGoalState) {
|
||||
self.emit(ServiceRuntimeConstants.CHANGED, currentGoalState);
|
||||
});
|
||||
}
|
||||
};
|
|
@ -24,5 +24,5 @@ function Protocol1RuntimeCurrentStateClient(currentStateSerializer, outputChanne
|
|||
|
||||
Protocol1RuntimeCurrentStateClient.prototype.setCurrentState = function (state, callback) {
|
||||
var serializedState = this.currentStateSerializer.serialize(state);
|
||||
this.outputChannel.writeOutputChannel(serializedState, callback);
|
||||
this.outputChannel.writeOutputChannel(this.endpoint, serializedState, callback);
|
||||
};
|
|
@ -17,6 +17,7 @@
|
|||
var EventEmitter = require('events').EventEmitter;
|
||||
var util = require('util');
|
||||
|
||||
var azureutil = require('../util/util');
|
||||
var Constants = require('../util/constants');
|
||||
var ServiceRuntimeConstants = Constants.ServiceRuntimeConstants;
|
||||
|
||||
|
@ -41,7 +42,7 @@ util.inherits(Protocol1RuntimeGoalStateClient, EventEmitter);
|
|||
|
||||
Protocol1RuntimeGoalStateClient.prototype.getCurrentGoalState = function (callback) {
|
||||
var self = this;
|
||||
this.ensureGoalStateRetrieved(function (error) {
|
||||
this._ensureGoalStateRetrieved(function (error) {
|
||||
if (!error) {
|
||||
callback(error, self.currentGoalState);
|
||||
} else {
|
||||
|
@ -52,12 +53,16 @@ Protocol1RuntimeGoalStateClient.prototype.getCurrentGoalState = function (callba
|
|||
|
||||
Protocol1RuntimeGoalStateClient.prototype.getRoleEnvironmentData = function (callback) {
|
||||
var self = this;
|
||||
this.ensureGoalStateRetrieved(function (error) {
|
||||
this._ensureGoalStateRetrieved(function (error) {
|
||||
if (!error) {
|
||||
if (!self.currentEnvironmentData) {
|
||||
self.fileInputChannel.readInputChannel(self.currentGoalState.roleEnvironmentPath, true, function (readError, data) {
|
||||
self.currentEnvironmentData = self.roleEnvironmentDataDeserializer.deserialize(data);
|
||||
callback(readError, self.currentEnvironmentData);
|
||||
if (!readError) {
|
||||
self.currentEnvironmentData = self.roleEnvironmentDataDeserializer.deserialize(data);
|
||||
callback(readError, self.currentEnvironmentData);
|
||||
} else {
|
||||
callback(readError);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback(undefined, self.currentEnvironmentData);
|
||||
|
@ -68,18 +73,43 @@ Protocol1RuntimeGoalStateClient.prototype.getRoleEnvironmentData = function (cal
|
|||
});
|
||||
};
|
||||
|
||||
Protocol1RuntimeGoalStateClient.prototype.ensureGoalStateRetrieved = function (callback) {
|
||||
var self = this;
|
||||
if (!self.currentGoalState) {
|
||||
self.namedPipeInputChannel.readInputChannel(self.endpoint, true, function (error, data) {
|
||||
if (error) {
|
||||
callback(error);
|
||||
} else {
|
||||
self.currentGoalState = self.goalStateDeserializer.deserialize(data);
|
||||
callback();
|
||||
}
|
||||
});
|
||||
Protocol1RuntimeGoalStateClient.prototype._ensureGoalStateRetrieved = function (callback) {
|
||||
if (!this.currentGoalState) {
|
||||
this._ensurePolling(callback);
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
};
|
||||
|
||||
Protocol1RuntimeGoalStateClient.prototype._ensurePolling = function (callback) {
|
||||
var currentCallback = callback;
|
||||
var self = this;
|
||||
|
||||
self.namedPipeInputChannel.closeOnRead = false;
|
||||
self.namedPipeInputChannel.readInputChannel(self.endpoint, true, function (error, data) {
|
||||
if (error) {
|
||||
if (currentCallback) {
|
||||
currentCallback(error);
|
||||
}
|
||||
} else if (data) {
|
||||
self.currentGoalState = self.goalStateDeserializer.deserialize(data);
|
||||
|
||||
// reset environment data to force refresh
|
||||
if (self.currentEnvironmentData) {
|
||||
self.currentEnvironmentData = null;
|
||||
}
|
||||
|
||||
self.currentStateClient.endpoint = self.currentGoalState.currentStateEndpoint;
|
||||
|
||||
// if callback available invoke it to return immediately
|
||||
if (currentCallback) {
|
||||
currentCallback();
|
||||
currentCallback = null;
|
||||
} else {
|
||||
// no call back means this is looping for the second time and so there's
|
||||
// a re-read that triggers a changed event
|
||||
self.emit(ServiceRuntimeConstants.CHANGED, self.currentGoalState);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
|
@ -31,8 +31,8 @@ RoleEnvironment.VersionEndpointFixedPath = '\\\\.\\pipe\\WindowsAzureRuntime';
|
|||
exports = module.exports = RoleEnvironment;
|
||||
|
||||
exports.clientId = uuid();
|
||||
exports.runtimeClient = null;
|
||||
|
||||
var runtimeClient = null;
|
||||
var currentGoalState = null;
|
||||
var currentEnvironmentData = null;
|
||||
var lastState = null;
|
||||
|
@ -41,66 +41,6 @@ var eventEmitter = new events.EventEmitter();
|
|||
|
||||
function RoleEnvironment() { }
|
||||
|
||||
RoleEnvironment._initialize = function (callback) {
|
||||
var getCurrentGoalState = function (error, rtClient) {
|
||||
if (error) {
|
||||
callback(error);
|
||||
} else {
|
||||
runtimeClient = rtClient;
|
||||
currentGoalState = runtimeClient.getCurrentGoalState(getCurrentEnvironmentData);
|
||||
}
|
||||
};
|
||||
|
||||
var getCurrentEnvironmentData = function (error, goalState) {
|
||||
if (error) {
|
||||
callback(error);
|
||||
} else {
|
||||
currentGoalState = goalState;
|
||||
runtimeClient.getRoleEnvironmentData(function (getRoleEnvironmentDataError, environmentData) {
|
||||
if (getRoleEnvironmentDataError) {
|
||||
callback(getRoleEnvironmentDataError);
|
||||
} else {
|
||||
currentEnvironmentData = environmentData;
|
||||
|
||||
runtimeClient.on(ServiceRuntimeConstants.CHANGED, function (newGoalState) {
|
||||
switch (newGoalState.expectedState) {
|
||||
case ServiceRuntimeConstants.STARTED:
|
||||
if (newGoalState.incarnation > currentGoalState.incarnation) {
|
||||
self._processGoalStateChange(newGoalState); // NOTE: do we need a callback here ?
|
||||
}
|
||||
break;
|
||||
case ServiceRuntimeConstants.STOPPED:
|
||||
/*
|
||||
raiseStoppingEvent();
|
||||
|
||||
CurrentState stoppedState = new AcquireCurrentState(clientId,
|
||||
newGoalState.getIncarnation(), CurrentStatus.STOPPED, maxDateTime);
|
||||
|
||||
runtimeClient.setCurrentState(stoppedState);*/
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (!runtimeClient) {
|
||||
var endpoint = process.env[RoleEnvironment.EnvironmentVariables.VersionEndpointEnvironmentName];
|
||||
|
||||
if (!endpoint) {
|
||||
endpoint = RoleEnvironment.VersionEndpointFixedPath;
|
||||
}
|
||||
|
||||
var kernel = RuntimeKernel.getKernel();
|
||||
kernel.getRuntimeVersionManager().getRuntimeClient(endpoint, getCurrentGoalState);
|
||||
} else {
|
||||
getCurrentGoalState(undefined, runtimeClient);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns a RoleInstance object that represents the role instance
|
||||
* in which this code is currently executing.
|
||||
|
@ -144,7 +84,7 @@ RoleEnvironment.getDeploymentId = function (callback) {
|
|||
RoleEnvironment.isAvailable = function (callback) {
|
||||
try {
|
||||
RoleEnvironment._initialize(function (initializeError) {
|
||||
callback(initializeError, runtimeClient != null);
|
||||
callback(initializeError, exports.runtimeClient != null);
|
||||
});
|
||||
} catch (error) {
|
||||
callback(error, false);
|
||||
|
@ -238,7 +178,7 @@ RoleEnvironment.requestRecycle = function (callback) {
|
|||
expiration: maxDateTime
|
||||
};
|
||||
|
||||
runtimeClient.setCurrentState(newState, callback);
|
||||
exports.runtimeClient.setCurrentState(newState, callback);
|
||||
} else {
|
||||
callback(error);
|
||||
}
|
||||
|
@ -279,7 +219,7 @@ RoleEnvironment.setStatus = function (roleInstanceStatus, expirationUtc, callbac
|
|||
|
||||
lastState = newState;
|
||||
|
||||
runtimeClient.setCurrentState(newState, callback);
|
||||
exports.runtimeClient.setCurrentState(newState, callback);
|
||||
} else {
|
||||
callback(error);
|
||||
}
|
||||
|
@ -299,33 +239,108 @@ RoleEnvironment.clearStatus = function (callback) {
|
|||
|
||||
lastState = newState;
|
||||
|
||||
runtimeClient.setCurrentState(newState, callback);
|
||||
exports.runtimeClient.setCurrentState(newState, callback);
|
||||
} else {
|
||||
callback(error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// TODO: find a better way to hook eventing up
|
||||
RoleEnvironment.on = function (event, callback) {
|
||||
eventEmitter.on(event, callback);
|
||||
};
|
||||
|
||||
RoleEnvironment._initialize = function (callback) {
|
||||
var getCurrentGoalState = function (finalCallback) {
|
||||
exports.runtimeClient.getCurrentGoalState(function (error, goalState) {
|
||||
if (error) {
|
||||
callback(error);
|
||||
} else {
|
||||
currentGoalState = goalState;
|
||||
getCurrentEnvironmentData(goalState, finalCallback);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var getCurrentEnvironmentData = function (goalState, finalCallback) {
|
||||
exports.runtimeClient.getRoleEnvironmentData(function (getRoleEnvironmentDataError, environmentData) {
|
||||
if (getRoleEnvironmentDataError) {
|
||||
callback(getRoleEnvironmentDataError);
|
||||
} else {
|
||||
currentEnvironmentData = environmentData;
|
||||
|
||||
finalCallback();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
if (!exports.runtimeClient) {
|
||||
var endpoint = process.env[RoleEnvironment.EnvironmentVariables.VersionEndpointEnvironmentName];
|
||||
|
||||
if (!endpoint) {
|
||||
endpoint = RoleEnvironment.VersionEndpointFixedPath;
|
||||
}
|
||||
|
||||
var kernel = RuntimeKernel.getKernel();
|
||||
kernel.getRuntimeVersionManager().getRuntimeClient(endpoint, function (error, rtClient) {
|
||||
if (error) {
|
||||
callback(error);
|
||||
} else {
|
||||
exports.runtimeClient = rtClient;
|
||||
|
||||
getCurrentGoalState(function (error) {
|
||||
if (error) {
|
||||
callback(error);
|
||||
} else {
|
||||
if (exports.runtimeClient.listeners(ServiceRuntimeConstants.CHANGED).length === 0) {
|
||||
exports.runtimeClient.on(ServiceRuntimeConstants.CHANGED, function (newGoalState) {
|
||||
switch (newGoalState.expectedState) {
|
||||
case ServiceRuntimeConstants.RoleStatus.STARTED:
|
||||
if (newGoalState.incarnation > currentGoalState.incarnation) {
|
||||
RoleEnvironment._processGoalStateChange(newGoalState, function () { });
|
||||
}
|
||||
|
||||
break;
|
||||
case ServiceRuntimeConstants.RoleStatus.STOPPED:
|
||||
RoleEnvironment._raiseStoppingEvent();
|
||||
|
||||
var stoppedState = {
|
||||
clientId: exports.clientId,
|
||||
incarnation: newGoalState.incarnation,
|
||||
status: ServiceRuntimeConstants.RoleStatus.STOPPED,
|
||||
expiration: maxDateTime
|
||||
};
|
||||
|
||||
exports.runtimeClient.setCurrentState(stoppedState, function () { });
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
callback();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
} else {
|
||||
getCurrentGoalState(callback);
|
||||
}
|
||||
};
|
||||
|
||||
RoleEnvironment._processGoalStateChange = function (newGoalState, callback) {
|
||||
var self = this;
|
||||
var last = lastState;
|
||||
|
||||
RoleEnvironment._calculateChanges(function (error, changes) {
|
||||
if (!error) {
|
||||
if (changes.length === 0) {
|
||||
self._acceptLatestIncarnation(newGoalState, last);
|
||||
RoleEnvironment._acceptLatestIncarnation(newGoalState, last);
|
||||
} else {
|
||||
eventEmitter.emit(ServiceRuntimeConstants.CHANGING, changes);
|
||||
|
||||
// TODO: check for canceled ?
|
||||
|
||||
RoleEnvironment._acceptLatestIncarnation(newGoalState, last);
|
||||
|
||||
runtimeClient.getRoleEnvironmentData(function (getRoleEnvironmentDataError, environmentData) {
|
||||
exports.runtimeClient.getRoleEnvironmentData(function (getRoleEnvironmentDataError, environmentData) {
|
||||
if (getRoleEnvironmentDataError) {
|
||||
callback(getRoleEnvironmentDataError);
|
||||
} else {
|
||||
|
@ -343,7 +358,22 @@ RoleEnvironment._processGoalStateChange = function (newGoalState, callback) {
|
|||
};
|
||||
|
||||
RoleEnvironment._acceptLatestIncarnation = function (newGoalState, last) {
|
||||
// TODO: implement
|
||||
var setGoalState = function () {
|
||||
currentGoalState = newGoalState;
|
||||
};
|
||||
|
||||
if (last !== null && last.status !== null) {
|
||||
var acceptState = {
|
||||
clientId: exports.clientId,
|
||||
incarnation: newGoalState.incarnation,
|
||||
status: last.status,
|
||||
expiration: last.expiration
|
||||
};
|
||||
|
||||
exports.runtimeClient.setCurrentState(acceptState, setGoalState);
|
||||
} else {
|
||||
setGoalState();
|
||||
}
|
||||
};
|
||||
|
||||
RoleEnvironment._calculateChanges = function (callback) {
|
||||
|
@ -352,7 +382,7 @@ RoleEnvironment._calculateChanges = function (callback) {
|
|||
var current = currentEnvironmentData;
|
||||
var newData;
|
||||
|
||||
runtimeClient.getRoleEnvironmentData(function (getRoleEnvironmentDataError, environmentData) {
|
||||
exports.runtimeClient.getRoleEnvironmentData(function (getRoleEnvironmentDataError, environmentData) {
|
||||
if (!getRoleEnvironmentDataError) {
|
||||
newData = environmentData;
|
||||
|
||||
|
@ -396,17 +426,17 @@ RoleEnvironment._calculateChanges = function (callback) {
|
|||
currentInstance = currentRole[instance];
|
||||
newInstance = newRole[instance];
|
||||
|
||||
if (currentInstance['faultDomain'] === newInstance['faultDomain'] &&
|
||||
currentInstance['updateDomain'] === currentInstance['updateDomain']) {
|
||||
if (currentInstance.faultDomain === newInstance.faultDomain &&
|
||||
currentInstance.updateDomain === newInstance.updateDomain) {
|
||||
|
||||
for (endpoint in currentInstance['endpoints']) {
|
||||
if (newInstance['endpoints'][endpoint]) {
|
||||
currentEndpoint = currentInstance['endpoints'][endpoint];
|
||||
newEndpoint = newInstance['endpoints'][endpoint];
|
||||
for (endpoint in currentInstance.endpoints) {
|
||||
if (newInstance.endpoints[endpoint]) {
|
||||
currentEndpoint = currentInstance.endpoints[endpoint];
|
||||
newEndpoint = newInstance.endpoints[endpoint];
|
||||
|
||||
if (currentEndpoint['protocol'] !== newEndpoint['protocol'] ||
|
||||
currentEndpoint['address'] !== newEndpoint['address'] ||
|
||||
currentEndpoint['port'] !== newEndpoint['port']) {
|
||||
if (currentEndpoint.protocol !== newEndpoint.protocol ||
|
||||
currentEndpoint.address !== newEndpoint.address ||
|
||||
currentEndpoint.port !== newEndpoint.port) {
|
||||
changedRoleSet.push(role);
|
||||
}
|
||||
} else {
|
||||
|
@ -435,17 +465,17 @@ RoleEnvironment._calculateChanges = function (callback) {
|
|||
currentInstance = currentRole[instance];
|
||||
newInstance = newRole[instance];
|
||||
|
||||
if (currentInstance['faultDomain'] === newInstance['faultDomain'] &&
|
||||
currentInstance['updateDomain'] === currentInstance['updateDomain']) {
|
||||
if (currentInstance.faultDomain === newInstance.faultDomain &&
|
||||
currentInstance.updateDomain === currentInstance.updateDomain) {
|
||||
|
||||
for (endpoint in newInstance['endpoints']) {
|
||||
if (currentInstance['endpoints'][endpoint]) {
|
||||
currentEndpoint = currentInstance['endpoints'][endpoint];
|
||||
newEndpoint = newInstance['endpoints'][endpoint];
|
||||
for (endpoint in newInstance.endpoints) {
|
||||
if (currentInstance.endpoints[endpoint]) {
|
||||
currentEndpoint = currentInstance.endpoints[endpoint];
|
||||
newEndpoint = newInstance.endpoints[endpoint];
|
||||
|
||||
if (currentEndpoint['protocol'] !== newEndpoint['protocol'] ||
|
||||
currentEndpoint['address'] !== newEndpoint['address'] ||
|
||||
currentEndpoint['port'] !== newEndpoint['port']) {
|
||||
if (currentEndpoint.protocol !== newEndpoint.protocol ||
|
||||
currentEndpoint.address !== newEndpoint.address ||
|
||||
currentEndpoint.port !== newEndpoint.port) {
|
||||
changedRoleSet.push(role);
|
||||
}
|
||||
} else {
|
||||
|
@ -473,4 +503,8 @@ RoleEnvironment._calculateChanges = function (callback) {
|
|||
callback(getRoleEnvironmentDataError);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
RoleEnvironment._raiseStoppingEvent = function () {
|
||||
eventEmitter.emit(ServiceRuntimeConstants.STOPPING);
|
||||
};
|
|
@ -1,21 +0,0 @@
|
|||
/**
|
||||
* Copyright 2011 Microsoft Corporation
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// Module dependencies.
|
||||
|
||||
// Expose 'RoleInstance'.
|
||||
exports = module.exports = RoleInstance;
|
||||
|
||||
function RoleInstance() { }
|
|
@ -14,6 +14,7 @@
|
|||
*/
|
||||
|
||||
// Module dependencies.
|
||||
var ISO8061Date = require('../util/iso8061date');
|
||||
var js2xml = require('../util/js2xml');
|
||||
var Constants = require('../util/constants');
|
||||
var ServiceRuntimeConstants = Constants.ServiceRuntimeConstants;
|
||||
|
@ -34,9 +35,11 @@ XmlCurrentStateSerializer.prototype.serialize = function (currentState) {
|
|||
if (currentState.status) {
|
||||
currentStateXml[ServiceRuntimeConstants.CURRENT_STATE][ServiceRuntimeConstants.STATUS_LEASE][ServiceRuntimeConstants.ACQUIRE] = {};
|
||||
|
||||
currentStateXml[ServiceRuntimeConstants.CURRENT_STATE][ServiceRuntimeConstants.STATUS_LEASE][ServiceRuntimeConstants.ACQUIRE][ServiceRuntimeConstants.EXPIRATION] = currentState.expiration;
|
||||
var expirationDate = ISO8061Date.format(currentState.expiration);
|
||||
currentStateXml[ServiceRuntimeConstants.CURRENT_STATE][ServiceRuntimeConstants.STATUS_LEASE][ServiceRuntimeConstants.ACQUIRE][ServiceRuntimeConstants.INCARNATION] = currentState.incarnation;
|
||||
currentStateXml[ServiceRuntimeConstants.CURRENT_STATE][ServiceRuntimeConstants.STATUS_LEASE][ServiceRuntimeConstants.ACQUIRE][ServiceRuntimeConstants.STATUS] = currentState.status;
|
||||
currentStateXml[ServiceRuntimeConstants.CURRENT_STATE][ServiceRuntimeConstants.STATUS_LEASE][ServiceRuntimeConstants.ACQUIRE][ServiceRuntimeConstants.STATUS_DETAIL] = currentState.status;
|
||||
currentStateXml[ServiceRuntimeConstants.CURRENT_STATE][ServiceRuntimeConstants.STATUS_LEASE][ServiceRuntimeConstants.ACQUIRE][ServiceRuntimeConstants.EXPIRATION] = expirationDate;
|
||||
} else {
|
||||
currentStateXml[ServiceRuntimeConstants.CURRENT_STATE][ServiceRuntimeConstants.STATUS_LEASE][ServiceRuntimeConstants.RELEASE] = {};
|
||||
}
|
||||
|
|
|
@ -94,33 +94,14 @@ XmlRoleEnvironmentDataDeserializer.prototype._translateCurrentInstance = functio
|
|||
currentInstance.roleName = xml[ServiceRuntimeConstants.CURRENT_INSTANCE][Constants.ATOM_METADATA_MARKER]['roleName'];
|
||||
currentInstance.faultDomain = xml[ServiceRuntimeConstants.CURRENT_INSTANCE][Constants.ATOM_METADATA_MARKER]['faultDomain'];
|
||||
currentInstance.updateDomain = xml[ServiceRuntimeConstants.CURRENT_INSTANCE][Constants.ATOM_METADATA_MARKER]['updateDomain'];
|
||||
currentInstance.endpoints = this._translateRoleInstanceEndpoints(xml);
|
||||
|
||||
return currentInstance;
|
||||
};
|
||||
|
||||
XmlRoleEnvironmentDataDeserializer.prototype._translateRoleInstanceEndpoints = function(xml) {
|
||||
var endpointsMap = { };
|
||||
|
||||
if (xml[ServiceRuntimeConstants.CURRENT_INSTANCE] &&
|
||||
xml[ServiceRuntimeConstants.CURRENT_INSTANCE][ServiceRuntimeConstants.ENDPOINTS] &&
|
||||
xml[ServiceRuntimeConstants.CURRENT_INSTANCE][ServiceRuntimeConstants.ENDPOINTS][ServiceRuntimeConstants.ENDPOINT]) {
|
||||
|
||||
var endpoints = xml[ServiceRuntimeConstants.CURRENT_INSTANCE][ServiceRuntimeConstants.ENDPOINTS][ServiceRuntimeConstants.ENDPOINT];
|
||||
if (!Array.isArray(endpoints)) {
|
||||
endpoints = [endpoints];
|
||||
}
|
||||
|
||||
for (var endpoint in endpoints) {
|
||||
var currentEndpoint = endpoints[endpoint];
|
||||
var currentEndpointName = currentEndpoint[Constants.ATOM_METADATA_MARKER]['name'];
|
||||
|
||||
delete currentEndpoint[Constants.ATOM_METADATA_MARKER]['name'];
|
||||
endpointsMap[currentEndpointName] = currentEndpoint[Constants.ATOM_METADATA_MARKER];
|
||||
}
|
||||
if (xml[ServiceRuntimeConstants.CURRENT_INSTANCE][ServiceRuntimeConstants.ENDPOINTS]) {
|
||||
currentInstance.endpoints = this._translateRoleInstanceEndpoints(xml[ServiceRuntimeConstants.CURRENT_INSTANCE][ServiceRuntimeConstants.ENDPOINTS]);
|
||||
} else {
|
||||
currentInstance.endpoints = {};
|
||||
}
|
||||
|
||||
return endpointsMap;
|
||||
return currentInstance;
|
||||
};
|
||||
|
||||
XmlRoleEnvironmentDataDeserializer.prototype._translateRoles = function (xml, currentInstance, currentRole) {
|
||||
|
|
|
@ -1202,6 +1202,22 @@ var Constants = {
|
|||
* @type {string}
|
||||
*/
|
||||
ServiceRuntimeConstants: {
|
||||
/**
|
||||
* The fault domain property.
|
||||
*
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
FAULT_DOMAIN: 'faultDomain',
|
||||
|
||||
/**
|
||||
* The update domain property.
|
||||
*
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
UPDATE_DOMAIN: 'updateDomain',
|
||||
|
||||
/**
|
||||
* The runtime server endpoint element.
|
||||
*
|
||||
|
@ -1354,6 +1370,14 @@ var Constants = {
|
|||
*/
|
||||
CHANGING: 'changing',
|
||||
|
||||
/**
|
||||
* The role environment stopping event.
|
||||
*
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
STOPPING: 'stopping',
|
||||
|
||||
/**
|
||||
* The ready event.
|
||||
*
|
||||
|
@ -1418,6 +1442,14 @@ var Constants = {
|
|||
*/
|
||||
STATUS: 'Status',
|
||||
|
||||
/**
|
||||
* The status detail element.
|
||||
*
|
||||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
STATUS_DETAIL: 'StatusDetail',
|
||||
|
||||
/**
|
||||
* The expiration element.
|
||||
*
|
||||
|
@ -1463,7 +1495,7 @@ var Constants = {
|
|||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
READY: 'ready',
|
||||
READY: 'Ready',
|
||||
|
||||
/**
|
||||
* The busy status.
|
||||
|
@ -1471,7 +1503,7 @@ var Constants = {
|
|||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
BUSY: 'busy'
|
||||
BUSY: 'Busy'
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1487,7 +1519,7 @@ var Constants = {
|
|||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
STARTED: 'started',
|
||||
STARTED: 'Started',
|
||||
|
||||
/**
|
||||
* The stopped event.
|
||||
|
@ -1495,7 +1527,7 @@ var Constants = {
|
|||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
STOPPED: 'stopped',
|
||||
STOPPED: 'Stopped',
|
||||
|
||||
/**
|
||||
* The busy event.
|
||||
|
@ -1503,7 +1535,7 @@ var Constants = {
|
|||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
BUSY: 'busy',
|
||||
BUSY: 'Busy',
|
||||
|
||||
/**
|
||||
* The recycle event.
|
||||
|
@ -1511,7 +1543,7 @@ var Constants = {
|
|||
* @const
|
||||
* @type {string}
|
||||
*/
|
||||
RECYCLE: 'recycle'
|
||||
RECYCLE: 'Recycle'
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -141,9 +141,6 @@
|
|||
<Content Include="..\..\lib\serviceruntime\roleenvironment.js">
|
||||
<Link>lib\serviceruntime\roleenvironment.js</Link>
|
||||
</Content>
|
||||
<Content Include="..\..\lib\serviceruntime\roleinstance.js">
|
||||
<Link>lib\serviceruntime\roleinstance.js</Link>
|
||||
</Content>
|
||||
<Content Include="..\..\lib\serviceruntime\runtimekernel.js">
|
||||
<Link>lib\serviceruntime\runtimekernel.js</Link>
|
||||
</Content>
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -23,7 +23,7 @@ var RuntimeVersionManager = require('../../lib/serviceruntime/runtimeversionmana
|
|||
suite('runtimeversionmanager-tests', function () {
|
||||
test('GetRuntimeClient', function (done) {
|
||||
var inputChannel = new NamedPipeInputChannel();
|
||||
inputChannel.readData = function (name, callback) {
|
||||
inputChannel._readData = function (name, callback) {
|
||||
callback(undefined,
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
||||
"<RuntimeServerDiscovery xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
||||
|
|
|
@ -21,7 +21,7 @@ var RuntimeVersionProtocolClient = require('../../lib/serviceruntime/runtimevers
|
|||
suite('runtimeversionprotocolclient-tests', function () {
|
||||
test('GetVersionMapSingle', function (done) {
|
||||
var inputChannel = new NamedPipeInputChannel();
|
||||
inputChannel.readData = function (name, callback) {
|
||||
inputChannel._readData = function (name, callback) {
|
||||
callback(undefined,
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
||||
"<RuntimeServerDiscovery xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
||||
|
@ -44,7 +44,7 @@ suite('runtimeversionprotocolclient-tests', function () {
|
|||
|
||||
test('GetVersionMapArray', function (done) {
|
||||
var inputChannel = new NamedPipeInputChannel();
|
||||
inputChannel.readData = function (name, callback) {
|
||||
inputChannel._readData = function (name, callback) {
|
||||
callback(undefined,
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
|
||||
"<RuntimeServerDiscovery xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
||||
|
|
Загрузка…
Ссылка в новой задаче