@Test public void invalidTypesTest() throws URISyntaxException { final String uri1 = "https://1"; final String uri2 = "bla:0"; final BroadcastDomainType type = BroadcastDomainType.getTypeOf(uri1); try { /* URI result = */ BroadcastDomainType.fromString(uri1); } catch (final CloudRuntimeException e) { Assert.assertEquals("unexpected parameter exception", "string 'https://1' has an unknown BroadcastDomainType.", e.getMessage()); } try { /* URI result = */ BroadcastDomainType.fromString(uri2); } catch (final CloudRuntimeException e) { Assert.assertEquals("unexpected parameter exception", "string 'bla:0' has an unknown BroadcastDomainType.", e.getMessage()); } } }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { try { final List<Host> devices = nwDeviceMgr.listNetworkDevice(this); final List<NetworkDeviceResponse> nwdeviceResponses = new ArrayList<>(); final ListResponse<NetworkDeviceResponse> listResponse = new ListResponse<>(); for (final Host d : devices) { final NetworkDeviceResponse response = nwDeviceMgr.getApiResponse(d); response.setObjectName("networkdevice"); response.setResponseName(getCommandName()); nwdeviceResponses.add(response); } listResponse.setResponses(nwdeviceResponses); listResponse.setResponseName(getCommandName()); this.setResponseObject(listResponse); } catch (final InvalidParameterValueException ipve) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); } catch (final CloudRuntimeException cre) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); } }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { try { final Host device = nwDeviceMgr.addNetworkDevice(this); final NetworkDeviceResponse response = nwDeviceMgr.getApiResponse(device); response.setObjectName("networkdevice"); response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (final InvalidParameterValueException ipve) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); } catch (final CloudRuntimeException cre) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); } }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException { try { final boolean result = nwDeviceMgr.deleteNetworkDevice(this); if (result) { final SuccessResponse response = new SuccessResponse(getCommandName()); response.setResponseName(getCommandName()); this.setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete network device:" + getId()); } } catch (final InvalidParameterValueException ipve) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); } catch (final CloudRuntimeException cre) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); } }
@Override public void execute() throws ResourceUnavailableException, ConcurrentOperationException { CallContext.current().setEventDetails("Vm Id: " + getId()); try { final UserVm result = _userVmService.expungeVm(this.getId()); if (result != null) { final SuccessResponse response = new SuccessResponse(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to expunge vm"); } } catch (final InvalidParameterValueException ipve) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage()); } catch (final CloudRuntimeException cre) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage()); } }