Remove unnecessary log
[dcaegen2/collectors/ves.git] / README.md
1 DCAE VESCollector
2 ======================================
3
4 This is the repository for VES Collector for Open DCAE.
5
6 Virtual Event Streaming (VES) Collector is RESTful collector for processing JSON messages into DCAE. The collector verifies the source (when authentication is enabled) and validates the events against VES schema before distributing to DMAAP MR topics for downstream system to subscribe. The VESCollector also provides configurable event transformation function and event distribution to DMAAP MR topics.
7
8 The collector supports individual events or eventbatch posted to collector end-point(s) and post them to interface/bus for other application to subscribe.
9
10
11 ### Build Instructions
12
13 This project is organized as a mvn project and has "org.onap.dcaegen2" as parent project. The build generate a jar and package into docker container. 
14
15 ```
16 git clone ssh://vv770d@gerrit.onap.org:29418/dcaegen2/collectors/ves
17 mvn clean install
18 ```
19
20 ### Running Locally
21
22 Build the image (it will go into your local docker repository)
23 ```
24 mvn clean package
25 ```
26
27 Run the image using docker-compose.yml
28 ```
29 docker-compose up
30 ```
31
32 ### Generate auth credential 
33
34 Library to generate new cryptographic password is stored in dcaegen2/sdk -"security/crypt-password"
35
36 or download artifact from: 
37
38 https://nexus.onap.org/#nexus-search;quick~crypt-password
39
40 How to use:
41 ```
42 java -jar crypt-password-<version>.jar password_to_crypt
43 ```
44
45 ### Environment variables in Docker Container
46 Most of the configuration of how VESCollector should be started and managed is done through environment variables.
47 Some of them are set during the image build process and some of them are defined manually or by
48 a particular deployment system.
49
50 Variables set manually / coming from deployment system:
51 - COLLECTOR_IP
52 - DMAAPHOST - should contain an address to DMaaP, so that event publishing can work
53 - CBSPOLLTIMER - it should be put in here if we want to automatically fetch configuration from CBS.
54 - CONSUL_PROTOCOL - Consul protocol by default set to **http**, if it is need to change it then that can be set to different value 
55 - CONSUL_HOST - used with conjunction with CBSPOLLTIMER, should be a host address (without port! e.g my-ip-or-host) where Consul service lies
56 - CBS_PROTOCOL - Config Binding Service protocol by default set to **http**, if it is need to change it then that can be set to different value
57 - CONFIG_BINDING_SERVICE - used with conjunction with CBSPOLLTIMER, should be a name of CBS as it is registered in Consul
58 - HOSTNAME - used with conjunction with CBSPOLLTIMER, should be a name of VESCollector application as it is registered in CBS catalog
59
60 ### Docker file system layout
61 The main directory where all code resides in docker container
62 looks like this and is located in /opt/app/VESCollector
63 ```
64 <host>:/opt/app/VESCollector# ls
65 Dockerfile  bin  etc  lib  logs  specs  tomcat.8080
66 ```
67 - bin contains sh scripts (path here is denoted by env var $SCRIPTS_PATH)
68 - etc contains various application configuration, most notably it reflects 'etc' directory from repository
69 - lib contains all libraries that are pulled into the app during maven build
70 - logs contains all application logs, especially collector.log file which is a main log file denoted by $MAIN_LOG_FILE variable
71 - specs contains json schemas specs for ves-collector
72
73 ## Managing application in Docker container
74 Scripts directory contain .sh scripts that are used to start & stop & configure the VESCollector application
75 inside the docker image.
76 These scripts are packaged inside the docker image by a mvn assembly & docker plugins.
77
78 ## How the application starts inside container
79 General flow goes like this
80 - Docker image is build, and it points docker-entry.sh as the entrypoint.
81 - Docker-entry point, depending on the deployment type,
82 configures a bunch of things and starts the application in a separate process
83 and loops indefinitely to hold the docker container process.
84
85 ### Release images
86 For R1 - image/version  pushed to nexus3 
87 ```
88 nexus3.onap.org:10003/snapshots/onap/org.onap.dcaegen2.collectors.ves.vescollector   1.1 
89 ```
90
91 ### Deployment
92
93 VESCollector in DCAE will be deployed as mS via DCAEGEN2 controller. A blueprint will be generated (CLAMP/SDC) which will fetch the docker image and install on the dockerhost identified. VESCollector on startup will query the configbindingService for updated configuration and starts the service. When configuration change is detected by DCAEGEN2 controller (via policy flow) - then contoller will notify Collector to fetch new configuration again. 
94
95 For testing purpose, the docker image includes preset configuration which can be ran without DCAEGEN2 platform.
96
97
98
99 ### Consul - Dynamic configuration 
100
101
102 Application properties like /etc/collector.properties and Dmaap configuration /etc/DmaapConfig.json are updated frequently by configuration stored in Consul(CBS) http://<kubernetes_host_ip>:30270/ui/#/dc1/kv/<vescollector_SCN> 
103 Configuration stored in Consul have bigger priority and always will override local configuration so all configuration modification should be done using Consul update on corresponding kv store. 
104 Frequently how often configuration will be fetch from Consul server is manageable in /etc/collector.properties property "collector.dynamic.config.update.frequency={time in minutes}".
105
106 Sample configuration of VESCollector K-V store can be found under /dpo/data-formats/ConsulConfig.json
107
108
109 ### Testing
110
111 For R1 as only measurement and faults are expected in ONAP, configuration are preset currently sto support these two topics only.
112
113 ```
114 STEPS FOR SETUP/TEST
115 1)      Get the VESCollector image from Nexus
116                 docker pull nexus.onap.org:10001/onap/org.onap.dcaegen2.collectors.ves.vescollector:latest
117 2)      Start the container (change the DMAAPHOST environment value to running DMAAP instance host)
118                 docker run -d -p 8080:8080/tcp -p 8443:8443/tcp -P -e DMAAPHOST='10.0.0.174' nexus.onap.org:10001/onap/org.onap.dcaegen2.collectors.ves.vescollector:1.1
119 3)      Login into container and tail /opt/app/VESCollector/logs/collector.log
120 4)      Simulate event into VEScollector (can be done from different vm or same)
121                 curl -i -X POST -d @measurement.txt --header "Content-Type: application/json" https://localhost:8443/eventListener/v5 -k
122                 or curl -i  -X POST -d @measurement.txt --header "Content-Type: application/json" http://localhost:8080/eventListener/v5 -k
123         Note: If DMAAPHOST provided is invalid, you will see exception around publish on the collector.logs (collector queues and attempts to resend the event hence exceptions reported will be periodic).   If you don’t want to see the error, publish to dmaap can be disabled by changing either “collector.dmaap.streamid” on etc/collector.properties OR by modifying the “name” defined on  etc/DmaapConfig.json. 
124
125         Any changes to property within container requires collector restart
126         cd /opt/app/VESCollector/
127         ./bin/appController.sh stop
128         ./bin/appController.sh start 
129
130 5)      If DMAAP instance (and DMAAPHOST passed during VESCollector startup) and VES input is valid, then events will be pushed to below topics depending on the domain
131         Fault :http://<dmaaphost>:3904/events/unauthenticated.SEC_FAULT_OUTPUT
132         Measurement : http://<dmaaphost>:3904/events/unauthenticated.SEC_MEASUREMENT_OUTPUT
133 6)      When test is done – do ensure to remove the container (docker rm -f <containerid>) to avoid port conflict
134 ```
135
136 Authentication is set by default to "noauth" (via auth.method property) on the container; below are the steps for enabling HTTPS/authentication for VESCollector. 
137 ```
138 1) Login to the container
139 2) Open /opt/app/VESCollector/etc/collector.properties and edit below properties
140                 a) Comment below property (with authentication enabled, standard http should be disabled)
141                         collector.service.port=8080
142                 b) Enable basic-authentication
143                   auth.method=basicAuth                 
144      Note: The actual credentials is stored part of header.authlist parameter. This is list of userid,password values. Default configuration has below set
145                 sample1,$2a$10$pgjaxDzSuc6XVFEeqvxQ5u90DKJnM/u7TJTcinAlFJVaavXMWf/Zi|vdnsagg,$2a$10$C45JhiRSY.qXTBfzWST3Q.AmwKlPRMc67c33O0U9hOH8KSGaweN4m
146                 where password maps to same value as username.
147                 Password is generated by crypt-password tool (https://nexus.onap.org/#nexus-search;quick~crypt-password)
148 3) Restart the collector
149                 cd /opt/app/VESCollector
150                 ./bin/appController.sh stop
151                 ./bin/appController.sh start                              
152 4) Exit from container and ensure tcp port on VM is not hanging on finwait – you can execute “netstat -an | grep 8443” . If under FIN_WAIT2, wait for server to release.
153 5) Simulate via curl (Note - username/pwd will be required)
154     Example of successfull POST:
155                 vv770d@osdcae-dev-16:~$ curl -i  -u 'sample1:sample1' -X POST -d @volte.txt --header "Content-Type: application/json" https://localhost:8443/eventListener/v5 -k
156                 HTTP/1.1 200 OK
157                 Server: Apache-Coyote/1.1
158                 X-Rathravane: ~ software is craft ~
159                 Content-Type: application/json;charset=ISO-8859-1
160                 Content-Length: 17
161                 Date: Thu, 21 Sep 2017 22:23:49 GMT
162                 Message Accepted
163
164         Example of authentication failure:
165                 vv770d@osdcae-dev-16:~$ curl -i -X POST -d @volte.txt --header "Content-Type: application/json" https://localhost:8443/eventListener/v5 -k
166                 HTTP/1.1 401 Unauthorized
167                 Server: Apache-Coyote/1.1
168                 X-Rathravane: ~ software is craft ~
169                 Content-Type: application/json;charset=ISO-8859-1
170                 Content-Length: 96
171                 Date: Thu, 21 Sep 2017 22:20:43 GMT
172                 Connection: close
173                 {"requestError":{"GeneralException":{"MessagID":"\"POL2000\"","text":"\"Unauthorized user\""}}}
174
175 Note: In general support for HTTPS also require certificate/keystore be installed on target VM with FS mapped into the container for VESCollector to load. For demo and testing purpose - a self signed certificate is included within docker build. When deployed via DCAEGEN2 platform - these configuration will be overridden dynamically to map to required path/certificate name. This will be exercised post R1 though.
176 ```
177
178 A client's certificate verification is disabled on the container by default; below are the steps for enabling mutual TLS authentication for VESCollector.
179 ```
180 1) Login to the container
181 2) Open /opt/app/VESCollector/etc/collector.properties and edit below properties
182                 a) Comment below property (with authentication enabled, standard http should be disabled)
183                         collector.service.port=8080
184                 b) Enable a client's certificate verification
185                   auth.method=certOnly (only certificate verification)  
186                         or
187                         auth.method=certBasicAuth ( certificate verification with basic auth verification )
188 3) Restart the collector
189                 cd /opt/app/VESCollector
190                 ./bin/appController.sh stop
191                 ./bin/appController.sh start
192 4) Exit from container and ensure tcp port on VM is not hanging on finwait – you can execute “netstat -an | grep 8443” . If under FIN_WAIT2, wait for server to release.
193 5) In order for VESCollector to accept a connection from a client, the client has to use TLS certificate signed by CA that is present in VESCollector truststore. If a default VESCollector truststore is used then a client's certificate may be generated using following steps:
194                 a) Generate a client's private key
195                     openssl genrsa -out client.key 2048
196                 b) Create the signing
197                     openssl req -new -key client.key -out client.csr
198                 c) Create the client's certificate (CA key password should be obtained from [VESCollectorRepository]/certs/password)
199                     openssl x509 -req -in client.csr -CA [VESCollectorRepository]/certs/rootCA.crt -CAkey [VESCollectorRepository]/certs/rootCA.key -CAcreateserial -out client.crt -days 500 -sha256
200 6) Simulate via curl (assuming that the certificate was created via step 5)
201     Example of successfull POST:
202         curl -i -X POST -d @event.json --header "Content-Type: application/json" https://localhost:8443/eventListener/v7 -k --cert client.crt --key client.key
203         HTTP/1.1 100 
204         
205         HTTP/1.1 202 
206         Content-Type: application/json
207         Content-Length: 8
208         Date: Wed, 21 Nov 2018 11:37:58 GMT
209         
210     Example of authentication failure (without a client's certificate):
211         curl -i -X POST -d @event.json --header "Content-Type: application/json" https://localhost:8443/eventListener/v7 -k
212         curl: (35) error:14094412:SSL routines:ssl3_read_bytes:sslv3 alert bad certificate