Alona Kaplan has uploaded a new change for review.

Change subject: engine: introducing AddVfsConfigLabelCommand
......................................................................

engine: introducing AddVfsConfigLabelCommand

Change-Id: Ib2fec58b2c5de89ae504b9057ab6781cf9a322df
Signed-off-by: Alona Kaplan <alkap...@redhat.com>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddVfsConfigLabelCommand.java
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/LabelVfsConfigCommandBase.java
M 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VfsConfigValidator.java
M 
backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VfsConfigValidatorTest.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/VfsConfigLabelParameters.java
M 
backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
M backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
M 
backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
M 
frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
M 
frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
11 files changed, 181 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/46/36846/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddVfsConfigLabelCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddVfsConfigLabelCommand.java
new file mode 100644
index 0000000..f996797
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/AddVfsConfigLabelCommand.java
@@ -0,0 +1,47 @@
+package org.ovirt.engine.core.bll.network.host;
+
+import java.util.Set;
+
+import org.ovirt.engine.core.bll.context.CommandContext;
+import org.ovirt.engine.core.common.AuditLogType;
+import org.ovirt.engine.core.common.action.VfsConfigLabelParameters;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+
+public class AddVfsConfigLabelCommand extends LabelVfsConfigCommandBase {
+
+    public AddVfsConfigLabelCommand(VfsConfigLabelParameters parameters) {
+        this(parameters, null);
+    }
+
+    public AddVfsConfigLabelCommand(VfsConfigLabelParameters parameters, 
CommandContext commandContext) {
+        super(parameters, commandContext);
+    }
+
+    @Override
+    protected boolean canDoAction() {
+        if (super.canDoAction()) {
+            return 
validate(getVfsConfigValidator().labelNotInVfsConfig(getLabel()));
+        }
+
+        return false;
+    }
+
+    @Override
+    public AuditLogType getAuditLogTypeValue() {
+        return getSucceeded() ? AuditLogType.ADD_VFS_CONFIG_LABEL
+                : AuditLogType.ADD_VFS_CONFIG_LABEL_FAILED;
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        super.setActionMessageParameters();
+        addCanDoActionMessage(VdcBllMessages.VAR__ACTION__ADD);
+    }
+
+    @Override
+    protected Set<String> getUpdatedLabelList() {
+        Set<String> labels = getVfsConfig().getLabels();
+        labels.add(getLabel());
+        return labels;
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/LabelVfsConfigCommandBase.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/LabelVfsConfigCommandBase.java
new file mode 100644
index 0000000..525813f
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/LabelVfsConfigCommandBase.java
@@ -0,0 +1,50 @@
+package org.ovirt.engine.core.bll.network.host;
+
+import java.util.Set;
+
+import org.ovirt.engine.core.bll.context.CommandContext;
+import org.ovirt.engine.core.common.action.VfsConfigLabelParameters;
+import org.ovirt.engine.core.common.businessentities.network.HostNicVfsConfig;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+
+public abstract class LabelVfsConfigCommandBase extends 
VfsConfigCommandBase<VfsConfigLabelParameters> {
+
+    public LabelVfsConfigCommandBase(VfsConfigLabelParameters parameters) {
+        this(parameters, null);
+    }
+
+    public LabelVfsConfigCommandBase(VfsConfigLabelParameters parameters, 
CommandContext commandContext) {
+        super(parameters, commandContext);
+    }
+
+    @Override
+    protected void executeCommand() {
+        super.executeCommand();
+
+        HostNicVfsConfig oldVfsConfig = getVfsConfig();
+        oldVfsConfig.setLabels(getUpdatedLabelList());
+        getVfsConfigDao().update(oldVfsConfig);
+
+        setSucceeded(true);
+    }
+
+    protected abstract Set<String> getUpdatedLabelList();
+
+    @Override
+    protected boolean canDoAction() {
+        if (super.canDoAction()) {
+            return 
validate(getVfsConfigValidator().settingSpecificNetworksAllowed());
+        }
+
+        return false;
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        
addCanDoActionMessage(VdcBllMessages.VAR__TYPE__HOST_NIC_VFS_CONFIG_LABEL);
+    }
+
+    protected String getLabel() {
+        return getParameters().getLabel();
+    }
+}
diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VfsConfigValidator.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VfsConfigValidator.java
index 6537114..86cbd65 100644
--- 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VfsConfigValidator.java
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/validator/VfsConfigValidator.java
@@ -22,6 +22,7 @@
     static final String MAX_NUM_OF_VFS_REPLACEMENT = "$maxNumOfVfs %d";
     static final String NETWORK_NAME_REPLACEMENT = "$networkName %s";
     static final String NETWORK_ID_REPLACEMENT = "$networkId %s";
+    static final String LABEL_REPLACEMENT = "$label %s";
 
     public VfsConfigValidator(Guid nicId) {
         this.nicId = nicId;
@@ -126,6 +127,17 @@
                 .when(!getOldVfsConfig().getNetworks().contains(networkId));
     }
 
+    /**
+     * @param label
+     *
+     * @return An error iff the label is already part of the VFs configuration
+     */
+    public ValidationResult labelNotInVfsConfig(String label) {
+        return 
ValidationResult.failWith(VdcBllMessages.ACTION_TYPE_FAILED_LABEL_ALREADY_IN_VFS_CONFIG,
+                getNicNameReplacement(), String.format(LABEL_REPLACEMENT, 
label))
+                .when(getOldVfsConfig().getLabels().contains(label));
+    }
+
     Network getNetwork(Guid networkId) {
         return getDbFacade().getNetworkDao().get(networkId);
     }
diff --git 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VfsConfigValidatorTest.java
 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VfsConfigValidatorTest.java
index 09f7003..2962147 100644
--- 
a/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VfsConfigValidatorTest.java
+++ 
b/backend/manager/modules/bll/src/test/java/org/ovirt/engine/core/bll/validator/VfsConfigValidatorTest.java
@@ -50,6 +50,8 @@
 
     private static final Guid NETWORK_ID = Guid.newGuid();
 
+    private static final String LABEL = "lbl";
+
     @Mock
     private VdsNetworkInterface nic;
 
@@ -293,4 +295,31 @@
         }
         when(oldVfsConfig.getNetworks()).thenReturn(networks);
     }
+
+    @Test
+    public void labelNotInVfsConfigValid() {
+        labelInVfsConfigCommonTest(false);
+        assertThat(validator.labelNotInVfsConfig(LABEL), isValid());
+    }
+
+    @Test
+    public void labelNotInVfsConfigNotValid() {
+        labelInVfsConfigCommonTest(true);
+        assertThat(validator.labelNotInVfsConfig(LABEL),
+                
failsWith(VdcBllMessages.ACTION_TYPE_FAILED_LABEL_ALREADY_IN_VFS_CONFIG,
+                        String.format(VfsConfigValidator.NIC_NAME_REPLACEMENT, 
nic.getName()),
+                        String.format(VfsConfigValidator.LABEL_REPLACEMENT, 
LABEL)));
+    }
+
+    private void labelInVfsConfigCommonTest(boolean inVfsConfig) {
+        simulateVfsConfigExists();
+
+        Set<String> labels = new HashSet<>();
+
+        if (inVfsConfig) {
+            labels.add(LABEL);
+        }
+        when(oldVfsConfig.getLabels()).thenReturn(labels);
+    }
+
 }
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 4fbca53..e5ecc08 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
@@ -759,6 +759,8 @@
     ADD_VFS_CONFIG_NETWORK_FAILED(1194),
     REMOVE_VFS_CONFIG_NETWORK(1195),
     REMOVE_VFS_CONFIG_NETWORK_FAILED(1196),
+    ADD_VFS_CONFIG_LABEL(1197),
+    ADD_VFS_CONFIG_LABEL_FAILED(1198),
 
     // NUMA
     NUMA_ADD_VM_NUMA_NODE_SUCCESS(1300),
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VfsConfigLabelParameters.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VfsConfigLabelParameters.java
new file mode 100644
index 0000000..9f8a9f5
--- /dev/null
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/action/VfsConfigLabelParameters.java
@@ -0,0 +1,27 @@
+package org.ovirt.engine.core.common.action;
+
+import javax.validation.constraints.NotNull;
+
+import 
org.ovirt.engine.core.common.validation.annotation.ValidNetworkLabelFormat;
+import org.ovirt.engine.core.compat.Guid;
+
+public class VfsConfigLabelParameters extends VfsConfigBaseParameters {
+
+    private static final long serialVersionUID = -918265384359602937L;
+
+    @NotNull
+    @ValidNetworkLabelFormat(message = "NETWORK_LABEL_FORMAT_INVALID")
+    private String label;
+
+    public VfsConfigLabelParameters() {
+    }
+
+    public VfsConfigLabelParameters(Guid nicId, String label) {
+        super(nicId);
+        this.label = label;
+    }
+
+    public String getLabel() {
+        return label;
+    }
+}
diff --git 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
index 4acea81..b233f69 100644
--- 
a/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
+++ 
b/backend/manager/modules/common/src/main/java/org/ovirt/engine/core/common/errors/VdcBllMessages.java
@@ -25,6 +25,7 @@
     VAR__TYPE__LABEL,
     VAR__TYPE__HOST_NIC_VFS_CONFIG,
     VAR__TYPE__HOST_NIC_VFS_CONFIG_NETWORK,
+    VAR__TYPE__HOST_NIC_VFS_CONFIG_LABEL,
     VAR__TYPE__PROVIDER,
     VAR__TYPE__PROVIDER_CERTIFICATE,
     VAR__TYPE__VM_DISK,
@@ -599,6 +600,7 @@
     ACTION_TYPE_FAILED_NETWORK_NOT_EXIST(ErrorType.BAD_PARAMETERS),
     ACTION_TYPE_FAILED_NETWORK_ALREADY_IN_VFS_CONFIG(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_NETWORK_NOT_IN_VFS_CONFIG(ErrorType.CONFLICT),
+    ACTION_TYPE_FAILED_LABEL_ALREADY_IN_VFS_CONFIG(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_STORAGE_DOMAIN_NOT_IN_STORAGE_POOL(ErrorType.CONFLICT),
     
ACTION_TYPE_FAILED_LUNS_ALREADY_PART_OF_STORAGE_DOMAINS(ErrorType.CONFLICT),
     ACTION_TYPE_FAILED_LUNS_ALREADY_USED_BY_DISKS(ErrorType.CONFLICT),
diff --git 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
index 88db8a7..2292fad 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -287,6 +287,7 @@
 VAR__TYPE__LABEL=$type Label
 VAR__TYPE__HOST_NIC_VFS_CONFIG=$type host NIC VFs configuration
 VAR__TYPE__HOST_NIC_VFS_CONFIG_NETWORK=$type host NIC VFs configuration network
+VAR__TYPE__HOST_NIC_VFS_CONFIG_LABEL=$type host NIC VFs configuration label
 VAR__TYPE__PROVIDER=$type provider
 VAR__TYPE__PROVIDER_CERTIFICATE=$type provider certificate
 VAR__TYPE__VM=$type VM
@@ -540,6 +541,7 @@
 ACTION_TYPE_FAILED_NETWORK_ALREADY_IN_VFS_CONFIG=Cannot ${action} ${type}. 
Network ${networkName} already exists in network interface ${nicName} VFs 
configuration.
 ACTION_TYPE_FAILED_NETWORK_NOT_IN_VFS_CONFIG=Cannot ${action} ${type}. Network 
${networkName} doesn't exist in network interface ${nicName} VFs configuration.
 ACTION_TYPE_FAILED_NETWORK_NOT_EXIST=Cannot ${action} ${type}. Network with id 
${networkId} doesn't exist.
+ACTION_TYPE_FAILED_LABEL_ALREADY_IN_VFS_CONFIG=Cannot ${action} ${type}. Label 
${label} already exists in network interface ${nicName} VFs configuration.
 
 ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover 
Data Center with active Data Storage Domain in Data Center.
 ERROR_CANNOT_DETACH_LAST_STORAGE_DOMAIN=Cannot remove the master Storage 
Domain from the Data Center without another active Storage Domain to take its 
place.\n\
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 2c10b7c..3288f02 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AuditLogMessages.properties
@@ -562,6 +562,8 @@
 UPDATE_HOST_NIC_VFS_CONFIG_FAILED=Failed to update the VFs configuration of 
network interface card ${NicName}.
 ADD_VFS_CONFIG_NETWORK=Network ${NetworkName} was added to the VFs 
configuration of network interface card ${NicName}.
 ADD_VFS_CONFIG_NETWORK_FAILED=Failed to add ${NetworkName} to the VFs 
configuration of network interface card ${NicName}.
+ADD_VFS_CONFIG_LABEL=Label ${Label} was added to the VFs configuration of 
network interface card ${NicName}.
+ADD_VFS_CONFIG_LABEL_FAILED=Failed to add ${Label} to the VFs configuration of 
network interface card ${NicName}.
 REMOVE_VFS_CONFIG_NETWORK=Network ${NetworkName} was removed from the VFs 
configuration of network interface card ${NicName}.
 REMOVE_VFS_CONFIG_NETWORK_FAILED=Failed to remove ${NetworkName} from the VFs 
configuration of network interface card ${NicName}.
 SYSTEM_DEACTIVATED_STORAGE_DOMAIN=Storage Domain ${StorageDomainName} (Data 
Center ${StoragePoolName}) was deactivated by system because it's not visible 
by any of the hosts.
diff --git 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
index ad35ef5..733fff3 100644
--- 
a/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
+++ 
b/frontend/webadmin/modules/frontend/src/main/java/org/ovirt/engine/ui/frontend/AppErrors.java
@@ -772,6 +772,9 @@
     @DefaultStringValue("$type host NIC VFs configuration network")
     String VAR__TYPE__HOST_NIC_VFS_CONFIG_NETWORK();
 
+    @DefaultStringValue("$type host NIC VFs configuration label")
+    String VAR__TYPE__HOST_NIC_VFS_CONFIG_LABEL();
+
     @DefaultStringValue("$type VM network interface profile")
     String VAR__TYPE__VNIC_PROFILE();
 
@@ -1510,6 +1513,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. Network with id 
${networkId} doesn't exist.")
     String ACTION_TYPE_FAILED_NETWORK_NOT_EXIST();
 
+    @DefaultStringValue("Cannot ${action} ${type}. Label ${label} already 
exists in network interface ${nicName} VFs configuration.")
+    String ACTION_TYPE_FAILED_LABEL_ALREADY_IN_VFS_CONFIG();
+
     @DefaultStringValue("Cannot recover Data Center with active Data Storage 
Domain in Data Center.")
     String ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS();
 
diff --git 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
index 8252ca0..beac682 100644
--- 
a/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
+++ 
b/frontend/webadmin/modules/webadmin/src/main/resources/org/ovirt/engine/ui/frontend/AppErrors.properties
@@ -283,6 +283,7 @@
 VAR__TYPE__LABEL=$type Label
 VAR__TYPE__HOST_NIC_VFS_CONFIG=$type host NIC VFs configuration
 VAR__TYPE__HOST_NIC_VFS_CONFIG_NETWORK=$type host NIC VFs configuration network
+VAR__TYPE__HOST_NIC_VFS_CONFIG_LABEL=$type host NIC VFs configuration label
 VAR__TYPE__VNIC_PROFILE=$type VM network interface profile
 VAR__TYPE__PROVIDER=$type provider
 VAR__TYPE__PROVIDER_CERTIFICATE=$type provider certificate
@@ -545,6 +546,7 @@
 ACTION_TYPE_FAILED_NETWORK_ALREADY_IN_VFS_CONFIG=Cannot ${action} ${type}. 
Network ${networkName} already exists in network interface ${nicName} VFs 
configuration.
 ACTION_TYPE_FAILED_NETWORK_NOT_IN_VFS_CONFIG=Cannot ${action} ${type}. Network 
${networkName} doesn't exist in network interface ${nicName} VFs configuration.
 ACTION_TYPE_FAILED_NETWORK_NOT_EXIST=Cannot ${action} ${type}. Network with id 
${networkId} doesn't exist.
+ACTION_TYPE_FAILED_LABEL_ALREADY_IN_VFS_CONFIG=Cannot ${action} ${type}. Label 
${label} already exists in network interface ${nicName} VFs configuration.
 
 ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover 
Data Center with active Data Storage Domain in Data Center.
 ERROR_CANNOT_DETACH_LAST_STORAGE_DOMAIN=Cannot remove the master Storage 
Domain from the Data Center without another active Storage Domain to take its 
place.\n\


-- 
To view, visit http://gerrit.ovirt.org/36846
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ib2fec58b2c5de89ae504b9057ab6781cf9a322df
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Alona Kaplan <alkap...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to