1919
2020package com .cloud .hypervisor .kvm .resource .wrapper ;
2121
22- import com .amazonaws .util .CollectionUtils ;
2322import com .cloud .agent .api .Answer ;
2423import com .cloud .hypervisor .kvm .resource .LibvirtComputingResource ;
2524import com .cloud .hypervisor .kvm .storage .KVMPhysicalDisk ;
3332import org .apache .cloudstack .backup .BackupAnswer ;
3433import org .apache .cloudstack .backup .TakeBackupCommand ;
3534import org .apache .cloudstack .storage .to .PrimaryDataStoreTO ;
35+ import org .apache .commons .collections .CollectionUtils ;
36+ import org .apache .commons .lang3 .StringUtils ;
3637
3738import java .util .ArrayList ;
3839import java .util .Arrays ;
@@ -92,7 +93,7 @@ public Answer execute(TakeBackupCommand command, LibvirtComputingResource libvir
9293
9394 if (result .first () != 0 ) {
9495 logger .debug ("Failed to take VM backup: " + result .second ());
95- BackupAnswer answer = new BackupAnswer (command , false , result .second (). trim ( ));
96+ BackupAnswer answer = new BackupAnswer (command , false , StringUtils . trimToEmpty ( result .second ()));
9697 if (EXIT_CLEANUP_FAILED .equals (result .first ())) {
9798 logger .debug ("Backup cleanup failed" );
9899 answer .setNeedsCleanup (true );
@@ -104,7 +105,7 @@ public Answer execute(TakeBackupCommand command, LibvirtComputingResource libvir
104105 // parent checkpoint can't be re-registered) and signals it with INCREMENTAL_FALLBACK
105106 // on stdout. Detect it, then strip the marker line before parsing the backup size.
106107 String rawStdout = result .second ();
107- boolean incrementalFallback = rawStdout .contains (INCREMENTAL_FALLBACK_MARKER );
108+ boolean incrementalFallback = StringUtils .contains (rawStdout , INCREMENTAL_FALLBACK_MARKER );
108109 String stdout = stripMarkerLines (rawStdout ).trim ();
109110 long backupSize = parseBackupSize (stdout , diskPaths );
110111
@@ -119,7 +120,7 @@ public Answer execute(TakeBackupCommand command, LibvirtComputingResource libvir
119120
120121 /** Remove nasbackup.sh's stdout signalling marker lines so they don't pollute size parsing. */
121122 private String stripMarkerLines (String stdout ) {
122- if (stdout == null || stdout . isEmpty ( )) {
123+ if (StringUtils . isBlank ( stdout )) {
123124 return "" ;
124125 }
125126 StringBuilder sb = new StringBuilder ();
@@ -151,21 +152,21 @@ private Pair<Integer, String> runBackupScript(LibvirtComputingResource libvirtCo
151152 "-m" , Objects .nonNull (mountOptions ) ? mountOptions : "" ,
152153 "-p" , backupPath ,
153154 "-q" , command .getQuiesce () != null && command .getQuiesce () ? "true" : "false" ,
154- "-d" , diskPaths .isEmpty () ? "" : String .join ("," , diskPaths )
155+ "-d" , CollectionUtils .isEmpty (diskPaths ) ? "" : String .join ("," , diskPaths )
155156 ));
156- if (mode != null && ! mode . isEmpty ( )) {
157+ if (StringUtils . isNotBlank ( mode )) {
157158 argv .add ("-M" );
158159 argv .add (mode );
159160 }
160- if (bitmapNew != null && ! bitmapNew . isEmpty ( )) {
161+ if (StringUtils . isNotBlank ( bitmapNew )) {
161162 argv .add ("--bitmap-new" );
162163 argv .add (bitmapNew );
163164 }
164- if (bitmapParent != null && ! bitmapParent . isEmpty ( )) {
165+ if (StringUtils . isNotBlank ( bitmapParent )) {
165166 argv .add ("--bitmap-parent" );
166167 argv .add (bitmapParent );
167168 }
168- if (parentPaths != null && ! parentPaths . isEmpty ( )) {
169+ if (CollectionUtils . isNotEmpty ( parentPaths )) {
169170 argv .add ("--parent-paths" );
170171 argv .add (String .join ("," , parentPaths ));
171172 }
@@ -181,29 +182,29 @@ private Pair<Integer, String> runBackupScript(LibvirtComputingResource libvirtCo
181182 */
182183 private String validateBackupArgs (TakeBackupCommand command ) {
183184 String mode = command .getMode ();
184- if (mode == null || mode . isEmpty ( )) {
185- return null ; // legacy full-only — no extra args expected
185+ if (StringUtils . isBlank ( mode )) {
186+ return null ; // legacy full-only, no extra args expected
186187 }
187188 if (MODE_INCREMENTAL .equals (mode )) {
188- if (command . getBitmapNew () == null || command .getBitmapNew (). isEmpty ( )) {
189+ if (StringUtils . isBlank ( command .getBitmapNew ())) {
189190 return "incremental mode requires bitmapNew" ;
190191 }
191- if (command . getBitmapParent () == null || command .getBitmapParent (). isEmpty ( )) {
192+ if (StringUtils . isBlank ( command .getBitmapParent ())) {
192193 return "incremental mode requires bitmapParent" ;
193194 }
194- if (command . getParentPaths () == null || command .getParentPaths (). isEmpty ( )) {
195+ if (CollectionUtils . isEmpty ( command .getParentPaths ())) {
195196 return "incremental mode requires parentPaths" ;
196197 }
197198 return null ;
198199 }
199200 if (MODE_FULL .equals (mode )) {
200- if (command . getBitmapNew () == null || command .getBitmapNew (). isEmpty ( )) {
201+ if (StringUtils . isBlank ( command .getBitmapNew ())) {
201202 return "full mode requires bitmapNew (the bitmap to create for the next incremental)" ;
202203 }
203204 return null ;
204205 }
205206 if (MODE_LEGACY_FULL .equals (mode )) {
206- return null ; // feature-off full backup — no bitmap or chain args expected
207+ return null ; // feature-off full backup, no bitmap or chain args expected
207208 }
208209 return "Unknown backup mode: " + mode ;
209210 }
@@ -215,7 +216,7 @@ private String validateBackupArgs(TakeBackupCommand command) {
215216 */
216217 private long parseBackupSize (String stdout , List <String > diskPaths ) {
217218 long backupSize = 0L ;
218- if (CollectionUtils .isNullOrEmpty (diskPaths )) {
219+ if (CollectionUtils .isEmpty (diskPaths )) {
219220 List <String > outputLines = Arrays .asList (stdout .split ("\n " ));
220221 if (!outputLines .isEmpty ()) {
221222 backupSize = Long .parseLong (outputLines .get (outputLines .size () - 1 ).trim ());
0 commit comments