Search in sources :

Example 6 with DetailedStackStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus in project cloudbreak by hortonworks.

the class ProviderChecker method updateAndGetStatuses.

public List<ProviderSyncResult> updateAndGetStatuses(Stack stack, Set<InstanceMetaData> checkableInstances, Map<InstanceMetaData, DetailedStackStatus> instanceHealthStatusMap, boolean updateStatusFromFlow) {
    return checkedMeasure(() -> {
        List<ProviderSyncResult> results = new ArrayList<>();
        List<CloudVmInstanceStatus> statuses = stackInstanceProviderChecker.checkStatus(stack, checkableInstances);
        if (!updateStatusFromFlow && flowLogService.isOtherFlowRunning(stack.getId())) {
            throw new InterruptSyncingException(":::Auto sync::: interrupt syncing in updateAndGetStatuses, flow is running on freeipa stack " + stack.getName());
        } else {
            statuses.forEach(s -> {
                Optional<InstanceMetaData> instanceMetaData = checkableInstances.stream().filter(i -> s.getCloudInstance().getInstanceId().equals(i.getInstanceId())).findFirst();
                if (instanceMetaData.isPresent()) {
                    InstanceStatus instanceStatus = updateStatuses(s, instanceMetaData.get(), instanceHealthStatusMap);
                    if (instanceStatus != null) {
                        results.add(new ProviderSyncResult("", instanceStatus, false, s.getCloudInstance().getInstanceId()));
                    }
                } else {
                    LOGGER.info(":::Auto sync::: Cannot find instanceMetaData");
                }
            });
            checkableInstances.forEach(instanceMetaData -> {
                if (statuses.stream().noneMatch(s -> s.getCloudInstance().getInstanceId().equals(instanceMetaData.getInstanceId()))) {
                    if (updateStatus) {
                        setStatusIfNotTheSame(instanceMetaData, InstanceStatus.DELETED_ON_PROVIDER_SIDE);
                        instanceMetaDataService.save(instanceMetaData);
                    } else {
                        LOGGER.debug("updateStatus flag is false, don't update status");
                    }
                }
            });
            return results;
        }
    }, LOGGER, ":::Auto sync::: provider is checked in {}ms");
}
Also used : InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) InstanceMetaDataService(com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService) Benchmark.checkedMeasure(com.sequenceiq.cloudbreak.util.Benchmark.checkedMeasure) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) Set(java.util.Set) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) Component(org.springframework.stereotype.Component) Map(java.util.Map) Optional(java.util.Optional) FlowLogService(com.sequenceiq.flow.core.FlowLogService) DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) InstanceMetaData(com.sequenceiq.freeipa.entity.InstanceMetaData) Stack(com.sequenceiq.freeipa.entity.Stack) InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList)

Example 7 with DetailedStackStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus in project cloudbreak by hortonworks.

the class ProviderChecker method updateStatuses.

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;
}
Also used : InstanceStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)

Example 8 with DetailedStackStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus in project cloudbreak by hortonworks.

the class DistroXServiceTest method testWithValidEnvironmentNameValueButTheActualEnvIsNotAvailableBadRequestExceptionShouldCome.

@ParameterizedTest
@EnumSource(value = com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus.class)
@DisplayName("When request contains a valid environment name but that environment is not in the AVAILABLE state then BadRequestException should come")
void testWithValidEnvironmentNameValueButTheActualEnvIsNotAvailableBadRequestExceptionShouldCome(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus detailedStackStatus) {
    if (!detailedStackStatus.getAvailabilityStatus().isAvailable()) {
        String envName = "someAwesomeExistingButNotAvailableEnvironment";
        DistroXV1Request r = new DistroXV1Request();
        r.setEnvironmentName(envName);
        DetailedEnvironmentResponse envResponse = new DetailedEnvironmentResponse();
        envResponse.setCrn("crn");
        envResponse.setName(envName);
        DescribeFreeIpaResponse freeipa = new DescribeFreeIpaResponse();
        freeipa.setAvailabilityStatus(detailedStackStatus.getAvailabilityStatus());
        freeipa.setStatus(detailedStackStatus.getStatus());
        when(freeipaClientService.getByEnvironmentCrn("crn")).thenReturn(freeipa);
        when(environmentClientService.getByName(envName)).thenReturn(envResponse);
        BadRequestException err = assertThrows(BadRequestException.class, () -> underTest.post(r));
        assertEquals(String.format("If you want to provision a Data Hub then the FreeIPA instance must be running in the '%s' Environment.", envName), err.getMessage());
        verify(environmentClientService, calledOnce()).getByName(any());
        verify(environmentClientService, calledOnce()).getByName(eq(envName));
        verify(stackOperations, never()).post(any(), any(), any(), anyBoolean());
        verify(workspaceService, never()).getForCurrentUser();
        verify(stackRequestConverter, never()).convert(any(DistroXV1Request.class));
    }
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) DetailedEnvironmentResponse(com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse) BadRequestException(com.sequenceiq.cloudbreak.common.exception.BadRequestException) DistroXV1Request(com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with DetailedStackStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus in project cloudbreak by hortonworks.

the class UpgradeCcmService method checkPrerequisitesState.

public void checkPrerequisitesState(Long stackId) {
    DetailedStackStatus detailedStatus = UPGRADE_CCM_IN_PROGRESS;
    String statusReason = "Checking prerequisites";
    stackUpdater.updateStackStatus(stackId, detailedStatus, statusReason);
}
Also used : DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus)

Example 10 with DetailedStackStatus

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus in project cloudbreak by hortonworks.

the class UpgradeCcmService method registerClusterProxyState.

public void registerClusterProxyState(Long stackId) {
    DetailedStackStatus detailedStatus = UPGRADE_CCM_IN_PROGRESS;
    String statusReason = "Registering into Cluster Proxy";
    stackUpdater.updateStackStatus(stackId, detailedStatus, statusReason);
}
Also used : DetailedStackStatus(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus)

Aggregations

DetailedStackStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.DetailedStackStatus)17 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)3 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)2 InstanceStatus (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceStatus)2 StackStatus (com.sequenceiq.freeipa.entity.StackStatus)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 RPCResponse (com.sequenceiq.cloudbreak.client.RPCResponse)1 BadRequestException (com.sequenceiq.cloudbreak.common.exception.BadRequestException)1 Benchmark.checkedMeasure (com.sequenceiq.cloudbreak.util.Benchmark.checkedMeasure)1 DistroXV1Request (com.sequenceiq.distrox.api.v1.distrox.model.DistroXV1Request)1 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)1 FlowLogService (com.sequenceiq.flow.core.FlowLogService)1 Status (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.Status)1 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)1 Stack (com.sequenceiq.freeipa.entity.Stack)1 InstanceMetaDataService (com.sequenceiq.freeipa.service.stack.instance.InstanceMetaDataService)1 LinkedList (java.util.LinkedList)1 List (java.util.List)1