From a47ebaa9dfb668bf44c1f5308eb1d37f503976ba Mon Sep 17 00:00:00 2001 From: masaaki Date: Sat, 2 Mar 2024 02:21:19 +0000 Subject: [PATCH] =?UTF-8?q?Merged=20PR=20798:=20[4=E5=9B=9E=E7=9B=AE?= =?UTF-8?q?=E5=AE=9F=E8=A1=8C][=E3=83=95=E3=83=AB=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF]develop=E7=92=B0=E5=A2=83=E3=81=A7=E3=81=AE=E7=A7=BB?= =?UTF-8?q?=E8=A1=8C=E5=AE=9F=E6=96=BD=E5=BE=8C=E3=81=AE=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E4=BD=9C=E6=A5=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 概要 [Task3821: [4回目実行][フルデータ]develop環境での移行実施後の修正作業](https://paruru.nds-tyo.co.jp:8443/tfs/ReciproCollection/fa4924a4-d079-4fab-9fb5-a9a11eb205f0/_workitems/edit/3821) - 元PBI or タスクへのリンク(内容・目的などはそちらにあるはず) - 移行ツールに対して以下の修正を実施しました。 - アカウントとユーザ間でAuthorIDが重複する際、通番を付与して重複を避けるようにしました - AADB2Cのエラー発生時、リトライ処理を行うように対応しました ## レビューポイント - 特にありません ## UIの変更 - 無し ## 動作確認状況 - ローカルで確認 ## 補足 - 相談、参考資料などがあれば --- .../features/transfer/transfer.controller.ts | 1 + .../src/features/transfer/transfer.service.ts | 61 +++++++------- .../src/gateways/adb2c/adb2c.service.ts | 81 +++++++++++-------- 3 files changed, 82 insertions(+), 61 deletions(-) diff --git a/data_migration_tools/server/src/features/transfer/transfer.controller.ts b/data_migration_tools/server/src/features/transfer/transfer.controller.ts index 507ed3f..c3c2dce 100644 --- a/data_migration_tools/server/src/features/transfer/transfer.controller.ts +++ b/data_migration_tools/server/src/features/transfer/transfer.controller.ts @@ -194,6 +194,7 @@ export class TransferController { const transferDuplicateAuthorResultUsers = await this.transferService.transferDuplicateAuthor( context, + resultDuplicateEmail.accountsFileLines, resultDuplicateEmail.usersFileLines ); diff --git a/data_migration_tools/server/src/features/transfer/transfer.service.ts b/data_migration_tools/server/src/features/transfer/transfer.service.ts index 60b8d5c..8168c04 100644 --- a/data_migration_tools/server/src/features/transfer/transfer.service.ts +++ b/data_migration_tools/server/src/features/transfer/transfer.service.ts @@ -627,11 +627,13 @@ export class TransferService { /** * transferDuplicateAuthor + * @param accountsFileLines: AccountsFile[] * @param usersFileLines: UsersFile[] * @returns UsersFile[] */ async transferDuplicateAuthor( context: Context, + accountsFileLines: AccountsFile[], usersFileLines: UsersFile[] ): Promise { // パラメータ内容が長大なのでログには出さない @@ -642,34 +644,39 @@ export class TransferService { try { const newUsersFileLines: UsersFile[] = []; - let processingAccountId: number = 0; //処理中のアカウントID - let duplicateSequence: number = 2; - let authorIdList: String[] = []; - for (const user of usersFileLines) { - if (user.accountId !== processingAccountId) { - //アカウントIDが別になった場合、通番を初期化する - duplicateSequence = 2; - processingAccountId = user.accountId; - authorIdList = []; - } - let assignAuthorId = user.authorId; - if (authorIdList.includes(user.authorId)) { - // 同じauthorIdがいる場合、自分のauthorIdに連番を付与する - assignAuthorId = assignAuthorId + duplicateSequence; - duplicateSequence = duplicateSequence + 1; - } - authorIdList.push(user.authorId); + for (const accountsFileLine of accountsFileLines) { + let duplicateSequence: number = 2; + let authorIdList: String[] = []; - // 新しいAuthorIdのユーザに詰め替え - const newUser: UsersFile = { - accountId: user.accountId, - userId: user.userId, - name: user.name, - role: user.role, - authorId: assignAuthorId, - email: user.email, - }; - newUsersFileLines.push(newUser); + // メールアドレス重複時はアカウントにもAuthorIdが設定されるので重複チェック用のリストに追加しておく + if (accountsFileLine.authorId) { + authorIdList.push(accountsFileLine.authorId); + } + + const targetaccountUsers = usersFileLines.filter( + (item) => item.accountId === accountsFileLine.accountId + ); + + for (const targetaccountUser of targetaccountUsers) { + let assignAuthorId = targetaccountUser.authorId; + if (authorIdList.includes(targetaccountUser.authorId)) { + // 同じauthorIdがいる場合、自分のauthorIdに連番を付与する + assignAuthorId = assignAuthorId + duplicateSequence; + duplicateSequence = duplicateSequence + 1; + } + authorIdList.push(targetaccountUser.authorId); + + // 新しいAuthorIdのユーザに詰め替え + const newUser: UsersFile = { + accountId: targetaccountUser.accountId, + userId: targetaccountUser.userId, + name: targetaccountUser.name, + role: targetaccountUser.role, + authorId: assignAuthorId, + email: targetaccountUser.email, + }; + newUsersFileLines.push(newUser); + } } return newUsersFileLines; diff --git a/data_migration_tools/server/src/gateways/adb2c/adb2c.service.ts b/data_migration_tools/server/src/gateways/adb2c/adb2c.service.ts index 5dbe646..afb2ab2 100644 --- a/data_migration_tools/server/src/gateways/adb2c/adb2c.service.ts +++ b/data_migration_tools/server/src/gateways/adb2c/adb2c.service.ts @@ -64,44 +64,57 @@ export class AdB2cService { this.logger.log( `[IN] [${context.getTrackingId()}] ${this.createUser.name}` ); - try { - // ユーザをADB2Cに登録 - const newUser = await this.graphClient.api("users/").post({ - accountEnabled: true, - displayName: username, - passwordPolicies: "DisableStrongPassword", - passwordProfile: { - forceChangePasswordNextSignIn: false, - password: password, - }, - identities: [ - { - signinType: ADB2C_SIGN_IN_TYPE.EMAILADDRESS, - issuer: `${this.tenantName}.onmicrosoft.com`, - issuerAssignedId: email, + + const retryCount: number = 3; + let retry = 0; + + while (retry < retryCount) { + try { + // ユーザをADB2Cに登録 + const newUser = await this.graphClient.api("users/").post({ + accountEnabled: true, + displayName: username, + passwordPolicies: "DisableStrongPassword", + passwordProfile: { + forceChangePasswordNextSignIn: false, + password: password, }, - ], - }); - this.logger.log( - `[${context.getTrackingId()}] [ADB2C CREATE] newUser: ${newUser}` - ); - return { sub: newUser.id }; - } catch (e) { - this.logger.error(`[${context.getTrackingId()}] error=${e}`); - if (e?.statusCode === 400 && e?.body) { - const error = JSON.parse(e.body); + identities: [ + { + signinType: ADB2C_SIGN_IN_TYPE.EMAILADDRESS, + issuer: `${this.tenantName}.onmicrosoft.com`, + issuerAssignedId: email, + }, + ], + }); + this.logger.log( + `[${context.getTrackingId()}] [ADB2C CREATE] newUser: ${newUser}` + ); + return { sub: newUser.id }; + } catch (e) { + this.logger.error(`[${context.getTrackingId()}] error=${e}`); + + if (e?.statusCode === 400 && e?.body) { + const error = JSON.parse(e.body); - // エラーが競合エラーである場合は、メールアドレス重複としてエラーを返す - if (error?.details?.find((x) => x.code === "ObjectConflict")) { - return { reason: "email", message: "ObjectConflict" }; + // エラーが競合エラーである場合は、メールアドレス重複としてエラーを返す + if (error?.details?.find((x) => x.code === "ObjectConflict")) { + return { reason: "email", message: "ObjectConflict" }; + } } - } - throw e; - } finally { - this.logger.log( - `[OUT] [${context.getTrackingId()}] ${this.createUser.name}` - ); + if (++retry < retryCount) { + this.logger.log(`ADB2Cエラー発生。5秒sleepしてリトライします (${retry}/${retryCount})...`); + await new Promise(resolve => setTimeout(resolve, 5000)); + } else { + this.logger.log(`リトライ数が上限に達したのでエラーを返却します`); + throw e; + } + } finally { + this.logger.log( + `[OUT] [${context.getTrackingId()}] ${this.createUser.name}` + ); + } } }