def _update_component_monitors(self, component_monitors): if not component_monitors: return monitors = component_monitors.get("add", []) for monitor in monitors: new_monitor = ServiceMonitor(**monitor) new_monitor.service_id = self.component.component_id new_monitor.tenant_id = self.component.tenant_id self.monitors.append(new_monitor)
def _update_component_monitors(self, component_monitors): if not component_monitors: return monitors = component_monitors.get("add", []) for monitor in monitors: new_monitor = ServiceMonitor(**monitor) new_monitor.service_id = self.component.component_id new_monitor.tenant_id = self.component.tenant_id self.monitors.append(new_monitor) self.update_action_type(ActionType.UPDATE.value)
def _create_component(snap): # component component = TenantServiceInfo(**snap["service_base"]) # component source component_source = ServiceSourceInfo(**snap["service_source"]) # environment envs = [TenantServiceEnvVar(**env) for env in snap["service_env_vars"]] # ports ports = [TenantServicesPort(**port) for port in snap["service_ports"]] # service_extend_method extend_info = ServiceExtendMethod(**snap["service_extend_method"]) # volumes volumes = [TenantServiceVolume(**volume) for volume in snap["service_volumes"]] # configuration files config_files = [TenantServiceConfigurationFile(**config_file) for config_file in snap["service_config_file"]] # probe probes = [ServiceProbe(**probe) for probe in snap["service_probes"]] # monitors monitors = [ServiceMonitor(**monitor) for monitor in snap["service_monitors"]] # graphs graphs = [ComponentGraph(**graph) for graph in snap["component_graphs"]] return Component( component=component, component_source=component_source, envs=envs, ports=ports, volumes=volumes, config_files=config_files, probe=probes[0] if probes else None, extend_info=extend_info, monitors=monitors, graphs=graphs, plugin_deps=[], )
def _create_component(self, snap): # component component = TenantServiceInfo(**snap["service_base"]) # component source component_source = ServiceSourceInfo(**snap["service_source"]) # environment envs = [TenantServiceEnvVar(**env) for env in snap["service_env_vars"]] # ports ports = [TenantServicesPort(**port) for port in snap["service_ports"]] # service_extend_method extend_info = None if snap.get("service_extend_method"): extend_info = ServiceExtendMethod( **snap.get("service_extend_method")) # volumes volumes = [ TenantServiceVolume(**volume) for volume in snap["service_volumes"] ] # configuration files config_files = [ TenantServiceConfigurationFile(**config_file) for config_file in snap["service_config_file"] ] # probe probes = [ServiceProbe(**probe) for probe in snap["service_probes"]] # monitors monitors = [ ServiceMonitor(**monitor) for monitor in snap["service_monitors"] ] # graphs graphs = [ ComponentGraph(**graph) for graph in snap["component_graphs"] ] service_labels = [ ServiceLabels(**label) for label in snap["service_labels"] ] cpt = Component( component=component, component_source=component_source, envs=envs, ports=ports, volumes=volumes, config_files=config_files, probes=probes, extend_info=extend_info, monitors=monitors, graphs=graphs, plugin_deps=[], labels=service_labels, support_labels=self.support_labels, ) cpt.action_type = snap.get("action_type", ActionType.BUILD.value) return cpt
def bulk_create_component_service_monitors(self, tenant, service, service_monitors): monitor_list = [] for monitor in service_monitors: if ServiceMonitor.objects.filter(tenant_id=tenant.tenant_id, name=monitor["name"]).count() > 0: monitor["name"] = "-".join([monitor["name"], make_uuid()[-4:]]) data = ServiceMonitor( name=monitor["name"], tenant_id=tenant.tenant_id, service_id=service.service_id, path=monitor["path"], port=monitor["port"], service_show_name=monitor["service_show_name"], interval=monitor["interval"]) monitor_list.append(data) ServiceMonitor.objects.bulk_create(monitor_list)
def _template_to_service_monitors(self, component, service_monitors): if not service_monitors: return [] monitors = [] for monitor in service_monitors: # Optimization: check all monitor names at once if ServiceMonitor.objects.filter(tenant_id=component.tenant_id, name=monitor["name"]).count() > 0: monitor["name"] = "-".join([monitor["name"], make_uuid()[-4:]]) data = ServiceMonitor( name=monitor["name"], tenant_id=component.tenant_id, service_id=component.service_id, path=monitor["path"], port=monitor["port"], service_show_name=monitor["service_show_name"], interval=monitor["interval"]) monitors.append(data) return monitors