.getName());
NodeGroupCreate ngSpec =
clusterSpec.getNodeGroup(node.getNodeGroup().getName());
// use current DS if it has enough space
VcDatastore currentDs =
VcResourceUtils.findDSInVcByName(swapDisk.getDatastoreName());
if (!currentDs.isAccessible()) {
throw ScaleServiceException.CURRENT_DATASTORE_UNACCESSIBLE(currentDs
.getName());
}
if ((int) (currentDs.getFreeSpace() >> 20) > newSwapSizeInMB
- swapDisk.getSizeInMB()) {
return currentDs;
}
// else find a valid datastore with largest free space
VcHost locateHost = VcResourceUtils.findHost(node.getHostName());
// swap disk should use image store pattern
String[] dsNamePatterns =
NodeGroupCreate.getImagestoreNamePattern(clusterSpec, ngSpec);
VcDatastore targetDs = null;
for (VcDatastore ds : locateHost.getDatastores()) {
if (!ds.isAccessible()) {
continue;
}
for (String pattern : dsNamePatterns) {
if (ds.getName().matches(pattern)) {
if (targetDs == null
|| targetDs.getFreeSpace() < ds.getFreeSpace()) {
targetDs = ds;
}
break;
}
}
}
if (targetDs != null
&& (int) (targetDs.getFreeSpace() >> 20) > newSwapSizeInMB) {
return targetDs;
}
logger.warn("cannot find a proper datastore to scale up swap disk of vm: "
+ node.getVmName());