You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by mc...@apache.org on 2013/01/17 06:58:29 UTC
[11/16] Clean up ApiServer,
ApiServlet and ApiDispatcher in handling various exceptions,
and Introduced ApiErrorCode to handle CloudStack API error code to standard
Http code mapping.
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java
index 8b53d70..c1ab22d 100644
--- a/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java
+++ b/plugins/network-elements/f5/src/com/cloud/api/commands/DeleteF5LoadBalancerCmd.java
@@ -22,6 +22,7 @@ import org.apache.log4j.Logger;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter;
@@ -74,12 +75,12 @@ public class DeleteF5LoadBalancerCmd extends BaseAsyncCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete F5 load balancer.");
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete F5 load balancer.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java
index bf1164b..1d276ce 100644
--- a/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java
+++ b/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancerNetworksCmd.java
@@ -23,6 +23,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.APICommand;
@@ -86,9 +87,9 @@ public class ListF5LoadBalancerNetworksCmd extends BaseListCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java b/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java
index c03d55a..deaa275 100644
--- a/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java
+++ b/plugins/network-elements/f5/src/com/cloud/api/commands/ListF5LoadBalancersCmd.java
@@ -88,9 +88,9 @@ public class ListF5LoadBalancersCmd extends BaseListCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddExternalFirewallCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddExternalFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddExternalFirewallCmd.java
index cda27fb..deaa612 100644
--- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddExternalFirewallCmd.java
+++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddExternalFirewallCmd.java
@@ -11,7 +11,7 @@
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
+// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.api.commands;
@@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.ZoneResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter;
@@ -34,30 +35,30 @@ import com.cloud.utils.exception.CloudRuntimeException;
@APICommand(name = "addExternalFirewall", description="Adds an external firewall appliance", responseObject = ExternalFirewallResponse.class)
public class AddExternalFirewallCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(AddExternalFirewallCmd.class.getName());
- private static final String s_name = "addexternalfirewallresponse";
-
+ public static final Logger s_logger = Logger.getLogger(AddExternalFirewallCmd.class.getName());
+ private static final String s_name = "addexternalfirewallresponse";
+
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
-
+
@Parameter(name=ApiConstants.ZONE_ID, type=CommandType.UUID, entityType = ZoneResponse.class,
required = true, description="Zone in which to add the external firewall appliance.")
private Long zoneId;
@Parameter(name=ApiConstants.URL, type=CommandType.STRING, required = true, description="URL of the external firewall appliance.")
- private String url;
-
+ private String url;
+
@Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Username of the external firewall appliance.")
- private String username;
-
+ private String username;
+
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Password of the external firewall appliance.")
private String password;
-
+
///////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
-
+
public Long getZoneId() {
return zoneId;
}
@@ -65,15 +66,15 @@ public class AddExternalFirewallCmd extends BaseCmd {
public String getUrl() {
return url;
}
-
+
public String getUsername() {
return username;
}
-
+
public String getPassword() {
return password;
}
-
+
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
@@ -85,12 +86,12 @@ public class AddExternalFirewallCmd extends BaseCmd {
public String getCommandName() {
return s_name;
}
-
+
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
}
-
+
@SuppressWarnings("deprecation")
@Override
public void execute(){
@@ -101,9 +102,9 @@ public class AddExternalFirewallCmd extends BaseCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException ipve) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, ipve.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ipve.getMessage());
} catch (CloudRuntimeException cre) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, cre.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, cre.getMessage());
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java
index a2ad4e5..9ed6814 100644
--- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java
+++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/AddSrxFirewallCmd.java
@@ -11,7 +11,7 @@
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
+// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.api.commands;
@@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.APICommand;
@@ -57,7 +58,7 @@ public class AddSrxFirewallCmd extends BaseAsyncCmd {
@Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to reach SRX firewall device")
private String username;
-
+
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to reach SRX firewall device")
private String password;
@@ -102,12 +103,12 @@ public class AddSrxFirewallCmd extends BaseAsyncCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
- throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add SRX firewall due to internal error.");
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add SRX firewall due to internal error.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
@@ -120,7 +121,7 @@ public class AddSrxFirewallCmd extends BaseAsyncCmd {
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_FIREWALL_DEVICE_ADD;
}
-
+
@Override
public String getCommandName() {
return s_name;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java
index 482fcc8..c9ea7cb 100644
--- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java
+++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ConfigureSrxFirewallCmd.java
@@ -11,7 +11,7 @@
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
+// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.api.commands;
@@ -19,6 +19,7 @@ package com.cloud.api.commands;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.APICommand;
@@ -81,12 +82,12 @@ public class ConfigureSrxFirewallCmd extends BaseAsyncCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
- throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to configure SRX firewall device due to internal error.");
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure SRX firewall device due to internal error.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteExternalFirewallCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteExternalFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteExternalFirewallCmd.java
index 5cdc9e3..7759789 100644
--- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteExternalFirewallCmd.java
+++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteExternalFirewallCmd.java
@@ -11,7 +11,7 @@
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
+// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.api.commands;
@@ -20,6 +20,7 @@ import org.apache.cloudstack.api.response.HostResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.Parameter;
@@ -32,9 +33,9 @@ import com.cloud.user.Account;
@APICommand(name = "deleteExternalFirewall", description="Deletes an external firewall appliance.", responseObject = SuccessResponse.class)
public class DeleteExternalFirewallCmd extends BaseCmd {
- public static final Logger s_logger = Logger.getLogger(DeleteExternalFirewallCmd.class.getName());
- private static final String s_name = "deleteexternalfirewallresponse";
-
+ public static final Logger s_logger = Logger.getLogger(DeleteExternalFirewallCmd.class.getName());
+ private static final String s_name = "deleteexternalfirewallresponse";
+
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@@ -42,15 +43,15 @@ public class DeleteExternalFirewallCmd extends BaseCmd {
@Parameter(name=ApiConstants.ID, type=CommandType.UUID, entityType = HostResponse.class,
required = true, description="Id of the external firewall appliance.")
private Long id;
-
+
///////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
-
+
public Long getId() {
return id;
}
-
+
/////////////////////////////////////////////////////
/////////////// API Implementation///////////////////
/////////////////////////////////////////////////////
@@ -61,7 +62,7 @@ public class DeleteExternalFirewallCmd extends BaseCmd {
public String getCommandName() {
return s_name;
}
-
+
@Override
public long getEntityOwnerId() {
return Account.ACCOUNT_ID_SYSTEM;
@@ -77,10 +78,10 @@ public class DeleteExternalFirewallCmd extends BaseCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete external firewall.");
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete external firewall.");
}
} catch (InvalidParameterValueException e) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "Failed to delete external firewall.");
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Failed to delete external firewall.");
}
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java
index 1dc792a..e45fe31 100644
--- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java
+++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/DeleteSrxFirewallCmd.java
@@ -11,7 +11,7 @@
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
+// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.api.commands;
@@ -19,6 +19,7 @@ package com.cloud.api.commands;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.APICommand;
@@ -72,12 +73,12 @@ public class DeleteSrxFirewallCmd extends BaseAsyncCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete SRX firewall device");
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete SRX firewall device");
}
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java
index 9c2b396..03ae962 100644
--- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java
+++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallNetworksCmd.java
@@ -11,7 +11,7 @@
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
+// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.api.commands;
@@ -80,9 +80,9 @@ public class ListSrxFirewallNetworksCmd extends BaseListCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallsCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallsCmd.java b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallsCmd.java
index 6508cc8..5242316 100644
--- a/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallsCmd.java
+++ b/plugins/network-elements/juniper-srx/src/com/cloud/api/commands/ListSrxFirewallsCmd.java
@@ -11,7 +11,7 @@
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
+// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
package com.cloud.api.commands;
@@ -88,9 +88,9 @@ public class ListSrxFirewallsCmd extends BaseListCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java
index 9d90297..79c657f 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/AddNetscalerLoadBalancerCmd.java
@@ -51,7 +51,7 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd {
@Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to reach netscaler load balancer device")
private String username;
-
+
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to reach netscaler load balancer device")
private String password;
@@ -96,12 +96,12 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
- throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add netscaler load balancer due to internal error.");
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add netscaler load balancer due to internal error.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
@@ -114,7 +114,7 @@ public class AddNetscalerLoadBalancerCmd extends BaseAsyncCmd {
public String getEventType() {
return EventTypes.EVENT_EXTERNAL_LB_DEVICE_ADD;
}
-
+
@Override
public String getCommandName() {
return s_name;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java
index e0ec73a..33fe7a2 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ConfigureNetscalerLoadBalancerCmd.java
@@ -101,12 +101,12 @@ public class ConfigureNetscalerLoadBalancerCmd extends BaseAsyncCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
- throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to configure netscaler load balancer due to internal error.");
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to configure netscaler load balancer due to internal error.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java
index ec7faab..5f62b80 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/DeleteNetscalerLoadBalancerCmd.java
@@ -18,6 +18,7 @@ package com.cloud.api.commands;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.APICommand;
@@ -72,12 +73,12 @@ public class DeleteNetscalerLoadBalancerCmd extends BaseAsyncCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete netscaler load balancer.");
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete netscaler load balancer.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java
index 52476df..ec94c6e 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancerNetworksCmd.java
@@ -20,6 +20,7 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.APICommand;
@@ -83,9 +84,9 @@ public class ListNetscalerLoadBalancerNetworksCmd extends BaseListCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancersCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancersCmd.java b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancersCmd.java
index bf679fa..8886218 100644
--- a/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancersCmd.java
+++ b/plugins/network-elements/netscaler/src/com/cloud/api/commands/ListNetscalerLoadBalancersCmd.java
@@ -21,6 +21,7 @@ import org.apache.cloudstack.api.response.PhysicalNetworkResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.APICommand;
@@ -91,9 +92,9 @@ public class ListNetscalerLoadBalancersCmd extends BaseListCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java
index 1734ce2..3bd39b8 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/AddNiciraNvpDeviceCmd.java
@@ -38,7 +38,7 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
private static final Logger s_logger = Logger.getLogger(AddNiciraNvpDeviceCmd.class.getName());
private static final String s_name = "addniciranvpdeviceresponse";
@PlugService NiciraNvpElementService _niciraNvpElementService;
-
+
/////////////////////////////////////////////////////
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
@@ -52,16 +52,16 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
@Parameter(name=ApiConstants.USERNAME, type=CommandType.STRING, required = true, description="Credentials to access the Nicira Controller API")
private String username;
-
+
@Parameter(name=ApiConstants.PASSWORD, type=CommandType.STRING, required = true, description="Credentials to access the Nicira Controller API")
private String password;
-
+
@Parameter(name=ApiConstants.NICIRA_NVP_TRANSPORT_ZONE_UUID, type=CommandType.STRING, required = true, description="The Transportzone UUID configured on the Nicira Controller")
private String transportzoneuuid;
-
+
@Parameter(name=ApiConstants.NICIRA_NVP_GATEWAYSERVICE_UUID, type=CommandType.STRING, required = false, description="The L3 Gateway Service UUID configured on the Nicira Controller")
private String l3gatewayserviceuuid;
-
+
/////////////////////////////////////////////////////
/////////////////// Accessors ///////////////////////
/////////////////////////////////////////////////////
@@ -81,11 +81,11 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
public String getPassword() {
return password;
}
-
+
public String getTransportzoneUuid() {
return transportzoneuuid;
}
-
+
public String getL3GatewayServiceUuid() {
return l3gatewayserviceuuid;
}
@@ -104,15 +104,15 @@ public class AddNiciraNvpDeviceCmd extends BaseAsyncCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
- throw new ServerApiException(BaseAsyncCmd.INTERNAL_ERROR, "Failed to add Nicira NVP device due to internal error.");
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to add Nicira NVP device due to internal error.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
-
+
@Override
public String getCommandName() {
return s_name;
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java
index 1254441..9a10c28 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/DeleteNiciraNvpDeviceCmd.java
@@ -20,6 +20,7 @@ import com.cloud.api.response.NiciraNvpDeviceResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseAsyncCmd;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.APICommand;
@@ -72,12 +73,12 @@ public class DeleteNiciraNvpDeviceCmd extends BaseAsyncCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Failed to delete Nicira device.");
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to delete Nicira device.");
}
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java
index bea417d..70973c0 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDeviceNetworksCmd.java
@@ -23,6 +23,7 @@ import com.cloud.api.response.NiciraNvpDeviceResponse;
import org.apache.log4j.Logger;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.APICommand;
@@ -85,9 +86,9 @@ public class ListNiciraNvpDeviceNetworksCmd extends BaseListCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDevicesCmd.java
----------------------------------------------------------------------
diff --git a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDevicesCmd.java b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDevicesCmd.java
index 04aab2a..0d2ca5a 100644
--- a/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDevicesCmd.java
+++ b/plugins/network-elements/nicira-nvp/src/com/cloud/api/commands/ListNiciraNvpDevicesCmd.java
@@ -20,6 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import org.apache.cloudstack.api.ApiConstants;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.BaseListCmd;
import org.apache.cloudstack.api.Parameter;
@@ -92,9 +93,9 @@ public class ListNiciraNvpDevicesCmd extends BaseListCmd {
response.setResponseName(getCommandName());
this.setResponseObject(response);
} catch (InvalidParameterValueException invalidParamExcp) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, invalidParamExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, invalidParamExcp.getMessage());
} catch (CloudRuntimeException runtimeExcp) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, runtimeExcp.getMessage());
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, runtimeExcp.getMessage());
}
}
@@ -102,5 +103,5 @@ public class ListNiciraNvpDevicesCmd extends BaseListCmd {
public String getCommandName() {
return s_name;
}
-
+
}
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/server/src/com/cloud/api/ApiDispatcher.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiDispatcher.java b/server/src/com/cloud/api/ApiDispatcher.java
index 55d7f42..04b46e5 100755
--- a/server/src/com/cloud/api/ApiDispatcher.java
+++ b/server/src/com/cloud/api/ApiDispatcher.java
@@ -105,46 +105,13 @@ public class ApiDispatcher {
_daoNameMap.put("com.cloud.template.VirtualMachineTemplate", VMTemplateDao.class);
}
- public void dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map<String, String> params) {
- processParameters(cmd, params);
+ public void dispatchCreateCmd(BaseAsyncCreateCmd cmd, Map<String, String> params) throws Exception {
+ processParameters(cmd, params);
+
+ UserContext ctx = UserContext.current();
+ ctx.setAccountId(cmd.getEntityOwnerId());
+ cmd.create();
- try {
- UserContext ctx = UserContext.current();
- ctx.setAccountId(cmd.getEntityOwnerId());
- cmd.create();
- } catch (Throwable t) {
- if (t instanceof InvalidParameterValueException || t instanceof IllegalArgumentException) {
- s_logger.info(t.getMessage());
- throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
- } else if (t instanceof PermissionDeniedException) {
- s_logger.info("PermissionDenied: " + t.getMessage());
- throw new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
- } else if (t instanceof AccountLimitException) {
- s_logger.info(t.getMessage());
- throw new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage());
- } else if (t instanceof InsufficientCapacityException) {
- s_logger.info(t.getMessage());
- throw new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
- } else if (t instanceof ResourceAllocationException) {
- s_logger.info(t.getMessage());
- throw new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage());
- } else if (t instanceof ResourceUnavailableException) {
- s_logger.warn("Exception: ", t);
- throw new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage());
- } else if (t instanceof AsyncCommandQueued) {
- throw (AsyncCommandQueued) t;
- } else if (t instanceof ServerApiException) {
- s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription());
- throw (ServerApiException) t;
- } else {
- s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t);
- if (UserContext.current().getCaller().getType() == Account.ACCOUNT_TYPE_ADMIN) {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
- } else {
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE);
- }
- }
- }
}
private void doAccessChecks(BaseCmd cmd, List<Object> entitiesToAccess) {
@@ -170,164 +137,36 @@ public class ApiDispatcher {
}
}
- public void dispatch(BaseCmd cmd, Map<String, String> params) {
- try {
- processParameters(cmd, params);
- UserContext ctx = UserContext.current();
- ctx.setAccountId(cmd.getEntityOwnerId());
- if (cmd instanceof BaseAsyncCmd) {
-
- BaseAsyncCmd asyncCmd = (BaseAsyncCmd) cmd;
- String startEventId = params.get("ctxStartEventId");
- ctx.setStartEventId(Long.valueOf(startEventId));
-
- // Synchronise job on the object if needed
- if (asyncCmd.getJob() != null && asyncCmd.getSyncObjId() != null && asyncCmd.getSyncObjType() != null) {
- Long queueSizeLimit = null;
- if (asyncCmd.getSyncObjType() != null && asyncCmd.getSyncObjType().equalsIgnoreCase(BaseAsyncCmd.snapshotHostSyncObject)) {
- queueSizeLimit = _createSnapshotQueueSizeLimit;
- } else {
- queueSizeLimit = 1L;
- }
-
- if (queueSizeLimit != null) {
- _asyncMgr.syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(),
- asyncCmd.getSyncObjId().longValue(), queueSizeLimit);
- } else {
- s_logger.trace("The queue size is unlimited, skipping the synchronizing");
- }
- }
- }
-
- cmd.execute();
-
- } catch (Throwable t) {
- if (t instanceof InvalidParameterValueException) {
- // earlier, we'd log the db id as part of the log message, but now since we've pushed
- // the id into a IdentityProxy object, we would need to dump that object alongwith the
- // message.
- InvalidParameterValueException ref = (InvalidParameterValueException) t;
- ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
- // copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- // Iterate through entire arraylist and copy over each proxy id.
- for (int i = 0 ; i < idList.size(); i++) {
- ex.addProxyObject(idList.get(i));
- s_logger.info(t.getMessage() + " uuid: " + idList.get(i));
- }
- } else {
- s_logger.info(t.getMessage());
- }
- // Also copy over the cserror code.
- ex.setCSErrorCode(ref.getCSErrorCode());
- throw ex;
- } else if(t instanceof IllegalArgumentException) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, t.getMessage());
- } else if (t instanceof PermissionDeniedException) {
- PermissionDeniedException ref = (PermissionDeniedException)t;
- ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_ERROR, t.getMessage());
- // copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- // Iterate through entire arraylist and copy over each proxy id.
- for (int i = 0 ; i < idList.size(); i++) {
- ex.addProxyObject(idList.get(i));
- s_logger.info("PermissionDenied: " + t.getMessage() + "uuid: " + idList.get(i));
- }
- } else {
- s_logger.info("PermissionDenied: " + t.getMessage());
- }
- // Also copy over the cserror code.
- ex.setCSErrorCode(ref.getCSErrorCode());
- throw ex;
- } else if (t instanceof AccountLimitException) {
- AccountLimitException ref = (AccountLimitException)t;
- ServerApiException ex = new ServerApiException(BaseCmd.ACCOUNT_RESOURCE_LIMIT_ERROR, t.getMessage());
- // copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- // Iterate through entire arraylist and copy over each proxy id.
- for (int i = 0 ; i < idList.size(); i++) {
- ex.addProxyObject(idList.get(i));
- s_logger.info(t.getMessage() + "uuid: " + idList.get(i));
- }
- } else {
- s_logger.info(t.getMessage());
- }
- // Also copy over the cserror code.
- ex.setCSErrorCode(ref.getCSErrorCode());
- throw ex;
- } else if (t instanceof InsufficientCapacityException) {
- InsufficientCapacityException ref = (InsufficientCapacityException)t;
- ServerApiException ex = new ServerApiException(BaseCmd.INSUFFICIENT_CAPACITY_ERROR, t.getMessage());
- // copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- // Iterate through entire arraylist and copy over each proxy id.
- for (int i = 0 ; i < idList.size(); i++) {
- ex.addProxyObject(idList.get(i));
- s_logger.info(t.getMessage() + "uuid: " + idList.get(i));
- }
- } else {
- s_logger.info(t.getMessage());
- }
- // Also copy over the cserror code
- ex.setCSErrorCode(ref.getCSErrorCode());
- throw ex;
- } else if (t instanceof ResourceAllocationException) {
- ResourceAllocationException ref = (ResourceAllocationException)t;
- ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_ALLOCATION_ERROR, t.getMessage());
- // copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- // Iterate through entire arraylist and copy over each proxy id.
- for (int i = 0 ; i < idList.size(); i++) {
- String id = idList.get(i);
- ex.addProxyObject(id);
- s_logger.warn("Exception: " + t.getMessage() + "uuid: " + id);
- }
+ public void dispatch(BaseCmd cmd, Map<String, String> params) throws Exception {
+ processParameters(cmd, params);
+ UserContext ctx = UserContext.current();
+ ctx.setAccountId(cmd.getEntityOwnerId());
+ if (cmd instanceof BaseAsyncCmd) {
+
+ BaseAsyncCmd asyncCmd = (BaseAsyncCmd) cmd;
+ String startEventId = params.get("ctxStartEventId");
+ ctx.setStartEventId(Long.valueOf(startEventId));
+
+ // Synchronise job on the object if needed
+ if (asyncCmd.getJob() != null && asyncCmd.getSyncObjId() != null && asyncCmd.getSyncObjType() != null) {
+ Long queueSizeLimit = null;
+ if (asyncCmd.getSyncObjType() != null && asyncCmd.getSyncObjType().equalsIgnoreCase(BaseAsyncCmd.snapshotHostSyncObject)) {
+ queueSizeLimit = _createSnapshotQueueSizeLimit;
} else {
- s_logger.warn("Exception: ", t);
+ queueSizeLimit = 1L;
}
- // Also copy over the cserror code.
- ex.setCSErrorCode(ref.getCSErrorCode());
- throw ex;
- } else if (t instanceof ResourceUnavailableException) {
- ResourceUnavailableException ref = (ResourceUnavailableException)t;
- ServerApiException ex = new ServerApiException(BaseCmd.RESOURCE_UNAVAILABLE_ERROR, t.getMessage());
- // copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- // Iterate through entire arraylist and copy over each proxy id.
- for (int i = 0 ; i < idList.size(); i++) {
- String id = idList.get(i);
- ex.addProxyObject(id);
- s_logger.warn("Exception: " + t.getMessage() + "uuid: " + id);
- }
- } else {
- s_logger.warn("Exception: ", t);
- }
- // Also copy over the cserror code.
- ex.setCSErrorCode(ref.getCSErrorCode());
- throw ex;
- } else if (t instanceof AsyncCommandQueued) {
- throw (AsyncCommandQueued) t;
- } else if (t instanceof ServerApiException) {
- s_logger.warn(t.getClass() + " : " + ((ServerApiException) t).getDescription());
- throw (ServerApiException) t;
- } else {
- s_logger.error("Exception while executing " + cmd.getClass().getSimpleName() + ":", t);
- ServerApiException ex;
- if (UserContext.current().getCaller().getType() == Account.ACCOUNT_TYPE_ADMIN) {
- ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, t.getMessage());
+
+ if (queueSizeLimit != null) {
+ _asyncMgr
+ .syncAsyncJobExecution(asyncCmd.getJob(), asyncCmd.getSyncObjType(), asyncCmd.getSyncObjId().longValue(), queueSizeLimit);
} else {
- ex = new ServerApiException(BaseCmd.INTERNAL_ERROR, BaseCmd.USER_ERROR_MESSAGE);
+ s_logger.trace("The queue size is unlimited, skipping the synchronizing");
}
- ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
- throw ex;
}
}
+
+ cmd.execute();
+
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@@ -343,11 +182,11 @@ public class ApiDispatcher {
}
if ((unpackedParams.get(ApiConstants.PAGE) == null) && (pageSize != null && pageSize != BaseListCmd.PAGESIZE_UNLIMITED)) {
- ServerApiException ex = new ServerApiException(BaseCmd.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
+ ServerApiException ex = new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"page\" parameter is required when \"pagesize\" is specified");
ex.setCSErrorCode(CSExceptionErrorCode.getCSErrCode(ex.getClass().getName()));
throw ex;
} else if (pageSize == null && (unpackedParams.get(ApiConstants.PAGE) != null)) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "\"pagesize\" parameter is required when \"page\" is specified");
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "\"pagesize\" parameter is required when \"page\" is specified");
}
}
@@ -370,7 +209,7 @@ public class ApiDispatcher {
Object paramObj = unpackedParams.get(parameterAnnotation.name());
if (paramObj == null) {
if (parameterAnnotation.required()) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to missing parameter "
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to missing parameter "
+ parameterAnnotation.name());
}
continue;
@@ -383,23 +222,23 @@ public class ApiDispatcher {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Unable to execute API command " + cmd.getCommandName() + " due to invalid value " + paramObj + " for parameter " + parameterAnnotation.name());
}
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value " + paramObj
+ " for parameter "
+ parameterAnnotation.name());
} catch (ParseException parseEx) {
if (s_logger.isDebugEnabled()) {
s_logger.debug("Invalid date parameter " + paramObj + " passed to command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
}
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8)
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to parse date " + paramObj + " for command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8)
+ ", please pass dates in the format mentioned in the api documentation");
} catch (InvalidParameterValueException invEx) {
- throw new ServerApiException(BaseCmd.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Unable to execute API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8) + " due to invalid value. " + invEx.getMessage());
} catch (CloudRuntimeException cloudEx) {
// FIXME: Better error message? This only happens if the API command is not executable, which typically
//means
// there was
// and IllegalAccessException setting one of the parameters.
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal error executing API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal error executing API command " + cmd.getCommandName().substring(0, cmd.getCommandName().length() - 8));
}
//check access on the resource this field points to
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index 72bed44..6b1de42 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -102,6 +102,8 @@ import org.apache.cloudstack.api.command.user.tag.ListTagsCmd;
import com.cloud.api.response.ApiResponseSerializer;
import org.apache.cloudstack.api.response.ExceptionResponse;
import org.apache.cloudstack.api.response.ListResponse;
+
+import com.cloud.async.AsyncCommandQueued;
import com.cloud.async.AsyncJob;
import com.cloud.async.AsyncJobManager;
import com.cloud.async.AsyncJobVO;
@@ -112,10 +114,14 @@ import com.cloud.configuration.dao.ConfigurationDao;
import com.cloud.domain.Domain;
import com.cloud.domain.DomainVO;
import com.cloud.event.EventUtils;
+import com.cloud.exception.AccountLimitException;
import com.cloud.exception.CloudAuthenticationException;
+import com.cloud.exception.InsufficientCapacityException;
import com.cloud.exception.InvalidParameterValueException;
import com.cloud.exception.PermissionDeniedException;
import com.cloud.exception.RequestLimitException;
+import com.cloud.exception.ResourceAllocationException;
+import com.cloud.exception.ResourceUnavailableException;
import com.cloud.server.ManagementServer;
import com.cloud.user.Account;
import com.cloud.user.AccountManager;
@@ -276,8 +282,8 @@ public class ApiServer implements HttpRequestHandler {
writeResponse(response, responseText, HttpStatus.SC_OK, responseType, null);
} catch (ServerApiException se) {
- String responseText = getSerializedApiError(se.getErrorCode(), se.getDescription(), parameterMap, responseType, se);
- writeResponse(response, responseText, se.getErrorCode(), responseType, se.getDescription());
+ String responseText = getSerializedApiError(se, parameterMap, responseType);
+ writeResponse(response, responseText, se.getErrorCode().getHttpCode(), responseType, se.getDescription());
sb.append(" " + se.getErrorCode() + " " + se.getDescription());
} catch (RuntimeException e) {
// log runtime exception like NullPointerException to help identify the source easier
@@ -306,7 +312,7 @@ public class ApiServer implements HttpRequestHandler {
s_logger.trace(" key: " + keyStr + ", value: " + ((value == null) ? "'null'" : value[0]));
}
}
- throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "Invalid request, no command sent");
+ throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "Invalid request, no command sent");
} else {
Map<String, String> paramMap = new HashMap<String, String>();
Set keys = params.keySet();
@@ -324,10 +330,10 @@ public class ApiServer implements HttpRequestHandler {
decodedValue = URLDecoder.decode(value[0], "UTF-8");
} catch (UnsupportedEncodingException usex) {
s_logger.warn(key + " could not be decoded, value = " + value[0]);
- throw new ServerApiException(BaseCmd.PARAM_ERROR, key + " could not be decoded, received value " + value[0]);
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, key + " could not be decoded, received value " + value[0]);
} catch (IllegalArgumentException iae) {
s_logger.warn(key + " could not be decoded, value = " + value[0]);
- throw new ServerApiException(BaseCmd.PARAM_ERROR, key + " could not be decoded, received value " + value[0] + " which contains illegal characters eg.%");
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, key + " could not be decoded, received value " + value[0] + " which contains illegal characters eg.%");
}
} else {
decodedValue = value[0];
@@ -348,51 +354,81 @@ public class ApiServer implements HttpRequestHandler {
String errorString = "Unknown API command: " + ((command == null) ? "null" : command[0]);
s_logger.warn(errorString);
auditTrailSb.append(" " + errorString);
- throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, errorString);
+ throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, errorString);
}
}
}
- } catch (Exception ex) {
- if (ex instanceof InvalidParameterValueException) {
- InvalidParameterValueException ref = (InvalidParameterValueException)ex;
- ServerApiException e = new ServerApiException(BaseCmd.PARAM_ERROR, ex.getMessage());
- // copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- // Iterate through entire arraylist and copy over each proxy id.
- for (int i = 0 ; i < idList.size(); i++) {
- e.addProxyObject(idList.get(i));
- }
- }
- // Also copy over the cserror code and the function/layer in which it was thrown.
- e.setCSErrorCode(ref.getCSErrorCode());
- throw e;
- } else if (ex instanceof PermissionDeniedException) {
- PermissionDeniedException ref = (PermissionDeniedException)ex;
- ServerApiException e = new ServerApiException(BaseCmd.ACCOUNT_ERROR, ex.getMessage());
- // copy over the IdentityProxy information as well and throw the serverapiexception.
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- // Iterate through entire arraylist and copy over each proxy id.
- for (int i = 0 ; i < idList.size(); i++) {
- e.addProxyObject(idList.get(i));
- }
- }
- e.setCSErrorCode(ref.getCSErrorCode());
- throw e;
- } else if (ex instanceof ServerApiException) {
- throw (ServerApiException) ex;
- } else {
- s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex);
- ServerApiException e = new ServerApiException(BaseCmd.INTERNAL_ERROR, "Internal server error, unable to execute request.");
- e.setCSErrorCode(CSExceptionErrorCode.getCSErrCode("ServerApiException"));
- throw e;
+ }
+ catch (InvalidParameterValueException ex){
+ s_logger.info(ex.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage(), ex);
+ }
+ catch (IllegalArgumentException ex){
+ s_logger.info(ex.getMessage());
+ throw new ServerApiException(ApiErrorCode.PARAM_ERROR, ex.getMessage(), ex);
+ }
+ catch (PermissionDeniedException ex){
+ ArrayList<String> idList = ex.getIdProxyList();
+ if (idList != null) {
+ s_logger.info("PermissionDenied: " + ex.getMessage() + " on uuids: [" + StringUtils.listToCsvTags(idList) + "]");
+ } else {
+ s_logger.info("PermissionDenied: " + ex.getMessage());
+ }
+ throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, ex.getMessage(), ex);
+ }
+ catch (AccountLimitException ex){
+ s_logger.info(ex.getMessage());
+ throw new ServerApiException(ApiErrorCode.ACCOUNT_RESOURCE_LIMIT_ERROR, ex.getMessage(), ex);
+ }
+ catch (InsufficientCapacityException ex){
+ s_logger.info(ex.getMessage());
+ String errorMsg = ex.getMessage();
+ if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){
+ // hide internal details to non-admin user for security reason
+ errorMsg = BaseCmd.USER_ERROR_MESSAGE;
+ }
+ throw new ServerApiException(ApiErrorCode.INSUFFICIENT_CAPACITY_ERROR, errorMsg, ex);
+ }
+ catch (ResourceAllocationException ex){
+ s_logger.info(ex.getMessage());
+ String errorMsg = ex.getMessage();
+ if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){
+ // hide internal details to non-admin user for security reason
+ errorMsg = BaseCmd.USER_ERROR_MESSAGE;
+ }
+ throw new ServerApiException(ApiErrorCode.RESOURCE_ALLOCATION_ERROR, errorMsg, ex);
+ }
+ catch (ResourceUnavailableException ex){
+ s_logger.info(ex.getMessage());
+ String errorMsg = ex.getMessage();
+ if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){
+ // hide internal details to non-admin user for security reason
+ errorMsg = BaseCmd.USER_ERROR_MESSAGE;
+ }
+ throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, errorMsg, ex);
+ }
+ catch (AsyncCommandQueued ex){
+ s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex);
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Internal server error, unable to execute request.");
+ }
+ catch (ServerApiException ex){
+ s_logger.info(ex.getDescription());
+ throw ex;
+ }
+ catch (Exception ex){
+ s_logger.error("unhandled exception executing api command: " + ((command == null) ? "null" : command[0]), ex);
+ String errorMsg = ex.getMessage();
+ if (UserContext.current().getCaller().getType() != Account.ACCOUNT_TYPE_ADMIN){
+ // hide internal details to non-admin user for security reason
+ errorMsg = BaseCmd.USER_ERROR_MESSAGE;
}
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMsg, ex);
}
+
return response;
}
- private String queueCommand(BaseCmd cmdObj, Map<String, String> params) {
+ private String queueCommand(BaseCmd cmdObj, Map<String, String> params) throws Exception {
UserContext ctx = UserContext.current();
Long callerUserId = ctx.getCallerUserId();
Account caller = ctx.getCaller();
@@ -448,7 +484,7 @@ public class ApiServer implements HttpRequestHandler {
if (jobId == 0L) {
String errorMsg = "Unable to schedule async job for command " + job.getCmd();
s_logger.warn(errorMsg);
- throw new ServerApiException(BaseCmd.INTERNAL_ERROR, errorMsg);
+ throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, errorMsg);
}
if (objectId != null) {
@@ -559,18 +595,18 @@ public class ApiServer implements HttpRequestHandler {
}
catch (PermissionDeniedException ex){
s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user with id:" + userId);
- throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user");
+ throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user");
}
catch (RequestLimitException ex){
s_logger.debug(ex.getMessage());
- throw new ServerApiException(BaseCmd.API_LIMIT_EXCEED, ex.getMessage());
+ throw new ServerApiException(ApiErrorCode.API_LIMIT_EXCEED, ex.getMessage());
}
return true;
} else {
// check against every available command to see if the command exists or not
if (!_apiNameCmdClassMap.containsKey(commandName) && !commandName.equals("login") && !commandName.equals("logout")) {
s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user with id:" + userId);
- throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user");
+ throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user");
}
}
@@ -666,7 +702,7 @@ public class ApiServer implements HttpRequestHandler {
}
catch (PermissionDeniedException ex){
s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user");
- throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command:" + commandName + " does not exist or it is not available for user with id:" + userId);
+ throw new ServerApiException(ApiErrorCode.UNSUPPORTED_ACTION_ERROR, "The given command:" + commandName + " does not exist or it is not available for user with id:" + userId);
}
// verify secret key exists
@@ -940,13 +976,13 @@ public class ApiServer implements HttpRequestHandler {
}
}
- public String getSerializedApiError(int errorCode, String errorText, Map<String, Object[]> apiCommandParams, String responseType, Exception ex) {
+ public String getSerializedApiError(int errorCode, String errorText, Map<String, Object[]> apiCommandParams, String responseType) {
String responseName = null;
Class<?> cmdClass = null;
String responseText = null;
try {
- if (errorCode == BaseCmd.UNSUPPORTED_ACTION_ERROR || apiCommandParams == null || apiCommandParams.isEmpty()) {
+ if (apiCommandParams == null || apiCommandParams.isEmpty()) {
responseName = "errorresponse";
} else {
Object cmdObj = apiCommandParams.get("command");
@@ -965,48 +1001,55 @@ public class ApiServer implements HttpRequestHandler {
apiResponse.setErrorCode(errorCode);
apiResponse.setErrorText(errorText);
apiResponse.setResponseName(responseName);
- // Also copy over the IdentityProxy object List into this new apiResponse, from
- // the exception caught. When invoked from handle(), the exception here can
- // be either ServerApiException, PermissionDeniedException or InvalidParameterValue
- // Exception. When invoked from ApiServlet's processRequest(), this can be
- // a standard exception like NumberFormatException. We'll leave the standard ones alone.
- if (ex != null) {
- if (ex instanceof ServerApiException || ex instanceof PermissionDeniedException
- || ex instanceof InvalidParameterValueException) {
- // Cast the exception appropriately and retrieve the IdentityProxy
- if (ex instanceof ServerApiException) {
- ServerApiException ref = (ServerApiException) ex;
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- for (int i=0; i < idList.size(); i++) {
- apiResponse.addProxyObject(idList.get(i));
- }
- }
- // Also copy over the cserror code and the function/layer in which it was thrown.
- apiResponse.setCSErrorCode(ref.getCSErrorCode());
- } else if (ex instanceof PermissionDeniedException) {
- PermissionDeniedException ref = (PermissionDeniedException) ex;
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- for (int i=0; i < idList.size(); i++) {
- apiResponse.addProxyObject(idList.get(i));
- }
- }
- // Also copy over the cserror code and the function/layer in which it was thrown.
- apiResponse.setCSErrorCode(ref.getCSErrorCode());
- } else if (ex instanceof InvalidParameterValueException) {
- InvalidParameterValueException ref = (InvalidParameterValueException) ex;
- ArrayList<String> idList = ref.getIdProxyList();
- if (idList != null) {
- for (int i=0; i < idList.size(); i++) {
- apiResponse.addProxyObject(idList.get(i));
- }
- }
- // Also copy over the cserror code and the function/layer in which it was thrown.
- apiResponse.setCSErrorCode(ref.getCSErrorCode());
- }
- }
+ SerializationContext.current().setUuidTranslation(true);
+ responseText = ApiResponseSerializer.toSerializedString(apiResponse, responseType);
+
+ } catch (Exception e) {
+ s_logger.error("Exception responding to http request", e);
+ }
+ return responseText;
+ }
+
+ public String getSerializedApiError(ServerApiException ex, Map<String, Object[]> apiCommandParams, String responseType) {
+ String responseName = null;
+ Class<?> cmdClass = null;
+ String responseText = null;
+
+ if (ex == null){
+ // this call should not be invoked with null exception
+ return getSerializedApiError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Some internal error happened", apiCommandParams, responseType);
+ }
+ try {
+ if (ex.getErrorCode() == ApiErrorCode.UNSUPPORTED_ACTION_ERROR || apiCommandParams == null || apiCommandParams.isEmpty()) {
+ responseName = "errorresponse";
+ } else {
+ Object cmdObj = apiCommandParams.get("command");
+ // cmd name can be null when "command" parameter is missing in
+ // the request
+ if (cmdObj != null) {
+ String cmdName = ((String[]) cmdObj)[0];
+ cmdClass = getCmdClass(cmdName);
+ if (cmdClass != null) {
+ responseName = ((BaseCmd) cmdClass.newInstance()).getCommandName();
+ } else {
+ responseName = "errorresponse";
+ }
+ }
}
+ ExceptionResponse apiResponse = new ExceptionResponse();
+ apiResponse.setErrorCode(ex.getErrorCode().getHttpCode());
+ apiResponse.setErrorText(ex.getDescription());
+ apiResponse.setResponseName(responseName);
+ ArrayList<String> idList = ex.getIdProxyList();
+ if (idList != null) {
+ for (int i = 0; i < idList.size(); i++) {
+ apiResponse.addProxyObject(idList.get(i));
+ }
+ }
+ // Also copy over the cserror code and the function/layer in which
+ // it was thrown.
+ apiResponse.setCSErrorCode(ex.getCSErrorCode());
+
SerializationContext.current().setUuidTranslation(true);
responseText = ApiResponseSerializer.toSerializedString(apiResponse, responseType);
http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/bdcfa191/server/src/com/cloud/api/ApiServlet.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServlet.java b/server/src/com/cloud/api/ApiServlet.java
index 21373cd..0f8924a 100755
--- a/server/src/com/cloud/api/ApiServlet.java
+++ b/server/src/com/cloud/api/ApiServlet.java
@@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
+import org.apache.cloudstack.api.ApiErrorCode;
import org.apache.cloudstack.api.BaseCmd;
import org.apache.cloudstack.api.ServerApiException;
import org.apache.log4j.Logger;
@@ -192,7 +193,7 @@ public class ApiServlet extends HttpServlet {
s_logger.warn("Invalid domain id entered by user");
auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "Invalid domain id entered, please enter a valid one");
String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "Invalid domain id entered, please enter a valid one", params,
- responseType, null);
+ responseType);
writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType);
}
}
@@ -227,10 +228,10 @@ public class ApiServlet extends HttpServlet {
} catch (IllegalStateException ise) {
}
- auditTrailSb.append(" " + BaseCmd.ACCOUNT_ERROR + " " + ex.getMessage() != null ? ex.getMessage() : "failed to authenticate user, check if username/password are correct");
- String serializedResponse = _apiServer.getSerializedApiError(BaseCmd.ACCOUNT_ERROR, ex.getMessage() != null ? ex.getMessage()
- : "failed to authenticate user, check if username/password are correct", params, responseType, null);
- writeResponse(resp, serializedResponse, BaseCmd.ACCOUNT_ERROR, responseType);
+ auditTrailSb.append(" " + ApiErrorCode.ACCOUNT_ERROR + " " + ex.getMessage() != null ? ex.getMessage() : "failed to authenticate user, check if username/password are correct");
+ String serializedResponse = _apiServer.getSerializedApiError(ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), ex.getMessage() != null ? ex.getMessage()
+ : "failed to authenticate user, check if username/password are correct", params, responseType);
+ writeResponse(resp, serializedResponse, ApiErrorCode.ACCOUNT_ERROR.getHttpCode(), responseType);
return;
}
}
@@ -257,7 +258,7 @@ public class ApiServlet extends HttpServlet {
} catch (IllegalStateException ise) {
}
auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials");
- String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials", params, responseType, null);
+ String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials", params, responseType);
writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType);
return;
}
@@ -269,7 +270,7 @@ public class ApiServlet extends HttpServlet {
if (command == null) {
s_logger.info("missing command, ignoring request...");
auditTrailSb.append(" " + HttpServletResponse.SC_BAD_REQUEST + " " + "no command specified");
- String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_BAD_REQUEST, "no command specified", params, responseType, null);
+ String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_BAD_REQUEST, "no command specified", params, responseType);
writeResponse(resp, serializedResponse, HttpServletResponse.SC_BAD_REQUEST, responseType);
return;
}
@@ -283,7 +284,7 @@ public class ApiServlet extends HttpServlet {
}
auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials");
- String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials", params, responseType, null);
+ String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials", params, responseType);
writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType);
return;
}
@@ -317,14 +318,14 @@ public class ApiServlet extends HttpServlet {
}
auditTrailSb.append(" " + HttpServletResponse.SC_UNAUTHORIZED + " " + "unable to verify user credentials and/or request signature");
- String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials and/or request signature", params, responseType, null);
+ String serializedResponse = _apiServer.getSerializedApiError(HttpServletResponse.SC_UNAUTHORIZED, "unable to verify user credentials and/or request signature", params, responseType);
writeResponse(resp, serializedResponse, HttpServletResponse.SC_UNAUTHORIZED, responseType);
}
} catch (ServerApiException se) {
- String serializedResponseText = _apiServer.getSerializedApiError(se.getErrorCode(), se.getDescription(), params, responseType, null);
+ String serializedResponseText = _apiServer.getSerializedApiError(se, params, responseType);
resp.setHeader("X-Description", se.getDescription());
- writeResponse(resp, serializedResponseText, se.getErrorCode(), responseType);
+ writeResponse(resp, serializedResponseText, se.getErrorCode().getHttpCode(), responseType);
auditTrailSb.append(" " + se.getErrorCode() + " " + se.getDescription());
} catch (Exception ex) {
s_logger.error("unknown exception writing api response", ex);