Skip to content

Commit ed2125e

Browse files
committed
CLOUDSTACK-669: convert volume attach/detach flows to make them be serialized with other VM operations
1 parent d0abf3f commit ed2125e

10 files changed

Lines changed: 636 additions & 356 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.vm;
18+
19+
public interface VmWorkConstants {
20+
public static final String VM_WORK_QUEUE = "VmWorkJobQueue";
21+
public static final String VM_WORK_JOB_DISPATCHER = "VmWorkJobDispatcher";
22+
public static final String VM_WORK_JOB_WAKEUP_DISPATCHER = "VmWorkJobWakeupDispatcher";
23+
}

engine/orchestration/src/com/cloud/vm/VmWorkJobHandler.java renamed to engine/components-api/src/com/cloud/vm/VmWorkJobHandler.java

File renamed without changes.

engine/orchestration/src/com/cloud/vm/VmWorkSerializer.java renamed to engine/components-api/src/com/cloud/vm/VmWorkSerializer.java

File renamed without changes.

‎engine/orchestration/resources/META-INF/cloudstack/core/spring-engine-orchestration-core-context.xml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,18 @@
7575

7676
<bean id= "vmWorkJobDispatcher" class="com.cloud.vm.VmWorkJobDispatcher">
7777
<property name="name">
78-
<util:constant static-field="com.cloud.vm.VmWorkJobDispatcher.VM_WORK_JOB_DISPATCHER"/>
78+
<util:constant static-field="com.cloud.vm.VmWorkConstants.VM_WORK_JOB_DISPATCHER"/>
7979
</property>
8080
<property name="handlers">
8181
<map>
8282
<entry key="VirtualMachineManagerImpl" value-ref="clusteredVirtualMachineManagerImpl" />
83+
<entry key="VolumeApiServiceImpl" value-ref="volumeApiServiceImpl" />
8384
</map>
8485
</property>
8586
</bean>
8687
<bean id= "vmWorkJobWakeupDispatcher" class="com.cloud.vm.VmWorkJobWakeupDispatcher">
8788
<property name="name">
88-
<util:constant static-field="com.cloud.vm.VmWorkJobDispatcher.VM_WORK_JOB_WAKEUP_DISPATCHER"/>
89+
<util:constant static-field="com.cloud.vm.VmWorkConstants.VM_WORK_JOB_WAKEUP_DISPATCHER"/>
8990
</property>
9091
</bean>
9192

‎engine/orchestration/src/com/cloud/vm/VirtualMachineManagerImpl.java‎

Lines changed: 265 additions & 263 deletions
Large diffs are not rendered by default.

‎engine/orchestration/src/com/cloud/vm/VmWorkJobDispatcher.java‎

Lines changed: 0 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,6 @@
3636
public class VmWorkJobDispatcher extends AdapterBase implements AsyncJobDispatcher {
3737
private static final Logger s_logger = Logger.getLogger(VmWorkJobDispatcher.class);
3838

39-
public static final String VM_WORK_QUEUE = "VmWorkJobQueue";
40-
public static final String VM_WORK_JOB_DISPATCHER = "VmWorkJobDispatcher";
41-
public static final String VM_WORK_JOB_WAKEUP_DISPATCHER = "VmWorkJobWakeupDispatcher";
42-
4339
@Inject private VirtualMachineManagerImpl _vmMgr;
4440
@Inject private AsyncJobManager _asyncJobMgr;
4541
@Inject private VMInstanceDao _instanceDao;
@@ -103,79 +99,6 @@ public void runJob(AsyncJob job) {
10399
Pair<JobInfo.Status, String> result = handler.handleVmWorkJob(job, work);
104100
_asyncJobMgr.completeAsyncJob(job.getId(), result.first(), 0, result.second());
105101

106-
/*
107-
VMInstanceVO vm = _instanceDao.findById(work.getVmId());
108-
if (vm == null) {
109-
s_logger.info("Unable to find vm " + work.getVmId());
110-
}
111-
assert(vm != null);
112-
if(work instanceof VmWorkStart) {
113-
VmWorkStart workStart = (VmWorkStart)work;
114-
_vmMgr.orchestrateStart(vm.getUuid(), workStart.getParams(), workStart.getPlan());
115-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
116-
} else if(work instanceof VmWorkStop) {
117-
VmWorkStop workStop = (VmWorkStop)work;
118-
_vmMgr.orchestrateStop(vm.getUuid(), workStop.isCleanup());
119-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
120-
} else if(work instanceof VmWorkMigrate) {
121-
VmWorkMigrate workMigrate = (VmWorkMigrate)work;
122-
_vmMgr.orchestrateMigrate(vm.getUuid(), workMigrate.getSrcHostId(), workMigrate.getDeployDestination());
123-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
124-
} else if(work instanceof VmWorkMigrateWithStorage) {
125-
VmWorkMigrateWithStorage workMigrateWithStorage = (VmWorkMigrateWithStorage)work;
126-
_vmMgr.orchestrateMigrateWithStorage(vm.getUuid(),
127-
workMigrateWithStorage.getSrcHostId(),
128-
workMigrateWithStorage.getDestHostId(),
129-
workMigrateWithStorage.getVolumeToPool());
130-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
131-
} else if(work instanceof VmWorkMigrateForScale) {
132-
VmWorkMigrateForScale workMigrateForScale = (VmWorkMigrateForScale)work;
133-
_vmMgr.orchestrateMigrateForScale(vm.getUuid(),
134-
workMigrateForScale.getSrcHostId(),
135-
workMigrateForScale.getDeployDestination(),
136-
workMigrateForScale.getNewServiceOfferringId());
137-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
138-
} else if(work instanceof VmWorkReboot) {
139-
VmWorkReboot workReboot = (VmWorkReboot)work;
140-
_vmMgr.orchestrateReboot(vm.getUuid(), workReboot.getParams());
141-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
142-
} else if(work instanceof VmWorkAddVmToNetwork) {
143-
VmWorkAddVmToNetwork workAddVmToNetwork = (VmWorkAddVmToNetwork)work;
144-
NicProfile nic = _vmMgr.orchestrateAddVmToNetwork(vm, workAddVmToNetwork.getNetwork(),
145-
workAddVmToNetwork.getRequestedNicProfile());
146-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0,
147-
JobSerializerHelper.toObjectSerializedString(nic));
148-
} else if(work instanceof VmWorkRemoveNicFromVm) {
149-
VmWorkRemoveNicFromVm workRemoveNicFromVm = (VmWorkRemoveNicFromVm)work;
150-
boolean result = _vmMgr.orchestrateRemoveNicFromVm(vm, workRemoveNicFromVm.getNic());
151-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0,
152-
JobSerializerHelper.toObjectSerializedString(new Boolean(result)));
153-
} else if(work instanceof VmWorkRemoveVmFromNetwork) {
154-
VmWorkRemoveVmFromNetwork workRemoveVmFromNetwork = (VmWorkRemoveVmFromNetwork)work;
155-
boolean result = _vmMgr.orchestrateRemoveVmFromNetwork(vm,
156-
workRemoveVmFromNetwork.getNetwork(), workRemoveVmFromNetwork.getBroadcastUri());
157-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0,
158-
JobSerializerHelper.toObjectSerializedString(new Boolean(result)));
159-
} else if(work instanceof VmWorkReconfigure) {
160-
VmWorkReconfigure workReconfigure = (VmWorkReconfigure)work;
161-
_vmMgr.reConfigureVm(vm.getUuid(), workReconfigure.getNewServiceOffering(),
162-
workReconfigure.isSameHost());
163-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
164-
} else if(work instanceof VmWorkStorageMigration) {
165-
VmWorkStorageMigration workStorageMigration = (VmWorkStorageMigration)work;
166-
_vmMgr.orchestrateStorageMigration(vm.getUuid(), workStorageMigration.getDestStoragePool());
167-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.SUCCEEDED, 0, null);
168-
} else {
169-
assert(false);
170-
s_logger.error("Unhandled VM work command: " + job.getCmd());
171-
172-
RuntimeException e = new RuntimeException("Unsupported VM work command: " + job.getCmd());
173-
String exceptionJson = JobSerializerHelper.toSerializedString(e);
174-
s_logger.error("Serialize exception object into json: " + exceptionJson);
175-
_asyncJobMgr.completeAsyncJob(job.getId(), JobInfo.Status.FAILED, 0, exceptionJson);
176-
}
177-
*/
178-
179102
} catch(Throwable e) {
180103
s_logger.error("Unable to complete " + job, e);
181104

‎framework/jobs/src/org/apache/cloudstack/framework/jobs/impl/OutcomeImpl.java‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,11 @@ public boolean isDone() {
109109
@Override
110110
public void execute(Task<T> task) {
111111
// TODO Auto-generated method stub
112-
113112
}
114113

115114
@Override
116115
public void execute(Task<T> task, long wait, TimeUnit unit) {
117116
// TODO Auto-generated method stub
118-
119117
}
120118

121119
public Predicate getPredicate() {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.storage;
18+
19+
import com.cloud.vm.VmWork;
20+
21+
public class VmWorkAttachVolume extends VmWork {
22+
private static final long serialVersionUID = 553291814854451740L;
23+
24+
private Long volumeId;
25+
private Long deviceId;
26+
27+
public VmWorkAttachVolume(long userId, long accountId, long vmId, String handlerName, Long volumeId, Long deviceId) {
28+
super(userId, accountId, vmId, handlerName);
29+
this.volumeId = volumeId;
30+
this.deviceId = deviceId;
31+
}
32+
33+
public Long getVolumeId() {
34+
return volumeId;
35+
}
36+
37+
public Long getDeviceId() {
38+
return deviceId;
39+
}
40+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.storage;
18+
19+
import com.cloud.vm.VmWork;
20+
21+
public class VmWorkDetachVolume extends VmWork {
22+
private static final long serialVersionUID = -8722243207385263101L;
23+
24+
private Long volumeId;
25+
26+
public VmWorkDetachVolume(long userId, long accountId, long vmId, String handlerName, Long volumeId) {
27+
super(userId, accountId, vmId, handlerName);
28+
this.volumeId = volumeId;
29+
}
30+
31+
public Long getVolumeId() {
32+
return volumeId;
33+
}
34+
}

0 commit comments

Comments
 (0)