-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matt Spilchen
committed
Nov 22, 2023
1 parent
bda295c
commit 8802a09
Showing
18 changed files
with
386 additions
and
83 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
(c) Copyright [2023] Open Text. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package vclusterops | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/vertica/vcluster/vclusterops/vlog" | ||
) | ||
|
||
type NMAStageDCTablesOp struct { | ||
ScrutinizeOpBase | ||
} | ||
|
||
type stageDCTablesRequestData struct { | ||
CatalogPath string `json:"catalog_path"` | ||
} | ||
|
||
type stageDCTablesResponseData struct { | ||
Name string `json:"name"` | ||
} | ||
|
||
func makeNMAStageDCTablesOp(logger vlog.Printer, | ||
id string, | ||
hosts []string, | ||
hostNodeNameMap map[string]string, | ||
hostCatPathMap map[string]string) (NMAStageDCTablesOp, error) { | ||
// base members | ||
op := NMAStageDCTablesOp{} | ||
op.name = "NMAStageDCTablesOp" | ||
op.logger = logger.WithName(op.name) | ||
op.hosts = hosts | ||
|
||
// scrutinize members | ||
op.id = id | ||
op.batch = scrutinizeBatchNormal | ||
op.hostNodeNameMap = hostNodeNameMap | ||
op.hostCatPathMap = hostCatPathMap | ||
op.httpMethod = PostMethod | ||
op.urlSuffix = "/data_collector" | ||
|
||
// the caller is responsible for making sure hosts and maps match up exactly | ||
err := validateHostMaps(hosts, hostNodeNameMap, hostCatPathMap) | ||
return op, err | ||
} | ||
|
||
func (op *NMAStageDCTablesOp) setupRequestBody(hosts []string) error { | ||
op.hostRequestBodyMap = make(map[string]string, len(hosts)) | ||
for _, host := range hosts { | ||
stageDCTablesData := stageDCTablesRequestData{} | ||
stageDCTablesData.CatalogPath = op.hostCatPathMap[host] | ||
|
||
dataBytes, err := json.Marshal(stageDCTablesData) | ||
if err != nil { | ||
return fmt.Errorf("[%s] fail to marshal request data to JSON string, detail %w", op.name, err) | ||
} | ||
|
||
op.hostRequestBodyMap[host] = string(dataBytes) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (op *NMAStageDCTablesOp) prepare(execContext *OpEngineExecContext) error { | ||
err := op.setupRequestBody(op.hosts) | ||
if err != nil { | ||
return err | ||
} | ||
execContext.dispatcher.setup(op.hosts) | ||
|
||
return op.setupClusterHTTPRequest(op.hosts) | ||
} | ||
|
||
func (op *NMAStageDCTablesOp) execute(execContext *OpEngineExecContext) error { | ||
if err := op.runExecute(execContext); err != nil { | ||
return err | ||
} | ||
|
||
return op.processResult(execContext) | ||
} | ||
|
||
func (op *NMAStageDCTablesOp) finalize(_ *OpEngineExecContext) error { | ||
return nil | ||
} | ||
|
||
func (op *NMAStageDCTablesOp) processResult(_ *OpEngineExecContext) error { | ||
fileList := make([]stageDCTablesResponseData, 0) | ||
return processStagedFilesResult(&op.ScrutinizeOpBase, fileList) | ||
} |
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,44 @@ | ||
/* | ||
(c) Copyright [2023] Open Text. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package vclusterops | ||
|
||
import mapset "github.com/deckarep/golang-set/v2" | ||
|
||
// the following structs only hosts necessary information for this op | ||
type NodeInfo struct { | ||
Address string `json:"address"` | ||
// vnode name, e.g., v_dbname_node0001 | ||
Name string `json:"name"` | ||
State string `json:"state"` | ||
CatalogPath string `json:"catalog_path"` | ||
} | ||
|
||
type NodesInfo struct { | ||
NodeList []NodeInfo `json:"node_list"` | ||
} | ||
|
||
// findHosts looks for hosts in a list of NodesInfo. | ||
// If found, return true; if not found, return false. | ||
func (nodesInfo *NodesInfo) findHosts(hosts []string) bool { | ||
inputHostSet := mapset.NewSet(hosts...) | ||
|
||
nodeAddrSet := mapset.NewSet[string]() | ||
for _, n := range nodesInfo.NodeList { | ||
nodeAddrSet.Add(n.Address) | ||
} | ||
|
||
return nodeAddrSet.Intersect(inputHostSet).Cardinality() > 0 | ||
} |
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,53 @@ | ||
/* | ||
(c) Copyright [2023] Open Text. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
You may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package vclusterops | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestFindHosts(t *testing.T) { | ||
var nodesInfo NodesInfo | ||
|
||
for i := 1; i <= 3; i++ { | ||
var n NodeInfo | ||
n.Address = fmt.Sprintf("vnode%d", i) | ||
nodesInfo.NodeList = append(nodesInfo.NodeList, n) | ||
} | ||
|
||
// positive case: single input | ||
found := nodesInfo.findHosts([]string{"vnode3"}) | ||
assert.True(t, found) | ||
|
||
// positive case: input multiple hosts | ||
found = nodesInfo.findHosts([]string{"vnode3", "vnode4"}) | ||
assert.True(t, found) | ||
|
||
// negative case | ||
found = nodesInfo.findHosts([]string{"vnode4"}) | ||
assert.False(t, found) | ||
|
||
// negative case: input multiple hosts | ||
found = nodesInfo.findHosts([]string{"vnode4", "vnode5"}) | ||
assert.False(t, found) | ||
|
||
// negative case: empty input | ||
found = nodesInfo.findHosts([]string{}) | ||
assert.False(t, found) | ||
} |
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.