fix build, due to refactor rpc

This commit is contained in:
Edison Su 2012-12-19 12:01:57 -08:00
parent ea713c70a2
commit 8214f18897
9 changed files with 151 additions and 90 deletions

View File

@ -19,8 +19,8 @@
package org.apache.cloudstack.storage.image.motion; package org.apache.cloudstack.storage.image.motion;
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher; import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
import org.apache.cloudstack.framework.async.AsyncCallbackHandler;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.framework.async.AsyncRpcConext;
import org.apache.cloudstack.storage.EndPoint; import org.apache.cloudstack.storage.EndPoint;
import org.apache.cloudstack.storage.command.CommandResult; import org.apache.cloudstack.storage.command.CommandResult;
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd; import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd;
@ -52,20 +52,34 @@ public class DefaultImageMotionStrategy implements ImageMotionStrategy {
ep.sendMessage(copyCommand); ep.sendMessage(copyCommand);
return true; return true;
} }
private class CreateTemplateContext<T> extends AsyncRpcConext<T> {
private final TemplateOnPrimaryDataStoreInfo template;
public CreateTemplateContext(AsyncCompletionCallback<T> callback, TemplateOnPrimaryDataStoreInfo template) {
super(callback);
this.template = template;
}
public TemplateOnPrimaryDataStoreInfo getTemplate() {
return this.template;
}
}
@Override @Override
public void copyTemplateAsync(TemplateOnPrimaryDataStoreInfo templateStore, EndPoint ep, AsyncCompletionCallback<CommandResult> callback) { public void copyTemplateAsync(TemplateOnPrimaryDataStoreInfo templateStore, EndPoint ep, AsyncCompletionCallback<CommandResult> callback) {
ImageOnPrimayDataStoreTO imageTo = new ImageOnPrimayDataStoreTO(templateStore); ImageOnPrimayDataStoreTO imageTo = new ImageOnPrimayDataStoreTO(templateStore);
CopyTemplateToPrimaryStorageCmd copyCommand = new CopyTemplateToPrimaryStorageCmd(imageTo); CopyTemplateToPrimaryStorageCmd copyCommand = new CopyTemplateToPrimaryStorageCmd(imageTo);
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this).setParentCallback(callback) CreateTemplateContext<CommandResult> context = new CreateTemplateContext<CommandResult>(callback, templateStore);
.setOperationName("defaultImageStrategy.copytemplate.callback") AsyncCallbackDispatcher<DefaultImageMotionStrategy> caller = AsyncCallbackDispatcher.create(this);
.setContextParam("templateStore", templateStore); caller.setCallback(caller.getTarget().copyTemplateCallBack(null, null))
.setContext(context);
ep.sendMessageAsync(copyCommand, caller); ep.sendMessageAsync(copyCommand, caller);
} }
@AsyncCallbackHandler(operationName="defaultImageStrategy.copytemplate.callback") public Object copyTemplateCallBack(AsyncCallbackDispatcher<DefaultImageMotionStrategy> callback, CreateTemplateContext<CommandResult> context) {
public void copyTemplateCallBack(AsyncCallbackDispatcher callback) { AsyncCompletionCallback<CommandResult> parentCall = context.getParentCallback();
AsyncCallbackDispatcher parentCall = callback.getParentCallback();
CopyTemplateToPrimaryStorageAnswer answer = callback.getResult(); CopyTemplateToPrimaryStorageAnswer answer = callback.getResult();
CommandResult result = new CommandResult(); CommandResult result = new CommandResult();
@ -73,12 +87,13 @@ public class DefaultImageMotionStrategy implements ImageMotionStrategy {
result.setSucess(answer.getResult()); result.setSucess(answer.getResult());
result.setResult(answer.getDetails()); result.setResult(answer.getDetails());
} else { } else {
TemplateOnPrimaryDataStoreInfo templateStore = callback.getContextParam("templateStore"); TemplateOnPrimaryDataStoreInfo templateStore = context.getTemplate();
templateStore.setPath(answer.getPath()); templateStore.setPath(answer.getPath());
result.setSucess(true); result.setSucess(true);
} }
parentCall.complete(result); parentCall.complete(result);
return null;
} }
} }

View File

@ -20,8 +20,6 @@ package org.apache.cloudstack.storage;
import javax.inject.Inject; import javax.inject.Inject;
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
import org.apache.cloudstack.framework.async.AsyncCallbackHandler;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
@ -62,15 +60,6 @@ public class HypervisorHostEndPoint implements EndPoint {
@Override @Override
public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback) { public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback) {
AsyncCallbackDispatcher dispatcher = new AsyncCallbackDispatcher(this).setContextParam("parentCallback", callback). rpcServer.sendCommandAsync(this.hostAddress, cmd, callback);
setOperationName("hypervisorEndpoint.sendMessage.callback");
rpcServer.sendCommandAsync(this.hostAddress, cmd, dispatcher);
}
@AsyncCallbackHandler(operationName="hypervisorEndpoint.sendMessage.callback")
public void sendMessageCallback(AsyncCallbackDispatcher callback) {
AsyncCallbackDispatcher parentDispatcher = callback.getContextParam("parentCallback");
parentDispatcher.complete(callback.getResult());
} }
} }

View File

@ -31,7 +31,7 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType; import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType; import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher; import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
import org.apache.cloudstack.framework.async.AsyncCallbackHandler; import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.storage.datastore.PrimaryDataStoreEntityImpl; import org.apache.cloudstack.storage.datastore.PrimaryDataStoreEntityImpl;
import org.apache.cloudstack.storage.image.TemplateEntityImpl; import org.apache.cloudstack.storage.image.TemplateEntityImpl;
import org.apache.cloudstack.storage.image.TemplateInfo; import org.apache.cloudstack.storage.image.TemplateInfo;
@ -197,8 +197,9 @@ public class VolumeEntityImpl implements VolumeEntity {
public boolean createVolumeFromTemplate(long dataStoreId, VolumeDiskType diskType, TemplateEntity template) { public boolean createVolumeFromTemplate(long dataStoreId, VolumeDiskType diskType, TemplateEntity template) {
TemplateInfo ti = ((TemplateEntityImpl)template).getTemplateInfo(); TemplateInfo ti = ((TemplateEntityImpl)template).getTemplateInfo();
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this) AsyncCallbackDispatcher<VolumeEntityImpl> caller = AsyncCallbackDispatcher.create(this);
.setOperationName("volumeEntity.createVolumeFromTemplateAsyncCallback"); caller.setCallback(caller.getTarget().createVolumeFromTemplateAsyncCallback(null, null));
vs.createVolumeFromTemplateAsync(volumeInfo, dataStoreId, diskType, ti, caller); vs.createVolumeFromTemplateAsync(volumeInfo, dataStoreId, diskType, ti, caller);
try { try {
synchronized (volumeInfo) { synchronized (volumeInfo) {
@ -210,11 +211,12 @@ public class VolumeEntityImpl implements VolumeEntity {
return true; return true;
} }
@AsyncCallbackHandler(operationName="volumeEntity.createVolumeFromTemplateAsyncCallback")
public void createVolumeFromTemplateAsyncCallback(AsyncCallbackDispatcher callback) { public Object createVolumeFromTemplateAsyncCallback(AsyncCompletionCallback<VolumeInfo> callback, Object context) {
synchronized (volumeInfo) { synchronized (volumeInfo) {
volumeInfo.notify(); volumeInfo.notify();
} }
return null;
} }
} }

View File

@ -11,8 +11,6 @@ import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreLifeCy
import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider; import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStoreProvider;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType; import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
import org.apache.cloudstack.framework.async.AsyncCallbackHandler;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.storage.EndPoint; import org.apache.cloudstack.storage.EndPoint;
import org.apache.cloudstack.storage.HypervisorHostEndPoint; import org.apache.cloudstack.storage.HypervisorHostEndPoint;
@ -31,7 +29,6 @@ import org.apache.log4j.Logger;
import com.cloud.host.HostVO; import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao; import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType; import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.Volume;
import com.cloud.utils.component.ComponentInject; import com.cloud.utils.component.ComponentInject;
import edu.emory.mathcs.backport.java.util.Collections; import edu.emory.mathcs.backport.java.util.Collections;
@ -197,19 +194,10 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
public void createVoluemFromBaseImageAsync(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo templateStore, AsyncCompletionCallback<CommandResult> callback) { public void createVoluemFromBaseImageAsync(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo templateStore, AsyncCompletionCallback<CommandResult> callback) {
VolumeObject vo = (VolumeObject) volume; VolumeObject vo = (VolumeObject) volume;
vo.setVolumeDiskType(templateStore.getTemplate().getDiskType()); vo.setVolumeDiskType(templateStore.getTemplate().getDiskType());
AsyncCallbackDispatcher<DefaultPrimaryDataStore> caller = new AsyncCallbackDispatcher<DefaultPrimaryDataStore>(this);
caller.setCallback(caller.getTarget().createVoluemFromBaseImageAsyncCallback(null, null)) this.driver.createVolumeFromBaseImageAsync(vo, templateStore, callback);
.setOperationName("primarydatastore.createvolumefrombaseImage");
this.driver.createVolumeFromBaseImageAsync(vo, templateStore, caller);
} }
@AsyncCallbackHandler(operationName="primarydatastore.createvolumefrombaseImage")
public Object createVoluemFromBaseImageAsyncCallback(AsyncCallbackDispatcher callback, Object parames) {
AsyncCallbackDispatcher parent = callback.getParentCallback();
CommandResult result = callback.getResult();
parent.complete(result);
}
@Override @Override
public boolean installTemplate(TemplateOnPrimaryDataStoreInfo template) { public boolean installTemplate(TemplateOnPrimaryDataStoreInfo template) {
// TODO Auto-generated method stub // TODO Auto-generated method stub

View File

@ -5,8 +5,8 @@ import java.util.Map;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo; import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher; import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
import org.apache.cloudstack.framework.async.AsyncCallbackHandler;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.framework.async.AsyncRpcConext;
import org.apache.cloudstack.storage.EndPoint; import org.apache.cloudstack.storage.EndPoint;
import org.apache.cloudstack.storage.command.CommandResult; import org.apache.cloudstack.storage.command.CommandResult;
import org.apache.cloudstack.storage.command.CreateVolumeAnswer; import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
@ -103,6 +103,19 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
return answer; return answer;
} }
private class CreateVolumeFromBaseImageContext<T> extends AsyncRpcConext<T> {
private final VolumeObject volume;
public CreateVolumeFromBaseImageContext(AsyncCompletionCallback<T> callback, VolumeObject volume) {
super(callback);
this.volume = volume;
}
public VolumeObject getVolume() {
return this.volume;
}
}
@Override @Override
public void createVolumeFromBaseImageAsync(VolumeObject volume, TemplateOnPrimaryDataStoreInfo template, AsyncCompletionCallback<CommandResult> callback) { public void createVolumeFromBaseImageAsync(VolumeObject volume, TemplateOnPrimaryDataStoreInfo template, AsyncCompletionCallback<CommandResult> callback) {
VolumeTO vol = new VolumeTO(volume); VolumeTO vol = new VolumeTO(volume);
@ -111,17 +124,17 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
List<EndPoint> endPoints = template.getPrimaryDataStore().getEndPoints(); List<EndPoint> endPoints = template.getPrimaryDataStore().getEndPoints();
EndPoint ep = endPoints.get(0); EndPoint ep = endPoints.get(0);
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this) CreateVolumeFromBaseImageContext<CommandResult> context = new CreateVolumeFromBaseImageContext<CommandResult>(callback, volume);
.setParentCallback(callback) AsyncCallbackDispatcher<DefaultPrimaryDataStoreDriverImpl> caller = AsyncCallbackDispatcher.create(this);
.setOperationName("primarydatastoredriver.createvolumefrombaseImage") caller.setContext(context)
.setContextParam("volume", volume); .setCallback(caller.getTarget().createVolumeFromBaseImageAsyncCallback(null, null));
ep.sendMessageAsync(cmd, caller); ep.sendMessageAsync(cmd, caller);
} }
@AsyncCallbackHandler(operationName="primarydatastoredriver.createvolumefrombaseImage") public Object createVolumeFromBaseImageAsyncCallback(AsyncCallbackDispatcher<DefaultPrimaryDataStoreDriverImpl> callback, CreateVolumeFromBaseImageContext<CommandResult> context) {
public void createVolumeFromBaseImageAsyncCallback(AsyncCallbackDispatcher callback) {
CreateVolumeAnswer answer = (CreateVolumeAnswer)callback.getResult(); CreateVolumeAnswer answer = (CreateVolumeAnswer)callback.getResult();
CommandResult result = new CommandResult(); CommandResult result = new CommandResult();
if (answer == null || answer.getDetails() != null) { if (answer == null || answer.getDetails() != null) {
@ -131,11 +144,12 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
} }
} else { } else {
result.setSucess(true); result.setSucess(true);
VolumeObject volume = callback.getContextParam("volume"); VolumeObject volume = context.getVolume();
volume.setPath(answer.getVolumeUuid()); volume.setPath(answer.getVolumeUuid());
} }
AsyncCallbackDispatcher parentCall = callback.getParentCallback(); AsyncCompletionCallback<CommandResult> parentCall = context.getParentCallback();
parentCall.complete(result); parentCall.complete(result);
return null;
} }
@Override @Override

View File

@ -25,8 +25,8 @@ import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType; import org.apache.cloudstack.engine.subsystem.api.storage.disktype.VolumeDiskType;
import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType; import org.apache.cloudstack.engine.subsystem.api.storage.type.VolumeType;
import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher; import org.apache.cloudstack.framework.async.AsyncCallbackDispatcher;
import org.apache.cloudstack.framework.async.AsyncCallbackHandler;
import org.apache.cloudstack.framework.async.AsyncCompletionCallback; import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
import org.apache.cloudstack.framework.async.AsyncRpcConext;
import org.apache.cloudstack.storage.EndPoint; import org.apache.cloudstack.storage.EndPoint;
import org.apache.cloudstack.storage.command.CommandResult; import org.apache.cloudstack.storage.command.CommandResult;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore; import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
@ -131,6 +131,30 @@ public class VolumeServiceImpl implements VolumeService {
return null; return null;
} }
private class CreateBaseImageContext<T> extends AsyncRpcConext<T> {
private final VolumeInfo volume;
private final PrimaryDataStore dataStore;
private final TemplateOnPrimaryDataStoreObject template;
public CreateBaseImageContext(AsyncCompletionCallback<T> callback, VolumeInfo volume, PrimaryDataStore datastore, TemplateOnPrimaryDataStoreObject template) {
super(callback);
this.volume = volume;
this.dataStore = datastore;
this.template = template;
}
public VolumeInfo getVolume() {
return this.volume;
}
public PrimaryDataStore getDataStore() {
return this.dataStore;
}
public TemplateOnPrimaryDataStoreObject getTemplate() {
return this.template;
}
}
@DB @DB
protected void createBaseImageAsync(VolumeInfo volume, PrimaryDataStore dataStore, TemplateInfo template, AsyncCompletionCallback<VolumeInfo> callback) { protected void createBaseImageAsync(VolumeInfo volume, PrimaryDataStore dataStore, TemplateInfo template, AsyncCompletionCallback<VolumeInfo> callback) {
TemplateOnPrimaryDataStoreObject templateOnPrimaryStoreObj = (TemplateOnPrimaryDataStoreObject) templatePrimaryStoreMgr.createTemplateOnPrimaryDataStore(template, dataStore); TemplateOnPrimaryDataStoreObject templateOnPrimaryStoreObj = (TemplateOnPrimaryDataStoreObject) templatePrimaryStoreMgr.createTemplateOnPrimaryDataStore(template, dataStore);
@ -147,21 +171,18 @@ public class VolumeServiceImpl implements VolumeService {
templateOnPrimaryStoreObj.updateStatus(Status.DOWNLOAD_IN_PROGRESS); templateOnPrimaryStoreObj.updateStatus(Status.DOWNLOAD_IN_PROGRESS);
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this) CreateBaseImageContext<VolumeInfo> context = new CreateBaseImageContext<VolumeInfo>(callback, volume, dataStore, templateOnPrimaryStoreObj);
.setParentCallback(callback) AsyncCallbackDispatcher<VolumeServiceImpl> caller = AsyncCallbackDispatcher.create(this);
.setOperationName("volumeservice.createbaseimage.callback") caller.setCallback(caller.getTarget().createBaseImageCallback(null, null))
.setContextParam("volume", volume) .setContext(context);
.setContextParam("primary", dataStore)
.setContextParam("templateOnPrimary", templateOnPrimaryStoreObj);
imageMotion.copyTemplateAsync(templateOnPrimaryStoreObj, caller); imageMotion.copyTemplateAsync(templateOnPrimaryStoreObj, caller);
} }
@DB @DB
@AsyncCallbackHandler(operationName="volumeservice.createbaseimage.callback") public Object createBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl> callback, CreateBaseImageContext<VolumeInfo> context) {
public void createBaseImageCallback(AsyncCallbackDispatcher callback) {
CommandResult result = callback.getResult(); CommandResult result = callback.getResult();
TemplateOnPrimaryDataStoreObject templateOnPrimaryStoreObj = callback.getContextParam("templateOnPrimary"); TemplateOnPrimaryDataStoreObject templateOnPrimaryStoreObj = context.getTemplate();
if (result.isSuccess()) { if (result.isSuccess()) {
templateOnPrimaryStoreObj.updateStatus(Status.DOWNLOADED); templateOnPrimaryStoreObj.updateStatus(Status.DOWNLOADED);
templateOnPrimaryStoreObj.stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event.OperationSuccessed); templateOnPrimaryStoreObj.stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event.OperationSuccessed);
@ -170,18 +191,28 @@ public class VolumeServiceImpl implements VolumeService {
templateOnPrimaryStoreObj.stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event.OperationFailed); templateOnPrimaryStoreObj.stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event.OperationFailed);
} }
AsyncCallbackDispatcher parentCaller = callback.getParentCallback(); AsyncCompletionCallback<VolumeInfo> parentCaller = context.getParentCallback();
VolumeInfo volume = callback.getContextParam("volume"); VolumeInfo volume = context.getVolume();
PrimaryDataStore pd = callback.getContextParam("primary"); PrimaryDataStore pd = context.getDataStore();
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this)
.setParentCallback(parentCaller) createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, pd, parentCaller);
.setOperationName("volumeservice.createvolumefrombaseimage.callback"); return null;
}
private class CreateVolumeFromBaseImageContext<T> extends AsyncRpcConext<T> {
private final VolumeObject vo;
public CreateVolumeFromBaseImageContext(AsyncCompletionCallback<T> callback, VolumeObject vo) {
super(callback);
this.vo = vo;
}
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, pd, caller); public VolumeObject getVolumeObject() {
return this.vo;
}
} }
@DB @DB
protected void createVolumeFromBaseImageAsync(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo templateOnPrimaryStore, PrimaryDataStore pd, AsyncCompletionCallback<VolumeObject> callback) { protected void createVolumeFromBaseImageAsync(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo templateOnPrimaryStore, PrimaryDataStore pd, AsyncCompletionCallback<VolumeInfo> callback) {
VolumeObject vo = (VolumeObject) volume; VolumeObject vo = (VolumeObject) volume;
try { try {
vo.stateTransit(Volume.Event.CreateRequested); vo.stateTransit(Volume.Event.CreateRequested);
@ -189,19 +220,17 @@ public class VolumeServiceImpl implements VolumeService {
throw new CloudRuntimeException(e.toString()); throw new CloudRuntimeException(e.toString());
} }
CreateVolumeFromBaseImageContext<VolumeInfo> context = new CreateVolumeFromBaseImageContext<VolumeInfo>(callback, vo);
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this) AsyncCallbackDispatcher<VolumeServiceImpl> caller = AsyncCallbackDispatcher.create(this);
.setParentCallback(callback) caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallback(null, null))
.setOperationName("volumeservice.createVolumeFromBaseImageCallback") .setContext(context);
.setContextParam("volume", vo);
pd.createVoluemFromBaseImageAsync(volume, templateOnPrimaryStore, caller); pd.createVoluemFromBaseImageAsync(volume, templateOnPrimaryStore, caller);
} }
@DB @DB
@AsyncCallbackHandler(operationName="volumeservice.createVolumeFromBaseImageCallback") public Object createVolumeFromBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl> callback, CreateVolumeFromBaseImageContext<VolumeInfo> context) {
public void createVolumeFromBaseImageCallback(AsyncCallbackDispatcher callback) { VolumeObject vo = context.getVolumeObject();
VolumeObject vo = callback.getContextParam("volume");
CommandResult result = callback.getResult(); CommandResult result = callback.getResult();
if (result.isSuccess()) { if (result.isSuccess()) {
vo.stateTransit(Volume.Event.OperationSucceeded); vo.stateTransit(Volume.Event.OperationSucceeded);
@ -209,16 +238,9 @@ public class VolumeServiceImpl implements VolumeService {
vo.stateTransit(Volume.Event.OperationFailed); vo.stateTransit(Volume.Event.OperationFailed);
} }
AsyncCallbackDispatcher parentCall = callback.getParentCallback(); AsyncCompletionCallback<VolumeInfo> parentCall = context.getParentCallback();
parentCall.complete(vo);
}
@DB
@AsyncCallbackHandler(operationName="volumeservice.createvolumefrombaseimage.callback")
public void createVolumeFromBaseImageAsyncCallback(AsyncCallbackDispatcher callback) {
AsyncCallbackDispatcher parentCall = callback.getParentCallback();
VolumeObject vo = callback.getResult();
parentCall.complete(vo); parentCall.complete(vo);
return null;
} }
@DB @DB
@ -230,12 +252,8 @@ public class VolumeServiceImpl implements VolumeService {
createBaseImageAsync(volume, pd, template, callback); createBaseImageAsync(volume, pd, template, callback);
return; return;
} }
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this)
.setParentCallback(callback)
.setOperationName("volumeservice.createvolumefrombaseimage.callback");
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStore, pd, caller); createVolumeFromBaseImageAsync(volume, templateOnPrimaryStore, pd, callback);
} }
@Override @Override

View File

@ -0,0 +1,30 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.cloudstack.framework.async;
public class AsyncRpcConext<T> {
protected final AsyncCompletionCallback<T> parentCallBack;
public AsyncRpcConext(AsyncCompletionCallback<T> callback) {
this.parentCallBack = callback;
}
public AsyncCompletionCallback<T> getParentCallback() {
return this.parentCallBack;
}
}

View File

@ -47,6 +47,7 @@ import javax.ejb.Local;
import javax.naming.ConfigurationException; import javax.naming.ConfigurationException;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException; import org.apache.xmlrpc.XmlRpcException;
import org.w3c.dom.Document; import org.w3c.dom.Document;
@ -559,8 +560,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return execute((Site2SiteVpnCfgCommand) cmd); return execute((Site2SiteVpnCfgCommand) cmd);
} else if (clazz == CheckS2SVpnConnectionsCommand.class) { } else if (clazz == CheckS2SVpnConnectionsCommand.class) {
return execute((CheckS2SVpnConnectionsCommand) cmd); return execute((CheckS2SVpnConnectionsCommand) cmd);
} else if (clazz == StorageCommand.class) { } else if (cmd instanceof StorageSubSystemCommand) {
return this.storageResource.handleStorageCommands((StorageCommand)cmd); return this.storageResource.handleStorageCommands((StorageSubSystemCommand)cmd);
} else { } else {
return Answer.createUnsupportedCommandAnswer(cmd); return Answer.createUnsupportedCommandAnswer(cmd);
} }

View File

@ -67,6 +67,7 @@ public class XenServerStorageResource {
} }
private long getTemplateSize(String url) { private long getTemplateSize(String url) {
/*
HttpGet method = new HttpGet(url); HttpGet method = new HttpGet(url);
HttpClient client = new HttpClient(); HttpClient client = new HttpClient();
try { try {
@ -82,6 +83,8 @@ public class XenServerStorageResource {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
*/
return 0;
} }
protected Answer directDownloadHttpTemplate(TemplateTO template, PrimaryDataStoreTO primarDataStore) { protected Answer directDownloadHttpTemplate(TemplateTO template, PrimaryDataStoreTO primarDataStore) {
@ -131,6 +134,7 @@ public class XenServerStorageResource {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
return null;
} }
protected Answer execute(CopyTemplateToPrimaryStorageCmd cmd) { protected Answer execute(CopyTemplateToPrimaryStorageCmd cmd) {