Skip to content

Commit d991613

Browse files
author
Edison Su
committed
so many traps in rpc call: you can't use aop in a thread, you need to intercept finalize call etc
1 parent 4b2d9f4 commit d991613

43 files changed

Lines changed: 569 additions & 237 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

engine/api/src/org/apache/cloudstack/engine/subsystem/api/storage/PrimaryDataStoreInfo.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ public interface PrimaryDataStoreInfo {
4141
public String getType();
4242
public PrimaryDataStoreLifeCycle getLifeCycle();
4343
PrimaryDataStoreProvider getProvider();
44+
4445
}

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/ChildTestConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public AgentManager agentMgr() {
2424

2525
@Bean
2626
public HostEndpointRpcServer rpcServer() {
27-
return new MockHypervsiorHostEndPointRpcServer();
27+
return new MockHostEndpointRpcServerDirectCallResource();
2828
}
2929
/* @Override
3030
@Bean

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/CloudStackTestNGBase.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.testng.annotations.AfterMethod;
77
import org.testng.annotations.BeforeMethod;
88
import org.testng.annotations.Parameters;
9+
import org.testng.annotations.Test;
910

1011
import com.cloud.utils.db.DB;
1112
import com.cloud.utils.db.Transaction;
@@ -17,13 +18,23 @@ public class CloudStackTestNGBase extends AbstractTestNGSpringContextTests {
1718
private String hostGuid;
1819
private String templateUrl;
1920
private String localStorageUuid;
21+
private String primaryStorageUrl;
2022
private Transaction txn;
2123

24+
protected void injectMockito() {
25+
26+
}
27+
2228
@BeforeMethod(alwaysRun = true)
2329
protected void injectDB(Method testMethod) throws Exception {
2430
txn = Transaction.open(testMethod.getName());
2531
}
2632

33+
@Test
34+
protected void injectMockitoTest() {
35+
injectMockito();
36+
}
37+
2738
@AfterMethod(alwaysRun = true)
2839
protected void closeDB(Method testMethod) throws Exception {
2940
if (txn != null) {
@@ -32,14 +43,19 @@ protected void closeDB(Method testMethod) throws Exception {
3243
}
3344

3445
@BeforeMethod(alwaysRun = true)
35-
@Parameters({"devcloud-host-uuid", "devcloud-host-gateway", "devcloud-host-cidr", "devcloud-host-ip", "template-url", "devcloud-local-storage-uuid"})
36-
protected void setup(String hostuuid, String gateway, String cidr, String hostIp, String templateUrl, String localStorageUuid) {
46+
@Parameters({"devcloud-host-uuid", "devcloud-host-gateway", "devcloud-host-cidr",
47+
"devcloud-host-ip", "template-url", "devcloud-local-storage-uuid",
48+
"primary-storage-want-to-add"})
49+
protected void setup(String hostuuid, String gateway, String cidr,
50+
String hostIp, String templateUrl, String localStorageUuid,
51+
String primaryStorage) {
3752
this.hostGuid = hostuuid;
3853
this.hostGateway = gateway;
3954
this.hostCidr = cidr;
4055
this.hostIp = hostIp;
4156
this.templateUrl = templateUrl;
4257
this.localStorageUuid = localStorageUuid;
58+
this.primaryStorageUrl = primaryStorage;
4359
}
4460

4561
protected String getHostGuid() {
@@ -65,4 +81,8 @@ protected String getTemplateUrl() {
6581
protected String getLocalStorageUuid() {
6682
return this.localStorageUuid;
6783
}
84+
85+
protected String getPrimaryStorageUrl() {
86+
return this.primaryStorageUrl;
87+
}
6888
}

engine/storage/integration-test/test/org/apache/cloudstack/storage/test/MockHostEndpointRpcServerDirectCallResource.java

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
import com.cloud.agent.api.Command;
3838
import com.cloud.exception.AgentUnavailableException;
3939
import com.cloud.exception.OperationTimedoutException;
40+
import com.cloud.utils.component.ComponentInject;
41+
import com.cloud.utils.db.DB;
42+
import com.cloud.utils.db.Transaction;
4043

4144

4245
public class MockHostEndpointRpcServerDirectCallResource implements HostEndpointRpcServer {
@@ -47,29 +50,14 @@ public class MockHostEndpointRpcServerDirectCallResource implements HostEndpoint
4750
public MockHostEndpointRpcServerDirectCallResource() {
4851
executor = Executors.newScheduledThreadPool(10);
4952
}
50-
protected class MockRpcCallBack implements Runnable {
51-
private final Command cmd;
52-
private final long hostId;
53-
private final AsyncCompletionCallback<Answer> callback;
54-
public MockRpcCallBack(long hostId, Command cmd, final AsyncCompletionCallback<Answer> callback) {
55-
this.cmd = cmd;
56-
this.callback = callback;
57-
this.hostId = hostId;
58-
}
59-
@Override
60-
public void run() {
61-
try {
62-
Answer answer = agentMgr.send(hostId, cmd);
63-
callback.complete(answer);
64-
} catch (Exception e) {
65-
s_logger.debug("send command failed:" + e.toString());
66-
}
67-
}
68-
69-
}
7053

7154
public void sendCommandAsync(HypervisorHostEndPoint host, final Command command, final AsyncCompletionCallback<Answer> callback) {
72-
executor.schedule(new MockRpcCallBack(host.getHostId(), command, callback), 10, TimeUnit.SECONDS);
55+
// new MockRpcCallBack(host.getHostId(), command, callback);
56+
MockRpcCallBack run = ComponentInject.inject(MockRpcCallBack.class);
57+
run.setCallback(callback);
58+
run.setCmd(command);
59+
run.setHostId(host.getHostId());
60+
executor.schedule(run, 10, TimeUnit.SECONDS);
7361
}
7462

7563
@Override
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package org.apache.cloudstack.storage.test;
2+
3+
import javax.inject.Inject;
4+
5+
import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
6+
7+
import com.cloud.agent.AgentManager;
8+
import com.cloud.agent.api.Answer;
9+
import com.cloud.agent.api.Command;
10+
import com.cloud.utils.db.DB;
11+
import com.cloud.utils.db.Transaction;
12+
13+
public class MockRpcCallBack implements Runnable {
14+
@Inject
15+
AgentManager agentMgr;
16+
private Command cmd;
17+
private long hostId;
18+
private AsyncCompletionCallback<Answer> callback;
19+
20+
public void setCmd(Command cmd) {
21+
this.cmd = cmd;
22+
}
23+
24+
public void setHostId(long hostId) {
25+
this.hostId = hostId;
26+
}
27+
28+
public void setCallback(AsyncCompletionCallback<Answer> callback) {
29+
this.callback = callback;
30+
}
31+
32+
@Override
33+
@DB
34+
public void run() {
35+
try {
36+
Answer answer = agentMgr.send(hostId, cmd);
37+
38+
callback.complete(answer);
39+
} catch (Throwable e) {
40+
//s_logger.debug("send command failed:" + e.toString());
41+
} finally {
42+
int i =1;
43+
}
44+
}
45+
46+
}

0 commit comments

Comments
 (0)