2 * ============LICENSE_START===================================================
3 * SPARKY (AAI UI service)
4 * ============================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
8 * ============================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=====================================================
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
26 package org.onap.aai.sparky.util;
28 import java.util.Collection;
29 import java.util.Comparator;
30 import java.util.HashMap;
32 import java.util.TreeMap;
33 import java.util.concurrent.atomic.AtomicInteger;
35 import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
36 import org.onap.aai.sparky.dal.exception.ElasticSearchOperationException;
37 import org.onap.aai.sparky.dal.rest.RestDataProvider;
40 * The Class ElasticEntitySummarizer.
42 public class ElasticEntitySummarizer {
44 private RestDataProvider syncAdapter;
45 private ElasticSearchConfig elasticConfig;
46 private Map<String, AtomicInteger> entityCounters;
49 * Instantiates a new elastic entity summarizer.
51 * @param loader the loader
52 * @throws Exception the exception
54 public ElasticEntitySummarizer() throws Exception {
57 elasticConfig = new ElasticSearchConfig();
59 elasticConfig.setIndexName("entitysearchindex-localhost");
60 elasticConfig.setIpAddress("127.0.0.1");
61 elasticConfig.setHttpPort("9200");
62 elasticConfig.setType("default");
64 // syncAdapter = new SyncAdapter(new RestClientBuilder(), elasticConfig, loader);
66 entityCounters = new HashMap<String, AtomicInteger>();
73 * @param entityName the entity name
75 private synchronized void pegCounter(String entityName) {
77 if (entityName == null || entityName.length() == 0) {
81 AtomicInteger counter = entityCounters.get(entityName);
83 if (counter == null) {
84 counter = new AtomicInteger(0);
85 entityCounters.put(entityName, counter);
88 counter.incrementAndGet();
96 public void enumerateEntities() {
100 Map<String, String> preSyncObjectIdsAndTypes = new HashMap<String, String>();
103 * Map<String, String> preSyncObjectIdsAndTypes =
104 * syncAdapter.retrieveAllDocumentIdentifiers(elasticConfig.getIndexName(),
105 * elasticConfig.getType(), 5, 5000);
108 if (preSyncObjectIdsAndTypes != null) {
110 Collection<String> entityTypes = preSyncObjectIdsAndTypes.values();
111 for (String t : entityTypes) {
116 TreeMap<String, AtomicInteger> elasticEntitySortedTreeMap =
117 new TreeMap<String, AtomicInteger>(new Comparator<String>() {
120 public int compare(String o1, String o2) {
121 return o1.toLowerCase().compareTo(o2.toLowerCase());
125 elasticEntitySortedTreeMap.putAll(entityCounters);
127 int totalEntities = 0;
129 System.out.println("\n");
131 for (String counterEntityKey : elasticEntitySortedTreeMap.keySet()) {
133 AtomicInteger counter = elasticEntitySortedTreeMap.get(counterEntityKey);
134 totalEntities += counter.get();
135 System.out.println(String.format("%-30s %-12d", counterEntityKey, counter.get()));
138 System.out.println(String.format("\n%-30s %-12d", "Total", totalEntities));
140 } catch (Exception exc) {
141 System.out.println("An error occurred while attempting to collect pre-sync elastic"
142 + " search document ids with an error cause = " + exc.getLocalizedMessage());
152 * @param args the arguments
153 * @throws ElasticSearchOperationException the elastic search operation exception
155 public static void main(String[] args) throws ElasticSearchOperationException {
158 // ElasticEntitySummarizer summarizer = new ElasticEntitySummarizer();
159 // summarizer.enumerateEntities();