Skip to content

Commit c05edc4

Browse files
Updated invalid parameter/value to com.cloud.exception.InvalidParameterValueException (#9455)
1 parent 70131be commit c05edc4

15 files changed

Lines changed: 72 additions & 85 deletions

File tree

api/src/main/java/org/apache/cloudstack/api/command/user/vm/GetVMPasswordCmd.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.vm;
1818

19-
import java.security.InvalidParameterException;
20-
21-
2219
import org.apache.cloudstack.acl.SecurityChecker.AccessType;
2320
import org.apache.cloudstack.api.ACL;
2421
import org.apache.cloudstack.api.APICommand;
@@ -28,6 +25,7 @@
2825
import org.apache.cloudstack.api.response.GetVMPasswordResponse;
2926
import org.apache.cloudstack.api.response.UserVmResponse;
3027

28+
import com.cloud.exception.InvalidParameterValueException;
3129
import com.cloud.user.Account;
3230
import com.cloud.uservm.UserVm;
3331
import com.cloud.vm.VirtualMachine;
@@ -61,7 +59,7 @@ public Long getId() {
6159
public void execute() {
6260
String passwd = _mgr.getVMPassword(this);
6361
if (passwd == null || passwd.equals(""))
64-
throw new InvalidParameterException("No password for VM with id '" + getId() + "' found.");
62+
throw new InvalidParameterValueException("No password for VM with id '" + getId() + "' found.");
6563

6664
setResponseObject(new GetVMPasswordResponse(getCommandName(), passwd));
6765
}

api/src/test/java/org/apache/cloudstack/api/command/user/vm/CreateVMScheduleCmdTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import org.mockito.Mockito;
3333
import org.mockito.MockitoAnnotations;
3434

35-
import java.security.InvalidParameterException;
36-
3735
public class CreateVMScheduleCmdTest {
3836
@Mock
3937
public VMScheduleManager vmScheduleManager;
@@ -70,11 +68,11 @@ public void testSuccessfulExecution() {
7068
/**
7169
* given: "We have a VMScheduleManager and CreateVMScheduleCmd"
7270
* when: "CreateVMScheduleCmd is executed with an invalid parameter"
73-
* then: "an InvalidParameterException is thrown"
71+
* then: "an InvalidParameterValueException is thrown"
7472
*/
75-
@Test(expected = InvalidParameterException.class)
76-
public void testInvalidParameterException() {
77-
Mockito.when(vmScheduleManager.createSchedule(createVMScheduleCmd)).thenThrow(InvalidParameterException.class);
73+
@Test(expected = InvalidParameterValueException.class)
74+
public void testInvalidParameterValueException() {
75+
Mockito.when(vmScheduleManager.createSchedule(createVMScheduleCmd)).thenThrow(InvalidParameterValueException.class);
7876
createVMScheduleCmd.execute();
7977
}
8078

@@ -94,7 +92,7 @@ public void testSuccessfulGetEntityOwnerId() {
9492
/**
9593
* given: "We have an EntityManager and CreateVMScheduleCmd"
9694
* when: "CreateVMScheduleCmd.getEntityOwnerId is executed for a VM which doesn't exist"
97-
* then: "an InvalidParameterException is thrown"
95+
* then: "an InvalidParameterValueException is thrown"
9896
*/
9997
@Test(expected = InvalidParameterValueException.class)
10098
public void testFailureGetEntityOwnerId() {

api/src/test/java/org/apache/cloudstack/api/command/user/vm/DeleteVMScheduleCmdTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import org.mockito.Mockito;
3535
import org.mockito.MockitoAnnotations;
3636

37-
import java.security.InvalidParameterException;
38-
3937
public class DeleteVMScheduleCmdTest {
4038
@Mock
4139
public VMScheduleManager vmScheduleManager;
@@ -89,11 +87,11 @@ public void testServerApiException() {
8987
/**
9088
* given: "We have a VMScheduleManager and DeleteVMScheduleCmd"
9189
* when: "DeleteVMScheduleCmd is executed with an invalid parameter"
92-
* then: "an InvalidParameterException is thrown"
90+
* then: "an InvalidParameterValueException is thrown"
9391
*/
94-
@Test(expected = InvalidParameterException.class)
95-
public void testInvalidParameterException() {
96-
Mockito.when(vmScheduleManager.removeSchedule(deleteVMScheduleCmd)).thenThrow(InvalidParameterException.class);
92+
@Test(expected = InvalidParameterValueException.class)
93+
public void testInvalidParameterValueException() {
94+
Mockito.when(vmScheduleManager.removeSchedule(deleteVMScheduleCmd)).thenThrow(InvalidParameterValueException.class);
9795
deleteVMScheduleCmd.execute();
9896
}
9997

@@ -113,7 +111,7 @@ public void testSuccessfulGetEntityOwnerId() {
113111
/**
114112
* given: "We have an EntityManager and DeleteVMScheduleCmd"
115113
* when: "DeleteVMScheduleCmd.getEntityOwnerId is executed for a VM which doesn't exist"
116-
* then: "an InvalidParameterException is thrown"
114+
* then: "an InvalidParameterValueException is thrown"
117115
*/
118116
@Test(expected = InvalidParameterValueException.class)
119117
public void testFailureGetEntityOwnerId() {

api/src/test/java/org/apache/cloudstack/api/command/user/vm/ListVMScheduleCmdTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
*/
1919
package org.apache.cloudstack.api.command.user.vm;
2020

21+
import com.cloud.exception.InvalidParameterValueException;
2122
import org.apache.cloudstack.api.response.ListResponse;
2223
import org.apache.cloudstack.api.response.VMScheduleResponse;
2324
import org.apache.cloudstack.vm.schedule.VMScheduleManager;
@@ -30,7 +31,6 @@
3031
import org.mockito.Mockito;
3132
import org.mockito.MockitoAnnotations;
3233

33-
import java.security.InvalidParameterException;
3434
import java.util.ArrayList;
3535
import java.util.Collections;
3636

@@ -88,11 +88,11 @@ public void testNonEmptyResponse() {
8888
/**
8989
* given: "We have a VMScheduleManager and ListVMScheduleCmd"
9090
* when: "ListVMScheduleCmd is executed with an invalid parameter"
91-
* then: "an InvalidParameterException is thrown"
91+
* then: "an InvalidParameterValueException is thrown"
9292
*/
93-
@Test(expected = InvalidParameterException.class)
94-
public void testInvalidParameterException() {
95-
Mockito.when(vmScheduleManager.listSchedule(listVMScheduleCmd)).thenThrow(InvalidParameterException.class);
93+
@Test(expected = InvalidParameterValueException.class)
94+
public void testInvalidParameterValueException() {
95+
Mockito.when(vmScheduleManager.listSchedule(listVMScheduleCmd)).thenThrow(InvalidParameterValueException.class);
9696
listVMScheduleCmd.execute();
9797
ListResponse<VMScheduleResponse> actualResponseObject = (ListResponse<VMScheduleResponse>) listVMScheduleCmd.getResponseObject();
9898
}

api/src/test/java/org/apache/cloudstack/api/command/user/vm/UpdateVMScheduleCmdTest.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@
3333
import org.mockito.Mockito;
3434
import org.mockito.MockitoAnnotations;
3535

36-
import java.security.InvalidParameterException;
37-
3836
public class UpdateVMScheduleCmdTest {
3937
@Mock
4038
public VMScheduleManager vmScheduleManager;
@@ -71,11 +69,11 @@ public void testSuccessfulExecution() {
7169
/**
7270
* given: "We have a VMScheduleManager and UpdateVMScheduleCmd"
7371
* when: "UpdateVMScheduleCmd is executed with an invalid parameter"
74-
* then: "an InvalidParameterException is thrown"
72+
* then: "an InvalidParameterValueException is thrown"
7573
*/
76-
@Test(expected = InvalidParameterException.class)
77-
public void testInvalidParameterException() {
78-
Mockito.when(vmScheduleManager.updateSchedule(updateVMScheduleCmd)).thenThrow(InvalidParameterException.class);
74+
@Test(expected = InvalidParameterValueException.class)
75+
public void testInvalidParameterValueException() {
76+
Mockito.when(vmScheduleManager.updateSchedule(updateVMScheduleCmd)).thenThrow(InvalidParameterValueException.class);
7977
updateVMScheduleCmd.execute();
8078
}
8179

@@ -99,7 +97,7 @@ public void testSuccessfulGetEntityOwnerId() {
9997
/**
10098
* given: "We have an EntityManager and UpdateVMScheduleCmd"
10199
* when: "UpdateVMScheduleCmd.getEntityOwnerId is executed for a VM Schedule which doesn't exist"
102-
* then: "an InvalidParameterException is thrown"
100+
* then: "an InvalidParameterValueException is thrown"
103101
*/
104102
@Test(expected = InvalidParameterValueException.class)
105103
public void testFailureGetEntityOwnerId() {

plugins/hypervisors/kvm/src/main/java/org/apache/cloudstack/kvm/ha/KVMHAProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
package org.apache.cloudstack.kvm.ha;
2121

22+
import com.cloud.exception.InvalidParameterValueException;
2223
import com.cloud.host.Host;
2324
import com.cloud.hypervisor.Hypervisor;
2425

@@ -36,7 +37,6 @@
3637
import org.joda.time.DateTime;
3738

3839
import javax.inject.Inject;
39-
import java.security.InvalidParameterException;
4040

4141
public final class KVMHAProvider extends HAAbstractHostProvider implements HAProvider<Host>, Configurable {
4242

@@ -129,7 +129,7 @@ public Object getConfigValue(final HAProviderConfig name, final Host host) {
129129
case MaxDegradedWaitTimeout:
130130
return KVMHAConfig.KvmHADegradedMaxPeriod.valueIn(clusterId);
131131
default:
132-
throw new InvalidParameterException("Unknown HAProviderConfig " + name.toString());
132+
throw new InvalidParameterValueException("Unknown HAProviderConfig " + name.toString());
133133
}
134134
}
135135

plugins/hypervisors/simulator/src/main/java/org/apache/cloudstack/ha/SimulatorHAProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.apache.cloudstack.ha;
1919

2020
import com.cloud.api.response.SimulatorHAStateResponse;
21+
import com.cloud.exception.InvalidParameterValueException;
2122
import com.cloud.host.Host;
2223
import com.cloud.hypervisor.Hypervisor;
2324
import com.cloud.utils.fsm.StateListener;
@@ -30,7 +31,6 @@
3031
import org.joda.time.DateTime;
3132

3233
import javax.inject.Inject;
33-
import java.security.InvalidParameterException;
3434
import java.util.Collections;
3535
import java.util.List;
3636
import java.util.Map;
@@ -129,7 +129,7 @@ public Object getConfigValue(final HAProvider.HAProviderConfig name, final Host
129129
case RecoveryWaitTimeout:
130130
return 1L;
131131
default:
132-
throw new InvalidParameterException("Unknown HAProviderConfig " + name.toString());
132+
throw new InvalidParameterValueException("Unknown HAProviderConfig " + name.toString());
133133
}
134134
}
135135

plugins/integrations/kubernetes-service/src/main/java/org/apache/cloudstack/api/command/user/kubernetes/cluster/CreateKubernetesClusterCmd.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.user.kubernetes.cluster;
1818

19-
import java.security.InvalidParameterException;
20-
2119
import javax.inject.Inject;
2220

2321
import com.cloud.exception.InvalidParameterValueException;
@@ -227,7 +225,7 @@ public String getDockerRegistryUrl() {
227225
public Long getNodeRootDiskSize() {
228226
if (nodeRootDiskSize != null) {
229227
if (nodeRootDiskSize < DEFAULT_NODE_ROOT_DISK_SIZE) {
230-
throw new InvalidParameterException("Provided node root disk size is lesser than default size of " + DEFAULT_NODE_ROOT_DISK_SIZE +"GB");
228+
throw new InvalidParameterValueException("Provided node root disk size is lesser than default size of " + DEFAULT_NODE_ROOT_DISK_SIZE +"GB");
231229
}
232230
return nodeRootDiskSize;
233231
} else {

plugins/network-elements/opendaylight/src/main/java/org/apache/cloudstack/network/opendaylight/agent/OpenDaylightControllerResource.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import java.net.MalformedURLException;
2323
import java.net.URL;
24-
import java.security.InvalidParameterException;
2524
import java.util.Collections;
2625
import java.util.HashMap;
2726
import java.util.Map;
@@ -69,6 +68,7 @@
6968
import com.cloud.agent.api.StartupCommand;
7069
import com.cloud.host.Host;
7170
import com.cloud.host.Host.Type;
71+
import com.cloud.exception.InvalidParameterValueException;
7272
import com.cloud.resource.ServerResource;
7373

7474
public class OpenDaylightControllerResource implements ServerResource {
@@ -332,11 +332,11 @@ private Answer executeRequest(AddHypervisorCommand cmd) {
332332

333333
private void updateConfiguration() {
334334
if (!configuration.containsKey("url") || !configuration.containsKey("username") || !configuration.containsKey("password"))
335-
throw new InvalidParameterException("OpenDaylightControllerResource needs a url, username and password.");
335+
throw new InvalidParameterValueException("OpenDaylightControllerResource needs a url, username and password.");
336336
try {
337337
controllerUrl = new URL((String)configuration.get("url"));
338338
} catch (MalformedURLException e) {
339-
throw new InvalidParameterException("OpenDaylightControllerResource found an invalid controller url");
339+
throw new InvalidParameterValueException("OpenDaylightControllerResource found an invalid controller url");
340340
}
341341
controllerUsername = (String)configuration.get("username");
342342
controllerPassword = (String)configuration.get("password");

plugins/network-elements/tungsten/src/main/java/org/apache/cloudstack/network/tungsten/service/TungstenServiceImpl.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.cloud.domain.Domain;
3333
import com.cloud.domain.DomainVO;
3434
import com.cloud.domain.dao.DomainDao;
35+
import com.cloud.exception.InvalidParameterValueException;
3536
import com.cloud.exception.ResourceUnavailableException;
3637
import com.cloud.host.Host;
3738
import com.cloud.host.HostVO;
@@ -219,7 +220,6 @@
219220
import java.io.UnsupportedEncodingException;
220221
import java.net.URLEncoder;
221222
import java.nio.charset.StandardCharsets;
222-
import java.security.InvalidParameterException;
223223
import java.util.ArrayList;
224224
import java.util.List;
225225
import java.util.Objects;
@@ -2466,7 +2466,7 @@ public boolean applyLBHealthMonitor(final long lbId) {
24662466
boolean success = true;
24672467
LoadBalancerVO loadBalancer = loadBalancerDao.findById(lbId);
24682468
if (loadBalancer == null) {
2469-
throw new InvalidParameterException("Invalid Load balancer Id:" + lbId);
2469+
throw new InvalidParameterValueException("Invalid Load balancer Id:" + lbId);
24702470
}
24712471

24722472
if (loadBalancer.getState() == FirewallRule.State.Active) {

0 commit comments

Comments
 (0)