def get_latest_upgrade_record(tenant: Tenants, app: ServiceGroup, upgrade_group_id=None, record_type=None): if upgrade_group_id: # check upgrade_group_id tenant_service_group_repo.get_component_group(upgrade_group_id) record = upgrade_repo.get_last_upgrade_record(tenant.tenant_id, app.app_id, upgrade_group_id, record_type) return record.to_dict() if record else None
def create_upgrade_record(self, enterprise_id, tenant: Tenants, app: ServiceGroup, upgrade_group_id): component_group = tenant_service_group_repo.get_component_group( upgrade_group_id) # If there are unfinished record, it is not allowed to create new record last_record = upgrade_repo.get_last_upgrade_record( tenant.tenant_id, app.ID, upgrade_group_id) if last_record and not last_record.is_finished(): raise ErrLastRecordUnfinished component_group = ComponentGroup(enterprise_id, component_group) app_template_source = component_group.app_template_source() # create new record record = { "tenant_id": tenant.tenant_id, "group_id": app.app_id, "group_key": component_group.app_model_key, "group_name": app.app_name, "create_time": datetime.now(), "is_from_cloud": component_group.is_install_from_cloud(), "market_name": app_template_source.get_market_name(), "upgrade_group_id": upgrade_group_id, "old_version": component_group.version, "record_type": AppUpgradeRecordType.UPGRADE.value, } record = upgrade_repo.create_app_upgrade_record(**record) return record.to_dict()
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 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_property_changes(self, tenant, region, user, app, upgrade_group_id, version): component_group = tenant_service_group_repo.get_component_group(upgrade_group_id) app_template_source = self._app_template_source(app.app_id, component_group.group_key, upgrade_group_id) app_template = self._app_template(user.enterprise_id, component_group.group_key, version, app_template_source) app_upgrade = AppUpgrade(user.enterprise_id, tenant, region, user, app, version, component_group, app_template, app_template_source.is_install_from_cloud(), app_template_source.get_market_name()) return app_upgrade.changes()
def upgrade_component(self, tenant, region, user, app, component: TenantServiceInfo, version): component_group = tenant_service_group_repo.get_component_group(component.upgrade_group_id) app_template_source = service_source_repo.get_service_source(component.tenant_id, component.component_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(), component_keys=[component.service_key], is_deploy=True, is_upgrade_one=True) app_upgrade.upgrade()