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.config.oxm.OxmModelLoader;
36 import org.onap.aai.sparky.dal.elasticsearch.config.ElasticSearchConfig;
37 import org.onap.aai.sparky.dal.exception.ElasticSearchOperationException;
38 import org.onap.aai.sparky.dal.rest.RestDataProvider;
39 import org.onap.aai.sparky.synchronizer.config.TaskProcessorConfig;
42 * The Class ElasticEntitySummarizer.
44 public class ElasticEntitySummarizer {
46 private RestDataProvider syncAdapter;
49 * @return the syncAdapter
51 public RestDataProvider getSyncAdapter() {
56 * @param syncAdapter the syncAdapter to set
58 public void setSyncAdapter(RestDataProvider syncAdapter) {
59 this.syncAdapter = syncAdapter;
63 * @return the elasticConfig
65 public ElasticSearchConfig getElasticConfig() {
70 * @param elasticConfig the elasticConfig to set
72 public void setElasticConfig(ElasticSearchConfig elasticConfig) {
73 this.elasticConfig = elasticConfig;
77 * @return the entityCounters
79 public Map<String, AtomicInteger> getEntityCounters() {
80 return entityCounters;
84 * @param entityCounters the entityCounters to set
86 public void setEntityCounters(Map<String, AtomicInteger> entityCounters) {
87 this.entityCounters = entityCounters;
91 private ElasticSearchConfig elasticConfig;
92 private Map<String, AtomicInteger> entityCounters;
95 * Instantiates a new elastic entity summarizer.
97 * @param loader the loader
98 * @throws Exception the exception
100 public ElasticEntitySummarizer(OxmModelLoader loader) throws Exception {
103 elasticConfig = new ElasticSearchConfig();
104 TaskProcessorConfig tpc = new TaskProcessorConfig();
105 elasticConfig.setProcessorConfig(tpc);
107 elasticConfig.setIndexName("entitysearchindex-localhost");
108 elasticConfig.setIpAddress("127.0.0.1");
109 elasticConfig.setHttpPort("9200");
110 elasticConfig.setType("default");
112 // syncAdapter = new SyncAdapter(new RestClientBuilder(), elasticConfig, loader);
114 entityCounters = new HashMap<String, AtomicInteger>();
121 * @param entityName the entity name
123 private synchronized void pegCounter(String entityName) {
125 if (entityName == null || entityName.length() == 0) {
129 AtomicInteger counter = entityCounters.get(entityName);
131 if (counter == null) {
132 counter = new AtomicInteger(0);
133 entityCounters.put(entityName, counter);
136 counter.incrementAndGet();
142 * Enumerate entities.
144 public void enumerateEntities() {
148 Map<String, String> preSyncObjectIdsAndTypes = new HashMap<String, String>();
151 * Map<String, String> preSyncObjectIdsAndTypes =
152 * syncAdapter.retrieveAllDocumentIdentifiers(elasticConfig.getIndexName(),
153 * elasticConfig.getType(), 5, 5000);
156 if (preSyncObjectIdsAndTypes != null) {
158 Collection<String> entityTypes = preSyncObjectIdsAndTypes.values();
159 for (String t : entityTypes) {
164 TreeMap<String, AtomicInteger> elasticEntitySortedTreeMap =
165 new TreeMap<String, AtomicInteger>(new Comparator<String>() {
168 public int compare(String o1, String o2) {
169 return o1.toLowerCase().compareTo(o2.toLowerCase());
173 elasticEntitySortedTreeMap.putAll(entityCounters);
175 int totalEntities = 0;
177 System.out.println("\n");
179 for (String counterEntityKey : elasticEntitySortedTreeMap.keySet()) {
181 AtomicInteger counter = elasticEntitySortedTreeMap.get(counterEntityKey);
182 totalEntities += counter.get();
183 System.out.println(String.format("%-30s %-12d", counterEntityKey, counter.get()));
186 System.out.println(String.format("\n%-30s %-12d", "Total", totalEntities));
188 } catch (Exception exc) {
189 System.out.println("An error occurred while attempting to collect pre-sync elastic"
190 + " search document ids with an error cause = " + exc.getLocalizedMessage());