Example usage for com.amazonaws.services.elasticache.model DescribeCacheClustersRequest DescribeCacheClustersRequest

List of usage examples for com.amazonaws.services.elasticache.model DescribeCacheClustersRequest DescribeCacheClustersRequest

Introduction

In this page you can find the example usage for com.amazonaws.services.elasticache.model DescribeCacheClustersRequest DescribeCacheClustersRequest.

Prototype

DescribeCacheClustersRequest

Source Link

Usage

From source file:it.polimi.modaclouds.cpimlibrary.memcache.AmazonMemcache.java

License:Apache License

private void start(String memcacheAddr) {
    AWSCredentials credentials = null;// w  w w.  ja  v  a  2  s. c o m
    try {
        credentials = new PropertiesCredentials(
                getClass().getClassLoader().getResourceAsStream("AwsCredentials.properties"));
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    ec = new AmazonElastiCacheClient(credentials);
    DescribeCacheClustersRequest describe_req = new DescribeCacheClustersRequest();
    describe_req.setShowCacheNodeInfo(true);
    DescribeCacheClustersResult describe_res = ec.describeCacheClusters(describe_req);
    List<CacheCluster> clusters = describe_res.getCacheClusters();
    for (CacheCluster c : clusters) {
        Endpoint conf_end = c.getConfigurationEndpoint();
        String addr = conf_end.getAddress() + ":" + conf_end.getPort();
        if (addr.equals(memcacheAddr)) {
            cluster = c;
            break;
        }
    }
    //setting security groups
    // List<String> sec_groups_names = new ArrayList<String>();
    // List<CacheSecurityGroup> res = ec.describeCacheSecurityGroups().getCacheSecurityGroups();
    // for(int i = 0; i < res.size(); i++) {
    //    if(res.get(i).getDescription().contains("Cloud Platform Independent Model"))
    //       sec_groups_names.add(res.get(i).getCacheSecurityGroupName());
    // }
    // ModifyCacheClusterRequest req = new ModifyCacheClusterRequest(cluster.getCacheClusterId());
    // req.setCacheSecurityGroupNames(sec_groups_names);
    // req.setApplyImmediately(true);
    // ec.modifyCacheCluster(req);
    //creation of memcached client
    List<InetSocketAddress> addrs = new ArrayList<InetSocketAddress>();
    if (cluster != null && cluster.getCacheNodes() != null) {
        for (CacheNode node : cluster.getCacheNodes()) {
            if (node != null) {
                Endpoint endpoint = node.getEndpoint();
                if (endpoint != null && endpoint.getAddress() != null) {
                    addrs.add(new InetSocketAddress(endpoint.getAddress(), endpoint.getPort()));
                }
            }
        }
    }
    if (addrs.size() > 0) {
        try {
            System.out.println("Creation of memCacheClient.");
            memCache = new MemcachedClient(addrs);
            System.out.println("memCacheClient created.");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    } else
        System.out.println("No available nodes.");
}

From source file:org.springframework.cloud.aws.cache.ElastiCacheFactoryBean.java

License:Apache License

@Override
protected Cache createInstance() throws Exception {
    DescribeCacheClustersRequest describeCacheClustersRequest = new DescribeCacheClustersRequest()
            .withCacheClusterId(getCacheClusterName());
    describeCacheClustersRequest.setShowCacheNodeInfo(true);

    DescribeCacheClustersResult describeCacheClustersResult = this.amazonElastiCache
            .describeCacheClusters(describeCacheClustersRequest);

    CacheCluster cacheCluster = describeCacheClustersResult.getCacheClusters().get(0);
    if (!"available".equals(cacheCluster.getCacheClusterStatus())) {
        LOGGER.warn(/*from   www.j ava  2s. c o  m*/
                "Cache cluster is not available now. Connection may fail during cache access. Current status is {}",
                cacheCluster.getCacheClusterStatus());
    }

    Endpoint configurationEndpoint = getEndpointForCache(cacheCluster);

    for (CacheFactory cacheFactory : this.cacheFactories) {
        if (cacheFactory.isSupportingCacheArchitecture(cacheCluster.getEngine())) {
            return cacheFactory.createCache(this.cacheClusterId, configurationEndpoint.getAddress(),
                    configurationEndpoint.getPort());
        }
    }

    throw new IllegalArgumentException("No CacheFactory configured for engine: " + cacheCluster.getEngine());
}

From source file:org.springframework.cloud.aws.cache.ElastiCacheMemcachedFactoryBean.java

License:Apache License

@Override
protected MemcachedClient createInstance() throws Exception {
    DescribeCacheClustersResult describeCacheClustersResult = this.amazonElastiCache.describeCacheClusters(
            new DescribeCacheClustersRequest().withCacheClusterId(getCacheClusterName()));

    CacheCluster cacheCluster = describeCacheClustersResult.getCacheClusters().get(0);
    if (!"available".equals(cacheCluster.getCacheClusterStatus())) {
        LOGGER.warn(/*from ww  w.j  a v a2s.  co  m*/
                "Cache cluster is not available now. Connection may fail during cache access. Current status is {}",
                cacheCluster.getCacheClusterStatus());
    }

    if (!"memcached".equals(cacheCluster.getEngine())) {
        throw new IllegalStateException("Currently only memcached is supported as the cache cluster engine");
    }

    Endpoint configurationEndpoint = cacheCluster.getConfigurationEndpoint();

    // We return every time one configuration endpoint. The amazon memcached client will connect to all nodes.
    return new MemcachedClient(
            new InetSocketAddress(configurationEndpoint.getAddress(), configurationEndpoint.getPort()));
}