Search in sources :

Example 21 with ApiHost

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

the class ClouderaManagerHostStatusCheckerTest method shouldBeFalseWhenOneHostHasDifferentIp.

@Test
public void shouldBeFalseWhenOneHostHasDifferentIp() throws ApiException {
    InstanceMetaData instanceMetaData = validInstanceMetadata();
    InstanceMetaData instanceMetaData2 = validInstanceMetadata();
    instanceMetaData2.setPrivateIp("2.2.2.2");
    ApiHost apiHost = getValidApiHost(instanceMetaData);
    ApiHost apiHost2 = getValidApiHost(instanceMetaData2).ipAddress("3.3.3.3");
    when(hostsResourceApi.readHosts(null, null, VIEWTYPE)).thenReturn(new ApiHostList().items(List.of(apiHost, apiHost2)));
    boolean result = underTest.doStatusCheck(getPollerObject(instanceMetaData, instanceMetaData2));
    assertFalse(result);
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiHost(com.cloudera.api.swagger.model.ApiHost) Test(org.junit.Test)

Example 22 with ApiHost

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

the class ClouderaManagerSetupServiceTest method apiHost.

private ApiHost apiHost(String fqdn) {
    ApiHost apiHost = new ApiHost();
    apiHost.setHostname(fqdn);
    return apiHost;
}
Also used : ApiHost(com.cloudera.api.swagger.model.ApiHost)

Example 23 with ApiHost

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

the class ClouderaManagerModificationServiceTest method verifyRackIdBatch.

private void verifyRackIdBatch(ApiBatchRequest batchRequest, String hostIdExpected, String rackIdExpected) {
    assertThat(batchRequest).isNotNull();
    List<ApiBatchRequestElement> batchRequestElements = batchRequest.getItems();
    assertThat(batchRequestElements).isNotNull();
    assertThat(batchRequestElements).hasSize(1);
    ApiBatchRequestElement batchRequestElement = batchRequestElements.get(0);
    assertThat(batchRequestElement.getMethod()).isEqualTo(HTTPMethod.PUT);
    assertThat(batchRequestElement.getUrl()).isEqualTo("/api/v31/hosts/" + hostIdExpected);
    assertThat(batchRequestElement.getAcceptType()).isEqualTo("application/json");
    assertThat(batchRequestElement.getContentType()).isEqualTo("application/json");
    assertThat(batchRequestElement.getBody()).isInstanceOf(ApiHost.class);
    ApiHost host = (ApiHost) batchRequestElement.getBody();
    assertThat(host.getRackId()).isEqualTo(rackIdExpected);
}
Also used : ApiBatchRequestElement(com.cloudera.api.swagger.model.ApiBatchRequestElement) ApiHost(com.cloudera.api.swagger.model.ApiHost)

Example 24 with ApiHost

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

the class ClouderaManagerModificationServiceTest method setUpReadHosts.

private void setUpReadHosts(boolean withUpscaled, String originalRackId) throws ApiException {
    ApiHostList apiHostsRef;
    ApiHost originalHost = new ApiHost().hostname("original").hostId("originalId").rackId(originalRackId);
    if (withUpscaled) {
        apiHostsRef = new ApiHostList().items(List.of(originalHost, new ApiHost().hostname("upscaled").hostId("upscaledId")));
    } else {
        apiHostsRef = new ApiHostList().items(List.of(originalHost));
    }
    when(hostResourceApi.readHosts(eq(null), eq(null), eq("SUMMARY"))).thenReturn(apiHostsRef);
    when(clouderaManagerApiFactory.getHostsResourceApi(eq(apiClientMock))).thenReturn(hostResourceApi);
}
Also used : ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiHost(com.cloudera.api.swagger.model.ApiHost)

Example 25 with ApiHost

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

the class ClouderaManagerModificationServiceTest method testUpgradeClusterWhenPatchUpgradeAndPostUpgradeCommandIsAvailable.

@Test
void testUpgradeClusterWhenPatchUpgradeAndPostUpgradeCommandIsAvailable() throws CloudbreakException, ApiException, ClouderaManagerClientInitException {
    TestUtil.clusterComponents(cluster);
    when(clouderaManagerApiFactory.getParcelResourceApi(any())).thenReturn(parcelResourceApi);
    when(clouderaManagerApiFactory.getClustersResourceApi(any())).thenReturn(clustersResourceApi);
    when(clouderaManagerApiFactory.getClouderaManagerResourceApi(any())).thenReturn(clouderaManagerResourceApi);
    when(clouderaManagerApiFactory.getMgmtServiceResourceApi(any())).thenReturn(mgmtServiceResourceApi);
    when(clouderaManagerApiFactory.getServicesResourceApi(any())).thenReturn(servicesResourceApi);
    BigDecimal apiCommandId = new BigDecimal(200);
    // Mgmt Service restart
    ApiCommandList apiCommandList = new ApiCommandList();
    apiCommandList.setItems(new ArrayList<>());
    when(mgmtServiceResourceApi.listActiveCommands("SUMMARY")).thenReturn(apiCommandList);
    when(mgmtServiceResourceApi.restartCommand()).thenReturn(new ApiCommand().id(apiCommandId));
    when(clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClientMock, apiCommandId)).thenReturn(success);
    // Start services if they are not running
    ApiServiceList serviceList = new ApiServiceList();
    ApiService service = new ApiService();
    service.setServiceState(ApiServiceState.STOPPED);
    serviceList.addItemsItem(service);
    ApiCommand startCommand = mock(ApiCommand.class);
    when(startCommand.getId()).thenReturn(apiCommandId);
    when(servicesResourceApi.readServices(any(), any())).thenReturn(serviceList);
    when(clustersResourceApi.startCommand(STACK_NAME)).thenReturn(startCommand);
    // Post parcel activation
    ClouderaManagerRepo clouderaManagerRepo = mock(ClouderaManagerRepo.class);
    when(clusterComponentConfigProvider.getClouderaManagerRepoDetails(CLUSTER_ID)).thenReturn(clouderaManagerRepo);
    when(clouderaManagerRepo.getVersion()).thenReturn(CLOUDERAMANAGER_VERSION_7_5_1.getVersion());
    // Restart services
    when(clustersResourceApi.listActiveCommands(stack.getName(), "SUMMARY")).thenReturn(new ApiCommandList().items(List.of()));
    when(clustersResourceApi.restartCommand(eq(stack.getName()), any(ApiRestartClusterArgs.class))).thenReturn(new ApiCommand().id(apiCommandId));
    when(clouderaManagerPollingServiceProvider.startPollingCmServicesRestart(stack, apiClientMock, apiCommandId)).thenReturn(success);
    when(clouderaManagerPollingServiceProvider.startPollingCmHostStatus(stack, apiClientMock)).thenReturn(success);
    InstanceGroup instanceGroup = new InstanceGroup();
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setDiscoveryFQDN(HOSTNAME);
    instanceGroup.setGroupName(GROUP_NAME);
    instanceGroup.setInstanceMetaData(Set.of(instanceMetaData));
    stack.setInstanceGroups(Set.of(instanceGroup));
    when(clouderaManagerApiFactory.getClustersResourceApi(any())).thenReturn(clustersResourceApi);
    ApiHostList clusterHostsRef = new ApiHostList().items(List.of(new ApiHost().hostname(HOSTNAME)));
    when(clustersResourceApi.listHosts(eq(STACK_NAME), eq(null), eq(null), eq(null))).thenReturn(clusterHostsRef);
    when(clusterComponentProvider.getClouderaManagerRepoDetails(CLUSTER_ID)).thenReturn(clouderaManagerRepo);
    when(clouderaManagerRepo.getVersion()).thenReturn(CLOUDERAMANAGER_VERSION_7_6_0.getVersion());
    when(clouderaManagerApiFactory.getHostsResourceApi(any())).thenReturn(hostResourceApi);
    Call call = mock(Call.class);
    when(hostResourceApi.addTagsAsync(eq(HOSTNAME), any(), any())).thenReturn(call);
    when(clouderaManagerApiClientProvider.getV45Client(any(), any(), any(), any())).thenReturn(apiClientMock);
    underTest.upgradeClusterRuntime(cluster.getComponents(), true, Optional.empty());
    verify(clouderaManagerPollingServiceProvider, times(1)).startPollingCmStartup(stack, apiClientMock);
    verify(clouderaManagerPollingServiceProvider, times(1)).startPollingCmHostStatus(stack, apiClientMock);
    verify(clouderaManagerParcelManagementService, times(1)).checkParcelApiAvailability(stack, apiClientMock);
    verify(clouderaManagerParcelManagementService, times(1)).setParcelRepos(any(), eq(clouderaManagerResourceApi));
    verify(clouderaManagerParcelManagementService, times(1)).refreshParcelRepos(clouderaManagerResourceApi, stack, apiClientMock);
    verify(mgmtServiceResourceApi, times(1)).listActiveCommands("SUMMARY");
    verify(mgmtServiceResourceApi, times(1)).restartCommand();
    verify(clouderaManagerPollingServiceProvider, times(2)).startPollingCmServicesRestart(stack, apiClientMock, apiCommandId);
    verify(clouderaManagerParcelManagementService, times(1)).downloadParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
    verify(clouderaManagerParcelManagementService, times(1)).distributeParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
    verify(clouderaManagerParcelManagementService, times(1)).activateParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
    verify(eventService, times(1)).fireCloudbreakEvent(stack.getId(), UPDATE_IN_PROGRESS.name(), ResourceEvent.CLUSTER_UPGRADE_START_POST_UPGRADE);
    verify(clustersResourceApi, times(1)).startCommand(STACK_NAME);
    verify(clouderaManagerUpgradeService, times(1)).callPostRuntimeUpgradeCommand(clustersResourceApi, stack, apiClientMock);
    verify(clustersResourceApi, times(1)).restartCommand(eq(stack.getName()), any(ApiRestartClusterArgs.class));
    verify(clustersResourceApi, times(2)).listActiveCommands(stack.getName(), "SUMMARY");
    verify(clouderaManagerApiClientProvider, times(1)).getV45Client(any(), any(), any(), any());
    ArgumentCaptor<List<ApiEntityTag>> entityTagListCaptor = ArgumentCaptor.forClass(List.class);
    verify(hostResourceApi, times(1)).addTagsAsync(eq(HOSTNAME), entityTagListCaptor.capture(), any());
    assertEquals("_cldr_cm_host_template_name", entityTagListCaptor.getValue().get(0).getName());
    assertEquals(GROUP_NAME, entityTagListCaptor.getValue().get(0).getValue());
    InOrder inOrder = Mockito.inOrder(clouderaManagerPollingServiceProvider, clouderaManagerParcelManagementService, clustersResourceApi, clouderaManagerUpgradeService, clouderaManagerApiClientProvider);
    inOrder.verify(clouderaManagerPollingServiceProvider).startPollingCmStartup(stack, apiClientMock);
    inOrder.verify(clouderaManagerPollingServiceProvider).startPollingCmHostStatus(stack, apiClientMock);
    inOrder.verify(clouderaManagerParcelManagementService).checkParcelApiAvailability(stack, apiClientMock);
    inOrder.verify(clouderaManagerParcelManagementService).setParcelRepos(any(), eq(clouderaManagerResourceApi));
    inOrder.verify(clouderaManagerParcelManagementService).refreshParcelRepos(clouderaManagerResourceApi, stack, apiClientMock);
    inOrder.verify(clouderaManagerParcelManagementService).downloadParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
    inOrder.verify(clouderaManagerParcelManagementService).distributeParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
    inOrder.verify(clouderaManagerParcelManagementService).activateParcels(any(), eq(parcelResourceApi), eq(stack), eq(apiClientMock));
    inOrder.verify(clustersResourceApi).startCommand(STACK_NAME);
    inOrder.verify(clustersResourceApi).listActiveCommands(eq(stack.getName()), any());
    inOrder.verify(clouderaManagerApiClientProvider).getV45Client(any(), any(), any(), any());
    inOrder.verify(clouderaManagerUpgradeService).callPostRuntimeUpgradeCommand(eq(clustersResourceApi), eq(stack), eq(apiClientMock));
    inOrder.verify(clustersResourceApi).restartCommand(eq(stack.getName()), any(ApiRestartClusterArgs.class));
}
Also used : ApiCommand(com.cloudera.api.swagger.model.ApiCommand) Call(com.squareup.okhttp.Call) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) InOrder(org.mockito.InOrder) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ApiRestartClusterArgs(com.cloudera.api.swagger.model.ApiRestartClusterArgs) BigDecimal(java.math.BigDecimal) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) ApiService(com.cloudera.api.swagger.model.ApiService) ApiCommandList(com.cloudera.api.swagger.model.ApiCommandList) ApiHostRefList(com.cloudera.api.swagger.model.ApiHostRefList) ArrayList(java.util.ArrayList) List(java.util.List) ApiHostList(com.cloudera.api.swagger.model.ApiHostList) ApiServiceList(com.cloudera.api.swagger.model.ApiServiceList) ApiHost(com.cloudera.api.swagger.model.ApiHost) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.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