Skip to content

Commit a1d2c53

Browse files
committed
Merge pull request apache#1007 from ustcweizhou/dedicated-ip-for-domain
[4.7] CLOUDSTACK-8958: add dedicated ips to domain (account for now)For now, we dedicate ip pool to account, however, other accounts in the same domain cannot fetch the ip from this ip pool. By dedicating ip pool to domain, accounts in the domain can fetch the public ip from same ip pool. * pr/1007: CLOUDSTACK-8958: throw an exception if project account cannot be found CLOUDSTACK-8958: add dedicated ips to domain (account for now) Signed-off-by: Remi Bergsma <[email protected]>
2 parents 9710046 + 89ce8bd commit a1d2c53

20 files changed

Lines changed: 380 additions & 55 deletions

File tree

api/src/com/cloud/configuration/ConfigurationService.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import com.cloud.dc.DataCenter;
4949
import com.cloud.dc.Pod;
5050
import com.cloud.dc.Vlan;
51+
import com.cloud.domain.Domain;
5152
import com.cloud.exception.ConcurrentOperationException;
5253
import com.cloud.exception.InsufficientCapacityException;
5354
import com.cloud.exception.InvalidParameterValueException;
@@ -255,6 +256,8 @@ Vlan createVlanAndPublicIpRange(CreateVlanIpRangeCmd cmd) throws InsufficientCap
255256

256257
Account getVlanAccount(long vlanId);
257258

259+
Domain getVlanDomain(long vlanId);
260+
258261
List<? extends NetworkOffering> listNetworkOfferings(TrafficType trafficType, boolean systemOnly);
259262

260263
Long getDefaultPageSize();

api/src/org/apache/cloudstack/api/command/admin/vlan/DedicatePublicIpRangeCmd.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class DedicatePublicIpRangeCmd extends BaseCmd {
4747
@Parameter(name = ApiConstants.ID, type = CommandType.UUID, entityType = VlanIpRangeResponse.class, required = true, description = "the id of the VLAN IP range")
4848
private Long id;
4949

50-
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, required = true, description = "account who will own the VLAN")
50+
@Parameter(name = ApiConstants.ACCOUNT, type = CommandType.STRING, description = "account who will own the VLAN")
5151
private String accountName;
5252

5353
@Parameter(name = ApiConstants.PROJECT_ID, type = CommandType.UUID, entityType = ProjectResponse.class, description = "project who will own the VLAN")

engine/components-api/src/com/cloud/configuration/ConfigurationManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.cloud.dc.HostPodVO;
2727
import com.cloud.dc.Pod;
2828
import com.cloud.dc.Vlan;
29+
import com.cloud.domain.Domain;
2930
import com.cloud.exception.ConcurrentOperationException;
3031
import com.cloud.exception.InsufficientCapacityException;
3132
import com.cloud.exception.InvalidParameterValueException;
@@ -213,7 +214,7 @@ NetworkOfferingVO createNetworkOffering(String name, String displayText, Traffic
213214
Map<NetworkOffering.Detail, String> details, boolean egressDefaultPolicy, Integer maxconn, boolean enableKeepAlive);
214215

215216
Vlan createVlanAndPublicIpRange(long zoneId, long networkId, long physicalNetworkId, boolean forVirtualNetwork, Long podId, String startIP, String endIP,
216-
String vlanGateway, String vlanNetmask, String vlanId, Account vlanOwner, String startIPv6, String endIPv6, String vlanIp6Gateway, String vlanIp6Cidr)
217+
String vlanGateway, String vlanNetmask, String vlanId, Domain domain, Account vlanOwner, String startIPv6, String endIPv6, String vlanIp6Gateway, String vlanIp6Cidr)
217218
throws InsufficientCapacityException, ConcurrentOperationException, InvalidParameterValueException;
218219

219220
void createDefaultSystemNetworks(long zoneId) throws ConcurrentOperationException;

engine/schema/resources/META-INF/cloudstack/core/spring-engine-schema-core-daos-context.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@
140140
<bean id="dataCenterLinkLocalIpAddressDaoImpl" class="com.cloud.dc.dao.DataCenterLinkLocalIpAddressDaoImpl" />
141141
<bean id="dataCenterVnetDaoImpl" class="com.cloud.dc.dao.DataCenterVnetDaoImpl" />
142142
<bean id="dataCenterDetailsDaoImpl" class="com.cloud.dc.dao.DataCenterDetailsDaoImpl" />
143+
<bean id="domainVlanMapDaoImpl" class="com.cloud.dc.dao.DomainVlanMapDaoImpl" />
143144
<bean id="engineDcDetailsDaoImpl" class="org.apache.cloudstack.engine.datacenter.entity.api.db.dao.DcDetailsDaoImpl" />
144145
<bean id="diskOfferingJoinDaoImpl" class="com.cloud.api.query.dao.DiskOfferingJoinDaoImpl" />
145146
<bean id="domainDaoImpl" class="com.cloud.domain.dao.DomainDaoImpl" />
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.dc;
18+
19+
import javax.persistence.Column;
20+
import javax.persistence.Entity;
21+
import javax.persistence.GeneratedValue;
22+
import javax.persistence.GenerationType;
23+
import javax.persistence.Id;
24+
import javax.persistence.Table;
25+
26+
import org.apache.cloudstack.api.InternalIdentity;
27+
28+
@Entity
29+
@Table(name="domain_vlan_map")
30+
public class DomainVlanMapVO implements InternalIdentity {
31+
32+
@Id
33+
@GeneratedValue(strategy=GenerationType.IDENTITY)
34+
@Column(name="id")
35+
private long id;
36+
37+
@Column(name="domain_id")
38+
private long domainId;
39+
40+
@Column(name="vlan_db_id")
41+
private long vlanDbId;
42+
43+
public DomainVlanMapVO(long domainId, long vlanDbId) {
44+
this.domainId = domainId;
45+
this.vlanDbId = vlanDbId;
46+
}
47+
48+
public DomainVlanMapVO() {
49+
50+
}
51+
52+
public long getId() {
53+
return id;
54+
}
55+
56+
public long getDomainId() {
57+
return domainId;
58+
}
59+
60+
public long getVlanDbId() {
61+
return vlanDbId;
62+
}
63+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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.dc.dao;
18+
19+
import java.util.List;
20+
21+
import com.cloud.dc.DomainVlanMapVO;
22+
import com.cloud.utils.db.GenericDao;
23+
24+
public interface DomainVlanMapDao extends GenericDao<DomainVlanMapVO, Long> {
25+
public List<DomainVlanMapVO> listDomainVlanMapsByDomain(long domainId);
26+
public List<DomainVlanMapVO> listDomainVlanMapsByVlan(long vlanDbId);
27+
public DomainVlanMapVO findDomainVlanMap(long domainId, long vlanDbId);
28+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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.dc.dao;
18+
19+
import java.util.List;
20+
21+
import javax.ejb.Local;
22+
23+
import org.springframework.stereotype.Component;
24+
25+
import com.cloud.dc.DomainVlanMapVO;
26+
import com.cloud.utils.db.GenericDaoBase;
27+
import com.cloud.utils.db.SearchBuilder;
28+
import com.cloud.utils.db.SearchCriteria;
29+
30+
@Component
31+
@Local(value={DomainVlanMapDao.class})
32+
public class DomainVlanMapDaoImpl extends GenericDaoBase<DomainVlanMapVO, Long> implements DomainVlanMapDao {
33+
protected SearchBuilder<DomainVlanMapVO> DomainSearch;
34+
protected SearchBuilder<DomainVlanMapVO> VlanSearch;
35+
protected SearchBuilder<DomainVlanMapVO> DomainVlanSearch;
36+
37+
@Override
38+
public List<DomainVlanMapVO> listDomainVlanMapsByDomain(long domainId) {
39+
SearchCriteria<DomainVlanMapVO> sc = DomainSearch.create();
40+
sc.setParameters("domainId", domainId);
41+
return listIncludingRemovedBy(sc);
42+
}
43+
44+
@Override
45+
public List<DomainVlanMapVO> listDomainVlanMapsByVlan(long vlanDbId) {
46+
SearchCriteria<DomainVlanMapVO> sc = VlanSearch.create();
47+
sc.setParameters("vlanDbId", vlanDbId);
48+
return listIncludingRemovedBy(sc);
49+
}
50+
51+
@Override
52+
public DomainVlanMapVO findDomainVlanMap(long domainId, long vlanDbId) {
53+
SearchCriteria<DomainVlanMapVO> sc = DomainVlanSearch.create();
54+
sc.setParameters("domainId", domainId);
55+
sc.setParameters("vlanDbId", vlanDbId);
56+
return findOneIncludingRemovedBy(sc);
57+
}
58+
59+
public DomainVlanMapDaoImpl() {
60+
DomainSearch = createSearchBuilder();
61+
DomainSearch.and("domainId", DomainSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
62+
DomainSearch.done();
63+
64+
VlanSearch = createSearchBuilder();
65+
VlanSearch.and("vlanDbId", VlanSearch.entity().getVlanDbId(), SearchCriteria.Op.EQ);
66+
VlanSearch.done();
67+
68+
DomainVlanSearch = createSearchBuilder();
69+
DomainVlanSearch.and("domainId", DomainVlanSearch.entity().getDomainId(), SearchCriteria.Op.EQ);
70+
DomainVlanSearch.and("vlanDbId", DomainVlanSearch.entity().getVlanDbId(), SearchCriteria.Op.EQ);
71+
DomainVlanSearch.done();
72+
}
73+
74+
}

engine/schema/src/com/cloud/dc/dao/VlanDaoImpl.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.springframework.stereotype.Component;
3030

3131
import com.cloud.dc.AccountVlanMapVO;
32+
import com.cloud.dc.DomainVlanMapVO;
3233
import com.cloud.dc.PodVlanMapVO;
3334
import com.cloud.dc.Vlan;
3435
import com.cloud.dc.Vlan.VlanType;
@@ -62,12 +63,15 @@ public class VlanDaoImpl extends GenericDaoBase<VlanVO, Long> implements VlanDao
6263
protected SearchBuilder<VlanVO> DedicatedVlanSearch;
6364

6465
protected SearchBuilder<AccountVlanMapVO> AccountVlanMapSearch;
66+
protected SearchBuilder<DomainVlanMapVO> DomainVlanMapSearch;
6567

6668
@Inject
6769
protected PodVlanMapDao _podVlanMapDao;
6870
@Inject
6971
protected AccountVlanMapDao _accountVlanMapDao;
7072
@Inject
73+
protected DomainVlanMapDao _domainVlanMapDao;
74+
@Inject
7175
protected IPAddressDao _ipAddressDao;
7276

7377
@Override
@@ -214,8 +218,12 @@ public boolean configure(String name, Map<String, Object> params) throws Configu
214218
AccountVlanMapSearch.and("accountId", AccountVlanMapSearch.entity().getAccountId(), SearchCriteria.Op.NULL);
215219
ZoneWideNonDedicatedVlanSearch.join("AccountVlanMapSearch", AccountVlanMapSearch, ZoneWideNonDedicatedVlanSearch.entity().getId(), AccountVlanMapSearch.entity()
216220
.getVlanDbId(), JoinBuilder.JoinType.LEFTOUTER);
221+
DomainVlanMapSearch = _domainVlanMapDao.createSearchBuilder();
222+
DomainVlanMapSearch.and("domainId", DomainVlanMapSearch.entity().getDomainId(), SearchCriteria.Op.NULL);
223+
ZoneWideNonDedicatedVlanSearch.join("DomainVlanMapSearch", DomainVlanMapSearch, ZoneWideNonDedicatedVlanSearch.entity().getId(), DomainVlanMapSearch.entity().getVlanDbId(), JoinBuilder.JoinType.LEFTOUTER);
217224
ZoneWideNonDedicatedVlanSearch.done();
218225
AccountVlanMapSearch.done();
226+
DomainVlanMapSearch.done();
219227

220228
DedicatedVlanSearch = createSearchBuilder();
221229
AccountVlanMapSearch = _accountVlanMapDao.createSearchBuilder();

server/src/com/cloud/api/ApiDBUtils.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
import com.cloud.dc.dao.DataCenterDao;
140140
import com.cloud.dc.dao.HostPodDao;
141141
import com.cloud.dc.dao.VlanDao;
142+
import com.cloud.domain.Domain;
142143
import com.cloud.domain.DomainVO;
143144
import com.cloud.domain.dao.DomainDao;
144145
import com.cloud.event.Event;
@@ -1245,6 +1246,10 @@ public static Account getVlanAccount(long vlanId) {
12451246
return s_configSvc.getVlanAccount(vlanId);
12461247
}
12471248

1249+
public static Domain getVlanDomain(long vlanId) {
1250+
return s_configSvc.getVlanDomain(vlanId);
1251+
}
1252+
12481253
public static boolean isSecurityGroupEnabledInZone(long zoneId) {
12491254
DataCenterVO dc = s_zoneDao.findById(zoneId);
12501255
if (dc == null) {

server/src/com/cloud/api/ApiResponseHelper.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,21 @@ public VlanIpRangeResponse createVlanIpRangeResponse(Vlan vlan) {
666666
if (owner != null) {
667667
populateAccount(vlanResponse, owner.getId());
668668
populateDomain(vlanResponse, owner.getDomainId());
669+
} else {
670+
Domain domain = ApiDBUtils.getVlanDomain(vlan.getId());
671+
if (domain != null) {
672+
populateDomain(vlanResponse, domain.getId());
673+
} else {
674+
Long networkId = vlan.getNetworkId();
675+
if (networkId != null) {
676+
Network network = _ntwkModel.getNetwork(networkId);
677+
if (network != null) {
678+
Long accountId = network.getAccountId();
679+
populateAccount(vlanResponse, accountId);
680+
populateDomain(vlanResponse, ApiDBUtils.findAccountById(accountId).getDomainId());
681+
}
682+
}
683+
}
669684
}
670685

671686
if (vlan.getPhysicalNetworkId() != null) {

0 commit comments

Comments
 (0)