Set<String> serviceNames, AmNodeDef nodeDef) {
ApiHostComponents apiHostComponents = new ApiHostComponents();
List<ApiHostComponent> hostComponents = new ArrayList<>();
apiHostComponents.setHostComponents(hostComponents);
for (String componentName : nodeDef.getComponents()) {
ApiComponentInfo definedCompInfo = componentToInfo.get(componentName);
if (definedCompInfo == null) {
logger.error("Component " + componentName + " is not supported. This should not happen.");
continue;
}
String serviceName = definedCompInfo.getServiceName();
if (!serviceNames.contains(serviceName)) {
logger.info("Service " + serviceName + " is removed from Ambari, igonre component " + componentName);
continue;
}
ApiHostComponent component = new ApiHostComponent();
hostComponents.add(component);
ApiComponentInfo componentInfo = new ApiComponentInfo();
componentInfo.setComponentName(componentName);
component.setHostComponent(componentInfo);
}
return apiHostComponents;
}