com.amazonaws.services.elasticsearch.model.ElasticsearchDomainStatus Java Examples
The following examples show how to use
com.amazonaws.services.elasticsearch.model.ElasticsearchDomainStatus.
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: ElasticsearchDomainMapProvider.java From aws-athena-query-federation with Apache License 2.0 | 6 votes |
/** * Gets the domainMap with domain-names and corresponding endpoints retrieved from the AWS ES SDK. * @param domainStatusList is a list of status objects returned by a listDomainNames request to the AWS ES SDK. * @return populated domainMap with domain-names and corresponding endpoints. * @throws RuntimeException when Amazon ES contains no domain information for user. */ private Map<String, String> getDomainMap(List<ElasticsearchDomainStatus> domainStatusList) throws RuntimeException { Map<String, String> domainMap = new HashMap<>(); for (ElasticsearchDomainStatus domainStatus : domainStatusList) { domainMap.put(domainStatus.getDomainName(), endpointPrefix + domainStatus.getEndpoint()); } if (domainMap.isEmpty()) { throw new RuntimeException("Amazon Elasticsearch Service has no domain information for user."); } return domainMap; }
Example #2
Source File: ElasticsearchCluster.java From billow with Apache License 2.0 | 6 votes |
public ElasticsearchCluster(ElasticsearchDomainStatus domainStatus, List<Tag> tagList) { this.domainName = domainStatus.getDomainName(); this.tags = new HashMap<>(tagList.size()); for(Tag tag : tagList) { this.tags.put(tag.getKey(), tag.getValue()); } this.version = domainStatus.getElasticsearchVersion(); this.endpoints = domainStatus.getEndpoints(); ElasticsearchClusterConfig esConfig = domainStatus.getElasticsearchClusterConfig(); this.instanceType = esConfig.getInstanceType(); this.instanceCount = esConfig.getInstanceCount(); this.dedicatedMasterEnabled = esConfig.getDedicatedMasterEnabled(); this.zoneAwarenessEnabled = esConfig.getZoneAwarenessEnabled(); this.dedicatedMasterType = esConfig.getDedicatedMasterType(); this.dedicatedMasterCount = esConfig.getDedicatedMasterCount(); }
Example #3
Source File: PublicAccessAutoFix.java From pacbot with Apache License 2.0 | 5 votes |
/** * Gets the domain status for es resource. * * @param clientMap the client map * @param resourceId the resource id * @return the domain status for es resource * @throws Exception the exception */ public static ElasticsearchDomainStatus getDomainStatusForEsResource(Map<String,Object> clientMap,String resourceId) throws Exception { AWSElasticsearch awsElasticsearch =(AWSElasticsearch) clientMap.get("client"); DescribeElasticsearchDomainRequest request = new DescribeElasticsearchDomainRequest(); request.setDomainName(resourceId); DescribeElasticsearchDomainResult result = awsElasticsearch.describeElasticsearchDomain(request); return result.getDomainStatus(); }
Example #4
Source File: ElasticSearchPublicAccessAutoFix.java From pacbot with Apache License 2.0 | 5 votes |
@Override public boolean backupExistingConfigForResource(final String resourceId, final String resourceType, Map<String, Object> clientMap, Map<String, String> ruleParams, Map<String, String> issue)throws AutoFixException { beforeAutoFixSg = null; try { String accessPolicies = null; Gson serializer = new GsonBuilder().create(); String rId = issue.get("resourceDisplayId"); ElasticsearchDomainStatus domainStatus = PublicAccessAutoFix.getDomainStatusForEsResource(clientMap,rId); String endPoint = domainStatus.getEndpoint(); if (!StringUtils.isEmpty(endPoint)) { accessPolicies = domainStatus.getAccessPolicies(); JsonObject accessPoliciesJson = serializer.fromJson(accessPolicies, JsonObject.class); backupOldConfig(resourceId, EXISTING_POLICY, accessPoliciesJson.toString()); }else{ List<String> originalSgMembers; Set<String> oldConfigSet = new HashSet<>(); VPCDerivedInfo vpcDerivedInfo = domainStatus.getVPCOptions(); originalSgMembers = vpcDerivedInfo.getSecurityGroupIds(); oldConfigSet.addAll(originalSgMembers); beforeAutoFixSg = oldConfigSet.toString(); backupOldConfig(resourceId, EXISTING_GROUPS, oldConfigSet.toString()); } }catch (Exception e) { LOGGER.error("back up failed", e); throw new AutoFixException("backup failed"); } LOGGER.debug("backup complete for {}" , resourceId); return true; }
Example #5
Source File: CommonTestUtils.java From pacbot with Apache License 2.0 | 5 votes |
public static ElasticsearchDomainStatus getElasticsearchDomainStatus(){ ElasticsearchDomainStatus elasticsearchDomainStatus = new ElasticsearchDomainStatus(); elasticsearchDomainStatus.setDomainId("123"); elasticsearchDomainStatus.setAccessPolicies("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"es:*\",\"Resource\":\"123\"}]}"); elasticsearchDomainStatus.setEndpoint("123"); return elasticsearchDomainStatus; }
Example #6
Source File: CommonTestUtils.java From pacbot with Apache License 2.0 | 5 votes |
public static ElasticsearchDomainStatus getWithoutEndPOintElasticsearchDomainStatus(){ VPCDerivedInfo vPCOptions = new VPCDerivedInfo(); vPCOptions.setSecurityGroupIds(Arrays.asList("123")); ElasticsearchDomainStatus elasticsearchDomainStatus = new ElasticsearchDomainStatus(); elasticsearchDomainStatus.setDomainId("123"); elasticsearchDomainStatus.setAccessPolicies("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"es:*\",\"Resource\":\"123\"}]}"); elasticsearchDomainStatus.setVPCOptions(vPCOptions); return elasticsearchDomainStatus; }
Example #7
Source File: ESInventoryUtilTest.java From pacbot with Apache License 2.0 | 5 votes |
/** * Fetch ES info test. * * @throws Exception the exception */ @SuppressWarnings("static-access") @Test public void fetchESInfoTest() throws Exception { mockStatic(AWSElasticsearchClientBuilder.class); AWSElasticsearch awsEsClient = PowerMockito.mock(AWSElasticsearch.class); AWSElasticsearchClientBuilder awsElasticsearchClientBuilder = PowerMockito.mock(AWSElasticsearchClientBuilder.class); AWSStaticCredentialsProvider awsStaticCredentialsProvider = PowerMockito.mock(AWSStaticCredentialsProvider.class); PowerMockito.whenNew(AWSStaticCredentialsProvider.class).withAnyArguments().thenReturn(awsStaticCredentialsProvider); when(awsElasticsearchClientBuilder.standard()).thenReturn(awsElasticsearchClientBuilder); when(awsElasticsearchClientBuilder.withCredentials(anyObject())).thenReturn(awsElasticsearchClientBuilder); when(awsElasticsearchClientBuilder.withRegion(anyString())).thenReturn(awsElasticsearchClientBuilder); when(awsElasticsearchClientBuilder.build()).thenReturn(awsEsClient); ListDomainNamesResult listDomainResult = new ListDomainNamesResult(); List<DomainInfo> domainNames = new ArrayList<>(); DomainInfo domainInfo = new DomainInfo(); domainInfo.setDomainName("domain"); domainNames.add(domainInfo); listDomainResult.setDomainNames(domainNames); when(awsEsClient.listDomainNames(anyObject())).thenReturn(listDomainResult); DescribeElasticsearchDomainsResult describeResult = new DescribeElasticsearchDomainsResult() ; List<ElasticsearchDomainStatus> domainStatusList = new ArrayList<>(); ElasticsearchDomainStatus domainStatus = new ElasticsearchDomainStatus(); domainStatus.setARN("arn"); domainStatusList.add(domainStatus); describeResult.setDomainStatusList(domainStatusList); when(awsEsClient.describeElasticsearchDomains(anyObject())).thenReturn(describeResult); ListTagsResult listTagsResult = new ListTagsResult(); listTagsResult.setTagList(new ArrayList<Tag>()); when(awsEsClient.listTags(anyObject())).thenReturn(listTagsResult); assertThat(esInventoryUtil.fetchESInfo(new BasicSessionCredentials("awsAccessKey", "awsSecretKey", "sessionToken"), "skipRegions", "account","accountName").size(), is(1)); }
Example #8
Source File: ElasticSearchPublicAccessAutoFixTest.java From pacbot with Apache License 2.0 | 4 votes |
@Test public void executeFixTest()throws Exception{ ElasticsearchDomainStatus emptyDomainStatus = new ElasticsearchDomainStatus(); emptyDomainStatus.setDomainId("123"); emptyDomainStatus.setAccessPolicies("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"es:*\",\"Resource\":\"123\"}]}"); DescribeElasticsearchDomainResult domainResult = new DescribeElasticsearchDomainResult(); domainResult.setDomainStatus(CommonTestUtils.getElasticsearchDomainStatus()); DescribeElasticsearchDomainResult emptyDdomainResult = new DescribeElasticsearchDomainResult(); emptyDdomainResult.setDomainStatus(CommonTestUtils.getElasticsearchDomainStatus()); mockStatic(PublicAccessAutoFix.class); Map<String,Object> ec2Map=new HashMap<String, Object>(); ec2Map.put("client", amazonEC2); when(PublicAccessAutoFix.getAWSClient(anyString(),anyObject(),anyString())).thenReturn(ec2Map); Map<String,Object> elasticSearch=new HashMap<String, Object>(); elasticSearch.put("client", elasticsearch); ElasticSearchPublicAccessAutoFix spy = Mockito.spy(new ElasticSearchPublicAccessAutoFix()); Mockito.doReturn(elasticSearch).when((BaseFix)spy).getClientFor(anyObject(), anyString(), anyObject()); when(PublicAccessAutoFix.getDomainStatusForEsResource(anyObject(),anyObject())).thenReturn(CommonTestUtils.getElasticsearchDomainStatus()); when(elasticsearch.describeElasticsearchDomain(anyObject())).thenReturn(domainResult); when(PublicAccessAutoFix.isEsHavingPublicAccess(anyObject(),anyString())).thenReturn(true); spy.executeFix(CommonTestUtils.getMapString("r_123 "), elasticSearch, CommonTestUtils.getMapString("r_123 ")); VPCDerivedInfo vPCOptions = new VPCDerivedInfo(); vPCOptions.setSecurityGroupIds(Arrays.asList("123")); ElasticsearchDomainStatus domainStatusEmpty = new ElasticsearchDomainStatus(); domainStatusEmpty.setDomainId("123"); domainStatusEmpty.setVPCOptions(vPCOptions); domainStatusEmpty.setAccessPolicies("{\"Version\":\"2012-10-17\",\"Statement\":[{\"Effect\":\"Allow\",\"Principal\":{\"AWS\":\"*\"},\"Action\":\"es:*\",\"Resource\":\"123\"}]}"); DescribeElasticsearchDomainResult domainEmptyResult = new DescribeElasticsearchDomainResult(); domainEmptyResult.setDomainStatus(domainStatusEmpty); when(PublicAccessAutoFix.getDomainStatusForEsResource(anyObject(),anyObject())).thenReturn(CommonTestUtils.getWithoutEndPOintElasticsearchDomainStatus()); when(PublicAccessAutoFix.getExistingSecurityGroupDetails(anyObject(),anyObject())).thenReturn(CommonTestUtils.getSecurityGroupIdList()); when(PublicAccessAutoFix.nestedSecurityGroupDetails(anyString(),anyObject(),anyObject(),anyObject(),anyObject(),anyInt())).thenReturn(CommonTestUtils.getSetString("123")); when(PublicAccessAutoFix.createSecurityGroup(anyString(),anyString(),anyObject(),anyObject(),anyString(),anyString(),anyObject())).thenReturn("123"); when(PublicAccessAutoFix.applySecurityGroupsToAppELB(anyObject(),anyObject(),anyString())).thenReturn(true); spy.executeFix(CommonTestUtils.getMapString("r_123 "), elasticSearch, CommonTestUtils.getMapString("r_123 ")); when(PublicAccessAutoFix.getAWSClient(anyString(),anyObject(),anyString())).thenThrow(new Exception()); /* assertThatThrownBy( () -> searchPublicAccessAutoFix.executeFix(CommonTestUtils.getMapString("r_123 "),elasticSearch,CommonTestUtils.getMapString("r_123 "))).isInstanceOf(Exception.class);*/ }
Example #9
Source File: ElasticsearchDomainVH.java From pacbot with Apache License 2.0 | 2 votes |
/** * Gets the elasticsearch domain status. * * @return the elasticsearch domain status */ public ElasticsearchDomainStatus getElasticsearchDomainStatus() { return domain; }
Example #10
Source File: ElasticsearchDomainVH.java From pacbot with Apache License 2.0 | 2 votes |
/** * Sets the elasticsearch domain status. * * @param domain the new elasticsearch domain status */ public void setElasticsearchDomainStatus( ElasticsearchDomainStatus domain) { this.domain = domain; }