diff --git a/clc/modules/cluster-manager/src/main/java/com/eucalyptus/compute/metadata/VmMetadata.java b/clc/modules/cluster-manager/src/main/java/com/eucalyptus/compute/metadata/VmMetadata.java index cafb6a6ce66..dc04bb9c83e 100644 --- a/clc/modules/cluster-manager/src/main/java/com/eucalyptus/compute/metadata/VmMetadata.java +++ b/clc/modules/cluster-manager/src/main/java/com/eucalyptus/compute/metadata/VmMetadata.java @@ -99,7 +99,7 @@ public class VmMetadata { private static// Logger LOG = Logger.getLogger( VmMetadata.class ); - + private static// Function dynamicFunc = new Function( ) { public ByteArray apply( MetadataRequest arg0 ) { @@ -146,7 +146,7 @@ public ByteArray apply( MetadataRequest arg0 ) { throw new NoSuchElementException( "Failed to lookup path: " + arg0.getLocalPath( ) ); } }; - + private static// ConcurrentMap> publicMetadataEndpoints = new ConcurrentSkipListMap>( ) { { @@ -166,11 +166,15 @@ public ByteArray apply( MetadataRequest arg0 ) { new Function( ) { public ByteArray apply( MetadataRequest arg0 ) { String listing = ""; - for ( String key : keySet( ) ) { + for ( String key : keySet( ) ) try { if ( !"".equals( key ) && get( key ).apply( arg0 ) != null ) { listing += key + "\n"; } + } catch ( final RuntimeException e ) { + if ( !Exceptions.isCausedBy( e, NoSuchElementException.class ) ) { + throw e; + } } listing = listing.replaceAll( "\n$", "" ); return ByteArray.newInstance( listing ); @@ -181,7 +185,7 @@ && get( key ).apply( arg0 ) != null ) { put( "meta-data", cache( metaDataFunc, VmInstances.VM_METADATA_INSTANCE_CACHE ) ); } }; - + private static// ConcurrentMap> // systemMetadataEndpoints = new ConcurrentSkipListMap>( ) { @@ -239,7 +243,10 @@ public Optional apply( final String requestIp ) { } - public byte[] handle( final String path ) { + /** + * @return byte[] for content or String for expected error + */ + public Object handle( final String path ) { final String[] parts = path.split( ":", 2 ); try { final String requestIpOrInstanceId = ResourceIdentifiers.tryNormalize( ).apply( parts[0] ); @@ -262,10 +269,8 @@ public byte[] handle( final String path ) { } else if ( publicMetadataEndpoints.containsKey( request.getMetadataName( ) ) ) { return publicMetadataEndpoints.get( request.getMetadataName( ) ).apply( request ).getBytes( ); } else { - throw new NoSuchElementException( "Metadata request failed: " + path ); + return "Metadata request failed: " + path; } - } catch ( NoSuchElementException ex ) { - throw ex; } catch ( Exception ex ) { NoSuchElementException noSuchElementException = Exceptions.findCause( ex, NoSuchElementException.class ); if ( noSuchElementException != null ) throw noSuchElementException; @@ -276,5 +281,5 @@ public byte[] handle( final String path ) { throw Exceptions.toUndeclared( ex ); } } - + }