mirror of https://github.com/apache/cloudstack.git
Implement getAffinityGroupNodeTypeMap in kubernetes service helper
This commit is contained in:
parent
9f137af735
commit
a7e5270336
|
|
@ -36,5 +36,6 @@ public interface KubernetesServiceHelper extends Adapter {
|
|||
boolean isValidNodeType(String nodeType);
|
||||
Map<String, Long> getServiceOfferingNodeTypeMap(Map<String, Map<String, String>> serviceOfferingNodeTypeMap);
|
||||
Map<String, Long> getTemplateNodeTypeMap(Map<String, Map<String, String>> templateNodeTypeMap);
|
||||
Map<String, Long> getAffinityGroupNodeTypeMap(Map<String, Map<String, String>> affinityGroupNodeTypeMap);
|
||||
void cleanupForAccount(Account account);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -93,6 +93,7 @@ public interface VmDetailConstants {
|
|||
String CKS_NODE_TYPE = "node";
|
||||
String OFFERING = "offering";
|
||||
String TEMPLATE = "template";
|
||||
String AFFINITY_GROUP = "affinitygroup";
|
||||
|
||||
// VMware to KVM VM migrations specific
|
||||
String VMWARE_TO_KVM_PREFIX = "vmware-to-kvm";
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ import java.util.Objects;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.affinity.AffinityGroup;
|
||||
import org.apache.cloudstack.affinity.dao.AffinityGroupDao;
|
||||
import com.cloud.exception.InvalidParameterValueException;
|
||||
import com.cloud.offering.ServiceOffering;
|
||||
import com.cloud.service.dao.ServiceOfferingDao;
|
||||
|
|
@ -66,6 +68,8 @@ public class KubernetesServiceHelperImpl extends AdapterBase implements Kubernet
|
|||
@Inject
|
||||
protected VMTemplateDao vmTemplateDao;
|
||||
@Inject
|
||||
protected AffinityGroupDao affinityGroupDao;
|
||||
@Inject
|
||||
KubernetesClusterService kubernetesClusterService;
|
||||
|
||||
protected void setEventTypeEntityDetails(Class<?> eventTypeDefinedClass, Class<?> entityClass) {
|
||||
|
|
@ -244,6 +248,62 @@ public class KubernetesServiceHelperImpl extends AdapterBase implements Kubernet
|
|||
return mapping;
|
||||
}
|
||||
|
||||
protected void checkNodeTypeAffinityGroupEntryCompleteness(String nodeTypeStr, String affinityGroupUuid) {
|
||||
if (StringUtils.isAnyBlank(nodeTypeStr, affinityGroupUuid)) {
|
||||
String error = String.format("Any Node Type to Affinity Group entry should have a valid '%s' and '%s' values",
|
||||
VmDetailConstants.CKS_NODE_TYPE, VmDetailConstants.AFFINITY_GROUP);
|
||||
logger.error(error);
|
||||
throw new InvalidParameterValueException(error);
|
||||
}
|
||||
}
|
||||
|
||||
protected void checkNodeTypeAffinityGroupEntryValues(String nodeTypeStr, AffinityGroup affinityGroup, String affinityGroupUuid) {
|
||||
if (!isValidNodeType(nodeTypeStr)) {
|
||||
String error = String.format("The provided value '%s' for Node Type is invalid", nodeTypeStr);
|
||||
logger.error(error);
|
||||
throw new InvalidParameterValueException(String.format(error));
|
||||
}
|
||||
if (affinityGroup == null) {
|
||||
String error = String.format("Cannot find an affinity group with ID %s", affinityGroupUuid);
|
||||
logger.error(error);
|
||||
throw new InvalidParameterValueException(error);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addNodeTypeAffinityGroupEntry(String nodeTypeStr, String affinityGroupUuid, AffinityGroup affinityGroup, Map<String, Long> mapping) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(String.format("Node Type: '%s' should use affinity group ID: '%s'", nodeTypeStr, affinityGroupUuid));
|
||||
}
|
||||
KubernetesClusterNodeType nodeType = KubernetesClusterNodeType.valueOf(nodeTypeStr.toUpperCase());
|
||||
mapping.put(nodeType.name(), affinityGroup.getId());
|
||||
}
|
||||
|
||||
protected void processNodeTypeAffinityGroupEntryAndAddToMappingIfValid(Map<String, String> entry, Map<String, Long> mapping) {
|
||||
if (MapUtils.isEmpty(entry)) {
|
||||
return;
|
||||
}
|
||||
String nodeTypeStr = entry.get(VmDetailConstants.CKS_NODE_TYPE);
|
||||
String affinityGroupUuid = entry.get(VmDetailConstants.AFFINITY_GROUP);
|
||||
checkNodeTypeAffinityGroupEntryCompleteness(nodeTypeStr, affinityGroupUuid);
|
||||
|
||||
AffinityGroup affinityGroup = affinityGroupDao.findByUuid(affinityGroupUuid);
|
||||
checkNodeTypeAffinityGroupEntryValues(nodeTypeStr, affinityGroup, affinityGroupUuid);
|
||||
|
||||
addNodeTypeAffinityGroupEntry(nodeTypeStr, affinityGroupUuid, affinityGroup, mapping);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, Long> getAffinityGroupNodeTypeMap(Map<String, Map<String, String>> affinityGroupNodeTypeMap) {
|
||||
Map<String, Long> mapping = new HashMap<>();
|
||||
if (MapUtils.isNotEmpty(affinityGroupNodeTypeMap)) {
|
||||
for (Map<String, String> entry : affinityGroupNodeTypeMap.values()) {
|
||||
processNodeTypeAffinityGroupEntryAndAddToMappingIfValid(entry, mapping);
|
||||
}
|
||||
}
|
||||
return mapping;
|
||||
}
|
||||
|
||||
|
||||
public void cleanupForAccount(Account account) {
|
||||
kubernetesClusterService.cleanupForAccount(account);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ public class CreateKubernetesClusterCmd extends BaseAsyncCreateCmd {
|
|||
@Inject
|
||||
public KubernetesClusterService kubernetesClusterService;
|
||||
@Inject
|
||||
protected KubernetesServiceHelper kubernetesClusterHelper;
|
||||
protected KubernetesServiceHelper kubernetesServiceHelper;
|
||||
@Inject
|
||||
private ConfigurationDao configurationDao;
|
||||
@Inject
|
||||
|
|
@ -320,11 +320,15 @@ public class CreateKubernetesClusterCmd extends BaseAsyncCreateCmd {
|
|||
}
|
||||
|
||||
public Map<String, Long> getServiceOfferingNodeTypeMap() {
|
||||
return kubernetesClusterHelper.getServiceOfferingNodeTypeMap(serviceOfferingNodeTypeMap);
|
||||
return kubernetesServiceHelper.getServiceOfferingNodeTypeMap(serviceOfferingNodeTypeMap);
|
||||
}
|
||||
|
||||
public Map<String, Long> getTemplateNodeTypeMap() {
|
||||
return kubernetesClusterHelper.getTemplateNodeTypeMap(templateNodeTypeMap);
|
||||
return kubernetesServiceHelper.getTemplateNodeTypeMap(templateNodeTypeMap);
|
||||
}
|
||||
|
||||
public Map<String, Long> getAffinityGroupNodeTypeMap() {
|
||||
return kubernetesServiceHelper.getAffinityGroupNodeTypeMap(affinityGroupNodeTypeMap);
|
||||
}
|
||||
|
||||
public Hypervisor.HypervisorType getHypervisorType() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue