private Set<InstanceMetaData> prepareInstanceMetaData(Stack stack, Set<CoreInstanceMetaData> coreInstanceMetaData, int startIndex) {
Set<InstanceMetaData> instanceMetaData = new HashSet<>();
int instanceIndex = startIndex;
String ambariIp = null;
for (CoreInstanceMetaData coreInstanceMetaDataEntry : coreInstanceMetaData) {
InstanceMetaData instanceMetaDataEntry = new InstanceMetaData();
instanceMetaDataEntry.setPrivateIp(coreInstanceMetaDataEntry.getPrivateIp());
instanceMetaDataEntry.setPublicIp(coreInstanceMetaDataEntry.getPublicDns());
instanceMetaDataEntry.setInstanceId(coreInstanceMetaDataEntry.getInstanceId());
instanceMetaDataEntry.setVolumeCount(coreInstanceMetaDataEntry.getVolumeCount());
instanceMetaDataEntry.setLongName(coreInstanceMetaDataEntry.getLongName());
instanceMetaDataEntry.setInstanceIndex(instanceIndex);
instanceMetaDataEntry.setDockerSubnet(String.format("172.18.%s.1", coreInstanceMetaDataEntry.getPrivateIp().split("\\.")[LAST]));
instanceMetaDataEntry.setContainerCount(coreInstanceMetaDataEntry.getContainerCount());
if (instanceIndex == 0) {
instanceMetaDataEntry.setAmbariServer(Boolean.TRUE);
instanceMetaDataEntry.setRemovable(false);
ambariIp = instanceMetaDataEntry.getPublicIp();
if (ambariIp == null) {
throw new WrongMetadataException(String.format("Public IP of Ambari server cannot be null [stack: '%s', instanceId: '%s' ]",
stack.getId(), coreInstanceMetaDataEntry.getInstanceId()));
}
} else {
instanceMetaDataEntry.setAmbariServer(Boolean.FALSE);
instanceMetaDataEntry.setRemovable(true);
}
instanceIndex++;
instanceMetaDataEntry.setStack(stack);
instanceMetaData.add(instanceMetaDataEntry);
}
return instanceMetaData;
}