Search in sources :

Example 31 with Component

use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.

the class CmSyncResultMergerServiceTest method testMergeWhenNoResultsAtAll.

@Test
void testMergeWhenNoResultsAtAll() {
    Stack stack = new Stack();
    CmRepoSyncOperationResult cmRepoSyncOperationResult = new CmRepoSyncOperationResult(null, null);
    CmParcelSyncOperationResult cmParcelSyncOperationResult = new CmParcelSyncOperationResult(Set.of(), Set.of());
    CmSyncOperationResult cmSyncOperationResult = new CmSyncOperationResult(cmRepoSyncOperationResult, cmParcelSyncOperationResult);
    Set<Component> mergedComponents = underTest.merge(stack, cmSyncOperationResult);
    assertThat(mergedComponents, emptyCollectionOf(Component.class));
    verify(componentConverter, never()).fromClouderaManagerRepo(any(), any());
    verify(componentConverter).fromClouderaManagerProductList(Set.of(), stack);
}
Also used : CmParcelSyncOperationResult(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmParcelSyncOperationResult) CmSyncOperationResult(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationResult) CmRepoSyncOperationResult(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmRepoSyncOperationResult) Component(com.sequenceiq.cloudbreak.domain.stack.Component) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 32 with Component

use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.

the class CmSyncResultMergerServiceTest method testMerge.

@Test
void testMerge() {
    Stack stack = new Stack();
    ClouderaManagerRepo clouderaManagerRepo = new ClouderaManagerRepo();
    CmRepoSyncOperationResult cmRepoSyncOperationResult = new CmRepoSyncOperationResult("", clouderaManagerRepo);
    when(componentConverter.fromClouderaManagerRepo(clouderaManagerRepo, stack)).thenReturn(componentWithName(CM_REPO_COMPONENT_NAME));
    Set<ClouderaManagerProduct> clouderaManagerProducts = Set.of(new ClouderaManagerProduct());
    CmParcelSyncOperationResult cmParcelSyncOperationResult = new CmParcelSyncOperationResult(Set.of(), clouderaManagerProducts);
    when(componentConverter.fromClouderaManagerProductList(clouderaManagerProducts, stack)).thenReturn(Set.of(componentWithName(CM_PARCEL_COMPONENT_NAME)));
    CmSyncOperationResult cmSyncOperationResult = new CmSyncOperationResult(cmRepoSyncOperationResult, cmParcelSyncOperationResult);
    Set<Component> mergedComponents = underTest.merge(stack, cmSyncOperationResult);
    assertThat(mergedComponents, hasSize(2));
    assertThat(mergedComponents, containsInAnyOrder(hasProperty("name", is(CM_REPO_COMPONENT_NAME)), hasProperty("name", is(CM_PARCEL_COMPONENT_NAME))));
    verify(componentConverter).fromClouderaManagerRepo(clouderaManagerRepo, stack);
    verify(componentConverter).fromClouderaManagerProductList(clouderaManagerProducts, stack);
}
Also used : ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) CmParcelSyncOperationResult(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmParcelSyncOperationResult) CmSyncOperationResult(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationResult) ClouderaManagerProduct(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct) CmRepoSyncOperationResult(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmRepoSyncOperationResult) Component(com.sequenceiq.cloudbreak.domain.stack.Component) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 33 with Component

use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.

the class ComponentPersistingServiceTest method testPersistComponentsToDb.

@Test
void testPersistComponentsToDb() {
    Stack stack = new Stack();
    CmSyncOperationResult cmSyncOperationResult = new CmSyncOperationResult(null, null);
    Set<Component> foundComponents = Set.of(new Component());
    when(cmSyncResultMergerService.merge(stack, cmSyncOperationResult)).thenReturn(foundComponents);
    underTest.persistComponentsToDb(stack, cmSyncOperationResult);
    verify(stackComponentUpdater).updateComponentsByStackId(stack, foundComponents, false);
    verify(clusterComponentUpdater).updateClusterComponentsByStackId(stack, foundComponents, false);
}
Also used : CmSyncOperationResult(com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationResult) Component(com.sequenceiq.cloudbreak.domain.stack.Component) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 34 with Component

use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.

the class StackComponentUpdaterTest method testUpdateImageComponents.

@Test
public void testUpdateImageComponents() throws CloudbreakImageCatalogException, CloudbreakImageNotFoundException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster();
    stack.setCluster(cluster);
    StatedImage targetImage = ImageTestUtil.getImageFromCatalog(true, "targetImageUuid", TARGET_STACK_VERSION);
    Image originalImage = ImageTestUtil.getImage(true, "originalImageUuid", STACK_VERSION);
    Component originalImageComponent = new Component(ComponentType.IMAGE, ComponentType.IMAGE.name(), new Json(originalImage), stack);
    when(componentConfigProviderService.getComponentsByStackId(stack.getId())).thenReturn(Set.of(originalImageComponent));
    Set<Component> targetComponents = createComponents(stack, targetImage);
    underTest.updateComponentsByStackId(stack, targetComponents, true);
    ArgumentCaptor<Set<Component>> componentCatcher = ArgumentCaptor.forClass(Set.class);
    verify(componentConfigProviderService, times(1)).store(componentCatcher.capture());
    assertEquals(3, componentCatcher.getValue().size());
    assertTrue(componentCatcher.getValue().stream().anyMatch(component -> {
        Object version = component.getAttributes().getValue("version");
        if (Objects.nonNull(version)) {
            return ((String) version).contains(TARGET_STACK_VERSION);
        } else {
            return false;
        }
    }));
    assertTrue(componentCatcher.getValue().stream().anyMatch(component -> {
        Object userData = component.getAttributes().getValue("userdata");
        if (Objects.nonNull(userData)) {
            return ((Map<String, String>) userData).get(InstanceGroupType.GATEWAY.name()).contains("gw user data");
        } else {
            return false;
        }
    }));
}
Also used : Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) ComponentType(com.sequenceiq.cloudbreak.common.type.ComponentType) Mock(org.mockito.Mock) ImageTestUtil(com.sequenceiq.cloudbreak.service.image.ImageTestUtil) TestUtil(com.sequenceiq.cloudbreak.TestUtil) ComponentConfigProviderService(com.sequenceiq.cloudbreak.service.ComponentConfigProviderService) ImageService(com.sequenceiq.cloudbreak.service.image.ImageService) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Map(java.util.Map) CloudbreakImageCatalogException(com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Component(com.sequenceiq.cloudbreak.domain.stack.Component) InjectMocks(org.mockito.InjectMocks) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Mockito.verify(org.mockito.Mockito.verify) CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) InstanceGroupType(com.sequenceiq.common.api.type.InstanceGroupType) Objects(java.util.Objects) Test(org.junit.jupiter.api.Test) Json(com.sequenceiq.cloudbreak.common.json.Json) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Set(java.util.Set) Cluster(com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster) Json(com.sequenceiq.cloudbreak.common.json.Json) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) Component(com.sequenceiq.cloudbreak.domain.stack.Component) ClusterComponent(com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Map(java.util.Map) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) Test(org.junit.jupiter.api.Test)

Example 35 with Component

use of com.sequenceiq.cloudbreak.domain.stack.Component in project cloudbreak by hortonworks.

the class StackImageService method findImageComponentByName.

public Optional<Component> findImageComponentByName(Long stackId, String componentName) {
    Component targetImageComponent = componentConfigProviderService.getComponent(stackId, ComponentType.IMAGE, componentName);
    LOGGER.debug("The following target image found for stack {}, {}", stackId, targetImageComponent);
    return Optional.ofNullable(targetImageComponent);
}
Also used : Component(com.sequenceiq.cloudbreak.domain.stack.Component)

Aggregations

Component (com.sequenceiq.cloudbreak.domain.stack.Component)37 Json (com.sequenceiq.cloudbreak.common.json.Json)16 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)14 Image (com.sequenceiq.cloudbreak.cloud.model.Image)12 Test (org.junit.jupiter.api.Test)11 ClouderaManagerProduct (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerProduct)6 ClouderaManagerRepo (com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo)6 ClusterComponent (com.sequenceiq.cloudbreak.domain.stack.cluster.ClusterComponent)6 CloudbreakImageCatalogException (com.sequenceiq.cloudbreak.core.CloudbreakImageCatalogException)5 CloudbreakImageNotFoundException (com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException)5 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)5 ClusterV4Request (com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.cluster.ClusterV4Request)4 StackMatrixV4Response (com.sequenceiq.cloudbreak.api.endpoint.v4.util.responses.StackMatrixV4Response)4 ImageBasedDefaultCDHInfo (com.sequenceiq.cloudbreak.cloud.model.component.ImageBasedDefaultCDHInfo)4 StackType (com.sequenceiq.cloudbreak.cloud.model.component.StackType)4 CloudbreakServiceException (com.sequenceiq.cloudbreak.common.exception.CloudbreakServiceException)4 CmSyncOperationResult (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmSyncOperationResult)4 DefaultCDHInfo (com.sequenceiq.cloudbreak.cloud.model.component.DefaultCDHInfo)3 ComponentType (com.sequenceiq.cloudbreak.common.type.ComponentType)3 CmParcelSyncOperationResult (com.sequenceiq.cloudbreak.service.upgrade.sync.operationresult.CmParcelSyncOperationResult)3