Skip to content

Commit 972b8b7

Browse files
CLOUDSTACK-8855 Improve Error Message for Host Alert State and reconnect host API. (#2387)
* CLOUDSTACK-8855 Improve Error Message for Host Alert State * [CLOUDSTACK-9846] create column to save the content of alert messages Remove declaration of throws CloudRuntimeException I also removed some unused variables and comments left behind This closes #837 * Isolate a problematic test "smoke/test_certauthority_root"
1 parent 989e4e2 commit 972b8b7

File tree

19 files changed

+286
-339
lines changed

19 files changed

+286
-339
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ env:
3333
- PATH=$HOME/.local/bin:$PATH
3434
matrix:
3535
# Keep the TESTS sorted by name and grouped by type
36+
- TESTS="smoke/test_certauthority_root"
37+
3638
- TESTS="smoke/test_accounts
3739
smoke/test_affinity_groups
3840
smoke/test_affinity_groups_projects
39-
smoke/test_certauthority_root
4041
smoke/test_deploy_vgpu_enabled_vm
4142
smoke/test_deploy_vm_iso
4243
smoke/test_deploy_vm_root_resize

api/src/main/java/com/cloud/alert/Alert.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ public interface Alert extends Identity, InternalIdentity {
4141
boolean getArchived();
4242

4343
String getName();
44+
45+
String getContent();
4446
}

api/src/main/java/com/cloud/resource/ResourceService.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
import java.util.List;
2020

21-
import com.cloud.dc.DataCenter;
2221
import org.apache.cloudstack.api.command.admin.cluster.AddClusterCmd;
2322
import org.apache.cloudstack.api.command.admin.cluster.DeleteClusterCmd;
2423
import org.apache.cloudstack.api.command.admin.host.AddHostCmd;
@@ -29,6 +28,8 @@
2928
import org.apache.cloudstack.api.command.admin.host.UpdateHostCmd;
3029
import org.apache.cloudstack.api.command.admin.host.UpdateHostPasswordCmd;
3130

31+
import com.cloud.dc.DataCenter;
32+
import com.cloud.exception.AgentUnavailableException;
3233
import com.cloud.exception.DiscoveryException;
3334
import com.cloud.exception.InvalidParameterValueException;
3435
import com.cloud.exception.ResourceInUseException;
@@ -41,25 +42,17 @@ public interface ResourceService {
4142
/**
4243
* Updates a host
4344
*
44-
* @param cmd
45-
* - the command specifying hostId
46-
* @return hostObject
47-
* @throws NoTransitionException
45+
* @param cmd - the command specifying hostId
4846
*/
4947
Host updateHost(UpdateHostCmd cmd) throws NoTransitionException;
5048

5149
Host cancelMaintenance(CancelMaintenanceCmd cmd);
5250

53-
Host reconnectHost(ReconnectHostCmd cmd);
51+
Host reconnectHost(ReconnectHostCmd cmd) throws AgentUnavailableException;
5452

5553
/**
5654
* We will automatically create an Apache CloudStack cluster to attach to the external cluster and return a hyper host to perform
5755
* host related operation within the cluster
58-
*
59-
* @param cmd
60-
* @return
61-
* @throws IllegalArgumentException
62-
* @throws DiscoveryException
6356
*/
6457
List<? extends Cluster> discoverCluster(AddClusterCmd cmd) throws IllegalArgumentException, DiscoveryException, ResourceInUseException;
6558

@@ -75,12 +68,6 @@ public interface ResourceService {
7568

7669
/**
7770
* Deletes a host
78-
*
79-
* @param hostId
80-
* TODO
81-
* @param isForced
82-
* TODO
83-
*
8471
* @param true if deleted, false otherwise
8572
*/
8673
boolean deleteHost(long hostId, boolean isForced, boolean isForceDeleteStorage);

api/src/main/java/org/apache/cloudstack/api/command/admin/host/ReconnectHostCmd.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
// under the License.
1717
package org.apache.cloudstack.api.command.admin.host;
1818

19-
import org.apache.log4j.Logger;
20-
2119
import org.apache.cloudstack.api.APICommand;
2220
import org.apache.cloudstack.api.ApiCommandJobType;
2321
import org.apache.cloudstack.api.ApiConstants;
@@ -27,13 +25,16 @@
2725
import org.apache.cloudstack.api.ServerApiException;
2826
import org.apache.cloudstack.api.response.HostResponse;
2927
import org.apache.cloudstack.context.CallContext;
28+
import org.apache.log4j.Logger;
3029

3130
import com.cloud.event.EventTypes;
31+
import com.cloud.exception.AgentUnavailableException;
32+
import com.cloud.exception.InvalidParameterValueException;
3233
import com.cloud.host.Host;
3334
import com.cloud.user.Account;
35+
import com.cloud.utils.exception.CloudRuntimeException;
3436

35-
@APICommand(name = "reconnectHost", description = "Reconnects a host.", responseObject = HostResponse.class,
36-
requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
37+
@APICommand(name = "reconnectHost", description = "Reconnects a host.", responseObject = HostResponse.class, requestHasSensitiveInfo = false, responseHasSensitiveInfo = false)
3738
public class ReconnectHostCmd extends BaseAsyncCmd {
3839
public static final Logger s_logger = Logger.getLogger(ReconnectHostCmd.class.getName());
3940

@@ -101,16 +102,15 @@ public Long getInstanceId() {
101102
public void execute() {
102103
try {
103104
Host result = _resourceService.reconnectHost(this);
104-
if (result != null) {
105-
HostResponse response = _responseGenerator.createHostResponse(result);
106-
response.setResponseName(getCommandName());
107-
this.setResponseObject(response);
108-
} else {
109-
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "Failed to reconnect host");
110-
}
111-
} catch (Exception ex) {
112-
s_logger.warn("Exception: ", ex);
113-
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, ex.getMessage());
105+
HostResponse response = _responseGenerator.createHostResponse(result);
106+
response.setResponseName(getCommandName());
107+
this.setResponseObject(response);
108+
} catch (InvalidParameterValueException e) {
109+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, e.getMessage());
110+
} catch (CloudRuntimeException e) {
111+
throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, e.getMessage());
112+
} catch (AgentUnavailableException e) {
113+
throw new ServerApiException(ApiErrorCode.RESOURCE_UNAVAILABLE_ERROR, e.getMessage());
114114
}
115115
}
116116
}

engine/components-api/src/main/java/com/cloud/agent/AgentManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
*/
3737
public interface AgentManager {
3838
static final ConfigKey<Integer> Wait = new ConfigKey<Integer>("Advanced", Integer.class, "wait", "1800", "Time in seconds to wait for control commands to return",
39-
true);
39+
true);
4040

4141
public enum TapAgentsAction {
4242
Add, Del, Contains,
@@ -143,7 +143,7 @@ public enum TapAgentsAction {
143143

144144
public void pullAgentOutMaintenance(long hostId);
145145

146-
boolean reconnect(long hostId);
146+
void reconnect(long hostId) throws AgentUnavailableException;
147147

148148
void rescan();
149149

0 commit comments

Comments
 (0)