mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fixes/tests on sample management server on new RPC/Async framework
This commit is contained in:
parent
510d3759a7
commit
a6c441fcc5
@ -26,7 +26,7 @@ public class SampleManagementServer {
|
||||
public void mainLoop() {
|
||||
while(true) {
|
||||
try {
|
||||
Thread.currentThread().sleep(1000);
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,20 +18,27 @@
|
||||
*/
|
||||
package org.apache.cloudstack.framework.messaging.server;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.apache.cloudstack.framework.messaging.EventBus;
|
||||
import org.apache.cloudstack.framework.messaging.EventDispatcher;
|
||||
import org.apache.cloudstack.framework.messaging.EventHandler;
|
||||
import org.apache.cloudstack.framework.messaging.RpcCallbackListener;
|
||||
import org.apache.cloudstack.framework.messaging.RpcException;
|
||||
import org.apache.cloudstack.framework.messaging.RpcProvider;
|
||||
import org.apache.cloudstack.framework.messaging.RpcServerCall;
|
||||
import org.apache.cloudstack.framework.messaging.RpcServiceDispatcher;
|
||||
import org.apache.cloudstack.framework.messaging.RpcServiceHandler;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SampleManagerComponent {
|
||||
private static final Logger s_logger = Logger.getLogger(SampleManagerComponent.class);
|
||||
|
||||
@Inject
|
||||
private EventBus _eventBus;
|
||||
@ -39,6 +46,8 @@ public class SampleManagerComponent {
|
||||
@Inject
|
||||
private RpcProvider _rpcProvider;
|
||||
|
||||
private Timer _timer = new Timer();
|
||||
|
||||
public SampleManagerComponent() {
|
||||
}
|
||||
|
||||
@ -50,6 +59,12 @@ public class SampleManagerComponent {
|
||||
// subscribe to all network events (for example)
|
||||
_eventBus.subscribe("network",
|
||||
EventDispatcher.getDispatcher(this));
|
||||
|
||||
_timer.schedule(new TimerTask() {
|
||||
public void run() {
|
||||
testRpc();
|
||||
}
|
||||
}, 3000);
|
||||
}
|
||||
|
||||
@RpcServiceHandler(command="NetworkPrepare")
|
||||
@ -60,4 +75,24 @@ public class SampleManagerComponent {
|
||||
@EventHandler(topic="network.prepare")
|
||||
void onPrepareNetwork(String sender, String topic, Object args) {
|
||||
}
|
||||
|
||||
void testRpc() {
|
||||
SampleStoragePrepareCommand cmd = new SampleStoragePrepareCommand();
|
||||
cmd.setStoragePool("Pool1");
|
||||
cmd.setVolumeId("vol1");
|
||||
|
||||
_rpcProvider.newCall()
|
||||
.setCommand("StoragePrepare").setCommandArg(cmd).setTimeout(10000)
|
||||
.addCallbackListener(new RpcCallbackListener<SampleStoragePrepareAnswer>() {
|
||||
@Override
|
||||
public void onSuccess(SampleStoragePrepareAnswer result) {
|
||||
s_logger.info("StoragePrepare return result: " + result.getResult());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(RpcException e) {
|
||||
s_logger.info("StoragePrepare failed");
|
||||
}
|
||||
}).apply();
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,10 +28,13 @@ import org.apache.cloudstack.framework.messaging.RpcProvider;
|
||||
import org.apache.cloudstack.framework.messaging.RpcServerCall;
|
||||
import org.apache.cloudstack.framework.messaging.RpcServiceDispatcher;
|
||||
import org.apache.cloudstack.framework.messaging.RpcServiceHandler;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class SampleManagerComponent2 {
|
||||
private static final Logger s_logger = Logger.getLogger(SampleManagerComponent2.class);
|
||||
|
||||
@Inject
|
||||
private EventBus _eventBus;
|
||||
|
||||
@ -53,7 +56,13 @@ public class SampleManagerComponent2 {
|
||||
|
||||
@RpcServiceHandler(command="StoragePrepare")
|
||||
void onStartCommand(RpcServerCall call) {
|
||||
call.completeCall("StoragePrepare completed");
|
||||
s_logger.info("Reevieved StoragePrpare call");
|
||||
SampleStoragePrepareCommand cmd = call.getCommandArgument();
|
||||
|
||||
s_logger.info("StoragePrepare command arg. pool: " + cmd.getStoragePool() + ", vol: " + cmd.getVolumeId());
|
||||
SampleStoragePrepareAnswer answer = new SampleStoragePrepareAnswer();
|
||||
|
||||
call.completeCall(answer);
|
||||
}
|
||||
|
||||
@EventHandler(topic="storage.prepare")
|
||||
|
||||
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* 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.messaging.server;
|
||||
|
||||
import org.apache.cloudstack.framework.messaging.OnwireName;
|
||||
|
||||
@OnwireName(name="SampleStoragePrepareAnswer")
|
||||
public class SampleStoragePrepareAnswer {
|
||||
String result;
|
||||
|
||||
public SampleStoragePrepareAnswer() {
|
||||
}
|
||||
|
||||
public String getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(String result) {
|
||||
this.result = result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* 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.messaging.server;
|
||||
|
||||
import org.apache.cloudstack.framework.messaging.OnwireName;
|
||||
|
||||
@OnwireName(name="SampleStoragePrepareCommand")
|
||||
public class SampleStoragePrepareCommand {
|
||||
|
||||
String storagePool;
|
||||
String volumeId;
|
||||
|
||||
public SampleStoragePrepareCommand() {
|
||||
}
|
||||
|
||||
public String getStoragePool() {
|
||||
return storagePool;
|
||||
}
|
||||
|
||||
public void setStoragePool(String storagePool) {
|
||||
this.storagePool = storagePool;
|
||||
}
|
||||
|
||||
public String getVolumeId() {
|
||||
return volumeId;
|
||||
}
|
||||
|
||||
public void setVolumeId(String volumeId) {
|
||||
this.volumeId = volumeId;
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user