use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class ClouderaManagerDecommisionerTest method testVerifyNodesAreRemovableWithoutRepairAndReplication.
@Test
public void testVerifyNodesAreRemovableWithoutRepairAndReplication() throws ApiException {
// GIVEN
VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", true, "fstab", List.of(), 50, "vt");
Stack stack = createTestStack(volumeSetAttributes);
Cluster cluster = new Cluster();
stack.setCluster(cluster);
Set<HostGroup> hostGroups = createTestHostGroups(2, 5);
cluster.setHostGroups(hostGroups);
ApiServiceConfig apiServiceConfig = createApiServiceConfigWithReplication("3", true);
ApiHostTemplateList hostTemplates = createHostTemplatesWithDataNodes(hostGroups.stream().findFirst().get().getName());
when(clouderaManagerApiFactory.getHostTemplatesResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
when(resourceAttributeUtil.getTypedAttributes(stack.getDiskResources().get(0), VolumeSetAttributes.class)).thenReturn(Optional.of(volumeSetAttributes));
when(clouderaManagerApiFactory.getServicesResourceApi(Mockito.any(ApiClient.class))).thenReturn(servicesResourceApi);
when(servicesResourceApi.readServiceConfig(stack.getName(), "hdfs", "full")).thenReturn(apiServiceConfig);
when(clouderaManagerApiFactory.getHostsResourceApi(Mockito.any(ApiClient.class))).thenReturn(hostsResourceApi);
when(hostsResourceApi.readHosts(eq(null), eq(null), anyString())).thenReturn(apiHostList);
when(apiHostList.getItems()).thenReturn(List.of());
// WHEN
HostGroup firstHostGroup = hostGroups.iterator().next();
Set<InstanceMetaData> firstHostGroupInstances = firstHostGroup.getInstanceGroup().getInstanceMetaDataSet();
Set<InstanceMetaData> removableInstances = firstHostGroupInstances.stream().limit(2).collect(Collectors.toSet());
underTest.verifyNodesAreRemovable(stack, removableInstances, new ApiClient());
// THEN no exception
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class ClouderaManagerDecommisionerTest method testCollectDownscaleCandidatesWhenEveryHostHasHostnameButNotEnoughNodesToDownscale.
@Test
public void testCollectDownscaleCandidatesWhenEveryHostHasHostnameButNotEnoughNodesToDownscale() throws ApiException {
// GIVEN
VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", false, "fstab", List.of(), 50, "vt");
Stack stack = createTestStack(volumeSetAttributes);
Cluster cluster = new Cluster();
stack.setCluster(cluster);
Set<HostGroup> hostGroups = createTestHostGroups(1, 6);
cluster.setHostGroups(hostGroups);
HostGroup downscaledHostGroup = hostGroups.iterator().next();
HostsResourceApi hostsResourceApi = mock(HostsResourceApi.class);
when(clouderaManagerApiFactory.getHostsResourceApi(any(ApiClient.class))).thenReturn(hostsResourceApi);
HostTemplatesResourceApi hostTemplatesResourceApi = mock(HostTemplatesResourceApi.class);
when(clouderaManagerApiFactory.getHostTemplatesResourceApi(any(ApiClient.class))).thenReturn(hostTemplatesResourceApi);
ApiHostTemplateList hostTemplates = createEmptyHostTemplates();
when(hostTemplatesResourceApi.readHostTemplates(stack.getName())).thenReturn(hostTemplates);
assertThrows(NotEnoughNodeException.class, () -> underTest.collectDownscaleCandidates(mock(ApiClient.class), stack, downscaledHostGroup, -8, downscaledHostGroup.getInstanceGroup().getAllInstanceMetaData()));
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class InstanceMetaDataServiceTest method testGetAzFromDiskOrNullIfRepairWhenRepairAndCloudPlatformSupportedButNoVolumeWithHostName.
@Test
public void testGetAzFromDiskOrNullIfRepairWhenRepairAndCloudPlatformSupportedButNoVolumeWithHostName() {
Stack stack = new Stack();
stack.setId(1L);
stack.setCloudPlatform(CloudPlatform.AWS.name());
VolumeSetAttributes volumeSetAttributes = new VolumeSetAttributes("az", false, "fstab", List.of(), 10, "type");
volumeSetAttributes.setDiscoveryFQDN("any-hostname");
CloudResource cloudResource = CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.DETACHED).name("name").params(Map.of(CloudResource.ATTRIBUTES, volumeSetAttributes)).build();
when(resourceRetriever.findAllByStatusAndTypeAndStackAndInstanceGroup(CommonStatus.DETACHED, ResourceType.AWS_VOLUMESET, 1L, "ig")).thenReturn(List.of(cloudResource));
String actual = underTest.getAzFromDiskOrNullIfRepair(stack, true, "ig", "hostname");
assertThat(actual).isNull();
verify(resourceRetriever).findAllByStatusAndTypeAndStackAndInstanceGroup(CommonStatus.DETACHED, ResourceType.AWS_VOLUMESET, 1L, "ig");
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class InstanceMetaDataService method getAzFromDiskOrNullIfRepair.
@VisibleForTesting
String getAzFromDiskOrNullIfRepair(Stack stack, boolean repair, String instanceGroup, String hostname) {
String availabilityZone = null;
if (repair) {
ResourceType resourceType = getSupportedReattachableDiskType(stack);
if (resourceType != null) {
List<CloudResource> reattachableDiskResources = resourceRetriever.findAllByStatusAndTypeAndStackAndInstanceGroup(CommonStatus.DETACHED, resourceType, stack.getId(), instanceGroup);
Optional<CloudResource> reattachableDiskResource = reattachableDiskResources.stream().filter(d -> d.getParameter(ATTRIBUTES, VolumeSetAttributes.class).getDiscoveryFQDN().equals(hostname)).findFirst();
if (reattachableDiskResource.isPresent()) {
VolumeSetAttributes volumeSetAttributes = reattachableDiskResource.get().getParameter(ATTRIBUTES, VolumeSetAttributes.class);
availabilityZone = volumeSetAttributes.getAvailabilityZone();
LOGGER.debug("Found AZ for the {}: {}", resourceType, availabilityZone);
} else {
LOGGER.debug("Cannot find {} for {} in instanceGroup of {}", resourceType, hostname, instanceGroup);
}
}
}
return availabilityZone;
}
use of com.sequenceiq.cloudbreak.cloud.model.VolumeSetAttributes in project cloudbreak by hortonworks.
the class VolumeMatcherTest method addVolumeResourcesToContextThrowsException.
@Test
public void addVolumeResourcesToContextThrowsException() {
List<CloudResource> workerInstanceResources = new ArrayList<>();
workerInstanceResources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("worker1").group("worker").params(Map.of("privateId", 1L)).build());
workerInstanceResources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("worker2").group("worker").params(Map.of("privateId", 10L)).build());
workerInstanceResources.add(CloudResource.builder().type(ResourceType.AWS_INSTANCE).status(CommonStatus.REQUESTED).name("worker3").group("worker").params(Map.of("privateId", 11L)).build());
List<CloudResource> workerVolumeResources = new ArrayList<>();
VolumeSetAttributes volume1attributes = new VolumeSetAttributes("az1", false, "fstab", new ArrayList<>(), 100, "general");
volume1attributes.setDiscoveryFQDN("worker3.example.com");
workerVolumeResources.add(CloudResource.builder().type(ResourceType.AWS_VOLUMESET).status(CommonStatus.REQUESTED).name("volume1").group("worker").params(Map.of("attributes", volume1attributes)).build());
List<CloudInstance> workerInstances = new ArrayList<>();
workerInstances.add(new CloudInstance(null, getInstanceTemplate(2L, "worker"), mock(InstanceAuthentication.class), "subnet1", "az1", Map.of(CloudInstance.FQDN, "worker2.example.com")));
workerInstances.add(new CloudInstance(null, getInstanceTemplate(3L, "worker"), mock(InstanceAuthentication.class), "subnet1", "az1", Map.of(CloudInstance.FQDN, "worker3.example.com")));
ResourceBuilderContext context = new ResourceBuilderContext("context", Location.location(Region.region("us-west-1")), 0);
CloudConnectorException cloudConnectorException = Assert.assertThrows(CloudConnectorException.class, () -> volumeMatcher.addVolumeResourcesToContext(workerInstances, workerInstanceResources, workerVolumeResources, context));
assertEquals("Can't find cloud instance by private ID: 2", cloudConnectorException.getMessage());
}
Aggregations