use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class InstanceGroupV4RequestToInstanceGroupConverterTest method testConvertWhenHostNameUpperCase.
@Test
public void testConvertWhenHostNameUpperCase() {
InstanceGroupV4Request source = new InstanceGroupV4Request();
source.setName("MixEdName");
source.setTemplate(new InstanceTemplateV4Request());
when(providerParameterCalculator.get(source)).thenReturn(mock(Mappable.class));
when(instanceTemplateV4RequestToTemplateConverter.convert(any())).thenReturn(new Template());
InstanceGroup actual = underTest.convert(source, "variant");
assertEquals(actual.getGroupName(), "mixedname");
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup 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.InstanceGroup 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.InstanceGroup in project cloudbreak by hortonworks.
the class ClusterHostServiceRunnerTest method setupMocksForRunClusterServices.
private void setupMocksForRunClusterServices() {
when(umsClient.getAccountDetails(any(), any(), any())).thenReturn(UserManagementProto.Account.getDefaultInstance());
when(stackService.get(any())).thenReturn(stack);
when(stack.getCluster()).thenReturn(cluster);
when(stack.getTunnel()).thenReturn(Tunnel.DIRECT);
when(stack.getCloudPlatform()).thenReturn(CloudPlatform.AWS.name());
when(stack.getResourceCrn()).thenReturn(TEST_CLUSTER_CRN);
when(cluster.getName()).thenReturn("clustername");
when(cluster.getStack()).thenReturn(stack);
when(componentLocator.getComponentLocation(any(), any())).thenReturn(new HashMap<>());
when(exposedServiceCollector.getImpalaService()).thenReturn(mock(ExposedService.class));
when(environmentConfigProvider.getParentEnvironmentCrn(any())).thenReturn("crn:cdp:iam:us-west-1:accid:user:mockuser@cloudera.com");
ClouderaManagerRepo clouderaManagerRepo = mock(ClouderaManagerRepo.class);
when(clouderaManagerRepo.getVersion()).thenReturn("7.2.2");
GatewayConfig gatewayConfig = mock(GatewayConfig.class);
when(gatewayConfig.getPrivateAddress()).thenReturn("1.2.3.4");
when(gatewayConfig.getHostname()).thenReturn("hostname");
when(gatewayConfigService.getPrimaryGatewayConfig(any())).thenReturn(gatewayConfig);
when(clusterComponentConfigProvider.getClouderaManagerRepoDetails(any())).thenReturn(clouderaManagerRepo);
when(exposedServiceCollector.getRangerService()).thenReturn(mock(ExposedService.class));
ExposedService cmExposedService = mock(ExposedService.class);
when(cmExposedService.getServiceName()).thenReturn("CM");
when(exposedServiceCollector.getClouderaManagerService()).thenReturn(cmExposedService);
Template template = new Template();
template.setTemporaryStorage(TemporaryStorage.EPHEMERAL_VOLUMES);
Set<InstanceGroup> instanceGroups = new HashSet<>();
createInstanceGroup(template, instanceGroups, "fqdn1", null, "1.1.1.1", "1.1.1.2");
createInstanceGroup(template, instanceGroups, "fqdn2", null, "1.1.2.1", "1.1.2.2");
InstanceGroup gwIg = createInstanceGroup(template, instanceGroups, "gateway1", "gateway2", "1.1.3.1", "1.1.3.2");
lenient().when(stack.getNotTerminatedAndNotZombieGatewayInstanceMetadata()).thenReturn(Lists.newArrayList(gwIg.getAllInstanceMetaData()));
when(stack.getInstanceGroups()).thenReturn(instanceGroups);
RdsConfigWithoutCluster rdsConfigWithoutCluster = mock(RdsConfigWithoutCluster.class);
when(rdsConfigWithoutClusterService.findByClusterIdAndType(any(), eq(DatabaseType.CLOUDERA_MANAGER))).thenReturn(rdsConfigWithoutCluster);
when(rdsConfigWithoutCluster.getType()).thenReturn("asdf");
when(rdsConfigWithoutCluster.getConnectionURL()).thenReturn("jdbc:postgresql:subname://some-rds.1d3nt1f13r.eu-west-1.rds.amazonaws.com:5432/ranger");
when(rdsConfigWithoutCluster.getConnectionUserName()).thenReturn(new Secret("username"));
when(rdsConfigWithoutCluster.getConnectionPassword()).thenReturn(new Secret("password"));
when(loadBalancerSANProvider.getLoadBalancerSAN(stack)).thenReturn(Optional.empty());
ClusterPreCreationApi clusterPreCreationApi = mock(ClusterPreCreationApi.class);
when(clusterApiConnectors.getConnector(cluster)).thenReturn(clusterPreCreationApi);
ServiceLocationMap serviceLocationMap = new ServiceLocationMap();
serviceLocationMap.add(new ServiceLocation("serv", "paath"));
when(clusterPreCreationApi.getServiceLocations()).thenReturn(serviceLocationMap);
ReflectionTestUtils.setField(underTest, "cmHeartbeatInterval", "1");
ReflectionTestUtils.setField(underTest, "cmMissedHeartbeatInterval", "1");
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class GrainPropertiesServiceTest method testAllInOne.
@Test
public void testAllInOne() {
when(componentLocator.getComponentLocationByHostname(eq(cluster), argThat(namenodeMatcher))).thenReturn(Map.of("NAMENODE", List.of("NMHOST")));
when(componentLocator.getComponentLocationByHostname(eq(cluster), argThat(knoxGatewayMatcher))).thenReturn(Map.of("KNOX_GATEWAY", List.of("KWGHOST")));
GatewayConfig gwconfig = mock(GatewayConfig.class);
when(gwconfig.getPublicAddress()).thenReturn("GWPUBADDR");
when(gwconfig.getHostname()).thenReturn("GWHOSTNAME");
Node node1 = new Node("", "", "", "", "node1fqdn", "");
InstanceMetaData im1 = new InstanceMetaData();
im1.setDiscoveryFQDN(node1.getHostname());
InstanceGroup logIg = new InstanceGroup();
logIg.setAttributes(new Json("{}"));
logIg.setCloudIdentityType(CloudIdentityType.LOG);
im1.setInstanceGroup(logIg);
when(instanceMetaDataService.getAllInstanceMetadataByStackId(1L)).thenReturn(Set.of(im1));
List<GrainProperties> result = underTest.createGrainProperties(List.of(gwconfig), cluster, Set.of(node1));
assertThat(result, hasItem(allOf(hasProperty("properties", allOf(hasEntry("GWHOSTNAME", Map.of("gateway-address", "GWPUBADDR")))))));
assertThat(result, hasItem(allOf(hasProperty("properties", allOf(hasEntry("NMHOST", Map.of("roles", "namenode")))))));
assertThat(result, hasItem(allOf(hasProperty("properties", allOf(hasEntry("KWGHOST", Map.of("roles", "knox")))))));
assertThat(result, hasItem(allOf(hasProperty("properties", allOf(hasEntry("node1fqdn", Map.of("roles", "LOG_CLOUD_IDENTITY_ROLE")))))));
}
Aggregations