Skip to content

Commit a06bd9f

Browse files
author
Prachi Damle
committed
CLOUDSTACK-4168 Root Admin should be able to create 'ExplicitDedication' affinity group at domain level and make it available for all accounts in the domain
Changes: - 'ExcplicitDedication' type of group can be created/deleted by Root admin only - Users can no longer create this type of affinity group - RootAdmin can create this type of affinitygroup at domain level. Such a domain level group is available for all accounts in that domain for listing and for use during deployVM. - The domain level affinitygroup should be visible to the users in that domain, domain admins and Root admin. Conflicts: server/src/com/cloud/api/query/QueryManagerImpl.java server/src/org/apache/cloudstack/affinity/AffinityGroupServiceImpl.java server/test/org/apache/cloudstack/affinity/AffinityApiUnitTest.java
1 parent 4952591 commit a06bd9f

21 files changed

Lines changed: 634 additions & 46 deletions

File tree

api/src/org/apache/cloudstack/affinity/AffinityGroup.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,6 @@ public interface AffinityGroup extends ControlledEntity, InternalIdentity, Ident
2828

2929
String getType();
3030

31+
ACLType getAclType();
32+
3133
}

api/src/org/apache/cloudstack/affinity/AffinityGroupProcessor.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,23 @@ void process(VirtualMachineProfile vm, DeploymentPlan plan, ExcludeList avoid)
5858
*/
5959
boolean check(VirtualMachineProfile vm, DeployDestination plannedDestination)
6060
throws AffinityConflictException;
61+
62+
/**
63+
* isAdminControlledGroup() should return true if the affinity/anti-affinity
64+
* group can only be operated on[create/delete/modify] by the Admin
65+
*
66+
* @return boolean true/false
67+
*/
68+
boolean isAdminControlledGroup();
69+
70+
71+
/**
72+
* canBeSharedDomainWide() should return true if the affinity/anti-affinity
73+
* group can be created for a domain and shared by all accounts under the
74+
* domain.
75+
*
76+
* @return boolean true/false
77+
*/
78+
boolean canBeSharedDomainWide();
79+
6180
}

api/src/org/apache/cloudstack/affinity/AffinityGroupService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,8 @@ Pair<List<? extends AffinityGroup>, Integer> listAffinityGroups(Long affinityGro
7575

7676
boolean isAffinityGroupProcessorAvailable(String affinityGroupType);
7777

78+
boolean isAdminControlledGroup(AffinityGroup group);
79+
80+
boolean isAffinityGroupAvailableInDomain(long affinityGroupId, long domainId);
81+
7882
}

api/src/org/apache/cloudstack/affinity/AffinityProcessorBase.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,14 @@ public boolean check(VirtualMachineProfile vm, DeployDestination plannedDestinat
4747
throws AffinityConflictException {
4848
return true;
4949
}
50+
51+
@Override
52+
public boolean isAdminControlledGroup() {
53+
return false;
54+
}
55+
56+
@Override
57+
public boolean canBeSharedDomainWide() {
58+
return false;
59+
}
5060
}

client/tomcatconf/applicationContext.xml.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,7 @@
377377
<bean id="StaticRoleBasedAPIAccessChecker" class="org.apache.cloudstack.acl.StaticRoleBasedAPIAccessChecker"/>
378378
<bean id="databaseIntegrityChecker" class="com.cloud.upgrade.DatabaseIntegrityChecker" />
379379
<bean id="domainChecker" class="com.cloud.acl.DomainChecker" />
380+
<bean id="affinityGroupAccessChecker" class="com.cloud.acl.AffinityGroupAccessChecker" />
380381

381382
<!--
382383
Authenticators
@@ -929,6 +930,8 @@
929930
</bean>
930931
<bean id="AffinityGroupVMMapDaoImpl" class="org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDaoImpl">
931932
</bean>
933+
<bean id="AffinityGroupDomainMapDaoImpl" class="org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDaoImpl">
934+
</bean>
932935

933936
<bean id="PlannerHostReservationDaoImpl" class="com.cloud.deploy.dao.PlannerHostReservationDaoImpl">
934937
</bean>

client/tomcatconf/componentContext.xml.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@
146146
<bean id="securityCheckers" class="com.cloud.utils.component.AdapterList">
147147
<property name="Adapters">
148148
<list>
149+
<ref bean="affinityGroupAccessChecker"/>
149150
<ref bean="domainChecker"/>
150151
</list>
151152
</property>

engine/schema/src/com/cloud/user/AccountVO.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public class AccountVO implements Account {
6565

6666
@Column(name="default_zone_id")
6767
private Long defaultZoneId = null;
68-
68+
6969
@Column(name = "default")
7070
boolean isDefault;
7171

@@ -77,7 +77,7 @@ public AccountVO(long id) {
7777
this.id = id;
7878
this.uuid = UUID.randomUUID().toString();
7979
}
80-
80+
8181
public AccountVO(String accountName, long domainId, String networkDomain, short type, String uuid) {
8282
this.accountName = accountName;
8383
this.domainId = domainId;
@@ -161,7 +161,7 @@ public long getAccountId() {
161161

162162
@Override
163163
public String toString() {
164-
return new StringBuilder("Acct[").append(id).append("-").append(accountName).append("]").toString();
164+
return new StringBuilder("Acct[").append(uuid).append("-").append(accountName).append("]").toString();
165165
}
166166

167167
@Override
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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 org.apache.cloudstack.affinity;
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 com.cloud.domain.PartOf;
27+
import org.apache.cloudstack.api.InternalIdentity;
28+
29+
@Entity
30+
@Table(name = "affinity_group_domain_map")
31+
public class AffinityGroupDomainMapVO implements PartOf, InternalIdentity {
32+
33+
@Id
34+
@GeneratedValue(strategy = GenerationType.IDENTITY)
35+
long id;
36+
37+
@Column(name = "domain_id")
38+
long domainId;
39+
40+
@Column(name = "affinity_group_id")
41+
private long affinityGroupId;
42+
43+
@Column(name = "subdomain_access")
44+
public Boolean subdomainAccess;
45+
46+
protected AffinityGroupDomainMapVO() {
47+
}
48+
49+
public AffinityGroupDomainMapVO(long affinityGroupId, long domainId, Boolean subdomainAccess) {
50+
this.affinityGroupId = affinityGroupId;
51+
this.domainId = domainId;
52+
this.subdomainAccess = subdomainAccess;
53+
}
54+
55+
@Override
56+
public long getId() {
57+
return id;
58+
}
59+
60+
@Override
61+
public long getDomainId() {
62+
return domainId;
63+
}
64+
65+
public long getAffinityGroupId() {
66+
return affinityGroupId;
67+
}
68+
69+
public Boolean isSubdomainAccess() {
70+
return subdomainAccess;
71+
}
72+
73+
}

engine/schema/src/org/apache/cloudstack/affinity/AffinityGroupVO.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,14 @@
2020

2121
import javax.persistence.Column;
2222
import javax.persistence.Entity;
23+
import javax.persistence.EnumType;
24+
import javax.persistence.Enumerated;
2325
import javax.persistence.GeneratedValue;
2426
import javax.persistence.GenerationType;
2527
import javax.persistence.Id;
2628
import javax.persistence.Table;
2729

30+
import org.apache.cloudstack.acl.ControlledEntity;
2831

2932
@Entity
3033
@Table(name = ("affinity_group"))
@@ -52,17 +55,22 @@ public class AffinityGroupVO implements AffinityGroup {
5255
@Column(name = "uuid")
5356
private String uuid;
5457

58+
@Column(name = "acl_type")
59+
@Enumerated(value = EnumType.STRING)
60+
ControlledEntity.ACLType aclType;
61+
5562
public AffinityGroupVO() {
5663
this.uuid = UUID.randomUUID().toString();
5764
}
5865

59-
public AffinityGroupVO(String name, String type, String description, long domainId, long accountId) {
66+
public AffinityGroupVO(String name, String type, String description, long domainId, long accountId, ACLType aclType) {
6067
this.name = name;
6168
this.description = description;
6269
this.domainId = domainId;
6370
this.accountId = accountId;
6471
this.uuid = UUID.randomUUID().toString();
6572
this.type = type;
73+
this.aclType = aclType;
6674
}
6775

6876
@Override
@@ -104,6 +112,11 @@ public String getType() {
104112
return type;
105113
}
106114

115+
@Override
116+
public ControlledEntity.ACLType getAclType() {
117+
return aclType;
118+
}
119+
107120
@Override
108121
public String toString() {
109122
StringBuilder buf = new StringBuilder("AffinityGroup[");
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 org.apache.cloudstack.affinity.dao;
18+
19+
import java.util.List;
20+
21+
import org.apache.cloudstack.affinity.AffinityGroupDomainMapVO;
22+
23+
import com.cloud.utils.db.GenericDao;
24+
25+
public interface AffinityGroupDomainMapDao extends GenericDao<AffinityGroupDomainMapVO, Long> {
26+
27+
AffinityGroupDomainMapVO findByAffinityGroup(long affinityGroupId);
28+
29+
List<AffinityGroupDomainMapVO> listByDomain(Object... domainId);
30+
31+
}

0 commit comments

Comments
 (0)