From 7f87c720d0fce09972e1293d2350e1cbf94e4634 Mon Sep 17 00:00:00 2001 From: abirembaut Date: Fri, 1 Dec 2023 12:20:24 +0100 Subject: [PATCH] feat(maintenance mode): rename AvailableWhenTenantIsPaused annotation (#2805) * rename AvailableWhenTenantIsPaused into AvailableInMaintenanceMode * refactor code in ServerAPIImpl to stop calling tenantAdministrationAPI.isPaused() * update logs --- .../engine/api/impl/ApplicationAPIImpl.java | 2 +- ...d.java => AvailableInMaintenanceMode.java} | 7 +- .../engine/api/impl/IdentityAPIImpl.java | 2 +- .../engine/api/impl/LoginAPIImpl.java | 6 +- .../engine/api/impl/MaintenanceAPIImpl.java | 2 +- .../engine/api/impl/OrganizationAPIImpl.java | 2 +- .../engine/api/impl/PageAPIImpl.java | 2 +- .../engine/api/impl/PermissionAPIImpl.java | 2 +- .../engine/api/impl/ProfileAPIImpl.java | 2 +- .../engine/api/impl/ServerAPIImpl.java | 73 ++++++------ .../api/impl/TenantAdministrationAPIImpl.java | 18 +-- .../engine/api/impl/ProfileAPIImplTest.java | 2 +- .../engine/api/impl/ServerAPIImplTest.java | 106 ++++++++++-------- .../impl/TenantAdministrationAPIImplTest.java | 18 +-- .../impl/profile/ProfileAPIIDelegateTest.java | 4 +- 15 files changed, 129 insertions(+), 119 deletions(-) rename bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/{AvailableWhenTenantIsPaused.java => AvailableInMaintenanceMode.java} (83%) diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java index 6d4f06bc4d0..573515b2bdc 100755 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ApplicationAPIImpl.java @@ -59,7 +59,7 @@ /** * @author Elias Ricken de Medeiros */ -@AvailableWhenTenantIsPaused +@AvailableInMaintenanceMode public class ApplicationAPIImpl implements ApplicationAPI { /** diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/AvailableWhenTenantIsPaused.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/AvailableInMaintenanceMode.java similarity index 83% rename from bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/AvailableWhenTenantIsPaused.java rename to bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/AvailableInMaintenanceMode.java index 3f2aa5aef80..437ab260cde 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/AvailableWhenTenantIsPaused.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/AvailableInMaintenanceMode.java @@ -19,17 +19,18 @@ import java.lang.annotation.Target; /** - * Used to identify tenant-level API methods that can be called if a the tenant is in a pause mode. All other API method + * Used to identify API methods that can be called if the maintenance mode is enabled. All other API method * calls will be rejected. * Used by the Bonita Engine server interceptor. * * @author Emmanuel Duchastenier * @author Matthieu Chaffotte + * @author Anthony Birembaut */ @Target({ ElementType.METHOD, ElementType.TYPE }) @Retention(RetentionPolicy.RUNTIME) -public @interface AvailableWhenTenantIsPaused { +public @interface AvailableInMaintenanceMode { - boolean onlyAvailableWhenPaused() default false; + boolean onlyAvailableInMaintenanceMode() default false; } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/IdentityAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/IdentityAPIImpl.java index afc7ede8ba3..e4bc625c7f5 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/IdentityAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/IdentityAPIImpl.java @@ -63,7 +63,7 @@ * @author Hongwen Zang * @author Celine Souchet */ -@AvailableWhenTenantIsPaused +@AvailableInMaintenanceMode @Slf4j public class IdentityAPIImpl implements IdentityAPI { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/LoginAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/LoginAPIImpl.java index cd830c17cc8..b39c02eb6d5 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/LoginAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/LoginAPIImpl.java @@ -50,7 +50,7 @@ public class LoginAPIImpl implements LoginAPI { @Override @CustomTransactions - @AvailableWhenTenantIsPaused + @AvailableInMaintenanceMode public APISession login(final String userName, final String password) throws LoginException { try { return loginInternal(userName, password); @@ -62,7 +62,7 @@ public APISession login(final String userName, final String password) throws Log } @CustomTransactions - @AvailableWhenTenantIsPaused + @AvailableInMaintenanceMode protected APISession login(final String userName, final String password, final Long tenantId) throws LoginException { try { @@ -76,7 +76,7 @@ protected APISession login(final String userName, final String password, final L @Override @CustomTransactions - @AvailableWhenTenantIsPaused + @AvailableInMaintenanceMode public APISession login(final Map credentials) throws LoginException { checkCredentialsAreNotNullOrEmpty(credentials); try { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/MaintenanceAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/MaintenanceAPIImpl.java index 0f5ce264a68..4c36c20ee0d 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/MaintenanceAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/MaintenanceAPIImpl.java @@ -36,7 +36,7 @@ /** * This API gives access to maintenance administration tasks. */ -@AvailableWhenTenantIsPaused +@AvailableInMaintenanceMode public class MaintenanceAPIImpl implements MaintenanceAPI { public MaintenanceAPIImpl() { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/OrganizationAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/OrganizationAPIImpl.java index 1504900594f..8ec1b912bbe 100755 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/OrganizationAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/OrganizationAPIImpl.java @@ -35,7 +35,7 @@ /** * @author Elias Ricken de Medeiros */ -@AvailableWhenTenantIsPaused +@AvailableInMaintenanceMode public class OrganizationAPIImpl { private final ServiceAccessor serviceAccessor; diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PageAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PageAPIImpl.java index 03991970d07..e8e7e7864c0 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PageAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PageAPIImpl.java @@ -31,7 +31,7 @@ import org.bonitasoft.engine.service.ServiceAccessor; import org.bonitasoft.engine.service.ServiceAccessorSingleton; -@AvailableWhenTenantIsPaused +@AvailableInMaintenanceMode public class PageAPIImpl implements PageAPI { protected ServiceAccessor getServiceAccessor() { diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PermissionAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PermissionAPIImpl.java index 0555a429c68..03931ce35ff 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PermissionAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/PermissionAPIImpl.java @@ -29,7 +29,7 @@ * @author Baptiste Mesta */ @Slf4j -@AvailableWhenTenantIsPaused +@AvailableInMaintenanceMode public class PermissionAPIImpl implements PermissionAPI { @Override diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProfileAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProfileAPIImpl.java index adcbb380dbc..376ee4750c2 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProfileAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ProfileAPIImpl.java @@ -38,7 +38,7 @@ * @author Celine Souchet * @author Matthieu Chaffotte */ -@AvailableWhenTenantIsPaused +@AvailableInMaintenanceMode public class ProfileAPIImpl implements ProfileAPI { @VisibleForTesting diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ServerAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ServerAPIImpl.java index ec099c92391..26241b8f519 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ServerAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/ServerAPIImpl.java @@ -28,9 +28,9 @@ import java.util.concurrent.TimeUnit; import java.util.function.Supplier; +import org.bonitasoft.engine.api.MaintenanceAPI; import org.bonitasoft.engine.api.NoSessionRequired; import org.bonitasoft.engine.api.PlatformAPI; -import org.bonitasoft.engine.api.TenantAdministrationAPI; import org.bonitasoft.engine.api.impl.transaction.CustomTransactions; import org.bonitasoft.engine.api.internal.ServerAPI; import org.bonitasoft.engine.api.internal.ServerWrappedException; @@ -45,6 +45,7 @@ import org.bonitasoft.engine.exception.*; import org.bonitasoft.engine.lock.BonitaLock; import org.bonitasoft.engine.lock.LockService; +import org.bonitasoft.engine.maintenance.MaintenanceDetails; import org.bonitasoft.engine.platform.NodeNotStartedException; import org.bonitasoft.engine.platform.PlatformService; import org.bonitasoft.engine.platform.PlatformState; @@ -69,10 +70,11 @@ * valid, is on the right scope (tenant or platform), and renew it *
  • When the method is NOT annotated with {@link CustomTransactions}, it opens a transaction
  • *
  • When the method is deprecated, it print a warning
  • - *
  • When the method or class is annotated with {@link AvailableWhenTenantIsPaused}, it verifies the tenant is - * paused
  • - *
  • When the method or class is annotated with {@link AvailableWhenTenantIsPaused} and onlyAvailableWhenPaused is set - * to true, it verifies the tenant is running
  • + *
  • When the method or class is annotated with {@link AvailableInMaintenanceMode}, it verifies the maintenance mode + * is enabled
  • + *
  • When the method or class is annotated with {@link AvailableInMaintenanceMode} and onlyAvailableInMaintenanceMode + * is set + * to true, it verifies the maintenance mode is enabled
  • *
  • When the method is NOT annotated with {@link AvailableOnStoppedNode}, it verifies the platform is * running
  • * @@ -335,53 +337,53 @@ protected void checkMethodAccessibility(final Object apiImpl, final String apiIn apiInterfaceName, method.getName(), method.getDeclaringClass().getName()); throw new NodeNotStartedException(); } - // we don't check if tenant is in pause mode at platform level and when there is no session + // we don't check maintenance mode at platform level and when there is no session // when there is no session means that we are trying to log in, in this case it is the LoginApiExt that check if the user is the technical user // For tenant level method call: if (!(session instanceof APISession)) { return; } - final long tenantId = ((APISession) session).getTenantId(); - if (methodAvailability.isAvailableOnPausedTenant && methodAvailability.isAvailableOnRunningTenant) { - //method can be called on paused and running tenant. + if (methodAvailability.isAvailableInMaintenanceMode + && methodAvailability.isAvailableWhenMaintenanceModeIsDisabled) { + //method can be called when maintenance is enabled or disabled. return; } - boolean tenantIsPaused = isTenantPaused(tenantId, session, isAlreadyInTransaction); - if (tenantIsPaused && !methodAvailability.isAvailableOnPausedTenant) { + boolean isMaintenanceModeEnabled = isMaintenanceModeEnabled(session, isAlreadyInTransaction); + if (isMaintenanceModeEnabled && !methodAvailability.isAvailableInMaintenanceMode) { throw new TenantStatusException( - MessageFormat.format("Unable to call API method {0}.{1}, The tenant {2} is paused.", - apiInterfaceName, method.getName(), tenantId)); + MessageFormat.format("Unable to call API method {0}.{1}, Maintenance mode is enabled.", + apiInterfaceName, method.getName())); } - if (!tenantIsPaused && !methodAvailability.isAvailableOnRunningTenant) { + if (!isMaintenanceModeEnabled && !methodAvailability.isAvailableWhenMaintenanceModeIsDisabled) { throw new TenantStatusException(MessageFormat.format( - "Unable to call API method {0}.{1}, The tenant {2} is running and this method can only be called when tenant is paused.", - apiInterfaceName, method.getName(), tenantId)); + "Unable to call API method {0}.{1}, Maintenance mode is disabled and this method can only be called when Maintenance mode is enabled.", + apiInterfaceName, method.getName())); } } private static class MethodAvailability { boolean isDeprecated; - boolean isAvailableOnRunningTenant = true; - boolean isAvailableOnPausedTenant = true; + boolean isAvailableWhenMaintenanceModeIsDisabled = true; + boolean isAvailableInMaintenanceMode = true; boolean isAvailableWhenPlatformIsStopped; } private MethodAvailability getMethodAvailability(Object apiInstance, Method method) { - AvailableWhenTenantIsPaused availableWhenTenantIsPaused = Optional - .ofNullable(method.getAnnotation(AvailableWhenTenantIsPaused.class)) - .orElseGet(() -> apiInstance.getClass().getAnnotation(AvailableWhenTenantIsPaused.class)); + AvailableInMaintenanceMode availableInMaintenanceMode = Optional + .ofNullable(method.getAnnotation(AvailableInMaintenanceMode.class)) + .orElseGet(() -> apiInstance.getClass().getAnnotation(AvailableInMaintenanceMode.class)); AvailableOnStoppedNode availableOnStoppedNode = method.getAnnotation(AvailableOnStoppedNode.class); MethodAvailability methodAvailability = new MethodAvailability(); // Deprecation methodAvailability.isDeprecated = method.isAnnotationPresent(Deprecated.class); - // Tenant status - if (availableWhenTenantIsPaused == null) { - methodAvailability.isAvailableOnPausedTenant = false; - } else if (availableWhenTenantIsPaused.onlyAvailableWhenPaused()) { - methodAvailability.isAvailableOnRunningTenant = false; + // Maintenance mode + if (availableInMaintenanceMode == null) { + methodAvailability.isAvailableInMaintenanceMode = false; + } else if (availableInMaintenanceMode.onlyAvailableInMaintenanceMode()) { + methodAvailability.isAvailableWhenMaintenanceModeIsDisabled = false; } // Platform status if (availableOnStoppedNode != null) { @@ -391,27 +393,26 @@ private MethodAvailability getMethodAvailability(Object apiInstance, Method meth } /** - * @param tenantId - * the ID of the tenant to check * @param session * the session to user * @param isAlreadyInTransaction * if the request is made in a transaction - * @return true if the tenant is available, false otherwise (if the tenant is paused) + * @return true if the maintenance mode is enabled, false otherwise */ - protected boolean isTenantPaused(final long tenantId, final Session session, boolean isAlreadyInTransaction) { + protected boolean isMaintenanceModeEnabled(final Session session, boolean isAlreadyInTransaction) { try { - TenantAdministrationAPI tenantAdministrationAPI = accessResolver - .getAPIImplementation(TenantAdministrationAPI.class); + MaintenanceAPI maintenanceAPI = accessResolver + .getAPIImplementation(MaintenanceAPI.class); if (isAlreadyInTransaction) { - return tenantAdministrationAPI.isPaused(); + return MaintenanceDetails.State.ENABLED + .equals(maintenanceAPI.getMaintenanceDetails().getMaintenanceState()); } else { return selectUserTransactionService(session, getSessionType(session)) - .executeInTransaction(tenantAdministrationAPI::isPaused); + .executeInTransaction(() -> MaintenanceDetails.State.ENABLED + .equals(maintenanceAPI.getMaintenanceDetails().getMaintenanceState())); } } catch (final Throwable e) { - throw new BonitaRuntimeException("Cannot determine if the tenant with ID " + tenantId + " is accessible", - e); + throw new BonitaRuntimeException("Cannot determine if the Maintenance mode is enabled", e); } } diff --git a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImpl.java b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImpl.java index 0ccd5ec1fd4..87704c4fda1 100644 --- a/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImpl.java +++ b/bpm/bonita-core/bonita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImpl.java @@ -57,7 +57,7 @@ protected long getTenantId() { } @Override - @AvailableWhenTenantIsPaused + @AvailableInMaintenanceMode public boolean isPaused() { final long tenantId = getTenantId(); try { @@ -68,7 +68,7 @@ public boolean isPaused() { } @Override - @AvailableWhenTenantIsPaused + @AvailableInMaintenanceMode @CustomTransactions public void pause() throws UpdateException { ServiceAccessor serviceAccessor = getServiceAccessorNoException(); @@ -80,7 +80,7 @@ public void pause() throws UpdateException { } @Override - @AvailableWhenTenantIsPaused + @AvailableInMaintenanceMode @CustomTransactions public void resume() throws UpdateException { ServiceAccessor serviceAccessor = getServiceAccessorNoException(); @@ -101,7 +101,7 @@ private void resolveDependenciesForAllProcesses() { } @Override - @AvailableWhenTenantIsPaused + @AvailableInMaintenanceMode public TenantResource getBusinessDataModelResource() { return getTenantResource(TenantResourceType.BDM); } @@ -120,7 +120,7 @@ protected TenantResource getTenantResource(TenantResourceType type) { //visible for testing @Override - @AvailableWhenTenantIsPaused + @AvailableInMaintenanceMode public String getBusinessDataModelVersion() throws BusinessDataRepositoryException { try { final BusinessDataModelRepository modelRepository = getServiceAccessor().getBusinessDataModelRepository(); @@ -157,7 +157,7 @@ private String installBusinessDataModel(final byte[] zip) } @Override - @AvailableWhenTenantIsPaused(onlyAvailableWhenPaused = true) + @AvailableInMaintenanceMode(onlyAvailableInMaintenanceMode = true) @WithLock(key = UPDATE_BDM) public void uninstallBusinessDataModel() throws BusinessDataRepositoryDeploymentException { log.info("Uninstalling the currently deployed BDM"); @@ -178,7 +178,7 @@ public void uninstallBusinessDataModel() throws BusinessDataRepositoryDeployment } @Override - @AvailableWhenTenantIsPaused(onlyAvailableWhenPaused = true) + @AvailableInMaintenanceMode(onlyAvailableInMaintenanceMode = true) @WithLock(key = UPDATE_BDM) @Deprecated(since = "9.0.0") public String updateBusinessDataModel(final byte[] zip) @@ -197,7 +197,7 @@ public String updateBusinessDataModel(final byte[] zip) } @Override - @AvailableWhenTenantIsPaused(onlyAvailableWhenPaused = true) + @AvailableInMaintenanceMode(onlyAvailableInMaintenanceMode = true) @WithLock(key = UPDATE_BDM) public void cleanAndUninstallBusinessDataModel() throws BusinessDataRepositoryDeploymentException { final ServiceAccessor serviceAccessor = getServiceAccessor(); @@ -216,7 +216,7 @@ public void cleanAndUninstallBusinessDataModel() throws BusinessDataRepositoryDe } @Override - @AvailableWhenTenantIsPaused + @AvailableInMaintenanceMode public byte[] getClientBDMZip() throws BusinessDataRepositoryException { final BusinessDataModelRepository bdmRepository = getServiceAccessor().getBusinessDataModelRepository(); try { diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProfileAPIImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProfileAPIImplTest.java index 71148aa2c3d..c74875d5557 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProfileAPIImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ProfileAPIImplTest.java @@ -83,7 +83,7 @@ public void should_invoke_getMemberType_from_delegate() throws Exception { @Test public void should_profile_api_be_available_when_tenant_is_paused() throws Exception { - assertThat(ProfileAPIImpl.class.isAnnotationPresent(AvailableWhenTenantIsPaused.class)) + assertThat(ProfileAPIImpl.class.isAnnotationPresent(AvailableInMaintenanceMode.class)) .as("should profile api be available when tenant is paused") .isTrue(); } diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ServerAPIImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ServerAPIImplTest.java index e4079871639..1695d6c4aa4 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ServerAPIImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/ServerAPIImplTest.java @@ -28,15 +28,16 @@ import java.util.Map; import java.util.concurrent.Callable; +import org.bonitasoft.engine.api.MaintenanceAPI; import org.bonitasoft.engine.api.NoSessionRequired; import org.bonitasoft.engine.api.PlatformAPI; -import org.bonitasoft.engine.api.TenantAdministrationAPI; import org.bonitasoft.engine.api.impl.transaction.CustomTransactions; import org.bonitasoft.engine.api.internal.ServerWrappedException; import org.bonitasoft.engine.classloader.ClassLoaderService; import org.bonitasoft.engine.core.login.LoginService; import org.bonitasoft.engine.core.platform.login.PlatformLoginService; import org.bonitasoft.engine.exception.*; +import org.bonitasoft.engine.maintenance.MaintenanceDetails; import org.bonitasoft.engine.platform.PlatformManager; import org.bonitasoft.engine.platform.PlatformState; import org.bonitasoft.engine.platform.session.PlatformSessionService; @@ -101,14 +102,16 @@ public class ServerAPIImplTest { private ServerAPIImpl serverAPIImpl; private MyApiImplementation myApi = new MyApiImplementation(); private MyApiWithNoSessionImpl myApiWithNoSession = new MyApiWithNoSessionImpl(); - private ApiFullyAccessibleWhenTenantIsPausedImpl myApiFullyAccessibleWhenTenantIsPaused = new ApiFullyAccessibleWhenTenantIsPausedImpl(); + private ApiFullyAccessibleWhenMaintenanceModeIsEnabledImpl myApiFullyAccessibleWhenMaintenanceModeIsEnabled = new ApiFullyAccessibleWhenMaintenanceModeIsEnabledImpl(); private APIAccessResolver accessResolver; @Mock private PlatformAPI platformApi; @Mock - private TenantAdministrationAPI tenantAdministrationApi; + private MaintenanceAPI maintenanceAPI; + @Mock + MaintenanceDetails maintenanceDetails; - private boolean isTenantPaused = false; + private boolean isMaintenanceEnabled = false; @Before public void createServerAPI() throws Exception { @@ -127,8 +130,10 @@ public void createServerAPI() throws Exception { doReturn(true).when(tenantLoginService).isValid(TENANT_SESSION_ID); doReturn(true).when(platformLoginService).isValid(PLATFORM_SESSION_ID); - - doAnswer(invocation -> isTenantPaused).when(tenantAdministrationApi).isPaused(); + doAnswer(invocation -> (isMaintenanceEnabled ? MaintenanceDetails.State.ENABLED + : MaintenanceDetails.State.DISABLED)) + .when(maintenanceDetails).getMaintenanceState(); + doAnswer(invocation -> maintenanceDetails).when(maintenanceAPI).getMaintenanceDetails(); accessResolver = new APIAccessResolver() { @@ -138,12 +143,12 @@ public T getAPIImplementation(Class apiInterface) throws APIImplementatio return (T) myApi; } else if (apiInterface.equals(MyApiWithNoSession.class)) { return (T) myApiWithNoSession; - } else if (apiInterface.equals(ApiFullyAccessibleWhenTenantIsPaused.class)) { - return (T) myApiFullyAccessibleWhenTenantIsPaused; + } else if (apiInterface.equals(ApiFullyAccessibleWhenMaintenanceModeIsEnabled.class)) { + return (T) myApiFullyAccessibleWhenMaintenanceModeIsEnabled; } else if (apiInterface.equals(PlatformAPI.class)) { return (T) platformApi; - } else if (apiInterface.equals(TenantAdministrationAPI.class)) { - return (T) tenantAdministrationApi; + } else if (apiInterface.equals(MaintenanceAPI.class)) { + return (T) maintenanceAPI; } else { throw new APIImplementationNotFoundException("not the FakeApi"); } @@ -193,7 +198,7 @@ public void should_not_open_transaction_on_CustomTransaction_annotated_methods() null); assertThat(myApi.customTxAPIMethodCalled).isTrue(); - //only one call: "tenantAdministrationApi.isTenantPaused" + //only one call: "maintenanceAPI.getMaintenanceDetails()" verify(userTransactionService, only()).executeInTransaction(any()); } @@ -223,8 +228,8 @@ public void should_fail_when_calling_normal_method_without_session() throws Thro } @Test - public void should_not_be_able_to_call_normal_method_when_tenant_is_paused() throws Exception { - isTenantPaused = true; + public void should_not_be_able_to_call_normal_method_when_maintenance_mode_is_enabled() throws Exception { + isMaintenanceEnabled = true; expectedException.expectCause(instanceOf(TenantStatusException.class)); serverAPIImpl.invokeMethod(options(tenantSession), MyApi.class.getName(), "notAnnotatedMethod", emptyList(), @@ -232,65 +237,67 @@ public void should_not_be_able_to_call_normal_method_when_tenant_is_paused() thr } @Test - public void should_be_able_to_call_method_with_AvailableWhenTenantIsPaused_when_tenant_is_paused() + public void should_be_able_to_call_method_with_AvailableInMaintenanceMode_when_maintenance_mode_is_enabled() throws Exception { - isTenantPaused = true; + isMaintenanceEnabled = true; - serverAPIImpl.invokeMethod(options(tenantSession), MyApi.class.getName(), "availableWhenTenantIsPaused", + serverAPIImpl.invokeMethod(options(tenantSession), MyApi.class.getName(), "availableInMaintenanceMode", emptyList(), null); - assertThat(myApi.availableWhenTenantIsPausedCalled).isTrue(); + assertThat(myApi.availableInMaintenanceModeCalled).isTrue(); } @Test - public void should_be_able_to_call_method_with_AvailableWhenTenantIsPaused_when_tenant_is_not_paused() + public void should_be_able_to_call_method_with_AvailableInMaintenanceMode_when_maintenance_mode_is_disabled() throws Exception { - isTenantPaused = false; + isMaintenanceEnabled = false; - serverAPIImpl.invokeMethod(options(tenantSession), MyApi.class.getName(), "availableWhenTenantIsPaused", + serverAPIImpl.invokeMethod(options(tenantSession), MyApi.class.getName(), "availableInMaintenanceMode", emptyList(), null); - assertThat(myApi.availableWhenTenantIsPausedCalled).isTrue(); + assertThat(myApi.availableInMaintenanceModeCalled).isTrue(); } @Test - public void should_not_be_able_to_call_method_with_OnlyAvailableWhenTenantIsPaused_when_tenant_is_not_paused() + public void should_not_be_able_to_call_method_with_OnlyAvailableInMaintenanceMode_when_maintenance_mode_is_disabled() throws Exception { - isTenantPaused = false; + isMaintenanceEnabled = false; expectedException.expectCause(instanceOf(TenantStatusException.class)); - serverAPIImpl.invokeMethod(options(tenantSession), MyApi.class.getName(), "onlyAvailableWhenTenantIsPaused", + serverAPIImpl.invokeMethod(options(tenantSession), MyApi.class.getName(), "onlyAvailableInMaintenanceMode", emptyList(), null); } @Test - public void should_be_able_to_call_method_with_OnlyAvailableWhenTenantIsPaused_when_tenant_is_paused() + public void should_be_able_to_call_method_with_OnlyAvailableInMaintenanceMode_when_maintenance_mode_is_enabled() throws Exception { - isTenantPaused = true; + isMaintenanceEnabled = true; - serverAPIImpl.invokeMethod(options(tenantSession), MyApi.class.getName(), "onlyAvailableWhenTenantIsPaused", + serverAPIImpl.invokeMethod(options(tenantSession), MyApi.class.getName(), "onlyAvailableInMaintenanceMode", emptyList(), null); - assertThat(myApi.onlyAvailableWhenTenantIsPausedCalled).isTrue(); + assertThat(myApi.onlyAvailableInMaintenanceModeCalled).isTrue(); } @Test - public void should_be_able_to_call_method_of_api_fully_available_when_tenant_is_paused() throws Exception { - isTenantPaused = true; + public void should_be_able_to_call_method_of_api_fully_available_when_maintenance_mode_is_enabled() + throws Exception { + isMaintenanceEnabled = true; - //There is no real check in server API whether it is a tenant or a platform api, we only check the type of session - serverAPIImpl.invokeMethod(options(tenantSession), ApiFullyAccessibleWhenTenantIsPaused.class.getName(), + //There is no real check in server API whether it is a tenant or a platform API, we only check the type of session + serverAPIImpl.invokeMethod(options(tenantSession), + ApiFullyAccessibleWhenMaintenanceModeIsEnabled.class.getName(), "aMethod", emptyList(), null); - assertThat(myApiFullyAccessibleWhenTenantIsPaused.aMethodCalled).isTrue(); + assertThat(myApiFullyAccessibleWhenMaintenanceModeIsEnabled.aMethodCalled).isTrue(); } @Test - public void should_be_able_to_call_platform_apis_when_tenant_is_paused() throws Exception { - isTenantPaused = true; + public void should_be_able_to_call_platform_apis_when_maintenance_mode_is_enabled() throws Exception { + isMaintenanceEnabled = true; - //There is no real check in server API whether it is a tenant or a platform api, we only check the type of session + //There is no real check in server API whether it is a tenant or a platform API, we only check the type of session serverAPIImpl.invokeMethod(options(platformSession), MyApi.class.getName(), "notAnnotatedMethod", emptyList(), null); @@ -379,13 +386,14 @@ private Map options(Session session) { // APIS for tests // ---- - interface ApiFullyAccessibleWhenTenantIsPaused { + interface ApiFullyAccessibleWhenMaintenanceModeIsEnabled { void aMethod(); } - @AvailableWhenTenantIsPaused - static class ApiFullyAccessibleWhenTenantIsPausedImpl implements ApiFullyAccessibleWhenTenantIsPaused { + @AvailableInMaintenanceMode + static class ApiFullyAccessibleWhenMaintenanceModeIsEnabledImpl + implements ApiFullyAccessibleWhenMaintenanceModeIsEnabled { boolean aMethodCalled; @@ -420,9 +428,9 @@ interface MyApi { @AvailableOnStoppedNode void callMeNew(); - void availableWhenTenantIsPaused(); + void availableInMaintenanceMode(); - void onlyAvailableWhenTenantIsPaused(); + void onlyAvailableInMaintenanceMode(); void customTxAPIMethod(); @@ -435,8 +443,8 @@ static class MyApiImplementation implements MyApi { boolean customTxAPIMethodCalled; boolean notAnnotatedMethodCalled; - boolean availableWhenTenantIsPausedCalled; - boolean onlyAvailableWhenTenantIsPausedCalled; + boolean availableInMaintenanceModeCalled; + boolean onlyAvailableInMaintenanceModeCalled; @Deprecated @AvailableOnStoppedNode @@ -449,14 +457,14 @@ public void callMeNew() { } - @AvailableWhenTenantIsPaused - public void availableWhenTenantIsPaused() { - availableWhenTenantIsPausedCalled = true; + @AvailableInMaintenanceMode + public void availableInMaintenanceMode() { + availableInMaintenanceModeCalled = true; } - @AvailableWhenTenantIsPaused(onlyAvailableWhenPaused = true) - public void onlyAvailableWhenTenantIsPaused() { - onlyAvailableWhenTenantIsPausedCalled = true; + @AvailableInMaintenanceMode(onlyAvailableInMaintenanceMode = true) + public void onlyAvailableInMaintenanceMode() { + onlyAvailableInMaintenanceModeCalled = true; } @CustomTransactions diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImplTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImplTest.java index 3e9a243c59f..0717c320924 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImplTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/TenantAdministrationAPIImplTest.java @@ -84,8 +84,8 @@ public void before() throws Exception { public void resume_should_have_annotation_available_when_tenant_is_paused() throws Exception { final Method method = TenantAdministrationAPIImpl.class.getMethod("resume"); - final boolean present = method.isAnnotationPresent(AvailableWhenTenantIsPaused.class) - || TenantAdministrationAPIImpl.class.isAnnotationPresent(AvailableWhenTenantIsPaused.class); + final boolean present = method.isAnnotationPresent(AvailableInMaintenanceMode.class) + || TenantAdministrationAPIImpl.class.isAnnotationPresent(AvailableInMaintenanceMode.class); assertThat(present).as( "Annotation @AvailableWhenTenantIsPaused should be present on API method 'resume' or directly on class TenantManagementAPIExt") @@ -96,8 +96,8 @@ public void resume_should_have_annotation_available_when_tenant_is_paused() thro public void pause_should_have_annotation_available_when_tenant_is_paused() throws Exception { final Method method = TenantAdministrationAPIImpl.class.getMethod("pause"); - final boolean present = method.isAnnotationPresent(AvailableWhenTenantIsPaused.class) - || TenantAdministrationAPIImpl.class.isAnnotationPresent(AvailableWhenTenantIsPaused.class); + final boolean present = method.isAnnotationPresent(AvailableInMaintenanceMode.class) + || TenantAdministrationAPIImpl.class.isAnnotationPresent(AvailableInMaintenanceMode.class); assertThat(present).as( "Annotation @AvailableWhenTenantIsPaused should be present on API method 'pause' or directly on class TenantManagementAPIExt") @@ -110,7 +110,7 @@ public void pageApi_should_be_available_in_maintenance_mode() { final Class classPageApiExt = PageAPIImpl.class; // then: - assertThat(classPageApiExt.isAnnotationPresent(AvailableWhenTenantIsPaused.class)).as( + assertThat(classPageApiExt.isAnnotationPresent(AvailableInMaintenanceMode.class)).as( "Annotation @AvailableOnMaintenanceTenant should be present on PageAPIIml"); } @@ -124,9 +124,9 @@ public void resume_should_resolve_dependencies_for_deployed_processes() throws E @Test public void installBDR_should_be_available_when_tenant_is_paused_ONLY() throws Exception { final Method method = TenantAdministrationAPIImpl.class.getMethod("updateBusinessDataModel", byte[].class); - final AvailableWhenTenantIsPaused annotation = method.getAnnotation(AvailableWhenTenantIsPaused.class); + final AvailableInMaintenanceMode annotation = method.getAnnotation(AvailableInMaintenanceMode.class); - final boolean present = annotation != null && annotation.onlyAvailableWhenPaused(); + final boolean present = annotation != null && annotation.onlyAvailableInMaintenanceMode(); assertThat(present).as( "Annotation @AvailableWhenTenantIsPaused(only=true) should be present on API method 'installBusinessDataModel(byte[])'") .isTrue(); @@ -135,9 +135,9 @@ public void installBDR_should_be_available_when_tenant_is_paused_ONLY() throws E @Test public void uninstallBDR_should_be_available_when_tenant_is_paused_ONLY() throws Exception { final Method method = TenantAdministrationAPIImpl.class.getMethod("uninstallBusinessDataModel"); - final AvailableWhenTenantIsPaused annotation = method.getAnnotation(AvailableWhenTenantIsPaused.class); + final AvailableInMaintenanceMode annotation = method.getAnnotation(AvailableInMaintenanceMode.class); - final boolean present = annotation != null && annotation.onlyAvailableWhenPaused(); + final boolean present = annotation != null && annotation.onlyAvailableInMaintenanceMode(); assertThat(present).as( "Annotation @AvailableWhenTenantIsPaused(only=true) should be present on API method 'uninstallBusinessDataModel()'") .isTrue(); diff --git a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/profile/ProfileAPIIDelegateTest.java b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/profile/ProfileAPIIDelegateTest.java index b59c5e72eef..1e4838a7ac1 100644 --- a/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/profile/ProfileAPIIDelegateTest.java +++ b/bpm/bonita-core/bonita-process-engine/src/test/java/org/bonitasoft/engine/api/impl/profile/ProfileAPIIDelegateTest.java @@ -20,7 +20,7 @@ import java.util.List; -import org.bonitasoft.engine.api.impl.AvailableWhenTenantIsPaused; +import org.bonitasoft.engine.api.impl.AvailableInMaintenanceMode; import org.bonitasoft.engine.api.impl.ProfileAPIImpl; import org.bonitasoft.engine.api.impl.transaction.profile.CreateProfileMember; import org.bonitasoft.engine.business.application.ApplicationService; @@ -153,7 +153,7 @@ public void memberType_MemberShip() throws Exception { @Test public void should_profile_api_be_available_when_tenant_is_paused() throws Exception { - assertThat(ProfileAPIImpl.class.isAnnotationPresent(AvailableWhenTenantIsPaused.class)) + assertThat(ProfileAPIImpl.class.isAnnotationPresent(AvailableInMaintenanceMode.class)) .as("should profile api be available when tenant is paused") .isTrue(); }