@@ -376,9 +376,10 @@ public boolean validateIfSeeded(TemplateDataStoreVO templDataStoreVO, String url
376376
377377 private static String getHypervisorArchKey (String hypervisorType , String arch ) {
378378 if (Hypervisor .HypervisorType .KVM .name ().equals (hypervisorType )) {
379- return String .format ("%s-%s" , hypervisorType , StringUtils .isBlank (arch ) ? CPU .archX86_64Identifier : arch );
379+ return String .format ("%s-%s" , hypervisorType .toLowerCase (),
380+ StringUtils .isBlank (arch ) ? CPU .archX86_64Identifier : arch );
380381 }
381- return hypervisorType ;
382+ return hypervisorType . toLowerCase () ;
382383 }
383384
384385 private static MetadataTemplateDetails getMetadataTemplateDetails (Hypervisor .HypervisorType hypervisorType , String arch ) {
@@ -744,25 +745,39 @@ public void registerTemplate(Hypervisor.HypervisorType hypervisor, String name,
744745 * exist a template corresponding to the current code version.
745746 */
746747 public static String parseMetadataFile () {
747- try {
748- Ini ini = new Ini ();
749- ini .load (new FileReader (METADATA_FILE ));
750- for (Pair <Hypervisor .HypervisorType , String > hypervisorType : hypervisorList ) {
751- String key = getHypervisorArchKey (hypervisorType .first ().name (), hypervisorType .second ());
752- Ini .Section section = ini .get (key );
753- NewTemplateMap .put (key , new MetadataTemplateDetails (hypervisorType .first (), section .get ("templatename" ),
754- section .get ("filename" ), section .get ("downloadurl" ), section .get ("checksum" ),
755- hypervisorType .second ()));
756- }
757- Ini .Section section = ini .get ("default" );
758- return section .get ("version" );
759- } catch (Exception e ) {
760- String errMsg = String .format ("Failed to parse systemVM template metadata file: %s" , METADATA_FILE );
748+ String errMsg = String .format ("Failed to parse systemVM template metadata file: %s" , METADATA_FILE );
749+ final Ini ini = new Ini ();
750+ try (FileReader reader = new FileReader (METADATA_FILE )) {
751+ ini .load (reader );
752+ } catch (IOException e ) {
761753 LOGGER .error (errMsg , e );
762754 throw new CloudRuntimeException (errMsg , e );
763755 }
756+ if (!ini .containsKey ("default" )) {
757+ errMsg = String .format ("%s as unable to default section" , errMsg );
758+ LOGGER .error (errMsg );
759+ throw new CloudRuntimeException (errMsg );
760+ }
761+ for (Pair <Hypervisor .HypervisorType , String > hypervisorType : hypervisorList ) {
762+ String key = getHypervisorArchKey (hypervisorType .first ().name (), hypervisorType .second ());
763+ Ini .Section section = ini .get (key );
764+ if (section == null ) {
765+ LOGGER .error ("Failed to find details for {} in template metadata file: {}" , key , METADATA_FILE );
766+ continue ;
767+ }
768+ NewTemplateMap .put (key , new MetadataTemplateDetails (
769+ hypervisorType .first (),
770+ section .get ("templatename" ),
771+ section .get ("filename" ),
772+ section .get ("downloadurl" ),
773+ section .get ("checksum" ),
774+ hypervisorType .second ()));
775+ }
776+ Ini .Section defaultSection = ini .get ("default" );
777+ return defaultSection .get ("version" );
764778 }
765779
780+
766781 private static void cleanupStore (Long templateId , String filePath ) {
767782 String destTempFolder = filePath + PARTIAL_TEMPLATE_FOLDER + String .valueOf (templateId );
768783 try {
0 commit comments