Example usage for com.amazonaws.internal EC2MetadataClient EC2MetadataClient

List of usage examples for com.amazonaws.internal EC2MetadataClient EC2MetadataClient

Introduction

In this page you can find the example usage for com.amazonaws.internal EC2MetadataClient EC2MetadataClient.

Prototype

EC2MetadataClient

Source Link

Usage

From source file:awslabs.lab51.InstanceIdentity.java

License:Open Source License

public InstanceIdentity() {
    try {// ww w . j a  v a 2s . c  o m
        String instanceMetadata = new EC2MetadataClient()
                .readResource("/latest/dynamic/instance-identity/document");
        JSONObject jsonObject = new JSONObject(instanceMetadata);

        if (jsonObject.has("instanceId")) {
            instanceId = jsonObject.getString("instanceId");
        }
        if (jsonObject.has("version")) {
            version = jsonObject.getString("version");
        }
        if (jsonObject.has("region")) {
            region = jsonObject.getString("region");
        }
        if (jsonObject.has("accountId")) {
            accountId = jsonObject.getString("accountId");
        }
        if (jsonObject.has("imageId")) {
            imageId = jsonObject.getString("imageId");
        }
        if (jsonObject.has("kernelId")) {
            kernelId = jsonObject.getString("kernelId");
        }
        if (jsonObject.has("ramdiskId")) {
            ramdiskId = jsonObject.getString("ramdiskId");
        }
        if (jsonObject.has("architecture")) {
            architecture = jsonObject.getString("architecture");
        }
        if (jsonObject.has("pendingTime")) {
            pendingTime = jsonObject.getString("pendingTime");
        }
        if (jsonObject.has("availabilityZone")) {
            availabilityZone = jsonObject.getString("availabilityZone");
        }
        if (jsonObject.has("privateIp")) {
            privateIp = jsonObject.getString("privateIp");
        }
        if (jsonObject.has("instanceType")) {
            instanceType = jsonObject.getString("instanceType");
        }
    } catch (Exception ex) {
        // If we have an exception, just stop processing and use the default values.
    }

}

From source file:org.wallride.autoconfigure.WallRideCacheConfiguration.java

License:Apache License

@Bean
@Override//  ww  w  .  j  a v a2  s  .c o  m
public CacheManager cacheManager() {
    // JGroups settings
    String jgroupsConfigurationFile = environment.getRequiredProperty("jgroups.configurationFile");
    if ("jgroups-ec2.xml".equals(jgroupsConfigurationFile)) {
        ClassConfigurator.addProtocol((short) 1000, S3_CLIENT_PING.class);
        EC2MetadataClient metadataClient = new EC2MetadataClient();
        String ipAddress;
        try {
            ipAddress = metadataClient.readResource("/latest/meta-data/local-ipv4");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        logger.info("jgroups.tcp.address -> {}", ipAddress);
        System.setProperty("jgroups.tcp.address", ipAddress);
        System.setProperty("jgroups.s3.bucket", environment.getRequiredProperty("jgroups.s3.bucket"));
    }

    Resource hibernateSearchConfig = new ClassPathResource(
            DefaultCacheManagerService.DEFAULT_INFINISPAN_CONFIGURATION_RESOURCENAME);
    ParserRegistry parserRegistry = new ParserRegistry();
    ConfigurationBuilderHolder holder;
    try {
        holder = parserRegistry.parse(hibernateSearchConfig.getInputStream());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    // GlobalConfiguration
    // @formatter:off
    GlobalConfigurationBuilder globalBuilder = holder.getGlobalConfigurationBuilder();
    globalBuilder.globalJmxStatistics().allowDuplicateDomains(true).transport().defaultTransport()
            .addProperty("configurationFile", jgroupsConfigurationFile);
    // @formatter:on

    // DefaultConfiguration
    // @formatter:off
    for (ConfigurationBuilder luceneIndexesBuilder : holder.getNamedConfigurationBuilders().values()) {
        if ("mysql".equals(dataSourceProperties.getPlatform())) {
            luceneIndexesBuilder.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class)
                    .preload(true).shared(true).key2StringMapper(LuceneKey2StringMapper.class).table()
                    .tableNamePrefix("ispn_string_table").idColumnName("id_column").idColumnType("varchar(255)")
                    .dataColumnName("data_column").dataColumnType("longblob")
                    .timestampColumnName("timestamp_column").timestampColumnType("bigint").dropOnExit(false)
                    .createOnStart(true).async().enable().threadPoolSize(10).fetchPersistentState(true)
                    .ignoreModifications(false).purgeOnStartup(false)
                    .connectionFactory(InfinispanDataSourceConnectionFactoryConfigurationBuilder.class)
                    .dataSource(dataSource);
        } else if ("postgresql".equals(dataSourceProperties.getPlatform())) {
            luceneIndexesBuilder.persistence().addStore(JdbcStringBasedStoreConfigurationBuilder.class)
                    .preload(true).shared(true).key2StringMapper(LuceneKey2StringMapper.class).table()
                    .tableNamePrefix("ispn_string_table").idColumnName("id_column").idColumnType("varchar(255)")
                    .dataColumnName("data_column").dataColumnType("bytea")
                    .timestampColumnName("timestamp_column").timestampColumnType("bigint").dropOnExit(false)
                    .createOnStart(true).async().enable().threadPoolSize(10).fetchPersistentState(true)
                    .ignoreModifications(false).purgeOnStartup(false)
                    .connectionFactory(InfinispanDataSourceConnectionFactoryConfigurationBuilder.class)
                    .dataSource(dataSource);
        } else {
            throw new IllegalStateException();
        }
    }
    // @formatter:on

    // @formatter:off
    ConfigurationBuilder cacheBuilder = new ConfigurationBuilder();
    cacheBuilder.clustering().cacheMode(CacheMode.REPL_SYNC).eviction().type(EvictionType.COUNT)
            .strategy(EvictionStrategy.LIRS).size(1000);
    //            .indexing()
    //               .index(Index.NONE);
    // @formatter:on

    holder.getNamedConfigurationBuilders().put(BLOG_CACHE, cacheBuilder);
    //      holder.getNamedConfigurationBuilders().put("settings", cacheBuilder);
    holder.getNamedConfigurationBuilders().put(POPULAR_POST_CACHE, cacheBuilder);
    holder.getNamedConfigurationBuilders().put(ARTICLE_CACHE, cacheBuilder);
    holder.getNamedConfigurationBuilders().put(PAGE_CACHE, cacheBuilder);
    holder.getNamedConfigurationBuilders().put(CATEGORY_CACHE, cacheBuilder);
    holder.getNamedConfigurationBuilders().put(CUSTOM_FIELD_CACHE, cacheBuilder);
    holder.getNamedConfigurationBuilders().put(MEDIA_CACHE, cacheBuilder);
    holder.getNamedConfigurationBuilders().put(BANNER_CACHE, cacheBuilder);
    holder.getNamedConfigurationBuilders().put(USER_CACHE, cacheBuilder);

    EmbeddedCacheManager embeddedCacheManager = new DefaultCacheManager(holder, true);
    InfinispanSingletonCacheManagerDirectoryProvider.cacheManager = embeddedCacheManager;
    return new SpringEmbeddedCacheManager(embeddedCacheManager);
}