Skip to content

Commit

Permalink
show alias next to index
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Gelb committed Jun 20, 2019
1 parent f6d4603 commit c97cf31
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 20 deletions.
3 changes: 3 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<add name="stage" connectionString="http://10.147.31.49:9200,http://10.147.31.51:9200,http://10.147.31.52:9200,http://10.147.31.53:9200,http://10.147.31.54:9200,http://10.147.31.55:9200"/>
<add name="prod" connectionString="http://10.147.21.109:9200,http://10.147.21.110:9200,http://10.147.21.111:9200,http://10.147.21.112:9200,http://10.147.21.113:9200,http://10.147.21.114:9200"/>

<add name="newprod" connectionString="http://10.50.136.80:9200,http://10.50.136.81:9200,http://10.50.136.82:9200,http://10.50.136.83:9200,http://10.50.136.84:9200"/>
<add name="newstage" connectionString="http://10.147.36.11:9200,http://10.147.36.12:9200,http://10.147.36.13:9200"/>

</connectionStrings>

<userSettings>
Expand Down
9 changes: 6 additions & 3 deletions ElasticSearchManager.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
</PropertyGroup>
<ItemGroup>
<Reference Include="AutoMapper, Version=8.1.1.0, Culture=neutral, PublicKeyToken=be96cd2c38ef1005, processorArchitecture=MSIL">
<HintPath>packages\AutoMapper.8.1.1\lib\net461\AutoMapper.dll</HintPath>
</Reference>
<Reference Include="Elasticsearch.Net, Version=6.0.0.0, Culture=neutral, PublicKeyToken=96c599bbe3e70f5d, processorArchitecture=MSIL">
<HintPath>packages\Elasticsearch.Net.6.3.1\lib\net461\Elasticsearch.Net.dll</HintPath>
</Reference>
Expand Down Expand Up @@ -72,6 +75,8 @@
<Compile Include="DataAccess\ElasticAccess.cs" />
<Compile Include="Common\Constants.cs" />
<Compile Include="DataAccess\Database.cs" />
<Compile Include="Entities\ElasticAlias.cs" />
<Compile Include="Entities\ElasticIndex.cs" />
<Compile Include="frmMain.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -126,8 +131,6 @@
<None Include="Resources\if_52_Circled_Arrow_Left_Circle_Direcrion_1864219.png" />
<None Include="Resources\if_89_Import_Down_Download_Save_1864210.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="Entities\" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
23 changes: 23 additions & 0 deletions Entities/ElasticAlias.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ElasticSearchManager {
public class ElasticAlias: CatAliasesRecord {

public static List<ElasticAlias> ToList(ICatResponse<CatAliasesRecord> aliasesRecords) {
var lst = new List<ElasticAlias>();

foreach (var item in aliasesRecords.Records) {

ElasticAlias ea = AutoMapper.Mapper.Map<ElasticAlias>(item);
lst.Add(ea);
}

return lst;
}
}
}
26 changes: 26 additions & 0 deletions Entities/ElasticIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using Nest;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ElasticSearchManager {
public class ElasticIndex : CatIndicesRecord {

public string Alias { get; set; }

public static List<ElasticIndex> ToList(ICatResponse<CatIndicesRecord> indexRecords) {
var lst = new List<ElasticIndex>();

foreach (var item in indexRecords.Records) {

ElasticIndex ea = AutoMapper.Mapper.Map<ElasticIndex>(item);
lst.Add(ea);
}

return lst;
}

}
}
66 changes: 49 additions & 17 deletions frmMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Linq;
using System.Reflection;
using System.Windows.Forms;
using AutoMapper;
using ElasticSearchManager.Common;
using ElasticSearchManager.DataAccess;
using Nest;
Expand Down Expand Up @@ -46,6 +47,7 @@ public frmMain() {
#region Events

private void frmMain_Load(object sender, EventArgs e) {
SetupInfractructure();
PopulateConnections();
InitializeUserSettings();
InitializeTextEditor();
Expand Down Expand Up @@ -90,6 +92,23 @@ private void InitializeUserSettings() {
appSplitContainer.SplitterDistance = Properties.Settings.Default.SplitterDistance;
}

private void SetupInfractructure() {

Mapper.Initialize(cfg => {

cfg.CreateMap<CatAliasesRecord, ElasticAlias>();
cfg.CreateMap<CatIndicesRecord, ElasticIndex>();
});

//Mapper.Initialize(cfg =>
// cfg.CreateMap<CatAliasesRecord, ElasticAlias>();
// cfg.CreateMap<CatIndicesRecord, ElasticIndex>();

//);
//Mapper.Initialize(cfg => cfg.CreateMap<CatIndicesRecord, ElasticIndex>());

}

private void PopulateConnections()
{
cboConnections.ComboBox.ValueMember = "ConnectionString";
Expand All @@ -111,11 +130,24 @@ private void PopulateConnectionEntities() {
using (var access = GetElasticAccess()) {
ClearTree();

ICatResponse<CatIndicesRecord> indexList = access.IndexList();
List<ElasticIndex> indexList = ElasticIndex.ToList(access.IndexList());
RenderIndexes(indexList);

ICatResponse<CatAliasesRecord> aliasList = access.AliasList();
List<ElasticAlias> aliasList = ElasticAlias.ToList(access.AliasList());
RenderAliases(aliasList);

// apply aliases to indexes
ApplyAliasesToIndexes(indexList, aliasList);
}
}

private void ApplyAliasesToIndexes(List<ElasticIndex> indexList, List<ElasticAlias> aliasList) {
foreach (var alias in aliasList) {
// look for the index
var index = indexList.SingleOrDefault(i => i.Index == alias.Index);
if (index != null) {
index.Alias = alias.Alias;
}
}
}

Expand All @@ -128,10 +160,10 @@ private void ClearTree() {
treeEntities.Nodes.Clear();
}

private void RenderIndexes(ICatResponse<CatIndicesRecord> indexList) {
private void RenderIndexes(List<ElasticIndex> indexList) {
var parentNode = treeEntities.Nodes.Add("Indexes");

var records = indexList.Records.OrderBy(r => r.Index).ToList();
var records = indexList.OrderBy(r => r.Index).ToList();
parentNode.Tag = records;

foreach (var record in records) {
Expand All @@ -145,10 +177,10 @@ private void RenderIndexes(ICatResponse<CatIndicesRecord> indexList) {
}
}

private void RenderAliases(ICatResponse<CatAliasesRecord> aliasList) {
private void RenderAliases(List<ElasticAlias> aliasList) {
var parentNode = treeEntities.Nodes.Add("Aliases");

var aliases = aliasList.Records.OrderBy(r => r.Alias).ToList();
var aliases = aliasList.OrderBy(r => r.Alias).ToList();
parentNode.Tag = aliases;

foreach (var alias in aliases) {
Expand Down Expand Up @@ -193,7 +225,7 @@ private void PopulateEntityInformation() {

break;
case EntityType.Alias:
var aliasRecord = (CatAliasesRecord) treeEntities.SelectedNode.Tag;
var aliasRecord = (ElasticAlias) treeEntities.SelectedNode.Tag;
break;
case EntityType.Unknown:
MessageBox.Show("Select either Indexes or Aliases on the left");
Expand Down Expand Up @@ -328,23 +360,23 @@ private void DisplayContentControl(ContentType contentType) {

private void PopulateIndexGrid() {
TreeNode node = treeEntities.SelectedNode;
var indexes = (List<CatIndicesRecord>) node.Tag;
var indexes = (List<ElasticIndex>) node.Tag;

string filter = txtToolbarSearch.Text;
List<CatIndicesRecord> filtered = string.IsNullOrWhiteSpace(filter) ? indexes : indexes.Where(idx => idx.Index.Contains(filter)).ToList();
List<ElasticIndex> filtered = string.IsNullOrWhiteSpace(filter) ? indexes : indexes.Where(idx => idx.Index.Contains(filter)).ToList();

var source = new SortableBindingList<CatIndicesRecord>(filtered);
var source = new SortableBindingList<ElasticIndex>(filtered);
grdEntities.DataSource = source;
}

private void PopulateAliasGrid() {
TreeNode node = treeEntities.SelectedNode;
var aliases = (List<CatAliasesRecord>) node.Tag;
var aliases = (List<ElasticAlias>) node.Tag;

string filter = txtToolbarSearch.Text;
List<CatAliasesRecord> filtered = string.IsNullOrWhiteSpace(filter) ? aliases : aliases.Where(idx => idx.Alias.Contains(filter)).ToList();
List<ElasticAlias> filtered = string.IsNullOrWhiteSpace(filter) ? aliases : aliases.Where(idx => idx.Alias.Contains(filter)).ToList();

var source = new SortableBindingList<CatAliasesRecord>(filtered);
var source = new SortableBindingList<ElasticAlias>(filtered);
grdEntities.DataSource = source;
}

Expand All @@ -370,7 +402,7 @@ private void btnDelete_Click(object sender, EventArgs e) {
access.DeleteIndex(entityIndex);
break;
case EntityType.Alias:
var entityAlias = (CatAliasesRecord)row.DataBoundItem;
var entityAlias = (ElasticAlias)row.DataBoundItem;
access.DeleteAlias(entityAlias);
break;
}
Expand All @@ -393,7 +425,7 @@ private DialogResult AskPermissionToDelete(EntityType selectedType) {
itemsToBeDeleted.Add(entityIndex.Index);
break;
case EntityType.Alias:
var entityAlias = (CatAliasesRecord)row.DataBoundItem;
var entityAlias = (ElasticAlias)row.DataBoundItem;
itemsToBeDeleted.Add(entityAlias.Alias);
break;
}
Expand All @@ -404,7 +436,7 @@ private DialogResult AskPermissionToDelete(EntityType selectedType) {
// check to see if any alias points to it.
TreeNode foundNode = treeEntities.Nodes.FindByFullPath("Aliases");
foreach (TreeNode aliasNode in foundNode.Nodes) {
var alias = (CatAliasesRecord)aliasNode.Tag;
var alias = (ElasticAlias)aliasNode.Tag;

if (itemsToBeDeleted.Contains(alias.Index)) {
indexesPointedToByAlias.Add(alias.Index);
Expand Down Expand Up @@ -450,7 +482,7 @@ private EntityType GetEntityType() {
object o = treeEntities.SelectedNode.Tag;
if (o is CatIndicesRecord) {
return EntityType.Index;
} else if (o is CatAliasesRecord) {
} else if (o is ElasticAlias) {
return EntityType.Alias;
}
}
Expand Down
1 change: 1 addition & 0 deletions packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AutoMapper" version="8.1.1" targetFramework="net472" />
<package id="Elasticsearch.Net" version="6.3.1" targetFramework="net472" />
<package id="jacobslusser.ScintillaNET" version="3.6.3" targetFramework="net461" />
<package id="NEST" version="6.3.1" targetFramework="net472" />
Expand Down

0 comments on commit c97cf31

Please sign in to comment.