Daniel Erez has uploaded a new change for review.

Change subject: core: added CRUD commands for LibvirtSecrets
......................................................................

core: added CRUD commands for LibvirtSecrets

Added Libvirt Secrets CRUD commands:
* AddLibvirtSecret
* UpdateLibvritSecret
* RemoveLibvirtSecret

Change-Id: I7278408ca2548b3c66a5eb862b234959c4f1748c
Bug-Url: https://bugzilla.redhat.com/1185826
Signed-off-by: Daniel Erez <[email protected]>
---
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandsFactory.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddLibvirtSecretCommand.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/LibvirtSecretCommandBase.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RemoveLibvirtSecretCommand.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateLibvirtSecretCommand.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
A 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/LibvirtSecretParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
M 
backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
9 files changed, 207 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/55/41555/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandsFactory.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandsFactory.java
index b0fa0e0..bf77c07 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandsFactory.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/CommandsFactory.java
@@ -47,6 +47,7 @@
         "org.ovirt.engine.core.bll.pm",
         "org.ovirt.engine.core.bll.provider",
         "org.ovirt.engine.core.bll.provider.network",
+        "org.ovirt.engine.core.bll.provider.storage",
         "org.ovirt.engine.core.bll.qos",
         "org.ovirt.engine.core.bll.scheduling.commands",
         "org.ovirt.engine.core.bll.scheduling.queries",
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddLibvirtSecretCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddLibvirtSecretCommand.java
new file mode 100644
index 0000000..6a709d4
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/AddLibvirtSecretCommand.java
@@ -0,0 +1,44 @@
+package org.ovirt.engine.core.bll.storage;
+
+import org.ovirt.engine.core.bll.provider.storage.LibvirtSecretValidator;
+import org.ovirt.engine.core.common.AuditLogType;
+import org.ovirt.engine.core.common.action.LibvirtSecretParameters;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+
+import java.util.Date;
+
+public class AddLibvirtSecretCommand extends LibvirtSecretCommandBase {
+
+    public AddLibvirtSecretCommand(LibvirtSecretParameters parameters) {
+        super(parameters);
+    }
+
+    @Override
+    protected boolean canDoAction() {
+        LibvirtSecretValidator libvirtSecretValidator =
+                new LibvirtSecretValidator(getParameters().getLibvirtSecret(), 
getDbFacade());
+        return validate(libvirtSecretValidator.uuidNotEmpty())
+                && validate(libvirtSecretValidator.uuidNotExist())
+                && validate(libvirtSecretValidator.valueNotEmpty())
+                && validate(libvirtSecretValidator.providerExist());
+    }
+
+    @Override
+    protected void executeCommand() {
+        super.executeCommand();
+        getParameters().getLibvirtSecret().setCreationDate(new Date());
+        getLibvirtSecretDAO().save(getParameters().getLibvirtSecret());
+        setSucceeded(true);
+    }
+
+    @Override
+    public AuditLogType getAuditLogTypeValue() {
+        return getSucceeded() ? AuditLogType.USER_ADDED_LIBVIRT_SECRET : 
AuditLogType.USER_FAILED_TO_ADD_LIBVIRT_SECRET;
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        super.setActionMessageParameters();
+        addCanDoActionMessage(VdcBllMessages.VAR__ACTION__ADD);
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/LibvirtSecretCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/LibvirtSecretCommandBase.java
new file mode 100644
index 0000000..5750295
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/LibvirtSecretCommandBase.java
@@ -0,0 +1,44 @@
+package org.ovirt.engine.core.bll.storage;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.ovirt.engine.core.bll.CommandBase;
+import org.ovirt.engine.core.bll.utils.PermissionSubject;
+import org.ovirt.engine.core.common.VdcObjectType;
+import org.ovirt.engine.core.common.action.LibvirtSecretParameters;
+import org.ovirt.engine.core.common.businessentities.ActionGroup;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.compat.Guid;
+import org.ovirt.engine.core.dao.LibvirtSecretDao;
+
+public abstract class LibvirtSecretCommandBase extends 
CommandBase<LibvirtSecretParameters> {
+
+    public LibvirtSecretCommandBase(LibvirtSecretParameters parameters) {
+        super(parameters);
+    }
+
+    protected LibvirtSecretDao getLibvirtSecretDAO() {
+        return getDbFacade().getLibvirtSecretDao();
+    }
+
+    @Override
+    public List<PermissionSubject> getPermissionCheckSubjects() {
+        return Collections.singletonList(new PermissionSubject(Guid.SYSTEM,
+                VdcObjectType.System,
+                ActionGroup.CREATE_STORAGE_POOL));
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        super.setActionMessageParameters();
+        addCanDoActionMessage(VdcBllMessages.VAR__TYPE__AUTHENTICATION_KEY);
+    }
+
+    @Override
+    protected void executeCommand() {
+        Guid secretUuid = getParameters().getLibvirtSecret().getId();
+        addCustomValue("LibvirtSecretUUID", secretUuid.toString());
+        getReturnValue().setActionReturnValue(secretUuid);
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RemoveLibvirtSecretCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RemoveLibvirtSecretCommand.java
new file mode 100644
index 0000000..214d1c8
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/RemoveLibvirtSecretCommand.java
@@ -0,0 +1,38 @@
+package org.ovirt.engine.core.bll.storage;
+
+import org.ovirt.engine.core.bll.provider.storage.LibvirtSecretValidator;
+import org.ovirt.engine.core.common.AuditLogType;
+import org.ovirt.engine.core.common.action.LibvirtSecretParameters;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+
+public class RemoveLibvirtSecretCommand extends LibvirtSecretCommandBase {
+
+    public RemoveLibvirtSecretCommand(LibvirtSecretParameters parameters) {
+        super(parameters);
+    }
+
+    @Override
+    protected boolean canDoAction() {
+        LibvirtSecretValidator libvirtSecretValidator =
+                new LibvirtSecretValidator(getParameters().getLibvirtSecret(), 
getDbFacade());
+        return validate(libvirtSecretValidator.uuidExist());
+    }
+
+    @Override
+    protected void executeCommand() {
+        super.executeCommand();
+        
getLibvirtSecretDAO().remove(getParameters().getLibvirtSecret().getId());
+        setSucceeded(true);
+    }
+
+    @Override
+    public AuditLogType getAuditLogTypeValue() {
+        return getSucceeded() ? AuditLogType.USER_REMOVED_LIBVIRT_SECRET : 
AuditLogType.USER_FAILED_TO_REMOVE_LIBVIRT_SECRET;
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        super.setActionMessageParameters();
+        addCanDoActionMessage(VdcBllMessages.VAR__ACTION__REMOVE);
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateLibvirtSecretCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateLibvirtSecretCommand.java
new file mode 100644
index 0000000..bc131c4
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/storage/UpdateLibvirtSecretCommand.java
@@ -0,0 +1,40 @@
+package org.ovirt.engine.core.bll.storage;
+
+import org.ovirt.engine.core.bll.provider.storage.LibvirtSecretValidator;
+import org.ovirt.engine.core.common.AuditLogType;
+import org.ovirt.engine.core.common.action.LibvirtSecretParameters;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+
+public class UpdateLibvirtSecretCommand extends LibvirtSecretCommandBase {
+
+    public UpdateLibvirtSecretCommand(LibvirtSecretParameters parameters) {
+        super(parameters);
+    }
+
+    @Override
+    protected boolean canDoAction() {
+        LibvirtSecretValidator libvirtSecretValidator =
+                new LibvirtSecretValidator(getParameters().getLibvirtSecret(), 
getDbFacade());
+        return validate(libvirtSecretValidator.uuidExist())
+                && validate(libvirtSecretValidator.valueNotEmpty())
+                && validate(libvirtSecretValidator.providerExist());
+    }
+
+    @Override
+    protected void executeCommand() {
+        super.executeCommand();
+        getLibvirtSecretDAO().update(getParameters().getLibvirtSecret());
+        setSucceeded(true);
+    }
+
+    @Override
+    public AuditLogType getAuditLogTypeValue() {
+        return getSucceeded() ? AuditLogType.USER_UPDATE_LIBVIRT_SECRET : 
AuditLogType.USER_FAILED_TO_UPDATE_LIBVIRT_SECRET;
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        super.setActionMessageParameters();
+        addCanDoActionMessage(VdcBllMessages.VAR__ACTION__UPDATE);
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
index 8ff4bd8..959ecfc 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/AuditLogType.java
@@ -1208,6 +1208,12 @@
     CINDER_PROVIDER_ERROR(10750, AuditLogSeverity.ERROR),
     CINDER_DISK_CONNECTION_FAILURE(10751, AuditLogSeverity.ERROR),
     CINDER_DISK_CONNECTION_VOLUME_DRIVER_UNSUPPORTED(10752, 
AuditLogSeverity.ERROR),
+    USER_ADDED_LIBVIRT_SECRET(10753),
+    USER_FAILED_TO_ADD_LIBVIRT_SECRET(10754, AuditLogSeverity.ERROR),
+    USER_UPDATE_LIBVIRT_SECRET(10755),
+    USER_FAILED_TO_UPDATE_LIBVIRT_SECRET(10756, AuditLogSeverity.ERROR),
+    USER_REMOVED_LIBVIRT_SECRET(10757),
+    USER_FAILED_TO_REMOVE_LIBVIRT_SECRET(10758, AuditLogSeverity.ERROR),
 
     // Host Devices
     VM_ADD_HOST_DEVICES(10800),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/LibvirtSecretParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/LibvirtSecretParameters.java
new file mode 100644
index 0000000..83bbcb9
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/LibvirtSecretParameters.java
@@ -0,0 +1,25 @@
+package org.ovirt.engine.core.common.action;
+
+import javax.validation.Valid;
+
+import org.ovirt.engine.core.common.businessentities.storage.LibvirtSecret;
+
+public class LibvirtSecretParameters extends VdcActionParametersBase {
+
+    private static final long serialVersionUID = -5231418068819634608L;
+
+    @Valid
+    private LibvirtSecret libvirtSecret;
+
+    public LibvirtSecretParameters() {
+    }
+
+    public LibvirtSecretParameters(LibvirtSecret libvirtSecret) {
+        this.libvirtSecret = libvirtSecret;
+    }
+
+    public LibvirtSecret getLibvirtSecret() {
+        return libvirtSecret;
+    }
+
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
index 845d419..130cd22 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VdcActionType.java
@@ -451,6 +451,9 @@
     CloneSingleCinderDisk(3204, ActionGroup.CONFIGURE_VM_STORAGE, 
QuotaDependency.STORAGE),
     CloneCinderDisks(3205, ActionGroup.CONFIGURE_VM_STORAGE, 
QuotaDependency.STORAGE),
     RegisterCinderDisk(3206, ActionGroup.CONFIGURE_VM_STORAGE, false, 
QuotaDependency.NONE),
+    AddLibvirtSecret(3207, false, QuotaDependency.NONE),
+    UpdateLibvirtSecret(3208, false, QuotaDependency.NONE),
+    RemoveLibvirtSecret(3209, false, QuotaDependency.NONE),
 
     // Host Devices
     RefreshHostDevices(4000, ActionGroup.MANIPULATE_HOST, false, 
QuotaDependency.NONE),
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
index 472184f..72d5b9b 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -995,6 +995,12 @@
 CINDER_PROVIDER_ERROR=An error occurred on Cinder provider: 
'${CinderException}'
 CINDER_DISK_CONNECTION_FAILURE=Failed to retrieve connection information for 
Cinder Disk '${DiskAlias}'.
 CINDER_DISK_CONNECTION_VOLUME_DRIVER_UNSUPPORTED=Unsupported volume driver for 
Cinder Disk '${DiskAlias}'.
+USER_ADDED_LIBVIRT_SECRET=Authentication Key ${LibvirtSecretUUID} was added. 
(User: ${UserName}).
+USER_FAILED_TO_ADD_LIBVIRT_SECRET=Failed to add Authentication Key 
${LibvirtSecretUUID}. (User: ${UserName}).
+USER_UPDATE_LIBVIRT_SECRET=Authentication Key ${LibvirtSecretUUID} was 
updated. (User: ${UserName}).
+USER_FAILED_TO_UPDATE_LIBVIRT_SECRET=Failed to update Authentication Key 
${LibvirtSecretUUID}. (User: ${UserName}).
+USER_REMOVED_LIBVIRT_SECRET=Authentication Key ${LibvirtSecretUUID} was 
removed. (User: ${UserName}).
+USER_FAILED_TO_REMOVE_LIBVIRT_SECRET=Failed to remove Authentication Key 
${LibvirtSecretUUID}. (User: ${UserName}).
 VM_ADD_HOST_DEVICES=Host devices ${NamesAdded} were attached to Vm ${VmName} 
by User ${UserName}.
 VM_REMOVE_HOST_DEVICES=Host devices ${NamesRemoved} were detached from Vm 
${VmName} by User ${UserName}.
 HOST_AVAILABLE_UPDATES_FAILED=Failed to check for available updates on host 
'${VdsName}' with message '${Message}'.


-- 
To view, visit https://gerrit.ovirt.org/41555
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I7278408ca2548b3c66a5eb862b234959c4f1748c
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Daniel Erez <[email protected]>
_______________________________________________
Engine-patches mailing list
[email protected]
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to