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