@Test public void testSubnetIdMissing() throws Throwable { VmGetIpStepCmd command = getVmGetIpStepCmd(); step.createOrUpdateTransientResource(ResourceReserveStepCmd.VM_ID, "vm-id"); Operation operation = mock(Operation.class); VmService.State state = createVmServiceState(); for (VmService.NetworkInfo networkInfo : state.networkInfo.values()) { networkInfo.id = null; } doReturn(state).when(operation).getBody(any()); doReturn(operation).when(photonControllerXenonRestClient).get(anyString()); try { command.execute(); fail("Should have failed due to missing network id"); } catch (NullPointerException e) { assertThat(e.getMessage(), containsString("subnetId is not available")); } }
@Override protected void execute() throws ApiFeException, InterruptedException, RpcException { String vmId = (String) step.getTransientResource(ResourceReserveStepCmd.VM_ID); checkNotNull(vmId, "VM id is not available"); Map<String, VmService.NetworkInfo> networkInfoMap = getVmNetworkInfo(vmId); logger.info("VM {} requested to be connected to {} network(s)", vmId, networkInfoMap.size()); if (networkInfoMap.size() > 0) { for (VmService.NetworkInfo networkInfo : networkInfoMap.values()) { networkInfo.privateIpAddress = allocateIpToMac(networkInfo.id, vmId, networkInfo.macAddress); taskCommand.getPhotonControllerXenonRestClient().post( SubnetIPLeaseSyncTriggerService.SELF_LINK , SubnetIPLeaseSyncUtils.buildSubnetIPLeaseSyncState(networkInfo.id)); } updateVmNetworkInfo(vmId, networkInfoMap); } }
VmGetIpStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { String vmId = (String) step.getTransientResource(ResourceReserveStepCmd.VM_ID); checkNotNull(vmId, "VM id is not available"); Map<String, VmService.NetworkInfo> networkInfoMap = getVmNetworkInfo(vmId); logger.info("VM {} requested to be connected to {} network(s)", vmId, networkInfoMap.size()); if (networkInfoMap.size() > 0) { for (VmService.NetworkInfo networkInfo : networkInfoMap.values()) { networkInfo.privateIpAddress = allocateIpToMac(networkInfo.id, vmId, networkInfo.macAddress); taskCommand.getPhotonControllerXenonRestClient().post( SubnetIPLeaseSyncTriggerService.SELF_LINK , SubnetIPLeaseSyncUtils.buildSubnetIPLeaseSyncState(networkInfo.id)); } updateVmNetworkInfo(vmId, networkInfoMap); } } }
VmGetIpStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { String vmId = (String) step.getTransientResource(ResourceReserveStepCmd.VM_ID); checkNotNull(vmId, "VM id is not available"); Map<String, VmService.NetworkInfo> networkInfoMap = getVmNetworkInfo(vmId); logger.info("VM {} requested to be connected to {} network(s)", vmId, networkInfoMap.size()); if (networkInfoMap.size() > 0) { for (VmService.NetworkInfo networkInfo : networkInfoMap.values()) { networkInfo.privateIpAddress = allocateIpToMac(networkInfo.id, vmId, networkInfo.macAddress); taskCommand.getPhotonControllerXenonRestClient().post( SubnetIPLeaseSyncTriggerService.SELF_LINK , SubnetIPLeaseSyncUtils.buildSubnetIPLeaseSyncState(networkInfo.id)); } updateVmNetworkInfo(vmId, networkInfoMap); } } VmGetIpStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step); }
VmGetIpStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { String vmId = (String) step.getTransientResource(ResourceReserveStepCmd.VM_ID); checkNotNull(vmId, "VM id is not available"); Map<String, VmService.NetworkInfo> networkInfoMap = getVmNetworkInfo(vmId); logger.info("VM {} requested to be connected to {} network(s)", vmId, networkInfoMap.size()); if (networkInfoMap.size() > 0) { for (VmService.NetworkInfo networkInfo : networkInfoMap.values()) { networkInfo.privateIpAddress = allocateIpToMac(networkInfo.id, vmId, networkInfo.macAddress); taskCommand.getPhotonControllerXenonRestClient().post( SubnetIPLeaseSyncTriggerService.SELF_LINK , SubnetIPLeaseSyncUtils.buildSubnetIPLeaseSyncState(networkInfo.id)); } updateVmNetworkInfo(vmId, networkInfoMap); } } VmGetIpStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step);  }
VmGetIpStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { String vmId = (String) step.getTransientResource(ResourceReserveStepCmd.VM_ID); checkNotNull(vmId, "VM id is not available"); Map<String, VmService.NetworkInfo> networkInfoMap = getVmNetworkInfo(vmId); logger.info("VM {} requested to be connected to {} network(s)", vmId, networkInfoMap.size()); if (networkInfoMap.size() > 0) { for (VmService.NetworkInfo networkInfo : networkInfoMap.values()) { networkInfo.privateIpAddress = allocateIpToMac(networkInfo.id, vmId, networkInfo.macAddress); taskCommand.getPhotonControllerXenonRestClient().post( SubnetIPLeaseSyncTriggerService.SELF_LINK , SubnetIPLeaseSyncUtils.buildSubnetIPLeaseSyncState(networkInfo.id)); } updateVmNetworkInfo(vmId, networkInfoMap); } } VmGetIpStepCmd(TaskCommand taskCommand, StepBackend stepBackend, StepEntity step);   }