Alona Kaplan has uploaded a new change for review.

Change subject: engine: introducing RemoveVfsConfigNetworkCommand
......................................................................

engine: introducing RemoveVfsConfigNetworkCommand

Change-Id: I30734cd8be89ed2750a5ade379e4539353b15a5e
Signed-off-by: Alona Kaplan <alkap...@redhat.com>
---
A 
backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/RemoveVfsConfigNetworkCommand.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
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
9 files changed, 85 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/90/36690/1

diff --git 
a/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/RemoveVfsConfigNetworkCommand.java
 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/RemoveVfsConfigNetworkCommand.java
new file mode 100644
index 0000000..8c38f4d
--- /dev/null
+++ 
b/backend/manager/modules/bll/src/main/java/org/ovirt/engine/core/bll/network/host/RemoveVfsConfigNetworkCommand.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.VfsConfigNetworkParameters;
+import org.ovirt.engine.core.common.errors.VdcBllMessages;
+import org.ovirt.engine.core.compat.Guid;
+
+public class RemoveVfsConfigNetworkCommand extends NetworkVfsConfigCommandBase 
{
+
+    public RemoveVfsConfigNetworkCommand(VfsConfigNetworkParameters 
parameters) {
+        this(parameters, null);
+    }
+
+    public RemoveVfsConfigNetworkCommand(VfsConfigNetworkParameters 
parameters, CommandContext commandContext) {
+        super(parameters, commandContext);
+    }
+
+    @Override
+    protected boolean canDoAction() {
+        if (super.canDoAction()) {
+            return 
validate(getVfsConfigValidator().networkInVfsConfig(getNetworkId()));
+        }
+
+        return false;
+    }
+
+    @Override
+    public AuditLogType getAuditLogTypeValue() {
+        return getSucceeded() ? AuditLogType.REMOVE_VFS_CONFIG_NETWORK
+                : AuditLogType.REMOVE_VFS_CONFIG_NETWORK_FAILED;
+    }
+
+    @Override
+    protected void setActionMessageParameters() {
+        addCanDoActionMessage(VdcBllMessages.VAR__ACTION__REMOVE);
+    }
+
+    @Override
+    protected Set<Guid> getUpdatedNetworkList() {
+        Set<Guid> networks = getVfsConfig().getNetworks();
+        networks.remove(getNetworkId());
+        return networks;
+    }
+}
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 6be4162..6537114 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
@@ -114,6 +114,18 @@
                 .when(getOldVfsConfig().getNetworks().contains(networkId));
     }
 
+    /**
+     * @param networkId
+     *
+     * @return An error iff the network is not part of the VFs configuration
+     */
+    public ValidationResult networkInVfsConfig(Guid networkId) {
+        String networkName = getNetwork(networkId).getName();
+        return 
ValidationResult.failWith(VdcBllMessages.ACTION_TYPE_FAILED_NETWORK_NOT_IN_VFS_CONFIG,
+                getNicNameReplacement(), 
String.format(NETWORK_NAME_REPLACEMENT, networkName))
+                .when(!getOldVfsConfig().getNetworks().contains(networkId));
+    }
+
     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 564579c..09f7003 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
@@ -266,6 +266,22 @@
                         String.format(VfsConfigValidator.NIC_NAME_REPLACEMENT, 
nic.getName()),
                         
String.format(VfsConfigValidator.NETWORK_NAME_REPLACEMENT, network.getName())));
     }
+
+    @Test
+    public void networkInVfsConfigValid() {
+        networkInVfsConfigCommonTest(true);
+        assertThat(validator.networkInVfsConfig(NETWORK_ID), isValid());
+    }
+
+    @Test
+    public void networkInVfsConfigNotValid() {
+        networkInVfsConfigCommonTest(false);
+        assertThat(validator.networkInVfsConfig(NETWORK_ID),
+                
failsWith(VdcBllMessages.ACTION_TYPE_FAILED_NETWORK_NOT_IN_VFS_CONFIG,
+                        String.format(VfsConfigValidator.NIC_NAME_REPLACEMENT, 
nic.getName()),
+                        
String.format(VfsConfigValidator.NETWORK_NAME_REPLACEMENT, network.getName())));
+    }
+
     private void networkInVfsConfigCommonTest(boolean inVfsConfig) {
         simulateVfsConfigExists();
         simulateNetworkExists();
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 45520d2..c561e06 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
@@ -748,6 +748,8 @@
     UPDATE_HOST_NIC_VFS_CONFIG_FAILED(1192, AuditLogSeverity.ERROR),
     ADD_VFS_CONFIG_NETWORK(1193),
     ADD_VFS_CONFIG_NETWORK_FAILED(1194),
+    REMOVE_VFS_CONFIG_NETWORK(1195),
+    REMOVE_VFS_CONFIG_NETWORK_FAILED(1196),
 
     // NUMA
     NUMA_ADD_VM_NUMA_NODE_SUCCESS(1300),
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 bc10db7..13e2e07 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
@@ -596,6 +596,7 @@
     ACTION_TYPE_FAILED_CANNOT_SET_SPECIFIC_NETWORKS(ErrorType.CONFLICT),
     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_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 3445ef6..622ac66 100644
--- 
a/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
+++ 
b/backend/manager/modules/dal/src/main/resources/bundles/AppErrors.properties
@@ -536,6 +536,7 @@
 ACTION_TYPE_FAILED_NUM_OF_VFS_NOT_IN_VALID_RANGE=Cannot ${action} ${type}. The 
specified number of VFs on network interface ${nicName} is ${numOfVfs}, the 
valid range is 0 - ${maxNumOfVfs}.
 ACTION_TYPE_FAILED_CANNOT_SET_SPECIFIC_NETWORKS=Cannot ${action} ${type}. All 
networks are allowed, cannot set specific network/label.
 ACTION_TYPE_FAILED_NETWORK_ALREADY_IN_VFS_CONFIG=Cannot ${action} ${type}. 
Network ${networkName} already exists on network interface ${nicName} VFs 
configuration.
+ACTION_TYPE_FAILED_NETWORK_NOT_IN_VFS_CONFIG=Cannot ${action} ${type}. Network 
${networkName} doesn't exist on network interface ${nicName} VFs configuration.
 ACTION_TYPE_FAILED_NETWORK_NOT_EXIST=Cannot ${action} ${type}. Network with id 
${networkId} doesn't exist.
 
 ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover 
Data Center with active Data Storage Domain in Data Center.
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 c8abe2b..34795d3 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}.
+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.
 SYSTEM_DEACTIVATE_STORAGE_DOMAIN_FAILED=Failed to deactivate Storage Domain 
${StorageDomainName} (Data Center ${StoragePoolName}).
 VDS_SET_NONOPERATIONAL_DOMAIN=Host ${VdsName} cannot access the Storage 
Domain(s) ${StorageDomainNames} attached to the Data Center ${StoragePoolName}. 
Setting Host state to Non-Operational.
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 686e369..fdf1342 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
@@ -1498,6 +1498,9 @@
     @DefaultStringValue("Cannot ${action} ${type}. Network ${networkName} 
already exists on network interface ${nicName} VFs configuration.")
     String ACTION_TYPE_FAILED_NETWORK_ALREADY_IN_VFS_CONFIG();
 
+    @DefaultStringValue("Cannot ${action} ${type}. Network ${networkName} 
doesn't exist on network interface ${nicName} VFs configuration.")
+    String ACTION_TYPE_FAILED_NETWORK_NOT_IN_VFS_CONFIG();
+
     @DefaultStringValue("Cannot ${action} ${type}. Network with id 
${networkId} doesn't exist.")
     String ACTION_TYPE_FAILED_NETWORK_NOT_EXIST();
 
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 ceb3ff2..56109e9 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
@@ -540,6 +540,7 @@
 ACTION_TYPE_FAILED_NUM_OF_VFS_NOT_IN_VALID_RANGE=Cannot ${action} ${type}. The 
specified number of VFs on network interface ${nicName} is ${numOfVfs}, the 
valid range is 0 - ${maxNumOfVfs}.
 ACTION_TYPE_FAILED_CANNOT_SET_SPECIFIC_NETWORKS=Cannot ${action} ${type}. All 
networks are allowed, cannot set specific network/label.
 ACTION_TYPE_FAILED_NETWORK_ALREADY_IN_VFS_CONFIG=Cannot ${action} ${type}. 
Network ${networkName} already exists on network interface ${nicName} VFs 
configuration.
+ACTION_TYPE_FAILED_NETWORK_NOT_IN_VFS_CONFIG=Cannot ${action} ${type}. Network 
${networkName} doesn't exist on network interface ${nicName} VFs configuration.
 ACTION_TYPE_FAILED_NETWORK_NOT_EXIST=Cannot ${action} ${type}. Network with id 
${networkId} doesn't exist.
 
 ERROR_CANNOT_RECOVERY_STORAGE_POOL_THERE_IS_ACTIVE_DATA_DOMAINS=Cannot recover 
Data Center with active Data Storage Domain in Data Center.


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I30734cd8be89ed2750a5ade379e4539353b15a5e
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