Skip to content

Commit

Permalink
Merge pull request #42 from hawkular/socket-onclose
Browse files Browse the repository at this point in the history
Add notification message on socket close
  • Loading branch information
mtho11 committed Sep 18, 2015
2 parents d792905 + aa1a26e commit 8bd310d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 36 deletions.
30 changes: 18 additions & 12 deletions dist/hawkular-ui-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ var hawkularRest;
_this.port = port;
return _this;
};
this.$get = ['$location', '$rootScope', function ($location, $rootScope) {
this.$get = ['$location', '$rootScope', '$log', function ($location, $rootScope, $log) {
_this.setHost(_this.host || $location.host() || 'localhost');
_this.setPort(_this.port || $location.port() || 8080);
var prefix = 'ws://' + _this.host + ':' + _this.port;
Expand All @@ -694,13 +694,13 @@ var hawkularRest;
var responseHandlers = [{
prefix: 'GenericSuccessResponse=',
handle: function (operationResponse) {
console.log('Execution Operation request delivery: ', operationResponse.message);
$log.log('Execution Operation request delivery: ', operationResponse.message);
NotificationService.info('Execution Ops request delivery: ' + operationResponse.message);
}
}, {
prefix: 'ExecuteOperationResponse=',
handle: function (operationResponse) {
console.log('Handling ExecuteOperationResponse');
$log.log('Handling ExecuteOperationResponse');
if (operationResponse.status === "OK") {
NotificationService.success('Operation "' + operationResponse.operationName + '" on resource "'
+ operationResponse.resourceId + '" succeeded.');
Expand All @@ -710,7 +710,7 @@ var hawkularRest;
+ operationResponse.resourceId + '" failed: ' + operationResponse.message);
}
else {
console.log('Unexpected operationResponse: ', operationResponse);
$log.log('Unexpected operationResponse: ', operationResponse);
}
}
},
Expand All @@ -732,7 +732,7 @@ var hawkularRest;
else {
message = 'Deployment File: "' + deploymentResponse.destinationFileName + '" on resource "'
+ deploymentResponse.resourcePath + '" failed: ' + deploymentResponse.message;
console.error('Unexpected AddDeploymentOperationResponse: ', deploymentResponse);
$log.warn('Unexpected AddDeploymentOperationResponse: ', deploymentResponse);
$rootScope.$broadcast('DeploymentAddError', message);
}
}
Expand All @@ -754,22 +754,28 @@ var hawkularRest;
else {
message = 'Add JBDC Driver on resource "'
+ addDriverResponse.resourcePath + '" failed: ' + addDriverResponse.message;
console.error('Unexpected AddJdbcDriverOperationResponse: ', addDriverResponse);
$log.warn('Unexpected AddJdbcDriverOperationResponse: ', addDriverResponse);
$rootScope.$broadcast('JDBCDriverAddError', message);
}
}
},
{
prefix: 'GenericErrorResponse=',
handle: function (operationResponse) {
NotificationService.error('Operation failed: ' + operationResponse.message);
$log.warn('Unexpected AddJdbcDriverOperationResponse: ', operationResponse.message);
NotificationService.info('Operation failed: ' + operationResponse.message);
}
}];
ws.onopen = function () {
console.log('Execution Ops Socket has been opened!');
$log.log('Execution Ops Socket has been opened!');
};
ws.onclose = function (event) {
$log.warn('Execution Ops Socket closed!');
NotificationService.error('Execution Ops socket closed: ' + event.reason);
$rootScope.$broadcast('WebSocketClosed', event.reason);
};
ws.onmessage = function (message) {
console.log('Execution Ops WebSocket received:', message);
$log.log('Execution Ops WebSocket received:', message);
var data = message.data;
for (var i = 0; i < responseHandlers.length; i++) {
var h = responseHandlers[i];
Expand All @@ -779,7 +785,7 @@ var hawkularRest;
break;
}
}
console.info('Unexpected WebSocket Execution Ops message: ', message);
$log.info('Unexpected WebSocket Execution Ops message: ', message);
};
factory.init = function (ns) {
NotificationService = ns;
Expand All @@ -791,13 +797,13 @@ var hawkularRest;
if (enabled === void 0) { enabled = true; }
var json = "DeployApplicationRequest={\"resourcePath\": \"" + resourcePath + "\",\n \"destinationFileName\":\"" + destinationFileName + "\", \"enabled\":\"" + enabled + "\",\n \"authentication\": {\"token\":\"" + authToken + "\", \"persona\":\"" + personaId + "\" } }";
var binaryblob = new Blob([json, fileBinaryContent], { type: 'application/octet-stream' });
console.log('DeployApplicationRequest: ' + json);
$log.log('DeployApplicationRequest: ' + json);
ws.send(binaryblob);
};
factory.performAddJDBCDriverOperation = function (resourcePath, driverJarName, driverName, moduleName, driverClass, fileBinaryContent, authToken, personaId) {
var json = "AddJdbcDriverRequest={\"resourcePath\": \"" + resourcePath + "\",\n \"driverJarName\":\"" + driverJarName + "\", \"driverName\":\"" + driverName + "\", \"moduleName\":\"" + moduleName + "\",\n \"driverClass\":\"" + driverClass + "\", \"authentication\": {\"token\":\"" + authToken + "\", \"persona\":\"" + personaId + "\" } }";
var binaryblob = new Blob([json, fileBinaryContent], { type: 'application/octet-stream' });
console.log('AddJDBCDriverRequest: ' + json);
$log.log('AddJDBCDriverRequest: ' + json);
ws.send(binaryblob);
};
return factory;
Expand Down
30 changes: 18 additions & 12 deletions dist/hawkular-ui-service.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,7 +682,7 @@ var hawkularRest;
_this.port = port;
return _this;
};
this.$get = ['$location', '$rootScope', function ($location, $rootScope) {
this.$get = ['$location', '$rootScope', '$log', function ($location, $rootScope, $log) {
_this.setHost(_this.host || $location.host() || 'localhost');
_this.setPort(_this.port || $location.port() || 8080);
var prefix = 'ws://' + _this.host + ':' + _this.port;
Expand All @@ -694,13 +694,13 @@ var hawkularRest;
var responseHandlers = [{
prefix: 'GenericSuccessResponse=',
handle: function (operationResponse) {
console.log('Execution Operation request delivery: ', operationResponse.message);
$log.log('Execution Operation request delivery: ', operationResponse.message);
NotificationService.info('Execution Ops request delivery: ' + operationResponse.message);
}
}, {
prefix: 'ExecuteOperationResponse=',
handle: function (operationResponse) {
console.log('Handling ExecuteOperationResponse');
$log.log('Handling ExecuteOperationResponse');
if (operationResponse.status === "OK") {
NotificationService.success('Operation "' + operationResponse.operationName + '" on resource "'
+ operationResponse.resourceId + '" succeeded.');
Expand All @@ -710,7 +710,7 @@ var hawkularRest;
+ operationResponse.resourceId + '" failed: ' + operationResponse.message);
}
else {
console.log('Unexpected operationResponse: ', operationResponse);
$log.log('Unexpected operationResponse: ', operationResponse);
}
}
},
Expand All @@ -732,7 +732,7 @@ var hawkularRest;
else {
message = 'Deployment File: "' + deploymentResponse.destinationFileName + '" on resource "'
+ deploymentResponse.resourcePath + '" failed: ' + deploymentResponse.message;
console.error('Unexpected AddDeploymentOperationResponse: ', deploymentResponse);
$log.warn('Unexpected AddDeploymentOperationResponse: ', deploymentResponse);
$rootScope.$broadcast('DeploymentAddError', message);
}
}
Expand All @@ -754,22 +754,28 @@ var hawkularRest;
else {
message = 'Add JBDC Driver on resource "'
+ addDriverResponse.resourcePath + '" failed: ' + addDriverResponse.message;
console.error('Unexpected AddJdbcDriverOperationResponse: ', addDriverResponse);
$log.warn('Unexpected AddJdbcDriverOperationResponse: ', addDriverResponse);
$rootScope.$broadcast('JDBCDriverAddError', message);
}
}
},
{
prefix: 'GenericErrorResponse=',
handle: function (operationResponse) {
NotificationService.error('Operation failed: ' + operationResponse.message);
$log.warn('Unexpected AddJdbcDriverOperationResponse: ', operationResponse.message);
NotificationService.info('Operation failed: ' + operationResponse.message);
}
}];
ws.onopen = function () {
console.log('Execution Ops Socket has been opened!');
$log.log('Execution Ops Socket has been opened!');
};
ws.onclose = function (event) {
$log.warn('Execution Ops Socket closed!');
NotificationService.error('Execution Ops socket closed: ' + event.reason);
$rootScope.$broadcast('WebSocketClosed', event.reason);
};
ws.onmessage = function (message) {
console.log('Execution Ops WebSocket received:', message);
$log.log('Execution Ops WebSocket received:', message);
var data = message.data;
for (var i = 0; i < responseHandlers.length; i++) {
var h = responseHandlers[i];
Expand All @@ -779,7 +785,7 @@ var hawkularRest;
break;
}
}
console.info('Unexpected WebSocket Execution Ops message: ', message);
$log.info('Unexpected WebSocket Execution Ops message: ', message);
};
factory.init = function (ns) {
NotificationService = ns;
Expand All @@ -791,13 +797,13 @@ var hawkularRest;
if (enabled === void 0) { enabled = true; }
var json = "DeployApplicationRequest={\"resourcePath\": \"" + resourcePath + "\",\n \"destinationFileName\":\"" + destinationFileName + "\", \"enabled\":\"" + enabled + "\",\n \"authentication\": {\"token\":\"" + authToken + "\", \"persona\":\"" + personaId + "\" } }";
var binaryblob = new Blob([json, fileBinaryContent], { type: 'application/octet-stream' });
console.log('DeployApplicationRequest: ' + json);
$log.log('DeployApplicationRequest: ' + json);
ws.send(binaryblob);
};
factory.performAddJDBCDriverOperation = function (resourcePath, driverJarName, driverName, moduleName, driverClass, fileBinaryContent, authToken, personaId) {
var json = "AddJdbcDriverRequest={\"resourcePath\": \"" + resourcePath + "\",\n \"driverJarName\":\"" + driverJarName + "\", \"driverName\":\"" + driverName + "\", \"moduleName\":\"" + moduleName + "\",\n \"driverClass\":\"" + driverClass + "\", \"authentication\": {\"token\":\"" + authToken + "\", \"persona\":\"" + personaId + "\" } }";
var binaryblob = new Blob([json, fileBinaryContent], { type: 'application/octet-stream' });
console.log('AddJDBCDriverRequest: ' + json);
$log.log('AddJDBCDriverRequest: ' + json);
ws.send(binaryblob);
};
return factory;
Expand Down
31 changes: 19 additions & 12 deletions src/rest/hawkRest-ops-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module hawkularRest {
return this;
};

this.$get = ['$location', '$rootScope', ($location, $rootScope) => {
this.$get = ['$location', '$rootScope','$log', ($location, $rootScope, $log) => {
// If available, used pre-configured values, otherwise use values from current browser location of fallback to
// defaults
this.setHost(this.host || $location.host() || 'localhost');
Expand All @@ -52,14 +52,14 @@ module hawkularRest {
let responseHandlers = [{
prefix: 'GenericSuccessResponse=',
handle: (operationResponse:any) => {
console.log('Execution Operation request delivery: ', operationResponse.message);
$log.log('Execution Operation request delivery: ', operationResponse.message);
// Probably makes no sense to show this in the UI
NotificationService.info('Execution Ops request delivery: ' + operationResponse.message);
}
}, {
prefix: 'ExecuteOperationResponse=',
handle: (operationResponse:any) => {
console.log('Handling ExecuteOperationResponse');
$log.log('Handling ExecuteOperationResponse');
if (operationResponse.status === "OK") {

NotificationService.success('Operation "' + operationResponse.operationName + '" on resource "'
Expand All @@ -68,7 +68,7 @@ module hawkularRest {
NotificationService.error('Operation "' + operationResponse.operationName + '" on resource "'
+ operationResponse.resourceId + '" failed: ' + operationResponse.message);
} else {
console.log('Unexpected operationResponse: ', operationResponse);
$log.log('Unexpected operationResponse: ', operationResponse);
}
}
},
Expand All @@ -92,7 +92,7 @@ module hawkularRest {
} else {
message = 'Deployment File: "' + deploymentResponse.destinationFileName + '" on resource "'
+ deploymentResponse.resourcePath + '" failed: ' + deploymentResponse.message;
console.error('Unexpected AddDeploymentOperationResponse: ', deploymentResponse);
$log.warn('Unexpected AddDeploymentOperationResponse: ', deploymentResponse);
$rootScope.$broadcast('DeploymentAddError', message);
}
}
Expand All @@ -116,24 +116,31 @@ module hawkularRest {
} else {
message = 'Add JBDC Driver on resource "'
+ addDriverResponse.resourcePath + '" failed: ' + addDriverResponse.message;
console.error('Unexpected AddJdbcDriverOperationResponse: ', addDriverResponse);
$log.warn('Unexpected AddJdbcDriverOperationResponse: ', addDriverResponse);
$rootScope.$broadcast('JDBCDriverAddError', message);
}
}
},
{
prefix: 'GenericErrorResponse=',
handle: (operationResponse) => {
NotificationService.error('Operation failed: ' + operationResponse.message);
$log.warn('Unexpected AddJdbcDriverOperationResponse: ', operationResponse.message);
NotificationService.info('Operation failed: ' + operationResponse.message);
}
}];

ws.onopen = () => {
console.log('Execution Ops Socket has been opened!');
$log.log('Execution Ops Socket has been opened!');
};

ws.onclose = (event) => {
$log.warn('Execution Ops Socket closed!');
NotificationService.error('Execution Ops socket closed: ' + event.reason);
$rootScope.$broadcast('WebSocketClosed', event.reason);
};

ws.onmessage = (message:any) => {
console.log('Execution Ops WebSocket received:', message);
$log.log('Execution Ops WebSocket received:', message);
let data = message.data;

for (let i = 0; i < responseHandlers.length; i++) {
Expand All @@ -144,7 +151,7 @@ module hawkularRest {
break;
}
}
console.info('Unexpected WebSocket Execution Ops message: ', message);
$log.info('Unexpected WebSocket Execution Ops message: ', message);
};

factory.init = (ns:any) => {
Expand All @@ -165,7 +172,7 @@ module hawkularRest {
"destinationFileName":"${destinationFileName}", "enabled":"${enabled}",
"authentication": {"token":"${authToken}", "persona":"${personaId}" } }`;
let binaryblob = new Blob([json, fileBinaryContent], {type: 'application/octet-stream'});
console.log('DeployApplicationRequest: ' + json);
$log.log('DeployApplicationRequest: ' + json);
ws.send(binaryblob);
};

Expand All @@ -181,7 +188,7 @@ module hawkularRest {
"driverJarName":"${driverJarName}", "driverName":"${driverName}", "moduleName":"${moduleName}",
"driverClass":"${driverClass}", "authentication": {"token":"${authToken}", "persona":"${personaId}" } }`;
let binaryblob = new Blob([json, fileBinaryContent], {type: 'application/octet-stream'});
console.log('AddJDBCDriverRequest: ' + json);
$log.log('AddJDBCDriverRequest: ' + json);
ws.send(binaryblob);
};

Expand Down

0 comments on commit 8bd310d

Please sign in to comment.