public boolean isHAEligible(final HAResource resource) { return resource != null && isHAEnabledForZone(resource) && isHAEnabledForCluster(resource) && isHAEligibleForResource(resource); }
public void processResult(boolean result, Throwable e) { final HAConfig haConfig = getHaConfig(); final HAResourceCounter counter = haManager.getHACounter(haConfig.getResourceId(), haConfig.getResourceType()); if (result) { counter.resetRecoveryCounter(); haManager.transitionHAState(HAConfig.Event.Fenced, haConfig); getHaProvider().fenceSubResources(getResource()); getHaProvider().enableMaintenance(getResource()); } getHaProvider().sendAlert(getResource(), HAConfig.HAState.Fencing); } }
public void processResult(boolean result, Throwable e) { final HAConfig haConfig = getHaConfig(); final HAResourceCounter counter = haManager.getHACounter(haConfig.getResourceId(), haConfig.getResourceType()); counter.incrRecoveryCounter(); counter.resetActivityCounter(); if (result) { haManager.transitionHAState(HAConfig.Event.Recovered, haConfig); getHaProvider().fenceSubResources(getResource()); } getHaProvider().sendAlert(getResource(), HAConfig.HAState.Recovering); } }
public void processResult(boolean result, Throwable e) { final HAConfig haConfig = getHaConfig(); final HAResourceCounter counter = haManager.getHACounter(haConfig.getResourceId(), haConfig.getResourceType()); if (result) { haManager.transitionHAState(HAConfig.Event.HealthCheckPassed, haConfig); if (haConfig.getState() == HAConfig.HAState.Fenced) { haManager.disableHA(haConfig.getResourceId(), haConfig.getResourceType()); } counter.resetSuspectTimestamp(); counter.resetActivityCounter(); counter.resetRecoveryCounter(); } else { haManager.transitionHAState(HAConfig.Event.HealthCheckFailed, haConfig); counter.markResourceSuspected(); } } }
public synchronized void processResult(boolean result, Throwable t) { final HAConfig haConfig = getHaConfig(); final HAResourceCounter counter = haManager.getHACounter(haConfig.getResourceId(), haConfig.getResourceType()); if (t != null && t instanceof HACheckerException) { haManager.transitionHAState(HAConfig.Event.Ineligible, getHaConfig()); counter.resetActivityCounter(); return; } counter.incrActivityCounter(!result); if (counter.getActivityCheckCounter() < maxActivityChecks) { haManager.transitionHAState(HAConfig.Event.TooFewActivityCheckSamples, haConfig); return; } if (counter.hasActivityThresholdExceeded(activityCheckFailureRatio)) { haManager.transitionHAState(HAConfig.Event.ActivityCheckFailureOverThresholdRatio, haConfig); } else { if (haManager.transitionHAState(HAConfig.Event.ActivityCheckFailureUnderThresholdRatio, haConfig)) { counter.markResourceDegraded(); } } counter.resetActivityCounter(); } }
private boolean isHAEligibleForResource(final HAResource resource) { if (resource == null || resource.getId() < 1L) { return false; } HAResource.ResourceType resourceType = null; if (resource instanceof Host) { resourceType = HAResource.ResourceType.Host; } if (resourceType == null) { return false; } final HAConfig haConfig = haConfigDao.findHAResource(resource.getId(), resourceType); return haConfig != null && haConfig.isEnabled() && haConfig.getState() != HAConfig.HAState.Disabled && haConfig.getState() != HAConfig.HAState.Ineligible; }
private HAProvider<HAResource> validateAndFindHAProvider(final HAConfig haConfig, final HAResource resource) { if (haConfig == null) { return null; } final HAProvider<HAResource> haProvider = haProviderMap.get(haConfig.getHaProvider()); if (haProvider != null && !haProvider.isEligible(resource)) { if (haConfig.getState() != HAConfig.HAState.Ineligible) { transitionHAState(HAConfig.Event.Ineligible, haConfig); } return null; } else if (haConfig.getState() == HAConfig.HAState.Ineligible) { transitionHAState(HAConfig.Event.Eligible, haConfig); } return haProvider; }
public HostHAResponse(final HAConfig config) { this(); if (config == null) { this.enabled = false; this.haState = HAConfig.HAState.Disabled; return; } setProvider(config.getHaProvider()); setEnabled(config.isEnabled()); setHaState(config.getState()); }
@Override public boolean preStateTransitionEvent(final HAConfig.HAState oldState, final HAConfig.Event event, final HAConfig.HAState newState, final HAConfig haConfig, final boolean status, final Object opaque) { if (oldState != newState || newState == HAConfig.HAState.Suspect || newState == HAConfig.HAState.Checking) { return false; } if (LOG.isTraceEnabled()) { LOG.trace("HA state pre-transition:: new state=" + newState + ", old state=" + oldState + ", for resource id=" + haConfig.getResourceId() + ", status=" + status + ", ha config state=" + haConfig.getState()); } if (status && haConfig.getState() != newState) { LOG.warn("HA state pre-transition:: HA state is not equal to transition state, HA state=" + haConfig.getState() + ", new state=" + newState); } return processHAStateChange(haConfig, newState, status); }
@Override public List<String> listHAProviders(final HAResource.ResourceType resourceType, final HAResource.ResourceSubType entityType) { final List<String> haProviderNames = new ArrayList<>(); for (final HAProvider<HAResource> haProvider : haProviders) { if (haProvider.resourceType().equals(resourceType) && haProvider.resourceSubType().equals(entityType)) { haProviderNames.add(haProvider.getClass().getSimpleName()); } } return haProviderNames; }
private boolean transitionResourceStateToDisabled(final Partition partition) { List<? extends HAResource> resources; if (partition.partitionType() == Partition.PartitionType.Cluster) { resources = hostDao.findByClusterId(partition.getId()); } else if (partition.partitionType() == Partition.PartitionType.Zone) { resources = hostDao.findByDataCenterId(partition.getId()); } else { return true; } boolean result = true; for (final HAResource resource: resources) { result = result && transitionHAState(HAConfig.Event.Disabled, haConfigDao.findHAResource(resource.getId(), resource.resourceType())); } return result; }
public synchronized HAResourceCounter getHACounter(final Long resourceId, final HAResource.ResourceType resourceType) { final String key = resourceCounterKey(resourceId, resourceType); if (!haCounterMap.containsKey(key)) { haCounterMap.put(key, new HAResourceCounter()); } return haCounterMap.get(key); }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { if (!Enums.getIfPresent(HAResource.ResourceSubType.class, hypervisorType).isPresent()) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Invalid or unsupported host hypervisor type provided. Supported types are: " + Arrays.toString(HAResource.ResourceSubType.values())); } final List<String> hostHAProviders = haConfigManager.listHAProviders(HAResource.ResourceType.Host, getHypervisorType()); setupResponse(hostHAProviders); } }
public HAResource.ResourceSubType getHypervisorType() { return HAResource.ResourceSubType.valueOf(hypervisorType); }
private String resourceCounterKey(final Long resourceId, final HAResource.ResourceType resourceType) { return resourceId.toString() + resourceType.toString(); }
private boolean checkHAOwnership(final HAConfig haConfig) { // Skip for resources not owned by this mgmt server return !(haConfig.getManagementServerId() != null && haConfig.getManagementServerId() != ManagementServerNode.getManagementServerId()); }
public synchronized void purgeHACounter(final Long resourceId, final HAResource.ResourceType resourceType) { final String key = resourceCounterKey(resourceId, resourceType); if (haCounterMap.containsKey(key)) { haCounterMap.remove(key); } }
@Override @ActionEvent(eventType = EventTypes.EVENT_HA_RESOURCE_ENABLE, eventDescription = "enabling HA for resource") public boolean enableHA(final Long resourceId, final HAResource.ResourceType resourceType) { Preconditions.checkArgument(resourceId != null && resourceId > 0L); Preconditions.checkArgument(resourceType != null); return configureHA(resourceId, resourceType, true, null); }
@Override public void execute() throws ResourceUnavailableException, InsufficientCapacityException, ServerApiException, ConcurrentOperationException, ResourceAllocationException, NetworkRuleConflictException { final List<HAConfig> hostHAConfig = haConfigManager.listHAResources(getHostId(), HAResource.ResourceType.Host); setupResponse(hostHAConfig); } }
@Override public boolean postStateTransitionEvent(final StateMachine2.Transition<HAConfig.HAState, HAConfig.Event> transition, final HAConfig haConfig, final boolean status, final Object opaque) { if (LOG.isTraceEnabled()) { 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()); } if (status && haConfig.getState() != transition.getToState()) { LOG.warn("HA state post-transition:: HA state is not equal to transition state, HA state=" + haConfig.getState() + ", new state=" + transition.getToState()); } return processHAStateChange(haConfig, transition.getToState(), status); }