Skip to content

Commit 0d38d85

Browse files
committed
add finishBackupChain command
1 parent aad4701 commit 0d38d85

27 files changed

Lines changed: 702 additions & 90 deletions

File tree

api/src/main/java/com/cloud/vm/VirtualMachine.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ public enum Event {
234234
BackupRequested,
235235
BackupSucceededStopped,
236236
BackupSucceededRunning,
237+
FinalizedBackupChain,
237238

238239
// added for new VMSync logic
239240
FollowAgentPowerOnReport,

api/src/main/java/org/apache/cloudstack/api/ApiConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,6 +1415,7 @@ public class ApiConstants {
14151415

14161416
public static final String SCHEDULED = "scheduled";
14171417
public static final String SCHEDULED_DATE = "scheduleddate";
1418+
public static final String LAST_KNOWN_STATE = "last_known_state";
14181419

14191420
/**
14201421
* This enum specifies IO Drivers, each option controls specific policies on I/O.

api/src/main/java/org/apache/cloudstack/api/command/user/backup/DownloadValidationScreenshotCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import javax.inject.Inject;
3838

3939
@APICommand(name = "downloadValidationScreenshot", description = "Download validation screenshot of given backup.",
40-
responseObject = ExtractResponse.class, since = "4.20.0.10-scclouds", requestHasSensitiveInfo = false,
40+
responseObject = ExtractResponse.class, since = "4.23.0.0", requestHasSensitiveInfo = false,
4141
responseHasSensitiveInfo = false)
4242
public class DownloadValidationScreenshotCmd extends BaseAsyncCmd {
4343

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package org.apache.cloudstack.api.command.user.backup;
18+
19+
import com.cloud.exception.ConcurrentOperationException;
20+
import com.cloud.exception.InsufficientCapacityException;
21+
import com.cloud.exception.NetworkRuleConflictException;
22+
import com.cloud.exception.ResourceAllocationException;
23+
import com.cloud.exception.ResourceUnavailableException;
24+
import com.cloud.user.Account;
25+
import com.cloud.vm.VirtualMachine;
26+
import org.apache.cloudstack.api.ACL;
27+
import org.apache.cloudstack.api.APICommand;
28+
import org.apache.cloudstack.api.ApiConstants;
29+
import org.apache.cloudstack.api.BaseCmd;
30+
import org.apache.cloudstack.api.Parameter;
31+
import org.apache.cloudstack.api.ServerApiException;
32+
import org.apache.cloudstack.api.response.SuccessResponse;
33+
import org.apache.cloudstack.api.response.VirtualMachineResponse;
34+
import org.apache.cloudstack.backup.NativeBackupService;
35+
36+
import javax.inject.Inject;
37+
38+
@APICommand(name = "finishBackupChain", description = "Finish backup chain of VM.",
39+
responseObject = SuccessResponse.class, since = "4.23.0.0", requestHasSensitiveInfo = false,
40+
responseHasSensitiveInfo = false)
41+
public class FinishBackupChainCmd extends BaseCmd {
42+
@Inject
43+
private NativeBackupService nativeBackupService;
44+
45+
/////////////////////////////////////////////////////
46+
//////////////// API parameters /////////////////////
47+
/////////////////////////////////////////////////////
48+
49+
@ACL
50+
@Parameter(name = ApiConstants.VIRTUAL_MACHINE_ID, type = CommandType.UUID, entityType = VirtualMachineResponse.class, required = true,
51+
description = "Id of the VM to finish the chain.")
52+
private Long vmId;
53+
54+
/////////////////////////////////////////////////////
55+
/////////////////// Accessors ///////////////////////
56+
/////////////////////////////////////////////////////
57+
58+
public Long getVmId() {
59+
return vmId;
60+
}
61+
62+
/////////////////////////////////////////////////////
63+
/////////////// API Implementation///////////////////
64+
/////////////////////////////////////////////////////
65+
66+
@Override
67+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException,
68+
NetworkRuleConflictException {
69+
boolean result = nativeBackupService.finishBackupChain(getVmId());
70+
SuccessResponse response = new SuccessResponse();
71+
response.setSuccess(result);
72+
response.setResponseName(getCommandName());
73+
response.setObjectName(getCommandName());
74+
this.setResponseObject(response);
75+
}
76+
77+
@Override
78+
public long getEntityOwnerId() {
79+
VirtualMachine vm = _entityMgr.findById(VirtualMachine.class, getVmId());
80+
if (vm != null) {
81+
return vm.getAccountId();
82+
}
83+
84+
return Account.ACCOUNT_ID_SYSTEM;
85+
}
86+
}

api/src/main/java/org/apache/cloudstack/backup/NativeBackupProvider.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,8 @@ default Set<String> getSecondaryStorageUrls(UserVm userVm) {
134134
* */
135135
default void prepareVmForSnapshotRevert(VMSnapshot vmSnapshot, VirtualMachine virtualMachine) {
136136
}
137+
138+
default boolean finishBackupChain(VirtualMachine virtualMachine) {
139+
return false;
140+
}
137141
}

api/src/main/java/org/apache/cloudstack/backup/NativeBackupService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ public interface NativeBackupService {
4949
boolean validateBackup(long backupId, long hostId, long zoneId);
5050

5151
ExtractResponse downloadScreenshot(long backupId);
52+
53+
boolean finishBackupChain(long vmId);
5254
}

core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotAnswer.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,20 +20,19 @@
2020

2121
import com.cloud.agent.api.Answer;
2222
import com.cloud.agent.api.Command;
23-
import com.cloud.utils.Pair;
2423

2524
import java.util.Map;
2625

2726
public class CreateDiskOnlyVmSnapshotAnswer extends Answer {
2827

29-
protected Map<String, Pair<Long, String>> mapVolumeToSnapshotSizeAndNewVolumePath;
28+
protected Map<String, Long> mapVolumeToSnapshotSize;
3029

31-
public CreateDiskOnlyVmSnapshotAnswer(Command command, boolean success, String details, Map<String, Pair<Long, String>> mapVolumeToSnapshotSizeAndNewVolumePath) {
30+
public CreateDiskOnlyVmSnapshotAnswer(Command command, boolean success, String details, Map<String, Long> mapVolumeToSnapshotSize) {
3231
super(command, success, details);
33-
this.mapVolumeToSnapshotSizeAndNewVolumePath = mapVolumeToSnapshotSizeAndNewVolumePath;
32+
this.mapVolumeToSnapshotSize = mapVolumeToSnapshotSize;
3433
}
3534

36-
public Map<String, Pair<Long, String>> getMapVolumeToSnapshotSizeAndNewVolumePath() {
37-
return mapVolumeToSnapshotSizeAndNewVolumePath;
35+
public Map<String, Long> getMapVolumeToSnapshotSize() {
36+
return mapVolumeToSnapshotSize;
3837
}
3938
}

core/src/main/java/com/cloud/agent/api/storage/CreateDiskOnlyVmSnapshotCommand.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
import com.cloud.agent.api.VMSnapshotBaseCommand;
2323
import com.cloud.agent.api.VMSnapshotTO;
24+
import com.cloud.utils.Pair;
2425
import com.cloud.vm.VirtualMachine;
2526
import org.apache.cloudstack.storage.to.VolumeObjectTO;
2627

@@ -30,12 +31,19 @@ public class CreateDiskOnlyVmSnapshotCommand extends VMSnapshotBaseCommand {
3031

3132
protected VirtualMachine.State vmState;
3233

33-
public CreateDiskOnlyVmSnapshotCommand(String vmName, VMSnapshotTO snapshot, List<VolumeObjectTO> volumeTOs, String guestOSType, VirtualMachine.State vmState) {
34-
super(vmName, snapshot, volumeTOs, guestOSType);
34+
List<Pair<VolumeObjectTO, String>> volumeTosAndNewPaths;
35+
36+
public CreateDiskOnlyVmSnapshotCommand(String vmName, VMSnapshotTO snapshot, List<Pair<VolumeObjectTO, String>> volumeTosAndNewPaths, String guestOSType, VirtualMachine.State vmState) {
37+
super(vmName, snapshot, null, guestOSType);
3538
this.vmState = vmState;
39+
this.volumeTosAndNewPaths = volumeTosAndNewPaths;
3640
}
3741

3842
public VirtualMachine.State getVmState() {
3943
return vmState;
4044
}
45+
46+
public List<Pair<VolumeObjectTO, String>> getVolumeTosAndNewPaths() {
47+
return volumeTosAndNewPaths;
48+
}
4149
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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.backup;
20+
21+
import com.cloud.agent.api.Answer;
22+
import com.cloud.agent.api.Command;
23+
import org.apache.cloudstack.storage.to.VolumeObjectTO;
24+
import org.apache.commons.collections4.CollectionUtils;
25+
26+
import java.util.List;
27+
28+
public class CleanupKnibBackupErrorAnswer extends Answer {
29+
List<VolumeObjectTO> volumeObjectTos;
30+
31+
public CleanupKnibBackupErrorAnswer(Command cmd, List<VolumeObjectTO> volumeObjectTos) {
32+
super(cmd, CollectionUtils.isNotEmpty(volumeObjectTos), null);
33+
this.volumeObjectTos = volumeObjectTos;
34+
}
35+
36+
public List<VolumeObjectTO> getVolumeObjectTos() {
37+
return volumeObjectTos;
38+
}
39+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package org.apache.cloudstack.backup;
2+
3+
import com.cloud.agent.api.Command;
4+
import org.apache.cloudstack.storage.to.KnibTO;
5+
6+
import java.util.List;
7+
8+
public class CleanupKnibBackupErrorCommand extends Command {
9+
10+
private boolean runningVM;
11+
12+
private String vmName;
13+
14+
private String imageStoreUrl;
15+
16+
private List<KnibTO> knibTOs;
17+
18+
public CleanupKnibBackupErrorCommand(boolean runningVM, String vmName, String imageStoreUrl, List<KnibTO> knibTOs) {
19+
this.runningVM = runningVM;
20+
this.vmName = vmName;
21+
this.imageStoreUrl = imageStoreUrl;
22+
this.knibTOs = knibTOs;
23+
}
24+
25+
public boolean isRunningVM() {
26+
return runningVM;
27+
}
28+
29+
public String getVmName() {
30+
return vmName;
31+
}
32+
33+
public String getImageStoreUrl() {
34+
return imageStoreUrl;
35+
}
36+
37+
public List<KnibTO> getKnibTOs() {
38+
return knibTOs;
39+
}
40+
41+
@Override
42+
public boolean executeInSequence() {
43+
return false;
44+
}
45+
}

0 commit comments

Comments
 (0)