Skip to content

Commit

Permalink
[beatscm] update to use seqNo/primaryTerm, remove unused method
Browse files Browse the repository at this point in the history
  • Loading branch information
spalger committed Feb 3, 2019
1 parent d563488 commit 52d890f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ export interface DatabaseSearchResponse<T> {
_id: string;
_score: number;
_source: T;
// TODO-VERSION
_version?: number;
_seq_no?: number;
_primary_term?: number;
_explanation?: DatabaseExplanation;
fields?: any;
highlight?: any;
Expand Down Expand Up @@ -129,8 +129,8 @@ export interface DatabaseGetDocumentResponse<Source> {
_index: string;
_type: string;
_id: string;
// TODO-VERSION
_version: number;
_seq_no: number;
_primary_term: number;
found: boolean;
_source: Source;
}
Expand Down Expand Up @@ -184,9 +184,8 @@ export interface DatabaseDeleteDocumentParams extends DatabaseGenericParams {
refresh?: DatabaseRefresh;
routing?: string;
timeout?: string;
// TODO-VERSION
version?: number;
versionType?: DatabaseVersionType;
ifSeqNo?: number;
ifPrimaryTerm?: number;
index: string;
type: string;
id: string;
Expand All @@ -197,8 +196,8 @@ export interface DatabaseIndexDocumentResponse {
_index: string;
_type: string;
_id: string;
// TODO-VERSION
_version: number;
_seq_no: number;
_primary_term: number;
result: string;
}

Expand All @@ -207,8 +206,8 @@ export interface DatabaseUpdateDocumentResponse {
_index: string;
_type: string;
_id: string;
// TODO-VERSION
_version: number;
_seq_no: number;
_primary_term: number;
result: string;
}

Expand All @@ -217,8 +216,8 @@ export interface DatabaseDeleteDocumentResponse {
_index: string;
_type: string;
_id: string;
// TODO-VERSION
_version: number;
_seq_no: number;
_primary_term: number;
result: string;
}

Expand All @@ -231,9 +230,8 @@ export interface DatabaseIndexDocumentParams<T> extends DatabaseGenericParams {
timeout?: string;
timestamp?: Date | number;
ttl?: string;
// TODO-VERSION
version?: number;
versionType?: DatabaseVersionType;
ifSeqNo?: number;
ifPrimaryTerm?: number;
pipeline?: string;
id?: string;
index: string;
Expand All @@ -253,9 +251,8 @@ export interface DatabaseCreateDocumentParams extends DatabaseGenericParams {
timeout?: string;
timestamp?: Date | number;
ttl?: string;
// TODO-VERSION
version?: number;
versionType?: DatabaseVersionType;
ifSeqNo?: number;
ifPrimaryTerm?: number;
pipeline?: string;
id?: string;
index: string;
Expand All @@ -273,9 +270,8 @@ export interface DatabaseDeleteDocumentParams extends DatabaseGenericParams {
refresh?: DatabaseRefresh;
routing?: string;
timeout?: string;
// TODO-VERSION
version?: number;
versionType?: DatabaseVersionType;
ifSeqNo?: number;
ifPrimaryTerm?: number;
index: string;
type: string;
id: string;
Expand All @@ -291,17 +287,15 @@ export interface DatabaseGetParams extends DatabaseGenericParams {
_source?: DatabaseNameList;
_sourceExclude?: DatabaseNameList;
_source_includes?: DatabaseNameList;
// TODO-VERSION
version?: number;
versionType?: DatabaseVersionType;
ifSeqNo?: number;
ifPrimaryTerm?: number;
id: string;
index: string;
type: string;
}

export type DatabaseNameList = string | string[] | boolean;
export type DatabaseRefresh = boolean | 'true' | 'false' | 'wait_for' | '';
export type DatabaseVersionType = 'internal' | 'external' | 'external_gte' | 'force';
export type ExpandWildcards = 'open' | 'closed' | 'none' | 'all';
export type DefaultOperator = 'AND' | 'OR';
export type DatabaseConflicts = 'abort' | 'proceed';
Expand All @@ -320,7 +314,7 @@ export interface DatabaseDeleteDocumentResponse {
_index: string;
_type: string;
_id: string;
// TODO-VERSION
_version: number;
_seq_no: number;
_primary_term: number;
result: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { get } from 'lodash';
import { INDEX_NAMES } from 'x-pack/plugins/beats_management/common/constants';
import { beatsIndexTemplate } from '../../../utils/index_templates';
import { FrameworkUser } from '../framework/adapter_types';
Expand Down Expand Up @@ -120,44 +119,6 @@ export class KibanaDatabaseAdapter implements DatabaseAdapter {
return result;
}

private async fetchAllFromScroll<Source>(
user: FrameworkUser,
response: DatabaseSearchResponse<Source>,
hits: DatabaseSearchResponse<Source>['hits']['hits'] = []
): Promise<
Array<{
_index: string;
_type: string;
_id: string;
_score: number;
_source: Source;
// TODO-VERSION
_version?: number;
fields?: any;
highlight?: any;
inner_hits?: any;
sort?: string[];
}>
> {
const newHits = get(response, 'hits.hits', []);
const scrollId = get(response, '_scroll_id');

if (newHits.length > 0) {
hits.push(...newHits);

return this.callWithUser(user, 'scroll', {
body: {
scroll: '30s',
scroll_id: scrollId,
},
}).then((innerResponse: DatabaseSearchResponse<Source>) => {
return this.fetchAllFromScroll(user, innerResponse, hits);
});
}

return Promise.resolve(hits);
}

private callWithUser(user: FrameworkUser, esMethod: string, options: any = {}): any {
if (user.kind === 'authenticated') {
return this.es.callWithRequest(
Expand Down

0 comments on commit 52d890f

Please sign in to comment.