Skip to content

Commit 6a9caf7

Browse files
committed
CLOUDSTACK-4430:[Automation][vmware] Failed to deploy vm, if one host is
down in a cluster.
1 parent a2476e9 commit 6a9caf7

2 files changed

Lines changed: 44 additions & 32 deletions

File tree

‎engine/schema/src/com/cloud/storage/VMTemplateStoragePoolVO.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,11 @@ public State getState() {
266266
return this.state;
267267
}
268268

269+
//TODO: this should be revisited post-4.2 to completely use state transition machine
270+
public void setState(ObjectInDataStoreStateMachine.State state) {
271+
this.state = state;
272+
}
273+
269274
public long getUpdatedCount() {
270275
return this.updatedCount;
271276
}

‎engine/storage/volume/src/org/apache/cloudstack/storage/volume/VolumeServiceImpl.java‎

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,68 +25,50 @@
2525

2626
import javax.inject.Inject;
2727

28+
import org.apache.log4j.Logger;
29+
import org.springframework.stereotype.Component;
30+
31+
import com.amazonaws.services.storagegateway.model.ChapInfo;
32+
2833
import org.apache.cloudstack.engine.cloud.entity.api.VolumeEntity;
2934
import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
3035
import org.apache.cloudstack.engine.subsystem.api.storage.CreateCmdResult;
31-
import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionService;
3236
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
3337
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
38+
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
3439
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
35-
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
36-
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine;
3740
import org.apache.cloudstack.engine.subsystem.api.storage.Scope;
38-
import org.apache.cloudstack.engine.subsystem.api.storage.ObjectInDataStoreStateMachine.Event;
39-
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreDriver;
40-
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreDriver;
41-
import org.apache.cloudstack.engine.subsystem.api.storage.SnapshotInfo;
42-
import org.apache.cloudstack.engine.subsystem.api.storage.TemplateInfo;
43-
import org.apache.cloudstack.engine.subsystem.api.storage.ChapInfo;
44-
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeDataFactory;
4541
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
46-
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeService;
4742
import org.apache.cloudstack.framework.async.AsyncCallFuture;
4843
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
4944
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
50-
import org.apache.cloudstack.framework.async.AsyncRpcContext;
5145
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
52-
import org.apache.cloudstack.storage.command.CommandResult;
53-
import org.apache.cloudstack.storage.command.DeleteCommand;
5446
import org.apache.cloudstack.storage.datastore.DataObjectManager;
5547
import org.apache.cloudstack.storage.datastore.ObjectInDataStoreManager;
5648
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
5749
import org.apache.cloudstack.storage.datastore.PrimaryDataStoreProviderManager;
58-
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
59-
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
60-
import org.apache.cloudstack.storage.to.VolumeObjectTO;
61-
62-
import org.apache.log4j.Logger;
63-
import org.springframework.stereotype.Component;
50+
import org.apache.cloudstack.storage.datastore.VolumeDataFactory;
51+
import org.apache.cloudstack.storage.endpoint.EndPointSelector;
52+
import org.apache.cloudstack.storage.image.TemplateInfo;
53+
import org.apache.cloudstack.storage.motion.DataMotionService;
54+
import org.apache.cloudstack.storage.snapshot.SnapshotInfo;
55+
import org.apache.cloudstack.storage.volume.db.VolumeVO;
6456

6557
import com.cloud.agent.api.Answer;
66-
import com.cloud.agent.api.storage.ListVolumeAnswer;
67-
import com.cloud.agent.api.storage.ListVolumeCommand;
6858
import com.cloud.agent.api.to.VirtualMachineTO;
69-
import com.cloud.alert.AlertManager;
7059
import com.cloud.configuration.Config;
7160
import com.cloud.configuration.Resource.ResourceType;
7261
import com.cloud.event.EventTypes;
7362
import com.cloud.event.UsageEventUtils;
7463
import com.cloud.exception.ConcurrentOperationException;
7564
import com.cloud.exception.ResourceAllocationException;
7665
import com.cloud.host.Host;
77-
import com.cloud.storage.DataStoreRole;
78-
import com.cloud.storage.ScopeType;
7966
import com.cloud.storage.StoragePool;
80-
import com.cloud.storage.VMTemplateStoragePoolVO;
8167
import com.cloud.storage.VMTemplateStorageResourceAssoc;
8268
import com.cloud.storage.VMTemplateStorageResourceAssoc.Status;
83-
import com.cloud.storage.Volume.State;
8469
import com.cloud.storage.Volume;
85-
import com.cloud.storage.VolumeVO;
86-
import com.cloud.storage.dao.VMTemplatePoolDao;
87-
import com.cloud.storage.dao.VolumeDao;
70+
import com.cloud.storage.Volume.State;
8871
import com.cloud.storage.snapshot.SnapshotManager;
89-
import com.cloud.storage.template.TemplateProp;
9072
import com.cloud.user.AccountManager;
9173
import com.cloud.user.ResourceLimitService;
9274
import com.cloud.utils.NumbersUtil;
@@ -504,6 +486,7 @@ protected Void createVolumeFromBaseImageCallBack(
504486
AsyncCallbackDispatcher<VolumeServiceImpl, CopyCommandResult> callback,
505487
CreateVolumeFromBaseImageContext<VolumeApiResult> context) {
506488
DataObject vo = context.vo;
489+
DataObject tmplOnPrimary = context.templateOnStore;
507490
CopyCommandResult result = callback.getResult();
508491
VolumeApiResult volResult = new VolumeApiResult((VolumeObject) vo);
509492

@@ -512,8 +495,32 @@ protected Void createVolumeFromBaseImageCallBack(
512495
} else {
513496
vo.processEvent(Event.OperationFailed);
514497
volResult.setResult(result.getResult());
498+
// hack for Vmware: host is down, previously download template to the host needs to be re-downloaded, so we need to reset
499+
// template_spool_ref entry here to NOT_DOWNLOADED and Allocated state
500+
Answer ans = result.getAnswer();
501+
if ( ans != null && ans instanceof CopyCmdAnswer && ans.getDetails().contains("request template reload")){
502+
if (tmplOnPrimary != null){
503+
s_logger.info("Reset template_spool_ref entry so that vmware template can be reloaded in next try");
504+
VMTemplateStoragePoolVO templatePoolRef = _tmpltPoolDao.findByPoolTemplate(tmplOnPrimary.getDataStore().getId(), tmplOnPrimary.getId());
505+
if (templatePoolRef != null) {
506+
long templatePoolRefId = templatePoolRef.getId();
507+
templatePoolRef = _tmpltPoolDao.acquireInLockTable(templatePoolRefId, 1200);
508+
if (templatePoolRef == null) {
509+
s_logger.warn("Reset Template State On Pool failed - unable to lock TemplatePoolRef " + templatePoolRefId);
510+
}
511+
512+
try {
513+
templatePoolRef.setDownloadState(VMTemplateStorageResourceAssoc.Status.NOT_DOWNLOADED);
514+
templatePoolRef.setState(ObjectInDataStoreStateMachine.State.Allocated);
515+
_tmpltPoolDao.update(templatePoolRefId, templatePoolRef);
516+
} finally {
517+
_tmpltPoolDao.releaseFromLockTable(templatePoolRefId);
518+
}
519+
}
520+
}
521+
}
515522
}
516-
523+
517524
AsyncCallFuture<VolumeApiResult> future = context.getFuture();
518525
future.complete(volResult);
519526
return null;

0 commit comments

Comments
 (0)