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);
}
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;
}
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);
}
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);
}
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));
}
Aggregations