Skip to content

Commit 19354af

Browse files
authored
Merge pull request #753 from Particular/allow-connectivity-config-via-webapp
Allow connectivity config via webapp
2 parents 2982061 + d81774a commit 19354af

File tree

70 files changed

+1607
-1103
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1607
-1103
lines changed

GitVersion.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
assembly-versioning-scheme: Major
2-
next-version: 1.19
2+
next-version: 1.20
33
branches:
44
release:
55
tag: rc
Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
1-
;(function (window, angular, undefined) { 'use strict';
2-
3-
window.config = {
4-
default_route: '/dashboard',
5-
service_control_url: 'http://localhost:33333/api/',
6-
monitoring_urls: ['http://localhost:33633/']
7-
};
8-
9-
angular.module('sc')
10-
.constant('version', '1.2.0')
11-
.constant('showPendingRetry', false)
12-
.constant('scConfig', window.config);
13-
14-
}(window, window.angular));
1+
window.defaultConfig = {
2+
default_route: '/dashboard',
3+
version: '1.2.0',
4+
service_control_url: 'http://localhost:33333/api/',
5+
monitoring_urls: ['http://localhost:33633/']
6+
};

src/ServicePulse.Host.Tests/ServicePulse.Host.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<PackageReference Include="NUnit" Version="3.11.0" />
1414
<PackageReference Include="NUnit3TestAdapter" Version="3.13.0" />
1515
<PackageReference Include="Particular.Approvals" Version="0.2.0" />
16+
<PackageReference Include="System.ValueTuple" Version="4.5.0" />
1617
</ItemGroup>
1718

1819
<ItemGroup>

src/ServicePulse.Host.Tests/VerifyAppConstantsJSTextReplacement.cs

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
using System.Reflection;
2-
3-
namespace ServicePulse.Host.Tests
1+
namespace ServicePulse.Host.Tests
42
{
3+
using NUnit.Framework;
54
using System;
65
using System.Collections.Generic;
76
using System.IO;
8-
97
using System.Text.RegularExpressions;
10-
using NUnit.Framework;
118

129
[TestFixture]
1310
public class VerifyAppConstantsJSTextReplacement
@@ -16,14 +13,14 @@ public class VerifyAppConstantsJSTextReplacement
1613
// this both user configurable and updated during installation
1714

1815
Regex sc_url_regex = new Regex(@"(service_control_url\s*\:\s*['""])(.*?)(['""])");
19-
Regex version_regex = new Regex(@"(constant\s*\(\s*'version'\s*,\s*['""])(.*?)(['""])");
16+
Regex version_regex = new Regex(@"(version\s*\:\s*['""])(.*?)(['""])");
2017

2118
[Test]
2219
public void app_constants_js_validation()
2320
{
2421
var pathToConfig = Path.Combine(TestContext.CurrentContext.TestDirectory, "app.constants.js");
2522
Assert.IsTrue(File.Exists(pathToConfig), "app.constants.js does not exist - this will break installation code");
26-
23+
2724
var config = File.ReadAllText(pathToConfig);
2825
var matchUrl = sc_url_regex.Match(config);
2926
Assert.IsTrue(matchUrl.Success, "regex failed to match app.constant.js for SC URI update");
@@ -37,35 +34,71 @@ public void app_constants_js_validation()
3734
[Test]
3835
public void replace_version_regex_tests()
3936
{
40-
var configSnippets = new Dictionary<string, string>
37+
var configSnippets = new Dictionary<string, (string ConfigSnippet, Regex VersionRegex)>()
4138
{
42-
{"1.3.0", @"angular.module('sc')
43-
.constant('version', '1.3.0')
44-
.constant('scConfig';"},
45-
{"1.3.0-beta1", @"angular.module('sc')
46-
.constant ( 'version' , '1.3.0-beta1')
47-
.constant('scConfig';"},
48-
{"", @"angular.module('sc')
49-
.constant('version' , '' )
50-
.constant('scConfig';"}
39+
{
40+
"1.3.0",
41+
(
42+
ConfigSnippet: @"angular.module('sc')
43+
.constant('version', '1.3.0')
44+
.constant('scConfig';",
45+
VersionRegex: new Regex(@"(constant\s*\(\s*'version'\s*,\s*['""])(.*?)(['""])")
46+
)
47+
},
48+
{
49+
"1.3.0-beta1",
50+
(
51+
ConfigSnippet: @"angular.module('sc')
52+
.constant ( 'version' , '1.3.0-beta1')
53+
.constant('scConfig';",
54+
VersionRegex: new Regex(@"(constant\s*\(\s*'version'\s*,\s*['""])(.*?)(['""])")
55+
)
56+
},
57+
{
58+
"",
59+
(
60+
ConfigSnippet: @"angular.module('sc')
61+
.constant('version' , '' )
62+
.constant('scConfig';",
63+
VersionRegex: new Regex(@"(constant\s*\(\s*'version'\s*,\s*['""])(.*?)(['""])")
64+
)
65+
},
66+
{
67+
"1.20.0",
68+
(
69+
ConfigSnippet: @"window.defaultConfig = {
70+
version: '1.20.0',
71+
service_control_url: '
72+
};",
73+
VersionRegex: new Regex(@"(version\s*\:\s*['""])(.*?)(['""])")
74+
)
75+
},
5176
};
5277

5378
foreach (var config in configSnippets)
5479
{
5580
var expectedResult = config.Key;
56-
var text = config.Value;
81+
var text = config.Value.ConfigSnippet;
5782

58-
var match = version_regex.Match(text);
83+
var match = config.Value.VersionRegex.Match(text);
5984
Assert.IsTrue(match.Success, "regex failed to match version string");
6085
Assert.IsTrue(match.Groups[2].Value.Equals(expectedResult), string.Format("Version regex did not return expected value which was {0}", expectedResult));
6186
}
6287
}
63-
88+
6489
[Test]
65-
public void test_regex_match_against_config_variants ()
90+
public void test_regex_match_against_config_variants()
6691
{
6792
var configVariations = new[]
6893
{
94+
// Standard 1.20.0 config
95+
@"window.defaultConfig = {
96+
default_route: '/dashboard',
97+
version: '1.20.0',
98+
service_control_url: 'http://localhost:33333/api/',
99+
monitoring_urls: ['http://localhost:33633/']
100+
};
101+
",
69102
// Standard 1.3 config
70103
@"angular.module('sc')
71104
.constant('version', '1.3.0')

src/ServicePulse.Host.Tests/karma.conf.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ module.exports = function(config) {
44
browsers: ['PhantomJS', 'PhantomJS_custom', 'Chrome'],
55
basePath: '../ServicePulse.Host/app',
66
files: [
7-
'./modules/dist/shell.dist.js',
8-
'../../ServicePulse.Host.Tests/tests/js/angular-mocks.js',
9-
'./js/app.js',
7+
'./modules/dist/shell.dist.js',
8+
'../../ServicePulse.Host.Tests/tests/js/angular-mocks.js',
109
'./js/**/*.html',
1110
'./js/app.constants.js',
11+
'./modules/dist/configuration.dist.js',
12+
'./js/app.js',
13+
'./js/app.bootstrap.js',
1214
'./js/**/*.module.js',
1315
'./js/**/*.tabset.js',
14-
'./js/**/*.js',
15-
'./modules/dist/configuration.dist.js',
16-
'./modules/dist/monitoring.dist.js',
17-
'../../ServicePulse.Host.Tests/tests/**/*.spec.js'],
16+
'./js/directives/**/*.js',
17+
'./js/polyfill/**/*.js',
18+
'./js/services/**/*.js',
19+
'./js/views/**/*.js',
20+
'./modules/dist/monitoring.dist.js',
21+
'../../ServicePulse.Host.Tests/tests/**/*.spec.js'],
1822
frameworks: ['jasmine'],
1923
// you can define custom flags
2024
customLaunchers: {
@@ -36,12 +40,12 @@ module.exports = function(config) {
3640
},
3741

3842
proxies: {
39-
'/js/views/dashboard/dashboard.html': '/base/js/views/dashboard/dashboard.html'
43+
'/js/views/dashboard/dashboard.html': '/base/js/views/dashboard/dashboard.html'
4044
},
4145

4246
phantomjsLauncher: {
4347
// Have phantomjs exit if a ResourceError is encountered (useful if karma exits without killing phantom)
4448
exitOnResourceError: true
45-
}
49+
}
4650
})
4751
}

src/ServicePulse.Host.Tests/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
{
22
"name": "ServicePulse.Host.Tests",
33
"version": "1.0.0",
4-
"dependencies": {
5-
6-
},
4+
"dependencies": {},
75
"devDependencies": {
86
"karma-chrome-launcher": "^2.2.0",
97
"karma-firefox-launcher": "^1.1.0",

src/ServicePulse.Host.Tests/tests/js/services/services.monitoring.spec.js

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,22 @@
2222

2323
var monitoringService, $httpBackend, scConfig;
2424

25-
beforeEach(inject(function (_monitoringService_, _$httpBackend_, _scConfig_) {
25+
beforeEach(inject(function (_monitoringService_, _$httpBackend_) {
2626
monitoringService = _monitoringService_;
2727
$httpBackend = _$httpBackend_;
28-
scConfig = _scConfig_;
28+
scConfig = window.defaultConfig;
2929
}));
3030

3131
it('should push endpoints retrieved from monitoring server', function (done) {
32-
scConfig.monitoring_urls = ['http://localhost:33633/'];
32+
window.defaultConfig.monitoring_urls = ['http://localhost:33633/'];
3333

3434
$httpBackend.whenGET('http://localhost:33633/monitored-endpoints?history=5').respond(monitoredEndpointWithData);
3535

3636
var monitoredEndpoints = [];
3737
var subscription = monitoringService.createEndpointsSource(5).subscribe(function (response) {
3838
monitoredEndpoints.push(response);
3939

40-
if (monitoredEndpoints.length == 2) {
40+
if (monitoredEndpoints.length === 2) {
4141
expect(monitoredEndpoints[0].name).toEqual("Samples.Metrics.Tracing.Endpoint1");
4242
expect(monitoredEndpoints[0].data.timestamps).toEqual([]);
4343
expect(monitoredEndpoints[0].data.criticalTime).toEqual([]);
@@ -56,26 +56,4 @@
5656
$httpBackend.flush();
5757
}, 0);
5858
});
59-
60-
it('should push endpoints retrieved from multiple monitoring servers', function (done) {
61-
$httpBackend.whenGET('http://localhost:1234/monitored-endpoints?history=5').respond(monitoredEndpointWithData);
62-
$httpBackend.whenGET('http://localhost:5678/monitored-endpoints?history=5').respond(monitoredEndpointWithData);
63-
64-
scConfig.monitoring_urls = ['http://localhost:1234/', 'http://localhost:5678/'];
65-
66-
var monitoredEndpoints = [];
67-
var subscription = monitoringService.createEndpointsSource(5).subscribe(function (response) {
68-
monitoredEndpoints.push(response);
69-
70-
if (monitoredEndpoints.length == 4) {
71-
expect(monitoredEndpoints.length).toEqual(4);
72-
subscription.dispose();
73-
done();
74-
}
75-
});
76-
77-
setTimeout(function () {
78-
$httpBackend.flush();
79-
}, 0);
80-
});
8159
});

src/ServicePulse.Host.Tests/tests/js/services/services.spec.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
describe("Unit: Uri Service ", function() {
44

55
it('should load angular', function() {
6-
expect(typeof (angular) == typeof (undefined)).toEqual(false);
6+
expect(typeof (angular) === typeof (undefined)).toEqual(false);
77
});
88

99
describe("Uri Joins:", function() {
@@ -12,7 +12,7 @@ describe("Unit: Uri Service ", function() {
1212

1313
it('should contain a uri service',
1414
inject(function(uri) {
15-
expect(typeof (uri) == typeof(undefined)).toEqual(false);
15+
expect(typeof (uri) === typeof(undefined)).toEqual(false);
1616
}));
1717

1818
it('should prevent double slashes for leading and trailing slashes', inject(function (uri) {
@@ -25,39 +25,39 @@ describe("Unit: Uri Service ", function() {
2525
expect(url).toEqual('http://localhost:33333/api/eventlogitems');
2626
}));
2727

28-
it('should make a url for get Failed Messages For Exception Group', inject(function (uri, scConfig) {
28+
it('should make a url for get Failed Messages For Exception Group', inject(function (uri) {
2929
var groupId = '85147b12-458c-431d-a389-35ea53abc9e1';
3030
var page = 1;
3131
var sortBy = 'time_of_failure';
32-
var url = uri.join(scConfig.service_control_url, 'recoverability', 'groups', groupId, 'errors?page=' + page + '&sort=' + sortBy + '&status=unresolved');
32+
var url = uri.join(window.defaultConfig.service_control_url, 'recoverability', 'groups', groupId, 'errors?page=' + page + '&sort=' + sortBy + '&status=unresolved');
3333
expect(url).toEqual('http://localhost:33333/api/recoverability/groups/85147b12-458c-431d-a389-35ea53abc9e1/errors?page=1&sort=time_of_failure&status=unresolved');
3434
}));
3535

36-
it('should make a url for get Failed Messages For Exception Group', inject(function (uri, scConfig) {
36+
it('should make a url for get Failed Messages For Exception Group', inject(function (uri) {
3737
var messageId = '85147b12-458c-431d-a389-35ea53abc9e1';
38-
var url = uri.join(scConfig.service_control_url, 'messages', messageId, 'body');
38+
var url = uri.join(window.defaultConfig.service_control_url, 'messages', messageId, 'body');
3939
expect(url).toEqual('http://localhost:33333/api/messages/85147b12-458c-431d-a389-35ea53abc9e1/body');
4040
}));
4141

42-
it('should make a url for getMessageBody', inject(function (uri, scConfig) {
42+
it('should make a url for getMessageBody', inject(function (uri) {
4343
var messageId = '85147b12-458c-431d-a389-35ea53abc9e1';
44-
var url = uri.join(scConfig.service_control_url, 'messages', messageId, 'body');
44+
var url = uri.join(window.defaultConfig.service_control_url, 'messages', messageId, 'body');
4545
expect(url).toEqual('http://localhost:33333/api/messages/85147b12-458c-431d-a389-35ea53abc9e1/body');
4646
}));
4747

48-
it('should make a url for getMessageHeaders', inject(function (uri, scConfig) {
48+
it('should make a url for getMessageHeaders', inject(function (uri) {
4949
var messageId = '85147b12-458c-431d-a389-35ea53abc9e1';
50-
var url = uri.join(scConfig.service_control_url, 'messages', 'search', messageId);
50+
var url = uri.join(window.defaultConfig.service_control_url, 'messages', 'search', messageId);
5151
expect(url).toEqual('http://localhost:33333/api/messages/search/85147b12-458c-431d-a389-35ea53abc9e1');
5252
}));
5353

54-
it('should make a url for getTotalFailedMessages', inject(function (uri, scConfig) {
55-
var url = uri.join(scConfig.service_control_url, 'errors?status=unresolved');
54+
it('should make a url for getTotalFailedMessages', inject(function (uri) {
55+
var url = uri.join(window.defaultConfig.service_control_url, 'errors?status=unresolved');
5656
expect(url).toEqual('http://localhost:33333/api/errors?status=unresolved');
5757
}));
5858

59-
it('should make a url for retry errors', inject(function (uri, scConfig) {
60-
var url = uri.join(scConfig.service_control_url, 'errors', 'retry');
59+
it('should make a url for retry errors', inject(function (uri) {
60+
var url = uri.join(window.defaultConfig.service_control_url, 'errors', 'retry');
6161
expect(url).toEqual('http://localhost:33333/api/errors/retry');
6262
}));
6363

src/ServicePulse.Host/Commands/ExtractAndUpdateConstantsCommand.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static void UpdateVersion(string directoryPath)
5959
{
6060
var appJsPath = Path.Combine(directoryPath, "js/app.constants.js");
6161
var appJsCode = File.ReadAllText(appJsPath);
62-
var updatedContent = Regex.Replace(appJsCode, @"(constant\(\s*'version'\s*,\s*')(.*?)(')", "${1}" + GetFileVersion() + "$3");
62+
var updatedContent = Regex.Replace(appJsCode, @"(version\s*\:\s*['""])(.*?)(['""])", "${1}" + GetFileVersion() + "$3");
6363
File.WriteAllText(appJsPath, updatedContent);
6464
}
6565

@@ -79,4 +79,4 @@ static string GetFileVersion()
7979
return typeof(AbstractCommand).Assembly.GetName().Version.ToString(4);
8080
}
8181
}
82-
}
82+
}

src/ServicePulse.Host/ServicePulse.Host.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
<ItemGroup>
1616
<PackageReference Include="GitVersionTask" Version="4.0.0-beta0012" PrivateAssets="All" />
1717
<PackageReference Include="Nancy.Hosting.Self" Version="1.4.1" />
18+
<Content Include="app\modules\configuration\connectionsManager.js" />
19+
<Content Include="app\js\views\sc_not_available.html" />
20+
<Content Include="app\modules\configuration\js\connections\connections.controller.js" />
21+
<Content Include="app\modules\configuration\js\connections\connections.module.js" />
22+
<Content Include="app\modules\configuration\js\connections\connections.route.js" />
23+
<Content Include="app\modules\configuration\views\connections.html" />
1824
</ItemGroup>
1925

2026
<ItemGroup>

0 commit comments

Comments
 (0)