2121import com.cloud.host.Status;
2222import com.cloud.host.dao.HostDao;
2323import com.cloud.hypervisor.Hypervisor;
24+ import com.cloud.utils.script.Script;
2425import com.cloud.storage.StoragePoolHostVO;
2526import com.cloud.storage.Volume;
2627import com.cloud.storage.VolumeVO;
3435import com.cloud.vm.VMInstanceVO;
3536import com.cloud.vm.VirtualMachine;
3637import com.cloud.vm.dao.VMInstanceDao;
38+
3739import org.apache.cloudstack.backup.dao.BackupDao;
3840import org.apache.cloudstack.backup.dao.BackupOfferingDaoImpl;
3941import org.apache.cloudstack.backup.networker.NetworkerClient;
4446import org.apache.logging.log4j.LogManager;
4547import org.apache.xml.utils.URI;
4648import org.apache.cloudstack.backup.networker.api.NetworkerBackup;
49+
4750import javax.inject.Inject;
51+
4852import java.net.URISyntaxException;
4953import java.security.KeyManagementException;
5054import java.security.NoSuchAlgorithmException;
6064import java.util.regex.Matcher;
6165import java.util.regex.Pattern;
6266import java.util.stream.Collectors;
63- import com.cloud.utils.script.Script;
6467
6568public class NetworkerBackupProvider extends AdapterBase implements BackupProvider, Configurable {
6669
@@ -169,7 +172,7 @@ protected HostVO getLastVMHypervisorHost(VirtualMachine vm) {
169172 List<HostVO> altClusterHosts = hostDao.findHypervisorHostInCluster(host.getClusterId());
170173 for (final HostVO candidateClusterHost : altClusterHosts) {
171174 if ( candidateClusterHost.getStatus() == Status.Up ) {
172- LOG.debug(String.format( "Found Host %s ", candidateClusterHost) );
175+ LOG.debug("Found Host {} ", candidateClusterHost);
173176 return candidateClusterHost;
174177 }
175178 }
@@ -178,7 +181,7 @@ protected HostVO getLastVMHypervisorHost(VirtualMachine vm) {
178181 List<HostVO> altZoneHosts = hostDao.findByDataCenterId(host.getDataCenterId());
179182 for (final HostVO candidateZoneHost : altZoneHosts) {
180183 if ( candidateZoneHost.getStatus() == Status.Up && candidateZoneHost.getHypervisorType() == Hypervisor.HypervisorType.KVM ) {
181- LOG.debug("Found Host " + candidateZoneHost);
184+ LOG.debug("Found Host {}", candidateZoneHost);
182185 return candidateZoneHost;
183186 }
184187 }
@@ -229,13 +232,13 @@ private String executeBackupCommand(HostVO host, String username, String passwor
229232 Pair<Boolean, String> response = SshHelper.sshExecute(host.getPrivateIpAddress(), 22,
230233 username, null, password, command, 120000, 120000, 3600000);
231234 if (!response.first()) {
232- LOG.error(String.format( "Backup Script failed on HYPERVISOR %s due to: %s ", host, response.second() ));
235+ LOG.error("Backup Script failed on HYPERVISOR {} due to: {} ", host, response.second());
233236 } else {
234- LOG.debug(String.format( "Networker Backup Results: %s ", response.second() ));
237+ LOG.debug("Networker Backup Results: {} ", response.second());
235238 }
236239 Matcher saveTimeMatcher = saveTimePattern.matcher(response.second());
237240 if (saveTimeMatcher.find()) {
238- LOG.debug(String.format( "Got saveTimeMatcher: %s ", saveTimeMatcher.group(1) ));
241+ LOG.debug("Got saveTimeMatcher: {} ", saveTimeMatcher.group(1));
239242 return saveTimeMatcher.group(1);
240243 }
241244 } catch (final Exception e) {
@@ -251,9 +254,9 @@ private boolean executeRestoreCommand(HostVO host, String username, String passw
251254 username, null, password, command, 120000, 120000, 3600000);
252255
253256 if (!response.first()) {
254- LOG.error(String.format( "Restore Script failed on HYPERVISOR %s due to: %s ", host, response.second() ));
257+ LOG.error("Restore Script failed on HYPERVISOR {} due to: {} ", host, response.second());
255258 } else {
256- LOG.debug(String.format( "Networker Restore Results: %s ",response.second() ));
259+ LOG.debug("Networker Restore Results: {} ",response.second());
257260 return true;
258261 }
259262 } catch (final Exception e) {
@@ -310,7 +313,7 @@ public boolean removeVMFromBackupOffering(VirtualMachine vm) {
310313 List<String> backupsTaken = getClient(vm.getDataCenterId()).getBackupsForVm(vm);
311314
312315 for (String backupId : backupsTaken) {
313- LOG.debug("Trying to remove backup with id" + backupId);
316+ LOG.debug("Trying to remove backup with id {}", backupId);
314317 getClient(vm.getDataCenterId()).deleteBackupForVM(backupId);
315318 }
316319
@@ -327,18 +330,18 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
327330 final NetworkerBackup networkerBackup=getClient(zoneId).getNetworkerBackupInfo(externalBackupId);
328331 final String SSID = networkerBackup.getShortId();
329332
330- LOG.debug(String.format( "Restoring vm %s from backup %s on the Networker Backup Provider", vm, backup) );
333+ LOG.debug("Restoring vm {} from backup {} on the Networker Backup Provider", vm, backup);
331334
332335 if ( SSID.isEmpty() ) {
333- LOG.debug("There was an error retrieving the SSID for backup with id " + externalBackupId + " from EMC NEtworker");
336+ LOG.debug("There was an error retrieving the SSID for backup with id {} from EMC NEtworker", externalBackupId );
334337 return false;
335338 }
336339
337340 // Find where the VM was last running
338341 hostVO = getLastVMHypervisorHost(vm);
339342 // Get credentials for that host
340343 Ternary<String, String, String> credentials = getKVMHyperisorCredentials(hostVO);
341- LOG.debug("The SSID was reported successfully " + externalBackupId);
344+ LOG.debug("The SSID was reported successfully {}", externalBackupId);
342345 try {
343346 networkerServer = getUrlDomain(NetworkerUrl.value());
344347 } catch (URISyntaxException e) {
@@ -355,14 +358,14 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
355358 script.add("-v");
356359
357360 Date restoreJobStart = new Date();
358- LOG.debug(String.format( "Starting Restore for VM %s and %s at %s ", vm, SSID, restoreJobStart) );
361+ LOG.debug("Starting Restore for VM {} and {} at {} ", vm, SSID, restoreJobStart);
359362
360363 if ( executeRestoreCommand(hostVO, credentials.first(), credentials.second(), script.toString()) ) {
361364 Date restoreJobEnd = new Date();
362- LOG.debug("Restore Job for SSID " + SSID + " completed successfully at " + restoreJobEnd);
365+ LOG.debug("Restore Job for SSID {} completed successfully at {}", SSID, restoreJobEnd);
363366 return true;
364367 } else {
365- LOG.debug("Restore Job for SSID " + SSID + " failed!");
368+ LOG.debug("Restore Job for SSID {} failed!", SSID );
366369 return false;
367370 }
368371 }
@@ -383,7 +386,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
383386 final String destinationNetworkerClient = hostVO.getName().split("\\.")[0];
384387 Long restoredVolumeDiskSize = 0L;
385388
386- LOG.debug(String.format( "Restoring volume %s with uuid %s from backup %s on the Networker Backup Provider", volume, volumeUuid, backup) );
389+ LOG.debug("Restoring volume {} with uuid {} from backup {} on the Networker Backup Provider", volume, volumeUuid, backup);
387390
388391 if ( SSID.isEmpty() ) {
389392 LOG.debug("There was an error retrieving the SSID for backup with id " + externalBackupId + " from EMC NEtworker");
@@ -536,8 +539,8 @@ public boolean deleteBackup(Backup backup, boolean forced) {
536539 @Override
537540 public Map<VirtualMachine, Backup.Metric> getBackupMetrics(Long zoneId, List<VirtualMachine> vms) {
538541 final Map<VirtualMachine, Backup.Metric> metrics = new HashMap<>();
539- Long vmBackupSize=0L;
540- Long vmBackupProtectedSize=0L;
542+ long vmBackupSize=0L;
543+ long vmBackupProtectedSize=0L;
541544
542545 if (CollectionUtils.isEmpty(vms)) {
543546 LOG.warn("Unable to get VM Backup Metrics because the list of VMs is empty.");
@@ -584,7 +587,7 @@ public Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoi
584587 throw new CloudRuntimeException(msg, e);
585588 }
586589 backup.setStatus(Backup.Status.BackedUp);
587- Long vmBackupProtectedSize=0L;
590+ long vmBackupProtectedSize=0L;
588591 for (Backup.VolumeInfo thisVMVol : vm.getBackupVolumeList()) {
589592 vmBackupProtectedSize += (thisVMVol.getSize() / 1024L / 1024L);
590593 }
@@ -605,9 +608,7 @@ public Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoi
605608 public List<Backup.RestorePoint> listRestorePoints(VirtualMachine vm) {
606609 final Long zoneId = vm.getDataCenterId();
607610 final ArrayList<String> backupIds = getClient(zoneId).getBackupsForVm(vm);
608- List<Backup.RestorePoint> restorePoints =
609- backupIds.stream().map(id -> new Backup.RestorePoint(id, null, null)).collect(Collectors.toList());
610- return restorePoints;
611+ return backupIds.stream().map(id -> new Backup.RestorePoint(id, null, null)).collect(Collectors.toList());
611612 }
612613
613614 @Override
0 commit comments