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.openecomp.sparky.util;
28 import java.util.concurrent.atomic.AtomicInteger;
30 import org.openecomp.sparky.dal.elasticsearch.config.ElasticSearchConfig;
31 import org.openecomp.sparky.dal.rest.RestDataProvider;
32 import org.openecomp.sparky.synchronizer.config.TaskProcessorConfig;
35 * The Class ElasticGarbageInjector.
37 public class ElasticGarbageInjector {
40 private AtomicInteger counter;
41 private long startTimeInMs;
42 private int progressStep;
45 * The Enum ActiveInventoryEntities.
47 private enum ActiveInventoryEntities {
49 COMPLEX("complex"), CUSTOMER("customer"), GENERIC_VNF("generic-vnf"), NEWVCE("newvce"), PSERVER(
50 "pserver"), SERVICE_INSTANCE("service-instance"), VCE("vce"), VPE("vpe"), VSERVER(
53 private final String entityName;
56 * Instantiates a new active inventory entities.
58 * @param name the name
60 private ActiveInventoryEntities(String name) {
61 this.entityName = name;
64 public String getEntityName() {
71 * Instantiates a new elastic garbage injector.
73 * @throws Exception the exception
75 public ElasticGarbageInjector() throws Exception {
77 this.counter = new AtomicInteger(0);
79 ElasticSearchConfig elasticConfig = new ElasticSearchConfig();
81 TaskProcessorConfig tpc = new TaskProcessorConfig();
83 tpc.setMaxConcurrentWorkers(5);
84 tpc.setTransactionRateControllerEnabled(false);
85 tpc.setNumSamplesPerThreadForRunningAverage(100);
86 tpc.setTargetTps(100.0);
88 tpc.setBytesHistogramLabel("bytesHistoLabel");
89 tpc.setBytesHistogramMaxYAxis(1000000);
90 tpc.setBytesHistogramNumBins(20);
91 tpc.setBytesHistogramNumDecimalPoints(2);
93 tpc.setQueueLengthHistogramLabel("queueHistoLabel");
94 tpc.setQueueLengthHistogramMaxYAxis(1000000);
95 tpc.setQueueLengthHistogramNumBins(20);
96 tpc.setQueueLengthHistogramNumDecimalPoints(2);
98 RestDataProvider syncAdapter = null;
99 // syncAdapter.setTaskProcessorConfig(tpc);
105 * public void handleEvent(AsyncEvent event) {
107 * if(event.getEventType() == AsyncEventType.RESOLVER_IDLE) { System.out.println("All Done!");
108 * resolver.shutdown(); }
112 * if(event.getEventType() == AsyncEventType.TRANSACTION_PROCESSED) {
115 * if ( event.getPayload() instanceof SyncTask) {
117 * counter.incrementAndGet();
119 * SyncTask ers = (SyncTask)event.getPayload();
121 * OperationResult or = ers.getResult();
123 * if ( or.wasSuccessful() ) { //System.out.println("Garbaged injected successfully"); }else {
124 * System.out.println(ers.getResult().toString()); }
126 * if ( counter.get() % progressStep == 0) {
128 * long duration = System.currentTimeMillis() - startTimeInMs; double tps = ( duration /
129 * counter.get() ); System.out.println("Currently inserting doc at index = " + counter.get() +
130 * ", current TPS = " + tps ); }
136 * public void injectGarbage(int numGarbageDocs, String baseUrl) {
138 * IndexDocument d = null; SyncTask syncTask = null; Random r = new Random();
140 * startTimeInMs = System.currentTimeMillis(); this.progressStep = (numGarbageDocs/5); if (
141 * this.progressStep == 0 ) { this.progressStep = 1; } int numEntities =
142 * ActiveInventoryEntities.values().length;
144 * for(int i = 0; i < numGarbageDocs; i++) { d = new IndexDocument(OXMModelLoader.getInstance());
145 * d.setId(UUID.randomUUID().toString());
146 * d.setEntityType(ActiveInventoryEntities.values()[r.nextInt(numEntities)].getEntityName());
148 * String link = baseUrl + d.getId(); syncTask = new SyncTask(d, link);
149 * syncTask.setResourceEntityType(d.getEntityType());
150 * syncTask.setPayload(d.getIndexDocumentJson());
152 * resolver.resolve(syncTask); }
156 * public static void main(String[] args) throws Exception {
158 * //System.getProperties().setProperty("AJSC_HOME", "X:\\aaiui\\");
160 * ElasticGarbageInjector sync = new ElasticGarbageInjector();
162 * //int numEntries = Integer.parseInt(args[0]); //String baseUrl = args[1];
164 * //sync.injectGarbage(numEntries,baseUrl);
165 * sync.injectGarbage(10000,"http://localhost:9200/entitysearchindex-localhost/default/");