Skip to content

Commit 1123adf

Browse files
committed
Addressed last set of review comments
1 parent 912639b commit 1123adf

File tree

18 files changed

+105
-82
lines changed

18 files changed

+105
-82
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ public class BackupResponse extends BaseResponse {
3636
private String id;
3737

3838
@SerializedName(ApiConstants.NAME)
39-
@Param(description = "name of the backup")
39+
@Param(description = "name of the backup", since = "4.21.0")
4040
private String name;
4141

4242
@SerializedName(ApiConstants.DESCRIPTION)
43-
@Param(description = "description for the backup")
43+
@Param(description = "description for the backup", since = "4.21.0")
4444
private String description;
4545

4646
@SerializedName(ApiConstants.VIRTUAL_MACHINE_ID)
@@ -116,11 +116,11 @@ public class BackupResponse extends BaseResponse {
116116
private Map<String, String> vmDetails;
117117

118118
@SerializedName(ApiConstants.INTERVAL_TYPE)
119-
@Param(description = "the interval type of the backup schedule")
119+
@Param(description = "the interval type of the backup schedule", since = "4.21.0")
120120
private String intervalType;
121121

122122
@SerializedName(ApiConstants.IS_ORPHAN)
123-
@Param(description = "The backups is orphaned and no associated with an existing VM. A new VM can still be created using the backup")
123+
@Param(description = "The backups is orphaned and not associated with an existing VM. A new VM can still be created using the backup", since = "4.21.0")
124124
private Boolean isOrphan;
125125

126126
public String getId() {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ public class ObjectStoreResponse extends BaseResponseWithAnnotations {
3838
@Param(description = "the url of the object store")
3939
private String url;
4040

41-
@SerializedName(ApiConstants.PROVIDER)
42-
@Param(description = "the name of the object store provider")
41+
@SerializedName("providername")
42+
@Param(description = "the provider name of the object store")
4343
private String providerName;
4444

45-
@SerializedName(ApiConstants.SIZE)
45+
@SerializedName("storagetotal")
4646
@Param(description = "the total size of the object store")
4747
private Long storageTotal;
4848

49-
@SerializedName(ApiConstants.ALLOCATED)
49+
@SerializedName("storageallocated")
5050
@Param(description = "the object store currently allocated size")
5151
private Long storageAllocated;
5252

53-
@SerializedName(ApiConstants.USED)
53+
@SerializedName("storageused")
5454
@Param(description = "the object store currently used size")
5555
private Long storageUsed;
5656

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,14 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
144144
ConfigKey.Scope.Global,
145145
null);
146146

147+
ConfigKey<Float> BackupStorageCapacityThreshold = new ConfigKey<>("Alert", Float.class,
148+
"zone.backupStorage.capacity.notificationthreshold",
149+
"0.75",
150+
"Percentage (as a value between 0 and 1) of backup storage utilization above which alerts will be sent about low storage available.",
151+
true,
152+
ConfigKey.Scope.Zone,
153+
null);
154+
147155
/**
148156
* List backup provider offerings
149157
* @param zoneId zone id
@@ -254,6 +262,8 @@ public interface BackupManager extends BackupService, Configurable, PluggableSer
254262

255263
Map<String, String> getDiskOfferingDetailsForBackup(Long vmId);
256264

265+
String getBackupNameFromVM(VirtualMachine vm);
266+
257267
void updateOrphanedBackups(VirtualMachine vm);
258268

259269
Capacity getBackupStorageUsedStats(Long zoneId);

engine/components-api/src/main/java/com/cloud/storage/StorageManager.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,14 @@ public interface StorageManager extends StorageService {
220220
"storage.pool.host.connect.workers", "1",
221221
"Number of worker threads to be used to connect hosts to a primary storage", true);
222222

223+
ConfigKey<Float> ObjectStorageCapacityThreshold = new ConfigKey<>("Alert", Float.class,
224+
"zone.objectStorage.capacity.notificationthreshold",
225+
"0.75",
226+
"Percentage (as a value between 0 and 1) of object storage utilization above which alerts will be sent about low storage available.",
227+
true,
228+
ConfigKey.Scope.Global,
229+
null);
230+
223231
/**
224232
* should we execute in sequence not involving any storages?
225233
* @return tru if commands should execute in sequence

engine/schema/src/main/resources/META-INF/db/schema-42010to42100.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.host', 'last_mgmt_server_id', 'bigin
3838
ALTER TABLE `cloud`.`backup_schedule` ADD COLUMN `max_backups` int(8) default NULL COMMENT 'maximum number of backups to maintain';
3939

4040
-- Add columns name, description and backup_interval_type to backup table
41-
ALTER TABLE `cloud`.`backups` ADD COLUMN `backup_interval_type` int(5) COMMENT 'type of backup, e.g. manual, recurring - hourly, daily, weekly or monthly';
42-
ALTER TABLE `cloud`.`backups` ADD COLUMN `name` varchar(255) NOT NULL COMMENT 'name of the backup';
43-
ALTER TABLE `cloud`.`backups` ADD COLUMN `vm_name` varchar(255) COMMENT 'name of the vm for which backup is taken, only set for orphaned backups';
44-
ALTER TABLE `cloud`.`backups` ADD COLUMN `description` varchar(1024) COMMENT 'description for the backup';
41+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backups', 'name', 'VARCHAR(255) NOT NULL COMMENT "name of the backup"');
42+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backups', 'description', 'VARCHAR(1024) COMMENT "description for the backup"');
43+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backups', 'backup_interval_type', 'int(5) COMMENT "type of backup, e.g. manual, recurring - hourly, daily, weekly or monthly"');
44+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.backups', 'vm_name', 'VARCHAR(255) COMMENT "name of the vm for which backup is taken, set only for orphaned backups"');
4545
UPDATE `cloud`.`backups` JOIN `cloud`.`vm_instance` ON `backups`.`vm_id` = `vm_instance`.`id` SET `backups`.`name` = `vm_instance`.`name`;
4646

4747
-- Make the column vm_id in backups table nullable to handle orphan backups
@@ -59,7 +59,7 @@ CREATE TABLE `cloud`.`backup_details` (
5959
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
6060

6161
-- Add column allocated_size to object_store table. Rename column 'used_bytes' to 'used_size'
62-
ALTER TABLE `cloud`.`object_store` ADD COLUMN `allocated_size` bigint unsigned COMMENT 'allocated size in bytes';
62+
CALL `cloud`.`IDEMPOTENT_ADD_COLUMN`('cloud.object_store', 'allocated_size', 'bigint unsigned COMMENT "allocated size in bytes"');
6363
ALTER TABLE `cloud`.`object_store` CHANGE COLUMN `used_bytes` `used_size` BIGINT UNSIGNED COMMENT 'used size in bytes';
6464
ALTER TABLE `cloud`.`object_store` MODIFY COLUMN `total_size` bigint unsigned COMMENT 'total size in bytes';
6565
UPDATE `cloud`.`object_store`

plugins/backup/dummy/src/main/java/org/apache/cloudstack/backup/DummyBackupProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.backup;
1818

19-
import java.text.SimpleDateFormat;
2019
import java.util.Arrays;
2120
import java.util.Date;
2221
import java.util.HashMap;
@@ -157,7 +156,7 @@ public Pair<Boolean, Backup> takeBackup(VirtualMachine vm) {
157156
backup.setAccountId(vm.getAccountId());
158157
backup.setDomainId(vm.getDomainId());
159158
backup.setZoneId(vm.getDataCenterId());
160-
backup.setName(vm.getHostName() + '-' + new SimpleDateFormat("yyyy-MM-dd'T'HH:mmX").format(new Date()));
159+
backup.setName(backupManager.getBackupNameFromVM(vm));
161160
backup.setBackedUpVolumes(BackupManagerImpl.createVolumeInfoFromVolumes(volumeDao.findByInstance(vm.getId())));
162161
Map<String, String> details = backupManager.getVmDetailsForBackup(vm);
163162
backup.setDetails(details);

plugins/backup/nas/src/main/java/org/apache/cloudstack/backup/NASBackupProvider.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.cloud.host.Status;
2525
import com.cloud.host.dao.HostDao;
2626
import com.cloud.hypervisor.Hypervisor;
27+
import com.cloud.resource.ResourceManager;
2728
import com.cloud.storage.ScopeType;
2829
import com.cloud.storage.StoragePoolHostVO;
2930
import com.cloud.storage.Volume;
@@ -94,16 +95,16 @@ public class NASBackupProvider extends AdapterBase implements BackupProvider, Co
9495
@Inject
9596
BackupManager backupManager;
9697

98+
@Inject
99+
ResourceManager resourceManager;
100+
97101
private Host getUpHostInZone(Long zoneId) {
98102
List<HostVO> hosts = hostDao.listByDataCenterIdAndHypervisorType(zoneId, Hypervisor.HypervisorType.KVM);
99-
if (hosts.size() == 0) {
103+
if (CollectionUtils.isNotEmpty(hosts)) {
100104
return null;
101105
}
102-
103-
Random random = new Random();
104-
int randomIndex = random.nextInt(hosts.size());
105-
HostVO hostInZone = hosts.get(randomIndex);
106-
LOG.debug("Found Host {} in zone {}", zoneId);
106+
HostVO hostInZone = hosts.get(new Random().nextInt(hosts.size()));
107+
LOG.debug("Found Host {} in zone {}", hostInZone, zoneId);
107108
return hostInZone;
108109
}
109110

@@ -127,7 +128,7 @@ protected Host getLastVMHypervisorHost(VirtualMachine vm) {
127128
}
128129
}
129130
// Try to find any Host in the zone
130-
return getUpHostInZone(host.getDataCenterId());
131+
return resourceManager.findOneRandomRunningHostByHypervisor(Hypervisor.HypervisorType.KVM, host.getDataCenterId());
131132
}
132133

133134
protected Host getVMHypervisorHost(VirtualMachine vm) {
@@ -219,7 +220,7 @@ private BackupVO createBackupObject(VirtualMachine vm, String backupPath) {
219220
backup.setAccountId(vm.getAccountId());
220221
backup.setDomainId(vm.getDomainId());
221222
backup.setZoneId(vm.getDataCenterId());
222-
backup.setName(vm.getHostName() + '-' + new SimpleDateFormat("yyyy-MM-dd'T'HH:mmX").format(new Date()));
223+
backup.setName(backupManager.getBackupNameFromVM(vm));
223224
Map<String, String> details = backupManager.getVmDetailsForBackup(vm);
224225
backup.setDetails(details);
225226

@@ -375,7 +376,7 @@ public boolean deleteBackup(Backup backup, boolean forced) {
375376
if (vm != null) {
376377
host = getLastVMHypervisorHost(vm);
377378
} else {
378-
host = getUpHostInZone(backup.getZoneId());
379+
host = resourceManager.findOneRandomRunningHostByHypervisor(Hypervisor.HypervisorType.KVM, backup.getZoneId());
379380
}
380381

381382
DeleteBackupCommand command = new DeleteBackupCommand(backup.getExternalId(), backupRepository.getType(),
@@ -473,7 +474,7 @@ public Pair<Long, Long> getBackupStorageStats(Long zoneId) {
473474
@Override
474475
public void syncBackupStorageStats(Long zoneId) {
475476
final List<BackupRepository> repositories = backupRepositoryDao.listByZoneAndProvider(zoneId, getName());
476-
final Host host = getUpHostInZone(zoneId);
477+
final Host host = resourceManager.findOneRandomRunningHostByHypervisor(Hypervisor.HypervisorType.KVM, zoneId);
477478
for (final BackupRepository repository : repositories) {
478479
GetBackupStorageStatsCommand command = new GetBackupStorageStatsCommand(repository.getType(), repository.getAddress(), repository.getMountOptions());
479480
BackupStorageStatsAnswer answer;

plugins/backup/nas/src/test/java/org/apache/cloudstack/backup/NASBackupProviderTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.cloud.host.Status;
4646
import com.cloud.host.dao.HostDao;
4747
import com.cloud.hypervisor.Hypervisor;
48+
import com.cloud.resource.ResourceManager;
4849
import com.cloud.storage.Volume;
4950
import com.cloud.storage.VolumeVO;
5051
import com.cloud.storage.dao.VolumeDao;
@@ -83,6 +84,9 @@ public class NASBackupProviderTest {
8384
@Mock
8485
private BackupManager backupManager;
8586

87+
@Mock
88+
private ResourceManager resourceManager;
89+
8690
@Test
8791
public void testDeleteBackup() throws OperationTimedoutException, AgentUnavailableException {
8892
Long hostId = 1L;
@@ -135,7 +139,7 @@ public void testSyncBackupStorageStats() throws AgentUnavailableException, Opera
135139
"nfs", "address", "sync", 1024L);
136140

137141
HostVO host = mock(HostVO.class);
138-
Mockito.when(hostDao.listByDataCenterIdAndHypervisorType(1L, Hypervisor.HypervisorType.KVM)).thenReturn(Collections.singletonList(host));
142+
Mockito.when(resourceManager.findOneRandomRunningHostByHypervisor(Hypervisor.HypervisorType.KVM, 1L)).thenReturn(host);
139143

140144
Mockito.when(backupRepositoryDao.listByZoneAndProvider(1L, "nas")).thenReturn(Collections.singletonList(backupRepository));
141145
GetBackupStorageStatsCommand command = new GetBackupStorageStatsCommand("nfs", "address", "sync");
@@ -198,7 +202,6 @@ public void takeBackupSuccessfully() throws AgentUnavailableException, Operation
198202
Mockito.when(vm.getAccountId()).thenReturn(accountId);
199203
Mockito.when(vm.getDomainId()).thenReturn(domainId);
200204
Mockito.when(vm.getDataCenterId()).thenReturn(zoneId);
201-
Mockito.when(vm.getHostName()).thenReturn("test-host");
202205
Mockito.when(vm.getState()).thenReturn(VMInstanceVO.State.Running);
203206

204207
BackupRepository backupRepository = mock(BackupRepository.class);

plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/NetworkerBackupProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ public Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoi
611611
backup.setAccountId(vm.getAccountId());
612612
backup.setDomainId(vm.getDomainId());
613613
backup.setZoneId(vm.getDataCenterId());
614-
backup.setName(vm.getHostName() + '-' + new SimpleDateFormat("yyyy-MM-dd'T'HH:mmX").format(new Date()));
614+
backup.setName(backupManager.getBackupNameFromVM(vm));
615615

616616
HashMap<String, String> details = new HashMap<>();
617617
details.put(ApiConstants.HYPERVISOR, vm.getHypervisorType().toString());

plugins/backup/networker/src/main/java/org/apache/cloudstack/backup/networker/NetworkerClient.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.fasterxml.jackson.databind.ObjectMapper;
2525
import org.apache.cloudstack.api.ApiErrorCode;
2626
import org.apache.cloudstack.api.ServerApiException;
27+
import org.apache.cloudstack.backup.BackupManager;
2728
import org.apache.cloudstack.backup.BackupOffering;
2829
import org.apache.cloudstack.backup.BackupVO;
2930
import org.apache.cloudstack.backup.networker.api.NetworkerBackup;
@@ -45,6 +46,7 @@
4546
import org.apache.logging.log4j.Logger;
4647
import org.apache.logging.log4j.LogManager;
4748

49+
import javax.inject.Inject;
4850
import javax.net.ssl.SSLContext;
4951
import javax.net.ssl.X509TrustManager;
5052
import java.io.IOException;
@@ -65,6 +67,9 @@
6567
import static org.apache.cloudstack.backup.NetworkerBackupProvider.BACKUP_IDENTIFIER;
6668

6769
public class NetworkerClient {
70+
@Inject
71+
BackupManager backupManager;
72+
6873
private static final Logger LOG = LogManager.getLogger(NetworkerClient.class);
6974
private final URI apiURI;
7075
private final String apiName;
@@ -267,7 +272,7 @@ public BackupVO registerBackupForVm(VirtualMachine vm, Date backupJobStart, Stri
267272
backup.setAccountId(vm.getAccountId());
268273
backup.setDomainId(vm.getDomainId());
269274
backup.setZoneId(vm.getDataCenterId());
270-
backup.setName(vm.getHostName() + '-' + new SimpleDateFormat("yyyy-MM-dd'T'HH:mmX").format(new Date()));
275+
backup.setName(backupManager.getBackupNameFromVM(vm));
271276

272277
return backup;
273278
} catch (final IOException e) {

0 commit comments

Comments
 (0)