private void throwInvalidIdException(String message, String uuid, String description) { InvalidParameterValueException ex = new InvalidParameterValueException(message); ex.addProxyObject(uuid, description); throw ex; }
@Override public void execute() { try { UserVm userVm = _userVmService.moveVMToUser(this); if (userVm == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm"); } UserVmResponse response = _responseGenerator.createUserVmResponse(ResponseView.Full, "virtualmachine", userVm).get(0); response.setResponseName(getCommandName()); setResponseObject(response); } catch (InvalidParameterValueException e){ e.printStackTrace(); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } catch (Exception e) { e.printStackTrace(); throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to move vm " + e.getMessage()); } }
public boolean validateVolumeSizeRange(long size) { if (size < 0 || (size > 0 && size < (1024 * 1024 * 1024))) { throw new InvalidParameterValueException("Please specify a size of at least 1 GB."); } else if (size > (_maxVolumeSizeInGb * 1024 * 1024 * 1024)) { throw new InvalidParameterValueException("Requested volume size is " + size + ", but the maximum size allowed is " + _maxVolumeSizeInGb + " GB."); } return true; }
@Override public void create() { try { HealthCheckPolicy result = _lbService.createLBHealthCheckPolicy(this); this.setEntityId(result.getId()); this.setEntityUuid(result.getUuid()); } catch (InvalidParameterValueException e) { s_logger.warn("Exception: ", e); throw new ServerApiException(ApiErrorCode.MALFORMED_PARAMETER_ERROR, e.getMessage()); } }
@Test public void testExecuteForDiscoveryException() { addHostCmd._resourceService = resourceService; try { Mockito.when(resourceService.discoverHosts(addHostCmd)).thenThrow(DiscoveryException.class); } catch (InvalidParameterValueException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (DiscoveryException e) { e.printStackTrace(); } try { addHostCmd.execute(); } catch (ServerApiException exception) { Assert.assertNull(exception.getDescription()); } }
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 { Map<String,Object> resp = _netsclarLbService.deployNetscalerServiceVm(this); if (resp.size() > 0) { SystemVmResponse response = _responseGenerator.createSystemVmResponse((VirtualMachine)resp.get("vm")); response.setGuestVlan((String)resp.get("guestvlan")); response.setPublicVlan((List<String>)resp.get("publicvlan")); response.setResponseName(getCommandName()); setResponseObject(response); } else { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Fail to start system vm"); } } catch (InvalidParameterValueException invalidParamExcp) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException runtimeExcp) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage()); } }
@Test public void testExecuteForNullResult() { ResourceService resourceService = Mockito.mock(ResourceService.class); addHostCmd._resourceService = resourceService; try { Mockito.when(resourceService.discoverHosts(addHostCmd)).thenReturn(null); } catch (InvalidParameterValueException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DiscoveryException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { addHostCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to add host", exception.getDescription()); } }
void verifyTemplateId(Long id) { // Don't allow to modify system template if (id.equals(Long.valueOf(1))) { InvalidParameterValueException ex = new InvalidParameterValueException("Unable to update template/iso of specified id"); ex.addProxyObject(String.valueOf(id), "templateId"); throw ex; } }
/** * Validates the network ACL rule action given as a {@link String}. * If the parameter is null, we do not perform any validations. Otherwise, we check if the parameter is equal to 'Allow' or 'Deny' (ignoring the case). * If the parameter is an invalid action, we throw an {@link InvalidParameterValueException}. */ protected void validateNetworkAclRuleAction(String action) { if (action != null) { if (!("Allow".equalsIgnoreCase(action) || "Deny".equalsIgnoreCase(action))) { throw new InvalidParameterValueException(String.format("Invalid action [%s]. Permitted actions are Allow and Deny", action)); } } }
@Override public void execute() throws ResourceAllocationException { Volume volume = null; try { CallContext.current().setEventDetails("Volume Id: " + this._uuidMgr.getUuid(Volume.class, getEntityId()) + " to size " + getSize() + "G"); volume = _volumeService.resizeVolume(this); } catch (InvalidParameterValueException ex) { s_logger.info(ex.getMessage()); throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, ex.getMessage()); } if (volume != null) { 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 testExecuteForNullResult() { updateCfgCmd._configService = configService; updateCfgCmd.setCfgName("some.cfg"); try { Mockito.when(configService.updateConfiguration(updateCfgCmd)).thenReturn(null); } catch (InvalidParameterValueException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } try { updateCfgCmd.execute(); } catch (ServerApiException exception) { Assert.assertEquals("Failed to update config", exception.getDescription()); } }
@Override public HypervisorType getHypervisorTypeOfUserVM(long vmId) { UserVmVO userVm = _vmDao.findById(vmId); if (userVm == null) { InvalidParameterValueException ex = new InvalidParameterValueException("unable to find a virtual machine with specified id"); ex.addProxyObject(String.valueOf(vmId), "vmId"); throw ex; } return userVm.getHypervisorType(); }
@Override public EngineHostVO loadHost(String uuid) { EngineHostVO host = _hostDao.findByUuid(uuid); if (host == null) { throw new InvalidParameterValueException("Host does not exist"); } return host; }
@Test public void testValidateRuleWithInvalidData() throws Exception { for (String rule : Arrays.asList(null, "", " ", " ", "\n", "\t", "\r", "\"", "\'", "^someApi$", "^someApi", "some$", "some-Api;", "some,Api", "^", "$", "^$", ".*", "\\w+", "r**l3rd0@Kr3", "j@s1n|+|0È·", "[a-z0-9-]+", "^([a-z0-9_\\.-]+)@([\\da-z\\.-]+)\\.([a-z\\.]{2,6})$")) { try { new Rule(rule); Assert.fail("Invalid rule, exception was expected"); } catch (InvalidParameterValueException e) { Assert.assertTrue(e.getMessage().startsWith("Only API names and wildcards are allowed")); } } } }
@Override public VirtualMachine.Type findSystemVMTypeById(final long instanceId) { final VMInstanceVO systemVm = _vmInstanceDao.findByIdTypes(instanceId, VirtualMachine.Type.ConsoleProxy, VirtualMachine.Type.SecondaryStorageVm); if (systemVm == null) { final InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find a system vm of specified instanceId"); ex.addProxyObject(String.valueOf(instanceId), "instanceId"); throw ex; } return systemVm.getType(); }
PhysicalNetwork getOnePhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType) { List<PhysicalNetworkVO> networkList = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, trafficType); if (networkList.isEmpty()) { throw new InvalidParameterValueException("Unable to find the default physical network with traffic=" + trafficType + " in zone id=" + zoneId + ". "); } if (networkList.size() > 1) { s_logger.info("More than one physical networks exist in zone id=" + zoneId + " with traffic type=" + trafficType + ". "); } return networkList.get(0); }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { try { List<NuageVspDomainTemplateResponse> responses = new LinkedList<>(); NuageVspDomainTemplateResponse answer = new NuageVspDomainTemplateResponse(_nuageVspManager.NuageVspVpcDomainTemplateName.value(),_nuageVspManager.NuageVspVpcDomainTemplateName.value()); responses.add(answer); ListResponse<NuageVspDomainTemplateResponse> response = new ListResponse<>(); response.setResponses(responses); response.setResponseName(getCommandName()); this.setResponseObject(response); } catch (InvalidParameterValueException invalidParamExcp) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage()); } catch (CloudRuntimeException e) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage()); } }
@Override public PhysicalNetwork getDefaultPhysicalNetworkByZoneAndTrafficType(long zoneId, TrafficType trafficType) { List<PhysicalNetworkVO> networkList = _physicalNetworkDao.listByZoneAndTrafficType(zoneId, trafficType); DataCenter dc = ApiDBUtils.findZoneById(zoneId); String dcUuid = String.valueOf(zoneId); if (dc != null) { dcUuid = dc.getUuid(); } if (networkList.isEmpty()) { InvalidParameterValueException ex = new InvalidParameterValueException("Unable to find the default physical network with traffic=" + trafficType + " in the specified zone id"); ex.addProxyObject(dcUuid, "zoneId"); throw ex; } if (networkList.size() > 1) { InvalidParameterValueException ex = new InvalidParameterValueException("More than one physical networks exist in zone id=" + zoneId + " with traffic type=" + trafficType); ex.addProxyObject(dcUuid, "zoneId"); throw ex; } return networkList.get(0); }
private IpAddress getIp() { IpAddress ip = _networkService.getIp(ipAddressId); if (ip == null) { throw new InvalidParameterValueException("Unable to find ip address by id " + ipAddressId); } return ip; }