-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Elasticsearch Version Resolve Capabilities #21
Changes from 5 commits
5ec02c7
9fc62eb
adfed39
0ef5ca4
5b473ee
ee82ad9
e905ac3
d89052a
408a38f
d417f00
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
using System; | ||
using System; | ||
|
||
public static class Constants { | ||
public static string ExpectedOperatingSystem; | ||
|
@@ -17,6 +17,11 @@ public static class Constants { | |
public static string SpecificRabbitVersion; | ||
public static string SpecificServiceVersion; | ||
|
||
// Elasticsearch variables | ||
public static string LatestElasticHostname; | ||
public static string SpecificElasticHostname; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
public static string SpecificElasticVersion; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
|
||
static Constants() { | ||
ExpectedOperatingSystem = Environment.GetEnvironmentVariable("OPERATING_SYSTEM") ?? "windows"; | ||
|
||
|
@@ -31,5 +36,9 @@ public static class Constants { | |
SpecificMongoVersion = Environment.GetEnvironmentVariable("SPECIFIC_MONGO_VERSION") ?? "3.0.0"; | ||
SpecificRabbitVersion = Environment.GetEnvironmentVariable("SPECIFIC_RABBIT_VERSION") ?? "3.6.5"; | ||
SpecificServiceVersion = Environment.GetEnvironmentVariable("SPECIFIC_SERVICE_VERSION") ?? "1.0.0"; | ||
|
||
LatestElasticHostname = Environment.GetEnvironmentVariable("LATEST_ELASTIC_HOSTNAME") ?? "localhost"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Environment Variables should also contain the full name of Elasticsearch, should be |
||
SpecificElasticHostname = Environment.GetEnvironmentVariable("SPECIFIC_ELASTIC_HOSTNAME") ?? "localhost"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
SpecificElasticVersion = Environment.GetEnvironmentVariable("SPECIFIC_ELASTIC_VERSION") ?? "5.5.1"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
using NAME.ConnectionStrings; | ||
using NAME.Core; | ||
using NAME.Elasticsearch; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Xunit; | ||
|
||
namespace NAME.IntegrationTests.Elasticsearch | ||
{ | ||
public class ElasticsearchVersionResolverTests | ||
{ | ||
[Fact] | ||
[Trait("TestCategory", "Integration")] | ||
public async Task GetVersions_SpecificVersion() | ||
{ | ||
ElasticsearchVersionResolver resolver = new ElasticsearchVersionResolver(new StaticConnectionStringProvider($"http://{ Constants.SpecificMongoHostname }:9200"), 10000, 10000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo, should be |
||
|
||
var versions = await resolver.GetVersions().ConfigureAwait(false); | ||
|
||
Assert.Equal(1, versions.Count()); | ||
Assert.Equal(versions.First(), DependencyVersion.Parse(Constants.SpecificElasticVersion)); | ||
} | ||
|
||
[Fact] | ||
[Trait("TestCategory", "Integration")] | ||
public async Task GetVersions_LatestVersion() | ||
{ | ||
ElasticsearchVersionResolver resolver = new ElasticsearchVersionResolver(new StaticConnectionStringProvider($"http://{ Constants.LatestMongoHostname }:9200"), 10000, 10000); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above |
||
|
||
var versions = await resolver.GetVersions().ConfigureAwait(false); | ||
|
||
Assert.Equal(1, versions.Count()); | ||
// Latest GA RELEASE: https://www.elastic.co/downloads/elasticsearch#ga-release | ||
Assert.Equal(versions.First(), DependencyVersion.Parse("5.6.3")); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ services: | |
- specific-mongo | ||
- specific-rabbitmq | ||
- dummy-service | ||
- elastic | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same, use the full name of elasticsearch, to keep things consistent. |
||
- specific-elastic | ||
environment: | ||
- LATEST_MONGO_HOSTNAME=mongo | ||
- LATEST_RABBIT_HOSTNAME=rabbitmq | ||
|
@@ -21,6 +23,9 @@ services: | |
- SPECIFIC_SERVICE_VERSION=1.0.0 | ||
- OPERATING_SYSTEM=debian | ||
- RUNNING_ON_DOCKER=true | ||
- LATEST_ELASTIC_HOSTNAME=elastic | ||
- SPECIFIC_ELASTIC_HOSTNAME=specific-elastic | ||
- SPECIFIC_ELASTIC_VERSION=5.5.1 | ||
volumes: | ||
- ../Output/Artifacts/NuGets/Release:/integration/nugets | ||
- ../Output/IntegrationTestsResults:/integration/TestResults | ||
|
@@ -31,6 +36,8 @@ services: | |
- specific-mongo | ||
- specific-rabbitmq | ||
- dummy-service | ||
- elastic | ||
- specific-elastic | ||
dummy-service: | ||
build: ./NAME.DummyService | ||
environment: | ||
|
@@ -61,4 +68,17 @@ services: | |
- "1433" | ||
environment: | ||
- SA_PASSWORD=W1#llnotbeused | ||
- ACCEPT_EULA=Y | ||
- ACCEPT_EULA=Y | ||
elastic: | ||
image: docker.elastic.co/elasticsearch/elasticsearch:5.6.3 | ||
expose: | ||
- "9200" | ||
environment: | ||
- xpack.security.enabled=false | ||
specific-elastic: | ||
image: docker.elastic.co/elasticsearch/elasticsearch:5.5.1 | ||
expose: | ||
- "9200" | ||
environment: | ||
- xpack.security.enabled=false | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
using NAME.Core; | ||
using NAME.Core.Exceptions; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
|
||
namespace NAME.Elasticsearch | ||
{ | ||
internal class ElasticsearchVersionResolver : ConnectedVersionResolver | ||
{ | ||
private IConnectionStringProvider connectionStringProvider; | ||
|
||
public ElasticsearchVersionResolver(IConnectionStringProvider connectionStringProvider, int connectTimeout, int readWriteTimeout) | ||
: base(connectTimeout, readWriteTimeout) | ||
{ | ||
this.connectionStringProvider = connectionStringProvider; | ||
} | ||
|
||
public override async Task<IEnumerable<DependencyVersion>> GetVersions() | ||
{ | ||
var versions = new List<DependencyVersion>(); | ||
var connectionString = string.Empty; | ||
|
||
if (!this.connectionStringProvider.TryGetConnectionString(out connectionString)) | ||
{ | ||
throw new ConnectionStringNotFoundException(this.connectionStringProvider.ToString()); | ||
} | ||
|
||
HttpWebResponse response; | ||
try | ||
{ | ||
var request = this.GetHttpWebRequest(connectionString, SupportedDependencies.Elasticsearch.ToString()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Although you set the |
||
response = await request.GetResponseAsync() as HttpWebResponse; | ||
} | ||
catch (Exception e) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should catch the most relevant exception instead of the base |
||
{ | ||
throw new DependencyNotReachableException($"{SupportedDependencies.Elasticsearch}: {e.Message}"); | ||
} | ||
using (var reader = new StreamReader(response.GetResponseStream())) | ||
{ | ||
var body = await reader.ReadToEndAsync(); | ||
var version = string.Empty; | ||
try | ||
{ | ||
version = this.DeserializeJsonResponse(body); | ||
versions.Add(DependencyVersion.Parse(version)); | ||
} | ||
catch (Exception e) | ||
{ | ||
throw new VersionParsingException(version, e.Message); | ||
} | ||
} | ||
|
||
return versions; | ||
} | ||
|
||
private string DeserializeJsonResponse(string result) | ||
{ | ||
var jsonResult = Json.Json.Parse(result); | ||
return jsonResult["version"]["number"]; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use the full name of Elasticsearch, should be
LatestElasticsearchHostname