Search in sources :

Example 26 with InstanceGroup

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");
}
Also used : InstanceTemplateV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.template.InstanceTemplateV4Request) Mappable(com.sequenceiq.cloudbreak.common.mappable.Mappable) InstanceGroupV4Request(com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.request.instancegroup.InstanceGroupV4Request) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test)

Example 27 with InstanceGroup

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"));
}
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 28 with InstanceGroup

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"));
}
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 29 with InstanceGroup

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");
}
Also used : ServiceLocationMap(com.sequenceiq.cloudbreak.cluster.model.ServiceLocationMap) ClusterPreCreationApi(com.sequenceiq.cloudbreak.cluster.api.ClusterPreCreationApi) Template(com.sequenceiq.cloudbreak.domain.Template) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Secret(com.sequenceiq.cloudbreak.service.secret.domain.Secret) ClouderaManagerRepo(com.sequenceiq.cloudbreak.cloud.model.ClouderaManagerRepo) ExposedService(com.sequenceiq.cloudbreak.api.service.ExposedService) ServiceLocation(com.sequenceiq.cloudbreak.cluster.model.ServiceLocation) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) HashSet(java.util.HashSet) RdsConfigWithoutCluster(com.sequenceiq.cloudbreak.domain.view.RdsConfigWithoutCluster)

Example 30 with InstanceGroup

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")))))));
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData) Node(com.sequenceiq.cloudbreak.common.orchestration.Node) GrainProperties(com.sequenceiq.cloudbreak.orchestrator.model.GrainProperties) Json(com.sequenceiq.cloudbreak.common.json.Json) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) InstanceGroup(com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceGroup (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup)288 InstanceMetaData (com.sequenceiq.cloudbreak.domain.stack.instance.InstanceMetaData)132 Stack (com.sequenceiq.cloudbreak.domain.stack.Stack)93 Test (org.junit.jupiter.api.Test)91 HashSet (java.util.HashSet)68 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)57 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)47 Template (com.sequenceiq.cloudbreak.domain.Template)45 Test (org.junit.Test)44 Json (com.sequenceiq.cloudbreak.common.json.Json)38 Set (java.util.Set)37 Cluster (com.sequenceiq.cloudbreak.domain.stack.cluster.Cluster)34 ArrayList (java.util.ArrayList)31 LinkedHashSet (java.util.LinkedHashSet)31 Map (java.util.Map)28 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)27 DetailedEnvironmentResponse (com.sequenceiq.environment.api.v1.environment.model.response.DetailedEnvironmentResponse)27 List (java.util.List)26 HostGroup (com.sequenceiq.cloudbreak.domain.stack.cluster.host.HostGroup)25 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)22