Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,19 @@ protected void migrateAuthorizations() {

protected void migrateTenant(Tenant tenant) {
try {
IdentityMigratorLogs.logMigratingTenant(tenant.getId());
IdentityMigratorLogs.logMigratingTenant(tenant);
c8Client.createTenant(tenant);
IdentityMigratorLogs.logMigratedTenant(tenant.getId());
IdentityMigratorLogs.logMigratedTenant(tenant);
saveRecord(IdKeyMapper.TYPE.TENANT, tenant.getId(), DEFAULT_TENANT_KEY);
} catch (MigratorException e) {
markAsSkipped(IdKeyMapper.TYPE.TENANT, tenant.getId(), e.getMessage());
markAsSkipped(tenant, e.getMessage());
return; // Only migrate memberships if tenant migration was successful
}
migrateTenantMemberships(tenant.getId());
}

protected void migrateAuthorization(Authorization authorization) {
IdentityMigratorLogs.logMigratingAuthorization(authorization.getId());
IdentityMigratorLogs.logMigratingAuthorization(authorization);
AuthorizationMappingResult mappingResult = authorizationManager.mapAuthorization(authorization);

if (mappingResult.isSuccess()) {
Expand All @@ -139,13 +139,13 @@ protected void migrateAuthorization(Authorization authorization) {
IdentityMigratorLogs.logMigratedChildAuthorization(auth.resourceId());
}
}
IdentityMigratorLogs.logMigratedAuthorization(authorization.getId());
IdentityMigratorLogs.logMigratedAuthorization(authorization);
saveRecord(IdKeyMapper.TYPE.AUTHORIZATION, authorization.getId(), migratedAuths.getFirst().getAuthorizationKey());
} catch (MigratorException e) {
markAsSkipped(IdKeyMapper.TYPE.AUTHORIZATION, authorization.getId(), e.getMessage());
markAsSkipped(authorization, e.getMessage());
}
} else {
markAsSkipped(IdKeyMapper.TYPE.AUTHORIZATION, authorization.getId(), mappingResult.getReason());
markAsSkipped(authorization, mappingResult.getReason());
}
}

Expand Down Expand Up @@ -177,13 +177,17 @@ protected void migrateTenantMemberships(String tenantId) {
}
}

protected void markAsSkipped(IdKeyMapper.TYPE type, String id, String reason) {
switch (type) {
case TENANT -> IdentityMigratorLogs.logSkippedTenant(id);
case AUTHORIZATION -> IdentityMigratorLogs.logSkippedAuthorization(id, reason);
protected void markAsSkipped(Authorization authorization, String reason) {
IdentityMigratorLogs.logSkippedAuthorization(authorization, reason);
if (MIGRATE.equals(mode)) {
saveRecord(IdKeyMapper.TYPE.AUTHORIZATION, authorization.getId(), null);
}
}

protected void markAsSkipped(Tenant tenant, String reason) {
IdentityMigratorLogs.logSkippedTenant(tenant, reason);
if (MIGRATE.equals(mode)) {
saveRecord(type, id, null);
saveRecord(IdKeyMapper.TYPE.TENANT, tenant.getId(), null);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
import io.camunda.migration.data.IdentityMigrator;
import io.camunda.migration.data.impl.persistence.IdKeyMapper;
import java.util.Optional;
import org.apache.commons.lang3.StringUtils;
import org.camunda.bpm.engine.authorization.Authorization;
import org.camunda.bpm.engine.identity.Tenant;
import org.camunda.bpm.engine.impl.util.ResourceTypeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -18,18 +22,18 @@ public class IdentityMigratorLogs {
protected static final Logger LOGGER = LoggerFactory.getLogger(IdentityMigrator.class);

// Event log constants
public static final String MIGRATING_TENANT = "Migrating tenant [{}]";
public static final String MIGRATING_TENANT = "Migrating tenant [{}] (name: {})";
public static final String MIGRATING_TENANT_MEMBERSHIPS = "Migrating tenant memberships for tenant [{}]";
public static final String MIGRATING_TENANT_MEMBERSHIP = "Migrating tenant membership for tenant [{}] and {} [{}]";
public static final String MIGRATED_TENANT_MEMBERSHIP = "Successfully migrated tenant membership for tenant [{}] and {} [{}]";
public static final String CANNOT_MIGRATE_TENANT_MEMBERSHIP = "There was an error while migrating tenant membership for tenant [{}] and {} [{}]: {}";
public static final String SUCCESSFULLY_MIGRATED_TENANT = "Successfully migrated tenant [{}]";
public static final String SKIPPED_TENANT = "Tenant with ID [{}] was skipped";
public static final String MIGRATING_AUTH = "Migrating authorization [{}]";
public static final String SUCCESSFULLY_MIGRATED_TENANT = "Successfully migrated tenant [{}] (name: {})";
public static final String SKIPPED_TENANT = "Tenant with ID [{}] (name: {}) was skipped: {}";
public static final String MIGRATING_AUTH = "Migrating authorization [{}] for {} [{}] on {} [{}]";
public static final String MIGRATING_CHILD_AUTH = "Migrating child authorization for resource [{}]";
public static final String SUCCESSFULLY_MIGRATED_CHILD_AUTH = "Successfully migrated child authorization for resource [{}]";
public static final String SUCCESSFULLY_MIGRATED_AUTH = "Successfully migrated authorization [{}]";
public static final String SKIPPED_AUTH = "Authorization with ID [{}] was skipped: {}";
public static final String SUCCESSFULLY_MIGRATED_AUTH = "Successfully migrated authorization [{}] for {} [{}] on {} [{}]";
public static final String SKIPPED_AUTH = "Authorization with ID [{}] for {} [{}] on {} [{}] was skipped: {}";
public static final String FOUND_DEFINITIONS_IN_DEPLOYMENT = "Found {} definitions for deployment [{}]";
public static final String FOUND_CMMN_IN_DEPLOYMENT = "Found {} CMMN resources for deployment [{}], but CMMN is not supported in Camunda 8";
public static final String STARTING_MIGRATION_OF_ENTITIES = "Starting migration of {} entities";
Expand All @@ -50,20 +54,21 @@ public static void logMigratingEntities(IdKeyMapper.TYPE type) {
LOGGER.info(STARTING_MIGRATION_OF_ENTITIES, type.name().toLowerCase());
}

public static void logMigratingTenant(String tenantId) {
LOGGER.debug(MIGRATING_TENANT, tenantId);
public static void logMigratingTenant(Tenant tenant) {
LOGGER.debug(MIGRATING_TENANT, tenant.getId(), tenant.getName());
}

public static void logMigratedTenant(String tenantId) {
LOGGER.info(SUCCESSFULLY_MIGRATED_TENANT, tenantId);
public static void logMigratedTenant(Tenant tenant) {
LOGGER.info(SUCCESSFULLY_MIGRATED_TENANT, tenant.getId(), tenant.getName());
}

public static void logSkippedTenant(String tenantId) {
LOGGER.warn(SKIPPED_TENANT, tenantId);
public static void logSkippedTenant(Tenant tenant, String reason) {
LOGGER.warn(SKIPPED_TENANT, tenant.getId(), tenant.getName(), reason);
}

public static void logMigratingAuthorization(String authId) {
LOGGER.debug(MIGRATING_AUTH, authId);
public static void logMigratingAuthorization(Authorization authorization) {
LOGGER.debug(MIGRATING_AUTH, authorization.getId(), ownerType(authorization), ownerId(authorization),
resourceTypeName(authorization), authorization.getResourceId());
}

public static void logMigratingChildAuthorization(String resourceId) {
Expand All @@ -74,12 +79,14 @@ public static void logMigratedChildAuthorization(String resourceId) {
LOGGER.debug(SUCCESSFULLY_MIGRATED_CHILD_AUTH, resourceId);
}

public static void logMigratedAuthorization(String authId) {
LOGGER.info(SUCCESSFULLY_MIGRATED_AUTH, authId);
public static void logMigratedAuthorization(Authorization authorization) {
LOGGER.info(SUCCESSFULLY_MIGRATED_AUTH, authorization.getId(), ownerType(authorization), ownerId(authorization),
resourceTypeName(authorization), authorization.getResourceId());
}

public static void logSkippedAuthorization(String authId, String reason) {
LOGGER.warn(SKIPPED_AUTH, authId, reason);
public static void logSkippedAuthorization(Authorization authorization, String reason) {
LOGGER.warn(SKIPPED_AUTH, authorization.getId(), ownerType(authorization), ownerId(authorization),
resourceTypeName(authorization), authorization.getResourceId(), reason);
}

public static void foundDefinitionsInDeployment(int count, String deploymentId) {
Expand Down Expand Up @@ -117,4 +124,16 @@ public static void logMigratedTenantMembership(String tenantId, String type, Str
public static void logCannotMigrateTenantMembership(String tenantId, String type, String userOrGroupId, String reason) {
LOGGER.warn(CANNOT_MIGRATE_TENANT_MEMBERSHIP, tenantId, type, userOrGroupId, reason);
}

static String ownerType(Authorization authorization) {
return StringUtils.isNotBlank(authorization.getUserId()) ? "user" : "group";
}

static String ownerId(Authorization authorization) {
return StringUtils.isNotBlank(authorization.getUserId()) ? authorization.getUserId() : authorization.getGroupId();
}

static String resourceTypeName(Authorization authorization) {
return ResourceTypeUtil.getResourceByType(authorization.getResourceType()).resourceName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package io.camunda.migration.data.impl.util;

import io.camunda.client.api.command.ClientException;
import io.camunda.client.api.command.ProblemException;
import io.camunda.migration.data.exception.HistoryMigratorException;
import io.camunda.migration.data.exception.IdentityMigratorException;
import io.camunda.migration.data.exception.MigratorException;
Expand Down Expand Up @@ -81,7 +82,11 @@ public static MigratorException wrapException(String message, Exception e) {
exception = new RuntimeMigratorException(message, e);
}

LOGGER.error(message, exception);
if (context == ExceptionContext.IDENTITY && e instanceof ProblemException pe && pe.details().getStatus() == 409) {
LOGGER.warn("{}: {}", message, pe.details().getDetail());
} else {
LOGGER.error(message, exception);
}
return exception;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
*/
package io.camunda.migration.data.qa.identity;

import static io.camunda.migration.data.impl.logging.IdentityMigratorLogs.SKIPPED_AUTH;
import static io.camunda.migration.data.impl.logging.IdentityMigratorLogs.SKIPPED_TENANT;
import static io.camunda.migration.data.qa.util.LogMessageFormatter.formatMessage;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.tuple;
import static org.awaitility.Awaitility.await;
Expand Down Expand Up @@ -170,11 +167,18 @@ protected void assertThatTenantsContain(List<org.camunda.bpm.engine.identity.Ten
}

protected void verifyAuthorizationSkippedViaLogs(String authorizationId, String reason, LogCapturer logs) {
logs.assertContains(formatMessage(SKIPPED_AUTH, authorizationId, reason));
assertThat(logs.getEvents())
.as("Expected a skip log for authorization [%s] with reason: %s", authorizationId, reason)
.anySatisfy(event -> {
assertThat(event.getMessage()).contains(authorizationId);
assertThat(event.getMessage()).contains(reason);
});
}

protected void verifyTenantSkippedViaLogs(String tenantId, LogCapturer logs) {
logs.assertContains(formatMessage(SKIPPED_TENANT, tenantId));
assertThat(logs.getEvents())
.as("Expected a skip log for tenant [%s]", tenantId)
.anySatisfy(event -> assertThat(event.getMessage()).contains(tenantId));
}

protected void assertThatUsersForTenantContainExactly(String tenantId, String... usernames) {
Expand Down