Search in sources :

Example 76 with InstanceMetaData

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

the class StackDownscaleServiceTest method finishStackDownscaleAndDontSaveVolumeFQDNTest.

@Test
public void finishStackDownscaleAndDontSaveVolumeFQDNTest() throws TransactionService.TransactionExecutionException {
    StackScalingFlowContext stackScalingFlowContext = mock(StackScalingFlowContext.class);
    Stack stack = mock(Stack.class);
    when(stackScalingFlowContext.getStack()).thenReturn(stack);
    when(stackScalingFlowContext.isRepair()).thenReturn(true);
    InstanceGroup masterGroup = new InstanceGroup();
    masterGroup.setGroupName("master");
    when(stack.getInstanceGroups()).thenReturn(Set.of(masterGroup));
    InstanceMetaData master = new InstanceMetaData();
    master.setInstanceId("i-1111");
    master.setPrivateId(1L);
    master.setDiscoveryFQDN("master1.cloudera.site");
    masterGroup.setInstanceMetaData(Set.of(master));
    ArrayList<Resource> volumes = new ArrayList<>();
    Resource volume1 = new Resource();
    volumes.add(volume1);
    volume1.setInstanceId("i-1111");
    VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az1", false, "", new ArrayList<>(), 50, "gp2");
    volumeSetAttributes.setDiscoveryFQDN("some.fqdn");
    volume1.setAttributes(Json.silent(volumeSetAttributes));
    doReturn(Optional.of(volumeSetAttributes)).when(resourceAttributeUtil).getTypedAttributes(volume1, VolumeSetAttributes.class);
    when(resourceService.findByStackIdAndType(any(), any())).thenReturn(volumes);
    stackDownscaleService.finishStackDownscale(stackScalingFlowContext, Set.of(1L));
    verify(resourceService).saveAll(resourcesCaptor.capture());
    Iterable<Resource> resourcesCaptorValue = resourcesCaptor.getValue();
    Json attributes = resourcesCaptorValue.iterator().next().getAttributes();
    assertEquals("some.fqdn", attributes.getValue("discoveryFQDN"));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Resource(com.sequenceiq.cloudbreak.domain.Resource) ArrayList(java.util.ArrayList) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test)

Example 77 with InstanceMetaData

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

the class StackDownscaleServiceTest method finishStackDownscaleAndSaveVolumeFQDNTest.

@Test
public void finishStackDownscaleAndSaveVolumeFQDNTest() throws TransactionService.TransactionExecutionException {
    StackScalingFlowContext stackScalingFlowContext = mock(StackScalingFlowContext.class);
    Stack stack = mock(Stack.class);
    when(stackScalingFlowContext.getStack()).thenReturn(stack);
    when(stackScalingFlowContext.isRepair()).thenReturn(true);
    InstanceGroup masterGroup = new InstanceGroup();
    masterGroup.setGroupName("master");
    when(stack.getInstanceGroups()).thenReturn(Set.of(masterGroup));
    InstanceMetaData master = new InstanceMetaData();
    master.setInstanceId("i-1111");
    master.setDiscoveryFQDN("master1.cloudera.site");
    master.setPrivateId(1L);
    masterGroup.setInstanceMetaData(Set.of(master));
    ArrayList<Resource> volumes = new ArrayList<>();
    Resource volume1 = new Resource();
    volumes.add(volume1);
    volume1.setInstanceId("i-1111");
    doReturn(Optional.of(new VolumeSetAttributes("az1", false, "", new ArrayList<>(), 50, "gp2"))).when(resourceAttributeUtil).getTypedAttributes(volume1, VolumeSetAttributes.class);
    when(resourceService.findByStackIdAndType(any(), any())).thenReturn(volumes);
    stackDownscaleService.finishStackDownscale(stackScalingFlowContext, Set.of(1L));
    verify(resourceService).saveAll(resourcesCaptor.capture());
    Iterable<Resource> resourcesCaptorValue = resourcesCaptor.getValue();
    Json attributes = resourcesCaptorValue.iterator().next().getAttributes();
    assertEquals("master1.cloudera.site", attributes.getValue("discoveryFQDN"));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Resource(com.sequenceiq.cloudbreak.domain.Resource) ArrayList(java.util.ArrayList) Json(com.sequenceiq.cloudbreak.common.json.Json) Stack(com.sequenceiq.cloudbreak.domain.stack.Stack) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) VolumeSetAttributes(com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes) Test(org.junit.jupiter.api.Test)

Example 78 with InstanceMetaData

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

the class PackageVersionCheckerTest method compareImageAndInstancesMandatoryPackageVersionPrewarmedOk.

@Test
public void compareImageAndInstancesMandatoryPackageVersionPrewarmedOk() throws JsonProcessingException {
    String packageName = "package";
    Map<String, String> packageVersions = Collections.singletonMap(packageName, "1");
    when(statedImage.getImage()).thenReturn(image);
    when(image.isPrewarmed()).thenReturn(true);
    when(image.getPackageVersions()).thenReturn(packageVersions);
    Package aPackage = new Package();
    aPackage.setName(packageName);
    aPackage.setPrewarmed(true);
    when(instanceMetadataUpdater.getPackages()).thenReturn(Collections.singletonList(aPackage));
    when(instanceMetadataUpdater.isPackagesVersionEqual(anyString(), anyString())).thenReturn(true);
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setImage(new Json(new com.sequenceiq.cloudbreak.cloud.model.Image("image", Collections.emptyMap(), "os", "ostype", "catalogn", "catalogu", "id", packageVersions)));
    Set<InstanceMetaData> instanceMetaDataSet = Collections.singleton(instanceMetaData);
    CheckResult result = underTest.compareImageAndInstancesMandatoryPackageVersion(statedImage, instanceMetaDataSet);
    assertEquals(EventStatus.OK, result.getStatus());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Package(com.sequenceiq.cloudbreak.service.cluster.Package) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.Test)

Example 79 with InstanceMetaData

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

the class PackageVersionCheckerTest method compareImageAndInstancesMandatoryPackageVersionDifferentPackageVersionInImage.

@Test
public void compareImageAndInstancesMandatoryPackageVersionDifferentPackageVersionInImage() throws JsonProcessingException {
    String packageName = "package";
    Map<String, String> packageVersions = Collections.singletonMap(packageName, "1");
    when(statedImage.getImage()).thenReturn(image);
    when(image.isPrewarmed()).thenReturn(true);
    when(image.getPackageVersions()).thenReturn(Collections.singletonMap(packageName, "2"));
    Package aPackage = new Package();
    aPackage.setName(packageName);
    aPackage.setPrewarmed(true);
    when(instanceMetadataUpdater.getPackages()).thenReturn(Collections.singletonList(aPackage));
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setImage(new Json(new com.sequenceiq.cloudbreak.cloud.model.Image("image", Collections.emptyMap(), "os", "ostype", "catalogn", "catalogu", "id", packageVersions)));
    Set<InstanceMetaData> instanceMetaDataSet = Collections.singleton(instanceMetaData);
    CheckResult result = underTest.compareImageAndInstancesMandatoryPackageVersion(statedImage, instanceMetaDataSet);
    assertEquals(EventStatus.FAILED, result.getStatus());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Package(com.sequenceiq.cloudbreak.service.cluster.Package) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.Test)

Example 80 with InstanceMetaData

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

the class PackageVersionCheckerTest method compareImageAndInstancesMandatoryPackageVersionMissingPackageInImage.

@Test
public void compareImageAndInstancesMandatoryPackageVersionMissingPackageInImage() throws JsonProcessingException {
    String packageName = "package";
    Map<String, String> packageVersions = Collections.singletonMap(packageName, "1");
    when(statedImage.getImage()).thenReturn(image);
    when(image.isPrewarmed()).thenReturn(true);
    when(image.getPackageVersions()).thenReturn(Collections.emptyMap());
    Package aPackage = new Package();
    aPackage.setName(packageName);
    aPackage.setPrewarmed(true);
    when(instanceMetadataUpdater.getPackages()).thenReturn(Collections.singletonList(aPackage));
    InstanceMetaData instanceMetaData = new InstanceMetaData();
    instanceMetaData.setImage(new Json(new com.sequenceiq.cloudbreak.cloud.model.Image("image", Collections.emptyMap(), "os", "ostype", "catalogn", "catalogu", "id", packageVersions)));
    Set<InstanceMetaData> instanceMetaDataSet = Collections.singleton(instanceMetaData);
    CheckResult result = underTest.compareImageAndInstancesMandatoryPackageVersion(statedImage, instanceMetaDataSet);
    assertEquals(EventStatus.FAILED, result.getStatus());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) CheckResult(com.sequenceiq.cloudbreak.core.flow2.CheckResult) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Package(com.sequenceiq.cloudbreak.service.cluster.Package) Json(com.sequenceiq.cloudbreak.common.json.Json) Image(com.sequenceiq.cloudbreak.cloud.model.catalog.Image) StatedImage(com.sequenceiq.cloudbreak.service.image.StatedImage) Test(org.junit.Test)

Aggregations

InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)415 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)165 InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)152 Test (org.junit.jupiter.api.Test)143 Map (java.util.Map)92 HashSet (java.util.HashSet)90 Set (java.util.Set)86 List (java.util.List)84 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)77 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)73 Collectors (java.util.stream.Collectors)71 ArrayList (java.util.ArrayList)62 Test (org.junit.Test)60 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)57 Optional (java.util.Optional)52 StackService (com.sequenceiq.cloudbreak.service.stack.StackService)48 Inject (javax.inject.Inject)47 Logger (org.slf4j.Logger)47 LoggerFactory (org.slf4j.LoggerFactory)47 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)45