Skip to content

Commit 4625f69

Browse files
authored
chore: Search revert to old version (#3096)
1 parent 5ac3d6b commit 4625f69

15 files changed

+197
-259
lines changed

internal/cli/deployments/search/indexes/create.go

+1-7
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,7 @@ func (opts *CreateOpts) RunAtlas() error {
105105
return err
106106
}
107107

108-
//TODO: CLOUDP-260963 Update to use the new struct
109-
result, err := opts.store.CreateSearchIndexes(opts.ConfigProjectID(), opts.DeploymentName, index)
110-
if err != nil {
111-
return err
112-
}
113-
114-
opts.index = search.IndexResponseToDeprecated(result)
108+
opts.index, err = opts.store.CreateSearchIndexes(opts.ConfigProjectID(), opts.DeploymentName, index)
115109
return err
116110
}
117111

internal/cli/deployments/search/indexes/create_test.go

+10-12
Original file line numberDiff line numberDiff line change
@@ -290,19 +290,17 @@ func TestCreate_RunAtlas(t *testing.T) {
290290
index, err := opts.NewSearchIndex()
291291
require.NoError(t, err)
292292

293-
indexWithID := &atlasv2.SearchIndexResponse{
294-
CollectionName: &opts.Collection,
295-
Database: &opts.DBName,
296-
LatestDefinition: &atlasv2.BaseSearchIndexResponseLatestDefinition{
297-
Analyzer: &opts.Analyzer,
298-
Mappings: &atlasv2.SearchMappings{
299-
Dynamic: &opts.Dynamic,
300-
Fields: nil,
301-
},
302-
SearchAnalyzer: &opts.SearchAnalyzer,
293+
indexWithID := &atlasv2.ClusterSearchIndex{
294+
CollectionName: opts.Collection,
295+
Database: opts.DBName,
296+
Analyzer: &opts.Analyzer,
297+
Mappings: &atlasv2.ApiAtlasFTSMappings{
298+
Dynamic: &opts.Dynamic,
299+
Fields: nil,
303300
},
304-
Name: &opts.Name,
305-
IndexID: &indexID,
301+
SearchAnalyzer: &opts.SearchAnalyzer,
302+
Name: opts.Name,
303+
IndexID: &indexID,
306304
}
307305

308306
deploymentTest.CommonAtlasMocks(opts.ProjectID)

internal/cli/deployments/search/indexes/describe_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -156,18 +156,18 @@ func TestDescribe_RunAtlas(t *testing.T) {
156156
mockStore.
157157
EXPECT().
158158
SearchIndex(opts.ProjectID, opts.DeploymentName, opts.indexID).
159-
Return(&atlasv2.SearchIndexResponse{
160-
Name: &name,
161-
Database: &database,
162-
CollectionName: &collectionName,
159+
Return(&atlasv2.ClusterSearchIndex{
160+
Name: name,
161+
Database: database,
162+
CollectionName: collectionName,
163163
IndexID: pointer.Get("test"),
164164
}, nil).
165165
Times(1)
166166

167-
expected := &atlasv2.SearchIndexResponse{
168-
Name: &name,
169-
Database: &database,
170-
CollectionName: &collectionName,
167+
expected := &atlasv2.ClusterSearchIndex{
168+
Name: name,
169+
Database: database,
170+
CollectionName: collectionName,
171171
IndexID: pointer.Get("test"),
172172
}
173173

internal/cli/deployments/search/indexes/list_test.go

+8-8
Original file line numberDiff line numberDiff line change
@@ -177,22 +177,22 @@ func TestList_RunAtlas(t *testing.T) {
177177
mockStore.
178178
EXPECT().
179179
SearchIndexes(opts.ProjectID, opts.DeploymentName, opts.DBName, opts.Collection).
180-
Return([]atlasv2.SearchIndexResponse{
180+
Return([]atlasv2.ClusterSearchIndex{
181181
{
182-
Name: &expectedName,
183-
Database: &expectedDB,
184-
CollectionName: &expectedCollection,
182+
Name: expectedName,
183+
Database: expectedDB,
184+
CollectionName: expectedCollection,
185185
IndexID: pointer.Get(expectedID),
186186
},
187187
}, nil).
188188
Times(1)
189189

190-
expected := []*atlasv2.SearchIndexResponse{
190+
expected := []*atlasv2.ClusterSearchIndex{
191191
{
192-
Name: &expectedName,
192+
Name: expectedName,
193193
IndexID: pointer.Get(expectedID),
194-
CollectionName: &expectedCollection,
195-
Database: &expectedDB,
194+
CollectionName: expectedCollection,
195+
Database: expectedDB,
196196
},
197197
}
198198

internal/cli/search/create_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func TestCreateOpts_Run(t *testing.T) {
4545
if err != nil {
4646
t.Fatalf("newSearchIndex() unexpected error: %v", err)
4747
}
48-
expected := &atlasv2.SearchIndexResponse{}
48+
expected := &atlasv2.ClusterSearchIndex{}
4949
mockStore.
5050
EXPECT().
5151
CreateSearchIndexes(opts.ProjectID, opts.clusterName, request).
@@ -68,7 +68,7 @@ func TestCreateOpts_Run(t *testing.T) {
6868
opts.Filename = fileName
6969
opts.Fs = appFS
7070

71-
expected := &atlasv2.SearchIndexResponse{}
71+
expected := &atlasv2.ClusterSearchIndex{}
7272
request, err := opts.NewSearchIndex()
7373
if err != nil {
7474
t.Fatalf("newSearchIndex() unexpected error: %v", err)

internal/cli/search/describe_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ func TestDescribe_Run(t *testing.T) {
3535
store: mockStore,
3636
}
3737

38-
expected := &atlasv2.SearchIndexResponse{
39-
Name: &describeOpts.clusterName,
38+
expected := &atlasv2.ClusterSearchIndex{
39+
Name: describeOpts.clusterName,
4040
}
4141
mockStore.
4242
EXPECT().

internal/cli/search/index_opts.go

+9-56
Original file line numberDiff line numberDiff line change
@@ -116,22 +116,9 @@ func (opts *IndexOpts) DeprecatedNewSearchIndex() (*atlasv2.ClusterSearchIndex,
116116
return i, nil
117117
}
118118

119-
func IndexResponseToDeprecated(r *atlasv2.SearchIndexResponse) *atlasv2.ClusterSearchIndex {
120-
return &atlasv2.ClusterSearchIndex{
121-
CollectionName: *r.CollectionName,
122-
Database: *r.Database,
123-
Mappings: (*atlasv2.ApiAtlasFTSMappings)(r.LatestDefinition.Mappings),
124-
Name: *r.Name,
125-
SearchAnalyzer: r.LatestDefinition.SearchAnalyzer,
126-
Status: r.Status,
127-
Type: r.Type,
128-
IndexID: r.IndexID,
129-
}
130-
}
131-
132-
func (opts *IndexOpts) NewSearchIndex() (*atlasv2.SearchIndexCreateRequest, error) {
119+
func (opts *IndexOpts) NewSearchIndex() (*atlasv2.ClusterSearchIndex, error) {
133120
if len(opts.Filename) > 0 {
134-
index := &atlasv2.SearchIndexCreateRequest{}
121+
index := &atlasv2.ClusterSearchIndex{}
135122
if err := file.Load(opts.Fs, opts.Filename, index); err != nil {
136123
return nil, fmt.Errorf(failedToLoadIndexMessage, err.Error())
137124
}
@@ -152,51 +139,17 @@ func (opts *IndexOpts) NewSearchIndex() (*atlasv2.SearchIndexCreateRequest, erro
152139
opts.SearchAnalyzer = DefaultAnalyzer
153140
}
154141

155-
i := &atlasv2.SearchIndexCreateRequest{
142+
i := &atlasv2.ClusterSearchIndex{
156143
CollectionName: opts.Collection,
157144
Database: opts.DBName,
158145
Name: opts.Name,
159146
// only search indexes can be created using flags
160-
Type: pointer.Get(SearchIndexType),
161-
Definition: &atlasv2.BaseSearchIndexCreateRequestDefinition{
162-
Analyzer: &opts.Analyzer,
163-
SearchAnalyzer: &opts.SearchAnalyzer,
164-
Mappings: &atlasv2.SearchMappings{
165-
Dynamic: &opts.Dynamic,
166-
Fields: f,
167-
},
168-
},
169-
}
170-
return i, nil
171-
}
172-
173-
func (opts *IndexOpts) NewSearchIndexUpdate() (*atlasv2.SearchIndexUpdateRequest, error) {
174-
if len(opts.Filename) > 0 {
175-
index := &atlasv2.SearchIndexUpdateRequest{}
176-
if err := file.Load(opts.Fs, opts.Filename, index); err != nil {
177-
return nil, fmt.Errorf(failedToLoadIndexMessage, err.Error())
178-
}
179-
180-
return index, nil
181-
}
182-
183-
f, err := opts.indexFields()
184-
if err != nil {
185-
return nil, err
186-
}
187-
188-
if opts.SearchAnalyzer == "" {
189-
opts.SearchAnalyzer = DefaultAnalyzer
190-
}
191-
192-
i := &atlasv2.SearchIndexUpdateRequest{
193-
Definition: atlasv2.SearchIndexUpdateRequestDefinition{
194-
Analyzer: &opts.Analyzer,
195-
SearchAnalyzer: &opts.SearchAnalyzer,
196-
Mappings: &atlasv2.SearchMappings{
197-
Dynamic: &opts.Dynamic,
198-
Fields: f,
199-
},
147+
Type: pointer.Get(SearchIndexType),
148+
Analyzer: &opts.Analyzer,
149+
SearchAnalyzer: &opts.SearchAnalyzer,
150+
Mappings: &atlasv2.ApiAtlasFTSMappings{
151+
Dynamic: &opts.Dynamic,
152+
Fields: f,
200153
},
201154
}
202155
return i, nil

internal/cli/search/list_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ func TestList_Run(t *testing.T) {
3434
}
3535

3636
name := "test"
37-
expected := []atlasv2.SearchIndexResponse{
37+
expected := []atlasv2.ClusterSearchIndex{
3838
{
39-
Name: &name,
39+
Name: name,
4040
},
4141
}
4242

internal/cli/search/nodes/delete.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ type DeleteOpts struct {
3535
store store.SearchNodesDeleter
3636
}
3737

38-
const atlasFtsDeploymentDoesNotExist = "ATLAS_FTS_DEPLOYMENT_DOES_NOT_EXIST"
38+
const atlasFtsDeploymentDoesNotExist = "ATLAS_SEARCH_DEPLOYMENT_DOES_NOT_EXIST"
3939

4040
func (opts *DeleteOpts) initStore(ctx context.Context) func() error {
4141
return func() error {

internal/cli/search/update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (opts *UpdateOpts) initStore(ctx context.Context) func() error {
4848
var updateTemplate = "Index {{.Name}} updated.\n"
4949

5050
func (opts *UpdateOpts) Run() error {
51-
index, err := opts.NewSearchIndexUpdate()
51+
index, err := opts.NewSearchIndex()
5252
if err != nil {
5353
return err
5454
}

internal/cli/search/update_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ func TestUpdateOpts_Run(t *testing.T) {
3737
updateOpts.Name = testName
3838
updateOpts.id = "1"
3939

40-
expected := &atlasv2.SearchIndexResponse{}
40+
expected := &atlasv2.ClusterSearchIndex{}
4141

42-
request, err := updateOpts.NewSearchIndexUpdate()
42+
request, err := updateOpts.NewSearchIndex()
4343
require.NoError(t, err)
4444
mockStore.
4545
EXPECT().
@@ -63,9 +63,9 @@ func TestUpdateOpts_Run(t *testing.T) {
6363
updateOpts.Filename = fileName
6464
updateOpts.Fs = appFS
6565

66-
expected := &atlasv2.SearchIndexResponse{}
66+
expected := &atlasv2.ClusterSearchIndex{}
6767

68-
request, err := updateOpts.NewSearchIndexUpdate()
68+
request, err := updateOpts.NewSearchIndex()
6969
require.NoError(t, err)
7070
mockStore.
7171
EXPECT().

internal/mocks/mock_search.go

+10-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)