|
22 | 22 | import java.util.Date; |
23 | 23 | import java.util.List; |
24 | 24 | import java.util.Map; |
| 25 | +import java.util.concurrent.ExecutionException; |
25 | 26 |
|
26 | 27 | import org.apache.cloudstack.engine.cloud.entity.api.SnapshotEntity; |
27 | 28 | import org.apache.cloudstack.engine.cloud.entity.api.TemplateEntity; |
|
30 | 31 | import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; |
31 | 32 | import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType; |
32 | 33 | import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType; |
| 34 | +import org.apache.cloudstack.framework.async.AsyncCallFuture; |
33 | 35 | import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher; |
34 | 36 | import org.apache.cloudstack.framework.async.AsyncCompletionCallback; |
35 | 37 | import org.apache.cloudstack.storage.datastore.PrimaryDataStoreEntityImpl; |
@@ -170,81 +172,52 @@ public StorageEntity getDataStore() { |
170 | 172 | @Override |
171 | 173 | public boolean createVolumeFromTemplate(long dataStoreId, VolumeDiskType diskType, TemplateEntity template) { |
172 | 174 | TemplateInfo ti = ((TemplateEntityImpl)template).getTemplateInfo(); |
173 | | - |
174 | | - AsyncCallbackDispatcher<VolumeEntityImpl, VolumeInfo> caller = AsyncCallbackDispatcher.create(this); |
175 | | - caller.setCallback(caller.getTarget().createVolumeFromTemplateAsyncCallback(null, null)); |
176 | 175 |
|
177 | | - vs.createVolumeFromTemplateAsync(volumeInfo, dataStoreId, diskType, ti, caller); |
| 176 | + AsyncCallFuture<VolumeApiResult> future = vs.createVolumeFromTemplateAsync(volumeInfo, dataStoreId, diskType, ti); |
178 | 177 | try { |
179 | | - synchronized (volumeInfo) { |
180 | | - volumeInfo.wait(); |
| 178 | + result = future.get(); |
| 179 | + if (!result.isSuccess()) { |
| 180 | + throw new CloudRuntimeException("create volume from template failed: " + result.getResult()); |
181 | 181 | } |
| 182 | + return true; |
182 | 183 | } catch (InterruptedException e) { |
183 | | - throw new CloudRuntimeException("wait volume info failed", e); |
184 | | - } |
185 | | - return true; |
186 | | - } |
187 | | - |
188 | | - |
189 | | - public Object createVolumeFromTemplateAsyncCallback(AsyncCallbackDispatcher<VolumeEntityImpl, VolumeInfo> callback, Object context) { |
190 | | - synchronized (volumeInfo) { |
191 | | - volumeInfo.notify(); |
| 184 | + throw new CloudRuntimeException("wait result failed", e); |
| 185 | + } catch (ExecutionException e) { |
| 186 | + throw new CloudRuntimeException("wait result failed", e); |
192 | 187 | } |
193 | | - return null; |
194 | 188 | } |
195 | 189 |
|
196 | 190 | @Override |
197 | 191 | public boolean createVolume(long dataStoreId, VolumeDiskType diskType) { |
198 | | - AsyncCallbackDispatcher<VolumeEntityImpl, VolumeApiResult> caller = AsyncCallbackDispatcher.create(this); |
199 | | - caller.setCallback(caller.getTarget().createVolumeCallback(null, null)); |
200 | | - vs.createVolumeAsync(volumeInfo, dataStoreId, diskType, caller); |
| 192 | + AsyncCallFuture<VolumeApiResult> future = vs.createVolumeAsync(volumeInfo, dataStoreId, diskType); |
201 | 193 | try { |
202 | | - synchronized (volumeInfo) { |
203 | | - volumeInfo.wait(); |
204 | | - } |
| 194 | + result = future.get(); |
205 | 195 | if (result.isSuccess()) { |
206 | 196 | return true; |
207 | 197 | } else { |
208 | 198 | throw new CloudRuntimeException("Failed to create volume:" + result.getResult()); |
209 | 199 | } |
210 | 200 | } catch (InterruptedException e) { |
211 | | - throw new CloudRuntimeException("wait volume info failed", e); |
212 | | - } |
213 | | - } |
214 | | - |
215 | | - public Void createVolumeCallback(AsyncCallbackDispatcher<VolumeApiResult, VolumeApiResult> callback, Object context) { |
216 | | - synchronized (volumeInfo) { |
217 | | - this.result = callback.getResult(); |
218 | | - volumeInfo.notify(); |
| 201 | + throw new CloudRuntimeException("wait volume info failed", e); |
| 202 | + } catch (ExecutionException e) { |
| 203 | + throw new CloudRuntimeException("wait volume failed", e); |
219 | 204 | } |
220 | | - return null; |
221 | 205 | } |
222 | 206 |
|
223 | | - |
224 | 207 | @Override |
225 | 208 | public void destroy() { |
226 | | - AsyncCallbackDispatcher<VolumeEntityImpl, VolumeApiResult> caller = AsyncCallbackDispatcher.create(this); |
227 | | - caller.setCallback(caller.getTarget().destroyCallback(null, null)); |
228 | | - vs.deleteVolumeAsync(volumeInfo, caller); |
| 209 | + AsyncCallFuture<VolumeApiResult> future = vs.deleteVolumeAsync(volumeInfo); |
229 | 210 | try { |
230 | | - synchronized (volumeInfo) { |
231 | | - volumeInfo.wait(); |
232 | | - } |
| 211 | + result = future.get(); |
233 | 212 | if (!result.isSuccess()) { |
234 | 213 | throw new CloudRuntimeException("Failed to create volume:" + result.getResult()); |
235 | 214 | } |
236 | 215 | } catch (InterruptedException e) { |
237 | | - throw new CloudRuntimeException("wait volume info failed", e); |
| 216 | + throw new CloudRuntimeException("wait to delete volume info failed", e); |
| 217 | + } catch (ExecutionException e) { |
| 218 | + throw new CloudRuntimeException("wait to delete volume failed", e); |
238 | 219 | } |
239 | 220 | } |
240 | | - |
241 | | - public Void destroyCallback(AsyncCallbackDispatcher<VolumeApiResult, VolumeApiResult> callback, Object context) { |
242 | | - synchronized (volumeInfo) { |
243 | | - this.result = callback.getResult(); |
244 | | - volumeInfo.notify(); |
245 | | - } |
246 | | - return null; |
247 | | - } |
248 | 221 |
|
249 | 222 | @Override |
250 | 223 | public Map<String, String> getDetails() { |
|
0 commit comments