Skip to content

Commit 2c77869

Browse files
committed
some bug fixes
1 parent e045883 commit 2c77869

11 files changed

Lines changed: 279 additions & 78 deletions

File tree

plugins/hypervisors/xen/src/com/cloud/hypervisor/xen/resource/CitrixResourceBase.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -999,7 +999,7 @@ private synchronized Network findOrCreateTunnelNetwork(Connection conn, String n
999999
/**
10001000
* This method creates a XenServer network and configures it for being used as a L2-in-L3 tunneled network
10011001
*/
1002-
private synchronized Network configureTunnelNetwork(Connection conn, long networkId, long hostId, String bridgeName) {
1002+
private synchronized Network configureTunnelNetwork(Connection conn, Long networkId, long hostId, String bridgeName) {
10031003
try {
10041004
Network nw = findOrCreateTunnelNetwork(conn, bridgeName);
10051005
String nwName = bridgeName;
@@ -1038,7 +1038,7 @@ private synchronized Network configureTunnelNetwork(Connection conn, long networ
10381038
String[] res = result.split(":");
10391039
if (res.length != 2 || !res[0].equalsIgnoreCase("SUCCESS")) {
10401040
//TODO: Should make this error not fatal?
1041-
throw new CloudRuntimeException("Unable to pre-configure OVS bridge " + bridge + " for network ID:" + networkId + " - " + res);
1041+
throw new CloudRuntimeException("Unable to pre-configure OVS bridge " + bridge );
10421042
}
10431043
}
10441044
return nw;
@@ -1090,7 +1090,7 @@ protected Network getNetwork(Connection conn, NicTO nic) throws XenAPIException,
10901090
_isOvs = true;
10911091
return setupvSwitchNetwork(conn);
10921092
} else {
1093-
return findOrCreateTunnelNetwork(conn, getOvsTunnelNetworkName(BroadcastDomainType.getValue(uri)));
1093+
return findOrCreateTunnelNetwork(conn, getOvsTunnelNetworkName(uri.getAuthority()));
10941094
}
10951095
} else if (type == BroadcastDomainType.Storage) {
10961096
if (uri == null) {
@@ -1114,7 +1114,7 @@ protected Network getNetwork(Connection conn, NicTO nic) throws XenAPIException,
11141114

11151115
private String getOvsTunnelNetworkName(String broadcastUri) {
11161116
if (broadcastUri.contains(".")) {
1117-
String[] parts = broadcastUri.split(".");
1117+
String[] parts = broadcastUri.split("\\.");
11181118
return "OVS-DR-VPC-Bridge"+parts[0];
11191119
} else {
11201120
try {
@@ -5266,7 +5266,8 @@ private Answer execute(OvsDestroyTunnelCommand cmd) {
52665266
}
52675267

52685268
String bridge = nw.getBridge(conn);
5269-
String result = callHostPlugin(conn, "ovstunnel", "configure_ovs_bridge_for_network_topology", "bridge", bridge, "in_port", cmd.getInPortName());
5269+
String result = callHostPlugin(conn, "ovstunnel", "destroy_tunnel", "bridge", bridge, "in_port", cmd.getInPortName());
5270+
52705271
if (result.equalsIgnoreCase("SUCCESS")) {
52715272
return new Answer(cmd, true, result);
52725273
} else {
@@ -5282,7 +5283,8 @@ public Answer execute(OvsVpcPhysicalTopologyConfigCommand cmd) {
52825283
Connection conn = getConnection();
52835284
try {
52845285
String result = callHostPlugin(conn, "ovstunnel", "configure_ovs_bridge_for_network_topology", "bridge",
5285-
cmd.getBridgeName(), "host-id", ((Long)cmd.getHostId()).toString());
5286+
cmd.getBridgeName(), "host-id", ((Long)cmd.getHostId()).toString(), "config",
5287+
cmd.getjsonVpcConfig());
52865288
if (result.equalsIgnoreCase("SUCCESS")) {
52875289
return new Answer(cmd, true, result);
52885290
} else {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.agent.api;
18+
19+
/**
20+
* This command represents view of how a VPC is laid out (on which hosts, which VM is on which host etc)
21+
* on the physical infrastructure.
22+
*/
23+
public class OvsVpcLogicalTopologyConfigCommand extends Command {
24+
25+
public OvsVpcLogicalTopologyConfigCommand() {
26+
27+
}
28+
29+
@Override
30+
public boolean executeInSequence() {
31+
return false;
32+
}
33+
}

plugins/network-elements/ovs/src/com/cloud/agent/api/OvsVpcPhysicalTopologyConfigCommand.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
import com.google.gson.GsonBuilder;
2121

2222
/**
23-
* This command represents view of how a VPC is laid out (on which hosts, which VM is on which host etc)
24-
* on the physical infrastructure.
23+
* This command represents physical view of how a VPC is laid out on the physical infrastructure.
24+
* - on which hypervisor hosts VPC spans (host is running in at least one VM from the VPC)
25+
* - information of tiers, so we can figure how one VM can talk to a different VM in same tier or different tier
26+
* - information on all the VM's in the VPC.
27+
* - information of NIC's of each VM in the VPC
2528
*/
2629
public class OvsVpcPhysicalTopologyConfigCommand extends Command {
2730

plugins/network-elements/ovs/src/com/cloud/network/element/OvsElement.java

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@
7575
import com.cloud.vm.ReservationContext;
7676
import com.cloud.vm.VirtualMachineProfile;
7777
import com.cloud.vm.dao.DomainRouterDao;
78-
import com.cloud.vm.UserVmVO;
7978
import com.cloud.vm.VirtualMachine;
8079

8180
@Local(value = {NetworkElement.class, ConnectivityProvider.class,
@@ -205,23 +204,6 @@ public boolean release(Network network, NicProfile nic,
205204
return false;
206205
}
207206

208-
List<UserVmVO> userVms = _userVmDao.listByAccountIdAndHostId(vm.getVirtualMachine().getAccountId(),
209-
vm.getVirtualMachine().getHostId());
210-
if (vm.getType() == VirtualMachine.Type.User) {
211-
if (userVms.size() > 1) {
212-
return true;
213-
}
214-
215-
List<DomainRouterVO> routers = _routerDao.findByNetwork(network.getId());
216-
for (DomainRouterVO router : routers) {
217-
if (router.getHostId().equals(vm.getVirtualMachine().getHostId())) {
218-
return true;
219-
}
220-
}
221-
} else if (vm.getType() == VirtualMachine.Type.DomainRouter && userVms.size() != 0) {
222-
return true;
223-
}
224-
225207
HostVO host = _hostDao.findById(vm.getVirtualMachine().getHostId());
226208
_ovsTunnelMgr.checkAndRemoveHostFromTunnelNetwork(network, host);
227209
return true;

plugins/network-elements/ovs/src/com/cloud/network/guru/OvsGuestNetworkGuru.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public Network implement(Network network, NetworkOffering offering,
154154
if (network.getVpcId() != null && isVpcEnabledForDistributedRouter(network.getVpcId())) {
155155
String keyStr = BroadcastDomainType.getValue(implemented.getBroadcastUri());
156156
Long vpcid= network.getVpcId();
157-
implemented.setBroadcastUri(BroadcastDomainType.Vswitch.toUri(vpcid.toString()+keyStr));
157+
implemented.setBroadcastUri(BroadcastDomainType.Vswitch.toUri(vpcid.toString() + "." + keyStr));
158158
}
159159

160160
return implemented;

plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsNetworkTopologyGuru.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public interface OvsNetworkTopologyGuru extends Manager {
3737
*/
3838
public List<Long> getVpcOnHost(long hostId);
3939

40+
/**
41+
* get the list of all active Vm id's in a network
42+
*/
43+
public List<Long> getAllActiveVmsInNetwork(long networkId);
44+
4045
/**
4146
* get the list of all active Vm id's in the VPC for all ther tiers
4247
*/
@@ -46,4 +51,9 @@ public interface OvsNetworkTopologyGuru extends Manager {
4651
* get the list of all Vm id's in the VPC for all the tiers that are running on the host
4752
*/
4853
public List<Long> getActiveVmsInVpcOnHost(long vpcId, long hostId);
54+
55+
/**
56+
* get the list of all Vm id's in the network that are running on the host
57+
*/
58+
public List<Long> getActiveVmsInNetworkOnHost(long vpcId, long hostId);
4959
}

plugins/network-elements/ovs/src/com/cloud/network/ovs/OvsNetworkTopologyGuruImpl.java

Lines changed: 121 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,24 @@
11
package com.cloud.network.ovs;
22

3+
import com.cloud.network.Network;
4+
import com.cloud.network.Networks;
5+
import com.cloud.network.dao.NetworkDao;
6+
import com.cloud.network.vpc.VpcManager;
37
import com.cloud.utils.component.ManagerBase;
48
import com.cloud.vm.DomainRouterVO;
59
import com.cloud.vm.UserVmVO;
610
import com.cloud.vm.VMInstanceVO;
711
import com.cloud.vm.VirtualMachine;
12+
import com.cloud.vm.NicVO;
13+
import com.cloud.vm.Nic;
814
import com.cloud.vm.dao.DomainRouterDao;
15+
import com.cloud.vm.dao.NicDao;
916
import com.cloud.vm.dao.UserVmDao;
17+
import com.cloud.vm.dao.VMInstanceDao;
1018
import java.util.ArrayList;
19+
import java.util.HashSet;
1120
import java.util.List;
21+
import java.util.Set;
1222
import javax.ejb.Local;
1323
import javax.inject.Inject;
1424
import org.springframework.stereotype.Component;
@@ -21,6 +31,14 @@ public class OvsNetworkTopologyGuruImpl extends ManagerBase implements OvsNetwor
2131
UserVmDao _userVmDao;
2232
@Inject
2333
DomainRouterDao _routerDao;
34+
@Inject
35+
VpcManager _vpcMgr;
36+
@Inject
37+
VMInstanceDao _vmInstanceDao;
38+
@Inject
39+
NicDao _nicDao;
40+
@Inject
41+
NetworkDao _networkDao;
2442

2543
/**
2644
* get the list of hypervisor hosts on which VM's belonging to a network currently spans
@@ -52,23 +70,121 @@ public List<Long> getNetworkSpanedHosts(long networkId) {
5270
return hostIds;
5371
}
5472

73+
/**
74+
* get the list of hypervisor hosts on which VM's belonging to a VPC currently spans
75+
*/
5576
@Override
56-
public List<Long> getVpcSpannedHosts(long vpId) {
57-
return null;
77+
public List<Long> getVpcSpannedHosts(long vpcId) {
78+
List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId);
79+
List<Long> vpcHostIds = new ArrayList<>();
80+
for (Network vpcNetwork : vpcNetworks) {
81+
List<Long> networkHostIds = new ArrayList<Long>();
82+
networkHostIds = getNetworkSpanedHosts(vpcNetwork.getId());
83+
if (networkHostIds != null && !networkHostIds.isEmpty()) {
84+
for (Long hostId : networkHostIds) {
85+
if (!vpcHostIds.contains(hostId)) {
86+
vpcHostIds.add(hostId);
87+
}
88+
}
89+
}
90+
}
91+
return vpcHostIds;
5892
}
5993

6094
@Override
6195
public List<Long> getVpcOnHost(long hostId) {
62-
return null;
96+
List<Long> vpcIds = new ArrayList<>();
97+
List<VMInstanceVO> vmInstances = _vmInstanceDao.listByHostId(hostId);
98+
for (VMInstanceVO instance : vmInstances) {
99+
List<NicVO> nics = _nicDao.listByVmId(instance.getId());
100+
for (Nic nic: nics) {
101+
Network network = _networkDao.findById(nic.getNetworkId());
102+
if (network.getTrafficType() == Networks.TrafficType.Guest && network.getVpcId() != null) {
103+
if (!vpcIds.contains(network.getVpcId())) {
104+
vpcIds.add(network.getVpcId());
105+
}
106+
}
107+
}
108+
}
109+
return vpcIds;
110+
}
111+
112+
@Override
113+
public List<Long> getAllActiveVmsInNetwork(long networkId) {
114+
List <Long> vmIds = new ArrayList<>();
115+
List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId,
116+
VirtualMachine.State.Running, VirtualMachine.State.Starting, VirtualMachine.State.Stopping, VirtualMachine.State.Unknown,
117+
VirtualMachine.State.Migrating);
118+
// Find routers for the network
119+
List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
120+
List<VMInstanceVO> ins = new ArrayList<VMInstanceVO>();
121+
122+
if (vms != null) {
123+
for (UserVmVO vm : vms) {
124+
vmIds.add(vm.getId());
125+
}
126+
}
127+
if (routers.size() != 0) {
128+
for (DomainRouterVO router: routers) {
129+
vmIds.add(router.getId());
130+
}
131+
}
132+
return vmIds;
63133
}
64134

65135
@Override
66136
public List<Long> getAllActiveVmsInVpc(long vpcId) {
67-
return null;
137+
138+
Set<Long> vmIdsSet = new HashSet<>();
139+
List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId);
140+
for (Network network : vpcNetworks) {
141+
List<Long> networkVmIds = getAllActiveVmsInNetwork(network.getId());
142+
if (networkVmIds != null && !networkVmIds.isEmpty()) {
143+
vmIdsSet.addAll(networkVmIds);
144+
}
145+
}
146+
List<Long> vmIds = new ArrayList<>();
147+
vmIds.addAll(vmIdsSet);
148+
return vmIds;
68149
}
69150

70151
@Override
71152
public List<Long> getActiveVmsInVpcOnHost(long vpcId, long hostId) {
72-
return null;
153+
Set<Long> vmIdsSet = new HashSet<>();
154+
List<? extends Network> vpcNetworks = _vpcMgr.getVpcNetworks(vpcId);
155+
for (Network network : vpcNetworks) {
156+
List<Long> networkVmIds = getActiveVmsInNetworkOnHost(network.getId(), hostId);
157+
if (networkVmIds != null && !networkVmIds.isEmpty()) {
158+
vmIdsSet.addAll(networkVmIds);
159+
}
160+
}
161+
List<Long> vmIds = new ArrayList<>();
162+
vmIds.addAll(vmIdsSet);
163+
return vmIds;
164+
}
165+
166+
@Override
167+
public List<Long> getActiveVmsInNetworkOnHost(long networkId, long hostId) {
168+
List <Long> vmIds = new ArrayList<>();
169+
List<UserVmVO> vms = _userVmDao.listByNetworkIdAndStates(networkId,
170+
VirtualMachine.State.Running, VirtualMachine.State.Starting, VirtualMachine.State.Stopping, VirtualMachine.State.Unknown,
171+
VirtualMachine.State.Migrating);
172+
// Find routers for the network
173+
List<DomainRouterVO> routers = _routerDao.findByNetwork(networkId);
174+
List<VMInstanceVO> ins = new ArrayList<VMInstanceVO>();
175+
176+
if (vms != null) {
177+
for (UserVmVO vm : vms) {
178+
if (vm.getHostId() == hostId)
179+
vmIds.add(vm.getId());
180+
}
181+
}
182+
if (routers.size() != 0) {
183+
for (DomainRouterVO router: routers) {
184+
if (router.getHostId() == hostId)
185+
vmIds.add(router.getId());
186+
}
187+
}
188+
return vmIds;
73189
}
74190
}

0 commit comments

Comments
 (0)