private void checkDeprecatedParameters() throws InvalidParameterValueException { if (gatewayId != null) { throw new InvalidParameterValueException("Parameter gatewayId is DEPRECATED, use vpcId and nextHop instead."); } }
@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()); } }
@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 long getEntityOwnerId() { final Project project = _projectService.getProject(getProjectId()); //verify input parameters if (project == null) { final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find project with specified ID"); ex.addProxyObject(getProjectId().toString(), "projectId"); throw ex; } return _projectService.getProjectOwner(getProjectId()).getId(); }
@Test public void testRemoveIpFromVmNicFailure() throws InsufficientAddressCapacityException { final NetworkService networkService = Mockito.mock(NetworkService.class); final RemoveIpFromVmNicCmd removeIpFromNic = Mockito.mock(RemoveIpFromVmNicCmd.class); Mockito.when(networkService.releaseSecondaryIpFromNic(Matchers.anyInt())).thenReturn(false); removeIpFromNic._networkService = networkService; successResponseGenerator = Mockito.mock(SuccessResponse.class); try { removeIpFromNic.execute(); } catch (final InvalidParameterValueException exception) { Assert.assertEquals("Failed to remove secondary ip address for the nic", exception.getLocalizedMessage()); } } }
@Test public void testExecuteForNullResult() { updateCfgCmd._configService = configService; try { Mockito.when(configService.updateConfiguration(updateCfgCmd)).thenReturn(null); } catch (final InvalidParameterValueException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { updateCfgCmd.execute(); } catch (final ServerApiException exception) { Assert.assertEquals("Failed to update config", exception.getDescription()); } }
@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"); } } }
@Test public void testGetEntityOwnerIdForNullProject() { final ProjectService projectService = Mockito.mock(ProjectService.class); Mockito.when(projectService.getProject(Matchers.anyLong())).thenReturn(null); activateProjectCmd._projectService = projectService; try { activateProjectCmd.getEntityOwnerId(); } catch (final InvalidParameterValueException exception) { Assert.assertEquals("Unable to find project by id 2", exception.getLocalizedMessage()); } }
@Test public void testExecuteForNullResult() { final ResourceService resourceService = Mockito.mock(ResourceService.class); addHostCmd._resourceService = resourceService; try { Mockito.when(resourceService.discoverHosts(addHostCmd)).thenReturn(null); } catch (final InvalidParameterValueException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (final DiscoveryException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { addHostCmd.execute(); } catch (final ServerApiException exception) { Assert.assertEquals("Failed to add host", exception.getDescription()); } }
public List<String> getSourceCidrList() { 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"); } return null; }
@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"); } }
/*** * * * * ***/ /* * @Test public void testGetEventDescriptionForAccount() { * * String result = addAccountToProjectCmd.getEventDescription(); String * expected = "Adding account accountName to project: 2"; * Assert.assertEquals(expected, result); * * } */ @Test public void testExecuteForNullAccountNameEmail() { try { addAccountToProjectCmd.execute(); } catch (final InvalidParameterValueException exception) { Assert.assertEquals("Either accountName or email is required", exception.getLocalizedMessage()); } }
@Test public void testExecuteForDiscoveryException() { addHostCmd._resourceService = resourceService; try { Mockito.when(resourceService.discoverHosts(addHostCmd)).thenThrow(DiscoveryException.class); } catch (final InvalidParameterValueException e) { e.printStackTrace(); } catch (final IllegalArgumentException e) { e.printStackTrace(); } catch (final DiscoveryException e) { e.printStackTrace(); } try { addHostCmd.execute(); } catch (final ServerApiException exception) { Assert.assertNull(exception.getDescription()); } } }
public List<String> getAccountNames() { if (accountNames != null && projectIds != null) { throw new InvalidParameterValueException("Accounts and projectIds can't be specified together"); } return accountNames; }
@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()); } }
public List<Long> getProjectIds() { if (accountNames != null && projectIds != null) { throw new InvalidParameterValueException("Accounts and projectIds can't be specified together"); } return projectIds; }
@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()); } }
private void checkDeprecatedParameters() throws InvalidParameterValueException { if (gatewayId != null) { throw new InvalidParameterValueException("Parameter gatewayId is DEPRECATED, use vpcId and nextHop instead."); } }
@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 List<String> getSourceCidrList() { 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"); } return null; }