Skip to content

Commit cc2c6e9

Browse files
GutoVeroneziDaniel Augusto Veronezi Salvador
andauthored
Improve logs on HAManagerImpl (#4707)
Co-authored-by: Daniel Augusto Veronezi Salvador <daniel@scclouds.com.br>
1 parent 3674e80 commit cc2c6e9

File tree

1 file changed

+44
-36
lines changed

1 file changed

+44
-36
lines changed

server/src/main/java/org/apache/cloudstack/ha/HAManagerImpl.java

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -156,19 +156,16 @@ public boolean transitionHAState(final HAConfig.Event event, final HAConfig haCo
156156
if (result) {
157157
final String message = String.format("Transitioned host HA state from:%s to:%s due to event:%s for the host id:%d",
158158
currentHAState, nextState, event, haConfig.getResourceId());
159-
if (LOG.isTraceEnabled()) {
160-
LOG.trace(message);
161-
}
159+
LOG.debug(message);
160+
162161
if (nextState == HAConfig.HAState.Recovering || nextState == HAConfig.HAState.Fencing || nextState == HAConfig.HAState.Fenced) {
163162
ActionEventUtils.onActionEvent(CallContext.current().getCallingUserId(), CallContext.current().getCallingAccountId(),
164163
Domain.ROOT_DOMAIN, EventTypes.EVENT_HA_STATE_TRANSITION, message);
165164
}
166165
}
167166
return result;
168167
} catch (NoTransitionException e) {
169-
if (LOG.isTraceEnabled()) {
170-
LOG.trace("Unable to find next HA state for current HA state: " + currentHAState + " for event: " + event + " for host" + haConfig.getResourceId());
171-
}
168+
LOG.warn(String.format("Unable to find next HA state for current HA state=[%s] for event=[%s] for host=[%s].", currentHAState, event, haConfig.getResourceId()), e);
172169
}
173170
return false;
174171
}
@@ -284,8 +281,21 @@ && isHAEnabledForCluster(resource)
284281
public void validateHAProviderConfigForResource(final Long resourceId, final HAResource.ResourceType resourceType, final HAProvider<HAResource> haProvider) {
285282
if (HAResource.ResourceType.Host.equals(resourceType)) {
286283
final Host host = hostDao.findById(resourceId);
287-
if (host.getHypervisorType() == null || haProvider.resourceSubType() == null || !host.getHypervisorType().toString().equals(haProvider.resourceSubType().toString())) {
288-
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Incompatible haprovider provided for the resource of hypervisor type:" + host.getHypervisorType());
284+
285+
if (host == null) {
286+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, String.format("Resource [%s] not found.", resourceId));
287+
}
288+
289+
if (host.getHypervisorType() == null) {
290+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, String.format("No hypervisor type provided on resource [%s].", resourceId));
291+
}
292+
293+
if (haProvider.resourceSubType() == null) {
294+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "No hypervisor type provided on haprovider.");
295+
}
296+
297+
if (!host.getHypervisorType().toString().equals(haProvider.resourceSubType().toString())) {
298+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, String.format("Incompatible haprovider provided [%s] for the resource [%s] of hypervisor type: [%s].", haProvider.resourceSubType().toString(), host.getId(),host.getHypervisorType()));
289299
}
290300
}
291301
}
@@ -298,14 +308,10 @@ public Boolean isVMAliveOnHost(final Host host) throws Investigator.UnknownVM {
298308
final HAConfig haConfig = haConfigDao.findHAResource(host.getId(), HAResource.ResourceType.Host);
299309
if (haConfig != null) {
300310
if (haConfig.getState() == HAConfig.HAState.Fenced) {
301-
if (LOG.isDebugEnabled()){
302-
LOG.debug("HA: Host is fenced " + host.getId());
303-
}
311+
LOG.debug(String.format("HA: Host [%s] is fenced.", host.getId()));
304312
return false;
305313
}
306-
if (LOG.isDebugEnabled()){
307-
LOG.debug("HA: HOST is alive " + host.getId());
308-
}
314+
LOG.debug(String.format("HA: Host [%s] is alive.", host.getId()));
309315
return true;
310316
}
311317
throw new Investigator.UnknownVM();
@@ -315,14 +321,10 @@ public Status getHostStatus(final Host host) {
315321
final HAConfig haConfig = haConfigDao.findHAResource(host.getId(), HAResource.ResourceType.Host);
316322
if (haConfig != null) {
317323
if (haConfig.getState() == HAConfig.HAState.Fenced) {
318-
if (LOG.isDebugEnabled()){
319-
LOG.debug("HA: Agent is available/suspect/checking Up " + host.getId());
320-
}
324+
LOG.debug(String.format("HA: Agent [%s] is available/suspect/checking Up.", host.getId()));
321325
return Status.Down;
322326
} else if (haConfig.getState() == HAConfig.HAState.Degraded || haConfig.getState() == HAConfig.HAState.Recovering || haConfig.getState() == HAConfig.HAState.Fencing) {
323-
if (LOG.isDebugEnabled()){
324-
LOG.debug("HA: Agent is disconnected " + host.getId());
325-
}
327+
LOG.debug(String.format("HA: Agent [%s] is disconnected. State: %s, %s.", host.getId(), haConfig.getState(), haConfig.getState().getDescription()));
326328
return Status.Disconnected;
327329
}
328330
return Status.Up;
@@ -351,7 +353,7 @@ public Boolean doInTransaction(TransactionStatus status) {
351353
haConfig.setResourceId(resourceId);
352354
haConfig.setResourceType(resourceType);
353355
if (Strings.isNullOrEmpty(haConfig.getHaProvider())) {
354-
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "HAProvider is not provided for the resource, failing configuration.");
356+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, String.format("HAProvider is not provided for the resource [%s], failing configuration.", resourceId));
355357
}
356358
if (haConfigDao.persist(haConfig) != null) {
357359
return true;
@@ -364,7 +366,7 @@ public Boolean doInTransaction(TransactionStatus status) {
364366
haConfig.setHaProvider(haProvider);
365367
}
366368
if (Strings.isNullOrEmpty(haConfig.getHaProvider())) {
367-
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "HAProvider is not provided for the resource, failing configuration.");
369+
throw new ServerApiException(ApiErrorCode.PARAM_ERROR, String.format("HAProvider is not provided for the resource [%s], failing configuration.", resourceId));
368370
}
369371
return haConfigDao.update(haConfig.getId(), haConfig);
370372
}
@@ -381,7 +383,7 @@ public boolean configureHA(final Long resourceId, final HAResource.ResourceType
381383
Preconditions.checkArgument(!Strings.isNullOrEmpty(haProvider));
382384

383385
if (!haProviderMap.containsKey(haProvider.toLowerCase())) {
384-
throw new CloudRuntimeException("Given HA provider does not exist.");
386+
throw new CloudRuntimeException(String.format("Given HA provider [%s] does not exist.", haProvider));
385387
}
386388
validateHAProviderConfigForResource(resourceId, resourceType, haProviderMap.get(haProvider.toLowerCase()));
387389
return configureHA(resourceId, resourceType, null, haProvider.toLowerCase());
@@ -533,22 +535,21 @@ public boolean preStateTransitionEvent(final HAConfig.HAState oldState, final HA
533535
if (oldState != newState || newState == HAConfig.HAState.Suspect || newState == HAConfig.HAState.Checking) {
534536
return false;
535537
}
536-
if (LOG.isTraceEnabled()) {
537-
LOG.trace("HA state pre-transition:: new state=" + newState + ", old state=" + oldState + ", for resource id=" + haConfig.getResourceId() + ", status=" + status + ", ha config state=" + haConfig.getState());
538-
}
538+
539+
LOG.debug(String.format("HA state pre-transition:: new state=[%s], old state=[%s], for resource id=[%s], status=[%s], ha config state=[%s]." , newState, oldState, haConfig.getResourceId(), status, haConfig.getState()));
540+
539541
if (status && haConfig.getState() != newState) {
540-
LOG.warn("HA state pre-transition:: HA state is not equal to transition state, HA state=" + haConfig.getState() + ", new state=" + newState);
542+
LOG.warn(String.format("HA state pre-transition:: HA state is not equal to transition state, HA state=[%s], new state=[%s].", haConfig.getState(), newState));
541543
}
542544
return processHAStateChange(haConfig, newState, status);
543545
}
544546

545547
@Override
546548
public boolean postStateTransitionEvent(final StateMachine2.Transition<HAConfig.HAState, HAConfig.Event> transition, final HAConfig haConfig, final boolean status, final Object opaque) {
547-
if (LOG.isTraceEnabled()) {
548-
LOG.trace("HA state post-transition:: new state=" + transition.getToState() + ", old state=" + transition.getCurrentState() + ", for resource id=" + haConfig.getResourceId() + ", status=" + status + ", ha config state=" + haConfig.getState());
549-
}
549+
LOG.debug(String.format("HA state post-transition:: new state=[%s], old state=[%s], for resource id=[%s], status=[%s], ha config state=[%s].", transition.getToState(), transition.getCurrentState(), haConfig.getResourceId(), status, haConfig.getState()));
550+
550551
if (status && haConfig.getState() != transition.getToState()) {
551-
LOG.warn("HA state post-transition:: HA state is not equal to transition state, HA state=" + haConfig.getState() + ", new state=" + transition.getToState());
552+
LOG.warn(String.format("HA state post-transition:: HA state is not equal to transition state, HA state=[%s], new state=[%s].", haConfig.getState(), transition.getToState()));
552553
}
553554
return processHAStateChange(haConfig, transition.getToState(), status);
554555
}
@@ -605,7 +606,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
605606
pollManager.submitTask(new HAManagerBgPollTask());
606607
HAConfig.HAState.getStateMachine().registerListener(this);
607608

608-
LOG.debug("HA manager has been configured");
609+
LOG.debug("HA manager has been configured.");
609610
return true;
610611
}
611612

@@ -639,12 +640,15 @@ public ConfigKey<?>[] getConfigKeys() {
639640
private final class HAManagerBgPollTask extends ManagedContextRunnable implements BackgroundPollTask {
640641
@Override
641642
protected void runInContext() {
643+
HAConfig currentHaConfig = null;
644+
642645
try {
643-
if (LOG.isTraceEnabled()) {
644-
LOG.trace("HA health check task is running...");
645-
}
646+
LOG.debug("HA health check task is running...");
647+
646648
final List<HAConfig> haConfigList = new ArrayList<HAConfig>(haConfigDao.listAll());
647649
for (final HAConfig haConfig : haConfigList) {
650+
currentHaConfig = haConfig;
651+
648652
if (haConfig == null) {
649653
continue;
650654
}
@@ -712,7 +716,11 @@ protected void runInContext() {
712716
}
713717
}
714718
} catch (Throwable t) {
715-
LOG.error("Error trying to perform health checks in HA manager", t);
719+
if (currentHaConfig != null) {
720+
LOG.error(String.format("Error trying to perform health checks in HA manager [%s].", currentHaConfig.getHaProvider()), t);
721+
} else {
722+
LOG.error("Error trying to perform health checks in HA manager.", t);
723+
}
716724
}
717725
}
718726

0 commit comments

Comments
 (0)