Initial commit for AAI-UI(sparky-backend)
[aai/sparky-be.git] / src / test / java / org / openecomp / sparky / util / ElasticGarbageInjector.java
1 /* 
2 * ============LICENSE_START=======================================================
3 * SPARKY (AAI UI service)
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property.
6 * Copyright © 2017 Amdocs
7 * All rights reserved.
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
12
13 *      http://www.apache.org/licenses/LICENSE-2.0
14
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=========================================================
21
22 * ECOMP and OpenECOMP are trademarks
23 * and service marks of AT&T Intellectual Property.
24 */
25
26 package org.openecomp.sparky.util;
27
28 import java.util.concurrent.atomic.AtomicInteger;
29
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;
33
34 /**
35  * The Class ElasticGarbageInjector.
36  */
37 public class ElasticGarbageInjector {
38
39
40   private AtomicInteger counter;
41   private long startTimeInMs;
42   private int progressStep;
43
44   /**
45    * The Enum ActiveInventoryEntities.
46    */
47   private enum ActiveInventoryEntities {
48
49     COMPLEX("complex"), CUSTOMER("customer"), GENERIC_VNF("generic-vnf"), NEWVCE("newvce"), PSERVER(
50         "pserver"), SERVICE_INSTANCE("service-instance"), VCE("vce"), VPE("vpe"), VSERVER(
51             "vserver");
52
53     private final String entityName;
54
55     /**
56      * Instantiates a new active inventory entities.
57      *
58      * @param name the name
59      */
60     private ActiveInventoryEntities(String name) {
61       this.entityName = name;
62     }
63
64     public String getEntityName() {
65       return entityName;
66     }
67
68   }
69
70   /**
71    * Instantiates a new elastic garbage injector.
72    *
73    * @throws Exception the exception
74    */
75   public ElasticGarbageInjector() throws Exception {
76
77     this.counter = new AtomicInteger(0);
78
79     ElasticSearchConfig elasticConfig = new ElasticSearchConfig();
80
81     TaskProcessorConfig tpc = new TaskProcessorConfig();
82
83     tpc.setMaxConcurrentWorkers(5);
84     tpc.setTransactionRateControllerEnabled(false);
85     tpc.setNumSamplesPerThreadForRunningAverage(100);
86     tpc.setTargetTps(100.0);
87
88     tpc.setBytesHistogramLabel("bytesHistoLabel");
89     tpc.setBytesHistogramMaxYAxis(1000000);
90     tpc.setBytesHistogramNumBins(20);
91     tpc.setBytesHistogramNumDecimalPoints(2);
92
93     tpc.setQueueLengthHistogramLabel("queueHistoLabel");
94     tpc.setQueueLengthHistogramMaxYAxis(1000000);
95     tpc.setQueueLengthHistogramNumBins(20);
96     tpc.setQueueLengthHistogramNumDecimalPoints(2);
97
98     RestDataProvider syncAdapter = null;
99     // syncAdapter.setTaskProcessorConfig(tpc);
100
101   }
102
103   // @Override
104   /*
105    * public void handleEvent(AsyncEvent event) {
106    * 
107    * if(event.getEventType() == AsyncEventType.RESOLVER_IDLE) { System.out.println("All Done!");
108    * resolver.shutdown(); }
109    * 
110    * 
111    * 
112    * if(event.getEventType() == AsyncEventType.TRANSACTION_PROCESSED) {
113    * 
114    * 
115    * if ( event.getPayload() instanceof SyncTask) {
116    * 
117    * counter.incrementAndGet();
118    * 
119    * SyncTask ers = (SyncTask)event.getPayload();
120    * 
121    * OperationResult or = ers.getResult();
122    * 
123    * if ( or.wasSuccessful() ) { //System.out.println("Garbaged injected successfully"); }else {
124    * System.out.println(ers.getResult().toString()); }
125    * 
126    * if ( counter.get() % progressStep == 0) {
127    * 
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 ); }
131    * 
132    * }
133    * 
134    * } }
135    * 
136    * public void injectGarbage(int numGarbageDocs, String baseUrl) {
137    * 
138    * IndexDocument d = null; SyncTask syncTask = null; Random r = new Random();
139    * 
140    * startTimeInMs = System.currentTimeMillis(); this.progressStep = (numGarbageDocs/5); if (
141    * this.progressStep == 0 ) { this.progressStep = 1; } int numEntities =
142    * ActiveInventoryEntities.values().length;
143    * 
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());
147    * 
148    * String link = baseUrl + d.getId(); syncTask = new SyncTask(d, link);
149    * syncTask.setResourceEntityType(d.getEntityType());
150    * syncTask.setPayload(d.getIndexDocumentJson());
151    * 
152    * resolver.resolve(syncTask); }
153    * 
154    * }
155    * 
156    * public static void main(String[] args) throws Exception {
157    * 
158    * //System.getProperties().setProperty("AJSC_HOME", "X:\\aaiui\\");
159    * 
160    * ElasticGarbageInjector sync = new ElasticGarbageInjector();
161    * 
162    * //int numEntries = Integer.parseInt(args[0]); //String baseUrl = args[1];
163    * 
164    * //sync.injectGarbage(numEntries,baseUrl);
165    * sync.injectGarbage(10000,"http://localhost:9200/entitysearchindex-localhost/default/");
166    * 
167    * }
168    */
169
170 }