Skip to content

Commit 6e3ede9

Browse files
author
Daman Arora
committed
add new resource KubernetesClusterAffinityGroupMap
1 parent a13f360 commit 6e3ede9

File tree

4 files changed

+165
-0
lines changed

4 files changed

+165
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.kubernetes.cluster;
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 = "kubernetes_cluster_affinity_group_map")
30+
public class KubernetesClusterAffinityGroupMapVO implements InternalIdentity {
31+
32+
@Id
33+
@GeneratedValue(strategy = GenerationType.IDENTITY)
34+
@Column(name = "id")
35+
private Long id;
36+
37+
@Column(name = "cluster_id")
38+
private long clusterId;
39+
40+
@Column(name = "node_type")
41+
private String nodeType;
42+
43+
@Column(name = "affinity_group_id")
44+
private long affinityGroupId;
45+
46+
public KubernetesClusterAffinityGroupMapVO() {
47+
}
48+
49+
public KubernetesClusterAffinityGroupMapVO(long clusterId, String nodeType, long affinityGroupId) {
50+
this.clusterId = clusterId;
51+
this.nodeType = nodeType;
52+
this.affinityGroupId = affinityGroupId;
53+
}
54+
55+
@Override
56+
public long getId() {
57+
return id;
58+
}
59+
60+
public long getClusterId() {
61+
return clusterId;
62+
}
63+
64+
public void setClusterId(long clusterId) {
65+
this.clusterId = clusterId;
66+
}
67+
68+
public String getNodeType() {
69+
return nodeType;
70+
}
71+
72+
public void setNodeType(String nodeType) {
73+
this.nodeType = nodeType;
74+
}
75+
76+
public long getAffinityGroupId() {
77+
return affinityGroupId;
78+
}
79+
80+
public void setAffinityGroupId(long affinityGroupId) {
81+
this.affinityGroupId = affinityGroupId;
82+
}
83+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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.kubernetes.cluster.dao;
18+
19+
import java.util.List;
20+
21+
import com.cloud.kubernetes.cluster.KubernetesClusterAffinityGroupMapVO;
22+
import com.cloud.utils.db.GenericDao;
23+
24+
public interface KubernetesClusterAffinityGroupMapDao extends GenericDao<KubernetesClusterAffinityGroupMapVO, Long> {
25+
26+
List<KubernetesClusterAffinityGroupMapVO> listByClusterIdAndNodeType(long clusterId, String nodeType);
27+
28+
List<Long> listAffinityGroupIdsByClusterIdAndNodeType(long clusterId, String nodeType);
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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.kubernetes.cluster.dao;
18+
19+
import java.util.List;
20+
import java.util.stream.Collectors;
21+
22+
import com.cloud.kubernetes.cluster.KubernetesClusterAffinityGroupMapVO;
23+
import com.cloud.utils.db.GenericDaoBase;
24+
import com.cloud.utils.db.SearchBuilder;
25+
import com.cloud.utils.db.SearchCriteria;
26+
27+
public class KubernetesClusterAffinityGroupMapDaoImpl extends GenericDaoBase<KubernetesClusterAffinityGroupMapVO, Long>
28+
implements KubernetesClusterAffinityGroupMapDao {
29+
30+
private final SearchBuilder<KubernetesClusterAffinityGroupMapVO> clusterIdAndNodeTypeSearch;
31+
32+
public KubernetesClusterAffinityGroupMapDaoImpl() {
33+
clusterIdAndNodeTypeSearch = createSearchBuilder();
34+
clusterIdAndNodeTypeSearch.and("clusterId", clusterIdAndNodeTypeSearch.entity().getClusterId(), SearchCriteria.Op.EQ);
35+
clusterIdAndNodeTypeSearch.and("nodeType", clusterIdAndNodeTypeSearch.entity().getNodeType(), SearchCriteria.Op.EQ);
36+
clusterIdAndNodeTypeSearch.done();
37+
}
38+
39+
@Override
40+
public List<KubernetesClusterAffinityGroupMapVO> listByClusterIdAndNodeType(long clusterId, String nodeType) {
41+
SearchCriteria<KubernetesClusterAffinityGroupMapVO> sc = clusterIdAndNodeTypeSearch.create();
42+
sc.setParameters("clusterId", clusterId);
43+
sc.setParameters("nodeType", nodeType);
44+
return listBy(sc);
45+
}
46+
47+
@Override
48+
public List<Long> listAffinityGroupIdsByClusterIdAndNodeType(long clusterId, String nodeType) {
49+
List<KubernetesClusterAffinityGroupMapVO> maps = listByClusterIdAndNodeType(clusterId, nodeType);
50+
return maps.stream().map(KubernetesClusterAffinityGroupMapVO::getAffinityGroupId).collect(Collectors.toList());
51+
}
52+
}

plugins/integrations/kubernetes-service/src/main/resources/META-INF/cloudstack/kubernetes-service/spring-kubernetes-service-context.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<bean id="kubernetesClusterDaoImpl" class="com.cloud.kubernetes.cluster.dao.KubernetesClusterDaoImpl" />
3333
<bean id="kubernetesClusterDetailsDaoImpl" class="com.cloud.kubernetes.cluster.dao.KubernetesClusterDetailsDaoImpl" />
3434
<bean id="kubernetesClusterVmMapDaoImpl" class="com.cloud.kubernetes.cluster.dao.KubernetesClusterVmMapDaoImpl" />
35+
<bean id="kubernetesClusterAffinityGroupMapDaoImpl" class="com.cloud.kubernetes.cluster.dao.KubernetesClusterAffinityGroupMapDaoImpl" />
3536
<bean id="kubernetesClusterManagerImpl" class="com.cloud.kubernetes.cluster.KubernetesClusterManagerImpl" />
3637

3738
<bean id="kubernetesServiceHelper" class="com.cloud.kubernetes.cluster.KubernetesServiceHelperImpl" >

0 commit comments

Comments
 (0)