-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(maintenance mode): add maintenance java API interface (#2701)
--------- Co-authored-by: abirembaut <anthony.birembaut@gmail.com>
- Loading branch information
1 parent
172d64e
commit 62c9f41
Showing
25 changed files
with
577 additions
and
109 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
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
79 changes: 79 additions & 0 deletions
79
bpm/bonita-common/src/main/java/org/bonitasoft/engine/api/MaintenanceAPI.java
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,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; | ||
} |
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
36 changes: 36 additions & 0 deletions
36
bpm/bonita-common/src/main/java/org/bonitasoft/engine/maintenance/MaintenanceInfo.java
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,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 | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...mon/src/main/java/org/bonitasoft/engine/maintenance/MaintenanceInfoNotFoundException.java
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,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); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...nita-common/src/main/java/org/bonitasoft/engine/maintenance/impl/MaintenanceInfoImpl.java
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,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; | ||
} | ||
} |
129 changes: 129 additions & 0 deletions
129
...onita-process-engine/src/main/java/org/bonitasoft/engine/api/impl/MaintenanceAPIImpl.java
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,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(); | ||
} | ||
} |
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
Oops, something went wrong.