Skip to content

Commit 92e509b

Browse files
author
Vijayendra Bhamidipati
committed
Bug CS-15372: IdentityProxy info should be copied over during exception handling in API layer for create(), like it is done in execute().
Description: 1. Added exception processing for uuid lists in exceptions, for commands of type BaseAsyncCreateCmd. 2. Added nullpointer check in addProxyObject(). 3. Miscellaneous whitespace reformatting for git patching. Conflicts: api/src/com/cloud/exception/CloudException.java utils/src/com/cloud/utils/exception/RuntimeCloudException.java
1 parent 130893b commit 92e509b

File tree

3 files changed

+322
-191
lines changed

3 files changed

+322
-191
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,88 @@
1-
// Copyright 2012 Citrix Systems, Inc. Licensed under the
2-
// Apache License, Version 2.0 (the "License"); you may not use this
3-
// file except in compliance with the License. Citrix Systems, Inc.
4-
// reserves all rights not expressly granted by the License.
5-
// You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6-
// Unless required by applicable law or agreed to in writing, software
7-
// distributed under the License is distributed on an "AS IS" BASIS,
8-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
9-
// See the License for the specific language governing permissions and
10-
// limitations under the License.
11-
//
12-
// Automatically generated by addcopyright.py at 04/03/2012
1+
/**
2+
* Copyright (C) 2011 Citrix Systems, Inc. All rights reserved
3+
*
4+
* This software is licensed under the GNU General Public License v3 or later.
5+
*
6+
* It is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License as published by
8+
* the Free Software Foundation, either version 3 of the License, or any later version.
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
*
17+
*/
1318
package com.cloud.exception;
1419

15-
import com.cloud.utils.IdentityProxy;
1620
import java.util.ArrayList;
17-
import com.cloud.utils.exception.CSExceptionErrorCode;
21+
1822
import com.cloud.utils.AnnotationHelper;
23+
import com.cloud.utils.IdentityProxy;
24+
import com.cloud.utils.exception.CSExceptionErrorCode;
1925

2026
/**
27+
* CloudException is a generic exception class that has an IdentityProxy
28+
* object in it to enable on the fly conversion of database ids to uuids
2129
* by the API response serializer. Any exceptions that are thrown by
30+
* command invocations must extend this class, or the RuntimeCloudException
2231
* class, which extends RuntimeException instead of Exception like this
23-
* class does.
32+
* class does.
2433
*/
2534

2635
public class CloudException extends Exception {
27-
28-
// This holds a list of uuids and their names. Add uuid:fieldname pairs
29-
protected ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>();
30-
31-
protected Integer csErrorCode;
32-
33-
public CloudException(String message) {
34-
super(message);
35-
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
36-
}
36+
37+
// This holds a list of uuids and their names. Add uuid:fieldname pairs
38+
// if required, to this list before throwing an exception, using addProxyObject().
39+
protected ArrayList<IdentityProxy> idList = new ArrayList<IdentityProxy>();
40+
41+
// This holds an error code. Set this before throwing an exception, if applicable.
42+
protected Integer csErrorCode;
43+
44+
public CloudException(String message) {
45+
super(message);
46+
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
47+
}
3748

3849
public CloudException(String message, Throwable cause) {
3950
super(message, cause);
4051
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
4152
}
42-
53+
4354
public void addProxyObject(Object voObj, Long id, String idFieldName) {
44-
// Get the VO object's table name.
45-
String tablename = AnnotationHelper.getTableName(voObj);
46-
if (tablename != null) {
47-
addProxyObject(tablename, id, idFieldName);
48-
}
49-
return;
55+
// Get the VO object's table name.
56+
if (voObj != null) {
57+
String tablename = AnnotationHelper.getTableName(voObj);
58+
if (tablename != null) {
59+
addProxyObject(tablename, id, idFieldName);
60+
}
61+
}
62+
return;
63+
}
64+
65+
public CloudException() {
66+
super();
67+
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
68+
}
69+
70+
public void addProxyObject(String tableName, Long id, String idFieldName) {
71+
if (tableName != null) {
72+
idList.add(new IdentityProxy(tableName, id, idFieldName));
73+
}
74+
return;
75+
}
76+
77+
public ArrayList<IdentityProxy> getIdProxyList() {
78+
return idList;
79+
}
80+
81+
public void setCSErrorCode(int cserrcode) {
82+
this.csErrorCode = cserrcode;
83+
}
84+
85+
public int getCSErrorCode() {
86+
return this.csErrorCode;
5087
}
51-
52-
public CloudException() {
53-
super();
54-
setCSErrorCode(CSExceptionErrorCode.getCSErrCode(this.getClass().getName()));
55-
}
56-
57-
public void addProxyObject(String tableName, Long id, String idFieldName) {
58-
idList.add(new IdentityProxy(tableName, id, idFieldName));
59-
return;
60-
}
61-
62-
public ArrayList<IdentityProxy> getIdProxyList() {
63-
return idList;
64-
}
65-
66-
public void setCSErrorCode(int cserrcode) {
67-
this.csErrorCode = cserrcode;
68-
}
69-
70-
public int getCSErrorCode() {
71-
return this.csErrorCode;
72-
}
7388
}

0 commit comments

Comments
 (0)