def sync_record(self, tenant_name, region_name, record: AppUpgradeRecord): # list component records component_records = component_upgrade_record_repo.list_by_app_record_id( record.ID) # filter out the finished records unfinished = { record.event_id: record for record in component_records if not record.is_finished() } # list events event_ids = [event_id for event_id in unfinished.keys()] body = region_api.get_tenant_events(region_name, tenant_name, event_ids) events = body.get("list", []) for event in events: component_record = unfinished.get(event["EventID"]) if not component_record: continue self._update_component_record_status(component_record, event["Status"]) self._update_app_record_status(record, component_records) # save app record and component records self.save_upgrade_record(record, component_records)
def upgrade(self, tenant, region, user, app, version, record: AppUpgradeRecord, component_keys=None): """ Upgrade application market applications """ if not record.can_upgrade(): raise ErrAppUpgradeWrongStatus component_group = tenant_service_group_repo.get_component_group(record.upgrade_group_id) app_template_source = self._app_template_source(record.group_id, record.group_key, record.upgrade_group_id) app_template = self._app_template(user.enterprise_id, component_group.group_key, version, app_template_source) app_upgrade = AppUpgrade( tenant.enterprise_id, tenant, region, user, app, version, component_group, app_template, app_template_source.is_install_from_cloud(), app_template_source.get_market_name(), record, component_keys, is_deploy=True) record = app_upgrade.upgrade() app_template_name = component_group.group_alias return self.serialized_upgrade_record(record), app_template_name
def deploy(self, tenant, region_name, user, record: AppUpgradeRecord): if not record.can_deploy(): raise ErrAppUpgradeRecordCanNotDeploy # failed events component_records = component_upgrade_record_repo.list_by_app_record_id(record.ID) component_records = [record for record in component_records] failed_component_records = { record.event_id: record for record in component_records if record.status in [UpgradeStatus.PARTIAL_UPGRADED.value, UpgradeStatus.PARTIAL_ROLLBACK.value, UpgradeStatus.DEPLOY_FAILED.value] } component_ids = [record.service_id for record in failed_component_records.values()] try: events = app_manage_service.batch_operations(tenant, region_name, user, "deploy", component_ids) status = UpgradeStatus.UPGRADING.value \ if record.record_type == UpgradeType.UPGRADE.value else UpgradeStatus.ROLLING.value upgrade_repo.change_app_record_status(record, status) except ServiceHandleException as e: upgrade_repo.change_app_record_status(record, UpgradeStatus.DEPLOY_FAILED.value) raise ErrAppUpgradeDeployFailed(e.msg) except Exception as e: upgrade_repo.change_app_record_status(record, UpgradeStatus.DEPLOY_FAILED.value) raise e self._update_component_records(record, failed_component_records.values(), events)
def restore(self, tenant, region, user, app, record: AppUpgradeRecord): if not record.can_rollback(): raise ErrAppUpgradeRecordCanNotRollback component_group = tenant_service_group_repo.get_component_group(record.upgrade_group_id) app_restore = AppRestore(tenant, region, user, app, component_group, record) record, component_group = app_restore.restore() return self.serialized_upgrade_record(record), component_group.group_alias
def get_app_not_upgrade_record(self, tenant_id, group_id, group_key): """获取未完成升级记录""" recode_kwargs = { "tenant_id": tenant_id, "group_id": int(group_id), "group_key": group_key, } try: return upgrade_repo.get_app_not_upgrade_record(status__lt=UpgradeStatus.UPGRADED.value, **recode_kwargs) except AppUpgradeRecord.DoesNotExist: return AppUpgradeRecord()
def init(self): self.sources = [ Tenants(), TenantRegionInfo(), TenantRegionResource(), ServiceInfo(), TenantServiceInfo(), TenantServiceInfoDelete(), TenantServiceLog(), TenantServiceRelation(), TenantServiceEnv(), TenantServiceAuth(), TenantServiceExtendMethod(), ServiceDomain(), ServiceDomainCertificate(), PermRelService(), PermRelTenant(), PhoneCode(), TenantServiceL7Info(), TenantServiceEnvVar(), TenantServicesPort(), TenantServiceMountRelation(), TenantServiceVolume(), TenantServiceConfigurationFile(), ServiceGroup(), ServiceGroupRelation(), ImageServiceRelation(), ComposeServiceRelation(), ServiceRule(), ServiceRuleHistory(), ServiceCreateStep(), ServiceProbe(), ConsoleConfig(), TenantEnterprise(), TenantEnterpriseToken(), TenantServiceGroup(), ServiceTcpDomain(), ThirdPartyServiceEndpoints(), ServiceWebhooks(), GatewayCustomConfiguration(), ConsoleSysConfig(), RainbondCenterApp(), RainbondCenterAppInherit(), RainbondCenterPlugin(), ServiceShareRecord(), EnterpriseUserPerm(), TenantUserRole(), TenantUserPermission(), TenantUserRolePermission(), PermGroup(), ServiceRelPerms(), AppExportRecord(), UserMessage(), AppImportRecord(), GroupAppBackupRecord(), GroupAppMigrateRecord(), GroupAppBackupImportRecord(), Applicants(), DeployRelation(), ServiceBuildSource(), TenantServiceBackup(), AppUpgradeRecord(), ServiceUpgradeRecord(), RegionConfig(), CloundBangImages(), Announcement(), ]