in src/main.py [0:0]
def __init__(self, ggv2_component_config):
'''
Initialises the AWS Greengrass V2 custom component including the IPC and MQTT PubSub Client
Greengrass Config expected to be passed from AWS Greengrass V2 deployment recipe.
'''
try:
#######################################################
# Log the start of the process
log.info('Initialising AWS Greengrass V2 Component')
super().__init__()
#######################################################
# Parse config passed to service from AWS Greengrass recipe
log.info('Parsing AWS Greengrass V2 Config.')
log.info('AWS Greengrass V2 Config: {}'.format(ggv2_component_config))
# This variable is returned in response to a component health_check request.
# Update it through the component logic with any valid object to describe
# the current component status.
self.health_status = {
"health-status-code" : 200,
"health-status: ": "healthy",
"last_status_message" : "initilised component"
}
# Common variables for all components in this framework / architecture
self.mqtt_pubsub_timeout = ggv2_component_config['mqtt_pubsub_timeout']
self.ipc_pubsub_timeout = ggv2_component_config['ipc_pubsub_timeout']
# MQTT Service, Data and Broadcast Topics
self.mqtt_service_topic = ggv2_component_config['mqtt_service_topic']
self.mqtt_data_topic = ggv2_component_config['mqtt_data_topic']
self.mqtt_broadcast_topic = ggv2_component_config['mqtt_broadcast_topic']
self.mqtt_subscribe_topics = ggv2_component_config['mqtt_subscribe_topics']
# IPC Service, Data and Broadcast Topics
self.ipc_service_topic = ggv2_component_config['ipc_service_topic']
self.ipc_data_topic = ggv2_component_config['ipc_data_topic']
self.ipc_broadcast_topic = ggv2_component_config['ipc_broadcast_topic']
self.ipc_subscribe_topics = ggv2_component_config['ipc_subscribe_topics']
# Completed processing recipe driven config for the Greengrass application.
log.info('Parsing AWS Greengrass V2 Config Complete.')
#######################################################
# Init local Topic and MQTT IoT Core PubSub message service.
log.info('Initialising IPC Topic PubSub message type / formats.')
self.pubsub_messages = PubSubMessages()
log.info('Initialising IPC Topic PubSub inter-service messaging.')
self.ipc_pubsub = IpcPubSub(self.pubsub_message_callback, self.ipc_subscribe_topics, self.ipc_pubsub_timeout)
log.info('Initialising IPC MQTT IoT Core PubSub messaging.')
self.mqtt_pubsub = MqttPubSub(self.pubsub_message_callback, self.mqtt_subscribe_topics, self.mqtt_pubsub_timeout)
log.info('Initialising AWS Greengrass V2 Component Complete.')
except ValueError as val_error: # pragma: no cover
log.error('VAL_ERROR: JSON Parsing Error / Unexpected component recipe config message format. ERROR MESSAGE: {} - GG CONFIG: {}'.format(val_error, ggv2_component_config))
except KeyError as key_error: # pragma: no cover
log.error('KEY_ERROR: Component recipe config missing required fields. ERROR MESSAGE: {} - GG CONFIG: {}'.format(key_error, ggv2_component_config))
except Exception as err: # pragma: no cover
log.error('EXCEPTION: Exception raised initialising AwsGreengrassV2Component. ERROR MESSAGE: {} - GG CONFIG: {}'.format(err, ggv2_component_config))