Search in sources :

Example 1 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class ClusterUpgradeHandler method getRemoteDataContext.

private Optional<String> getRemoteDataContext(Stack stack) {
    Optional<String> remoteDataContext = Optional.empty();
    if (!stack.isDatalake() && StringUtils.isNotEmpty(stack.getDatalakeCrn())) {
        Stack datalake = stackService.getByCrn(stack.getDatalakeCrn());
        LOGGER.info("Fetch the Remote Data Context from {} to update the Data Hub", stack.getName());
        ClusterApi datalakeConnector = clusterApiConnectors.getConnector(datalake);
        remoteDataContext = Optional.of(datalakeConnector.getSdxContext());
    }
    return remoteDataContext;
}
Also used : ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 2 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class ClusterUpscaleServiceTest method testInstallServicesOnNewHostWithRestartButThereIsAnUnhealthyNode.

@Test
public void testInstallServicesOnNewHostWithRestartButThereIsAnUnhealthyNode() throws CloudbreakException {
    Stack stack = new Stack();
    stack.setId(1L);
    Cluster cluster = new Cluster();
    cluster.setId(2L);
    stack.setCluster(cluster);
    when(stackService.getByIdWithClusterInTransaction(eq(1L))).thenReturn(stack);
    ClusterApi clusterApi = mock(ClusterApi.class);
    when(clusterApiConnectors.getConnector(any(Stack.class))).thenReturn(clusterApi);
    HostGroup hostGroup = new HostGroup();
    InstanceGroup instanceGroup = new InstanceGroup();
    InstanceMetaData im1 = new InstanceMetaData();
    im1.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
    InstanceMetaData im2 = new InstanceMetaData();
    im2.setInstanceStatus(InstanceStatus.SERVICES_HEALTHY);
    InstanceMetaData im3 = new InstanceMetaData();
    im3.setInstanceStatus(InstanceStatus.DELETED_BY_PROVIDER);
    stack.setInstanceGroups(Set.of(instanceGroup));
    instanceGroup.setInstanceMetaData(Set.of(im1, im2, im3));
    hostGroup.setInstanceGroup(instanceGroup);
    when(hostGroupService.getByClusterWithRecipes(any())).thenReturn(Set.of(hostGroup));
    when(parcelService.removeUnusedParcelComponents(stack)).thenReturn(new ParcelOperationStatus(Collections.emptyMap(), Collections.emptyMap()));
    underTest.installServicesOnNewHosts(1L, Set.of("master"), true, true);
    verify(clusterApi, times(1)).upscaleCluster(any());
    verify(clusterApi, times(0)).restartAll(false);
    verify(parcelService).removeUnusedParcelComponents(stack);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 3 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class ClusterUpgradeExistingUpgradeCommandValidationHandler method doAccept.

@Override
protected Selectable doAccept(HandlerEvent<ClusterUpgradeExistingUpgradeCommandValidationEvent> event) {
    LOGGER.debug("Accepting Cluster upgrade existing upgradeCDH command validation event.");
    ClusterUpgradeExistingUpgradeCommandValidationEvent request = event.getData();
    Image targetImage = request.getImage();
    Long stackId = request.getResourceId();
    Stack stack = getStack(stackId);
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    Optional<ClusterManagerCommand> optionalUpgradeCommand = connector.clusterStatusService().findCommand(stack, ClusterCommandType.UPGRADE_CLUSTER);
    if (optionalUpgradeCommand.isEmpty()) {
        LOGGER.debug("There is no existing upgradeCDH command, validation passed successfully");
        return new ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(stackId);
    } else {
        ClusterManagerCommand upgradeCommand = optionalUpgradeCommand.get();
        if (upgradeCommand.getActive() || (!upgradeCommand.getSuccess() && upgradeCommand.getRetryable())) {
            return validateIfExistingRuntimeMatchesTargetRuntime(stack, connector, targetImage);
        } else {
            LOGGER.debug("There is no retryable upgradeCDH command, validation passed successfully");
            return new ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(stackId);
        }
    }
}
Also used : ClusterUpgradeExistingUpgradeCommandValidationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeExistingUpgradeCommandValidationEvent) ClusterManagerCommand(com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Image(com.sequenceiq.cloudbreak.cloud.model.Image) ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.datalake.upgrade.validation.event.ClusterUpgradeExistingUpgradeCommandValidationFinishedEvent) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Example 4 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class StackStatusCheckerJob method doSync.

private void doSync(Stack stack) {
    ClusterApi connector = clusterApiConnectors.getConnector(stack);
    Set<InstanceMetaData> runningInstances = instanceMetaDataService.findNotTerminatedAndNotZombieForStack(stack.getId());
    try {
        if (isClusterManagerRunning(stack, connector)) {
            ExtendedHostStatuses extendedHostStatuses = getExtendedHostStatuses(stack, connector);
            Map<HostName, Set<HealthCheck>> hostStatuses = extendedHostStatuses.getHostsHealth();
            LOGGER.debug("Cluster '{}' state check, host certicates expiring: [{}], cm running, hoststates: {}", stack.getId(), extendedHostStatuses.isAnyCertExpiring(), hostStatuses);
            reportHealthAndSyncInstances(stack, runningInstances, getFailedInstancesInstanceMetadata(extendedHostStatuses, runningInstances), getNewHealthyHostNames(extendedHostStatuses, runningInstances), extendedHostStatuses.isAnyCertExpiring());
        } else {
            syncInstances(stack, runningInstances, false);
        }
    } catch (RuntimeException e) {
        LOGGER.warn("Error during sync", e);
        syncInstances(stack, runningInstances, false);
    }
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) Collectors.toSet(java.util.stream.Collectors.toSet) EnumSet(java.util.EnumSet) Set(java.util.Set) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName)

Example 5 with ClusterApi

use of com.sequenceiq.cloudbreak.cluster.api.ClusterApi in project cloudbreak by hortonworks.

the class DeregisterServicesHandler method accept.

@Override
public void accept(Event<DeregisterServicesRequest> event) {
    DeregisterServicesResult result;
    try {
        LOGGER.info("Received DeregisterServicesRequest event: {}", event.getData());
        Stack stack = stackService.getByIdWithListsInTransaction(event.getData().getResourceId());
        ClusterApi clusterApi = clusterApiConnectors.getConnector(stack);
        Optional<DatalakeDto> datalakeDto = Optional.empty();
        Optional<Stack> dataLakeOptional = datalakeService.getDatalakeStackByDatahubStack(stack);
        if (dataLakeOptional.isPresent()) {
            Stack dataLake = dataLakeOptional.get();
            HttpClientConfig httpClientConfig = tlsSecurityService.buildTLSClientConfigForPrimaryGateway(dataLake.getId(), dataLake.getClusterManagerIp(), dataLake.cloudPlatform());
            datalakeDto = Optional.ofNullable(DatalakeDto.DatalakeDtoBuilder.aDatalakeDto().withGatewayPort(dataLake.getGatewayPort()).withHttpClientConfig(httpClientConfig).withPassword(dataLake.getCluster().getCloudbreakAmbariPassword()).withUser(dataLake.getCluster().getCloudbreakAmbariUser()).withName(dataLake.getName()).build());
        }
        clusterApi.clusterSecurityService().deregisterServices(stack.getName(), datalakeDto);
        LOGGER.info("Finished disabling Security");
        result = new DeregisterServicesResult(event.getData());
    } catch (Exception e) {
        LOGGER.warn("An error has occured during disabling security", e);
        result = new DeregisterServicesResult(e.getMessage(), e, event.getData());
    }
    LOGGER.info("Sending out DeregisterServicesResult: {}", result);
    eventBus.notify(result.selector(), new Event<>(event.getHeaders(), result));
    LOGGER.info("DeregisterServicesResult has been sent");
}
Also used : ClusterApi(com.sequenceiq.cloudbreak.cluster.api.ClusterApi) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) DatalakeDto(com.sequenceiq.cloudbreak.dto.datalake.DatalakeDto) DeregisterServicesResult(com.sequenceiq.cloudbreak.reactor.api.event.cluster.DeregisterServicesResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack)

Aggregations

ClusterApi (com.sequenceiq.cloudbreak.cluster.api.ClusterApi)27 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)20 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)9 Set (java.util.Set)7 ExtendedHostStatuses (com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses)6 ParcelOperationStatus (com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus)5 ClusterApiConnectors (com.sequenceiq.cloudbreak.service.cluster.ClusterApiConnectors)5 ClusterStatusService (com.sequenceiq.cloudbreak.cluster.api.ClusterStatusService)4 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)4 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)4 InstanceMetaDataService (com.sequenceiq.cloudbreak.service.stack.InstanceMetaDataService)4 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)4 Collectors (java.util.stream.Collectors)4 Inject (javax.inject.Inject)4 Test (org.junit.jupiter.api.Test)4 Logger (org.slf4j.Logger)4 LoggerFactory (org.slf4j.LoggerFactory)4 Service (org.springframework.stereotype.Service)4 InstanceStatus (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus)3 HostName (com.sequenceiq.cloudbreak.cloud.model.HostName)3