@Test public void testVmNotFoundExceptionInNonErrorState() throws Exception { when(hostClient.getVmNetworks(vmId)).thenThrow(new VmNotFoundException("Error")); VmGetNetworksStepCmd command = getCommand(); try { command.execute(); fail("should have failed due to Internal exception"); } catch (InternalException ex) { } }
@Override protected void execute() throws ApiFeException, InterruptedException, RpcException { try { List<VmEntity> entityList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(entityList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = entityList.get(0); vmId = vm.getId(); Long timeout = (Long) step.getTransientResource(RETRY_TIMEOUT_KEY); Long startTime = System.currentTimeMillis(); GetVmNetworkResponse response = getVmNetworksOp(vm); while (timeout != null && timeout > 0 && !areMACsPresent(response)) { if (System.currentTimeMillis() - startTime > timeout) { throw new RuntimeException("MAC addresses were not allocated before timeout"); } Thread.sleep(pollInterval); response = getVmNetworksOp(vm); } if (timeout != null && response.getNetwork_info() != null && !response.getNetwork_info().isEmpty()) { List<VmService.NetworkInfo> vmNetworkInfo = convertAgentNetworkToVmNetwork(response.getNetwork_info()); if (vmNetworkInfo != null && !vmNetworkInfo.isEmpty()) { vmBackend.updateState(vm, vmNetworkInfo); } } VmNetworks vmNetworks = toApiRepresentation(response.getNetwork_info()); String networkProperties = objectMapper.writeValueAsString(vmNetworks); taskBackend.setTaskResourceProperties(taskCommand.getTask(), networkProperties); } catch (JsonProcessingException e) { throw new IllegalArgumentException(String.format("Error serializing resourceProperties for vm %s: %s", vmId, e.getMessage())); } catch (RpcException e) { logger.error("failed creating Get VM Networks task for vm {}", vmId, e); throw e; } }
VmGetNetworksStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { try { List<VmEntity> entityList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(entityList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = entityList.get(0); vmId = vm.getId(); Long timeout = (Long) step.getTransientResource(RETRY_TIMEOUT_KEY); Long startTime = System.currentTimeMillis(); GetVmNetworkResponse response = getVmNetworksOp(vm); while (timeout != null && timeout > 0 && !areMACsPresent(response)) { if (System.currentTimeMillis() - startTime > timeout) { throw new RuntimeException("MAC addresses were not allocated before timeout"); } Thread.sleep(pollInterval); response = getVmNetworksOp(vm); } if (timeout != null && response.getNetwork_info() != null && !response.getNetwork_info().isEmpty()) { List<VmService.NetworkInfo> vmNetworkInfo = convertAgentNetworkToVmNetwork(response.getNetwork_info()); if (vmNetworkInfo != null && !vmNetworkInfo.isEmpty()) { vmBackend.updateState(vm, vmNetworkInfo); } } VmNetworks vmNetworks = toApiRepresentation(response.getNetwork_info()); String networkProperties = objectMapper.writeValueAsString(vmNetworks); taskBackend.setTaskResourceProperties(taskCommand.getTask(), networkProperties); } catch (JsonProcessingException e) { throw new IllegalArgumentException(String.format("Error serializing resourceProperties for vm %s: %s", vmId, e.getMessage())); } catch (RpcException e) { logger.error("failed creating Get VM Networks task for vm {}", vmId, e); throw e; } } }
VmGetNetworksStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { try { List<VmEntity> entityList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(entityList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = entityList.get(0); vmId = vm.getId(); Long timeout = (Long) step.getTransientResource(RETRY_TIMEOUT_KEY); Long startTime = System.currentTimeMillis(); GetVmNetworkResponse response = getVmNetworksOp(vm); while (timeout != null && timeout > 0 && !areMACsPresent(response)) { if (System.currentTimeMillis() - startTime > timeout) { throw new RuntimeException("MAC addresses were not allocated before timeout"); } Thread.sleep(pollInterval); response = getVmNetworksOp(vm); } if (timeout != null && response.getNetwork_info() != null && !response.getNetwork_info().isEmpty()) { List<VmService.NetworkInfo> vmNetworkInfo = convertAgentNetworkToVmNetwork(response.getNetwork_info()); if (vmNetworkInfo != null && !vmNetworkInfo.isEmpty()) { vmBackend.updateState(vm, vmNetworkInfo); } } VmNetworks vmNetworks = toApiRepresentation(response.getNetwork_info()); String networkProperties = objectMapper.writeValueAsString(vmNetworks); taskBackend.setTaskResourceProperties(taskCommand.getTask(), networkProperties); } catch (JsonProcessingException e) { throw new IllegalArgumentException(String.format("Error serializing resourceProperties for vm %s: %s", vmId, e.getMessage())); } catch (RpcException e) { logger.error("failed creating Get VM Networks task for vm {}", vmId, e); throw e; } } VmGetNetworksStepCmd(TaskCommand taskCommand,
                              StepBackend stepBackend,
                              StepEntity step,
                              TaskBackend taskBackend,
                              NetworkBackend networkBackend,
                              VmBackend vmBackend,
                              NetworkHelper networkHelper); }
VmGetNetworksStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { try { List<VmEntity> entityList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(entityList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = entityList.get(0); vmId = vm.getId(); Long timeout = (Long) step.getTransientResource(RETRY_TIMEOUT_KEY); Long startTime = System.currentTimeMillis(); GetVmNetworkResponse response = getVmNetworksOp(vm); while (timeout != null && timeout > 0 && !areMACsPresent(response)) { if (System.currentTimeMillis() - startTime > timeout) { throw new RuntimeException("MAC addresses were not allocated before timeout"); } Thread.sleep(pollInterval); response = getVmNetworksOp(vm); } if (timeout != null && response.getNetwork_info() != null && !response.getNetwork_info().isEmpty()) { List<VmService.NetworkInfo> vmNetworkInfo = convertAgentNetworkToVmNetwork(response.getNetwork_info()); if (vmNetworkInfo != null && !vmNetworkInfo.isEmpty()) { vmBackend.updateState(vm, vmNetworkInfo); } } VmNetworks vmNetworks = toApiRepresentation(response.getNetwork_info()); String networkProperties = objectMapper.writeValueAsString(vmNetworks); taskBackend.setTaskResourceProperties(taskCommand.getTask(), networkProperties); } catch (JsonProcessingException e) { throw new IllegalArgumentException(String.format("Error serializing resourceProperties for vm %s: %s", vmId, e.getMessage())); } catch (RpcException e) { logger.error("failed creating Get VM Networks task for vm {}", vmId, e); throw e; } } VmGetNetworksStepCmd(TaskCommand taskCommand,
                              StepBackend stepBackend,
                              StepEntity step,
                              TaskBackend taskBackend,
                              NetworkBackend networkBackend,
                              VmBackend vmBackend,
                              NetworkHelper networkHelper);  }
VmGetNetworksStepCmd extends StepCommand { @Override protected void execute() throws ApiFeException, InterruptedException, RpcException { try { List<VmEntity> entityList = step.getTransientResourceEntities(Vm.KIND); Preconditions.checkArgument(entityList.size() == 1, "There should be only 1 VM referenced by step %s", step.getId()); VmEntity vm = entityList.get(0); vmId = vm.getId(); Long timeout = (Long) step.getTransientResource(RETRY_TIMEOUT_KEY); Long startTime = System.currentTimeMillis(); GetVmNetworkResponse response = getVmNetworksOp(vm); while (timeout != null && timeout > 0 && !areMACsPresent(response)) { if (System.currentTimeMillis() - startTime > timeout) { throw new RuntimeException("MAC addresses were not allocated before timeout"); } Thread.sleep(pollInterval); response = getVmNetworksOp(vm); } if (timeout != null && response.getNetwork_info() != null && !response.getNetwork_info().isEmpty()) { List<VmService.NetworkInfo> vmNetworkInfo = convertAgentNetworkToVmNetwork(response.getNetwork_info()); if (vmNetworkInfo != null && !vmNetworkInfo.isEmpty()) { vmBackend.updateState(vm, vmNetworkInfo); } } VmNetworks vmNetworks = toApiRepresentation(response.getNetwork_info()); String networkProperties = objectMapper.writeValueAsString(vmNetworks); taskBackend.setTaskResourceProperties(taskCommand.getTask(), networkProperties); } catch (JsonProcessingException e) { throw new IllegalArgumentException(String.format("Error serializing resourceProperties for vm %s: %s", vmId, e.getMessage())); } catch (RpcException e) { logger.error("failed creating Get VM Networks task for vm {}", vmId, e); throw e; } } VmGetNetworksStepCmd(TaskCommand taskCommand,
                              StepBackend stepBackend,
                              StepEntity step,
                              TaskBackend taskBackend,
                              NetworkBackend networkBackend,
                              VmBackend vmBackend,
                              NetworkHelper networkHelper);  static final String RETRY_TIMEOUT_KEY; static final long DEFAULT_POLL_INTERVAL; }