Skip to content

Commit b965032

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.
1 parent 359967d commit b965032

21 files changed

Lines changed: 625 additions & 44 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
@@ -59,4 +59,23 @@ void process(VirtualMachineProfile<? extends VirtualMachine> vm, DeploymentPlan
5959
*/
6060
boolean check(VirtualMachineProfile<? extends VirtualMachine> vm, DeployDestination plannedDestination)
6161
throws AffinityConflictException;
62+
63+
/**
64+
* isAdminControlledGroup() should return true if the affinity/anti-affinity
65+
* group can only be operated on[create/delete/modify] by the Admin
66+
*
67+
* @return boolean true/false
68+
*/
69+
boolean isAdminControlledGroup();
70+
71+
72+
/**
73+
* canBeSharedDomainWide() should return true if the affinity/anti-affinity
74+
* group can be created for a domain and shared by all accounts under the
75+
* domain.
76+
*
77+
* @return boolean true/false
78+
*/
79+
boolean canBeSharedDomainWide();
80+
6281
}

‎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
@@ -48,4 +48,14 @@ public boolean check(VirtualMachineProfile<? extends VirtualMachine> vm, DeployD
4848
throws AffinityConflictException {
4949
return true;
5050
}
51+
52+
@Override
53+
public boolean isAdminControlledGroup() {
54+
return false;
55+
}
56+
57+
@Override
58+
public boolean canBeSharedDomainWide() {
59+
return false;
60+
}
5161
}

‎client/tomcatconf/applicationContext.xml.in‎

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

383384
<!--
384385
Authenticators
@@ -917,6 +918,8 @@
917918
</bean>
918919
<bean id="AffinityGroupVMMapDaoImpl" class="org.apache.cloudstack.affinity.dao.AffinityGroupVMMapDaoImpl">
919920
</bean>
921+
<bean id="AffinityGroupDomainMapDaoImpl" class="org.apache.cloudstack.affinity.dao.AffinityGroupDomainMapDaoImpl">
922+
</bean>
920923

921924
<bean id="PlannerHostReservationDaoImpl" class="com.cloud.deploy.dao.PlannerHostReservationDaoImpl">
922925
</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)