Skip to content

Commit 956a596

Browse files
author
Prasanna Santhanam
committed
Pulling out Network operations into a separate manager
Network operations like VM, host and storage are pulled into a separate managaer for simulator. Signed-off-by: Prasanna Santhanam <tsp@apache.org>
1 parent 6a92f3b commit 956a596

5 files changed

Lines changed: 161 additions & 121 deletions

File tree

‎plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockAgentManager.java‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@
1616
// under the License.
1717
package com.cloud.agent.manager;
1818

19-
import java.util.Map;
20-
21-
import javax.naming.ConfigurationException;
22-
2319
import com.cloud.agent.api.Answer;
2420
import com.cloud.agent.api.CheckHealthCommand;
2521
import com.cloud.agent.api.CheckNetworkCommand;
@@ -31,13 +27,12 @@
3127
import com.cloud.simulator.MockHost;
3228
import com.cloud.utils.component.Manager;
3329

30+
import javax.naming.ConfigurationException;
31+
import java.util.Map;
32+
3433
public interface MockAgentManager extends Manager {
35-
public static final long DEFAULT_HOST_MEM_SIZE = 8 * 1024 * 1024 * 1024L; // 8G,
36-
// unit
37-
// of
38-
// Mbytes
39-
public static final int DEFAULT_HOST_CPU_CORES = 4; // 2 dual core CPUs (2 x
40-
// 2)
34+
public static final long DEFAULT_HOST_MEM_SIZE = 8 * 1024 * 1024 * 1024L; // 8G, unit of Mbytes
35+
public static final int DEFAULT_HOST_CPU_CORES = 4; // 2 dual core CPUs (2 x 2)
4136
public static final int DEFAULT_HOST_SPEED_MHZ = 8000; // 1 GHz CPUs
4237

4338
boolean configure(String name, Map<String, Object> params) throws ConfigurationException;

‎plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManager.java‎

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -16,88 +16,98 @@
1616
// under the License.
1717
package com.cloud.agent.manager;
1818

19-
import java.util.HashMap;
20-
import java.util.Map;
21-
2219
import com.cloud.agent.api.Answer;
2320
import com.cloud.agent.api.BumpUpPriorityCommand;
2421
import com.cloud.agent.api.CheckRouterAnswer;
2522
import com.cloud.agent.api.CheckRouterCommand;
2623
import com.cloud.agent.api.CheckVirtualMachineCommand;
2724
import com.cloud.agent.api.CleanupNetworkRulesCmd;
25+
import com.cloud.agent.api.CreateVMSnapshotCommand;
26+
import com.cloud.agent.api.DeleteVMSnapshotCommand;
2827
import com.cloud.agent.api.GetDomRVersionAnswer;
2928
import com.cloud.agent.api.GetDomRVersionCmd;
3029
import com.cloud.agent.api.GetVmStatsCommand;
3130
import com.cloud.agent.api.GetVncPortCommand;
3231
import com.cloud.agent.api.MigrateAnswer;
3332
import com.cloud.agent.api.MigrateCommand;
34-
import com.cloud.agent.api.NetworkUsageCommand;
33+
import com.cloud.agent.api.NetworkRulesVmSecondaryIpCommand;
3534
import com.cloud.agent.api.PrepareForMigrationAnswer;
3635
import com.cloud.agent.api.PrepareForMigrationCommand;
36+
import com.cloud.agent.api.RebootAnswer;
3737
import com.cloud.agent.api.RebootCommand;
38+
import com.cloud.agent.api.RevertToVMSnapshotCommand;
39+
import com.cloud.agent.api.ScaleVmCommand;
3840
import com.cloud.agent.api.SecurityGroupRuleAnswer;
3941
import com.cloud.agent.api.SecurityGroupRulesCmd;
42+
import com.cloud.agent.api.StartAnswer;
4043
import com.cloud.agent.api.StartCommand;
44+
import com.cloud.agent.api.StopAnswer;
4145
import com.cloud.agent.api.StopCommand;
4246
import com.cloud.agent.api.check.CheckSshAnswer;
4347
import com.cloud.agent.api.check.CheckSshCommand;
4448
import com.cloud.agent.api.proxy.CheckConsoleProxyLoadCommand;
4549
import com.cloud.agent.api.proxy.WatchConsoleProxyLoadCommand;
46-
import com.cloud.agent.api.routing.DhcpEntryCommand;
47-
import com.cloud.agent.api.routing.IpAssocCommand;
48-
import com.cloud.agent.api.routing.LoadBalancerConfigCommand;
4950
import com.cloud.agent.api.routing.SavePasswordCommand;
50-
import com.cloud.agent.api.routing.SetFirewallRulesCommand;
51-
import com.cloud.agent.api.routing.SetPortForwardingRulesCommand;
52-
import com.cloud.agent.api.routing.SetStaticNatRulesCommand;
5351
import com.cloud.agent.api.routing.VmDataCommand;
5452
import com.cloud.simulator.MockVMVO;
5553
import com.cloud.utils.Pair;
5654
import com.cloud.utils.component.Manager;
5755
import com.cloud.vm.VirtualMachine.State;
5856

57+
import java.util.HashMap;
58+
import java.util.Map;
59+
5960
public interface MockVmManager extends Manager {
60-
public Answer stopVM(StopCommand cmd);
61-
public Answer rebootVM(RebootCommand cmd);
6261

63-
public Answer checkVmState(CheckVirtualMachineCommand cmd);
64-
public Map<String, State> getVmStates(String hostGuid);
65-
public Answer getVncPort(GetVncPortCommand cmd);
62+
Map<String, State> getVmStates(String hostGuid);
6663

67-
Answer startVM(StartCommand cmd, SimulatorInfo info);
64+
Map<String, MockVMVO> getVms(String hostGuid);
6865

69-
Answer getVmStats(GetVmStatsCommand cmd);
70-
public CheckSshAnswer checkSshCommand(CheckSshCommand cmd);
66+
HashMap<String, Pair<Long, Long>> syncNetworkGroups(SimulatorInfo info);
7167

72-
Answer SetStaticNatRules(SetStaticNatRulesCommand cmd);
68+
StartAnswer startVM(StartCommand cmd, SimulatorInfo info);
7369

74-
Answer SetPortForwardingRules(SetPortForwardingRulesCommand cmd);
70+
StopAnswer stopVM(StopCommand cmd);
7571

76-
Answer SetFirewallRules(SetFirewallRulesCommand cmd);
72+
RebootAnswer rebootVM(RebootCommand cmd);
7773

78-
Answer getNetworkUsage(NetworkUsageCommand cmd);
74+
Answer checkVmState(CheckVirtualMachineCommand cmd);
7975

80-
Answer IpAssoc(IpAssocCommand cmd);
76+
Answer getVncPort(GetVncPortCommand cmd);
8177

82-
Answer LoadBalancerConfig(LoadBalancerConfigCommand cmd);
78+
Answer getVmStats(GetVmStatsCommand cmd);
8379

84-
Answer AddDhcpEntry(DhcpEntryCommand cmd);
80+
CheckSshAnswer checkSshCommand(CheckSshCommand cmd);
8581

8682
Answer setVmData(VmDataCommand cmd);
87-
Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info);
8883

8984
Answer CheckConsoleProxyLoad(CheckConsoleProxyLoadCommand cmd);
85+
9086
Answer WatchConsoleProxyLoad(WatchConsoleProxyLoadCommand cmd);
9187

9288
Answer SavePassword(SavePasswordCommand cmd);
93-
HashMap<String, Pair<Long, Long>> syncNetworkGroups(SimulatorInfo info);
94-
SecurityGroupRuleAnswer AddSecurityGroupRules(SecurityGroupRulesCmd cmd, SimulatorInfo info);
95-
MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info);
89+
90+
MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info);
91+
9692
PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cmd);
97-
GetDomRVersionAnswer getDomRVersion(GetDomRVersionCmd cmd);
98-
Map<String, MockVMVO> getVms(String hostGuid);
93+
94+
SecurityGroupRuleAnswer AddSecurityGroupRules(SecurityGroupRulesCmd cmd, SimulatorInfo info);
95+
96+
GetDomRVersionAnswer getDomRVersion(GetDomRVersionCmd cmd);
9997

10098
CheckRouterAnswer checkRouter(CheckRouterCommand cmd);
10199

102100
Answer bumpPriority(BumpUpPriorityCommand cmd);
101+
102+
Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info);
103+
104+
Answer scaleVm(ScaleVmCommand cmd);
105+
106+
Answer plugSecondaryIp(NetworkRulesVmSecondaryIpCommand cmd);
107+
108+
Answer createVmSnapshot(CreateVMSnapshotCommand cmd);
109+
110+
Answer deleteVmSnapshot(DeleteVMSnapshotCommand cmd);
111+
112+
Answer revertVmSnapshot(RevertToVMSnapshotCommand cmd);
103113
}

‎plugins/hypervisors/simulator/src/com/cloud/agent/manager/MockVmManagerImpl.java‎

Lines changed: 28 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ public CheckVirtualMachineAnswer checkVmState(CheckVirtualMachineCommand cmd) {
346346
}
347347

348348
@Override
349-
public Answer startVM(StartCommand cmd, SimulatorInfo info) {
349+
public StartAnswer startVM(StartCommand cmd, SimulatorInfo info) {
350350
VirtualMachineTO vm = cmd.getVirtualMachine();
351351
String result = startVM(vm.getName(), vm.getNics(), vm.getCpus()* vm.getMaxSpeed(), vm.getMaxRam(), vm.getBootArgs(), info.getHostUuid());
352352
if (result != null) {
@@ -361,27 +361,8 @@ public CheckSshAnswer checkSshCommand(CheckSshCommand cmd) {
361361
return new CheckSshAnswer(cmd);
362362
}
363363

364-
@Override
365-
public Answer SetStaticNatRules(SetStaticNatRulesCommand cmd) {
366-
return new Answer(cmd);
367-
}
368-
369-
@Override
370-
public Answer SetPortForwardingRules(SetPortForwardingRulesCommand cmd) {
371-
return new Answer(cmd);
372-
}
373-
374-
@Override
375-
public Answer SetFirewallRules(SetFirewallRulesCommand cmd) {
376-
return new Answer(cmd);
377-
}
378364

379365

380-
@Override
381-
public NetworkUsageAnswer getNetworkUsage(NetworkUsageCommand cmd) {
382-
return new NetworkUsageAnswer(cmd, null, 100L, 100L);
383-
}
384-
385366
@Override
386367
public MigrateAnswer Migrate(MigrateCommand cmd, SimulatorInfo info) {
387368
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
@@ -437,21 +418,6 @@ public PrepareForMigrationAnswer prepareForMigrate(PrepareForMigrationCommand cm
437418
}
438419
}
439420

440-
@Override
441-
public Answer IpAssoc(IpAssocCommand cmd) {
442-
return new Answer(cmd);
443-
}
444-
445-
@Override
446-
public Answer LoadBalancerConfig(LoadBalancerConfigCommand cmd) {
447-
return new Answer(cmd);
448-
}
449-
450-
@Override
451-
public Answer AddDhcpEntry(DhcpEntryCommand cmd) {
452-
return new Answer(cmd);
453-
}
454-
455421
@Override
456422
public Answer setVmData(VmDataCommand cmd) {
457423
return new Answer(cmd);
@@ -482,7 +448,32 @@ public Answer CleanupNetworkRules(CleanupNetworkRulesCmd cmd, SimulatorInfo info
482448
}
483449

484450
@Override
485-
public Answer stopVM(StopCommand cmd) {
451+
public Answer scaleVm(ScaleVmCommand cmd) {
452+
return null; //To change body of implemented methods use File | Settings | File Templates.
453+
}
454+
455+
@Override
456+
public Answer plugSecondaryIp(NetworkRulesVmSecondaryIpCommand cmd) {
457+
return null; //To change body of implemented methods use File | Settings | File Templates.
458+
}
459+
460+
@Override
461+
public Answer createVmSnapshot(CreateVMSnapshotCommand cmd) {
462+
return null; //To change body of implemented methods use File | Settings | File Templates.
463+
}
464+
465+
@Override
466+
public Answer deleteVmSnapshot(DeleteVMSnapshotCommand cmd) {
467+
return null; //To change body of implemented methods use File | Settings | File Templates.
468+
}
469+
470+
@Override
471+
public Answer revertVmSnapshot(RevertToVMSnapshotCommand cmd) {
472+
return null; //To change body of implemented methods use File | Settings | File Templates.
473+
}
474+
475+
@Override
476+
public StopAnswer stopVM(StopCommand cmd) {
486477
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
487478
try {
488479
txn.start();
@@ -509,7 +500,7 @@ public Answer stopVM(StopCommand cmd) {
509500
}
510501

511502
@Override
512-
public Answer rebootVM(RebootCommand cmd) {
503+
public RebootAnswer rebootVM(RebootCommand cmd) {
513504
Transaction txn = Transaction.open(Transaction.SIMULATOR_DB);
514505
try {
515506
txn.start();

0 commit comments

Comments
 (0)