-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] Add get_cluster_snapshot_restore_state rest api (#55667)
Signed-off-by: xiangguangyxg <[email protected]>
- Loading branch information
1 parent
94726ee
commit 72a602c
Showing
3 changed files
with
91 additions
and
0 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
44 changes: 44 additions & 0 deletions
44
fe/fe-core/src/main/java/com/starrocks/http/rest/GetClusterSnapshotRestoreStateAction.java
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 @@ | ||
// Copyright 2021-present StarRocks, Inc. 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 | ||
// | ||
// https://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 com.starrocks.http.rest; | ||
|
||
import com.starrocks.http.ActionController; | ||
import com.starrocks.http.BaseRequest; | ||
import com.starrocks.http.BaseResponse; | ||
import com.starrocks.http.IllegalArgException; | ||
import com.starrocks.lake.snapshot.RestoreClusterSnapshotMgr; | ||
import io.netty.handler.codec.http.HttpMethod; | ||
|
||
public class GetClusterSnapshotRestoreStateAction extends RestBaseAction { | ||
public GetClusterSnapshotRestoreStateAction(ActionController controller) { | ||
super(controller); | ||
} | ||
|
||
public static void registerAction(ActionController controller) | ||
throws IllegalArgException { | ||
controller.registerHandler(HttpMethod.GET, "/api/v2/get_cluster_snapshot_restore_state", | ||
new GetClusterSnapshotRestoreStateAction(controller)); | ||
} | ||
|
||
@Override | ||
public void execute(BaseRequest request, BaseResponse response) { | ||
response.setContentType("application/json"); | ||
|
||
RestResult result = new RestResult(); | ||
result.addResultEntry("cluster_snapshot_restore_state", | ||
RestoreClusterSnapshotMgr.isRestoring() ? "restoring" : "finished"); | ||
sendResult(request, response, result); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
fe/fe-core/src/test/java/com/starrocks/http/GetClusterSnapshotRestoreStateActionTest.java
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,45 @@ | ||
// Copyright 2021-present StarRocks, Inc. 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 | ||
// | ||
// https://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 com.starrocks.http; | ||
|
||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
public class GetClusterSnapshotRestoreStateActionTest extends StarRocksHttpTestCase { | ||
|
||
private String sendHttp() throws IOException { | ||
Request request = new Request.Builder() | ||
.get() | ||
.url("http://localhost:" + HTTP_PORT + "/api/v2/get_cluster_snapshot_restore_state") | ||
.build(); | ||
Response response = networkClient.newCall(request).execute(); | ||
assertTrue(response.isSuccessful()); | ||
String respStr = response.body().string(); | ||
Assert.assertNotNull(respStr); | ||
return respStr; | ||
} | ||
|
||
@Test | ||
public void testGetFeatures() throws IOException { | ||
String resp = sendHttp(); | ||
Assert.assertTrue(resp.contains("finished")); | ||
} | ||
} |