Skip to content

Commit ca59720

Browse files
authored
vpc,event: fix events for createVpc (#9055)
Fixes #8496 * vpc,event: fix events for createVpc
1 parent edf7394 commit ca59720

4 files changed

Lines changed: 16 additions & 8 deletions

File tree

api/src/main/java/com/cloud/network/vpc/VpcService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ Pair<List<? extends Vpc>, Integer> listVpcs(Long id, String vpcName, String disp
132132
*/
133133
boolean startVpc(long vpcId, boolean destroyOnFailure) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
134134

135+
void startVpc(CreateVPCCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException;
136+
135137
/**
136138
* Shuts down the VPC which includes shutting down all VPC provider and rules cleanup on the backend
137139
*

api/src/main/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmd.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,11 +210,7 @@ public void create() throws ResourceAllocationException {
210210
public void execute() {
211211
Vpc vpc = null;
212212
try {
213-
if (isStart()) {
214-
_vpcService.startVpc(getEntityId(), true);
215-
} else {
216-
s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
217-
}
213+
_vpcService.startVpc(this);
218214
vpc = _entityMgr.findById(Vpc.class, getEntityId());
219215
} catch (ResourceUnavailableException ex) {
220216
s_logger.warn("Exception: ", ex);

api/src/test/java/org/apache/cloudstack/api/command/user/vpc/CreateVPCCmdTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,16 @@ public void testCreate() throws ResourceAllocationException {
167167

168168
@Test
169169
public void testExecute() throws ResourceUnavailableException, InsufficientCapacityException {
170-
ReflectionTestUtils.setField(cmd, "start", true);
171170
Vpc vpc = Mockito.mock(Vpc.class);
172171
VpcResponse response = Mockito.mock(VpcResponse.class);
173172

174173
ReflectionTestUtils.setField(cmd, "id", 1L);
175174
responseGenerator = Mockito.mock(ResponseGenerator.class);
176-
Mockito.when(_vpcService.startVpc(1L, true)).thenReturn(true);
175+
Mockito.doNothing().when(_vpcService).startVpc(cmd);
177176
Mockito.when(_entityMgr.findById(Mockito.eq(Vpc.class), Mockito.any(Long.class))).thenReturn(vpc);
178177
cmd._responseGenerator = responseGenerator;
179178
Mockito.when(responseGenerator.createVpcResponse(ResponseObject.ResponseView.Restricted, vpc)).thenReturn(response);
180179
cmd.execute();
181-
Mockito.verify(_vpcService, Mockito.times(1)).startVpc(Mockito.anyLong(), Mockito.anyBoolean());
180+
Mockito.verify(_vpcService, Mockito.times(1)).startVpc(cmd);
182181
}
183182
}

server/src/main/java/com/cloud/network/vpc/VpcManagerImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1677,6 +1677,17 @@ public boolean startVpc(final long vpcId, final boolean destroyOnFailure) throws
16771677
return result;
16781678
}
16791679

1680+
1681+
@Override
1682+
@ActionEvent(eventType = EventTypes.EVENT_VPC_CREATE, eventDescription = "creating vpc", async = true)
1683+
public void startVpc(final CreateVPCCmd cmd) throws ConcurrentOperationException, ResourceUnavailableException, InsufficientCapacityException {
1684+
if (!cmd.isStart()) {
1685+
s_logger.debug("Not starting VPC as " + ApiConstants.START + "=false was passed to the API");
1686+
return;
1687+
}
1688+
startVpc(cmd.getEntityId(), true);
1689+
}
1690+
16801691
protected boolean startVpc(final Vpc vpc, final DeployDestination dest, final ReservationContext context) throws ConcurrentOperationException, ResourceUnavailableException,
16811692
InsufficientCapacityException {
16821693
// deploy provider

0 commit comments

Comments
 (0)