Skip to content

Commit

Permalink
chore: Search revert to old version (#3096)
Browse files Browse the repository at this point in the history
  • Loading branch information
blva authored Jul 11, 2024
1 parent 5ac3d6b commit 4625f69
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 259 deletions.
8 changes: 1 addition & 7 deletions internal/cli/deployments/search/indexes/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,7 @@ func (opts *CreateOpts) RunAtlas() error {
return err
}

//TODO: CLOUDP-260963 Update to use the new struct
result, err := opts.store.CreateSearchIndexes(opts.ConfigProjectID(), opts.DeploymentName, index)
if err != nil {
return err
}

opts.index = search.IndexResponseToDeprecated(result)
opts.index, err = opts.store.CreateSearchIndexes(opts.ConfigProjectID(), opts.DeploymentName, index)
return err
}

Expand Down
22 changes: 10 additions & 12 deletions internal/cli/deployments/search/indexes/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,19 +290,17 @@ func TestCreate_RunAtlas(t *testing.T) {
index, err := opts.NewSearchIndex()
require.NoError(t, err)

indexWithID := &atlasv2.SearchIndexResponse{
CollectionName: &opts.Collection,
Database: &opts.DBName,
LatestDefinition: &atlasv2.BaseSearchIndexResponseLatestDefinition{
Analyzer: &opts.Analyzer,
Mappings: &atlasv2.SearchMappings{
Dynamic: &opts.Dynamic,
Fields: nil,
},
SearchAnalyzer: &opts.SearchAnalyzer,
indexWithID := &atlasv2.ClusterSearchIndex{
CollectionName: opts.Collection,
Database: opts.DBName,
Analyzer: &opts.Analyzer,
Mappings: &atlasv2.ApiAtlasFTSMappings{
Dynamic: &opts.Dynamic,
Fields: nil,
},
Name: &opts.Name,
IndexID: &indexID,
SearchAnalyzer: &opts.SearchAnalyzer,
Name: opts.Name,
IndexID: &indexID,
}

deploymentTest.CommonAtlasMocks(opts.ProjectID)
Expand Down
16 changes: 8 additions & 8 deletions internal/cli/deployments/search/indexes/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,18 @@ func TestDescribe_RunAtlas(t *testing.T) {
mockStore.
EXPECT().
SearchIndex(opts.ProjectID, opts.DeploymentName, opts.indexID).
Return(&atlasv2.SearchIndexResponse{
Name: &name,
Database: &database,
CollectionName: &collectionName,
Return(&atlasv2.ClusterSearchIndex{
Name: name,
Database: database,
CollectionName: collectionName,
IndexID: pointer.Get("test"),
}, nil).
Times(1)

expected := &atlasv2.SearchIndexResponse{
Name: &name,
Database: &database,
CollectionName: &collectionName,
expected := &atlasv2.ClusterSearchIndex{
Name: name,
Database: database,
CollectionName: collectionName,
IndexID: pointer.Get("test"),
}

Expand Down
16 changes: 8 additions & 8 deletions internal/cli/deployments/search/indexes/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,22 +177,22 @@ func TestList_RunAtlas(t *testing.T) {
mockStore.
EXPECT().
SearchIndexes(opts.ProjectID, opts.DeploymentName, opts.DBName, opts.Collection).
Return([]atlasv2.SearchIndexResponse{
Return([]atlasv2.ClusterSearchIndex{
{
Name: &expectedName,
Database: &expectedDB,
CollectionName: &expectedCollection,
Name: expectedName,
Database: expectedDB,
CollectionName: expectedCollection,
IndexID: pointer.Get(expectedID),
},
}, nil).
Times(1)

expected := []*atlasv2.SearchIndexResponse{
expected := []*atlasv2.ClusterSearchIndex{
{
Name: &expectedName,
Name: expectedName,
IndexID: pointer.Get(expectedID),
CollectionName: &expectedCollection,
Database: &expectedDB,
CollectionName: expectedCollection,
Database: expectedDB,
},
}

Expand Down
4 changes: 2 additions & 2 deletions internal/cli/search/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func TestCreateOpts_Run(t *testing.T) {
if err != nil {
t.Fatalf("newSearchIndex() unexpected error: %v", err)
}
expected := &atlasv2.SearchIndexResponse{}
expected := &atlasv2.ClusterSearchIndex{}
mockStore.
EXPECT().
CreateSearchIndexes(opts.ProjectID, opts.clusterName, request).
Expand All @@ -68,7 +68,7 @@ func TestCreateOpts_Run(t *testing.T) {
opts.Filename = fileName
opts.Fs = appFS

expected := &atlasv2.SearchIndexResponse{}
expected := &atlasv2.ClusterSearchIndex{}
request, err := opts.NewSearchIndex()
if err != nil {
t.Fatalf("newSearchIndex() unexpected error: %v", err)
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/search/describe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ func TestDescribe_Run(t *testing.T) {
store: mockStore,
}

expected := &atlasv2.SearchIndexResponse{
Name: &describeOpts.clusterName,
expected := &atlasv2.ClusterSearchIndex{
Name: describeOpts.clusterName,
}
mockStore.
EXPECT().
Expand Down
65 changes: 9 additions & 56 deletions internal/cli/search/index_opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,9 @@ func (opts *IndexOpts) DeprecatedNewSearchIndex() (*atlasv2.ClusterSearchIndex,
return i, nil
}

func IndexResponseToDeprecated(r *atlasv2.SearchIndexResponse) *atlasv2.ClusterSearchIndex {
return &atlasv2.ClusterSearchIndex{
CollectionName: *r.CollectionName,
Database: *r.Database,
Mappings: (*atlasv2.ApiAtlasFTSMappings)(r.LatestDefinition.Mappings),
Name: *r.Name,
SearchAnalyzer: r.LatestDefinition.SearchAnalyzer,
Status: r.Status,
Type: r.Type,
IndexID: r.IndexID,
}
}

func (opts *IndexOpts) NewSearchIndex() (*atlasv2.SearchIndexCreateRequest, error) {
func (opts *IndexOpts) NewSearchIndex() (*atlasv2.ClusterSearchIndex, error) {
if len(opts.Filename) > 0 {
index := &atlasv2.SearchIndexCreateRequest{}
index := &atlasv2.ClusterSearchIndex{}
if err := file.Load(opts.Fs, opts.Filename, index); err != nil {
return nil, fmt.Errorf(failedToLoadIndexMessage, err.Error())
}
Expand All @@ -152,51 +139,17 @@ func (opts *IndexOpts) NewSearchIndex() (*atlasv2.SearchIndexCreateRequest, erro
opts.SearchAnalyzer = DefaultAnalyzer
}

i := &atlasv2.SearchIndexCreateRequest{
i := &atlasv2.ClusterSearchIndex{
CollectionName: opts.Collection,
Database: opts.DBName,
Name: opts.Name,
// only search indexes can be created using flags
Type: pointer.Get(SearchIndexType),
Definition: &atlasv2.BaseSearchIndexCreateRequestDefinition{
Analyzer: &opts.Analyzer,
SearchAnalyzer: &opts.SearchAnalyzer,
Mappings: &atlasv2.SearchMappings{
Dynamic: &opts.Dynamic,
Fields: f,
},
},
}
return i, nil
}

func (opts *IndexOpts) NewSearchIndexUpdate() (*atlasv2.SearchIndexUpdateRequest, error) {
if len(opts.Filename) > 0 {
index := &atlasv2.SearchIndexUpdateRequest{}
if err := file.Load(opts.Fs, opts.Filename, index); err != nil {
return nil, fmt.Errorf(failedToLoadIndexMessage, err.Error())
}

return index, nil
}

f, err := opts.indexFields()
if err != nil {
return nil, err
}

if opts.SearchAnalyzer == "" {
opts.SearchAnalyzer = DefaultAnalyzer
}

i := &atlasv2.SearchIndexUpdateRequest{
Definition: atlasv2.SearchIndexUpdateRequestDefinition{
Analyzer: &opts.Analyzer,
SearchAnalyzer: &opts.SearchAnalyzer,
Mappings: &atlasv2.SearchMappings{
Dynamic: &opts.Dynamic,
Fields: f,
},
Type: pointer.Get(SearchIndexType),
Analyzer: &opts.Analyzer,
SearchAnalyzer: &opts.SearchAnalyzer,
Mappings: &atlasv2.ApiAtlasFTSMappings{
Dynamic: &opts.Dynamic,
Fields: f,
},
}
return i, nil
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/search/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ func TestList_Run(t *testing.T) {
}

name := "test"
expected := []atlasv2.SearchIndexResponse{
expected := []atlasv2.ClusterSearchIndex{
{
Name: &name,
Name: name,
},
}

Expand Down
2 changes: 1 addition & 1 deletion internal/cli/search/nodes/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type DeleteOpts struct {
store store.SearchNodesDeleter
}

const atlasFtsDeploymentDoesNotExist = "ATLAS_FTS_DEPLOYMENT_DOES_NOT_EXIST"
const atlasFtsDeploymentDoesNotExist = "ATLAS_SEARCH_DEPLOYMENT_DOES_NOT_EXIST"

func (opts *DeleteOpts) initStore(ctx context.Context) func() error {
return func() error {
Expand Down
2 changes: 1 addition & 1 deletion internal/cli/search/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (opts *UpdateOpts) initStore(ctx context.Context) func() error {
var updateTemplate = "Index {{.Name}} updated.\n"

func (opts *UpdateOpts) Run() error {
index, err := opts.NewSearchIndexUpdate()
index, err := opts.NewSearchIndex()
if err != nil {
return err
}
Expand Down
8 changes: 4 additions & 4 deletions internal/cli/search/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ func TestUpdateOpts_Run(t *testing.T) {
updateOpts.Name = testName
updateOpts.id = "1"

expected := &atlasv2.SearchIndexResponse{}
expected := &atlasv2.ClusterSearchIndex{}

request, err := updateOpts.NewSearchIndexUpdate()
request, err := updateOpts.NewSearchIndex()
require.NoError(t, err)
mockStore.
EXPECT().
Expand All @@ -63,9 +63,9 @@ func TestUpdateOpts_Run(t *testing.T) {
updateOpts.Filename = fileName
updateOpts.Fs = appFS

expected := &atlasv2.SearchIndexResponse{}
expected := &atlasv2.ClusterSearchIndex{}

request, err := updateOpts.NewSearchIndexUpdate()
request, err := updateOpts.NewSearchIndex()
require.NoError(t, err)
mockStore.
EXPECT().
Expand Down
20 changes: 10 additions & 10 deletions internal/mocks/mock_search.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 4625f69

Please sign in to comment.