Skip to content

Commit 1f1c96d

Browse files
committed
volume upload: management server polling and upload status from agent
- Added config parameters for upload monitoring interval and operation timeout - Some updates to the volume state machine
1 parent 0eee9e8 commit 1f1c96d

3 files changed

Lines changed: 43 additions & 19 deletions

File tree

‎api/src/com/cloud/storage/Volume.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public String getDescription() {
106106
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(Expunged, Event.OperationFailed, Expunged, null));
107107
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(NotUploaded, Event.OperationTimeout, UploadAbandoned, null));
108108
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(NotUploaded, Event.UploadRequested, UploadInProgress, null));
109+
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(NotUploaded, Event.OperationSucceeded, Uploaded, null));
110+
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(NotUploaded, Event.OperationFailed, UploadError, null));
109111
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(UploadInProgress, Event.OperationSucceeded, Uploaded, null));
110112
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(UploadInProgress, Event.OperationFailed, UploadError, null));
111113
s_fsm.addTransition(new StateMachine2.Transition<State, Event>(UploadInProgress, Event.OperationTimeout, UploadError, null));

‎core/src/org/apache/cloudstack/storage/command/UploadStatusCommand.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,29 @@
2222
import com.cloud.agent.api.Command;
2323

2424
public class UploadStatusCommand extends Command {
25-
25+
public enum EntityType {
26+
Volume,
27+
Template
28+
}
2629
private long entityId;
30+
private EntityType entityType;
2731

2832
protected UploadStatusCommand() {
2933
}
3034

31-
public UploadStatusCommand(long entityId) {
35+
public UploadStatusCommand(long entityId, EntityType entityType) {
3236
this.entityId = entityId;
37+
this.entityType = entityType;
3338
}
3439

3540
public long getEntityId() {
3641
return entityId;
3742
}
3843

44+
public EntityType getEntityType() {
45+
return entityType;
46+
}
47+
3948
@Override
4049
public boolean executeInSequence() {
4150
return false;

‎server/src/com/cloud/storage/ImageStoreUploadMonitorImpl.java‎

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
3333
import org.apache.cloudstack.engine.subsystem.api.storage.EndPoint;
3434
import org.apache.cloudstack.engine.subsystem.api.storage.EndPointSelector;
35-
import org.apache.cloudstack.framework.config.dao.ConfigurationDao;
35+
import org.apache.cloudstack.framework.config.ConfigKey;
36+
import org.apache.cloudstack.framework.config.Configurable;
3637
import org.apache.cloudstack.managed.context.ManagedContextRunnable;
3738
import org.apache.cloudstack.storage.command.UploadStatusAnswer;
3839
import org.apache.cloudstack.storage.command.UploadStatusCommand;
40+
import org.apache.cloudstack.storage.command.UploadStatusCommand.EntityType;
3941
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreDao;
4042
import org.apache.cloudstack.storage.datastore.db.VolumeDataStoreVO;
4143
import org.apache.cloudstack.utils.identity.ManagementServerNode;
@@ -65,12 +67,10 @@
6567
*/
6668
@Component
6769
@Local(value = {ImageStoreUploadMonitor.class})
68-
public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageStoreUploadMonitor, Listener {
70+
public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageStoreUploadMonitor, Listener, Configurable {
6971

7072
static final Logger s_logger = Logger.getLogger(ImageStoreUploadMonitorImpl.class);
7173

72-
@Inject
73-
private ConfigurationDao _configDao;
7474
@Inject
7575
private VolumeDao _volumeDao;
7676
@Inject
@@ -87,12 +87,16 @@ public class ImageStoreUploadMonitorImpl extends ManagerBase implements ImageSto
8787
private int _monitoringInterval;
8888
private long _uploadOperationTimeout;
8989

90+
static final ConfigKey<Integer> UploadMonitoringInterval = new ConfigKey<Integer>("Advanced", Integer.class, "upload.monitoring.interval", "60",
91+
"Interval (in seconds) to check the status of volumes that are uploaded using HTTP POST request", true);
92+
static final ConfigKey<Integer> UploadOperationTimeout = new ConfigKey<Integer>("Advanced", Integer.class, "upload.operation.timeout", "10",
93+
"Time (in minutes) to wait before abandoning volume upload using HTTP POST request", true);
94+
9095
@Override
9196
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
9297
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("Upload-Monitor"));
93-
//TODO: use config variable
94-
_monitoringInterval = 60;
95-
_uploadOperationTimeout = 10 * 60 * 1000; // 10 minutes
98+
_monitoringInterval = UploadMonitoringInterval.value();
99+
_uploadOperationTimeout = UploadOperationTimeout.value() * 60 * 1000;
96100
_nodeId = ManagementServerNode.getManagementServerId();
97101
return true;
98102
}
@@ -176,18 +180,18 @@ protected void runInContext() {
176180
}
177181
Host host = _hostDao.findById(ep.getId());
178182
if (host != null && host.getManagementServerId() != null && _nodeId == host.getManagementServerId().longValue()) {
179-
UploadStatusCommand cmd = new UploadStatusCommand(volume.getId());
183+
UploadStatusCommand cmd = new UploadStatusCommand(volume.getId(), EntityType.Volume);
180184
Answer answer = ep.sendMessage(cmd);
181185
if (answer == null || !(answer instanceof UploadStatusAnswer)) {
182186
s_logger.warn("No or invalid answer corresponding to UploadStatusCommand for volume " + volumeDataStore.getVolumeId());
183187
continue;
184188
}
185-
handleStatusResponse((UploadStatusAnswer)answer, volume, volumeDataStore);
189+
handleVolumeStatusResponse((UploadStatusAnswer)answer, volume, volumeDataStore);
186190
}
187191
}
188192
}
189193

190-
private void handleStatusResponse(final UploadStatusAnswer answer, final VolumeVO volume, final VolumeDataStoreVO volumeDataStore) {
194+
private void handleVolumeStatusResponse(final UploadStatusAnswer answer, final VolumeVO volume, final VolumeDataStoreVO volumeDataStore) {
191195
final StateMachine2<Volume.State, Event, Volume> stateMachine = Volume.State.getStateMachine();
192196
Transaction.execute(new TransactionCallbackNoReturn() {
193197
@Override
@@ -204,13 +208,13 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
204208
}
205209
break;
206210
case IN_PROGRESS:
207-
tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.UPLOAD_IN_PROGRESS);
208-
// check for timeout
209-
if (tmpVolumeDataStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.NOT_UPLOADED ||
210-
tmpVolumeDataStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.UPLOAD_IN_PROGRESS) {
211+
if (tmpVolume.getState() == Volume.State.NotUploaded) {
212+
tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.UPLOAD_IN_PROGRESS);
213+
stateMachine.transitTo(tmpVolume, Event.UploadRequested, null, _volumeDao);
214+
} else if (tmpVolume.getState() == Volume.State.UploadInProgress) { // check for timeout
211215
if (System.currentTimeMillis() - tmpVolumeDataStore.getCreated().getTime() > _uploadOperationTimeout) {
212-
tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.DOWNLOAD_ERROR);
213-
stateMachine.transitTo(tmpVolume, Event.OperationTimeout, null, _volumeDao);
216+
tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.UPLOAD_ERROR);
217+
stateMachine.transitTo(tmpVolume, Event.OperationFailed, null, _volumeDao);
214218
if (s_logger.isDebugEnabled()) {
215219
s_logger.debug("Volume " + tmpVolume.getUuid() + " failed to upload due to operation timed out");
216220
}
@@ -226,7 +230,7 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
226230
break;
227231
case UNKNOWN:
228232
// check for timeout
229-
if (tmpVolumeDataStore.getDownloadState() == VMTemplateStorageResourceAssoc.Status.NOT_UPLOADED) {
233+
if (tmpVolume.getState() == Volume.State.NotUploaded) {
230234
if (System.currentTimeMillis() - tmpVolumeDataStore.getCreated().getTime() > _uploadOperationTimeout) {
231235
tmpVolumeDataStore.setDownloadState(VMTemplateStorageResourceAssoc.Status.ABANDONED);
232236
stateMachine.transitTo(tmpVolume, Event.OperationTimeout, null, _volumeDao);
@@ -246,5 +250,14 @@ public void doInTransactionWithoutResult(TransactionStatus status) {
246250
}
247251
}
248252

253+
@Override
254+
public String getConfigComponentName() {
255+
return ImageStoreUploadMonitor.class.getSimpleName();
256+
}
257+
258+
@Override
259+
public ConfigKey<?>[] getConfigKeys() {
260+
return new ConfigKey<?>[] {UploadMonitoringInterval, UploadOperationTimeout};
261+
}
249262

250263
}

0 commit comments

Comments
 (0)