@Override public void create() { try { final HealthCheckPolicy result = _lbService.createLBHealthCheckPolicy(this); this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (final InvalidParameterValueException e) { s_logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, e.getMessage()); } }
@Override public void execute() throws ResourceAllocationException { Volume volume = null; try { CallContext.current().setEventDetails("Volume Id: " + getEntityId() + " to size " + getSize() + "G"); volume = _volumeService.resizeVolume(this); } catch (final InvalidParameterValueException ex) { s_logger.info(ex.getMessage()); throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage()); } if (volume != null) { final VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Restricted, volume); //FIXME - have to be moved to ApiResponseHelper response.setResponseName(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to resize volume"); } }
@Override public void execute() throws ResourceAllocationException { Volume volume = null; try { CallContext.current().setEventDetails("Volume Id: " + getEntityId() + " to size " + getSize() + "G"); volume = _volumeService.resizeVolume(this); } catch (final InvalidParameterValueException ex) { s_logger.info(ex.getMessage()); throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage()); } if (volume != null) { final VolumeResponse response = _responseGenerator.createVolumeResponse(ResponseView.Full, volume); //FIXME - have to be moved to ApiResponseHelper response.setResponseName(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to resize volume"); } } }
@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()); } }
@Test public void testExecuteForNullResult() { updateHostPasswordCmd._mgr = managementServer; updateHostPasswordCmd._resourceService = resourceService; try { Mockito.when(managementServer.updateHostPassword(updateHostPasswordCmd)).thenReturn(false); } catch (final InvalidParameterValueException e) { fail(e.getMessage()); } catch (final IllegalArgumentException e) { fail(e.getMessage()); } try { updateHostPasswordCmd.execute(); } catch (final ServerApiException exception) { Assert.assertEquals("Failed to update config", exception.getDescription()); } assertFalse("The attribute updatePasswdOnHost should be false, but it isn't.", updateHostPasswordCmd.getUpdatePasswdOnHost()); verify(managementServer, times(1)).updateHostPassword(updateHostPasswordCmd); }
@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()); } }
@Override public void create() { //cidr list parameter is deprecated if (cidrlist != null) { throw new InvalidParameterValueException( "Parameter cidrList is deprecated; if you need to open firewall rule for the specific CIDR, please refer to createFirewallRule command"); } if (lbProtocol != null && !lbProtocol.toLowerCase().startsWith("tcp")) { throw new InvalidParameterValueException( "Only TCP protocol is supported because HAProxy can only do TCP."); } try { final LoadBalancer result = _lbService.createPublicLoadBalancerRule(getXid(), getName(), getDescription(), getSourcePortStart(), getSourcePortEnd(), getDefaultPortStart(), getDefaultPortEnd(), getSourceIpAddressId(), getProtocol(), getAlgorithm(), getNetworkId(), getEntityOwnerId(), getOpenFirewall(), getLbProtocol(), isDisplay(), getClientTimeout(), getServerTimeout()); this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (final NetworkRuleConflictException e) { s_logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.NETWORK_RULE_CONFLICT_ERROR, e.getMessage()); } catch (final InsufficientAddressCapacityException e) { s_logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, e.getMessage()); } catch (final InvalidParameterValueException e) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage()); } }