Search in sources :

Example 6 with ApiHost

use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.

the class ClouderaManagerSetupService method configureCmMgmtServices.

private void configureCmMgmtServices(TemplatePreparationObject templatePreparationObject, String sdxCrn, Telemetry telemetry, String sdxContextName, ProxyConfig proxyConfig) throws ApiException {
    Optional<ApiHost> optionalCmHost = getCmHost(templatePreparationObject, apiClient);
    if (optionalCmHost.isPresent()) {
        ApiHost cmHost = optionalCmHost.get();
        ApiHostRef cmHostRef = new ApiHostRef();
        cmHostRef.setHostId(cmHost.getHostId());
        cmHostRef.setHostname(cmHost.getHostname());
        mgmtSetupService.setupMgmtServices(stack, apiClient, cmHostRef, telemetry, sdxContextName, sdxCrn, proxyConfig);
    } else {
        LOGGER.warn("Unable to determine Cloudera Manager host. Skipping management services installation.");
    }
}
Also used : ApiHostRef(com.cloudera.api.swagger.model.ApiHostRef) ApiHost(com.cloudera.api.swagger.model.ApiHost)

Example 7 with ApiHost

use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.

the class ClouderaManagerClusterStatusService method getCertCheck.

private static Optional<HealthCheck> getCertCheck(ApiHost apiHost) {
    Optional<ApiHealthCheck> healthCheck = emptyIfNull(apiHost.getHealthChecks()).stream().filter(health -> HOST_AGENT_CERTIFICATE_EXPIRY.equals(health.getName())).findFirst();
    if (healthCheck.isPresent()) {
        HealthCheckResult result = ApiHealthSummary.BAD.equals(healthCheck.get().getSummary()) || ApiHealthSummary.CONCERNING.equals(healthCheck.get().getSummary()) ? HealthCheckResult.UNHEALTHY : HealthCheckResult.HEALTHY;
        Optional<String> reason = Optional.ofNullable(healthCheck.get().getSummary()).map(apiSum -> "Cert health on CM: " + apiSum.getValue());
        return Optional.of(new HealthCheck(HealthCheckType.CERT, result, reason));
    }
    return Optional.empty();
}
Also used : CloudbreakException(com.sequenceiq.cloudbreak.service.CloudbreakException) HealthCheckResult(com.sequenceiq.cloudbreak.common.type.HealthCheckResult) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) ClusterClientInitException(com.sequenceiq.cloudbreak.cluster.service.ClusterClientInitException) ExtendedHostStatuses(com.sequenceiq.cloudbreak.cluster.status.ExtendedHostStatuses) LoggerFactory(org.slf4j.LoggerFactory) ApiService(com.cloudera.api.swagger.model.ApiService) ApiRole(com.cloudera.api.swagger.model.ApiRole) StringUtils(org.apache.commons.lang3.StringUtils) ApiException(com.cloudera.api.swagger.client.ApiException) ClusterCommandType(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterCommandType) ClustersResourceApi(com.cloudera.api.swagger.ClustersResourceApi) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) BigDecimal(java.math.BigDecimal) Collectors.toMap(java.util.stream.Collectors.toMap) Pair(org.apache.commons.lang3.tuple.Pair) Map(java.util.Map) ClouderaManagerResourceApi(com.cloudera.api.swagger.ClouderaManagerResourceApi) SyncApiCommandRetriever(com.sequenceiq.cloudbreak.cm.commands.SyncApiCommandRetriever) Collection(java.util.Collection) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) Set(java.util.Set) HttpClientConfig(com.sequenceiq.cloudbreak.client.HttpClientConfig) Collectors(java.util.stream.Collectors) ApiVersionInfo(com.cloudera.api.swagger.model.ApiVersionInfo) Collectors.joining(java.util.stream.Collectors.joining) Sets(com.google.common.collect.Sets) ClusterStatus(com.sequenceiq.cloudbreak.cluster.status.ClusterStatus) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) ApiHealthSummary(com.cloudera.api.swagger.model.ApiHealthSummary) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) CollectionUtils.emptyIfNull(org.apache.commons.collections4.CollectionUtils.emptyIfNull) Joiner(com.google.common.base.Joiner) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ApiCommand(com.cloudera.api.swagger.model.ApiCommand) CMRepositoryVersionUtil(com.sequenceiq.cloudbreak.cmtemplate.CMRepositoryVersionUtil) ApiClient(com.cloudera.api.swagger.client.ApiClient) Collectors.groupingBy(java.util.stream.Collectors.groupingBy) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ClusterStatusResult(com.sequenceiq.cloudbreak.cluster.status.ClusterStatusResult) ClouderaManagerClientInitException(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerClientInitException) HashMap(java.util.HashMap) Function(java.util.function.Function) Scope(org.springframework.context.annotation.Scope) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) Inject(javax.inject.Inject) Value(org.springframework.beans.factory.annotation.Value) ClouderaManagerApiClientProvider(com.sequenceiq.cloudbreak.cm.client.ClouderaManagerApiClientProvider) Service(org.springframework.stereotype.Service) ApiHost(com.cloudera.api.swagger.model.ApiHost) Collectors.mapping(java.util.stream.Collectors.mapping) RolesResourceApi(com.cloudera.api.swagger.RolesResourceApi) ApiServiceState(com.cloudera.api.swagger.model.ApiServiceState) ApiHealthCheck(com.cloudera.api.swagger.model.ApiHealthCheck) HealthCheckType(com.sequenceiq.cloudbreak.common.type.HealthCheckType) Logger(org.slf4j.Logger) ClusterStatusService(com.sequenceiq.cloudbreak.cluster.api.ClusterStatusService) TimeUnit(java.util.concurrent.TimeUnit) HostName.hostName(com.sequenceiq.cloudbreak.cloud.model.HostName.hostName) Collectors.toList(java.util.stream.Collectors.toList) ClusterManagerCommand(com.sequenceiq.cloudbreak.cluster.model.ClusterManagerCommand) HostName(com.sequenceiq.cloudbreak.cloud.model.HostName) RetryTemplate(org.springframework.retry.support.RetryTemplate) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ApiHealthCheck(com.cloudera.api.swagger.model.ApiHealthCheck) HealthCheck(com.sequenceiq.cloudbreak.common.type.HealthCheck) ApiHealthCheck(com.cloudera.api.swagger.model.ApiHealthCheck) HealthCheckResult(com.sequenceiq.cloudbreak.common.type.HealthCheckResult)

Example 8 with ApiHost

use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.

the class ClouderaManagerModificationServiceTest method setUpListClusterHosts.

private void setUpListClusterHosts() throws ApiException {
    ApiHostList clusterHostsRef = new ApiHostList().items(List.of(new ApiHost().hostname("original")));
    when(clustersResourceApi.listHosts(eq(STACK_NAME), eq(null), eq(null), eq(null))).thenReturn(clusterHostsRef);
    when(clouderaManagerApiFactory.getClustersResourceApi(eq(apiClientMock))).thenReturn(clustersResourceApi);
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiHost(com.cloudera.api.swagger.model.ApiHost)

Example 9 with ApiHost

use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.

the class ClouderaManagerSecurityServiceTest method createApiHostList.

private ApiHostList createApiHostList() {
    ApiHostList apiHostList = new ApiHostList();
    ApiClusterRef clusterRef = new ApiClusterRef();
    ApiHost apiHost1 = new ApiHost().hostId("host-1").clusterRef(clusterRef);
    ApiHost apiHost2 = new ApiHost().hostId("host@company.com 2").clusterRef(clusterRef);
    apiHostList.items(List.of(apiHost1, apiHost2));
    return apiHostList;
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiClusterRef(com.cloudera.api.swagger.model.ApiClusterRef) ApiHost(com.cloudera.api.swagger.model.ApiHost)

Example 10 with ApiHost

use of com.cloudera.api.swagger.model.ApiHost in project cloudbreak by hortonworks.

the class ClouderaManagerDecommisionerTest method testCollectDownscaleCandidatesWhenOneHostDoesNotHaveFQDN.

@Test
public void testCollectDownscaleCandidatesWhenOneHostDoesNotHaveFQDN() throws ApiException {
    // GIVEN
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", false, "fstab", List.of(), 50, "vt");
    Stack stack = createTestStack(volumeSetAttributes);
    Cluster cluster = new Cluster();
    stack.setCluster(cluster);
    Set<HostGroup> hostGroups = createTestHostGroups(1, 6);
    cluster.setHostGroups(hostGroups);
    HostGroup downscaledHostGroup = hostGroups.iterator().next();
    Optional<InstanceMetaData> hgHost2 = downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData().stream().filter(instanceMetaData -> instanceMetaData.getDiscoveryFQDN().equals("hg0-host-2")).findFirst();
    hgHost2.ifPresent(instanceMetaData -> instanceMetaData.setDiscoveryFQDN(null));
    HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
    when(clouderaManagerApiFactory.getHostsResourceApi(any(ApiClient.class))).thenReturn(hostsResourceApi);
    HostTemplatesResourceApi hostTemplatesResourceApi = mock(HostTemplatesResourceApi.class);
    when(clouderaManagerApiFactory.getHostTemplatesResourceApi(any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
    ApiHostTemplateList hostTemplates = createEmptyHostTemplates();
    when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
    ApiHostList apiHostRefList = new ApiHostList();
    List<ApiHost> apiHosts = new ArrayList<>();
    hostGroups.stream().flatMap(hostGroup -> hostGroup.getInstanceGroup().getAllInstanceMetaData().stream()).map(InstanceMetaData::getDiscoveryFQDN).forEach(hostName -> {
        ApiHost apiHostRef = new ApiHost();
        apiHostRef.setHostname(hostName);
        apiHostRef.setHostId(hostName);
        apiHostRef.setHealthSummary(ApiHealthSummary.GOOD);
        apiHosts.add(apiHostRef);
    });
    apiHostRefList.setItems(apiHosts);
    when(hostsResourceApi.readHosts(any(), any(), any())).thenReturn(apiHostRefList);
    Set<InstanceMetaData> downscaleCandidates = underTest.collectDownscaleCandidates(mock(ApiClient.class), stack, downscaledHostGroup, -2, downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData());
    assertEquals(2, downscaleCandidates.size());
    assertTrue("Assert if downscaleCandidates contains hg0-host-2, because FQDN is missing", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-instanceid-2".equals(instanceMetaData.getInstanceId())));
    assertTrue("Assert if downscaleCandidates contains hg0-host-5", downscaleCandidates.stream().anyMatch(instanceMetaData -> "hg0-host-5".equals(instanceMetaData.getDiscoveryFQDN())));
}
Also used : Resource(com.sequenceiq.cloudbreak.domain.Resource) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) ApiException(com.cloudera.api.swagger.client.ApiException) ApiRoleState(com.cloudera.api.swagger.model.ApiRoleState) ApiHostTemplate(com.cloudera.api.swagger.model.ApiHostTemplate) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) NotEnoughNodeException(com.sequenceiq.cloudbreak.cluster.service.NotEnoughNodeException) ApiConfig(com.cloudera.api.swagger.model.ApiConfig) ResourceAttributeUtil(com.sequenceiq.cloudbreak.cluster.util.ResourceAttributeUtil) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) InstanceStatus(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus) Set(java.util.Set) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Collectors(java.util.stream.Collectors) Json(com.sequenceiq.cloudbreak.common.json.Json) List(java.util.List) ApiServiceConfig(com.cloudera.api.swagger.model.ApiServiceConfig) ApiHealthSummary(com.cloudera.api.swagger.model.ApiHealthSummary) Optional(java.util.Optional) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Mock(org.mockito.Mock) ApiClient(com.cloudera.api.swagger.client.ApiClient) RunWith(org.junit.runner.RunWith) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ServicesResourceApi(com.cloudera.api.swagger.ServicesResourceApi) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ApiHost(com.cloudera.api.swagger.model.ApiHost) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) NodeIsBusyException(com.sequenceiq.cloudbreak.cluster.service.NodeIsBusyException) CloudConstants(com.sequenceiq.cloudbreak.common.type.CloudConstants) InjectMocks(org.mockito.InjectMocks) ApiRoleConfigGroupRef(com.cloudera.api.swagger.model.ApiRoleConfigGroupRef) ResourceType(com.sequenceiq.common.api.type.ResourceType) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Mockito(org.mockito.Mockito) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Assertions(org.junit.jupiter.api.Assertions) ApiRoleRef(com.cloudera.api.swagger.model.ApiRoleRef) ClouderaManagerApiFactory(com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) HostTemplatesResourceApi(com.cloudera.api.swagger.HostTemplatesResourceApi) ArrayList(java.util.ArrayList) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup) ApiClient(com.cloudera.api.swagger.client.ApiClient) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) HostsResourceApi(com.cloudera.api.swagger.HostsResourceApi) ApiHostTemplateList(com.cloudera.api.swagger.model.ApiHostTemplateList) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Aggregations

ApiHost (com.cloudera.api.swagger.model.ApiHost)49 ApiHostList (com.cloudera.api.swagger.model.ApiHostList)30 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)26 Test (org.junit.Test)23 HostsResourceApi (com.cloudera.api.swagger.HostsResourceApi)16 ApiException (com.cloudera.api.swagger.client.ApiException)16 List (java.util.List)14 ApiClient (com.cloudera.api.swagger.client.ApiClient)13 Set (java.util.Set)13 Collectors (java.util.stream.Collectors)13 ClouderaManagerApiFactory (com.sequenceiq.cloudbreak.cm.client.retry.ClouderaManagerApiFactory)12 ApiCommand (com.cloudera.api.swagger.model.ApiCommand)11 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)11 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)11 ApiHealthSummary (com.cloudera.api.swagger.model.ApiHealthSummary)10 ApiRoleRef (com.cloudera.api.swagger.model.ApiRoleRef)10 ClouderaManagerPollingServiceProvider (com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 ClouderaManagerResourceApi (com.cloudera.api.swagger.ClouderaManagerResourceApi)9