Source:
<code>private InstanceStatus updateStatuses(CloudVmInstanceStatus vmInstanceStatus, InstanceMetaData instanceMetaData, Map<InstanceMetaData, DetailedStackStatus> instanceHealthStatusMap) { LOGGER.info(":::Auto sync::: instance metadata status update in progress, new status: {}", instanceMetaData.getShortHostname(), vmInstanceStatus); InstanceStatus status = null; <START> if (DetailedStackStatus.UNREACHABLE == instanceHealthStatusMap.get(instanceMetaData)) { <END> setStatusIfNotTheSame(instanceMetaData, InstanceStatus.UNREACHABLE); status = InstanceStatus.UNREACHABLE; } else { switch (vmInstanceStatus.getStatus()) { case STARTED: setStatusIfNotTheSame(instanceMetaData, InstanceStatus.CREATED); status = InstanceStatus.CREATED; break; case STOPPED: setStatusIfNotTheSame(instanceMetaData, InstanceStatus.STOPPED); status = InstanceStatus.STOPPED; break; case FAILED: setStatusIfNotTheSame(instanceMetaData, InstanceStatus.FAILED); status = InstanceStatus.FAILED; break; case TERMINATED: setStatusIfNotTheSame(instanceMetaData, InstanceStatus.DELETED_ON_PROVIDER_SIDE); status = InstanceStatus.DELETED_ON_PROVIDER_SIDE; break; case TERMINATED_BY_PROVIDER: setStatusIfNotTheSame(instanceMetaData, InstanceStatus.DELETED_BY_PROVIDER); status = InstanceStatus.DELETED_BY_PROVIDER; break; default: LOGGER.info(":::Auto sync::: the '{}' status is not converted", vmInstanceStatus.getStatus()); } } if (updateStatus) { instanceMetaDataService.save(instanceMetaData); } else { LOGGER.debug("updateStatus flag is false, don't update status"); } return status; }</code><technical_language>I this work for cases status is unreachable. For example, if instance health is unhealthy I suspect UI report "running" rely VM status started means instance status created means UI report "running"</technical_language>

Target:
private InstanceStatus updateStatuses(CloudVmInstanceStatus vmInstanceStatus, InstanceMetaData instanceMetaData, Map<InstanceMetaData, DetailedStackStatus> instanceHealthStatusMap) { LOGGER.info(":::Auto sync::: instance metadata status update in progress, new status: {}", instanceMetaData.getShortHostname(), vmInstanceStatus); InstanceStatus status = null; switch (vmInstanceStatus.getStatus()) { case STARTED: if (DetailedStackStatus.UNREACHABLE == instanceHealthStatusMap.get(instanceMetaData)) { setStatusIfNotTheSame(instanceMetaData, InstanceStatus.UNREACHABLE); status = InstanceStatus.UNREACHABLE; } else if (DetailedStackStatus.UNHEALTHY == instanceHealthStatusMap.get(instanceMetaData)) { setStatusIfNotTheSame(instanceMetaData, InstanceStatus.UNHEALTHY); status = InstanceStatus.UNHEALTHY; } else { setStatusIfNotTheSame(instanceMetaData, InstanceStatus.CREATED); status = InstanceStatus.CREATED; } break; case STOPPED: setStatusIfNotTheSame(instanceMetaData, InstanceStatus.STOPPED); status = InstanceStatus.STOPPED; break; case FAILED: setStatusIfNotTheSame(instanceMetaData, InstanceStatus.FAILED); status = InstanceStatus.FAILED; break; case TERMINATED: setStatusIfNotTheSame(instanceMetaData, InstanceStatus.DELETED_ON_PROVIDER_SIDE); status = InstanceStatus.DELETED_ON_PROVIDER_SIDE; break; case TERMINATED_BY_PROVIDER: setStatusIfNotTheSame(instanceMetaData, InstanceStatus.DELETED_BY_PROVIDER); status = InstanceStatus.DELETED_BY_PROVIDER; break; default: LOGGER.info(":::Auto sync::: the '{}' status is not converted", vmInstanceStatus.getStatus()); } if (updateStatus) { instanceMetaDataService.save(instanceMetaData); } else { LOGGER.debug("updateStatus flag is false, don't update status"); } return status; }