Skip to content

Commit 7a73ebe

Browse files
committed
Merge branch 'main' of https://github.com/apache/cloudstack into support-list-policies
2 parents b68b727 + ec533cd commit 7a73ebe

File tree

58 files changed

+2184
-308
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2184
-308
lines changed

api/src/main/java/com/cloud/event/EventTypes.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.apache.cloudstack.api.response.HostResponse;
2828
import org.apache.cloudstack.api.response.PodResponse;
2929
import org.apache.cloudstack.api.response.ZoneResponse;
30+
import org.apache.cloudstack.backup.BackupRepositoryService;
3031
import org.apache.cloudstack.config.Configuration;
3132
import org.apache.cloudstack.datacenter.DataCenterIpv4GuestSubnet;
3233
import org.apache.cloudstack.extension.Extension;
@@ -852,6 +853,10 @@ public class EventTypes {
852853
// Custom Action
853854
public static final String EVENT_CUSTOM_ACTION = "CUSTOM.ACTION";
854855

856+
// Backup Repository
857+
public static final String EVENT_BACKUP_REPOSITORY_ADD = "BACKUP.REPOSITORY.ADD";
858+
public static final String EVENT_BACKUP_REPOSITORY_UPDATE = "BACKUP.REPOSITORY.UPDATE";
859+
855860
static {
856861

857862
// TODO: need a way to force author adding event types to declare the entity details as well, with out braking
@@ -1385,6 +1390,10 @@ public class EventTypes {
13851390
entityEventDetails.put(EVENT_EXTENSION_CUSTOM_ACTION_ADD, ExtensionCustomAction.class);
13861391
entityEventDetails.put(EVENT_EXTENSION_CUSTOM_ACTION_UPDATE, ExtensionCustomAction.class);
13871392
entityEventDetails.put(EVENT_EXTENSION_CUSTOM_ACTION_DELETE, ExtensionCustomAction.class);
1393+
1394+
// Backup Repository
1395+
entityEventDetails.put(EVENT_BACKUP_REPOSITORY_ADD, BackupRepositoryService.class);
1396+
entityEventDetails.put(EVENT_BACKUP_REPOSITORY_UPDATE, BackupRepositoryService.class);
13881397
}
13891398

13901399
public static boolean isNetworkEvent(String eventType) {

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

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,31 @@ UserVm upgradeVirtualMachine(ScaleVMCmd cmd) throws ResourceUnavailableException
507507

508508
void collectVmNetworkStatistics (UserVm userVm);
509509

510-
UserVm importVM(final DataCenter zone, final Host host, final VirtualMachineTemplate template, final String instanceName, final String displayName, final Account owner, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
510+
/**
511+
* Import VM into CloudStack
512+
* @param zone importing zone
513+
* @param host importing host
514+
* @param template template for the imported VM
515+
* @param instanceNameInternal set to null to CloudStack to autogenerate from the next available VM ID on database
516+
* @param displayName display name for the imported VM
517+
* @param owner owner of the imported VM
518+
* @param userData user data for the imported VM
519+
* @param caller caller account
520+
* @param isDisplayVm true to display the imported VM
521+
* @param keyboard keyboard distribution for the imported VM
522+
* @param accountId account ID
523+
* @param userId user ID
524+
* @param serviceOffering service offering for the imported VM
525+
* @param sshPublicKey ssh key for the imported VM
526+
* @param hostName the name for the imported VM
527+
* @param hypervisorType hypervisor type for the imported VM
528+
* @param customParameters details for the imported VM
529+
* @param powerState power state of the imported VM
530+
* @param networkNicMap network to nic mapping
531+
* @return the imported VM
532+
* @throws InsufficientCapacityException in case of errors
533+
*/
534+
UserVm importVM(final DataCenter zone, final Host host, final VirtualMachineTemplate template, final String instanceNameInternal, final String displayName, final Account owner, final String userData, final Account caller, final Boolean isDisplayVm, final String keyboard,
511535
final long accountId, final long userId, final ServiceOffering serviceOffering, final String sshPublicKey,
512536
final String hostName, final HypervisorType hypervisorType, final Map<String, String> customParameters,
513537
final VirtualMachine.PowerState powerState, final LinkedHashMap<String, List<NicProfile>> networkNicMap) throws InsufficientCapacityException;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public static class Param {
7878
public static final Param BootIntoSetup = new Param("enterHardwareSetup");
7979
public static final Param PreserveNics = new Param("PreserveNics");
8080
public static final Param ConsiderLastHost = new Param("ConsiderLastHost");
81+
public static final Param ReturnAfterVolumePrepare = new Param("ReturnAfterVolumePrepare");
8182

8283
private String name;
8384

api/src/main/java/com/cloud/vm/snapshot/VMSnapshotService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import java.util.List;
2121

22+
import com.cloud.utils.fsm.NoTransitionException;
2223
import org.apache.cloudstack.api.command.user.vmsnapshot.ListVMSnapshotCmd;
2324

2425
import com.cloud.exception.ConcurrentOperationException;
@@ -53,4 +54,6 @@ UserVm revertToSnapshot(Long vmSnapshotId) throws InsufficientServerCapacityExce
5354
* @param id vm id
5455
*/
5556
boolean deleteVMSnapshotsFromDB(Long vmId, boolean unmanage);
57+
58+
void updateOperationFailed(VMSnapshot vmSnapshot) throws NoTransitionException;
5659
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ public class ApiConstants {
139139
public static final String CPU_SPEED = "cpuspeed";
140140
public static final String CPU_LOAD_AVERAGE = "cpuloadaverage";
141141
public static final String CREATED = "created";
142+
public static final String CROSS_ZONE_INSTANCE_CREATION = "crosszoneinstancecreation";
142143
public static final String CTX_ACCOUNT_ID = "ctxaccountid";
143144
public static final String CTX_DETAILS = "ctxDetails";
144145
public static final String CTX_USER_ID = "ctxuserid";

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ public class AddBackupRepositoryCmd extends BaseCmd {
6363
type = CommandType.UUID,
6464
entityType = ZoneResponse.class,
6565
required = true,
66-
description = "ID of the zone where the backup repository is to be added")
66+
description = "ID of the zone where the backup repository is to be added for taking backups")
6767
private Long zoneId;
6868

6969
@Parameter(name = ApiConstants.CAPACITY_BYTES, type = CommandType.LONG, description = "capacity of this backup repository")
7070
private Long capacityBytes;
7171

72+
@Parameter(name = ApiConstants.CROSS_ZONE_INSTANCE_CREATION, type = CommandType.BOOLEAN, description = "backups on this repository can be used to create Instances on all Zones", since = "4.22.0")
73+
private Boolean crossZoneInstanceCreation;
7274

7375
/////////////////////////////////////////////////////
7476
/////////////////// Accessors ///////////////////////
@@ -109,6 +111,10 @@ public Long getCapacityBytes() {
109111
return capacityBytes;
110112
}
111113

114+
public Boolean crossZoneInstanceCreationEnabled() {
115+
return crossZoneInstanceCreation;
116+
}
117+
112118
/////////////////////////////////////////////////////
113119
/////////////////// Accessors ///////////////////////
114120
/////////////////////////////////////////////////////
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
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+
18+
package org.apache.cloudstack.api.command.user.backup.repository;
19+
20+
import org.apache.cloudstack.acl.RoleType;
21+
import org.apache.cloudstack.api.APICommand;
22+
import org.apache.cloudstack.api.ApiConstants;
23+
import org.apache.cloudstack.api.ApiErrorCode;
24+
import org.apache.cloudstack.api.BaseCmd;
25+
import org.apache.cloudstack.api.Parameter;
26+
import org.apache.cloudstack.api.ServerApiException;
27+
import org.apache.cloudstack.api.response.BackupRepositoryResponse;
28+
import org.apache.cloudstack.backup.BackupRepository;
29+
import org.apache.cloudstack.backup.BackupRepositoryService;
30+
import org.apache.cloudstack.context.CallContext;
31+
32+
import javax.inject.Inject;
33+
34+
@APICommand(name = "updateBackupRepository",
35+
description = "Update a backup repository",
36+
responseObject = BackupRepositoryResponse.class, since = "4.22.0",
37+
authorized = {RoleType.Admin})
38+
public class UpdateBackupRepositoryCmd extends BaseCmd {
39+
40+
@Inject
41+
private BackupRepositoryService backupRepositoryService;
42+
43+
/////////////////////////////////////////////////////
44+
//////////////// API parameters /////////////////////
45+
/////////////////////////////////////////////////////
46+
47+
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, required = true, entityType = BackupRepositoryResponse.class, description = "ID of the backup repository")
48+
private Long id;
49+
50+
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, description = "name of the backup repository")
51+
private String name;
52+
53+
@Parameter(name = ApiConstants.ADDRESS, type = CommandType.STRING, description = "address of the backup repository")
54+
private String address;
55+
56+
@Parameter(name = ApiConstants.MOUNT_OPTIONS, type = CommandType.STRING, description = "shared storage mount options")
57+
private String mountOptions;
58+
59+
@Parameter(name = ApiConstants.CROSS_ZONE_INSTANCE_CREATION, type = CommandType.BOOLEAN, description = "backups in this repository can be used to create Instances on all Zones")
60+
private Boolean crossZoneInstanceCreation;
61+
62+
/////////////////////////////////////////////////////
63+
/////////////////// Accessors ///////////////////////
64+
/////////////////////////////////////////////////////
65+
66+
public BackupRepositoryService getBackupRepositoryService() {
67+
return backupRepositoryService;
68+
}
69+
70+
public Long getId() {
71+
return id;
72+
}
73+
74+
public String getName() {
75+
return name;
76+
}
77+
78+
public String getAddress() {
79+
return address;
80+
}
81+
82+
public String getMountOptions() {
83+
return mountOptions == null ? "" : mountOptions;
84+
}
85+
86+
public Boolean crossZoneInstanceCreationEnabled() {
87+
return crossZoneInstanceCreation;
88+
}
89+
90+
/////////////////////////////////////////////////////
91+
/////////////////////////////////////////////////////
92+
/////////////////// Accessors ///////////////////////
93+
/////////////////////////////////////////////////////
94+
95+
@Override
96+
public void execute() {
97+
try {
98+
BackupRepository result = backupRepositoryService.updateBackupRepository(this);
99+
if (result != null) {
100+
BackupRepositoryResponse response = _responseGenerator.createBackupRepositoryResponse(result);
101+
response.setResponseName(getCommandName());
102+
this.setResponseObject(response);
103+
} else {
104+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to update the backup repository");
105+
}
106+
} catch (Exception ex4) {
107+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, ex4.getMessage());
108+
}
109+
110+
}
111+
112+
@Override
113+
public long getEntityOwnerId() {
114+
return CallContext.current().getCallingAccount().getId();
115+
}
116+
}

api/src/main/java/org/apache/cloudstack/api/response/BackupRepositoryResponse.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public class BackupRepositoryResponse extends BaseResponse {
6161
@Param(description = "capacity of the backup repository")
6262
private Long capacityBytes;
6363

64+
@SerializedName(ApiConstants.CROSS_ZONE_INSTANCE_CREATION)
65+
@Param(description = "the backups in this repository can be used to create Instances on all Zones")
66+
private Boolean crossZoneInstanceCreation;
67+
6468
@SerializedName("created")
6569
@Param(description = "the date and time the backup repository was added")
6670
private Date created;
@@ -132,6 +136,14 @@ public void setCapacityBytes(Long capacityBytes) {
132136
this.capacityBytes = capacityBytes;
133137
}
134138

139+
public Boolean getCrossZoneInstanceCreation() {
140+
return crossZoneInstanceCreation;
141+
}
142+
143+
public void setCrossZoneInstanceCreation(Boolean crossZoneInstanceCreation) {
144+
this.crossZoneInstanceCreation = crossZoneInstanceCreation;
145+
}
146+
135147
public Date getCreated() {
136148
return created;
137149
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
206206

207207
Boolean canCreateInstanceFromBackup(Long backupId);
208208

209+
Boolean canCreateInstanceFromBackupAcrossZones(Long backupId);
210+
209211
/**
210212
* Restore a backup to a new Instance
211213
*/

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
public interface BackupProvider {
2525

26+
Boolean crossZoneInstanceCreationEnabled(BackupOffering backupOffering);
27+
2628
/**
2729
* Returns the unique name of the provider
2830
* @return returns provider name
@@ -85,7 +87,7 @@ public interface BackupProvider {
8587
*/
8688
boolean deleteBackup(Backup backup, boolean forced);
8789

88-
boolean restoreBackupToVM(VirtualMachine vm, Backup backup, String hostIp, String dataStoreUuid);
90+
Pair<Boolean, String> restoreBackupToVM(VirtualMachine vm, Backup backup, String hostIp, String dataStoreUuid);
8991

9092
/**
9193
* Restore VM from backup

0 commit comments

Comments
 (0)