-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* crate entity, repo, do, mapper for synchronization and deletion-reconcilation.uc * add synchronization service and tests * changes in reconcilation UC * add lastSyncedAt to userEntity and change create in synchronization service * create synchronization module and move files from deletion module into it * add new interface, builders, method in userrepo and new methos in userservice, ande test cases * some changes * mofdify acount, user service and synchronization UC * add some tests, remove userIdAndExternalId interface, builder * changes in synchronizationEntity * add staus to synchronizationEntity * add update method in repo in synchronization module * fix imports, add update method and test in service * add synchromization.module, fix import, modify uc * fix in acount service test * change folder structure in synchronization module, fix test in repo * coments about chunk * add loggable, and extension of UC * add test cases to loggable and to userService * add tests to useCase in synchronizationModule * add test to UC * BC-6223-add chunks * add test cases in UC * add tests * remove private methon * refactor * add tests and change loop * add test to UC * add config * sum with promise.all * fixes typo, changes test in UC * rename testConfig file * add new command (for queueing unsynchronized entities for deletion) * add new Ansible role for moin.schule sync with users deletion queueing CronJob task * Update apps/server/src/shared/repo/user/user.repo.integration.spec.ts Co-authored-by: Bartosz Nowicki <[email protected]> * fix some issues after review * fiz error cases in uc * add test in UC * modify SynchronizationErrorLoggableException * main logic impl * fix tests * remove files that were not resolved automatically after merge * Pr fix and test implementation part1 * test impl part2 * test impl part 3 * test implementation part 3 * add needed modules and providers * add mongoDb flag * fix import order * import fix * import chnages * refactor dependencies --------- Co-authored-by: WojciechGrancow <[email protected]> Co-authored-by: Wojciech Grancow <[email protected]> Co-authored-by: micners <[email protected]> Co-authored-by: WojciechGrancow <[email protected]> Co-authored-by: Szymon Szafoni <[email protected]> Co-authored-by: sszafGCA <[email protected]>
- Loading branch information
Showing
15 changed files
with
589 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
ansible/roles/moin-schule-sync/templates/moin-schule-users-deletion-queueing-cronjob.yml.j2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
apiVersion: batch/v1 | ||
kind: CronJob | ||
metadata: | ||
namespace: {{ NAMESPACE }} | ||
labels: | ||
app: moin-schule-users-deletion-queueing-cronjob | ||
app.kubernetes.io/part-of: schulcloud-verbund | ||
app.kubernetes.io/version: {{ SCHULCLOUD_SERVER_IMAGE_TAG }} | ||
app.kubernetes.io/name: moin-schule-users-deletion-queueing-cronjob | ||
app.kubernetes.io/component: sync | ||
app.kubernetes.io/managed-by: ansible | ||
git.branch: {{ SCHULCLOUD_SERVER_BRANCH_NAME }} | ||
git.repo: {{ SCHULCLOUD_SERVER_REPO_NAME }} | ||
name: moin-schule-users-deletion-queueing-cronjob | ||
spec: | ||
schedule: "{{ MOIN_SCHULE_USERS_DELETION_QUEUEING_CRONJOB_SCHEDULE|default("@hourly", true) }}" | ||
jobTemplate: | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: moin-schule-users-deletion-queueing-cronjob | ||
image: {{ SCHULCLOUD_SERVER_IMAGE }}:{{ SCHULCLOUD_SERVER_IMAGE_TAG }} | ||
envFrom: | ||
- secretRef: | ||
name: moin-schule-sync-secret | ||
command: ['/bin/sh','-c'] | ||
args: ['npm run nest:start:deletion-console -- queue unsynced --systemId $SYSTEM_ID'] | ||
resources: | ||
limits: | ||
cpu: {{ API_CPU_LIMITS|default("2000m", true) }} | ||
memory: {{ API_MEMORY_LIMITS|default("2Gi", true) }} | ||
requests: | ||
cpu: {{ API_CPU_REQUESTS|default("100m", true) }} | ||
memory: {{ API_MEMORY_REQUESTS|default("150Mi", true) }} | ||
restartPolicy: OnFailure | ||
{% if AFFINITY_ENABLE is defined and AFFINITY_ENABLE|bool %} | ||
affinity: | ||
podAffinity: | ||
preferredDuringSchedulingIgnoredDuringExecution: | ||
- weight: 100 | ||
podAffinityTerm: | ||
labelSelector: | ||
matchExpressions: | ||
- key: app.kubernetes.io/part-of | ||
operator: In | ||
values: | ||
- schulcloud-verbund | ||
topologyKey: "kubernetes.io/hostname" | ||
namespaceSelector: {} | ||
{% endif %} | ||
metadata: | ||
labels: | ||
app: moin-schule-users-deletion-queueing-cronjob | ||
app.kubernetes.io/part-of: schulcloud-verbund | ||
app.kubernetes.io/version: {{ SCHULCLOUD_SERVER_IMAGE_TAG }} | ||
app.kubernetes.io/name: moin-schule-users-deletion-queueing-cronjob | ||
app.kubernetes.io/component: sync | ||
app.kubernetes.io/managed-by: ansible | ||
git.branch: {{ SCHULCLOUD_SERVER_BRANCH_NAME }} | ||
git.repo: {{ SCHULCLOUD_SERVER_REPO_NAME }} |
49 changes: 49 additions & 0 deletions
49
apps/server/src/modules/deletion-console/builder/unsynced-entities-options.builder.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { ObjectId } from 'bson'; | ||
import { UnsyncedEntitiesOptions } from '../interface'; | ||
import { UnsyncedEntitiesOptionsBuilder } from './unsynced-entities-options.builder'; | ||
|
||
describe(UnsyncedEntitiesOptionsBuilder.name, () => { | ||
describe(UnsyncedEntitiesOptionsBuilder.build.name, () => { | ||
describe('when called with valid arguments', () => { | ||
const setup = () => { | ||
const systemId = new ObjectId().toHexString(); | ||
const unsyncedForMinutes = 3600; | ||
const targetRefDomain = 'school'; | ||
const deleteInMinutes = 43200; | ||
const callsDelayMs = 100; | ||
|
||
const expectedOutput: UnsyncedEntitiesOptions = { | ||
systemId, | ||
unsyncedForMinutes, | ||
targetRefDomain, | ||
deleteInMinutes, | ||
callsDelayMs, | ||
}; | ||
|
||
return { | ||
systemId, | ||
unsyncedForMinutes, | ||
targetRefDomain, | ||
deleteInMinutes, | ||
callsDelayMs, | ||
expectedOutput, | ||
}; | ||
}; | ||
|
||
it('should return valid options object with expected values', () => { | ||
const { systemId, unsyncedForMinutes, targetRefDomain, deleteInMinutes, callsDelayMs, expectedOutput } = | ||
setup(); | ||
|
||
const output = UnsyncedEntitiesOptionsBuilder.build( | ||
systemId, | ||
unsyncedForMinutes, | ||
targetRefDomain, | ||
deleteInMinutes, | ||
callsDelayMs | ||
); | ||
|
||
expect(output).toStrictEqual(expectedOutput); | ||
}); | ||
}); | ||
}); | ||
}); |
20 changes: 20 additions & 0 deletions
20
apps/server/src/modules/deletion-console/builder/unsynced-entities-options.builder.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { EntityId } from '@shared/domain/types'; | ||
import { UnsyncedEntitiesOptions } from '../interface'; | ||
|
||
export class UnsyncedEntitiesOptionsBuilder { | ||
static build( | ||
systemId: EntityId, | ||
unsyncedForMinutes: number, | ||
targetRefDomain?: string, | ||
deleteInMinutes?: number, | ||
callsDelayMs?: number | ||
): UnsyncedEntitiesOptions { | ||
return { | ||
systemId, | ||
unsyncedForMinutes, | ||
targetRefDomain, | ||
deleteInMinutes, | ||
callsDelayMs, | ||
}; | ||
} | ||
} |
38 changes: 28 additions & 10 deletions
38
apps/server/src/modules/deletion-console/deletion-console.module.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,48 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { ConsoleModule } from 'nestjs-console'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { MikroOrmModule } from '@mikro-orm/nestjs'; | ||
import { HttpModule } from '@nestjs/axios'; | ||
import { ConsoleWriterModule } from '@infra/console'; | ||
import { createConfigModuleOptions } from '@src/config'; | ||
import { DeletionClient } from './deletion-client'; | ||
import { UserModule } from '@modules/user'; | ||
import { ALL_ENTITIES } from '@shared/domain/entity'; | ||
import { DB_PASSWORD, DB_URL, DB_USERNAME, createConfigModuleOptions } from '@src/config'; | ||
import { defaultMikroOrmOptions } from '@modules/server'; | ||
import { AccountModule } from '@modules/account'; | ||
import { getDeletionClientConfig } from './deletion-client/deletion-client.config'; | ||
import { FileEntity } from '../files/entity'; | ||
import { DeletionClient } from './deletion-client'; | ||
import { DeletionQueueConsole } from './deletion-queue.console'; | ||
import { DeletionExecutionConsole } from './deletion-execution.console'; | ||
import { BatchDeletionService } from './services'; | ||
import { BatchDeletionUc, DeletionExecutionUc } from './uc'; | ||
import { BatchDeletionService } from './services'; | ||
import { DeletionExecutionConsole } from './deletion-execution.console'; | ||
|
||
@Module({ | ||
imports: [ | ||
ConsoleModule, | ||
ConsoleWriterModule, | ||
HttpModule, | ||
UserModule, | ||
ConfigModule.forRoot(createConfigModuleOptions(getDeletionClientConfig)), | ||
MikroOrmModule.forRoot({ | ||
...defaultMikroOrmOptions, | ||
type: 'mongo', | ||
clientUrl: DB_URL, | ||
password: DB_PASSWORD, | ||
user: DB_USERNAME, | ||
allowGlobalContext: true, | ||
entities: [...ALL_ENTITIES, FileEntity], | ||
debug: true, | ||
}), | ||
AccountModule, | ||
HttpModule, | ||
], | ||
providers: [ | ||
DeletionClient, | ||
BatchDeletionService, | ||
BatchDeletionUc, | ||
DeletionExecutionUc, | ||
DeletionQueueConsole, | ||
BatchDeletionUc, | ||
BatchDeletionService, | ||
DeletionExecutionConsole, | ||
DeletionExecutionUc, | ||
], | ||
}) | ||
export class DeletionConsoleModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export * from './push-delete-requests-options.interface'; | ||
export * from './trigger-deletion-execution-options.interface'; | ||
export * from './unsynced-entities-options.interface'; | ||
export * from './deletion-execution-trigger-status.enum'; | ||
export * from './deletion-execution-trigger-result'; |
9 changes: 9 additions & 0 deletions
9
apps/server/src/modules/deletion-console/interface/unsynced-entities-options.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { EntityId } from '@shared/domain/types'; | ||
|
||
export interface UnsyncedEntitiesOptions { | ||
systemId: EntityId; | ||
unsyncedForMinutes: number; | ||
targetRefDomain?: string; | ||
deleteInMinutes?: number; | ||
callsDelayMs?: number; | ||
} |
Oops, something went wrong.