Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Operator and Processor #2136

Merged
merged 83 commits into from
Jul 11, 2024
Merged

Event Operator and Processor #2136

merged 83 commits into from
Jul 11, 2024

Conversation

ATorrise
Copy link
Contributor

@ATorrise ATorrise commented May 9, 2024

Overview

The EventOperator class is a singleton controller for managing EventProcessor instances. It organizes event management for applications by mapping each application's name to an event processor, which manages and fires callbacks provided by the subscriber to a given application-specific event.

Example Use Case

Imagine you have a Notepad application that wants to subscribe to events from a Calculator application to display the numbers typed in the Calculator:

  1. The Notepad application requests an EventProcessor instance with watch permissions for the Calculator from the EventOperator.
  2. The Notepad application subscribes to the Calculator's "number pressed" event with a callback to display the number that was pressed.
  3. Whenever a number is pressed in the Calculator, the Notepad application receives the event and can display the number.
// Notepad application subscribing to Calculator's events
const calcProcessor = EventOperator.getWatcher('calculator');
calcProcessor.subscribeUser('numberPressed', (number) => {
  notepad.display(`Number ${number} pressed in Calculator`);  // fake code to show notepad's callback/event handling
});

Design Pattern

Instances of EventProcessor are stored within a static map inside EventOperator, keyed by application names. This prevents cross-application event collisions, maintains a clean separation of events, and allows multiple applications to subscribe to the same application-specific events efficiently.

Functionality

  • Singleton Management
    • EventOperator manages singleton instances of EventProcessor for different applications. Retrieves existing instances or creates new ones as needed.
  • Subscription Management
    • Each EventProcessor manages its own subscriptions, handling the addition, emission, and removal of events. It uses a map where event names are keys, and values are Event objects that hold detailed event information and subscriptions.
  • Event Emission
    • Emitting an event updates its timestamp and the eventTimes map to meet specific timing requirements for FsWatcher.

Code Examples

EventUtils.getListOfApps()
// Output: [fakeApp, fakeApp_vsce, Zowe]

const watcherInstance = EventOperator.getWatcher('fakeApp'); 
processor.subscribeShared('sharedEvent', callback); 
processor.unsubscribe('sharedEvent');`
const bothInstance= EventOperator.getProcessor('fakeApp_vsce'); 
bothInstance.subscribeUser('userEvent', [callback1, callback2]);
bothInstance.emitEvent('userEvent'); 
bothInstance.emitEvent('otherEvent'); 
bothInstance.unsubscribe('userEvent'); 

Event Types Explained

Within our system, events are categorized into four main types:

Zowe User Events Zowe Shared Events User Events Shared Events
Event Origin Zowe CLI Zowe CLI Extender Applications Extender Applications
Use case Derived from the Zowe CLI only, these events are triggered by actions directly related to user interactions or specific user activities. Derived from the Zowe CLI only, these events are relevant to multiple users of a shared system and need to be accessible by various components or services. These events are specific to the extender’s application and are customizable. To be used for user-specific changes and settings. These events are specific to the extender’s application. To be used when an event is relevant to multiple users of a shared system or the event needs to be watched by various components or services.
Event file path  ~/.zowe/.events/Zowe/$userEventName $ZOWE_CLI_HOME/.events/Zowe/$sharedEventName  ~/.zowe/.events/$appName/$customSharedEventName $ZOWE_CLI_HOME/.events/$appName/$customSharedEventName

How to Test

Operate the sample VSCE without error:

  • Use the eeM-pre branch from zowe-cli-sample-scripts to operate a VSCE mock we have been testing with.
  • Navigate to your ZE Data Sets, right-click on an item in the list, and use the context menu to subscribe to events, emit events, and unsubscribe from events.

Review Checklist
I certify that I have:

Amber Torrise added 15 commits April 29, 2024 16:02
Signed-off-by: Amber Torrise <[email protected]>
Signed-off-by: Amber Torrise <[email protected]>
Signed-off-by: Amber Torrise <[email protected]>
Signed-off-by: Amber Torrise <[email protected]>
Signed-off-by: Amber Torrise <[email protected]>
Signed-off-by: Amber Torrise <[email protected]>
Signed-off-by: Amber Torrise <[email protected]>
… a WIP of first iteration idea change

Signed-off-by: Amber Torrise <[email protected]>
Signed-off-by: Amber Torrise <[email protected]>
@ATorrise ATorrise changed the base branch from poc-1987 to poc-1987-mvp May 9, 2024 21:44
@ATorrise ATorrise changed the title EventEmitter and EventEmitterManager class creation EventEmitter and EventEmitterManager creation May 9, 2024
@ATorrise ATorrise requested review from adam-wolfe and anaxceron May 9, 2024 21:48
…sses to index for exporting

Signed-off-by: Amber Torrise <[email protected]>
Copy link

codecov bot commented May 13, 2024

Codecov Report

Attention: Patch coverage is 86.66667% with 30 lines in your changes missing coverage. Please review.

Project coverage is 91.08%. Comparing base (7df9fce) to head (8cb0253).
Report is 2 commits behind head on next.

Files Patch % Lines
packages/imperative/src/events/src/EventUtils.ts 63.07% 24 Missing ⚠️
packages/imperative/src/config/src/ProfileInfo.ts 50.00% 3 Missing ⚠️
packages/imperative/src/events/src/Event.ts 91.66% 1 Missing ⚠️
...ckages/imperative/src/events/src/EventProcessor.ts 98.36% 1 Missing ⚠️
...tive/src/security/src/CredentialManagerOverride.ts 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             next    #2136      +/-   ##
==========================================
- Coverage   91.22%   91.08%   -0.14%     
==========================================
  Files         629      632       +3     
  Lines       17964    18007      +43     
  Branches     3831     3802      -29     
==========================================
+ Hits        16387    16402      +15     
- Misses       1576     1604      +28     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@zFernand0 zFernand0 mentioned this pull request May 13, 2024
7 tasks
Copy link
Member

@zFernand0 zFernand0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I'm not allowed to approve this PR, but FWIW...
LGTM! 😋

ATorrise added 3 commits July 1, 2024 10:18
Signed-off-by: Amber Torrise <[email protected]>
Signed-off-by: Amber Torrise <[email protected]>
Copy link
Member

@traeok traeok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your work on this @ATorrise and @zFernand0! I left a few comments, some for my own edification. It looks like there are some functions across the new Event classes that would benefit from adding @throws. I also had a question regarding the subscribe... function implementations.

Copy link
Member

@gejohnston gejohnston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trae had some comments worth considering.
However, I have nothing else to add, so I am approving.

Copy link
Member

@zFernand0 zFernand0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe all comments should be addressed in a4e268a

Thanks for the reviews.

We should have a short demo ready for later this week 😋

@ATorrise ATorrise requested a review from traeok July 2, 2024 14:29
Copy link
Member

@traeok traeok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - thanks @ATorrise @zFernand0 !

Copy link
Member

@t1m0thyj t1m0thyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just one comment about potentially redundant code

@zFernand0
Copy link
Member

Here is something worth checking, besides the few integration tests that are failing here:

The above is a workflow that shows a few tests where the .events directory may fail to be created. Something to keep in mind in case other tests fail in a similar fashion. (Thanks @gejohnston for the pointer)

Copy link

@zFernand0 zFernand0 merged commit 894607b into next Jul 11, 2024
19 checks passed
@zFernand0 zFernand0 deleted the custEventsPt2 branch July 11, 2024 21:17
Copy link

Release succeeded for the next branch. 🎉

The following packages have been published:

Powered by Octorelease 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Notify extenders when changes to the vault have been made
7 participants