Search in sources :

Example 6 with ApiParcel

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

the class ParcelGeneratorUtil method getActivatedCDHParcelWithVersion.

public ApiParcel getActivatedCDHParcelWithVersion(String version) {
    ApiParcel parcel = new ApiParcel();
    ApiParcelState state = new ApiParcelState();
    state.setCount(new BigDecimal(0));
    parcel.setProduct("CDH");
    parcel.setState(state);
    parcel.setVersion(version);
    parcel.setStage("ACTIVATED");
    return parcel;
}
Also used : ApiParcel(com.cloudera.api.swagger.model.ApiParcel) BigDecimal(java.math.BigDecimal) ApiParcelState(com.cloudera.api.swagger.model.ApiParcelState)

Example 7 with ApiParcel

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

the class ParcelMockActivatorUtil method getDefaultApiParcels.

private List<ApiParcel> getDefaultApiParcels(MockedTestContext testContext) {
    String blueprintCdhVersion = testContext.getCloudProvider().getBlueprintCdhVersion();
    DefaultCDHInfo defaultCDHInfo = inTestCdhParcelProvider.getParcels(blueprintCdhVersion).get(blueprintCdhVersion);
    return defaultCDHInfo.getParcels().stream().map(product -> {
        ApiParcel apiParcel = new ApiParcel();
        apiParcel.setVersion(product.getVersion());
        apiParcel.setProduct(product.getName());
        apiParcel.setStage("ACTIVATED");
        ApiParcelState state = new ApiParcelState();
        state.setCount(new BigDecimal(0));
        apiParcel.setState(state);
        return apiParcel;
    }).collect(Collectors.toList());
}
Also used : Arrays(java.util.Arrays) MockedTestContext(com.sequenceiq.it.cloudbreak.context.MockedTestContext) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) DefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.DefaultCDHInfo) ApiParcel(com.cloudera.api.swagger.model.ApiParcel) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) CollectionUtils(org.apache.commons.collections4.CollectionUtils) Inject(javax.inject.Inject) BigDecimal(java.math.BigDecimal) InTestCdhParcelProvider(com.sequenceiq.it.config.InTestCdhParcelProvider) List(java.util.List) Component(org.springframework.stereotype.Component) TestFailException(com.sequenceiq.it.cloudbreak.exception.TestFailException) ApiParcelList(com.cloudera.api.swagger.model.ApiParcelList) ApiParcelState(com.cloudera.api.swagger.model.ApiParcelState) ApiParcel(com.cloudera.api.swagger.model.ApiParcel) DefaultCDHInfo(com.sequenceiq.cloudbreak.cloud.model.component.DefaultCDHInfo) BigDecimal(java.math.BigDecimal) ApiParcelState(com.cloudera.api.swagger.model.ApiParcelState)

Example 8 with ApiParcel

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

the class ClouderaManagerParcelDecommissionServiceTest method testRemoveUnusedParcelVersions.

@Test
public void testRemoveUnusedParcelVersions() throws ApiException {
    Stack stack = mock(Stack.class);
    when(stack.getName()).thenReturn(STACK_NAME);
    ClouderaManagerProduct currentProductWithVersionToKeep = new ClouderaManagerProduct().withName("CDH").withVersion("current");
    doReturn(List.of(new ApiParcel().product("ignored").version("current"), new ApiParcel().product(currentProductWithVersionToKeep.getName()).version("old"), new ApiParcel().product(currentProductWithVersionToKeep.getName()).version("old2"), new ApiParcel().product(currentProductWithVersionToKeep.getName()).version(currentProductWithVersionToKeep.getVersion()))).when(parcelManagementService).getClouderaManagerParcelsByStatus(parcelsResourceApi, STACK_NAME, ParcelStatus.DISTRIBUTED);
    ArgumentCaptor<Multimap<String, String>> parcelVersionsCaptorForDownloaded = ArgumentCaptor.forClass(Multimap.class);
    when(clouderaManagerPollingServiceProvider.startPollingCmParcelStatus(eq(stack), eq(apiClient), parcelVersionsCaptorForDownloaded.capture(), eq(ParcelStatus.DOWNLOADED))).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().success().build());
    doReturn(List.of(new ApiParcel().product("ignored").version("current"), new ApiParcel().product(currentProductWithVersionToKeep.getName()).version("old"), new ApiParcel().product(currentProductWithVersionToKeep.getName()).version("old2"), new ApiParcel().product(currentProductWithVersionToKeep.getName()).version(currentProductWithVersionToKeep.getVersion()))).when(parcelManagementService).getClouderaManagerParcelsByStatus(parcelsResourceApi, STACK_NAME, ParcelStatus.DOWNLOADED);
    ArgumentCaptor<Multimap<String, String>> parcelVersionsCaptorForDelete = ArgumentCaptor.forClass(Multimap.class);
    when(clouderaManagerPollingServiceProvider.startPollingCmParcelDelete(eq(stack), eq(apiClient), parcelVersionsCaptorForDelete.capture())).thenReturn(new ExtendedPollingResult.ExtendedPollingResultBuilder().success().build());
    underTest.removeUnusedParcelVersions(apiClient, parcelsResourceApi, parcelResourceApi, stack, currentProductWithVersionToKeep);
    verify(parcelResourceApi).startRemovalOfDistributionCommand(STACK_NAME, currentProductWithVersionToKeep.getName(), "old");
    verify(parcelResourceApi).startRemovalOfDistributionCommand(STACK_NAME, currentProductWithVersionToKeep.getName(), "old2");
    assertEquals(2, parcelVersionsCaptorForDownloaded.getValue().size());
    assertTrue(parcelVersionsCaptorForDownloaded.getValue().containsEntry("CDH", "old"));
    assertTrue(parcelVersionsCaptorForDownloaded.getValue().containsEntry("CDH", "old2"));
    verify(parcelResourceApi).removeDownloadCommand(STACK_NAME, currentProductWithVersionToKeep.getName(), "old");
    verify(parcelResourceApi).removeDownloadCommand(STACK_NAME, currentProductWithVersionToKeep.getName(), "old2");
    assertEquals(2, parcelVersionsCaptorForDelete.getValue().size());
    assertTrue(parcelVersionsCaptorForDelete.getValue().containsEntry("CDH", "old"));
    assertTrue(parcelVersionsCaptorForDelete.getValue().containsEntry("CDH", "old2"));
    verifyNoMoreInteractions(parcelResourceApi);
}
Also used : ApiParcel(com.cloudera.api.swagger.model.ApiParcel) Multimap(com.google.common.collect.Multimap) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 9 with ApiParcel

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

the class ClouderaManagerParcelDecommissionServiceTest method createApiParcelList.

private ApiParcelList createApiParcelList(Map<String, String> products, ParcelStatus parcelStatus) {
    ApiParcelList parcelList = new ApiParcelList();
    List<ApiParcel> apiParcels = products.entrySet().stream().map(entry -> createApiParcel(entry.getKey(), entry.getValue(), parcelStatus)).collect(Collectors.toList());
    parcelList.setItems(apiParcels);
    return parcelList;
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) ApiClient(com.cloudera.api.swagger.client.ApiClient) ApiParcel(com.cloudera.api.swagger.model.ApiParcel) Multimap(com.google.common.collect.Multimap) ApiException(com.cloudera.api.swagger.client.ApiException) ParcelStatus(com.sequenceiq.cloudbreak.cm.model.ParcelStatus) ClouderaManagerPollingServiceProvider(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerPollingServiceProvider) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) ApiParcelList(com.cloudera.api.swagger.model.ApiParcelList) Map(java.util.Map) Spy(org.mockito.Spy) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Mockito.doReturn(org.mockito.Mockito.doReturn) ParcelResourceApi(com.cloudera.api.swagger.ParcelResourceApi) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ParcelOperationStatus(com.sequenceiq.cloudbreak.cluster.model.ParcelOperationStatus) Set(java.util.Set) ExtendedPollingResult(com.sequenceiq.cloudbreak.polling.ExtendedPollingResult) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) ParcelsResourceApi(com.cloudera.api.swagger.ParcelsResourceApi) Mockito.mock(org.mockito.Mockito.mock) ApiParcel(com.cloudera.api.swagger.model.ApiParcel) ApiParcelList(com.cloudera.api.swagger.model.ApiParcelList)

Example 10 with ApiParcel

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

the class ClouderaManagerParcelActivationListenerTaskTest method checkStatusActivated.

@Test
void checkStatusActivated() throws ApiException {
    when(clouderaManagerApiPojoFactory.getParcelsResourceApi(eq(apiClientMock))).thenReturn(parcelsResourcesApi);
    ClouderaManagerCommandPollerObject clouderaManagerCommandPollerObject = new ClouderaManagerCommandPollerObject(stack, apiClientMock, COMMAND_ID);
    ApiParcel apiParcel1 = TestUtil.apiParcel(CDH, ACTIVATED);
    ApiParcel apiParcel2 = TestUtil.apiParcel(CDSW, ACTIVATED);
    ApiParcelList apiParcelList = new ApiParcelList().items(List.of(apiParcel1, apiParcel2));
    when(parcelsResourcesApi.readParcels(eq(STACK_NAME), eq(SUMMARY))).thenReturn(apiParcelList);
    assertTrue(underTest.checkStatus(clouderaManagerCommandPollerObject));
}
Also used : ApiParcel(com.cloudera.api.swagger.model.ApiParcel) ClouderaManagerCommandPollerObject(com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerCommandPollerObject) ApiParcelList(com.cloudera.api.swagger.model.ApiParcelList) Test(org.junit.jupiter.api.Test)

Aggregations

ApiParcel (com.cloudera.api.swagger.model.ApiParcel)20 ApiParcelList (com.cloudera.api.swagger.model.ApiParcelList)9 ApiClient (com.cloudera.api.swagger.client.ApiClient)7 ClouderaManagerCommandPollerObject (com.sequenceiq.cloudbreak.cm.polling.ClouderaManagerCommandPollerObject)6 Test (org.junit.jupiter.api.Test)6 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)5 ParcelResourceApi (com.cloudera.api.swagger.ParcelResourceApi)4 ApiParcelState (com.cloudera.api.swagger.model.ApiParcelState)3 Description (com.sequenceiq.it.cloudbreak.context.Description)3 Test (org.testng.annotations.Test)3 ApiException (com.cloudera.api.swagger.client.ApiException)2 Multimap (com.google.common.collect.Multimap)2 ClouderaManagerProduct (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct)2 ExtendedPollingResult (com.sequenceiq.cloudbreak.polling.ExtendedPollingResult)2 TestCaseDescription (com.sequenceiq.it.cloudbreak.context.TestCaseDescription)2 ClouderaManagerProductTestDto (com.sequenceiq.it.cloudbreak.dto.ClouderaManagerProductTestDto)2 ClouderaManagerTestDto (com.sequenceiq.it.cloudbreak.dto.ClouderaManagerTestDto)2 ClusterTestDto (com.sequenceiq.it.cloudbreak.dto.ClusterTestDto)2 InstanceGroupTestDto (com.sequenceiq.it.cloudbreak.dto.InstanceGroupTestDto)2 StackTestDto (com.sequenceiq.it.cloudbreak.dto.stack.StackTestDto)2