forked from banzaicloud/go-cruise-control
-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add disk removal endpoint #1
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
/* | ||
Copyright © 2021 Cisco and/or its affiliates. All rights reserved. | ||
|
||
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 integration_test | ||
|
||
import ( | ||
"github.com/banzaicloud/go-cruise-control/integration_test/helpers" | ||
"github.com/banzaicloud/go-cruise-control/pkg/api" | ||
"github.com/banzaicloud/go-cruise-control/pkg/types" | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
var _ = Describe("Remove Disks", | ||
Label("api:remove_disks", "api:user_tasks", "api:kafka_cluster_load", "api:state"), | ||
Serial, | ||
func() { | ||
const ( | ||
brokerID = 0 | ||
logDir = "/var/lib/kafka/data0" | ||
pollIntervalSeconds = 15 | ||
cruiseControlRemoveDiskTimeoutSeconds = 600 | ||
) | ||
|
||
BeforeEach(func(ctx SpecContext) { | ||
By("waiting until Cruise Control is ready") | ||
Eventually(ctx, func() bool { | ||
ready, err := helpers.IsCruiseControlReady(ctx, cruisecontrol) | ||
Expect(err).NotTo(HaveOccurred()) | ||
return ready | ||
}, CruiseControlReadyTimeout, pollIntervalSeconds).Should(BeTrue()) | ||
}) | ||
|
||
Describe("Removing a disk in Kafka cluster", func() { | ||
It("should return no error", func(ctx SpecContext) { | ||
By("sending a remove request to Cruise Control") | ||
req := &api.RemoveDisksRequest{} | ||
|
||
req.BrokerIDAndLogDirs = map[int32][]string{ | ||
brokerID: {logDir}, | ||
} | ||
req.Reason = "integration testing" | ||
|
||
resp, err := cruisecontrol.RemoveDisks(ctx, req) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(resp.Failed()).To(BeFalse()) | ||
|
||
By("waiting until the remove task finished") | ||
Eventually(ctx, func() bool { | ||
finished, err := helpers.HasUserTaskFinished(ctx, cruisecontrol, resp.TaskID) | ||
Expect(err).NotTo(HaveOccurred()) | ||
return finished | ||
}, cruiseControlRemoveDiskTimeoutSeconds, pollIntervalSeconds).Should(BeTrue()) | ||
|
||
By("checking that the disk has been drained") | ||
req2 := api.KafkaClusterLoadRequestWithDefaults() | ||
req2.PopulateDiskInfo = true | ||
req2.Reason = "integration testing" | ||
|
||
resp2, err := cruisecontrol.KafkaClusterLoad(ctx, req2) | ||
Expect(err).NotTo(HaveOccurred()) | ||
Expect(resp2.Failed()).To(BeFalse()) | ||
|
||
Expect(resp2.Result.Brokers).ToNot(BeEmpty()) | ||
|
||
var affectedBroker types.BrokerLoadStats | ||
for _, broker := range resp2.Result.Brokers { | ||
if broker.Broker == brokerID { | ||
affectedBroker = broker | ||
break | ||
} | ||
} | ||
|
||
Expect(affectedBroker).ToNot(BeNil()) | ||
|
||
var affectedDiskState types.DiskStats | ||
for logDir, state := range affectedBroker.DiskState { | ||
if logDir == logDir { | ||
affectedDiskState = state | ||
break | ||
} | ||
} | ||
|
||
Expect(affectedDiskState).ToNot(BeNil()) | ||
|
||
replicas := affectedDiskState.NumReplicas | ||
log.V(0).Info("partition replicas on broker disk", "broker_id", brokerID, "logDir", logDir, "replicas", replicas) | ||
Expect(replicas).To(BeNumerically("==", 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,88 @@ | ||
/* | ||
Copyright © 2021 Cisco and/or its affiliates. All rights reserved. | ||
|
||
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 api | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/banzaicloud/go-cruise-control/pkg/types" | ||
) | ||
|
||
const ( | ||
EndpointRemoveDisks types.APIEndpoint = "REMOVE_DISKS" | ||
) | ||
|
||
type RemoveDisksRequest struct { | ||
types.GenericRequestWithReason | ||
|
||
// Map of broker id to list of disks to remove. | ||
BrokerIDAndLogDirs map[int32][]string `param:"brokerid_and_logdirs"` | ||
// Whether to dry-run the request or not. | ||
DryRun bool `param:"dryrun"` | ||
} | ||
|
||
type RemoveDisksResponse struct { | ||
types.GenericResponse | ||
|
||
Result *types.OptimizationResult | ||
} | ||
|
||
func (s RemoveDisksRequest) Validate() error { | ||
if len(s.BrokerIDAndLogDirs) == 0 { | ||
return errors.New("broker id and log dirs map must not be empty") | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *RemoveDisksResponse) UnmarshalResponse(resp *http.Response) error { | ||
if err := r.GenericResponse.UnmarshalResponse(resp); err != nil { | ||
return fmt.Errorf("failed to parse HTTP response metadata: %w", err) | ||
} | ||
|
||
var bodyBytes []byte | ||
var err error | ||
|
||
bodyBytes, err = io.ReadAll(resp.Body) | ||
if err != nil { | ||
return fmt.Errorf("failed to read HTTP response body: %w", err) | ||
} | ||
|
||
var d interface{} | ||
switch resp.StatusCode { | ||
case http.StatusOK: | ||
r.Result = &types.OptimizationResult{} | ||
d = r.Result | ||
case http.StatusAccepted: | ||
r.Progress = &types.ProgressResult{} | ||
d = r.Progress | ||
default: | ||
r.Error = &types.APIError{} | ||
d = r.Error | ||
} | ||
|
||
if err = json.Unmarshal(bodyBytes, d); err != nil { | ||
return fmt.Errorf("failed to parse JSON response: %w", err) | ||
} | ||
|
||
return nil | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be Adobe