@@ -273,7 +273,11 @@ protected CopyCmdAnswer postProcessing(File destFile, String downloadPath, Strin
273273 newTemplTO .setSize (size );
274274 newDestTO = newTemplTO ;
275275 } else {
276- return new CopyCmdAnswer ("not implemented yet" );
276+ VolumeObjectTO newVolTO = new VolumeObjectTO ();
277+ newVolTO .setPath (finalDownloadPath );
278+ newVolTO .setName (finalFileName );
279+ newVolTO .setSize (size );
280+ newDestTO = newVolTO ;
277281 }
278282
279283 return new CopyCmdAnswer (newDestTO );
@@ -313,11 +317,11 @@ protected Answer copyFromS3ToNfs(CopyCommand cmd, DataTO srcData, S3TO s3, DataT
313317
314318 File destFile = S3Utils .getFile (s3 , s3 .getBucketName (), srcData .getPath (), downloadDirectory ,
315319 new FileNamingStrategy () {
316- @ Override
317- public String determineFileName (final String key ) {
318- return substringAfterLast (key , S3Utils .SEPARATOR );
319- }
320- });
320+ @ Override
321+ public String determineFileName (final String key ) {
322+ return substringAfterLast (key , S3Utils .SEPARATOR );
323+ }
324+ });
321325
322326 if (destFile == null ) {
323327 return new CopyCmdAnswer ("Can't find template" );
@@ -589,10 +593,10 @@ protected Answer registerTemplateOnSwift(DownloadCommand cmd) {
589593
590594 DownloadAnswer answer = new DownloadAnswer (null , 100 , null , VMTemplateStorageResourceAssoc .Status .DOWNLOADED ,
591595 swiftPath , swiftPath , file .length (), file .length (), md5sum
592- );
596+ );
593597 return answer ;
594598 } catch (Exception e ) {
595- s_logger .debug ("Failed to register template into swift" , e );
599+ s_logger .debug ("Failed to register template into swift" , e );
596600 return new DownloadAnswer (e .toString (), VMTemplateStorageResourceAssoc .Status .DOWNLOAD_ERROR );
597601 } finally {
598602 if (file != null ) {
@@ -650,16 +654,17 @@ private ImageFormat getTemplateFormat(String filePath) {
650654 ext = filePath .substring (i + 1 );
651655 }
652656 if (ext != null ) {
653- if (ext .equalsIgnoreCase ("vhd" ))
657+ if (ext .equalsIgnoreCase ("vhd" )) {
654658 return ImageFormat .VHD ;
655- else if (ext .equalsIgnoreCase ("qcow2" ))
659+ } else if (ext .equalsIgnoreCase ("qcow2" )) {
656660 return ImageFormat .QCOW2 ;
657- else if (ext .equalsIgnoreCase ("ova" ))
661+ } else if (ext .equalsIgnoreCase ("ova" )) {
658662 return ImageFormat .OVA ;
659- else if (ext .equalsIgnoreCase ("tar" ))
663+ } else if (ext .equalsIgnoreCase ("tar" )) {
660664 return ImageFormat .TAR ;
661- else if (ext .equalsIgnoreCase ("img" ))
665+ } else if (ext .equalsIgnoreCase ("img" )) {
662666 return ImageFormat .RAW ;
667+ }
663668 }
664669
665670 return null ;
@@ -921,16 +926,16 @@ public Answer execute(DeleteSnapshotsDirCommand cmd) {
921926 } else if (dstore instanceof SwiftTO ) {
922927 String path = cmd .getDirectory ();
923928 String volumeId = StringUtils .substringAfterLast (path , "/" ); // assuming
924- // that
925- // the
926- // filename
927- // is
928- // the
929- // last
930- // section
931- // in
932- // the
933- // path
929+ // that
930+ // the
931+ // filename
932+ // is
933+ // the
934+ // last
935+ // section
936+ // in
937+ // the
938+ // path
934939 String result = swiftDelete ((SwiftTO ) dstore , "V-" + volumeId .toString (), "" );
935940 if (result != null ) {
936941 String errMsg = "failed to delete snapshot for volume " + volumeId + " , err=" + result ;
@@ -971,12 +976,12 @@ public Void call() throws Exception {
971976 final File targetFile = S3Utils .getFile (s3 , s3 .getBucketName (), key ,
972977 _storage .getFile (directoryName ), new FileNamingStrategy () {
973978
974- @ Override
975- public String determineFileName (String key ) {
976- return snapshotFileName ;
977- }
979+ @ Override
980+ public String determineFileName (String key ) {
981+ return snapshotFileName ;
982+ }
978983
979- });
984+ });
980985
981986 if (cmd .getParent () != null ) {
982987
@@ -1125,8 +1130,9 @@ private Answer execute(ComputeChecksumCommand cmd) {
11251130 return new Answer (cmd , false , checksum );
11261131 } finally {
11271132 try {
1128- if (is != null )
1133+ if (is != null ) {
11291134 is .close ();
1135+ }
11301136 } catch (IOException e ) {
11311137 if (s_logger .isDebugEnabled ()) {
11321138 s_logger .debug ("Could not close the file " + absoluteTemplatePath );
@@ -1239,24 +1245,24 @@ private String deleteSnapshotBackupfromS3(final S3TO s3, final Long accountId, f
12391245 final String result = executeWithNoWaitLock (determineSnapshotLockId (accountId , volumeId ),
12401246 new Callable <String >() {
12411247
1242- @ Override
1243- public String call () throws Exception {
1244-
1245- if (deleteAllFlag ) {
1246- S3Utils .deleteDirectory (s3 , bucket , determineSnapshotS3Directory (accountId , volumeId ));
1247- } else {
1248- S3Utils .deleteObject (
1249- s3 ,
1250- bucket ,
1251- determineSnapshotS3Key (accountId , volumeId ,
1252- determineSnapshotBackupFilename (name )));
1253- }
1248+ @ Override
1249+ public String call () throws Exception {
1250+
1251+ if (deleteAllFlag ) {
1252+ S3Utils .deleteDirectory (s3 , bucket , determineSnapshotS3Directory (accountId , volumeId ));
1253+ } else {
1254+ S3Utils .deleteObject (
1255+ s3 ,
1256+ bucket ,
1257+ determineSnapshotS3Key (accountId , volumeId ,
1258+ determineSnapshotBackupFilename (name )));
1259+ }
12541260
1255- return null ;
1261+ return null ;
12561262
1257- }
1263+ }
12581264
1259- });
1265+ });
12601266
12611267 return result ;
12621268
@@ -1330,16 +1336,16 @@ protected Answer deleteSnapshot(final DeleteCommand cmd) {
13301336 } else if (dstore instanceof SwiftTO ) {
13311337 String path = obj .getPath ();
13321338 String filename = StringUtils .substringAfterLast (path , "/" ); // assuming
1333- // that
1334- // the
1335- // filename
1336- // is
1337- // the
1338- // last
1339- // section
1340- // in
1341- // the
1342- // path
1339+ // that
1340+ // the
1341+ // filename
1342+ // is
1343+ // the
1344+ // last
1345+ // section
1346+ // in
1347+ // the
1348+ // path
13431349 String volumeId = StringUtils .substringAfterLast (StringUtils .substringBeforeLast (path , "/" ), "/" );
13441350 String result = swiftDelete ((SwiftTO ) dstore , "V-" + volumeId , filename );
13451351 if (result != null ) {
@@ -1391,8 +1397,9 @@ Map<String, TemplateProp> s3ListTemplate(S3TO s3) {
13911397 String bucket = s3 .getBucketName ();
13921398 // List the objects in the source directory on S3
13931399 final List <S3ObjectSummary > objectSummaries = S3Utils .getDirectory (s3 , bucket , this .TEMPLATE_ROOT_DIR );
1394- if (objectSummaries == null )
1400+ if (objectSummaries == null ) {
13951401 return null ;
1402+ }
13961403 Map <String , TemplateProp > tmpltInfos = new HashMap <String , TemplateProp >();
13971404 for (S3ObjectSummary objectSummary : objectSummaries ) {
13981405 String key = objectSummary .getKey ();
@@ -1412,8 +1419,9 @@ Map<Long, TemplateProp> s3ListVolume(S3TO s3) {
14121419 String bucket = s3 .getBucketName ();
14131420 // List the objects in the source directory on S3
14141421 final List <S3ObjectSummary > objectSummaries = S3Utils .getDirectory (s3 , bucket , this .VOLUME_ROOT_DIR );
1415- if (objectSummaries == null )
1422+ if (objectSummaries == null ) {
14161423 return null ;
1424+ }
14171425 Map <Long , TemplateProp > tmpltInfos = new HashMap <Long , TemplateProp >();
14181426 for (S3ObjectSummary objectSummary : objectSummaries ) {
14191427 String key = objectSummary .getKey ();
@@ -1596,8 +1604,9 @@ private Answer execute(SecStorageFirewallCfgCommand cmd) {
15961604 boolean success = true ;
15971605 String result ;
15981606 result = configureIpFirewall (ipList , cmd .getIsAppendAIp ());
1599- if (result != null )
1607+ if (result != null ) {
16001608 success = false ;
1609+ }
16011610
16021611 return new Answer (cmd , success , result );
16031612 }
@@ -1807,16 +1816,16 @@ protected Answer deleteVolume(final DeleteCommand cmd) {
18071816 Long volumeId = obj .getId ();
18081817 String path = obj .getPath ();
18091818 String filename = StringUtils .substringAfterLast (path , "/" ); // assuming
1810- // that
1811- // the
1812- // filename
1813- // is
1814- // the
1815- // last
1816- // section
1817- // in
1818- // the
1819- // path
1819+ // that
1820+ // the
1821+ // filename
1822+ // is
1823+ // the
1824+ // last
1825+ // section
1826+ // in
1827+ // the
1828+ // path
18201829 String result = swiftDelete ((SwiftTO ) dstore , "V-" + volumeId .toString (), filename );
18211830 if (result != null ) {
18221831 String errMsg = "failed to delete volume " + filename + " , err=" + result ;
@@ -1882,8 +1891,9 @@ protected long convertFilesystemSize(final String size) {
18821891
18831892 @ Override
18841893 public Type getType () {
1885- if (SecondaryStorageVm .Role .templateProcessor .toString ().equals (_role ))
1894+ if (SecondaryStorageVm .Role .templateProcessor .toString ().equals (_role )) {
18861895 return Host .Type .SecondaryStorage ;
1896+ }
18871897
18881898 return Host .Type .SecondaryStorageCmdExecutor ;
18891899 }
@@ -1946,8 +1956,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
19461956 }
19471957 }
19481958
1949- if (_inSystemVM )
1959+ if (_inSystemVM ) {
19501960 _storage .mkdirs (_parent );
1961+ }
19511962
19521963 _configSslScr = Script .findScript (getDefaultScriptsDir (), "config_ssl.sh" );
19531964 if (_configSslScr != null ) {
@@ -1972,8 +1983,9 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
19721983 }
19731984
19741985 _role = (String ) params .get ("role" );
1975- if (_role == null )
1986+ if (_role == null ) {
19761987 _role = SecondaryStorageVm .Role .templateProcessor .toString ();
1988+ }
19771989 s_logger .info ("Secondary storage runs in role " + _role );
19781990
19791991 _guid = (String ) params .get ("guid" );
@@ -2189,8 +2201,9 @@ protected String mount(String root, String nfsPath) {
21892201 if (result != null ) {
21902202 s_logger .warn ("Unable to mount " + nfsPath + " due to " + result );
21912203 file = new File (root );
2192- if (file .exists ())
2204+ if (file .exists ()) {
21932205 file .delete ();
2206+ }
21942207 return null ;
21952208 }
21962209
@@ -2223,8 +2236,9 @@ public StartupCommand[] initialize() {
22232236
22242237 final StartupSecondaryStorageCommand cmd = new StartupSecondaryStorageCommand ();
22252238 fillNetworkInformation (cmd );
2226- if (_publicIp != null )
2239+ if (_publicIp != null ) {
22272240 cmd .setPublicIpAddress (_publicIp );
2241+ }
22282242
22292243 if (_inSystemVM ) {
22302244 Script command = new Script ("/bin/bash" , s_logger );
0 commit comments