in src/lambdas/r8s_api_handler/processors/application_processor.py [0:0]
def patch(self, event):
_LOG.debug(f'Update job definition event: {secure_event(event)}')
validate_params(event, (APPLICATION_ID_ATTR,))
applications = self.application_service.resolve_application(
event=event
)
application_id = event.get(APPLICATION_ID_ATTR)
if not applications:
_LOG.warning(f'Application with id '
f'\'{application_id}\' does not exist.')
return build_response(
code=RESPONSE_RESOURCE_NOT_FOUND_CODE,
content=f'Application with id '
f'\'{application_id}\' does not exist.'
)
application = applications[0]
application_meta = self.application_service.get_application_meta(
application=application
)
input_storage = event.get(INPUT_STORAGE_ATTR)
input_storage_obj = None
if input_storage:
_LOG.debug(f'Validating input storage \'{input_storage}\'')
input_storage_obj = self.storage_service.get_by_name(
name=input_storage)
self._validate_storage(
storage_name=input_storage,
storage=input_storage_obj,
required_type=StorageTypeEnum.DATA_SOURCE.value
)
output_storage = event.get(OUTPUT_STORAGE_ATTR)
output_storage_obj = None
if output_storage:
_LOG.debug(f'Validating output storage \'{output_storage}\'')
output_storage_obj = self.storage_service.get_by_name(
name=output_storage)
self._validate_storage(
storage_name=output_storage,
storage=output_storage_obj,
required_type=StorageTypeEnum.STORAGE.value
)
connection = event.get(CONNECTION_ATTR)
connection_obj = None
password = None
if connection:
_LOG.debug(f'Validating connection \'{connection}\'')
if not isinstance(connection, dict):
_LOG.error(f'\'{CONNECTION_ATTR}\' attribute must be a valid '
f'dict.')
return build_response(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'\'{CONNECTION_ATTR}\' attribute must be a valid '
f'dict.'
)
connection = {**application_meta.connection.as_dict(),
**connection}
password = connection.pop(PASSWORD_ATTR, None)
connection_obj = ConnectionAttribute(**connection)
description = None
if DESCRIPTION_ATTR in event:
description = event.get(DESCRIPTION_ATTR)
if not isinstance(description, str):
_LOG.error(f'Attribute \'{DESCRIPTION_ATTR}\' '
f'must be a string.')
return build_response(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'Attribute \'{DESCRIPTION_ATTR}\' '
f'must be a string.'
)
if not description:
_LOG.error(f'Description must not be empty.')
return build_response(
code=RESPONSE_BAD_REQUEST_CODE,
content=f'Description must not be empty.'
)
_LOG.debug(f'Updating application \'{application.application_id}\'')
self.application_service.update_rightsizer_application(
application=application,
description=description,
input_storage=input_storage_obj,
output_storage=output_storage_obj,
connection=connection_obj,
password=password
)
_LOG.debug(f'Saving application')
self.application_service.save(application=application)
application_dto = self.application_service.get_dto(
application=application)
_LOG.debug(f'Response: {application_dto}')
return build_response(
code=RESPONSE_OK_CODE,
content=application_dto
)