Skip to content

Commit f50dbd0

Browse files
committed
some cleanups while waiting for compile
1 parent aeb0710 commit f50dbd0

File tree

4 files changed

+32
-43
lines changed

4 files changed

+32
-43
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public interface BackupProvider {
5050
/**
5151
* Assign a VM to a backup offering or policy
5252
* @param vm
53-
* @param backup
54-
* @param policy
53+
* @param backupOffering
5554
* @return
5655
*/
5756
boolean assignVMToBackupOffering(VirtualMachine vm, BackupOffering backupOffering);
@@ -72,14 +71,14 @@ public interface BackupProvider {
7271
/**
7372
* Starts and creates an adhoc backup process
7473
* for a previously registered VM backup
75-
* @param backup
74+
* @param vm
7675
* @return
7776
*/
7877
Pair<Boolean, Backup> takeBackup(VirtualMachine vm);
7978

8079
/**
8180
* Delete an existing backup
82-
* @param backuo The backup to exclude
81+
* @param backup The backup to exclude
8382
* @param forced Indicates if backup will be force removed or not
8483
* @return
8584
*/

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoi
112112

113113
@Override
114114
public boolean removeVMFromBackupOffering(VirtualMachine vm) {
115-
logger.debug(String.format("Removing VM %s from backup offering by the Dummy Backup Provider", vm));
115+
logger.debug("Removing VM {} from backup offering by the Dummy Backup Provider", vm);
116116
return true;
117117
}
118118

@@ -123,15 +123,15 @@ public boolean willDeleteBackupsOnOfferingRemoval() {
123123

124124
@Override
125125
public Pair<Boolean, Backup> takeBackup(VirtualMachine vm) {
126-
logger.debug(String.format("Starting backup for VM %s on Dummy provider", vm));
126+
logger.debug("Starting backup for VM {} on Dummy provider", vm);
127127

128128
BackupVO backup = new BackupVO();
129129
backup.setVmId(vm.getId());
130130
backup.setExternalId("dummy-external-id");
131131
backup.setType("FULL");
132132
backup.setDate(new Date());
133133
backup.setSize(1024000L);
134-
backup.setProtectedSize(1 * Resource.ResourceType.bytesToGiB);
134+
backup.setProtectedSize(Resource.ResourceType.bytesToGiB);
135135
backup.setStatus(Backup.Status.BackedUp);
136136
backup.setBackupOfferingId(vm.getBackupOfferingId());
137137
backup.setAccountId(vm.getAccountId());

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

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
package org.apache.cloudstack.backup;
1818

1919
import com.cloud.agent.AgentManager;
20-
import com.cloud.dc.dao.ClusterDao;
2120
import com.cloud.exception.AgentUnavailableException;
2221
import com.cloud.exception.OperationTimedoutException;
2322
import com.cloud.host.Host;
@@ -38,7 +37,6 @@
3837
import com.cloud.vm.dao.VMInstanceDao;
3938

4039
import org.apache.cloudstack.backup.dao.BackupDao;
41-
import org.apache.cloudstack.backup.dao.BackupOfferingDao;
4240
import org.apache.cloudstack.backup.dao.BackupRepositoryDao;
4341
import org.apache.cloudstack.framework.config.ConfigKey;
4442
import org.apache.cloudstack.framework.config.Configurable;
@@ -71,15 +69,9 @@ public class NASBackupProvider extends AdapterBase implements BackupProvider, Co
7169
@Inject
7270
private BackupRepositoryDao backupRepositoryDao;
7371

74-
@Inject
75-
private BackupOfferingDao backupOfferingDao;
76-
7772
@Inject
7873
private HostDao hostDao;
7974

80-
@Inject
81-
private ClusterDao clusterDao;
82-
8375
@Inject
8476
private VolumeDao volumeDao;
8577

@@ -167,7 +159,7 @@ public Pair<Boolean, Backup> takeBackup(final VirtualMachine vm) {
167159
command.setVolumePaths(volumePaths);
168160
}
169161

170-
BackupAnswer answer = null;
162+
BackupAnswer answer;
171163
try {
172164
answer = (BackupAnswer) agentManager.send(host.getId(), command);
173165
} catch (AgentUnavailableException e) {
@@ -205,7 +197,7 @@ private BackupVO createBackupObject(VirtualMachine vm, String backupPath) {
205197
virtualSize += volume.getSize();
206198
}
207199
}
208-
backup.setProtectedSize(Long.valueOf(virtualSize));
200+
backup.setProtectedSize(virtualSize);
209201
backup.setStatus(Backup.Status.BackingUp);
210202
backup.setBackupOfferingId(vm.getBackupOfferingId());
211203
backup.setAccountId(vm.getAccountId());
@@ -232,7 +224,7 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
232224
restoreCommand.setVmExists(vm.getRemoved() == null);
233225
restoreCommand.setVmState(vm.getState());
234226

235-
BackupAnswer answer = null;
227+
BackupAnswer answer;
236228
try {
237229
answer = (BackupAnswer) agentManager.send(host.getId(), restoreCommand);
238230
} catch (AgentUnavailableException e) {
@@ -299,7 +291,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
299291
restoreCommand.setVmState(vmNameAndState.second());
300292
restoreCommand.setRestoreVolumeUUID(volumeUuid);
301293

302-
BackupAnswer answer = null;
294+
BackupAnswer answer;
303295
try {
304296
answer = (BackupAnswer) agentManager.send(hostVO.getId(), restoreCommand);
305297
} catch (AgentUnavailableException e) {
@@ -351,7 +343,7 @@ public boolean deleteBackup(Backup backup, boolean forced) {
351343
DeleteBackupCommand command = new DeleteBackupCommand(backup.getExternalId(), backupRepository.getType(),
352344
backupRepository.getAddress(), backupRepository.getMountOptions());
353345

354-
BackupAnswer answer = null;
346+
BackupAnswer answer;
355347
try {
356348
answer = (BackupAnswer) agentManager.send(host.getId(), command);
357349
} catch (AgentUnavailableException e) {
@@ -364,7 +356,7 @@ public boolean deleteBackup(Backup backup, boolean forced) {
364356
return backupDao.remove(backup.getId());
365357
}
366358

367-
logger.debug("There was an error removing the backup with id " + backup.getId());
359+
logger.debug("There was an error removing the backup with id {}", backup.getId());
368360
return false;
369361
}
370362

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

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ protected HostVO getLastVMHypervisorHost(VirtualMachine vm) {
176176
List<HostVO> altClusterHosts = hostDao.findHypervisorHostInCluster(host.getClusterId());
177177
for (final HostVO candidateClusterHost : altClusterHosts) {
178178
if ( candidateClusterHost.getStatus() == Status.Up ) {
179-
LOG.debug(String.format("Found Host %s", candidateClusterHost));
179+
LOG.debug("Found Host {}", candidateClusterHost);
180180
return candidateClusterHost;
181181
}
182182
}
@@ -185,7 +185,7 @@ protected HostVO getLastVMHypervisorHost(VirtualMachine vm) {
185185
List<HostVO> altZoneHosts = hostDao.findByDataCenterId(host.getDataCenterId());
186186
for (final HostVO candidateZoneHost : altZoneHosts) {
187187
if ( candidateZoneHost.getStatus() == Status.Up && candidateZoneHost.getHypervisorType() == Hypervisor.HypervisorType.KVM ) {
188-
LOG.debug("Found Host " + candidateZoneHost);
188+
LOG.debug("Found Host {}", candidateZoneHost);
189189
return candidateZoneHost;
190190
}
191191
}
@@ -236,13 +236,13 @@ private String executeBackupCommand(HostVO host, String username, String passwor
236236
Pair<Boolean, String> response = SshHelper.sshExecute(host.getPrivateIpAddress(), 22,
237237
username, null, password, command, 120000, 120000, 3600000);
238238
if (!response.first()) {
239-
LOG.error(String.format("Backup Script failed on HYPERVISOR %s due to: %s", host, response.second()));
239+
LOG.error("Backup Script failed on HYPERVISOR {} due to: {}", host, response.second());
240240
} else {
241-
LOG.debug(String.format("Networker Backup Results: %s", response.second()));
241+
LOG.debug("Networker Backup Results: {}", response.second());
242242
}
243243
Matcher saveTimeMatcher = saveTimePattern.matcher(response.second());
244244
if (saveTimeMatcher.find()) {
245-
LOG.debug(String.format("Got saveTimeMatcher: %s", saveTimeMatcher.group(1)));
245+
LOG.debug("Got saveTimeMatcher: {}", saveTimeMatcher.group(1));
246246
return saveTimeMatcher.group(1);
247247
}
248248
} catch (final Exception e) {
@@ -258,9 +258,9 @@ private boolean executeRestoreCommand(HostVO host, String username, String passw
258258
username, null, password, command, 120000, 120000, 3600000);
259259

260260
if (!response.first()) {
261-
LOG.error(String.format("Restore Script failed on HYPERVISOR %s due to: %s", host, response.second()));
261+
LOG.error("Restore Script failed on HYPERVISOR {} due to: {}", host, response.second());
262262
} else {
263-
LOG.debug(String.format("Networker Restore Results: %s",response.second()));
263+
LOG.debug("Networker Restore Results: {}",response.second());
264264
return true;
265265
}
266266
} catch (final Exception e) {
@@ -317,7 +317,7 @@ public boolean removeVMFromBackupOffering(VirtualMachine vm) {
317317
List<String> backupsTaken = getClient(vm.getDataCenterId()).getBackupsForVm(vm);
318318

319319
for (String backupId : backupsTaken) {
320-
LOG.debug("Trying to remove backup with id" + backupId);
320+
LOG.debug("Trying to remove backup with id {}", backupId);
321321
getClient(vm.getDataCenterId()).deleteBackupForVM(backupId);
322322
}
323323

@@ -334,18 +334,18 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
334334
final NetworkerBackup networkerBackup=getClient(zoneId).getNetworkerBackupInfo(externalBackupId);
335335
final String SSID = networkerBackup.getShortId();
336336

337-
LOG.debug(String.format("Restoring vm %s from backup %s on the Networker Backup Provider", vm, backup));
337+
LOG.debug("Restoring vm {} from backup {} on the Networker Backup Provider", vm, backup);
338338

339339
if ( SSID.isEmpty() ) {
340-
LOG.debug("There was an error retrieving the SSID for backup with id " + externalBackupId + " from EMC NEtworker");
340+
LOG.debug("There was an error retrieving the SSID for backup with id {} from EMC NEtworker", externalBackupId);
341341
return false;
342342
}
343343

344344
// Find where the VM was last running
345345
hostVO = getLastVMHypervisorHost(vm);
346346
// Get credentials for that host
347347
Ternary<String, String, String> credentials = getKVMHyperisorCredentials(hostVO);
348-
LOG.debug("The SSID was reported successfully " + externalBackupId);
348+
LOG.debug("The SSID was reported successfully {}", externalBackupId);
349349
try {
350350
networkerServer = getUrlDomain(NetworkerUrl.value());
351351
} catch (URISyntaxException e) {
@@ -362,14 +362,14 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
362362
script.add("-v");
363363

364364
Date restoreJobStart = new Date();
365-
LOG.debug(String.format("Starting Restore for VM %s and %s at %s", vm, SSID, restoreJobStart));
365+
LOG.debug("Starting Restore for VM {} and {} at {}", vm, SSID, restoreJobStart);
366366

367367
if ( executeRestoreCommand(hostVO, credentials.first(), credentials.second(), script.toString()) ) {
368368
Date restoreJobEnd = new Date();
369-
LOG.debug("Restore Job for SSID " + SSID + " completed successfully at " + restoreJobEnd);
369+
LOG.debug("Restore Job for SSID {} completed successfully at {}", SSID, restoreJobEnd);
370370
return true;
371371
} else {
372-
LOG.debug("Restore Job for SSID " + SSID + " failed!");
372+
LOG.debug("Restore Job for SSID {} failed!", SSID);
373373
return false;
374374
}
375375
}
@@ -390,7 +390,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
390390
final String destinationNetworkerClient = hostVO.getName().split("\\.")[0];
391391
Long restoredVolumeDiskSize = 0L;
392392

393-
LOG.debug(String.format("Restoring volume %s with uuid %s from backup %s on the Networker Backup Provider", volume, volumeUuid, backup));
393+
LOG.debug("Restoring volume {} with uuid {} from backup {} on the Networker Backup Provider", volume, volumeUuid, backup);
394394

395395
if ( SSID.isEmpty() ) {
396396
LOG.debug("There was an error retrieving the SSID for backup with id " + externalBackupId + " from EMC NEtworker");
@@ -543,8 +543,8 @@ public boolean deleteBackup(Backup backup, boolean forced) {
543543
@Override
544544
public Map<VirtualMachine, Backup.Metric> getBackupMetrics(Long zoneId, List<VirtualMachine> vms) {
545545
final Map<VirtualMachine, Backup.Metric> metrics = new HashMap<>();
546-
Long vmBackupSize=0L;
547-
Long vmBackupProtectedSize=0L;
546+
long vmBackupSize=0L;
547+
long vmBackupProtectedSize=0L;
548548

549549
if (CollectionUtils.isEmpty(vms)) {
550550
LOG.warn("Unable to get VM Backup Metrics because the list of VMs is empty.");
@@ -577,7 +577,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
577577
final ArrayList<String> backupsInNetworker = getClient(zoneId).getBackupsForVm(vm);
578578
final List<Long> removeList = backupsInDb.stream().map(InternalIdentity::getId).collect(Collectors.toList());
579579
for (final String networkerBackupId : backupsInNetworker ) {
580-
Long vmBackupSize=0L;
580+
long vmBackupSize=0L;
581581
boolean backupExists = false;
582582
for (final Backup backupInDb : backupsInDb) {
583583
LOG.debug(String.format("Checking if Backup %s with external ID %s for VM %s is valid", backupsInDb, backupInDb.getName(), vm));
@@ -671,7 +671,7 @@ public Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoi
671671
throw new CloudRuntimeException(msg, e);
672672
}
673673
backup.setStatus(Backup.Status.BackedUp);
674-
Long vmBackupProtectedSize=0L;
674+
long vmBackupProtectedSize=0L;
675675
for (Backup.VolumeInfo thisVMVol : vm.getBackupVolumeList()) {
676676
vmBackupProtectedSize += (thisVMVol.getSize() / 1024L / 1024L);
677677
}
@@ -692,9 +692,7 @@ public Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoi
692692
public List<Backup.RestorePoint> listRestorePoints(VirtualMachine vm) {
693693
final Long zoneId = vm.getDataCenterId();
694694
final ArrayList<String> backupIds = getClient(zoneId).getBackupsForVm(vm);
695-
List<Backup.RestorePoint> restorePoints =
696-
backupIds.stream().map(id -> new Backup.RestorePoint(id, null, null)).collect(Collectors.toList());
697-
return restorePoints;
695+
return backupIds.stream().map(id -> new Backup.RestorePoint(id, null, null)).collect(Collectors.toList());
698696
}
699697

700698
@Override

0 commit comments

Comments
 (0)