Skip to content

Commit

Permalink
feat(maintenance mode): add maintenance java API interface (#2701)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: abirembaut <anthony.birembaut@gmail.com>
  • Loading branch information
Shmayro and abirembaut authored Sep 11, 2023
1 parent 172d64e commit 62c9f41
Show file tree
Hide file tree
Showing 25 changed files with 577 additions and 109 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public void setUp() {
public void all_required_cache_configurations_should_exist() {
assertThat(cacheService.getCacheConfigurationNames()).containsExactlyInAnyOrder(
"CONFIGURATION_FILES_CACHE",
"PLATFORM",
"USER_FILTER",
"transient_data",
"GROOVY_SCRIPT_CACHE_NAME",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public void should_save_and_get_SPlatform() {
entry("CREATED_BY", "The almighty"),
entry("INITIAL_BONITA_VERSION", "5.9.0"),
entry("APPLICATION_VERSION", "0.0.0"),
entry("MAINTENANCE_MESSAGE", null),
entry("MAINTENANCE_MESSAGE_ACTIVE", false),
entry("VERSION", "1.2"),
entry("INFORMATION", "some infos XYZ"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,4 +128,8 @@ public static ApplicationAPI getApplicationAPI(final APISession session)
return getAPI(ApplicationAPI.class, session);
}

public static MaintenanceAPI getMaintenanceAPI(final APISession session)
throws BonitaHomeNotSetException, ServerAPIException, UnknownAPITypeException {
return getAPI(MaintenanceAPI.class, session);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**
* Copyright (C) 2023 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.engine.api;

import org.bonitasoft.engine.exception.UpdateException;
import org.bonitasoft.engine.maintenance.MaintenanceInfo;
import org.bonitasoft.engine.maintenance.MaintenanceInfoNotFoundException;
import org.bonitasoft.engine.platform.PlatformNotFoundException;

/**
* This API gives access to maintenance administration tasks such as enabling maintenance mode and also enable/disable
* maintenance message.
*/
public interface MaintenanceAPI {

/**
* Retrieve maintenance info details
*
* @return MaintenanceInfo
* @throws MaintenanceInfoNotFoundException
* @throws PlatformNotFoundException
*/
MaintenanceInfo getMaintenanceInfo() throws MaintenanceInfoNotFoundException, PlatformNotFoundException;

/**
* Enable maintenance mode
* This method replaces {@link TenantAdministrationAPI#pause()}
* When maintenance mode is enabled, All BPM and BDM APIs are not accessible.
*
* @throws UpdateException
* if maintenance state cannot be updated.
*/
void enableMaintenanceMode() throws UpdateException;

/**
* Disable maintenance mode
* This method replaces {@link TenantAdministrationAPI#resume()}
*
* @throws UpdateException
* if maintenance state cannot be updated.
*/
void disableMaintenanceMode() throws UpdateException;

/**
* Update maintenance message
* This message will be displayed in bonita apps if enabled
*
* @throws UpdateException
* if maintenance message cannot be updated.
*/
void updateMaintenanceMessage(String message) throws UpdateException;

/**
* Enable maintenance message
*
* @throws UpdateException
* if maintenance message cannot be enabled.
*/
void enableMaintenanceMessage() throws UpdateException;

/**
* Disable maintenance message
*
* @throws UpdateException
* if maintenance message cannot be disabled.
*/
void disableMaintenanceMessage() throws UpdateException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,19 @@ public interface TenantAdministrationAPI {
*
* @throws org.bonitasoft.engine.exception.UpdateException
* if the tenant cannot be paused.
* This method is deprecated, use {@link MaintenanceAPI#enableMaintenanceMode()} instead.
*/
@Deprecated
void pause() throws UpdateException;

/**
* Resume the tenant to a normal state after a pause.
*
* @throws org.bonitasoft.engine.exception.UpdateException
* if the tenant cannot be resumed.
* This method is deprecated, use {@link MaintenanceAPI#disableMaintenanceMode()} ()} instead.
*/
@Deprecated
void resume() throws UpdateException;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**
* Copyright (C) 2023 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.engine.maintenance;

import org.bonitasoft.engine.bpm.BonitaObject;

/**
* This object holds maintenance details such as maintenance state and message.
*/
public interface MaintenanceInfo extends BonitaObject {

public State getMaintenanceState();

public String getMaintenanceMessage();

public boolean isMaintenanceMessageActive();

/**
* Activation state of platform maintenance
*/
public enum State {

ENABLED, DISABLED
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Copyright (C) 2023 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.engine.maintenance;

import org.bonitasoft.engine.exception.NotFoundException;

public class MaintenanceInfoNotFoundException extends NotFoundException {

public MaintenanceInfoNotFoundException(String message) {
super(message);
}

public MaintenanceInfoNotFoundException(final String message, final Throwable cause) {
super(message, cause);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* Copyright (C) 2023 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.engine.maintenance.impl;

import lombok.Builder;
import org.bonitasoft.engine.maintenance.MaintenanceInfo;

@Builder
public class MaintenanceInfoImpl implements MaintenanceInfo {

private State maintenanceState;
private String maintenanceMessage;
private boolean maintenanceMessageActive;

public State getMaintenanceState() {
return maintenanceState;
}

@Override
public String getMaintenanceMessage() {
return maintenanceMessage;
}

public boolean isMaintenanceMessageActive() {
return maintenanceMessageActive;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/**
* Copyright (C) 2023 Bonitasoft S.A.
* Bonitasoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This library is free software; you can redistribute it and/or modify it under the terms
* of the GNU Lesser General Public License as published by the Free Software Foundation
* version 2.1 of the License.
* This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public License along with this
* program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
* Floor, Boston, MA 02110-1301, USA.
**/
package org.bonitasoft.engine.api.impl;

import org.bonitasoft.engine.api.MaintenanceAPI;
import org.bonitasoft.engine.exception.BonitaRuntimeException;
import org.bonitasoft.engine.exception.UpdateException;
import org.bonitasoft.engine.maintenance.MaintenanceInfo;
import org.bonitasoft.engine.maintenance.MaintenanceInfoNotFoundException;
import org.bonitasoft.engine.maintenance.impl.MaintenanceInfoImpl;
import org.bonitasoft.engine.platform.PlatformNotFoundException;
import org.bonitasoft.engine.platform.PlatformService;
import org.bonitasoft.engine.platform.exception.SPlatformNotFoundException;
import org.bonitasoft.engine.platform.exception.SPlatformUpdateException;
import org.bonitasoft.engine.platform.exception.STenantNotFoundException;
import org.bonitasoft.engine.platform.model.SPlatform;
import org.bonitasoft.engine.platform.model.builder.SPlatformUpdateBuilder;
import org.bonitasoft.engine.platform.model.builder.impl.SPlatformUpdateBuilderImpl;
import org.bonitasoft.engine.recorder.model.EntityUpdateDescriptor;
import org.bonitasoft.engine.service.ServiceAccessor;
import org.bonitasoft.engine.service.impl.ServiceAccessorFactory;
import org.bonitasoft.engine.tenant.TenantStateManager;

/**
* This API gives access to maintenance administration tasks.
*/
public class MaintenanceAPIImpl implements MaintenanceAPI {

public MaintenanceAPIImpl() {
}

protected ServiceAccessor getServiceAccessor() {
try {
return ServiceAccessorFactory.getInstance().createServiceAccessor();
} catch (final Exception e) {
throw new BonitaRuntimeException(e);
}
}

@Override
public MaintenanceInfo getMaintenanceInfo() throws MaintenanceInfoNotFoundException, PlatformNotFoundException {
try {
PlatformService platformService = getServiceAccessor().getPlatformService();
MaintenanceInfo.State state = platformService.getDefaultTenant().isPaused() ? MaintenanceInfo.State.ENABLED
: MaintenanceInfo.State.DISABLED;
SPlatform platform = platformService.getPlatform();
return MaintenanceInfoImpl.builder()
.maintenanceMessage(platform.getMaintenanceMessage())
.maintenanceMessageActive(platform.isMaintenanceMessageActive())
.maintenanceState(state)
.build();
} catch (STenantNotFoundException e) {
throw new MaintenanceInfoNotFoundException("Maintenance info not found", e);
} catch (SPlatformNotFoundException e) {
throw new PlatformNotFoundException(e.getMessage(), e);
}
}

@Override
public void enableMaintenanceMode() throws UpdateException {
try {
TenantStateManager tenantStateManager = getServiceAccessor().getTenantStateManager();
tenantStateManager.pause();
} catch (Exception e) {
throw new UpdateException(e);
}
}

@Override
public void disableMaintenanceMode() throws UpdateException {
try {
TenantStateManager tenantStateManager = getServiceAccessor().getTenantStateManager();
tenantStateManager.resume();
disableMaintenanceMessage();
} catch (Exception e) {
throw new UpdateException(e);
}
}

@Override
public void updateMaintenanceMessage(String message) throws UpdateException {
try {
PlatformService platformService = getServiceAccessor().getPlatformService();
platformService.updatePlatform(getPlatformUpdateBuilder()
.setMaintenanceMessage(message).done());
} catch (SPlatformUpdateException e) {
throw new UpdateException(e);
}
}

@Override
public void enableMaintenanceMessage() throws UpdateException {
try {
PlatformService platformService = getServiceAccessor().getPlatformService();
platformService.updatePlatform(getPlatformUpdateBuilder()
.setMaintenanceMessageActive(true).done());
} catch (SPlatformUpdateException e) {
throw new UpdateException(e);
}
}

@Override
public void disableMaintenanceMessage() throws UpdateException {
try {
PlatformService platformService = getServiceAccessor().getPlatformService();
platformService.updatePlatform(getPlatformUpdateBuilder()
.setMaintenanceMessageActive(false).done());
} catch (SPlatformUpdateException e) {
throw new UpdateException(e);
}
}

protected SPlatformUpdateBuilder getPlatformUpdateBuilder() {
return SPlatformUpdateBuilderImpl.builder()
.descriptor(new EntityUpdateDescriptor())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public class APIAccessResolverImpl implements APIAccessResolver {
apis.put(TenantAdministrationAPI.class.getName(), new TenantAdministrationAPIImpl());
apis.put(BusinessDataAPI.class.getName(), new BusinessDataAPIImpl());
apis.put(TemporaryContentAPI.class.getName(), new TemporaryContentAPIImpl());
apis.put(MaintenanceAPI.class.getName(), new MaintenanceAPIImpl());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,6 @@
<property name="readIntensive" value="${bonita.platform.cache.synchro.readIntensive}" />
</bean>

<bean id="platformCacheConfig" class="org.bonitasoft.engine.cache.CacheConfiguration">
<property name="name" value="PLATFORM" />
<property name="maxElementsInMemory" value="${bonita.platform.cache.platform.maxElementsInMemory}" />
<property name="inMemoryOnly" value="${bonita.platform.cache.platform.inMemoryOnly}" />
<property name="eternal" value="${bonita.platform.cache.platform.eternal}" />
<property name="evictionPolicy" value="${bonita.platform.cache.platform.evictionPolicy}" />
<property name="timeToLiveSeconds" value="${bonita.platform.cache.platform.timeToLiveSeconds}" />
<property name="maxElementsOnDisk" value="${bonita.platform.cache.platform.maxElementsOnDisk}" />
<property name="copyOnRead" value="${bonita.platform.cache.platform.copyOnRead}" />
<property name="copyOnWrite" value="${bonita.platform.cache.platform.copyOnWrite}" />
<property name="readIntensive" value="${bonita.platform.cache.platform.readIntensive}" />
</bean>

<bean id="configFilesCacheConfig" class="org.bonitasoft.engine.cache.CacheConfiguration">
<property name="name" value="CONFIGURATION_FILES_CACHE" />
<property name="maxElementsInMemory" value="${bonita.platform.cache.configfiles.maxElementsInMemory}" />
Expand Down
Loading

0 comments on commit 62c9f41

Please sign in to comment.