@itentialopensource/adapter-kafkav2 0.12.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,20 @@
1
1
 
2
+ ## 0.14.0 [08-04-2023]
3
+
4
+ * Add logic to clean topics.json from service config
5
+
6
+ See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!11
7
+
8
+ ---
9
+
10
+ ## 0.13.0 [08-03-2023]
11
+
12
+ * Add seperate sasl props for consumer and producer
13
+
14
+ See merge request itentialopensource/adapters/notification-messaging/adapter-kafkav2!10
15
+
16
+ ---
17
+
2
18
  ## 0.12.0 [08-03-2023]
3
19
 
4
20
  * Add seperate sasl props for consumer and producer
package/README.md CHANGED
@@ -75,6 +75,39 @@ git clone git@gitlab.com:\@itentialopensource/adapters/adapter-Kafkav2
75
75
  npm install
76
76
  ```
77
77
 
78
+ ## Installing an Itential Product Adapter
79
+
80
+ 1. Set up the name space location in your IAP node_modules.
81
+
82
+ ```json
83
+ cd /opt/pronghorn/current/node_modules
84
+ if the @itentialopensource directory does not exist, create it:
85
+ mkdir @itentialopensource
86
+ ```
87
+
88
+ 1. Clone the adapter into your IAP environment.
89
+
90
+ ```json
91
+ cd \@itentialopensource
92
+ git clone git@gitlab.com:\@itentialopensource/adapters/adapter-Kafka
93
+ ```
94
+
95
+ 1. Install the dependencies for the adapter.
96
+
97
+ ```json
98
+ cd adapter-Kafka
99
+ npm install
100
+ ```
101
+
102
+ 1. Add the adapter properties for Kafka (created from Adapter Builder) to the `properties.json` file for your Itential build. You will need to change the credentials and possibly the host information below.
103
+ [Kafka sample properties](sampleProperties.json)
104
+
105
+ 1. Restart IAP
106
+
107
+ ```json
108
+ systemctl restart pronghorn
109
+ ```
110
+
78
111
  ## Adapter Properties and Descriptions
79
112
 
80
113
  This section defines **all** the properties that are available for the adapter, including detailed information on what each property is for. If you are not using certain capabilities with this adapter, you do not need to define all of the properties. An example of how the properties for this adapter can be used with tests or IAP are provided in the **Installation** section.
@@ -96,9 +129,7 @@ This section defines **all** the properties that are available for the adapter,
96
129
  "brokers": [
97
130
  "broker:9093"
98
131
  ],
99
- "clientId": "my-app",
100
- "ssl": {},
101
- "sasl": {}
132
+ "clientId": "my-app"
102
133
  },
103
134
  "producer": {
104
135
  "requireAcks": 1,
@@ -247,10 +278,10 @@ These base properties are used to connect to Kafka upon the adapter initially co
247
278
 
248
279
  | Property | Description |
249
280
  | ------- | ------- |
250
- | host | Optional. A fully qualified domain name or IP address.|
251
- | port | Required if `host` set. Used to connect to the server.|
281
+ | host | Optional. A fully qualified domain name or IP address. This is not needed for latest version of the adapter as the broker is set under client properties.|
282
+ | port | Required if `host` set. Used to connect to the server. This is not needed for latest version of the adapter as the port is set under client properties|
252
283
  | interval_time | Optional. The Kafka adapter keeps information about topics and offsets in memory in order to be more efficient. In order to work across restarts the adapter must persist the data. So the data is written into the .topics.json file. This write time defines how often to write the file.|
253
- | stub | Optional. Slightlu different meaning than normal, this is just telling the adapter whether to run the write topics interval. This should always be false unless you are running standalone tests.|
284
+ | stub | Optional. Slightly different meaning than normal, this is just telling the adapter to not actually send any request to kafka and mock a healthy connection. Should be set to false unless you are wanting to force the adapter to be green without an actual connection.|
254
285
 
255
286
  #### Important
256
287
  When adapter works in consumer configuration: `autoCommit:false` `fromOffset:true` current offset setting on adapter startup is loaded from .topic.json file for each (topic:partition).
@@ -301,6 +332,8 @@ The `parseMessage` property allows the user to define how they want the Kafka me
301
332
 
302
333
  ## Send message sample payload
303
334
 
335
+ Note that this is an array, so it can have multiple topics.
336
+
304
337
  ```json
305
338
  [{
306
339
  "topic": "topic-name",
@@ -312,122 +345,42 @@ The `parseMessage` property allows the user to define how they want the Kafka me
312
345
  ```
313
346
  For all options of messages array please follow [kafkajs documentation](https://kafka.js.org/docs/producing#producing-messages)
314
347
 
315
- ## Testing an Itential Product Adapter
316
-
317
- Mocha is generally used to test all Itential Product Adapters. There are unit tests as well as integration tests performed. Integration tests can generally be run as standalone using mock data and running the adapter in stub mode, or as integrated. When running integrated, every effort is made to prevent environmental failures, however there is still a possibility.
348
+ ## Triggering jobs in IAP from a kafka message
318
349
 
319
- ### Unit Testing
350
+ Once you have the adapter configured and online in an IAP instance, you can create triggers in Operations Manager to kick off jobs when a kafka message is consumed. The adapter listens for messages on the subscribed topics and publishes to an event. This event is picked up by the Operations Manager. If you have created triggers for this specific topic, a job will get triggered. For a step-by-step example follow the next sub-section.
320
351
 
321
- Unit Testing includes testing basic adapter functionality as well as error conditions that are triggered in the adapter prior to any integration. There are two ways to run unit tests. The prefered method is to use the testRunner script; however, both methods are provided here.
352
+ ### Listen to a topic called test-topic and trigger a workflow called test
322
353
 
354
+ 1. Subscribe to partition 0 of test-topic. Add this to your adapter service config. To see different options of topic properties see PROPERTIES.md
323
355
 
324
356
  ```json
325
- node utils/testRunner --unit
326
-
327
- npm run test:unit
328
- ```
329
-
330
- To add new unit tests, edit the `test/unit/adapterTestUnit.js` file. The tests that are already in this file should provide guidance for adding additional tests.
331
-
332
- ### Integration Testing - Standalone
333
-
334
- Standalone Integration Testing requires mock data to be provided with the entities. If this data is not provided, standalone integration testing will fail. When the adapter is set to run in stub mode (setting the stub property to true), the adapter will run through its code up to the point of making the request. It will then retrieve the mock data and return that as if it had received that data as the response from Kafka. It will then translate the data so that the adapter can return the expected response to the rest of the Itential software. Standalone is the default integration test.
335
-
336
- Similar to unit testing, there are two ways to run integration tests. Using the testRunner script is better because it prevents you from having to edit the test script; it will also resets information after testing is complete so that credentials are not saved in the file.
337
-
338
- ```json
339
- node utils/testRunner
340
- answer no at the first prompt
341
-
342
- npm run test:integration
343
- ```
344
-
345
- To add new integration tests, edit the `test/integration/adapterTestIntegration.js` file. The tests that are already in this file should provide guidance for adding additional tests.
346
-
347
- ### Integration Testing
348
-
349
- Integration Testing requires connectivity to Kafka. By using the testRunner script it prevents you from having to edit the integration test. It also resets the integration test after the test is complete so that credentials are not saved in the file.
350
-
351
- > **Note**: These tests have been written as a best effort to make them work in most environments. However, the Adapter Builder often does not have the necessary information that is required to set up valid integration tests. For example, the order of the requests can be very important and data is often required for `creates` and `updates`. Hence, integration tests may have to be enhanced before they will work (integrate) with Kafka. Even after tests have been set up properly, it is possible there are environmental constraints that could result in test failures. Some examples of possible environmental issues are customizations that have been made within Kafka which change order dependencies or required data.
352
-
353
- ```json
354
- node utils/testRunner
355
- answer yes at the first prompt
356
- answer all other questions on connectivity and credentials
357
- ```
358
-
359
- Test should also be written to clean up after themselves. However, it is important to understand that in some cases this may not be possible. In addition, whenever exceptions occur, test execution may be stopped, which will prevent cleanup actions from running. It is recommended that tests be utilized in dev and test labs only.
360
-
361
- > **Reminder**: Do not check in code with actual credentials to systems.
362
-
363
- ## Installing an Itential Product Adapter
364
-
365
- 1. Set up the name space location in your IAP node_modules.
366
-
367
- ```json
368
- cd /opt/pronghorn/current/node_modules
369
- if the @itentialopensource directory does not exist, create it:
370
- mkdir @itentialopensource
371
- ```
372
-
373
- 1. Clone the adapter into your IAP environment.
374
-
375
- ```json
376
- cd \@itentialopensource
377
- git clone git@gitlab.com:\@itentialopensource/adapters/adapter-Kafka
378
- ```
379
-
380
- 1. Install the dependencies for the adapter.
381
-
382
- ```json
383
- cd adapter-Kafka
384
- npm install
385
- ```
386
-
387
- 1. Add the adapter properties for Kafka (created from Adapter Builder) to the `properties.json` file for your Itential build. You will need to change the credentials and possibly the host information below.
388
- [Kafka sample properties](sampleProperties.json)
389
-
390
- 1. Restart IAP
391
-
392
- ```json
393
- systemctl restart pronghorn
394
- ```
395
-
396
- ## Installing a Custom Adapter
397
-
398
- If you built this as a custom adapter through the Adapter Builder, it is recommended you go through setting up a development environment and testing the adapter before installing it. There is often configuration and authentication work that is required before the adapter will work in IAP.
399
-
400
- 1. Move the adapter into the IAP `node_modules` directory.
401
-
402
- ```json
403
- Depending on where your code is located, this process is different.
404
- Could be a tar, move, untar
405
- Could be a git clone of a repository
406
- Could also be a cp -R from a coding directory
407
- Adapter should be placed into: /opt/pronghorn/current/node_modules/\@itentialopensource
357
+ "topics": [
358
+ {
359
+ "name": "test-topic",
360
+ "always": true,
361
+ "partition": 0,
362
+ "subscriberInfo": [
363
+ {
364
+ "subname": "default",
365
+ "filters": [],
366
+ "rabbit": "test-topic-rabbit",
367
+ "throttle": {}
368
+ }
369
+ ]
370
+ }
371
+ ],
408
372
  ```
409
373
 
410
- 1. Follow Steps 3-5 (above) to install an Itential adapter to load your properties, dependencies and restart IAP.
374
+ Note the rabbit key in the config is set to kafka. The adapter will send any message on test-topic-rabbit to a Rabbit queue named kafka. If no rabbit topic is supplied, events will be published to a topic with the same name as the Kafka topic. Also note that the filter array can be left empty to consume all messages on partion 0 of test-topic.
411
375
 
412
- ## Using this Adapter
376
+ 2. Create an automation in Operations Manager
413
377
 
414
- The `adapter.js` file contains the calls the adapter makes available to the rest of the Itential Platform. The API detailed for these calls should be available through JSDOC. The following is a brief summary of the calls.
378
+ Create a new automation, and add a trigger.
415
379
 
416
- ### Generic Adapter Calls
417
-
418
- ```json
419
- connect()
420
- The connect call is run when the Adapter is first loaded by he Itential Platform. It validates the properties have been provided correctly.
421
- ```
422
-
423
- ```json
424
- healthCheck(callback)
425
- Insures that the adapter can communicate with Kafka. The actual call that is used is defined in the adapter properties.
426
- ```
380
+ When selecting the Event for your trigger, make sure to select test-topic-rabbit from the drop down list. This is critical as the adpater will be sending the message on this queue. You can add filtering in the trigger by providing a Payload Schema Filter.
427
381
 
428
- ### Specific Adapter Calls
382
+ After saving the trigger, select the workflow you want to trigger. Save the Automation and view all jobs to see a job getting triggered as soon as a message is published on test-topic partition 0.
429
383
 
430
- Specific adapter calls are built based on the API of the Kafka. The Adapter Builder creates the proper method comments for generating JS-DOC for the adapter. This is the best way to get information on the calls.
431
384
 
432
385
  ## Troubleshooting the Adapter
433
386
 
package/adapter.js CHANGED
@@ -349,12 +349,45 @@ class Kafkav2 extends AdapterBaseCl {
349
349
  processed: 0,
350
350
  subscribers: 99999,
351
351
  avro: useAvro,
352
- subInfo
352
+ subInfo,
353
+ source: 'props'
353
354
  });
354
355
  }
355
356
  }
356
357
  }
357
358
 
359
+ // check if service config doesnt have a topic and the source was props, delete it from topics
360
+ for (let te = 0; te < this.topicsEvents.length; te += 1) {
361
+ let topicFound = false;
362
+ for (let t = 0; t < this.props.topics.length; t += 1) {
363
+ if (this.topicsEvents[te].topic === this.props.topics[t].name && this.topicsEvents[te].source) {
364
+ if (this.topicsEvents[te].subInfo) {
365
+ const { subInfo } = this.topicsEvents[te];
366
+ for (let sub = 0; sub < subInfo.length; sub += 1) {
367
+ let subFound = false;
368
+ for (let s = 0; s < this.props.topics[t].subscriberInfo.length; s += 1) {
369
+ // if the subscriber is found, no need to add anything
370
+ if (subInfo[sub].subname === this.props.topics[t].subscriberInfo[s].subname) {
371
+ subFound = true;
372
+ break;
373
+ }
374
+ }
375
+ if (subFound === false) {
376
+ this.topicsEvents[te].subInfo.splice(sub, 1);
377
+ }
378
+ }
379
+ }
380
+ topicFound = true;
381
+ }
382
+ }
383
+ if (topicFound === false && this.topicsEvents[te].source === 'props') {
384
+ this.topicsEvents.splice(te, 1);
385
+ const split = topicsFile.split('/');
386
+ log.debug(`Update ${split[split.length - 1]} file.`);
387
+ fs.writeFileSync(topicsFile, JSON.stringify(this.topicsEvents, null, 2));
388
+ }
389
+ }
390
+
358
391
  // if we need to restart the adapter due to changes to pronghorn.json
359
392
  if (needRestart) {
360
393
  fs.writeFileSync(pronghornFile, JSON.stringify(pjson, null, 2));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itentialopensource/adapter-kafkav2",
3
- "version": "0.12.0",
3
+ "version": "0.14.0",
4
4
  "description": "Itential adapter to connect to kafka",
5
5
  "main": "adapter.js",
6
6
  "wizardVersion": "2.35.0",
Binary file