forked from spinnaker/deck
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(search): add supplemental searching capability (spinnaker#4133)
* when keyword search is not performed, removes applications and clusters from being searched by the the search API to speed up searching because both can be determined separately. * application information can be retrieved via the applications API endpoint - which is cached.. * cluster information for search results can be determined entirely from server groups. * adds ability to hydrate search results posthumously to add requested, extra information.
- Loading branch information
Showing
20 changed files
with
403 additions
and
85 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
app/scripts/modules/core/src/application/ApplicationPostSearchResultSearcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import { IPromise } from 'angular'; | ||
import { StateService } from '@uirouter/angularjs'; | ||
|
||
import { urlBuilderRegistry } from 'core/navigation/urlBuilder.registry'; | ||
import { ApplicationReader, IApplicationSummary } from './service/application.read.service'; | ||
import { IPostSearchResultSearcher } from 'core/search/searchResult/PostSearchResultSearcherRegistry'; | ||
import { ISearchResult } from 'core/search/search.service'; | ||
import { ISearchResultFormatter, searchResultFormatterRegistry } from 'core/search/searchResult/searchResultFormatter.registry'; | ||
import { ISearchResultSet } from 'core/search/infrastructure/infrastructureSearch.service'; | ||
import { IServerGroupSearchResult } from 'core/search/searchResult/model/IServerGroupSearchResult'; | ||
|
||
export class ApplicationPostSearchResultSearcher implements IPostSearchResultSearcher<IServerGroupSearchResult> { | ||
|
||
private static TYPE = 'applications'; | ||
|
||
constructor(private $state: StateService, private applicationReader: ApplicationReader) {} | ||
|
||
public getPostSearchResults(inputs: IServerGroupSearchResult[]): IPromise<ISearchResultSet[]> { | ||
|
||
const names: Set<string> = new Set<string>(inputs.map((result: IServerGroupSearchResult) => result.application)); | ||
return this.applicationReader.listApplications(true).then((apps: IApplicationSummary[]) => { | ||
|
||
const results: ISearchResult[] = apps.filter((app: IApplicationSummary) => names.has(app.name)) | ||
.map((app: IApplicationSummary) => { | ||
return { | ||
accounts: app.accounts, | ||
application: app.name, | ||
displayName: app.name, | ||
href: urlBuilderRegistry.getBuilder(ApplicationPostSearchResultSearcher.TYPE).build({ | ||
application: app.name, | ||
type: ApplicationPostSearchResultSearcher.TYPE | ||
}, this.$state), | ||
email: app.email, | ||
provider: app.cloudProviders, | ||
type: ApplicationPostSearchResultSearcher.TYPE | ||
}; | ||
}); | ||
const formatter: ISearchResultFormatter = searchResultFormatterRegistry.get(ApplicationPostSearchResultSearcher.TYPE); | ||
|
||
return [{ | ||
id: ApplicationPostSearchResultSearcher.TYPE, | ||
category: ApplicationPostSearchResultSearcher.TYPE, | ||
icon: formatter.icon, | ||
iconClass: '', | ||
order: formatter.order, | ||
results | ||
}]; | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
app/scripts/modules/core/src/cluster/ClusterPostSearchResultSearcher.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { IPromise, IQService } from 'angular'; | ||
import { StateService } from '@uirouter/angularjs'; | ||
|
||
import { urlBuilderRegistry } from 'core/navigation/urlBuilder.registry'; | ||
import { | ||
ISearchResultFormatter, | ||
searchResultFormatterRegistry | ||
} from 'core/search/searchResult/searchResultFormatter.registry'; | ||
import { ISearchResultSet } from 'core/search/infrastructure/infrastructureSearch.service'; | ||
import { IClusterSearchResult } from 'core/search/searchResult/model/IClusterSearchResult'; | ||
import { IServerGroupSearchResult } from 'core/search/searchResult/model/IServerGroupSearchResult'; | ||
import { IPostSearchResultSearcher } from 'core/search/searchResult/PostSearchResultSearcherRegistry'; | ||
|
||
export class ClusterPostSearchResultSearcher implements IPostSearchResultSearcher<IServerGroupSearchResult> { | ||
|
||
private static TYPE = 'clusters'; | ||
|
||
constructor(private $q: IQService, private $state: StateService) { | ||
} | ||
|
||
public getPostSearchResults(inputs: IServerGroupSearchResult[]): IPromise<ISearchResultSet[]> { | ||
|
||
const clusters: IClusterSearchResult[] = inputs.map((serverGroup: IServerGroupSearchResult) => { | ||
const { account, application, cluster, detail, region, stack } = serverGroup; | ||
return { | ||
account, | ||
application, | ||
cluster, | ||
displayName: cluster, | ||
href: urlBuilderRegistry.getBuilder(ClusterPostSearchResultSearcher.TYPE).build({ | ||
account, | ||
application, | ||
cluster, | ||
stack, | ||
detail, | ||
region, | ||
type: ClusterPostSearchResultSearcher.TYPE | ||
}, this.$state), | ||
provider: serverGroup.provider, | ||
stack, | ||
type: ClusterPostSearchResultSearcher.TYPE | ||
} | ||
}); | ||
|
||
const formatter: ISearchResultFormatter = searchResultFormatterRegistry.get(ClusterPostSearchResultSearcher.TYPE); | ||
return this.$q.when([{ | ||
id: ClusterPostSearchResultSearcher.TYPE, | ||
category: ClusterPostSearchResultSearcher.TYPE, | ||
icon: formatter.icon, | ||
iconClass: '', | ||
order: formatter.order, | ||
results: clusters | ||
}]); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/scripts/modules/core/src/cluster/ClusterSearchResultHydrator.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { get } from 'lodash'; | ||
|
||
import { ApplicationReader, IApplicationSummary } from 'core/application/service/application.read.service'; | ||
import { IClusterSearchResult } from 'core/search/searchResult/model/IClusterSearchResult'; | ||
import { ISearchResultHydrator } from 'core/search/searchResult/SearchResultHydratorRegistry'; | ||
|
||
export class ClusterSearchResultHydrator implements ISearchResultHydrator<IClusterSearchResult> { | ||
|
||
private static FIELDS: string[] = ['email']; | ||
|
||
constructor(private applicationReader: ApplicationReader) {} | ||
|
||
public hydrate(target: IClusterSearchResult[]): void { | ||
|
||
const appMap: Map<string, IApplicationSummary> = this.applicationReader.getApplicationMap(); | ||
target.forEach((cluster: IClusterSearchResult) => { | ||
|
||
const app: IApplicationSummary = appMap.get(cluster.application); | ||
|
||
// pluck all fields from the application and set on the cluster | ||
const hydrationData: { [key: string]: string } = | ||
ClusterSearchResultHydrator.FIELDS.reduce((data: { [key: string]: string }, field: string) => { | ||
data[field] = get<string>(app, field); | ||
return data; | ||
}, {}); | ||
Object.assign(cluster, hydrationData); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,23 @@ | ||
import { module } from 'angular'; | ||
import { IQService, module } from 'angular'; | ||
import { StateService } from '@uirouter/angularjs'; | ||
|
||
import './ClusterSearchResultFormatter'; | ||
import { CLUSTER_ALLCLUSTERSGROUPINGS } from './allClustersGroupings.component'; | ||
import { ON_DEMAND_CLUSTER_PICKER_COMPONENT } from './onDemand/onDemandClusterPicker.component'; | ||
import './ClusterSearchResultFormatter'; | ||
import { PostSearchResultSearcherRegistry } from 'core/search/searchResult/PostSearchResultSearcherRegistry'; | ||
import { SearchResultHydratorRegistry } from 'core/search/searchResult/SearchResultHydratorRegistry'; | ||
import { ClusterPostSearchResultSearcher } from './ClusterPostSearchResultSearcher'; | ||
import { ClusterSearchResultHydrator } from './ClusterSearchResultHydrator'; | ||
import { ApplicationReader } from 'core/application/service/application.read.service'; | ||
|
||
export const CLUSTER_MODULE = 'spinnaker.core.cluster'; | ||
|
||
module(CLUSTER_MODULE, [ | ||
require('./allClusters.controller.js'), | ||
CLUSTER_ALLCLUSTERSGROUPINGS, | ||
ON_DEMAND_CLUSTER_PICKER_COMPONENT, | ||
]); | ||
]) | ||
.run(($q: IQService, $state: StateService, applicationReader: ApplicationReader) => { | ||
PostSearchResultSearcherRegistry.register('clusters', 'serverGroups', new ClusterPostSearchResultSearcher($q, $state)); | ||
SearchResultHydratorRegistry.register('clusters', new ClusterSearchResultHydrator(applicationReader)); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.