com.amazonaws.services.elasticache.model.Endpoint Java Examples

The following examples show how to use com.amazonaws.services.elasticache.model.Endpoint. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ElastiCacheFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void getObject_availableCluster_returnsConfiguredMemcachedClient() throws Exception {
	// Arrange
	AmazonElastiCache amazonElastiCache = mock(AmazonElastiCacheClient.class);

	DescribeCacheClustersRequest testCache = new DescribeCacheClustersRequest()
			.withCacheClusterId("testCache");
	testCache.setShowCacheNodeInfo(true);

	when(amazonElastiCache.describeCacheClusters(testCache)).thenReturn(
			new DescribeCacheClustersResult().withCacheClusters(new CacheCluster()
					.withConfigurationEndpoint(
							new Endpoint().withAddress("localhost").withPort(45678))
					.withCacheClusterStatus("available").withEngine("memcached")));
	ElastiCacheFactoryBean elasticCacheFactoryBean = new ElastiCacheFactoryBean(
			amazonElastiCache, "testCache", Collections.singletonList(
					new TestCacheFactory("testCache", "localhost", 45678)));

	// Act
	elasticCacheFactoryBean.afterPropertiesSet();
	Cache cache = elasticCacheFactoryBean.getObject();

	// Assert
	assertThat(cache).isNotNull();
}
 
Example #2
Source File: ElastiCacheFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 6 votes vote down vote up
@Test
void getObject_clusterWithRedisEngineConfigured_reportsError() throws Exception {
	// Arrange
	AmazonElastiCache amazonElastiCache = mock(AmazonElastiCacheClient.class);
	DescribeCacheClustersRequest memcached = new DescribeCacheClustersRequest()
			.withCacheClusterId("memcached");
	memcached.setShowCacheNodeInfo(true);

	when(amazonElastiCache.describeCacheClusters(memcached))
			.thenReturn(new DescribeCacheClustersResult().withCacheClusters(
					new CacheCluster().withEngine("redis").withCacheNodes(
							new CacheNode().withEndpoint(new Endpoint()
									.withAddress("localhost").withPort(45678)))));

	ElastiCacheFactoryBean elastiCacheFactoryBean = new ElastiCacheFactoryBean(
			amazonElastiCache, "memcached", Collections.singletonList(
					new TestCacheFactory("testCache", "localhost", 45678)));

	// Assert
	assertThatThrownBy(elastiCacheFactoryBean::afterPropertiesSet)
			.isInstanceOf(IllegalArgumentException.class)
			.hasMessageContaining("engine");
}
 
Example #3
Source File: ElastiCacheFactoryBean.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
private static Endpoint getEndpointForCache(CacheCluster cacheCluster) {
	if (cacheCluster.getConfigurationEndpoint() != null) {
		return cacheCluster.getConfigurationEndpoint();
	}

	if (!cacheCluster.getCacheNodes().isEmpty()) {
		return cacheCluster.getCacheNodes().get(0).getEndpoint();
	}

	throw new IllegalArgumentException(
			"No Configuration Endpoint or Cache Node available to "
					+ "receive address information for cluster:'"
					+ cacheCluster.getCacheClusterId() + "'");
}
 
Example #4
Source File: ElastiCacheFactoryBean.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@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(
				"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());
}
 
Example #5
Source File: ElastiCacheFactoryBeanTest.java    From spring-cloud-aws with Apache License 2.0 5 votes vote down vote up
@Test
void getObject_availableClusterWithLogicalName_returnsConfigurationMemcachedClientWithPhysicalName()
		throws Exception {
	// Arrange
	AmazonElastiCache amazonElastiCache = mock(AmazonElastiCacheClient.class);
	DescribeCacheClustersRequest testCache = new DescribeCacheClustersRequest()
			.withCacheClusterId("testCache");
	testCache.setShowCacheNodeInfo(true);

	when(amazonElastiCache.describeCacheClusters(testCache)).thenReturn(
			new DescribeCacheClustersResult().withCacheClusters(new CacheCluster()
					.withConfigurationEndpoint(
							new Endpoint().withAddress("localhost").withPort(45678))
					.withCacheClusterStatus("available").withEngine("memcached")));

	ResourceIdResolver resourceIdResolver = mock(ResourceIdResolver.class);
	when(resourceIdResolver.resolveToPhysicalResourceId("test"))
			.thenReturn("testCache");

	ElastiCacheFactoryBean elastiCacheFactoryBean = new ElastiCacheFactoryBean(
			amazonElastiCache, "test", resourceIdResolver,
			Collections.<CacheFactory>singletonList(
					new TestCacheFactory("test", "localhost", 45678)));

	// Act
	elastiCacheFactoryBean.afterPropertiesSet();
	Cache cache = elastiCacheFactoryBean.getObject();

	// Assert
	assertThat(cache).isNotNull();
}
 
Example #6
Source File: ElastiCacheUtil.java    From pacbot with Apache License 2.0 4 votes vote down vote up
/**
 * Populate VH.
 *
 * @param cacheClusterList the cache cluster list
 * @param replicationGroupList the replication group list
 * @return the list
 */
private static List<ElastiCacheVH> populateVH(Map<String,List<CacheCluster>> cacheMap,Map<String,ReplicationGroup> replGrpMap  ){
    
    List<ElastiCacheVH> elasticacheList = new ArrayList<>();
    
    cacheMap.forEach((k,v)->{
        String clusterName = k;
        ElastiCacheVH elastiCacheVH = new ElastiCacheVH();
        elastiCacheVH.setClusterName(clusterName);
        elastiCacheVH.setAvailabilityZones(v.stream().map(CacheCluster::getPreferredAvailabilityZone).collect(Collectors.toSet()).stream().collect(Collectors.joining(",")));
        
        CacheCluster cluster = v.get(0);
        elastiCacheVH.setSecurityGroups(cluster.getSecurityGroups().stream().map(sg -> sg.getSecurityGroupId()+"("+sg.getStatus()+")").collect(Collectors.joining(",")));
        elastiCacheVH.setParameterGroup(cluster.getCacheParameterGroup().getCacheParameterGroupName()+"("+cluster.getCacheParameterGroup().getParameterApplyStatus()+")");
        elastiCacheVH.setCluster(cluster);
        String engine = cluster.getEngine();
          	
        if("memcached".equalsIgnoreCase(engine)){
            elastiCacheVH.setNoOfNodes(cluster.getNumCacheNodes());
            elastiCacheVH.setPrimaryOrConfigEndpoint(cluster.getConfigurationEndpoint().getAddress()+":"+cluster.getConfigurationEndpoint().getPort());
        }else{
            ReplicationGroup rplGrp = replGrpMap.get(clusterName);
            Endpoint endPoint ;
            if(rplGrp!=null){
                elastiCacheVH.setDescription(rplGrp.getDescription());
                elastiCacheVH.setNoOfNodes(rplGrp.getMemberClusters().size());
                endPoint = rplGrp.getConfigurationEndpoint();
                if(endPoint==null){
                    endPoint = rplGrp.getNodeGroups().stream().filter(obj->obj.getPrimaryEndpoint()!=null).map(obj-> obj.getPrimaryEndpoint()).findAny().get();
                }
            }else{
                elastiCacheVH.setNoOfNodes(cluster.getNumCacheNodes());
                endPoint = cluster.getCacheNodes().stream().map(CacheNode::getEndpoint).findAny().get();
                
            }
            elastiCacheVH.setPrimaryOrConfigEndpoint(endPoint.getAddress().replaceAll(cluster.getCacheClusterId(), clusterName)+":"+endPoint.getPort());
        }
        
        elasticacheList.add(elastiCacheVH);
        
    });
    return elasticacheList;
}