Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

const Chance = require('chance'); // eslint-disable-line import/no-extraneous-dependencies
const chance = new Chance();

export const getAutoFollowPatternMock = (
remoteCluster = chance.string(),
leaderIndexPatterns = [chance.string()],
followIndexPattern = chance.string()
) => ({
remote_cluster: remoteCluster,
leader_index_patterns: leaderIndexPatterns,
follow_index_pattern: followIndexPattern
});

export const getAutoFollowPatternListMock = (total = 3) => {
const list = {};

let i = total;
while(i--) {
list[chance.string()] = getAutoFollowPatternMock();
}

return list;
};
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ export class AutoFollowPatternListUI extends PureComponent {
title={(
<h1>
<FormattedMessage
id="xpack.cross_cluster_replication.autofollow_pattern_list.empty_prompt_title"
defaultMessage="Create your first auto-follow pattern"
id="xpack.crossClusterReplication.autoFollowPatternList.emptyPromptTitle"
defaultMessage="Cross cluster replication"
/>
</h1>
)}
body={
<Fragment>
<p>
<FormattedMessage
id="xpack.cross_cluster_replication.autofollow_pattern_list.empty_prompt_description"
defaultMessage="Auto follow-patterns automatically create follower index to replicate indices from a leader cluster."
id="xpack.crossClusterReplication.autoFollowPatternList.emptyPromptDescription"
defaultMessage="Auto-follow patterns replicate leader indices from a remote cluster to follower indices on the local cluster." //eslint-disable-line max-len
/>
</p>
</Fragment>
Expand All @@ -65,7 +65,7 @@ export class AutoFollowPatternListUI extends PureComponent {
iconType="plusInCircle"
>
<FormattedMessage
id="xpack.cross_cluster_replication.add_autofollow_pattern_button_label"
id="xpack.crossClusterReplication.addAutoFollowPatternButtonLabel"
defaultMessage="Add auto-follow pattern"
/>
</EuiButton>
Expand All @@ -81,7 +81,7 @@ export class AutoFollowPatternListUI extends PureComponent {
return (
<SectionLoading>
<FormattedMessage
id="xpack.cross_cluster_replication.autofollow_pattern_list.loading_title"
id="xpack.crossClusterReplication.autoFollowPatternList.loadingTitle"
defaultMessage="Loading auto-follow patterns..."
/>
</SectionLoading>
Expand All @@ -104,7 +104,7 @@ export class AutoFollowPatternListUI extends PureComponent {

if (apiError) {
const title = intl.formatMessage({
id: 'xpack.cross_cluster_replication.autofollow_pattern_list.loading_error_title',
id: 'xpack.crossClusterReplication.autoFollowPatternList.loadingErrorTitle',
defaultMessage: 'Error loading auto-follow patterns',
});
return <SectionError title={title} error={apiError} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,12 @@ export class AutoFollowPatternTableUI extends PureComponent {

if(queryText) {
return autoFollowPatterns.filter(autoFollowPattern => {
const { __id__, remote_cluster } = autoFollowPattern; // eslint-disable-line camelcase
const { name, remoteCluster } = autoFollowPattern;

if (__id__.toLowerCase().toLowerCase().includes(queryText)) {
return true;
}
const inName = name.toLowerCase().includes(queryText);
const inRemoteCluster = remoteCluster.toLowerCase().includes(queryText);

if (remote_cluster.toLowerCase().toLowerCase().includes(queryText)) {
return true;
}

return false;
return inName || inRemoteCluster;
});
}

Expand All @@ -60,7 +55,7 @@ export class AutoFollowPatternTableUI extends PureComponent {
const { intl } = this.props;

return [{
field: '__id__',
field: 'name',
name: (
<FormattedMessage
id="xpack.cross_cluster_replication.autofollow_pattern_list.table.name_column_title"
Expand All @@ -70,7 +65,7 @@ export class AutoFollowPatternTableUI extends PureComponent {
sortable: true,
truncateText: false,
}, {
field: 'remote_cluster',
field: 'remoteCluster',
name: (
<FormattedMessage
id="xpack.cross_cluster_replication.autofollow_pattern_list.table.cluster_column_title"
Expand All @@ -80,7 +75,7 @@ export class AutoFollowPatternTableUI extends PureComponent {
truncateText: true,
sortable: true,
}, {
field: 'leader_index_patterns',
field: 'leaderIndexPatterns',
name: (
<FormattedMessage
id="xpack.cross_cluster_replication.autofollow_pattern_list.table.leader_patterns_column_title"
Expand All @@ -89,7 +84,7 @@ export class AutoFollowPatternTableUI extends PureComponent {
),
render: (leaderPatterns) => leaderPatterns.join(', '),
}, {
field: 'follow_index_pattern',
field: 'followIndexPattern',
name: (
<FormattedMessage
id="xpack.cross_cluster_replication.autofollow_pattern_list.table.connected_nodes_column_title"
Expand Down Expand Up @@ -119,7 +114,7 @@ export class AutoFollowPatternTableUI extends PureComponent {

const sorting = {
sort: {
field: '__id__',
field: 'name',
direction: 'asc',
}
};
Expand Down Expand Up @@ -153,7 +148,7 @@ export class AutoFollowPatternTableUI extends PureComponent {
return (
<EuiInMemoryTable
items={this.getFilteredPatterns()}
itemId="__id__"
itemId="name"
columns={this.getTableColumns()}
search={search}
pagination={pagination}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export class CrossClusterReplicationHomeUI extends PureComponent {
getHeaderSection() {
const { autoFollowPatterns } = this.props;

if (!autoFollowPatterns.length) {
return null;
}

return (
<Fragment>
<EuiPageContentHeader>
Expand All @@ -48,61 +52,32 @@ export class CrossClusterReplicationHomeUI extends PureComponent {
/>
</h1>
</EuiTitle>
<EuiText>
<p>
<FormattedMessage
id="xpack.cross_cluster_replication.autofolloPatternList.sectionDescription"
defaultMessage="Auto-follow patterns replicate leader indices from a remote cluster to follower indices on the local cluster." //eslint-disable-line max-len
/>
</p>
</EuiText>
</EuiPageContentHeaderSection>
<EuiPageContentHeaderSection>
{ autoFollowPatterns.length
? (
<EuiButton
{...routing.getRouterLinkProps(`${BASE_PATH}/auto_follow_patterns/add`)}
fill
>
<FormattedMessage
id="xpack.cross_cluster_replication.add_autofollow_pattern_button_label"
defaultMessage="Add auto-follow pattern"
/>
</EuiButton>
)
: null }
<EuiButton
{...routing.getRouterLinkProps(`${BASE_PATH}/auto_follow_patterns/add`)}
fill
>
<FormattedMessage
id="xpack.cross_cluster_replication.add_autofollow_pattern_button_label"
defaultMessage="Create auto-follow pattern"
/>
</EuiButton>
</EuiPageContentHeaderSection>
</EuiPageContentHeader>
<EuiSpacer />
</Fragment>
);
}

/**
* In phase 1 we only have the aufo-follow patterns but in phase 2 we will add
* the follower indices. We will render here the Tab navigation at that moment.
* For now we simply render a Title
*/
getTitleSection() {
const { autoFollowPatterns, isAutoFollowApiAuthorized } = this.props;
const showTitle = autoFollowPatterns.length || !isAutoFollowApiAuthorized;

return showTitle ? (
<Fragment>
<EuiTitle>
<h2>
<FormattedMessage
id="xpack.cross_cluster_replication.autofollow_pattern_list_title"
defaultMessage="Auto-follow patterns"
/>
</h2>
</EuiTitle>
<EuiSpacer size="s" />
<EuiText>
<p>
<FormattedMessage
id="xpack.cross_cluster_replication.autofolloPatternList.sectionDescription"
defaultMessage="Manage your auto-follow patterns"
/>
</p>
</EuiText>
<EuiSpacer />
</Fragment>
) : null;
}

getUnauthorizedSection() {
const { isAutoFollowApiAuthorized } = this.props;
if (!isAutoFollowApiAuthorized) {
Expand Down Expand Up @@ -133,7 +108,6 @@ export class CrossClusterReplicationHomeUI extends PureComponent {
<EuiPageBody>
<EuiPageContent>
{this.getHeaderSection()}
{this.getTitleSection()}
{this.getUnauthorizedSection()}
{this.getSection()}
</EuiPageContent>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,19 @@ export const elasticsearchJsPlugin = (Client, config, components) => {
],
method: 'GET'
});

ccr.createAutoFollowPattern = ca({
urls: [
{
fmt: '/_ccr/auto_follow/<%=id%>',
req: {
id: {
type: 'string'
}
}
}
],
needBody: true,
method: 'PUT'
});
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

export const deserializeAutoFollowPattern = (
name,
{ remote_cluster, leader_index_patterns, follow_index_pattern } = {} // eslint-disable-line camelcase
) => ({
name,
remoteCluster: remote_cluster,
leaderIndexPatterns: leader_index_patterns,
followIndexPattern: follow_index_pattern,
});

export const deserializeListAutoFollowPatterns = autofollowPatterns =>
Object.entries(autofollowPatterns).reduce(
(deserialized, [name, autofollowPattern]) => ({
...deserialized,
[name]: deserializeAutoFollowPattern(name, autofollowPattern),
}),
{}
);

export const serializeAutoFollowPattern = ({
remoteCluster,
leaderIndexPatterns,
followIndexPattern,
}) => ({
remote_cluster: remoteCluster,
leader_index_patterns: leaderIndexPatterns,
follow_index_pattern: followIndexPattern,
});

Loading