cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yas...@apache.org
Subject [1/2] Contrail plugin fixes -master branch, single commit, no transaction wrappers
Date Wed, 15 Jan 2014 22:26:02 GMT
Updated Branches:
  refs/heads/master 7164fc6e7 -> cc2b1c496


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cc2b1c49/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java
b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java
index df0af90..4d0218c 100644
--- a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java
+++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualMachineModel.java
@@ -29,6 +29,7 @@ import net.juniper.contrail.api.types.VirtualMachine;
 
 import org.apache.cloudstack.network.contrail.management.ContrailManager;
 import org.apache.log4j.Logger;
+import org.apache.commons.lang.StringUtils;
 
 import com.cloud.exception.InternalErrorException;
 import com.cloud.network.dao.NetworkDao;
@@ -101,22 +102,27 @@ public class VirtualMachineModel extends ModelObjectBase {
         ApiConnector api = controller.getApiAccessor();
         _serviceUuid = serviceUuid;
 
-        ServiceInstanceModel siModel = manager.getDatabase().lookupServiceInstance(serviceUuid);
-        if (siModel == null) {
-            ServiceInstance siObj;
-            try {
-                siObj = (ServiceInstance)api.findById(ServiceInstance.class, serviceUuid);
-            } catch (IOException ex) {
-                s_logger.warn("service-instance read", ex);
-                throw new CloudRuntimeException("Unable to read service-instance object",
ex);
-            }
-            if (siObj == null) {
-                //If the ServiceInstance object is null, do not call build. It will break
in many places. Instead, call update passing the controller as parameter.
-                //It will then create a new ServiceInstance is that's null.
-                siModel = new ServiceInstanceModel(serviceUuid);
-                siModel.update(controller);
-
-                siObj = siModel.getServiceInstance();
+        ServiceInstance siObj;
+        try {
+            siObj = (ServiceInstance) api.findById(ServiceInstance.class, serviceUuid);
+        } catch (IOException ex) {
+            s_logger.warn("service-instance read", ex);
+            throw new CloudRuntimeException("Unable to read service-instance object", ex);
+        }
+        ServiceInstanceModel siModel;
+        if (siObj == null) {
+            siModel = new ServiceInstanceModel(serviceUuid);
+            siModel.build(controller, siObj);
+            manager.getDatabase().getServiceInstances().add(siModel);
+        } else {
+            String fqn = StringUtils.join(siObj.getQualifiedName(), ':');
+            siModel = manager.getDatabase().lookupServiceInstance(fqn);
+            if (siModel == null) {
+                if (siObj == null) {
+                    siModel = new ServiceInstanceModel(serviceUuid);
+                    siModel.build(controller, siObj);
+                    manager.getDatabase().getServiceInstances().add(siModel);
+                }
             }
         }
         _serviceModel = siModel;

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cc2b1c49/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java
b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java
index 547d4bd..b0505b1 100644
--- a/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java
+++ b/plugins/network-elements/juniper-contrail/src/org/apache/cloudstack/network/contrail/model/VirtualNetworkModel.java
@@ -29,6 +29,7 @@ import net.juniper.contrail.api.types.NetworkIpam;
 import net.juniper.contrail.api.types.Project;
 import net.juniper.contrail.api.types.SubnetType;
 import net.juniper.contrail.api.types.VirtualNetwork;
+import net.juniper.contrail.api.types.VirtualNetworkPolicyType;
 import net.juniper.contrail.api.types.VnSubnetsType;
 
 import org.apache.log4j.Logger;
@@ -66,6 +67,7 @@ public class VirtualNetworkModel extends ModelObjectBase {
     private NetworkIpam _ipam;
 
     private FloatingIpPoolModel _fipPoolModel;
+    private NetworkPolicyModel _policyModel;
 
     public VirtualNetworkModel(Network network, String uuid, String name, TrafficType trafficType)
{
         _uuid = uuid;
@@ -133,6 +135,10 @@ public class VirtualNetworkModel extends ModelObjectBase {
             successor.delete(controller);
         }
 
+        if (_policyModel != null) {
+            _policyModel.removeSuccessor(this);
+        }
+
         try {
             api.delete(VirtualNetwork.class, _uuid);
         } catch (IOException ex) {
@@ -181,6 +187,8 @@ public class VirtualNetworkModel extends ModelObjectBase {
             }
         }
 
+        _id = network.getId();
+
         try {
             _projectId = manager.getProjectId(network.getDomainId(), network.getAccountId());
         } catch (IOException ex) {
@@ -226,6 +234,16 @@ public class VirtualNetworkModel extends ModelObjectBase {
             }
         }
 
+        if (_policyModel == null) {
+            vn.clearNetworkPolicy();
+        } else if (!_policyModel.hasPolicyRules()) {
+            vn.clearNetworkPolicy();
+            _policyModel.removeSuccessor(this);
+        } else {
+            vn.setNetworkPolicy(_policyModel.getPolicy(), new VirtualNetworkPolicyType(
+                    new VirtualNetworkPolicyType.SequenceType(1, 0), null));
+        }
+
         if (_ipam == null) {
             NetworkIpam ipam = null;
             try {
@@ -402,6 +420,22 @@ public class VirtualNetworkModel extends ModelObjectBase {
             return false;
         }
 
+        List<ObjectReference<VirtualNetworkPolicyType>> policyRefs = _vn.getNetworkPolicy();
+        if ((policyRefs == null || policyRefs.isEmpty()) && _policyModel != null)
{
+            return false;
+        }
+
+        if ((policyRefs != null && !policyRefs.isEmpty()) && _policyModel
== null) {
+            return false;
+        }
+
+        if (policyRefs != null && !policyRefs.isEmpty() && _policyModel !=
null) {
+            ObjectReference<VirtualNetworkPolicyType> ref = policyRefs.get(0);
+            if (!ref.getUuid().equals(_policyModel.getUuid())) {
+                return false;
+            }
+        }
+
         for (ModelObject successor : successors()) {
             if (!successor.verify(controller)) {
                 return false;
@@ -413,8 +447,6 @@ public class VirtualNetworkModel extends ModelObjectBase {
     @Override
     public boolean compare(ModelController controller, ModelObject o) {
         VirtualNetworkModel latest;
-        ApiConnector api = controller.getApiAccessor();
-
         assert this._vn != null : "vnc virtual network current is not initialized";
 
         try {
@@ -475,6 +507,40 @@ public class VirtualNetworkModel extends ModelObjectBase {
             return false;
         }
 
+        List<ObjectReference<VirtualNetworkPolicyType>> currentPolicyRefs = this._vn.getNetworkPolicy();
+        List<ObjectReference<VirtualNetworkPolicyType>> latestPolicyRefs = latest._vn.getNetworkPolicy();
+
+        if (currentPolicyRefs == null && latestPolicyRefs == null) {
+            return true;
+        }
+
+        if ((currentPolicyRefs == null && latestPolicyRefs != null) ||
+                (currentPolicyRefs != null && latestPolicyRefs == null) ||
+                (currentPolicyRefs.size() != latestPolicyRefs.size())) {
+            return false;
+        }
+
+        if (currentPolicyRefs.isEmpty() && latestPolicyRefs.isEmpty()) {
+            return true;
+        }
+
+        //both must be non empty lists
+        ObjectReference<VirtualNetworkPolicyType> ref1 = currentPolicyRefs.get(0);
+        ObjectReference<VirtualNetworkPolicyType> ref2 = latestPolicyRefs.get(0);
+
+        if ((ref1 != null && ref2 == null) || (ref1 == null && ref2 != null))
{
+            return false;
+        }
+
+        if ((ref1.getUuid() != null && ref2.getUuid() == null) || (ref1.getUuid()
== null && ref2.getUuid() != null)) {
+            return false;
+        }
+        if (ref1.getUuid() == null && ref2.getUuid() == null) {
+            return true;
+        }
+        if (!ref1.getUuid().equals(ref2.getUuid())) {
+            return false;
+        }
         return true;
     }
 
@@ -485,4 +551,18 @@ public class VirtualNetworkModel extends ModelObjectBase {
     public void setFipPoolModel(FloatingIpPoolModel fipPoolModel) {
         _fipPoolModel = fipPoolModel;
     }
+
+    public NetworkPolicyModel getNetworkPolicyModel() {
+        return _policyModel;
+    }
+
+    public void addToNetworkPolicy(NetworkPolicyModel policyModel) {
+        if (_policyModel != null) {
+            _policyModel.removeSuccessor(this);
+        }
+        _policyModel = policyModel;
+        if (_policyModel != null) {
+            _policyModel.addSuccessor(this);
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cc2b1c49/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
index cd7ac35..e16eedb 100644
--- a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
+++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/ManagementServerMock.java
@@ -357,10 +357,10 @@ public class ManagementServerMock {
         }
 
         Pair<List<? extends PhysicalNetworkServiceProvider>, Integer> providers
=
-            _networkService.listNetworkServiceProviders(_znet.getId(), Provider.JuniperContrail.getName(),
null, null, null);
+            _networkService.listNetworkServiceProviders(_znet.getId(), Provider.JuniperContrailRouter.getName(),
null, null, null);
         if (providers.second() == 0) {
-            s_logger.debug("Add " + Provider.JuniperContrail.getName() + " to network " +
_znet.getName());
-            PhysicalNetworkServiceProvider provider = _networkService.addProviderToPhysicalNetwork(_znet.getId(),
Provider.JuniperContrail.getName(), null, null);
+            s_logger.debug("Add " + Provider.JuniperContrailRouter.getName() + " to network
" + _znet.getName());
+            PhysicalNetworkServiceProvider provider = _networkService.addProviderToPhysicalNetwork(_znet.getId(),
Provider.JuniperContrailRouter.getName(), null, null);
             _networkService.updateNetworkServiceProvider(provider.getId(), PhysicalNetworkServiceProvider.State.Enabled.toString(),
null);
         } else {
             PhysicalNetworkServiceProvider provider = providers.first().get(0);
@@ -372,7 +372,7 @@ public class ManagementServerMock {
         providers = _networkService.listNetworkServiceProviders(_znet.getId(), null, PhysicalNetworkServiceProvider.State.Enabled.toString(),
null, null);
         s_logger.debug(_znet.getName() + " has " + providers.second().toString() + " Enabled
providers");
         for (PhysicalNetworkServiceProvider provider : providers.first()) {
-            if (provider.getProviderName().equals(Provider.JuniperContrail.getName())) {
+            if (provider.getProviderName().equals(Provider.JuniperContrailRouter.getName()))
{
                 continue;
             }
             s_logger.debug("Disabling " + provider.getProviderName());

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/cc2b1c49/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
index 6996a28..9520490 100644
--- a/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
+++ b/plugins/network-elements/juniper-contrail/test/org/apache/cloudstack/network/contrail/management/NetworkProviderTest.java
@@ -204,7 +204,7 @@ public class NetworkProviderTest extends TestCase {
         ManagementServerMock.setParameter(cmd, "accountName", BaseCmd.CommandType.STRING,
system.getAccountName());
         ManagementServerMock.setParameter(cmd, ApiConstants.NAME, BaseCmd.CommandType.STRING,
name);
         ManagementServerMock.setParameter(cmd, "displayText", BaseCmd.CommandType.STRING,
"test network");
-        ManagementServerMock.setParameter(cmd, "networkOfferingId", BaseCmd.CommandType.LONG,
_contrailMgr.getOffering().getId());
+        ManagementServerMock.setParameter(cmd, "networkOfferingId", BaseCmd.CommandType.LONG,
_contrailMgr.getRouterOffering().getId());
         ManagementServerMock.setParameter(cmd, "zoneId", BaseCmd.CommandType.LONG, zone.getId());
         ManagementServerMock.setParameter(cmd, ApiConstants.GATEWAY, BaseCmd.CommandType.STRING,
"10.0.1.254");
         ManagementServerMock.setParameter(cmd, ApiConstants.NETMASK, BaseCmd.CommandType.STRING,
"255.255.255.0");


Mime
View raw message