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;
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.AsyncRpcConext;
import org.apache.cloudstack.storage.EndPoint;
import org.apache.cloudstack.storage.command.CommandResult;
import org.apache.cloudstack.storage.command.CopyTemplateToPrimaryStorageCmd;
@ -53,19 +53,33 @@ public class DefaultImageMotionStrategy implements ImageMotionStrategy {
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
public void copyTemplateAsync(TemplateOnPrimaryDataStoreInfo templateStore, EndPoint ep, AsyncCompletionCallback<CommandResult> callback) {
ImageOnPrimayDataStoreTO imageTo = new ImageOnPrimayDataStoreTO(templateStore);
CopyTemplateToPrimaryStorageCmd copyCommand = new CopyTemplateToPrimaryStorageCmd(imageTo);
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this).setParentCallback(callback)
.setOperationName("defaultImageStrategy.copytemplate.callback")
.setContextParam("templateStore", templateStore);
CreateTemplateContext<CommandResult> context = new CreateTemplateContext<CommandResult>(callback, templateStore);
AsyncCallbackDispatcher<DefaultImageMotionStrategy> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().copyTemplateCallBack(null, null))
.setContext(context);
ep.sendMessageAsync(copyCommand, caller);
}
@AsyncCallbackHandler(operationName="defaultImageStrategy.copytemplate.callback")
public void copyTemplateCallBack(AsyncCallbackDispatcher callback) {
AsyncCallbackDispatcher parentCall = callback.getParentCallback();
public Object copyTemplateCallBack(AsyncCallbackDispatcher<DefaultImageMotionStrategy> callback, CreateTemplateContext<CommandResult> context) {
AsyncCompletionCallback<CommandResult> parentCall = context.getParentCallback();
CopyTemplateToPrimaryStorageAnswer answer = callback.getResult();
CommandResult result = new CommandResult();
@ -73,12 +87,13 @@ public class DefaultImageMotionStrategy implements ImageMotionStrategy {
result.setSucess(answer.getResult());
result.setResult(answer.getDetails());
} else {
TemplateOnPrimaryDataStoreInfo templateStore = callback.getContextParam("templateStore");
TemplateOnPrimaryDataStoreInfo templateStore = context.getTemplate();
templateStore.setPath(answer.getPath());
result.setSucess(true);
}
parentCall.complete(result);
return null;
}
}

View File

@ -20,8 +20,6 @@ package org.apache.cloudstack.storage;
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.log4j.Logger;
@ -62,15 +60,6 @@ public class HypervisorHostEndPoint implements EndPoint {
@Override
public void sendMessageAsync(Command cmd, AsyncCompletionCallback<Answer> callback) {
AsyncCallbackDispatcher dispatcher = new AsyncCallbackDispatcher(this).setContextParam("parentCallback", 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());
rpcServer.sendCommandAsync(this.hostAddress, cmd, callback);
}
}

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.type.VolumeType;
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.image.TemplateEntityImpl;
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) {
TemplateInfo ti = ((TemplateEntityImpl)template).getTemplateInfo();
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this)
.setOperationName("volumeEntity.createVolumeFromTemplateAsyncCallback");
AsyncCallbackDispatcher<VolumeEntityImpl> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createVolumeFromTemplateAsyncCallback(null, null));
vs.createVolumeFromTemplateAsync(volumeInfo, dataStoreId, diskType, ti, caller);
try {
synchronized (volumeInfo) {
@ -210,11 +211,12 @@ public class VolumeEntityImpl implements VolumeEntity {
return true;
}
@AsyncCallbackHandler(operationName="volumeEntity.createVolumeFromTemplateAsyncCallback")
public void createVolumeFromTemplateAsyncCallback(AsyncCallbackDispatcher callback) {
public Object createVolumeFromTemplateAsyncCallback(AsyncCompletionCallback<VolumeInfo> callback, Object context) {
synchronized (volumeInfo) {
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.VolumeInfo;
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.storage.EndPoint;
import org.apache.cloudstack.storage.HypervisorHostEndPoint;
@ -31,7 +29,6 @@ import org.apache.log4j.Logger;
import com.cloud.host.HostVO;
import com.cloud.host.dao.HostDao;
import com.cloud.hypervisor.Hypervisor.HypervisorType;
import com.cloud.storage.Volume;
import com.cloud.utils.component.ComponentInject;
import edu.emory.mathcs.backport.java.util.Collections;
@ -197,17 +194,8 @@ public class DefaultPrimaryDataStore implements PrimaryDataStore {
public void createVoluemFromBaseImageAsync(VolumeInfo volume, TemplateOnPrimaryDataStoreInfo templateStore, AsyncCompletionCallback<CommandResult> callback) {
VolumeObject vo = (VolumeObject) volume;
vo.setVolumeDiskType(templateStore.getTemplate().getDiskType());
AsyncCallbackDispatcher<DefaultPrimaryDataStore> caller = new AsyncCallbackDispatcher<DefaultPrimaryDataStore>(this);
caller.setCallback(caller.getTarget().createVoluemFromBaseImageAsyncCallback(null, null))
.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);
this.driver.createVolumeFromBaseImageAsync(vo, templateStore, callback);
}
@Override

View File

@ -5,8 +5,8 @@ import java.util.Map;
import org.apache.cloudstack.engine.subsystem.api.storage.VolumeInfo;
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.AsyncRpcConext;
import org.apache.cloudstack.storage.EndPoint;
import org.apache.cloudstack.storage.command.CommandResult;
import org.apache.cloudstack.storage.command.CreateVolumeAnswer;
@ -103,6 +103,19 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
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
public void createVolumeFromBaseImageAsync(VolumeObject volume, TemplateOnPrimaryDataStoreInfo template, AsyncCompletionCallback<CommandResult> callback) {
VolumeTO vol = new VolumeTO(volume);
@ -111,17 +124,17 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
List<EndPoint> endPoints = template.getPrimaryDataStore().getEndPoints();
EndPoint ep = endPoints.get(0);
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this)
.setParentCallback(callback)
.setOperationName("primarydatastoredriver.createvolumefrombaseImage")
.setContextParam("volume", volume);
CreateVolumeFromBaseImageContext<CommandResult> context = new CreateVolumeFromBaseImageContext<CommandResult>(callback, volume);
AsyncCallbackDispatcher<DefaultPrimaryDataStoreDriverImpl> caller = AsyncCallbackDispatcher.create(this);
caller.setContext(context)
.setCallback(caller.getTarget().createVolumeFromBaseImageAsyncCallback(null, null));
ep.sendMessageAsync(cmd, caller);
}
@AsyncCallbackHandler(operationName="primarydatastoredriver.createvolumefrombaseImage")
public void createVolumeFromBaseImageAsyncCallback(AsyncCallbackDispatcher callback) {
public Object createVolumeFromBaseImageAsyncCallback(AsyncCallbackDispatcher<DefaultPrimaryDataStoreDriverImpl> callback, CreateVolumeFromBaseImageContext<CommandResult> context) {
CreateVolumeAnswer answer = (CreateVolumeAnswer)callback.getResult();
CommandResult result = new CommandResult();
if (answer == null || answer.getDetails() != null) {
@ -131,11 +144,12 @@ public class DefaultPrimaryDataStoreDriverImpl implements PrimaryDataStoreDriver
}
} else {
result.setSucess(true);
VolumeObject volume = callback.getContextParam("volume");
VolumeObject volume = context.getVolume();
volume.setPath(answer.getVolumeUuid());
}
AsyncCallbackDispatcher parentCall = callback.getParentCallback();
AsyncCompletionCallback<CommandResult> parentCall = context.getParentCallback();
parentCall.complete(result);
return null;
}
@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.type.VolumeType;
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.AsyncRpcConext;
import org.apache.cloudstack.storage.EndPoint;
import org.apache.cloudstack.storage.command.CommandResult;
import org.apache.cloudstack.storage.datastore.PrimaryDataStore;
@ -131,6 +131,30 @@ public class VolumeServiceImpl implements VolumeService {
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
protected void createBaseImageAsync(VolumeInfo volume, PrimaryDataStore dataStore, TemplateInfo template, AsyncCompletionCallback<VolumeInfo> callback) {
TemplateOnPrimaryDataStoreObject templateOnPrimaryStoreObj = (TemplateOnPrimaryDataStoreObject) templatePrimaryStoreMgr.createTemplateOnPrimaryDataStore(template, dataStore);
@ -147,21 +171,18 @@ public class VolumeServiceImpl implements VolumeService {
templateOnPrimaryStoreObj.updateStatus(Status.DOWNLOAD_IN_PROGRESS);
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this)
.setParentCallback(callback)
.setOperationName("volumeservice.createbaseimage.callback")
.setContextParam("volume", volume)
.setContextParam("primary", dataStore)
.setContextParam("templateOnPrimary", templateOnPrimaryStoreObj);
CreateBaseImageContext<VolumeInfo> context = new CreateBaseImageContext<VolumeInfo>(callback, volume, dataStore, templateOnPrimaryStoreObj);
AsyncCallbackDispatcher<VolumeServiceImpl> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createBaseImageCallback(null, null))
.setContext(context);
imageMotion.copyTemplateAsync(templateOnPrimaryStoreObj, caller);
}
@DB
@AsyncCallbackHandler(operationName="volumeservice.createbaseimage.callback")
public void createBaseImageCallback(AsyncCallbackDispatcher callback) {
public Object createBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl> callback, CreateBaseImageContext<VolumeInfo> context) {
CommandResult result = callback.getResult();
TemplateOnPrimaryDataStoreObject templateOnPrimaryStoreObj = callback.getContextParam("templateOnPrimary");
TemplateOnPrimaryDataStoreObject templateOnPrimaryStoreObj = context.getTemplate();
if (result.isSuccess()) {
templateOnPrimaryStoreObj.updateStatus(Status.DOWNLOADED);
templateOnPrimaryStoreObj.stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event.OperationSuccessed);
@ -170,18 +191,28 @@ public class VolumeServiceImpl implements VolumeService {
templateOnPrimaryStoreObj.stateTransit(TemplateOnPrimaryDataStoreStateMachine.Event.OperationFailed);
}
AsyncCallbackDispatcher parentCaller = callback.getParentCallback();
VolumeInfo volume = callback.getContextParam("volume");
PrimaryDataStore pd = callback.getContextParam("primary");
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this)
.setParentCallback(parentCaller)
.setOperationName("volumeservice.createvolumefrombaseimage.callback");
AsyncCompletionCallback<VolumeInfo> parentCaller = context.getParentCallback();
VolumeInfo volume = context.getVolume();
PrimaryDataStore pd = context.getDataStore();
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, pd, caller);
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStoreObj, pd, parentCaller);
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;
}
public VolumeObject getVolumeObject() {
return this.vo;
}
}
@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;
try {
vo.stateTransit(Volume.Event.CreateRequested);
@ -189,19 +220,17 @@ public class VolumeServiceImpl implements VolumeService {
throw new CloudRuntimeException(e.toString());
}
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this)
.setParentCallback(callback)
.setOperationName("volumeservice.createVolumeFromBaseImageCallback")
.setContextParam("volume", vo);
CreateVolumeFromBaseImageContext<VolumeInfo> context = new CreateVolumeFromBaseImageContext<VolumeInfo>(callback, vo);
AsyncCallbackDispatcher<VolumeServiceImpl> caller = AsyncCallbackDispatcher.create(this);
caller.setCallback(caller.getTarget().createVolumeFromBaseImageCallback(null, null))
.setContext(context);
pd.createVoluemFromBaseImageAsync(volume, templateOnPrimaryStore, caller);
}
@DB
@AsyncCallbackHandler(operationName="volumeservice.createVolumeFromBaseImageCallback")
public void createVolumeFromBaseImageCallback(AsyncCallbackDispatcher callback) {
VolumeObject vo = callback.getContextParam("volume");
public Object createVolumeFromBaseImageCallback(AsyncCallbackDispatcher<VolumeServiceImpl> callback, CreateVolumeFromBaseImageContext<VolumeInfo> context) {
VolumeObject vo = context.getVolumeObject();
CommandResult result = callback.getResult();
if (result.isSuccess()) {
vo.stateTransit(Volume.Event.OperationSucceeded);
@ -209,16 +238,9 @@ public class VolumeServiceImpl implements VolumeService {
vo.stateTransit(Volume.Event.OperationFailed);
}
AsyncCallbackDispatcher parentCall = callback.getParentCallback();
parentCall.complete(vo);
}
@DB
@AsyncCallbackHandler(operationName="volumeservice.createvolumefrombaseimage.callback")
public void createVolumeFromBaseImageAsyncCallback(AsyncCallbackDispatcher callback) {
AsyncCallbackDispatcher parentCall = callback.getParentCallback();
VolumeObject vo = callback.getResult();
AsyncCompletionCallback<VolumeInfo> parentCall = context.getParentCallback();
parentCall.complete(vo);
return null;
}
@DB
@ -231,11 +253,7 @@ public class VolumeServiceImpl implements VolumeService {
return;
}
AsyncCallbackDispatcher caller = new AsyncCallbackDispatcher(this)
.setParentCallback(callback)
.setOperationName("volumeservice.createvolumefrombaseimage.callback");
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStore, pd, caller);
createVolumeFromBaseImageAsync(volume, templateOnPrimaryStore, pd, callback);
}
@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.xml.parsers.DocumentBuilderFactory;
import org.apache.cloudstack.storage.command.StorageSubSystemCommand;
import org.apache.log4j.Logger;
import org.apache.xmlrpc.XmlRpcException;
import org.w3c.dom.Document;
@ -559,8 +560,8 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
return execute((Site2SiteVpnCfgCommand) cmd);
} else if (clazz == CheckS2SVpnConnectionsCommand.class) {
return execute((CheckS2SVpnConnectionsCommand) cmd);
} else if (clazz == StorageCommand.class) {
return this.storageResource.handleStorageCommands((StorageCommand)cmd);
} else if (cmd instanceof StorageSubSystemCommand) {
return this.storageResource.handleStorageCommands((StorageSubSystemCommand)cmd);
} else {
return Answer.createUnsupportedCommandAnswer(cmd);
}

View File

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