-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[LITE-30645] - TierConfig requests and Fulfillment requests are added…
… to the sync
- Loading branch information
Showing
17 changed files
with
916 additions
and
398 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,205 @@ | ||
from connect.eaas.core.decorators import event, schedulable | ||
from connect.eaas.core.extension import EventsApplicationBase | ||
from connect.eaas.core.responses import ( | ||
BackgroundResponse, | ||
ScheduledExecutionResponse, | ||
) | ||
from connect.client import ClientError | ||
from connect_ext_datalake.services.settings import get_settings | ||
from connect_ext_datalake.services.publish import ( | ||
publish_ff_request, | ||
) | ||
from connect_ext_datalake.services.client import GooglePubsubClient | ||
|
||
|
||
class FulfillmentEventsMixin: | ||
def __process_ff_request_event(self, ff_request): | ||
self.logger.info(f"Obtained fulfillment request with id {ff_request['id']}") | ||
hub_id = ff_request.get('asset', {}).get('connection', {}).get('hub', {}).get('id', None) | ||
if hub_id: | ||
setting = get_settings(self.installation, hub_id) | ||
if setting: | ||
try: | ||
client = GooglePubsubClient(setting) | ||
publish_ff_request( | ||
client, | ||
ff_request, | ||
self.logger, | ||
) | ||
except Exception as e: | ||
self.logger.exception( | ||
f"Publish of fulfillment request {ff_request['id']} is failed." | ||
) | ||
raise e | ||
else: | ||
self.logger.info( | ||
f"Publish of fulfillment request {ff_request['id']} is not processed" | ||
f" as settings not available for respective hub {hub_id}." | ||
) | ||
else: | ||
self.logger.info( | ||
f"Publish of fulfillment request {ff_request['id']} is not processed" | ||
f" as hub id is not found in request." | ||
) | ||
return BackgroundResponse.done() | ||
|
||
@event( | ||
'asset_suspend_request_processing', | ||
statuses=[ | ||
'pending', | ||
'approved', | ||
'failed', | ||
'scheduled', | ||
'revoking', | ||
'revoked', | ||
], | ||
) | ||
def handle_asset_suspend_request_processing(self, ff_request): | ||
return self.__process_ff_request_event(ff_request) | ||
|
||
@event( | ||
'asset_adjustment_request_processing', | ||
statuses=[ | ||
'pending', | ||
'approved', | ||
'failed', | ||
'inquiring', | ||
'scheduled', | ||
'revoking', | ||
'revoked', | ||
], | ||
) | ||
def handle_asset_adjustment_request_processing(self, ff_request): | ||
return self.__process_ff_request_event(ff_request) | ||
|
||
@event( | ||
'asset_cancel_request_processing', | ||
statuses=[ | ||
'pending', | ||
'approved', | ||
'failed', | ||
'scheduled', | ||
'revoking', | ||
'revoked', | ||
], | ||
) | ||
def handle_asset_cancel_request_processing(self, ff_request): | ||
return self.__process_ff_request_event(ff_request) | ||
|
||
@event( | ||
'tier_account_update_request_processing', | ||
statuses=[ | ||
'pending', | ||
'accepted', | ||
'ignored', | ||
], | ||
) | ||
def handle_tier_account_update_request_processing(self, ff_request): | ||
return self.__process_ff_request_event(ff_request) | ||
|
||
@event( | ||
'asset_purchase_request_processing', | ||
statuses=[ | ||
'pending', | ||
'approved', | ||
'failed', | ||
'inquiring', | ||
'scheduled', | ||
'revoking', | ||
'revoked', | ||
], | ||
) | ||
def handle_asset_purchase_request_processing(self, ff_request): | ||
return self.__process_ff_request_event(ff_request) | ||
|
||
@event( | ||
'asset_change_request_processing', | ||
statuses=[ | ||
'pending', | ||
'approved', | ||
'failed', | ||
'inquiring', | ||
'scheduled', | ||
'revoking', | ||
'revoked', | ||
], | ||
) | ||
def handle_asset_change_request_processing(self, ff_request): | ||
return self.__process_ff_request_event(ff_request) | ||
|
||
@event( | ||
'asset_resume_request_processing', | ||
statuses=[ | ||
'pending', | ||
'approved', | ||
'failed', | ||
'scheduled', | ||
'revoking', | ||
'revoked', | ||
], | ||
) | ||
def handle_asset_resume_request_processing(self, ff_request): | ||
return self.__process_ff_request_event(ff_request) | ||
|
||
|
||
class FulfillmentTasksMixin: | ||
@schedulable( | ||
'Publish FF Requests', | ||
'Publish FF Requests to Xvantage Goggle PubSub Topic.', | ||
) | ||
def publish_ff_requests(self, schedule): | ||
self.logger.info( | ||
f"Start of execution for schedule {schedule['id']} " f'for publishing all ff requests' | ||
) | ||
try: | ||
installation_id = schedule['parameter']['installation_id'] | ||
installation_client = self.get_installation_admin_client(installation_id) | ||
installation_client.resourceset_append = False | ||
|
||
installation = installation_client('devops').installations[installation_id].get() | ||
count = installation_client('requests').all().count() | ||
self.logger.info(f'Total number of ff requests: {count}') | ||
prs = ( | ||
installation_client('requests') | ||
.all() | ||
.select( | ||
'-asset', | ||
'-template', | ||
'-connection', | ||
'-params', | ||
'-contract', | ||
'-marketplace', | ||
'-previous_approved_request', | ||
) | ||
) | ||
counter = 1 | ||
|
||
for pr in prs: | ||
try: | ||
pr_full = installation_client('requests').get(pr['id']) | ||
hub_id = pr_full['asset']['connection']['hub']['id'] | ||
|
||
setting = get_settings(installation, hub_id) | ||
if setting: | ||
pubsub_client = GooglePubsubClient(setting) | ||
self.logger.info(f'Processing PR in {counter} position') | ||
publish_ff_request( | ||
pubsub_client, | ||
pr_full, | ||
self.logger, | ||
) | ||
else: | ||
self.logger.info( | ||
f"Publish of PR {pr['id']} is not processed" | ||
f" as settings not available for respective hub." | ||
) | ||
counter += 1 | ||
except (ClientError, GoogleAPIError): | ||
self.logger.exception( | ||
f"Problem in while publishing Fulfillment request {pr['id']}." | ||
) | ||
except ClientError as e: | ||
self.logger.exception('Problem in calling Connect or Google APIs.') | ||
raise e | ||
|
||
return ScheduledExecutionResponse.done() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.