Skip to content

Commit 25b4159

Browse files
koushik-dasDaanHoogland
authored andcommitted
CLOUDSTACK-6445: Simulator enhancements
Refer FS - https://cwiki.apache.org/confluence/display/CLOUDSTACK/Simulator+enhancements (cherry picked from commit 617826d)
1 parent 19eb06b commit 25b4159

21 files changed

Lines changed: 1373 additions & 188 deletions

File tree

‎agent-simulator/tomcatconf/commands-simulator.properties.in‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,5 @@
1717

1818

1919
configureSimulator=com.cloud.api.commands.ConfigureSimulatorCmd;1
20+
querySimulatorMock=com.cloud.api.commands.QuerySimulatorMockCmd;1
21+
cleanupSimulatorMock=com.cloud.api.commands.CleanupSimulatorMockCmd;1

‎client/tomcatconf/commands.properties.in‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,8 @@ deleteStratoshereSsp=1
620620
#### host simulator commands
621621

622622
configureSimulator=1
623+
querySimulatorMock=1
624+
cleanupSimulatorMock=1
623625

624626
#### api discovery commands
625627

‎plugins/hypervisors/simulator/resources/META-INF/cloudstack/simulator-compute/spring-simulator-compute-context.xml‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,10 @@
3030
<bean id="SimulatorGuru" class="com.cloud.simulator.SimulatorGuru">
3131
<property name="name" value="Simulator Guru"/>
3232
</bean>
33-
33+
<bean id="SimulatorInvestigator" class="com.cloud.ha.SimulatorInvestigator">
34+
<property name="name" value="Simulator Investigator"/>
35+
</bean>
36+
<bean id="SimulatorFencer" class="com.cloud.ha.SimulatorFencer">
37+
<property name="name" value="Simulator Fencer"/>
38+
</bean>
3439
</beans>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.cloud.agent.api.CleanupNetworkRulesCmd;
2828
import com.cloud.agent.api.CreateVMSnapshotCommand;
2929
import com.cloud.agent.api.DeleteVMSnapshotCommand;
30+
import com.cloud.agent.api.FenceCommand;
3031
import com.cloud.agent.api.GetDomRVersionAnswer;
3132
import com.cloud.agent.api.GetDomRVersionCmd;
3233
import com.cloud.agent.api.GetVmStatsCommand;
@@ -110,4 +111,6 @@ public interface MockVmManager extends Manager {
110111
Answer deleteVmSnapshot(DeleteVMSnapshotCommand cmd);
111112

112113
Answer revertVmSnapshot(RevertToVMSnapshotCommand cmd);
114+
115+
Answer fence(FenceCommand cmd);
113116
}

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.naming.ConfigurationException;
2828

2929
import com.cloud.network.VirtualNetworkApplianceService;
30+
3031
import org.apache.log4j.Logger;
3132
import org.springframework.stereotype.Component;
3233

@@ -41,6 +42,8 @@
4142
import com.cloud.agent.api.CreateVMSnapshotCommand;
4243
import com.cloud.agent.api.DeleteVMSnapshotAnswer;
4344
import com.cloud.agent.api.DeleteVMSnapshotCommand;
45+
import com.cloud.agent.api.FenceAnswer;
46+
import com.cloud.agent.api.FenceCommand;
4447
import com.cloud.agent.api.GetDomRVersionAnswer;
4548
import com.cloud.agent.api.GetDomRVersionCmd;
4649
import com.cloud.agent.api.GetVmStatsAnswer;
@@ -661,4 +664,8 @@ public HashMap<String, Pair<Long, Long>> syncNetworkGroups(SimulatorInfo info) {
661664
return maps;
662665
}
663666

667+
@Override
668+
public Answer fence(FenceCommand cmd) {
669+
return new FenceAnswer(cmd);
670+
}
664671
}

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
import com.cloud.agent.api.Answer;
2323
import com.cloud.agent.api.Command;
2424
import com.cloud.agent.api.StoragePoolInfo;
25+
import com.cloud.simulator.MockConfigurationVO;
2526
import com.cloud.simulator.MockVMVO;
27+
import com.cloud.simulator.dao.MockConfigurationDao;
2628
import com.cloud.utils.Pair;
2729
import com.cloud.utils.component.Manager;
2830
import com.cloud.vm.VirtualMachine.State;
@@ -56,11 +58,17 @@ public int value() {
5658

5759
StoragePoolInfo getLocalStorage(String hostGuid);
5860

59-
boolean configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command, String values);
61+
Long configureSimulator(Long zoneId, Long podId, Long clusterId, Long hostId, String command, String values, Integer count, String jsonResponse);
6062

6163
public HashMap<String, Pair<Long, Long>> syncNetworkGroups(String hostGuid);
6264

6365
Map<String, State> getVmStates(String hostGuid);
6466

6567
Map<String, MockVMVO> getVms(String hostGuid);
68+
69+
MockConfigurationVO querySimulatorMock(Long id);
70+
71+
boolean clearSimulatorMock(Long id);
72+
73+
MockConfigurationDao getMockConfigurationDao();
6674
}

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

Lines changed: 262 additions & 159 deletions
Large diffs are not rendered by default.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.api.commands;
18+
19+
import com.cloud.agent.manager.SimulatorManager;
20+
import com.cloud.exception.ConcurrentOperationException;
21+
import com.cloud.exception.InsufficientCapacityException;
22+
import com.cloud.exception.ResourceAllocationException;
23+
import com.cloud.exception.ResourceUnavailableException;
24+
import com.cloud.user.Account;
25+
26+
import org.apache.cloudstack.api.APICommand;
27+
import org.apache.cloudstack.api.ApiConstants;
28+
import org.apache.cloudstack.api.ApiErrorCode;
29+
import org.apache.cloudstack.api.BaseCmd;
30+
import org.apache.cloudstack.api.Parameter;
31+
import org.apache.cloudstack.api.ServerApiException;
32+
import org.apache.cloudstack.api.response.SuccessResponse;
33+
import org.apache.log4j.Logger;
34+
35+
import javax.inject.Inject;
36+
37+
38+
@APICommand(name = "cleanupSimulatorMock", description="cleanup simulator mock", responseObject=SuccessResponse.class)
39+
public class CleanupSimulatorMockCmd extends BaseCmd {
40+
public static final Logger s_logger = Logger.getLogger(CleanupSimulatorMockCmd.class.getName());
41+
private static final String s_name = "cleanupsimulatormockresponse";
42+
43+
@Inject SimulatorManager _simMgr;
44+
45+
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="id of the configured mock")
46+
private Long id;
47+
48+
@Override
49+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
50+
boolean result = _simMgr.clearSimulatorMock(id);
51+
if (!result) {
52+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to cleanup mock");
53+
}
54+
55+
SuccessResponse response = new SuccessResponse(getCommandName());
56+
this.setResponseObject(response);
57+
}
58+
59+
@Override
60+
public String getCommandName() {
61+
return s_name;
62+
}
63+
64+
@Override
65+
public long getEntityOwnerId() {
66+
return Account.ACCOUNT_ID_SYSTEM;
67+
}
68+
69+
}

‎plugins/hypervisors/simulator/src/com/cloud/api/commands/ConfigureSimulatorCmd.java‎

100755100644
Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,27 @@
1919
import javax.inject.Inject;
2020

2121
import org.apache.log4j.Logger;
22-
2322
import org.apache.cloudstack.api.APICommand;
2423
import org.apache.cloudstack.api.ApiConstants;
2524
import org.apache.cloudstack.api.ApiErrorCode;
2625
import org.apache.cloudstack.api.BaseCmd;
2726
import org.apache.cloudstack.api.Parameter;
2827
import org.apache.cloudstack.api.ServerApiException;
29-
import org.apache.cloudstack.api.response.SuccessResponse;
28+
import org.apache.cloudstack.api.response.ClusterResponse;
29+
import org.apache.cloudstack.api.response.HostResponse;
30+
import org.apache.cloudstack.api.response.PodResponse;
31+
import org.apache.cloudstack.api.response.ZoneResponse;
3032

3133
import com.cloud.agent.manager.SimulatorManager;
34+
import com.cloud.api.response.MockResponse;
3235
import com.cloud.exception.ConcurrentOperationException;
3336
import com.cloud.exception.InsufficientCapacityException;
3437
import com.cloud.exception.ResourceAllocationException;
3538
import com.cloud.exception.ResourceUnavailableException;
39+
import com.cloud.simulator.MockConfigurationVO;
3640
import com.cloud.user.Account;
3741

38-
@APICommand(name = "configureSimulator", description = "configure simulator", responseObject = SuccessResponse.class,
42+
@APICommand(name = "configureSimulator", description = "configure simulator", responseObject = MockResponse.class,
3943
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
4044
public class ConfigureSimulatorCmd extends BaseCmd {
4145
public static final Logger s_logger = Logger.getLogger(ConfigureSimulatorCmd.class.getName());
@@ -44,16 +48,16 @@ public class ConfigureSimulatorCmd extends BaseCmd {
4448
@Inject
4549
SimulatorManager _simMgr;
4650

47-
@Parameter(name = ApiConstants.ZONE_ID, type = CommandType.LONG, description = "configure range: in a zone")
51+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType=ZoneResponse.class, description="configure range: in a zone")
4852
private Long zoneId;
4953

50-
@Parameter(name = ApiConstants.POD_ID, type = CommandType.LONG, description = "configure range: in a pod")
54+
@Parameter(name=ApiConstants.POD_ID, type=CommandType.UUID, entityType=PodResponse.class, description="configure range: in a pod")
5155
private Long podId;
5256

53-
@Parameter(name = ApiConstants.CLUSTER_ID, type = CommandType.LONG, description = "configure range: in a cluster")
57+
@Parameter(name=ApiConstants.CLUSTER_ID, type=CommandType.UUID, entityType=ClusterResponse.class, description="configure range: in a cluster")
5458
private Long clusterId;
5559

56-
@Parameter(name = ApiConstants.HOST_ID, type = CommandType.LONG, description = "configure range: in a host")
60+
@Parameter(name=ApiConstants.HOST_ID, type=CommandType.UUID, entityType=HostResponse.class, description="configure range: in a host")
5761
private Long hostId;
5862

5963
@Parameter(name = ApiConstants.NAME, type = CommandType.STRING, required = true, description = "which command needs to be configured")
@@ -62,15 +66,34 @@ public class ConfigureSimulatorCmd extends BaseCmd {
6266
@Parameter(name = ApiConstants.VALUE, type = CommandType.STRING, required = true, description = "configuration options for this command, which is seperated by ;")
6367
private String values;
6468

69+
@Parameter(name=ApiConstants.COUNT, type=CommandType.INTEGER, description="number of times the mock is active")
70+
private Integer count;
71+
72+
@Parameter(name="jsonresponse", type=CommandType.STRING, description="agent command response to be returned")
73+
private String jsonResponse;
74+
6575
@Override
6676
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException,
6777
ResourceAllocationException {
68-
boolean result = _simMgr.configureSimulator(zoneId, podId, clusterId, hostId, command, values);
69-
if (!result) {
78+
Long id = _simMgr.configureSimulator(zoneId, podId, clusterId, hostId, command, values, count, jsonResponse);
79+
if (id == null) {
7080
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure simulator");
7181
}
7282

73-
SuccessResponse response = new SuccessResponse(getCommandName());
83+
MockConfigurationVO config = _simMgr.querySimulatorMock(id);
84+
if (config == null) {
85+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to query simulator mock");
86+
}
87+
88+
MockResponse response = new MockResponse();
89+
response.setId(config.getId());
90+
response.setZoneId(config.getDataCenterId());
91+
response.setPodId(config.getPodId());
92+
response.setClusterId(config.getClusterId());
93+
response.setHostId(config.getHostId());
94+
response.setName(config.getName());
95+
response.setCount(config.getCount());
96+
response.setResponseName("simulatormock");
7497
this.setResponseObject(response);
7598
}
7699

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
package com.cloud.api.commands;
18+
19+
import com.cloud.agent.manager.SimulatorManager;
20+
import com.cloud.api.response.MockResponse;
21+
import com.cloud.exception.ConcurrentOperationException;
22+
import com.cloud.exception.InsufficientCapacityException;
23+
import com.cloud.exception.ResourceAllocationException;
24+
import com.cloud.exception.ResourceUnavailableException;
25+
import com.cloud.simulator.MockConfigurationVO;
26+
import com.cloud.user.Account;
27+
28+
import org.apache.cloudstack.api.APICommand;
29+
import org.apache.cloudstack.api.ApiConstants;
30+
import org.apache.cloudstack.api.ApiErrorCode;
31+
import org.apache.cloudstack.api.BaseCmd;
32+
import org.apache.cloudstack.api.Parameter;
33+
import org.apache.cloudstack.api.ServerApiException;
34+
import org.apache.log4j.Logger;
35+
36+
import javax.inject.Inject;
37+
38+
39+
@APICommand(name = "querySimulatorMock", description="query simulator mock", responseObject=MockResponse.class)
40+
public class QuerySimulatorMockCmd extends BaseCmd {
41+
public static final Logger s_logger = Logger.getLogger(QuerySimulatorMockCmd.class.getName());
42+
private static final String s_name = "querysimulatormockresponse";
43+
44+
@Inject SimulatorManager _simMgr;
45+
46+
@Parameter(name=ApiConstants.ID, type=CommandType.LONG, description="id of the configured mock")
47+
private Long id;
48+
49+
@Override
50+
public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException {
51+
MockConfigurationVO config = _simMgr.querySimulatorMock(id);
52+
if (config == null) {
53+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to query mock");
54+
}
55+
56+
MockResponse response = new MockResponse();
57+
response.setId(config.getId());
58+
response.setZoneId(config.getDataCenterId());
59+
response.setPodId(config.getPodId());
60+
response.setClusterId(config.getClusterId());
61+
response.setHostId(config.getHostId());
62+
response.setName(config.getName());
63+
response.setCount(config.getCount());
64+
response.setResponseName("simulatormock");
65+
this.setResponseObject(response);
66+
}
67+
68+
@Override
69+
public String getCommandName() {
70+
return s_name;
71+
}
72+
73+
@Override
74+
public long getEntityOwnerId() {
75+
return Account.ACCOUNT_ID_SYSTEM;
76+
}
77+
78+
}

0 commit comments

Comments
 (0)