Skip to content

Updated Endpoint Selector to pick the Cluster in Enabled state (in addition to Host state) #10757

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: 4.20
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public class DefaultEndPointSelector implements EndPointSelector {
private final String findOneHostOnPrimaryStorage = "select t.id from "
+ "(select h.id, cd.value, hd.value as " + VOL_ENCRYPT_COLUMN_NAME + " "
+ "from host h join storage_pool_host_ref s on h.id = s.host_id "
+ "join cluster c on c.id=h.cluster_id "
+ "join cluster c on c.id=h.cluster_id and c.allocation_state = 'Enabled'"
+ "left join cluster_details cd on c.id=cd.cluster_id and cd.name='" + CapacityManager.StorageOperationsExcludeCluster.key() + "' "
+ "left join host_details hd on h.id=hd.host_id and hd.name='" + HOST_VOLUME_ENCRYPTION + "' "
+ "where h.status = 'Up' and h.type = 'Routing' and h.resource_state = 'Enabled' and s.pool_id = ? ";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,11 @@
} else {
vo.processEvent(Event.OperationFailed);
errMsg = result.getResult();
VolumeVO volume = volDao.findById(vo.getId());

Check warning on line 331 in engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java#L331

Added line #L331 was not covered by tests
if (volume != null && volume.getState() == State.Allocated && volume.getPodId() != null) {
volume.setPoolId(null);
volDao.update(volume.getId(), volume);

Check warning on line 334 in engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java#L333-L334

Added lines #L333 - L334 were not covered by tests
}
}
VolumeApiResult volResult = new VolumeApiResult((VolumeObject)vo);
if (errMsg != null) {
Expand Down Expand Up @@ -1237,6 +1242,10 @@
}

if (volume.getState() == State.Allocated) { // Possible states here: Allocated, Ready & Creating
if (volume.getPodId() != null) {
volume.setPoolId(null);
volDao.update(volume.getId(), volume);

Check warning on line 1247 in engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java#L1246-L1247

Added lines #L1246 - L1247 were not covered by tests
}
return;
}

Expand Down Expand Up @@ -2476,7 +2485,7 @@
try {
volume.processEvent(Event.ResizeRequested);
} catch (Exception e) {
logger.debug("Failed to change state to resize", e);
logger.debug("Failed to change volume state to resize", e);

Check warning on line 2488 in engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java#L2488

Added line #L2488 was not covered by tests
result.setResult(e.toString());
future.complete(result);
return future;
Expand All @@ -2488,10 +2497,8 @@
try {
volume.getDataStore().getDriver().resize(volume, caller);
} catch (Exception e) {
logger.debug("Failed to change state to resize", e);

logger.debug("Failed to resize volume", e);

Check warning on line 2500 in engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java#L2500

Added line #L2500 was not covered by tests
result.setResult(e.toString());

future.complete(result);
}

Expand Down Expand Up @@ -2535,7 +2542,7 @@
try {
volume.processEvent(Event.OperationFailed);
} catch (Exception e) {
logger.debug("Failed to change state", e);
logger.debug("Failed to change volume state (after resize failure)", e);

Check warning on line 2545 in engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java#L2545

Added line #L2545 was not covered by tests
}
VolumeApiResult res = new VolumeApiResult(volume);
res.setResult(result.getResult());
Expand All @@ -2546,13 +2553,8 @@
try {
volume.processEvent(Event.OperationSuccessed);
} catch (Exception e) {
logger.debug("Failed to change state", e);
VolumeApiResult res = new VolumeApiResult(volume);
res.setResult(result.getResult());
future.complete(res);
return null;
logger.debug("Failed to change volume state (after resize success)", e);

Check warning on line 2556 in engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java

View check run for this annotation

Codecov / codecov/patch

engine/storage/volume/src/main/java/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java#L2556

Added line #L2556 was not covered by tests
}

VolumeApiResult res = new VolumeApiResult(volume);
future.complete(res);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,17 +432,25 @@
boolean encryptionRequired = anyVolumeRequiresEncryption(vol);
long [] endpointsToRunResize = resizeParameter.hosts;

CreateCmdResult result = new CreateCmdResult(null, null);

Check warning on line 435 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java#L435

Added line #L435 was not covered by tests

// if hosts are provided, they are where the VM last ran. We can use that.
if (endpointsToRunResize == null || endpointsToRunResize.length == 0) {
EndPoint ep = epSelector.select(data, encryptionRequired);
if (ep == null) {
String errMsg = String.format(NO_REMOTE_ENDPOINT_WITH_ENCRYPTION, encryptionRequired);
logger.error(errMsg);
result.setResult(errMsg);
callback.complete(result);
return;

Check warning on line 445 in plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java

View check run for this annotation

Codecov / codecov/patch

plugins/storage/volume/default/src/main/java/org/apache/cloudstack/storage/datastore/driver/CloudStackPrimaryDataStoreDriverImpl.java#L441-L445

Added lines #L441 - L445 were not covered by tests
}
endpointsToRunResize = new long[] {ep.getId()};
}
ResizeVolumeCommand resizeCmd = new ResizeVolumeCommand(vol.getPath(), new StorageFilerTO(pool), vol.getSize(),
resizeParameter.newSize, resizeParameter.shrinkOk, resizeParameter.instanceName, vol.getChainInfo(), vol.getPassphrase(), vol.getEncryptFormat());
if (pool.getParent() != 0) {
resizeCmd.setContextParam(DiskTO.PROTOCOL_TYPE, Storage.StoragePoolType.DatastoreCluster.toString());
}
CreateCmdResult result = new CreateCmdResult(null, null);
try {
ResizeVolumeAnswer answer = (ResizeVolumeAnswer) storageMgr.sendToPool(pool, endpointsToRunResize, resizeCmd);
if (answer != null && answer.getResult()) {
Expand All @@ -459,7 +467,6 @@
logger.debug("return a null answer, mark it as failed for unknown reason");
result.setResult("return a null answer, mark it as failed for unknown reason");
}

} catch (Exception e) {
logger.debug("sending resize command failed", e);
result.setResult(e.toString());
Expand Down
Loading