@Test void getProperty_knownAttribute_returnsAttributeValue() throws Exception { httpServer.createContext("/latest/meta-data/instance-id", new StringWritingHttpHandler("i1234567".getBytes("UTF-8"))); AmazonEc2InstanceDataPropertySource amazonEc2InstanceDataPropertySource = new AmazonEc2InstanceDataPropertySource( "test"); assertThat(amazonEc2InstanceDataPropertySource.getProperty("instance-id")) .isEqualTo("i1234567"); httpServer.removeContext("/latest/meta-data/instance-id"); }
@Override public Object getProperty(String name) { Map<String, String> userData = getUserData(); if (userData.containsKey(name)) { return userData.get(name); } if (!KNOWN_PROPERTY_NAMES.containsKey(getRootPropertyName(name))) { return null; } try { return EC2MetadataUtils.getData(EC2_METADATA_ROOT + "/" + name); } catch (AmazonClientException e) { LOGGER.warn( "Error getting instance meta-data with name '{}' error message is '{}'", name, e.getMessage()); return null; } }
AmazonEc2InstanceDataPropertySource extends EnumerablePropertySource<Object> { @Override public Object getProperty(String name) { Map<String, String> userData = getUserData(); if (userData.containsKey(name)) { return userData.get(name); } if (!KNOWN_PROPERTY_NAMES.containsKey(getRootPropertyName(name))) { return null; } try { return EC2MetadataUtils.getData(EC2_METADATA_ROOT + "/" + name); } catch (AmazonClientException e) { LOGGER.warn( "Error getting instance meta-data with name '{}' error message is '{}'", name, e.getMessage()); return null; } } }
AmazonEc2InstanceDataPropertySource extends EnumerablePropertySource<Object> { @Override public Object getProperty(String name) { Map<String, String> userData = getUserData(); if (userData.containsKey(name)) { return userData.get(name); } if (!KNOWN_PROPERTY_NAMES.containsKey(getRootPropertyName(name))) { return null; } try { return EC2MetadataUtils.getData(EC2_METADATA_ROOT + "/" + name); } catch (AmazonClientException e) { LOGGER.warn( "Error getting instance meta-data with name '{}' error message is '{}'", name, e.getMessage()); return null; } } AmazonEc2InstanceDataPropertySource(String name); }
AmazonEc2InstanceDataPropertySource extends EnumerablePropertySource<Object> { @Override public Object getProperty(String name) { Map<String, String> userData = getUserData(); if (userData.containsKey(name)) { return userData.get(name); } if (!KNOWN_PROPERTY_NAMES.containsKey(getRootPropertyName(name))) { return null; } try { return EC2MetadataUtils.getData(EC2_METADATA_ROOT + "/" + name); } catch (AmazonClientException e) { LOGGER.warn( "Error getting instance meta-data with name '{}' error message is '{}'", name, e.getMessage()); return null; } } AmazonEc2InstanceDataPropertySource(String name); void setUserDataAttributeSeparator(String userDataAttributeSeparator); void setUserDataValueSeparator(String userDataValueSeparator); @Override Object getProperty(String name); @Override String[] getPropertyNames(); }
AmazonEc2InstanceDataPropertySource extends EnumerablePropertySource<Object> { @Override public Object getProperty(String name) { Map<String, String> userData = getUserData(); if (userData.containsKey(name)) { return userData.get(name); } if (!KNOWN_PROPERTY_NAMES.containsKey(getRootPropertyName(name))) { return null; } try { return EC2MetadataUtils.getData(EC2_METADATA_ROOT + "/" + name); } catch (AmazonClientException e) { LOGGER.warn( "Error getting instance meta-data with name '{}' error message is '{}'", name, e.getMessage()); return null; } } AmazonEc2InstanceDataPropertySource(String name); void setUserDataAttributeSeparator(String userDataAttributeSeparator); void setUserDataValueSeparator(String userDataValueSeparator); @Override Object getProperty(String name); @Override String[] getPropertyNames();  }