com.amazonaws.services.elasticache.model.CacheCluster Java Examples
The following examples show how to use
com.amazonaws.services.elasticache.model.CacheCluster.
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 |
@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 |
@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: ElastiCacheUtil.java From pacbot with Apache License 2.0 | 5 votes |
private static List<ElastiCacheNodeVH> getNodeDetails(Map<String,List<CacheCluster>> cacheClusterMap,Map<String,ReplicationGroup> replGroupMap ,String accountId, String arnTemplate, Region region, AmazonElastiCache amazonElastiCache, ElastiCacheVH cacheVH) { List<ElastiCacheNodeVH> nodeDetails = new ArrayList<>(); String clusterName = cacheVH.getClusterName(); String engine = cacheVH.getCluster().getEngine(); List<CacheCluster> cacheClusters = cacheClusterMap.get(clusterName); cacheClusters.forEach(cacheCluster -> { String clusterId = cacheCluster.getCacheClusterId(); List<CacheNode> nodes = cacheCluster.getCacheNodes(); if(!nodes.isEmpty()){ for(CacheNode node : nodes){ ElastiCacheNodeVH nodeVH = new ElastiCacheNodeVH(); nodeVH.setNode(node); if("memcached".equalsIgnoreCase(engine)){ nodeVH.setNodeName(node.getCacheNodeId()); }else{ nodeVH.setNodeName(cacheCluster.getCacheClusterId()); try { List<Tag> tags = amazonElastiCache.listTagsForResource(new com.amazonaws.services.elasticache.model.ListTagsForResourceRequest(). withResourceName(String.format(arnTemplate, region.getName(),accountId,clusterId))).getTagList(); nodeVH.setTags(tags.stream().map(tag->tag.getKey()+":"+tag.getValue()).collect(Collectors.joining(","))); } catch (Exception e) { } } nodeDetails.add(nodeVH); } } }); return nodeDetails; }
Example #4
Source File: ElastiCacheFactoryBean.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
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 #5
Source File: ElastiCacheFactoryBean.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@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 #6
Source File: ElastiCacheFactoryBeanTest.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@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 #7
Source File: AWSDatabase.java From billow with Apache License 2.0 | 5 votes |
private String elasticacheARN(String partition, String regionName, String accountNumber, CacheCluster cacheCluster) { return String.format( "arn:%s:elasticache:%s:%s:cluster:%s", partition, regionName, accountNumber, cacheCluster.getCacheClusterId() ); }
Example #8
Source File: ElasticacheCluster.java From billow with Apache License 2.0 | 5 votes |
public ElasticacheCluster(CacheCluster cacheCluster, NodeGroupMember nodeGroupMember, List<Tag> tagList) { this.cacheClusterId = cacheCluster.getCacheClusterId(); this.clientDownloadLandingPage = cacheCluster.getClientDownloadLandingPage(); this.cacheNodeType = cacheCluster.getCacheNodeType(); this.engine = cacheCluster.getEngine(); this.engineVersion = cacheCluster.getEngineVersion(); this.cacheClusterStatus = cacheCluster.getCacheClusterStatus(); this.numCacheNodes = cacheCluster.getNumCacheNodes(); this.preferredAvailabilityZone = cacheCluster.getPreferredAvailabilityZone(); this.cacheClusterCreateTime = cacheCluster.getCacheClusterCreateTime(); this.preferredMaintenanceWindow = cacheCluster.getPreferredMaintenanceWindow(); this.pendingModifiedValues = cacheCluster.getPendingModifiedValues().toString(); if (cacheCluster.getNotificationConfiguration() != null) { this.notificationConfiguration = cacheCluster.getNotificationConfiguration().toString(); } else { this.notificationConfiguration = "empty"; } this.cacheSecurityGroups = cacheCluster.getSecurityGroups().toString(); this.cacheParameterGroup = cacheCluster.getCacheParameterGroup().toString(); this.cacheSubnetGroupName = cacheCluster.getCacheSubnetGroupName(); this.cacheNodes = cacheCluster.getCacheNodes().toString(); this.autoMinorVersionUpgrade = cacheCluster.getAutoMinorVersionUpgrade(); this.securityGroups = cacheCluster.getSecurityGroups().toString(); this.replicationGroupId = cacheCluster.getReplicationGroupId(); this.snapshotRetentionLimit = cacheCluster.getSnapshotRetentionLimit(); this.snapshotWindow = cacheCluster.getSnapshotWindow(); if (nodeGroupMember != null) { this.endpoint = nodeGroupMember.getReadEndpoint(); this.currentRole = nodeGroupMember.getCurrentRole(); } else { this.endpoint = cacheCluster.getConfigurationEndpoint(); this.currentRole = null; } this.tags = new HashMap<>(tagList.size()); for(Tag tag : tagList) { this.tags.put(tag.getKey(), tag.getValue()); } }
Example #9
Source File: ElastiCacheUtil.java From pacbot with Apache License 2.0 | 4 votes |
/** * Fetch elasti cache info. * * @param temporaryCredentials the temporary credentials * @param skipRegions the skip regions * @param accountId the accountId * @return the map */ public static Map<String,List<ElastiCacheVH>> fetchElastiCacheInfo(BasicSessionCredentials temporaryCredentials, String skipRegions,String accountId,String accountName) { Map<String,List<ElastiCacheVH>> elastiCache = new LinkedHashMap<>(); String expPrefix = InventoryConstants.ERROR_PREFIX_CODE+accountId + "\",\"Message\": \"Exception in fetching info for resource \" ,\"type\": \"ElastiCache\"" ; String arnTemplate = "arn:aws:elasticache:%s:%s:cluster:%s"; for(Region region : RegionUtils.getRegions()) { try{ if(!skipRegions.contains(region.getName())){ List<CacheCluster> cacheClusterList = new ArrayList<>(); AmazonElastiCache amazonElastiCache = AmazonElastiCacheClientBuilder.standard().withCredentials(new AWSStaticCredentialsProvider(temporaryCredentials)).withRegion(region.getName()).build(); String marker = null; DescribeCacheClustersResult describeResult ; DescribeCacheClustersRequest rqst; do{ rqst =new DescribeCacheClustersRequest().withMarker(marker); rqst.setShowCacheNodeInfo(true); describeResult = amazonElastiCache.describeCacheClusters(rqst); cacheClusterList.addAll(describeResult.getCacheClusters()); marker = describeResult.getMarker(); }while(marker!=null); List<ReplicationGroup> replicationGroupList = new ArrayList<>(); marker = null; DescribeReplicationGroupsResult describeRGResult ; DescribeReplicationGroupsRequest rgRqst; do{ rgRqst = new DescribeReplicationGroupsRequest().withMarker(marker); describeRGResult = amazonElastiCache.describeReplicationGroups(rgRqst); replicationGroupList.addAll(describeRGResult.getReplicationGroups()); marker = describeResult.getMarker(); }while(marker!=null); Map<String,List<CacheCluster>> cacheMap = cacheClusterList.stream().collect(Collectors.groupingBy(cluster-> cluster.getReplicationGroupId()!=null?cluster.getReplicationGroupId():cluster.getCacheClusterId())); Map<String,ReplicationGroup> replGrpMap = replicationGroupList.stream().collect(Collectors.toMap(rplGrp -> rplGrp.getReplicationGroupId(),rplGrp->rplGrp)); List<ElastiCacheVH> elasticacheList = populateVH(cacheMap,replGrpMap); String engine; String arn ; for(ElastiCacheVH cacheVH :elasticacheList){ engine = cacheVH.getCluster().getEngine(); arn = String.format(arnTemplate, region.getName(),accountId,cacheVH.getCluster().getCacheClusterId()); cacheVH.setArn(String.format(arnTemplate, region.getName(),accountId,cacheVH.getClusterName())); if("memcached".equalsIgnoreCase(engine)){ cacheVH.setTags(amazonElastiCache.listTagsForResource(new com.amazonaws.services.elasticache.model.ListTagsForResourceRequest(). withResourceName(arn)).getTagList()); } List<CacheSubnetGroup> subnetGroups = amazonElastiCache.describeCacheSubnetGroups( new DescribeCacheSubnetGroupsRequest().withCacheSubnetGroupName(cacheVH.getCluster().getCacheSubnetGroupName())).getCacheSubnetGroups(); subnetGroups.forEach(cacheGroup-> { cacheVH.setVpc(cacheGroup.getVpcId()); cacheVH.setSubnets(cacheGroup.getSubnets().stream().map(Subnet::getSubnetIdentifier).collect(Collectors.toList())); }); List<ElastiCacheNodeVH> nodeDetails = getNodeDetails(cacheMap,replGrpMap,accountId, arnTemplate, region, amazonElastiCache, cacheVH); cacheVH.setNodes(nodeDetails); } if(!elasticacheList.isEmpty()) { log.debug(InventoryConstants.ACCOUNT + accountId +" Type : ElastiCache "+region.getName() + " >> "+elasticacheList.size()); elastiCache.put(accountId+delimiter+accountName+delimiter+region.getName(), elasticacheList); } } }catch(Exception e){ log.warn(expPrefix+ region.getName()+InventoryConstants.ERROR_CAUSE +e.getMessage()+"\"}"); ErrorManageUtil.uploadError(accountId,"","elastiCache",e.getMessage()); } } return elastiCache; }
Example #10
Source File: ElastiCacheUtil.java From pacbot with Apache License 2.0 | 4 votes |
/** * 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; }
Example #11
Source File: ElastiCacheVH.java From pacbot with Apache License 2.0 | 2 votes |
/** * Gets the cluster. * * @return the cluster */ public CacheCluster getCluster() { return cluster; }
Example #12
Source File: ElastiCacheVH.java From pacbot with Apache License 2.0 | 2 votes |
/** * Sets the cluster. * * @param cluster the new cluster */ public void setCluster(CacheCluster cluster) { this.cluster = cluster; }