diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EngineBackupAwarenessManager.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EngineBackupAwarenessManager.java index 50f86aff8c7..c9bf98f19e6 100644 --- a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EngineBackupAwarenessManager.java +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/EngineBackupAwarenessManager.java @@ -15,6 +15,7 @@ import org.ovirt.engine.core.common.AuditLogType; import org.ovirt.engine.core.common.BackendService; import org.ovirt.engine.core.common.businessentities.EngineBackupLog; +import org.ovirt.engine.core.common.businessentities.EngineBackupScope; import org.ovirt.engine.core.common.config.Config; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.dal.dbbroker.auditloghandling.AuditLogDirector; @@ -32,21 +33,6 @@ @Singleton public class EngineBackupAwarenessManager implements BackendService { - private enum BackupScope { - DB("db"), - FILES("files"); - - String name; - - BackupScope(String name) { - this.name = name; - } - - public String getName() { - return name; - } - } - private static final Logger log = LoggerFactory.getLogger(EngineBackupAwarenessManager.class); private Lock lock = new ReentrantLock(); @Inject @@ -96,8 +82,8 @@ private void doBackupCheck() { AuditLogable alert = new AuditLogableImpl(); //try to get last backup record - EngineBackupLog lastDbBackup = getLastBackupByScope(BackupScope.DB); - EngineBackupLog lastFilesBackup = getLastBackupByScope(BackupScope.FILES); + EngineBackupLog lastDbBackup = getLastBackupByScope(EngineBackupScope.DB); + EngineBackupLog lastFilesBackup = getLastBackupByScope(EngineBackupScope.FILES); if (lastDbBackup == null || lastFilesBackup == null) { auditLogDirector.log(alert, AuditLogType.ENGINE_NO_FULL_BACKUP); } else { @@ -118,7 +104,7 @@ private void doBackupCheck() { } - private EngineBackupLog getLastBackupByScope(BackupScope scope) { + private EngineBackupLog getLastBackupByScope(EngineBackupScope scope) { return engineBackupLogDao.getLastSuccessfulEngineBackup(scope.getName()); } } diff --git a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/aaa/GetLastEngineBackupQuery.java b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/aaa/GetLastEngineBackupQuery.java new file mode 100644 index 00000000000..06e0d134617 --- /dev/null +++ b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/aaa/GetLastEngineBackupQuery.java @@ -0,0 +1,25 @@ +package org.ovirt.engine.core.bll.aaa; + +import javax.inject.Inject; + +import org.ovirt.engine.core.bll.QueriesCommandBase; +import org.ovirt.engine.core.bll.context.EngineContext; +import org.ovirt.engine.core.common.businessentities.EngineBackupLog; +import org.ovirt.engine.core.common.queries.GetLastEngineBackupParameters; +import org.ovirt.engine.core.dao.EngineBackupLogDao; + +public class GetLastEngineBackupQuery

extends QueriesCommandBase

{ + + @Inject + private EngineBackupLogDao engineBackupLogDao; + + public GetLastEngineBackupQuery(P parameters, EngineContext engineContext) { + super(parameters, engineContext); + } + + @Override + protected void executeQueryCommand() { + EngineBackupLog log = (EngineBackupLog) engineBackupLogDao.getLastSuccessfulEngineBackup(getParameters().getEngineBackupScope()); + getQueryReturnValue().setReturnValue(log); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/EngineBackupScope.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/EngineBackupScope.java new file mode 100644 index 00000000000..0b4fe12437d --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/businessentities/EngineBackupScope.java @@ -0,0 +1,30 @@ +package org.ovirt.engine.core.common.businessentities; + +public enum EngineBackupScope { + + DB("db"), + FILES("files"), + DWH("dwhdb"), + CINDER("cinderlib"), + KEYCLOAK("keycloak"), + GRAFANA("grafanadb"); + + String name; + + EngineBackupScope(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public static EngineBackupScope fromString(String name) { + for (EngineBackupScope scope : EngineBackupScope.values()) { + if (scope.getName().equalsIgnoreCase(name)) { + return scope; + } + } + throw new IllegalArgumentException("No enum constant for name " + name); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetLastEngineBackupParameters.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetLastEngineBackupParameters.java new file mode 100644 index 00000000000..8f7f7f207d7 --- /dev/null +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/GetLastEngineBackupParameters.java @@ -0,0 +1,23 @@ +package org.ovirt.engine.core.common.queries; + +import org.ovirt.engine.core.common.businessentities.EngineBackupScope; + +public class GetLastEngineBackupParameters extends QueryParametersBase { + + private EngineBackupScope scope; + + public GetLastEngineBackupParameters() { + } + + public GetLastEngineBackupParameters(EngineBackupScope scope) { + this.scope = scope; + } + + public void setEngineBackupScope(EngineBackupScope scope) { + this.scope = scope; + } + + public String getEngineBackupScope() { + return scope.getName(); + } +} diff --git a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/QueryType.java b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/QueryType.java index 76251ead855..2c429da1386 100644 --- a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/QueryType.java +++ b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/queries/QueryType.java @@ -539,7 +539,10 @@ public enum QueryType implements Serializable { GetSystemOption(QueryAuthType.User), // Default type instead of having to null check - Unknown(QueryAuthType.User); + Unknown(QueryAuthType.User), + + // Last Engine Backup + GetLastEngineBackup; /** * What kind of authorization the query requires. Although this is essentially a boolean, it's diff --git a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java index f704878f308..1191d41a4ce 100644 --- a/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java +++ b/backend/manager/modules/restapi/jaxrs/src/main/java/org/ovirt/engine/api/restapi/resource/BackendApiResource.java @@ -25,6 +25,7 @@ import org.ovirt.engine.api.model.ApiSummaryItem; import org.ovirt.engine.api.model.BaseResource; import org.ovirt.engine.api.model.DetailedLink; +import org.ovirt.engine.api.model.EngineBackupInfo; import org.ovirt.engine.api.model.ProductInfo; import org.ovirt.engine.api.model.Rsdl; import org.ovirt.engine.api.model.SpecialObjects; @@ -95,10 +96,13 @@ import org.ovirt.engine.core.branding.BrandingManager; import org.ovirt.engine.core.common.action.ActionParametersBase; import org.ovirt.engine.core.common.action.ActionType; +import org.ovirt.engine.core.common.businessentities.EngineBackupLog; +import org.ovirt.engine.core.common.businessentities.EngineBackupScope; import org.ovirt.engine.core.common.businessentities.aaa.DbUser; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.constants.QueryConstants; import org.ovirt.engine.core.common.mode.ApplicationMode; +import org.ovirt.engine.core.common.queries.GetLastEngineBackupParameters; import org.ovirt.engine.core.common.queries.GetSystemStatisticsQueryParameters; import org.ovirt.engine.core.common.queries.QueryParametersBase; import org.ovirt.engine.core.common.queries.QueryReturnValue; @@ -282,6 +286,9 @@ public Response get() { //(https://bugzilla.redhat.com/1612124) if (!isFiltered()) { addSummary(api); + // Backup info also admin-only + EngineBackupInfo lastEngineBackupInfo = getLastEngineBackup(); + api.setEngineBackup(lastEngineBackupInfo); } } setAuthenticatedUser(api); @@ -289,6 +296,40 @@ public Response get() { } } + private EngineBackupInfo getLastEngineBackup() { + EngineBackupInfo backupInfo = new EngineBackupInfo(); + for (EngineBackupScope backupScope : EngineBackupScope.values()) { + QueryReturnValue lastBackupQuery = runQuery(QueryType.GetLastEngineBackup, + new GetLastEngineBackupParameters(backupScope)); + EngineBackupLog backupLog = lastBackupQuery.getReturnValue(); + if (backupLog != null) { + switch (backupScope) { + case DB: + backupInfo.setLastDbBackup(DateMapper.map(backupLog.getDoneAt(), null)); + break; + case DWH: + backupInfo.setLastDwhBackup(DateMapper.map(backupLog.getDoneAt(), null)); + break; + case CINDER: + backupInfo.setLastCinderBackup(DateMapper.map(backupLog.getDoneAt(), null)); + break; + case KEYCLOAK: + backupInfo.setLastKeycloakBackup(DateMapper.map(backupLog.getDoneAt(), null)); + break; + case GRAFANA: + backupInfo.setLastGrafanaBackup(DateMapper.map(backupLog.getDoneAt(), null)); + break; + case FILES: + backupInfo.setLastEngineBackup(DateMapper.map(backupLog.getDoneAt(), null)); + break; + default: + break; + } + } + } + return backupInfo; + } + /** * Set a link to the user of the current session * (the 'authenticated user') in the API object. diff --git a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java index 575420b63e8..2a74b0e8527 100644 --- a/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java +++ b/backend/manager/modules/restapi/jaxrs/src/test/java/org/ovirt/engine/api/restapi/resource/BackendApiResourceTest.java @@ -3,12 +3,14 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import static org.ovirt.engine.api.restapi.test.util.TestHelper.eqParams; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Locale; @@ -22,6 +24,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.mockito.ArgumentMatcher; import org.ovirt.engine.api.model.Api; import org.ovirt.engine.api.model.Link; import org.ovirt.engine.api.model.SpecialObjects; @@ -29,11 +32,14 @@ import org.ovirt.engine.api.restapi.invocation.CurrentManager; import org.ovirt.engine.api.restapi.invocation.VersionSource; import org.ovirt.engine.api.restapi.logging.MessageBundle; +import org.ovirt.engine.core.common.businessentities.EngineBackupLog; +import org.ovirt.engine.core.common.businessentities.EngineBackupScope; import org.ovirt.engine.core.common.businessentities.aaa.DbUser; import org.ovirt.engine.core.common.config.ConfigValues; import org.ovirt.engine.core.common.interfaces.BackendLocal; import org.ovirt.engine.core.common.mode.ApplicationMode; import org.ovirt.engine.core.common.queries.GetConfigurationValueParameters; +import org.ovirt.engine.core.common.queries.GetLastEngineBackupParameters; import org.ovirt.engine.core.common.queries.GetSystemStatisticsQueryParameters; import org.ovirt.engine.core.common.queries.QueryParametersBase; import org.ovirt.engine.core.common.queries.QueryReturnValue; @@ -306,6 +312,7 @@ private void setupExpectations(ApplicationMode appMode) { setUpGetInstanceIdExpectations(); setUpGetUserBySessionExpectations(); setUpGetSystemStatisticsExpectations(); + setUpGetLastDbBackendExpectations(); } protected void doTestGlusterOnlyGet() { @@ -465,6 +472,22 @@ private QueryParametersBase getProductVersionParams() { return eqParams(QueryParametersBase.class, new String[0], new Object[0]); } + protected void setUpGetLastDbBackendExpectations() { + QueryReturnValue queryResult = new QueryReturnValue(); + queryResult.setSucceeded(true); + EngineBackupLog emptyReturn = new EngineBackupLog(); + emptyReturn.setDoneAt(new Date()); + emptyReturn.setScope(EngineBackupScope.DB.getName()); + queryResult.setReturnValue(emptyReturn); + when(backend.runQuery(eq(QueryType.GetLastEngineBackup), argThat(new ArgumentMatcher() { + @Override + public boolean matches(GetLastEngineBackupParameters argument) { + return argument != null && argument.getEngineBackupScope() != null; // Match any non-null EngineBackupScope + } + } + ))).thenReturn(queryResult); + } + protected void setUpGetSystemStatisticsExpectations() { QueryReturnValue queryResult = new QueryReturnValue(); diff --git a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml index fedce9b7da6..63ccebac983 100644 --- a/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml +++ b/frontend/webadmin/modules/gwt-common/src/main/resources/org/ovirt/engine/core/Common.gwt.xml @@ -544,6 +544,9 @@ + + + diff --git a/pom.xml b/pom.xml index e4cf23878a5..8e8a4a2313a 100644 --- a/pom.xml +++ b/pom.xml @@ -44,7 +44,7 @@ 0.5.0 1.3.10 - 4.6.0 + 4.6.1-SNAPSHOT 1.0.1 1.7.2