Skip to content

Package: EntityAttributeMigrator

EntityAttributeMigrator

nameinstructionbranchcomplexitylinemethod
EntityAttributeMigrator()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
getEntityMigrators()
M: 16 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
migrate()
M: 110 C: 0
0%
M: 6 C: 0
0%
M: 4 C: 0
0%
M: 19 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.extras.migrator.encryption;
14:
15: import org.eclipse.kapua.KapuaException;
16: import org.eclipse.kapua.extras.migrator.encryption.api.EntitySecretAttributeMigrator;
17: import org.eclipse.kapua.extras.migrator.encryption.authentication.MfaOptionAttributeMigrator;
18: import org.eclipse.kapua.extras.migrator.encryption.job.JobStepAttributeMigrator;
19: import org.slf4j.Logger;
20: import org.slf4j.LoggerFactory;
21:
22: import java.util.Arrays;
23: import java.util.List;
24:
25: public class EntityAttributeMigrator {
26:
27: private static final Logger LOG = LoggerFactory.getLogger(EntityAttributeMigrator.class);
28:
29: private static final int PAGE_SIZE = 50;
30:
31: protected EntityAttributeMigrator() {
32: }
33:
34: public void migrate() throws KapuaException {
35: List<EntitySecretAttributeMigrator<?>> entitySecretAttributeMigrators = getEntityMigrators();
36:
37: LOG.info("Found {} entity migrators:", entitySecretAttributeMigrators.size());
38:• for (EntitySecretAttributeMigrator<?> entityAttributeMigrator : entitySecretAttributeMigrators) {
39: LOG.info(" + {} for entity {}", entityAttributeMigrator.getClass(), entityAttributeMigrator.getEntityName());
40: }
41: LOG.info("");
42:
43:• for (EntitySecretAttributeMigrator<?> entityAttributeMigrator : entitySecretAttributeMigrators) {
44: LOG.info("Migrating: {}...", entityAttributeMigrator.getEntityName());
45:
46: long totalEntitiesToMigrate = entityAttributeMigrator.getTotalCount();
47:
48: LOG.info(" Entities to migrate: {}", totalEntitiesToMigrate);
49:• for (int i = 0; i < totalEntitiesToMigrate; i = i + PAGE_SIZE) {
50: LOG.info(" Migrating entities from {} to {} - total {}", i, i + PAGE_SIZE, totalEntitiesToMigrate);
51: List entitiesToMigrate = entityAttributeMigrator.getChunk(i, PAGE_SIZE);
52:
53: entityAttributeMigrator.migrate(entitiesToMigrate);
54: }
55: LOG.info(" Entities migrated: {}", totalEntitiesToMigrate);
56: LOG.info("Migrating: {}... DONE!", entityAttributeMigrator.getEntityName());
57: LOG.info("");
58: }
59: }
60:
61: public List<EntitySecretAttributeMigrator<?>> getEntityMigrators() {
62: return Arrays.asList(
63: new JobStepAttributeMigrator(),
64: new MfaOptionAttributeMigrator()
65: );
66: }
67: }