|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | +package org.apache.cloudstack.storage.feign.client; |
| 20 | + |
| 21 | +import feign.Headers; |
| 22 | +import feign.Param; |
| 23 | +import feign.QueryMap; |
| 24 | +import feign.RequestLine; |
| 25 | +import org.apache.cloudstack.storage.feign.model.FlexVolSnapshot; |
| 26 | +import org.apache.cloudstack.storage.feign.model.SnapshotFileRestoreRequest; |
| 27 | +import org.apache.cloudstack.storage.feign.model.response.JobResponse; |
| 28 | +import org.apache.cloudstack.storage.feign.model.response.OntapResponse; |
| 29 | + |
| 30 | +import java.util.Map; |
| 31 | + |
| 32 | +/** |
| 33 | + * Feign client for ONTAP FlexVolume snapshot operations. |
| 34 | + * |
| 35 | + * <p>Maps to the ONTAP REST API endpoint: |
| 36 | + * {@code /api/storage/volumes/{volume_uuid}/snapshots}</p> |
| 37 | + * |
| 38 | + * <p>FlexVolume snapshots are point-in-time, space-efficient copies of an entire |
| 39 | + * FlexVolume. Unlike file-level clones, a single FlexVolume snapshot atomically |
| 40 | + * captures <b>all</b> files/LUNs within the volume, making it ideal for VM-level |
| 41 | + * snapshots when multiple CloudStack disks reside on the same FlexVolume.</p> |
| 42 | + */ |
| 43 | +public interface SnapshotFeignClient { |
| 44 | + |
| 45 | + /** |
| 46 | + * Creates a new snapshot for the specified FlexVolume. |
| 47 | + * |
| 48 | + * <p>ONTAP REST: {@code POST /api/storage/volumes/{volume_uuid}/snapshots}</p> |
| 49 | + * |
| 50 | + * @param authHeader Basic auth header |
| 51 | + * @param volumeUuid UUID of the ONTAP FlexVolume |
| 52 | + * @param snapshot Snapshot request body (at minimum, the {@code name} field) |
| 53 | + * @return JobResponse containing the async job reference |
| 54 | + */ |
| 55 | + @RequestLine("POST /api/storage/volumes/{volumeUuid}/snapshots") |
| 56 | + @Headers({"Authorization: {authHeader}", "Content-Type: application/json"}) |
| 57 | + JobResponse createSnapshot(@Param("authHeader") String authHeader, |
| 58 | + @Param("volumeUuid") String volumeUuid, |
| 59 | + FlexVolSnapshot snapshot); |
| 60 | + |
| 61 | + /** |
| 62 | + * Lists snapshots for the specified FlexVolume. |
| 63 | + * |
| 64 | + * <p>ONTAP REST: {@code GET /api/storage/volumes/{volume_uuid}/snapshots}</p> |
| 65 | + * |
| 66 | + * @param authHeader Basic auth header |
| 67 | + * @param volumeUuid UUID of the ONTAP FlexVolume |
| 68 | + * @param queryParams Optional query parameters (e.g., {@code name}, {@code fields}) |
| 69 | + * @return Paginated response of FlexVolSnapshot records |
| 70 | + */ |
| 71 | + @RequestLine("GET /api/storage/volumes/{volumeUuid}/snapshots") |
| 72 | + @Headers({"Authorization: {authHeader}"}) |
| 73 | + OntapResponse<FlexVolSnapshot> getSnapshots(@Param("authHeader") String authHeader, |
| 74 | + @Param("volumeUuid") String volumeUuid, |
| 75 | + @QueryMap Map<String, Object> queryParams); |
| 76 | + |
| 77 | + /** |
| 78 | + * Retrieves a specific snapshot by UUID. |
| 79 | + * |
| 80 | + * <p>ONTAP REST: {@code GET /api/storage/volumes/{volume_uuid}/snapshots/{uuid}}</p> |
| 81 | + * |
| 82 | + * @param authHeader Basic auth header |
| 83 | + * @param volumeUuid UUID of the ONTAP FlexVolume |
| 84 | + * @param snapshotUuid UUID of the snapshot |
| 85 | + * @return The FlexVolSnapshot object |
| 86 | + */ |
| 87 | + @RequestLine("GET /api/storage/volumes/{volumeUuid}/snapshots/{snapshotUuid}") |
| 88 | + @Headers({"Authorization: {authHeader}"}) |
| 89 | + FlexVolSnapshot getSnapshotByUuid(@Param("authHeader") String authHeader, |
| 90 | + @Param("volumeUuid") String volumeUuid, |
| 91 | + @Param("snapshotUuid") String snapshotUuid); |
| 92 | + |
| 93 | + /** |
| 94 | + * Deletes a specific snapshot. |
| 95 | + * |
| 96 | + * <p>ONTAP REST: {@code DELETE /api/storage/volumes/{volume_uuid}/snapshots/{uuid}}</p> |
| 97 | + * |
| 98 | + * @param authHeader Basic auth header |
| 99 | + * @param volumeUuid UUID of the ONTAP FlexVolume |
| 100 | + * @param snapshotUuid UUID of the snapshot to delete |
| 101 | + * @return JobResponse containing the async job reference |
| 102 | + */ |
| 103 | + @RequestLine("DELETE /api/storage/volumes/{volumeUuid}/snapshots/{snapshotUuid}") |
| 104 | + @Headers({"Authorization: {authHeader}"}) |
| 105 | + JobResponse deleteSnapshot(@Param("authHeader") String authHeader, |
| 106 | + @Param("volumeUuid") String volumeUuid, |
| 107 | + @Param("snapshotUuid") String snapshotUuid); |
| 108 | + |
| 109 | + /** |
| 110 | + * Restores a volume to a specific snapshot. |
| 111 | + * |
| 112 | + * <p>ONTAP REST: {@code PATCH /api/storage/volumes/{volume_uuid}/snapshots/{uuid}} |
| 113 | + * with body {@code {"restore": true}} triggers a snapshot restore operation.</p> |
| 114 | + * |
| 115 | + * <p><b>Note:</b> This is a destructive operation — all data written after the |
| 116 | + * snapshot was taken will be lost.</p> |
| 117 | + * |
| 118 | + * @param authHeader Basic auth header |
| 119 | + * @param volumeUuid UUID of the ONTAP FlexVolume |
| 120 | + * @param snapshotUuid UUID of the snapshot to restore to |
| 121 | + * @param body Request body, typically {@code {"restore": true}} |
| 122 | + * @return JobResponse containing the async job reference |
| 123 | + */ |
| 124 | + @RequestLine("PATCH /api/storage/volumes/{volumeUuid}/snapshots/{snapshotUuid}?restore_to_snapshot=true") |
| 125 | + @Headers({"Authorization: {authHeader}", "Content-Type: application/json"}) |
| 126 | + JobResponse restoreSnapshot(@Param("authHeader") String authHeader, |
| 127 | + @Param("volumeUuid") String volumeUuid, |
| 128 | + @Param("snapshotUuid") String snapshotUuid); |
| 129 | + |
| 130 | + /** |
| 131 | + * Restores a single file or LUN from a FlexVolume snapshot. |
| 132 | + * |
| 133 | + * <p>ONTAP REST: |
| 134 | + * {@code POST /api/storage/volumes/{volume_uuid}/snapshots/{snapshot_uuid}/files/{file_path}/restore}</p> |
| 135 | + * |
| 136 | + * <p>This restores only the specified file/LUN from the snapshot to the |
| 137 | + * given {@code destination_path}, without reverting the entire FlexVolume. |
| 138 | + * Ideal when multiple VMs share the same FlexVolume.</p> |
| 139 | + * |
| 140 | + * @param authHeader Basic auth header |
| 141 | + * @param volumeUuid UUID of the ONTAP FlexVolume |
| 142 | + * @param snapshotUuid UUID of the snapshot containing the file |
| 143 | + * @param filePath path of the file within the snapshot (URL-encoded if needed) |
| 144 | + * @param request request body with {@code destination_path} |
| 145 | + * @return JobResponse containing the async job reference |
| 146 | + */ |
| 147 | + @RequestLine("POST /api/storage/volumes/{volumeUuid}/snapshots/{snapshotUuid}/files/{filePath}/restore") |
| 148 | + @Headers({"Authorization: {authHeader}", "Content-Type: application/json"}) |
| 149 | + JobResponse restoreFileFromSnapshot(@Param("authHeader") String authHeader, |
| 150 | + @Param("volumeUuid") String volumeUuid, |
| 151 | + @Param("snapshotUuid") String snapshotUuid, |
| 152 | + @Param("filePath") String filePath, |
| 153 | + SnapshotFileRestoreRequest request); |
| 154 | +} |
0 commit comments