diff --git a/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java b/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java index 59ef6686ef0..5aa4fca4afa 100644 --- a/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java +++ b/core/src/com/cloud/agent/api/routing/SetNetworkACLCommand.java @@ -45,12 +45,8 @@ public class SetNetworkACLCommand extends NetworkElementCommand { public String[][] generateFwRules() { final List aclList = Arrays.asList(rules); - Collections.sort(aclList, new Comparator() { - @Override - public int compare(final NetworkACLTO acl1, final NetworkACLTO acl2) { - return acl1.getNumber() < acl2.getNumber() ? 1 : -1; - } - }); + + orderNetworkAclRulesByRuleNumber(aclList); final String[][] result = new String[2][aclList.size()]; int i = 0; @@ -97,6 +93,15 @@ public class SetNetworkACLCommand extends NetworkElementCommand { return result; } + protected void orderNetworkAclRulesByRuleNumber(List aclList) { + Collections.sort(aclList, new Comparator() { + @Override + public int compare(final NetworkACLTO acl1, final NetworkACLTO acl2) { + return acl1.getNumber() > acl2.getNumber() ? 1 : -1; + } + }); + } + public NicTO getNic() { return nic; } diff --git a/core/test/com/cloud/agent/api/routing/SetNetworkACLCommandTest.java b/core/test/com/cloud/agent/api/routing/SetNetworkACLCommandTest.java new file mode 100644 index 00000000000..af30652d8ca --- /dev/null +++ b/core/test/com/cloud/agent/api/routing/SetNetworkACLCommandTest.java @@ -0,0 +1,53 @@ +// +// Licensed to the Apache Software Foundation (ASF) under one +// or more contributor license agreements. See the NOTICE file +// distributed with this work for additional information +// regarding copyright ownership. The ASF licenses this file +// to you under the Apache License, Version 2.0 (the +// "License"); you may not use this file except in compliance +// with the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. +// + +package com.cloud.agent.api.routing; + +import static org.junit.Assert.assertEquals; + +import java.util.List; + +import org.junit.Test; + +import com.cloud.agent.api.to.NetworkACLTO; +import com.google.common.collect.Lists; + +public class SetNetworkACLCommandTest { + + @Test + public void testNetworkAclRuleOrdering(){ + + //given + List aclList = Lists.newArrayList(); + + aclList.add(new NetworkACLTO(3, null, null, null, null, false, false, null, null, null, null, false, 3)); + aclList.add(new NetworkACLTO(1, null, null, null, null, false, false, null, null, null, null, false, 1)); + aclList.add(new NetworkACLTO(2, null, null, null, null, false, false, null, null, null, null, false, 2)); + + SetNetworkACLCommand cmd = new SetNetworkACLCommand(aclList, null); + + //when + cmd.orderNetworkAclRulesByRuleNumber(aclList); + + //then + for(int i=0; i< aclList.size();i++){ + assertEquals(aclList.get(i).getNumber(), i+1); + } + } +} diff --git a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java index 2a79d26b045..f3f9f643466 100644 --- a/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java +++ b/plugins/hypervisors/xenserver/src/com/cloud/hypervisor/xenserver/resource/wrapper/xen610/XenServer610MigrateWithStorageCommandWrapper.java @@ -24,6 +24,7 @@ import java.util.List; import java.util.Map; import java.util.Set; +import com.cloud.utils.Pair; import org.apache.cloudstack.storage.to.VolumeObjectTO; import org.apache.log4j.Logger; @@ -60,7 +61,7 @@ public final class XenServer610MigrateWithStorageCommandWrapper extends CommandW public Answer execute(final MigrateWithStorageCommand command, final XenServer610Resource xenServer610Resource) { final Connection connection = xenServer610Resource.getConnection(); final VirtualMachineTO vmSpec = command.getVirtualMachine(); - final Map volumeToFiler = command.getVolumeToFiler(); + final List> volumeToFiler = command.getVolumeToFilerAsList(); final String vmName = vmSpec.getName(); Task task = null; @@ -80,13 +81,14 @@ public final class XenServer610MigrateWithStorageCommandWrapper extends CommandW final XsLocalNetwork nativeNetworkForTraffic = xenServer610Resource.getNativeNetworkForTraffic(connection, TrafficType.Storage, null); final Network networkForSm = nativeNetworkForTraffic.getNetwork(); - // Create the vif map. The vm stays in the same cluster so we have to pass an empty vif map. + // Create the vif map. The vm stays in the same cluster so we have to pass an empty vif map. final Map vifMap = new HashMap(); final Map vdiMap = new HashMap(); - for (final Map.Entry entry : volumeToFiler.entrySet()) { - final VolumeTO volume = entry.getKey(); - final StorageFilerTO sotrageFiler = entry.getValue(); - vdiMap.put(xenServer610Resource.getVDIbyUuid(connection, volume.getPath()), xenServer610Resource.getStorageRepository(connection, sotrageFiler.getUuid())); + + for (final Pair entry : volumeToFiler) { + final StorageFilerTO storageFiler = entry.second(); + final VolumeTO volume = entry.first(); + vdiMap.put(xenServer610Resource.getVDIbyUuid(connection, volume.getPath()), xenServer610Resource.getStorageRepository(connection, storageFiler.getUuid())); } // Get the vm to migrate.