Skip to content

Commit

Permalink
[Enhancement] Add get_cluster_snapshot_restore_state rest api (#55667)
Browse files Browse the repository at this point in the history
Signed-off-by: xiangguangyxg <[email protected]>
  • Loading branch information
xiangguangyxg authored Feb 7, 2025
1 parent 94726ee commit 72a602c
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fe/fe-core/src/main/java/com/starrocks/http/HttpServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import com.starrocks.http.rest.ConnectionAction;
import com.starrocks.http.rest.ExecuteSqlAction;
import com.starrocks.http.rest.FeatureAction;
import com.starrocks.http.rest.GetClusterSnapshotRestoreStateAction;
import com.starrocks.http.rest.GetDdlStmtAction;
import com.starrocks.http.rest.GetLoadInfoAction;
import com.starrocks.http.rest.GetLogFileAction;
Expand Down Expand Up @@ -176,6 +177,7 @@ private void registerActions() throws IllegalArgException {
// rest action
HealthAction.registerAction(controller);
FeatureAction.registerAction(controller);
GetClusterSnapshotRestoreStateAction.registerAction(controller);
MetricsAction.registerAction(controller);
ShowMetaInfoAction.registerAction(controller);
ShowProcAction.registerAction(controller);
Expand Down
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);
}
}
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"));
}
}

0 comments on commit 72a602c

Please sign in to comment.