21
21
import com .cloud .host .Status ;
22
22
import com .cloud .host .dao .HostDao ;
23
23
import com .cloud .hypervisor .Hypervisor ;
24
+ import com .cloud .utils .script .Script ;
24
25
import com .cloud .storage .StoragePoolHostVO ;
25
26
import com .cloud .storage .Volume ;
26
27
import com .cloud .storage .VolumeVO ;
34
35
import com .cloud .vm .VMInstanceVO ;
35
36
import com .cloud .vm .VirtualMachine ;
36
37
import com .cloud .vm .dao .VMInstanceDao ;
38
+
37
39
import org .apache .cloudstack .backup .dao .BackupDao ;
38
40
import org .apache .cloudstack .backup .dao .BackupOfferingDaoImpl ;
39
41
import org .apache .cloudstack .backup .networker .NetworkerClient ;
44
46
import org .apache .logging .log4j .LogManager ;
45
47
import org .apache .xml .utils .URI ;
46
48
import org .apache .cloudstack .backup .networker .api .NetworkerBackup ;
49
+
47
50
import javax .inject .Inject ;
51
+
48
52
import java .net .URISyntaxException ;
49
53
import java .security .KeyManagementException ;
50
54
import java .security .NoSuchAlgorithmException ;
60
64
import java .util .regex .Matcher ;
61
65
import java .util .regex .Pattern ;
62
66
import java .util .stream .Collectors ;
63
- import com .cloud .utils .script .Script ;
64
67
65
68
public class NetworkerBackupProvider extends AdapterBase implements BackupProvider , Configurable {
66
69
@@ -169,7 +172,7 @@ protected HostVO getLastVMHypervisorHost(VirtualMachine vm) {
169
172
List <HostVO > altClusterHosts = hostDao .findHypervisorHostInCluster (host .getClusterId ());
170
173
for (final HostVO candidateClusterHost : altClusterHosts ) {
171
174
if ( candidateClusterHost .getStatus () == Status .Up ) {
172
- LOG .debug (String . format ( "Found Host %s " , candidateClusterHost ) );
175
+ LOG .debug ("Found Host {} " , candidateClusterHost );
173
176
return candidateClusterHost ;
174
177
}
175
178
}
@@ -178,7 +181,7 @@ protected HostVO getLastVMHypervisorHost(VirtualMachine vm) {
178
181
List <HostVO > altZoneHosts = hostDao .findByDataCenterId (host .getDataCenterId ());
179
182
for (final HostVO candidateZoneHost : altZoneHosts ) {
180
183
if ( candidateZoneHost .getStatus () == Status .Up && candidateZoneHost .getHypervisorType () == Hypervisor .HypervisorType .KVM ) {
181
- LOG .debug ("Found Host " + candidateZoneHost );
184
+ LOG .debug ("Found Host {}" , candidateZoneHost );
182
185
return candidateZoneHost ;
183
186
}
184
187
}
@@ -229,13 +232,13 @@ private String executeBackupCommand(HostVO host, String username, String passwor
229
232
Pair <Boolean , String > response = SshHelper .sshExecute (host .getPrivateIpAddress (), 22 ,
230
233
username , null , password , command , 120000 , 120000 , 3600000 );
231
234
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 ());
233
236
} else {
234
- LOG .debug (String . format ( "Networker Backup Results: %s " , response .second () ));
237
+ LOG .debug ("Networker Backup Results: {} " , response .second ());
235
238
}
236
239
Matcher saveTimeMatcher = saveTimePattern .matcher (response .second ());
237
240
if (saveTimeMatcher .find ()) {
238
- LOG .debug (String . format ( "Got saveTimeMatcher: %s " , saveTimeMatcher .group (1 ) ));
241
+ LOG .debug ("Got saveTimeMatcher: {} " , saveTimeMatcher .group (1 ));
239
242
return saveTimeMatcher .group (1 );
240
243
}
241
244
} catch (final Exception e ) {
@@ -251,9 +254,9 @@ private boolean executeRestoreCommand(HostVO host, String username, String passw
251
254
username , null , password , command , 120000 , 120000 , 3600000 );
252
255
253
256
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 ());
255
258
} else {
256
- LOG .debug (String . format ( "Networker Restore Results: %s " ,response .second () ));
259
+ LOG .debug ("Networker Restore Results: {} " ,response .second ());
257
260
return true ;
258
261
}
259
262
} catch (final Exception e ) {
@@ -310,7 +313,7 @@ public boolean removeVMFromBackupOffering(VirtualMachine vm) {
310
313
List <String > backupsTaken = getClient (vm .getDataCenterId ()).getBackupsForVm (vm );
311
314
312
315
for (String backupId : backupsTaken ) {
313
- LOG .debug ("Trying to remove backup with id" + backupId );
316
+ LOG .debug ("Trying to remove backup with id {}" , backupId );
314
317
getClient (vm .getDataCenterId ()).deleteBackupForVM (backupId );
315
318
}
316
319
@@ -327,18 +330,18 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
327
330
final NetworkerBackup networkerBackup =getClient (zoneId ).getNetworkerBackupInfo (externalBackupId );
328
331
final String SSID = networkerBackup .getShortId ();
329
332
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 );
331
334
332
335
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 );
334
337
return false ;
335
338
}
336
339
337
340
// Find where the VM was last running
338
341
hostVO = getLastVMHypervisorHost (vm );
339
342
// Get credentials for that host
340
343
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 );
342
345
try {
343
346
networkerServer = getUrlDomain (NetworkerUrl .value ());
344
347
} catch (URISyntaxException e ) {
@@ -355,14 +358,14 @@ public boolean restoreVMFromBackup(VirtualMachine vm, Backup backup) {
355
358
script .add ("-v" );
356
359
357
360
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 );
359
362
360
363
if ( executeRestoreCommand (hostVO , credentials .first (), credentials .second (), script .toString ()) ) {
361
364
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 );
363
366
return true ;
364
367
} else {
365
- LOG .debug ("Restore Job for SSID " + SSID + " failed!" );
368
+ LOG .debug ("Restore Job for SSID {} failed!" , SSID );
366
369
return false ;
367
370
}
368
371
}
@@ -383,7 +386,7 @@ public Pair<Boolean, String> restoreBackedUpVolume(Backup backup, String volumeU
383
386
final String destinationNetworkerClient = hostVO .getName ().split ("\\ ." )[0 ];
384
387
Long restoredVolumeDiskSize = 0L ;
385
388
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 );
387
390
388
391
if ( SSID .isEmpty () ) {
389
392
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) {
536
539
@ Override
537
540
public Map <VirtualMachine , Backup .Metric > getBackupMetrics (Long zoneId , List <VirtualMachine > vms ) {
538
541
final Map <VirtualMachine , Backup .Metric > metrics = new HashMap <>();
539
- Long vmBackupSize =0L ;
540
- Long vmBackupProtectedSize =0L ;
542
+ long vmBackupSize =0L ;
543
+ long vmBackupProtectedSize =0L ;
541
544
542
545
if (CollectionUtils .isEmpty (vms )) {
543
546
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
584
587
throw new CloudRuntimeException (msg , e );
585
588
}
586
589
backup .setStatus (Backup .Status .BackedUp );
587
- Long vmBackupProtectedSize =0L ;
590
+ long vmBackupProtectedSize =0L ;
588
591
for (Backup .VolumeInfo thisVMVol : vm .getBackupVolumeList ()) {
589
592
vmBackupProtectedSize += (thisVMVol .getSize () / 1024L / 1024L );
590
593
}
@@ -605,9 +608,7 @@ public Backup createNewBackupEntryForRestorePoint(Backup.RestorePoint restorePoi
605
608
public List <Backup .RestorePoint > listRestorePoints (VirtualMachine vm ) {
606
609
final Long zoneId = vm .getDataCenterId ();
607
610
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 ());
611
612
}
612
613
613
614
@ Override
0 commit comments