diff --git a/dsms-engine-application/src/main/java/com/dsms/modules/storagepool/service/impl/StoragePoolImpl.java b/dsms-engine-application/src/main/java/com/dsms/modules/storagepool/service/impl/StoragePoolImpl.java index e44efc13a986d54e9938c53620cc8178f0f0cd1a..fe81699c58c7235c6a1e65e4acf9dc546161d400 100644 --- a/dsms-engine-application/src/main/java/com/dsms/modules/storagepool/service/impl/StoragePoolImpl.java +++ b/dsms-engine-application/src/main/java/com/dsms/modules/storagepool/service/impl/StoragePoolImpl.java @@ -100,7 +100,7 @@ public class StoragePoolImpl implements IStoragePoolService { //get the infomation of file system List fsLsResponse; try { - fsLsResponse = fileSystemApi.getFsStatus(RemoteCallUtil.generateRemoteRequest()); + fsLsResponse = fileSystemApi.getFsLs(RemoteCallUtil.generateRemoteRequest()); } catch (DsmsEngineException e) { log.error("get filesystem info from dsms-storage fail,fail message:{}", e.getMessage(), e); throw new DsmsEngineException(e, ResultCode.POOL_GETFILESYSTEM_ERROR); diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/CommandDirector.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/CommandDirector.java index 5be224dd0e49078ad0817874478643fc9a59349d..e79647393d7b7923021d99f336bc7a1a8e219871 100644 --- a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/CommandDirector.java +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/common/CommandDirector.java @@ -19,7 +19,8 @@ package com.dsms.dfsbroker.common; import com.dsms.common.remotecall.model.RemoteRequest; import com.dsms.dfsbroker.cluster.request.ServerRequest; import com.dsms.dfsbroker.common.request.GetResultRequest; -import com.dsms.dfsbroker.filesystem.request.FsLsRequest; +import com.dsms.dfsbroker.filesystem.model.dto.FileSystemDTO; +import com.dsms.dfsbroker.filesystem.request.*; import com.dsms.dfsbroker.node.request.*; import com.dsms.dfsbroker.osd.crushmap.request.CreateBucketRequest; import com.dsms.dfsbroker.osd.crushmap.request.CreateRuleRequest; @@ -101,4 +102,20 @@ public class CommandDirector { public static void constructGetOSDById(RemoteRequest request, int id) { request.buildRequestParam(new GetOsdByIdRequest(id)); } + + public static void constructFsStatusRequest(RemoteRequest request) { + request.buildRequestParam(new FsStatusRequest()); + } + + public static void constructCreateFsRequest(RemoteRequest request, FileSystemDTO fileSystem) { + request.buildRequestParam(new CreateFsRequest(fileSystem)); + } + + public static void constructRemoveFsRequest(RemoteRequest request, FileSystemDTO fileSystem) { + request.buildRequestParam(new RemoveFsRequest(fileSystem)); + } + + public static void constructFailFsRequest(RemoteRequest request, FileSystemDTO fileSystem) { + request.buildRequestParam(new FailFsRequest(fileSystem)); + } } diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/api/FileSystemApi.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/api/FileSystemApi.java index 25206bfed9cd48f9be51cc0194154c83a22c4dfd..831d5e296c664e9264ca287fa38c53172658375a 100644 --- a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/api/FileSystemApi.java +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/api/FileSystemApi.java @@ -17,9 +17,12 @@ package com.dsms.dfsbroker.filesystem.api; import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.common.remotecall.model.RemoteResponse; import com.dsms.dfsbroker.common.CommandDirector; import com.dsms.dfsbroker.common.api.CommonApi; +import com.dsms.dfsbroker.filesystem.model.dto.FileSystemDTO; import com.dsms.dfsbroker.filesystem.model.remote.FsLsResponse; +import com.dsms.dfsbroker.filesystem.model.remote.FsStatusResponse; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -41,9 +44,43 @@ public class FileSystemApi { * * @return FsResponse */ - public List getFsStatus(RemoteRequest remoteRequest) throws Throwable { + public List getFsLs(RemoteRequest remoteRequest) throws Throwable { CommandDirector.constructFsLsRequest(remoteRequest); FsLsResponse[] fsLsResponses = commonApi.remoteCallRequest(remoteRequest, MAX_RETRIES, FsLsResponse[].class); return Arrays.stream(fsLsResponses).collect(Collectors.toList()); } + + /** + * obtain the file system status + * + * @return FsStatusResponse + */ + public FsStatusResponse getFsStatus(RemoteRequest remoteRequest) throws Throwable { + CommandDirector.constructFsStatusRequest(remoteRequest); + return commonApi.remoteCallRequest(remoteRequest, MAX_RETRIES, FsStatusResponse.class); + } + + /** + * make new filesystem using named pools metadata and data + */ + public RemoteResponse createFs(RemoteRequest remoteRequest, FileSystemDTO fileSystem) throws Throwable { + CommandDirector.constructCreateFsRequest(remoteRequest, fileSystem); + return commonApi.remoteCall(remoteRequest, MAX_RETRIES, RemoteResponse.class); + } + + /** + * remove the named filesystem + */ + public RemoteResponse removeFs(RemoteRequest remoteRequest, FileSystemDTO fileSystem) throws Throwable { + CommandDirector.constructRemoveFsRequest(remoteRequest, fileSystem); + return commonApi.remoteCall(remoteRequest, MAX_RETRIES, RemoteResponse.class); + } + + /** + * fail the named filesystem + */ + public RemoteResponse failFs(RemoteRequest remoteRequest, FileSystemDTO fileSystem) throws Throwable { + CommandDirector.constructFailFsRequest(remoteRequest, fileSystem); + return commonApi.remoteCall(remoteRequest, MAX_RETRIES, RemoteResponse.class); + } } diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/model/dto/FileSystemDTO.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/model/dto/FileSystemDTO.java new file mode 100644 index 0000000000000000000000000000000000000000..25024e1bcc2fdf6597463f67a78442662e06e1cc --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/model/dto/FileSystemDTO.java @@ -0,0 +1,28 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * 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 com.dsms.dfsbroker.filesystem.model.dto; + + +import lombok.Data; + +@Data +public class FileSystemDTO { + + private String fsName; + private String metadata; + private String data; +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/model/remote/FsStatusResponse.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/model/remote/FsStatusResponse.java new file mode 100644 index 0000000000000000000000000000000000000000..2f8b58064b7038d56a0461de832c6934e8eae000 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/model/remote/FsStatusResponse.java @@ -0,0 +1,80 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * 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 com.dsms.dfsbroker.filesystem.model.remote; + +import com.alibaba.fastjson2.annotation.JSONField; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * dsms-storage (fs status -f json) execute result + */ +@NoArgsConstructor +@Data +public class FsStatusResponse { + @JSONField(name = "clients") + private List clients; + @JSONField(name = "mds_version") + private String mdsVersion; + @JSONField(name = "mdsmap") + private List mdsmap; + @JSONField(name = "pools") + private List pools; + + @NoArgsConstructor + @Data + public static class ClientsDTO { + @JSONField(name = "clients") + private Integer clients; + @JSONField(name = "fs") + private String fs; + } + + @NoArgsConstructor + @Data + public static class MdsmapDTO { + @JSONField(name = "dns") + private Integer dns; + @JSONField(name = "inos") + private Integer inos; + @JSONField(name = "name") + private String name; + @JSONField(name = "rank") + private Integer rank; + @JSONField(name = "rate") + private Integer rate; + @JSONField(name = "state") + private String state; + } + + @NoArgsConstructor + @Data + public static class PoolsDTO { + @JSONField(name = "avail") + private Long avail; + @JSONField(name = "id") + private Integer id; + @JSONField(name = "name") + private String name; + @JSONField(name = "type") + private String type; + @JSONField(name = "used") + private Integer used; + } +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/CreateFsRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/CreateFsRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..5776cb059622feea8e8bb381cc7cde461a6a757f --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/CreateFsRequest.java @@ -0,0 +1,41 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * 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 com.dsms.dfsbroker.filesystem.request; + +import com.alibaba.fastjson2.JSON; +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import com.dsms.dfsbroker.filesystem.model.dto.FileSystemDTO; +import org.springframework.http.HttpMethod; + +import java.util.HashMap; +import java.util.Map; + +public class CreateFsRequest extends RemoteRequest { + public CreateFsRequest(FileSystemDTO fileSystem) { + + Map requestParam = new HashMap<>(4); + requestParam.put("prefix", "fs new"); + requestParam.put("fs_name", fileSystem.getFsName()); + requestParam.put("metadata", fileSystem.getMetadata()); + requestParam.put("data", fileSystem.getData()); + + this.setUrlPrefix(RequestUrlEnum.REQUEST_URL.getUrlPrefix()); + this.setHttpMethod(HttpMethod.POST); + this.setRequestBody(JSON.toJSONString(requestParam)); + } +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/FailFsRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/FailFsRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..8e655da5f735a98693c3a95653849fd63a751652 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/FailFsRequest.java @@ -0,0 +1,38 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * 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 com.dsms.dfsbroker.filesystem.request; + +import com.alibaba.fastjson2.JSON; +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import com.dsms.dfsbroker.filesystem.model.dto.FileSystemDTO; +import org.springframework.http.HttpMethod; + +import java.util.HashMap; +import java.util.Map; + +public class FailFsRequest extends RemoteRequest { + public FailFsRequest(FileSystemDTO fileSystem) { + Map requestParam = new HashMap<>(4); + requestParam.put("prefix", "fs fail"); + requestParam.put("fs_name", fileSystem.getFsName()); + + this.setUrlPrefix(RequestUrlEnum.REQUEST_URL.getUrlPrefix()); + this.setHttpMethod(HttpMethod.POST); + this.setRequestBody(JSON.toJSONString(requestParam)); + } +} diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/FsStatusRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/FsStatusRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..6e075d3490b648bd2fee25c67478fb12acdcb3d5 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/FsStatusRequest.java @@ -0,0 +1,37 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * 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 com.dsms.dfsbroker.filesystem.request; + +import com.alibaba.fastjson2.JSON; +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import org.springframework.http.HttpMethod; + +import java.util.HashMap; +import java.util.Map; + +public class FsStatusRequest extends RemoteRequest { + + public FsStatusRequest() { + Map requestParam = new HashMap<>(4); + requestParam.put("prefix", "fs status"); + requestParam.put("format", "json"); + this.setUrlPrefix(RequestUrlEnum.REQUEST_URL.getUrlPrefix()); + this.setHttpMethod(HttpMethod.POST); + this.setRequestBody(JSON.toJSONString(requestParam)); + } +} \ No newline at end of file diff --git a/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/RemoveFsRequest.java b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/RemoveFsRequest.java new file mode 100644 index 0000000000000000000000000000000000000000..83d39bcc6f4a498a68cfd070b21968fa647ae3a8 --- /dev/null +++ b/dsms-engine-dfsbroker/src/main/java/com/dsms/dfsbroker/filesystem/request/RemoveFsRequest.java @@ -0,0 +1,39 @@ +/* + * Copyright 2022 The DSMS Authors. + * + * 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 com.dsms.dfsbroker.filesystem.request; + +import com.alibaba.fastjson2.JSON; +import com.dsms.common.remotecall.model.RemoteRequest; +import com.dsms.dfsbroker.common.RequestUrlEnum; +import com.dsms.dfsbroker.filesystem.model.dto.FileSystemDTO; +import org.springframework.http.HttpMethod; + +import java.util.HashMap; +import java.util.Map; + +public class RemoveFsRequest extends RemoteRequest { + public RemoveFsRequest(FileSystemDTO fileSystem) { + Map requestParam = new HashMap<>(4); + requestParam.put("prefix", "fs rm"); + requestParam.put("fs_name", fileSystem.getFsName()); + requestParam.put("yes_i_really_mean_it", true); + + this.setUrlPrefix(RequestUrlEnum.REQUEST_URL.getUrlPrefix()); + this.setHttpMethod(HttpMethod.POST); + this.setRequestBody(JSON.toJSONString(requestParam)); + } +}