use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MetadataSetupServiceTest method saveInstanceMetaDataTestOneNewInstance.
@Test
public void saveInstanceMetaDataTestOneNewInstance() throws CloudbreakImageNotFoundException {
when(imageService.getImage(STACK_ID)).thenReturn(image);
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setId(INSTANCE_GROUP_ID);
instanceGroup.setGroupName(GROUP_NAME);
Set<InstanceGroup> instanceGroupSet = new TreeSet<>();
instanceGroupSet.add(instanceGroup);
when(instanceGroupService.findByStackId(STACK_ID)).thenReturn(instanceGroupSet);
when(clock.getCurrentTimeMillis()).thenReturn(CURRENT_TIME);
Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = getCloudVmMetaDataStatuses(InstanceStatus.CREATED);
InstanceMetaData pgwInstanceMetadata = new InstanceMetaData();
pgwInstanceMetadata.setInstanceMetadataType(GATEWAY_PRIMARY);
when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of(pgwInstanceMetadata));
int newInstances = underTest.saveInstanceMetaData(stack, cloudVmMetaDataStatuses, CREATED);
assertEquals(1, newInstances);
verify(imageService).getImage(STACK_ID);
verify(instanceMetaDataService).save(instanceMetaDataCaptor.capture());
InstanceMetaData instanceMetaData = instanceMetaDataCaptor.getValue();
assertThat(instanceMetaData.getInstanceGroup()).isSameAs(instanceGroup);
assertCommonProperties(instanceMetaData);
assertEquals(CREATED, instanceMetaData.getInstanceStatus());
assertNotNull(instanceMetaData.getImage());
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MetadataSetupServiceTest method saveInstanceMetaDataTestOneZombieInstance.
@Test
public void saveInstanceMetaDataTestOneZombieInstance() {
Stack stack = new Stack();
stack.setId(STACK_ID);
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setId(INSTANCE_GROUP_ID);
instanceGroup.setGroupName(GROUP_NAME);
Set<InstanceGroup> instanceGroupSet = new TreeSet<>();
instanceGroupSet.add(instanceGroup);
when(instanceGroupService.findByStackId(STACK_ID)).thenReturn(instanceGroupSet);
when(clock.getCurrentTimeMillis()).thenReturn(CURRENT_TIME);
Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = getCloudVmMetaDataStatuses(InstanceStatus.CREATED);
InstanceMetaData pgwInstanceMetadata = new InstanceMetaData();
pgwInstanceMetadata.setInstanceMetadataType(GATEWAY_PRIMARY);
InstanceMetaData zombieInstanceMetadata = new InstanceMetaData();
zombieInstanceMetadata.setInstanceStatus(ZOMBIE);
zombieInstanceMetadata.setPrivateId(PRIVATE_ID);
when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of(zombieInstanceMetadata, pgwInstanceMetadata));
int newInstances = underTest.saveInstanceMetaData(stack, cloudVmMetaDataStatuses, SERVICES_RUNNING);
assertEquals(1, newInstances);
verifyNoInteractions(imageService);
verify(instanceMetaDataService).save(instanceMetaDataCaptor.capture());
InstanceMetaData instanceMetaData = instanceMetaDataCaptor.getValue();
assertThat(instanceMetaData.getInstanceGroup()).isSameAs(instanceGroup);
assertCommonProperties(instanceMetaData);
assertEquals(ZOMBIE, instanceMetaData.getInstanceStatus());
assertNull(instanceMetaData.getImage());
assertFalse(instanceMetaData.getClusterManagerServer());
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MetadataSetupServiceTest method saveInstanceMetaDataTestServerFlagIsAlreadySet.
@ParameterizedTest(name = "{0}")
@MethodSource("saveInstanceMetaDataTestServerFlagIsAlreadySetDataProvider")
public void saveInstanceMetaDataTestServerFlagIsAlreadySet(String testCaseName, String subnetId, String availabilityZone, String rackId) throws CloudbreakImageNotFoundException {
when(imageService.getImage(STACK_ID)).thenReturn(image);
InstanceGroup instanceGroup = new InstanceGroup();
instanceGroup.setId(INSTANCE_GROUP_ID);
instanceGroup.setGroupName(GROUP_NAME);
Set<InstanceGroup> instanceGroupSet = new TreeSet<>();
instanceGroupSet.add(instanceGroup);
when(instanceGroupService.findByStackId(STACK_ID)).thenReturn(instanceGroupSet);
when(clock.getCurrentTimeMillis()).thenReturn(CURRENT_TIME);
Iterable<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = getCloudVmMetaDataStatuses(InstanceStatus.STOPPED);
InstanceMetaData originalInstanceMetadata = new InstanceMetaData();
originalInstanceMetadata.setServer(true);
originalInstanceMetadata.setInstanceId("instanceId");
originalInstanceMetadata.setPrivateId(PRIVATE_ID);
originalInstanceMetadata.setInstanceGroup(instanceGroup);
originalInstanceMetadata.setInstanceMetadataType(GATEWAY_PRIMARY);
originalInstanceMetadata.setSubnetId(subnetId);
originalInstanceMetadata.setAvailabilityZone(availabilityZone);
originalInstanceMetadata.setRackId(rackId);
when(instanceMetaDataService.findNotTerminatedForStack(STACK_ID)).thenReturn(Set.of(originalInstanceMetadata));
int newInstances = underTest.saveInstanceMetaData(stack, cloudVmMetaDataStatuses, SERVICES_RUNNING);
assertEquals(0, newInstances);
verify(imageService).getImage(STACK_ID);
verify(instanceMetaDataService).save(instanceMetaDataCaptor.capture());
InstanceMetaData instanceMetaData = instanceMetaDataCaptor.getValue();
assertThat(instanceMetaData.getInstanceGroup()).isSameAs(instanceGroup);
assertTrue(instanceMetaData.getAmbariServer());
assertTrue(instanceMetaData.getClusterManagerServer());
assertThat(instanceMetaData.getSubnetId()).isEqualTo(subnetId);
assertThat(instanceMetaData.getAvailabilityZone()).isEqualTo(availabilityZone);
assertThat(instanceMetaData.getRackId()).isEqualTo(rackId);
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MetadataSetupServiceTest method testSaveInstanceMetadataAndSelectTheRightPGW.
@Test
public void testSaveInstanceMetadataAndSelectTheRightPGW() throws CloudbreakImageNotFoundException {
List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id1", new InstanceTemplate("medium", "gateway", 10L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 40L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.1", "1.1.1.1")));
cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id2", new InstanceTemplate("medium", "gateway", 11L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 40L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.2", "1.1.1.2")));
cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id3", new InstanceTemplate("medium", "worker", 12L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 41L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.2", "1.1.1.2")));
InstanceMetaData lastTerminatedPGW = new InstanceMetaData();
String primaryGWDiscoveryFQDN = "primarygw.example.com";
lastTerminatedPGW.setDiscoveryFQDN(primaryGWDiscoveryFQDN);
when(instanceMetaDataService.getLastTerminatedPrimaryGatewayInstanceMetadata(1L)).thenReturn(Optional.of(lastTerminatedPGW));
InstanceMetaData gwInstanceMetadata1 = new InstanceMetaData();
InstanceGroup gwInstanceGroup = new InstanceGroup();
gwInstanceGroup.setGroupName("gateway");
gwInstanceGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
gwInstanceMetadata1.setInstanceGroup(gwInstanceGroup);
gwInstanceMetadata1.setPrivateId(10L);
gwInstanceMetadata1.setDiscoveryFQDN(primaryGWDiscoveryFQDN);
InstanceMetaData gwInstanceMetadata2 = new InstanceMetaData();
gwInstanceMetadata2.setInstanceGroup(gwInstanceGroup);
gwInstanceMetadata2.setPrivateId(11L);
String gw1DiscoveryFQDN = "gw1.example.com";
gwInstanceMetadata2.setDiscoveryFQDN(gw1DiscoveryFQDN);
InstanceGroup workerInstanceGroup = new InstanceGroup();
workerInstanceGroup.setGroupName("worker");
workerInstanceGroup.setInstanceGroupType(InstanceGroupType.CORE);
InstanceMetaData gwInstanceMetadata3 = new InstanceMetaData();
gwInstanceMetadata3.setInstanceGroup(workerInstanceGroup);
gwInstanceMetadata3.setPrivateId(12L);
String gw2DiscoveryFQDN = "gw2.example.com";
gwInstanceMetadata3.setDiscoveryFQDN(gw2DiscoveryFQDN);
when(imageService.getImage(STACK_ID)).thenReturn(image);
when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of(gwInstanceMetadata1, gwInstanceMetadata2, gwInstanceMetadata3));
underTest.saveInstanceMetaData(stack, cloudVmMetaDataStatuses, CREATED);
verify(instanceMetaDataService, times(3)).save(instanceMetaDataCaptor.capture());
List<InstanceMetaData> savedInstanceMetadatas = instanceMetaDataCaptor.getAllValues();
List<InstanceMetaData> primaryGWs = savedInstanceMetadatas.stream().filter(instanceMetaData -> GATEWAY_PRIMARY.equals(instanceMetaData.getInstanceMetadataType())).collect(Collectors.toList());
assertEquals(1, primaryGWs.size());
assertEquals(primaryGWDiscoveryFQDN, primaryGWs.get(0).getDiscoveryFQDN());
List<InstanceMetaData> gws = savedInstanceMetadatas.stream().filter(instanceMetaData -> GATEWAY.equals(instanceMetaData.getInstanceMetadataType())).collect(Collectors.toList());
assertEquals(1, gws.size());
assertEquals(gw1DiscoveryFQDN, gws.get(0).getDiscoveryFQDN());
}
use of com.sequenceiq.cloudbreak.domain.stack.instance.InstanceGroup in project cloudbreak by hortonworks.
the class MetadataSetupServiceTest method testSaveInstanceMetadataAndSelectTheRightPGWButFQDNDidNotMatchSoFallback.
@Test
public void testSaveInstanceMetadataAndSelectTheRightPGWButFQDNDidNotMatchSoFallback() throws CloudbreakImageNotFoundException {
List<CloudVmMetaDataStatus> cloudVmMetaDataStatuses = new ArrayList<>();
cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id1", new InstanceTemplate("medium", "gateway", 10L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 40L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.1", "1.1.1.1")));
cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id2", new InstanceTemplate("medium", "gateway", 11L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 40L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.2", "1.1.1.2")));
cloudVmMetaDataStatuses.add(new CloudVmMetaDataStatus(new CloudVmInstanceStatus(new CloudInstance("id3", new InstanceTemplate("medium", "worker", 12L, Collections.emptyList(), InstanceStatus.CREATED, Map.of(), 41L, "imageid", TemporaryStorage.ATTACHED_VOLUMES, 0L), null, "subnet", "az"), InstanceStatus.CREATED), new CloudInstanceMetaData("1.1.1.3", "1.1.1.3")));
InstanceMetaData lastTerminatedPGW = new InstanceMetaData();
String primaryGWDiscoveryFQDN = "primarygw.example.com";
lastTerminatedPGW.setDiscoveryFQDN(primaryGWDiscoveryFQDN);
when(instanceMetaDataService.getLastTerminatedPrimaryGatewayInstanceMetadata(1L)).thenReturn(Optional.of(lastTerminatedPGW));
InstanceMetaData gwInstanceMetadata1 = new InstanceMetaData();
InstanceGroup gwInstanceGroup = new InstanceGroup();
gwInstanceGroup.setGroupName("gateway");
gwInstanceGroup.setInstanceGroupType(InstanceGroupType.GATEWAY);
gwInstanceMetadata1.setInstanceGroup(gwInstanceGroup);
gwInstanceMetadata1.setPrivateId(10L);
String gw1DiscoveryFQDN = "gw1.example.com";
gwInstanceMetadata1.setDiscoveryFQDN(gw1DiscoveryFQDN);
InstanceMetaData gwInstanceMetadata2 = new InstanceMetaData();
gwInstanceMetadata2.setInstanceGroup(gwInstanceGroup);
gwInstanceMetadata2.setPrivateId(11L);
String gw2DiscoveryFQDN = "gw2.example.com";
gwInstanceMetadata2.setDiscoveryFQDN(gw2DiscoveryFQDN);
gwInstanceGroup.setInstanceMetaData(Set.of(gwInstanceMetadata1, gwInstanceMetadata2));
InstanceGroup workerInstanceGroup = new InstanceGroup();
workerInstanceGroup.setGroupName("worker");
workerInstanceGroup.setInstanceGroupType(InstanceGroupType.CORE);
InstanceMetaData workerInstanceMetadata3 = new InstanceMetaData();
workerInstanceMetadata3.setInstanceGroup(workerInstanceGroup);
workerInstanceMetadata3.setPrivateId(12L);
String worker1DiscoveryFQDN = "worker1.example.com";
workerInstanceMetadata3.setDiscoveryFQDN(worker1DiscoveryFQDN);
workerInstanceGroup.setInstanceMetaData(Set.of(workerInstanceMetadata3));
when(imageService.getImage(STACK_ID)).thenReturn(image);
when(instanceGroupService.findByStackId(1L)).thenReturn(Set.of(gwInstanceGroup, workerInstanceGroup));
when(instanceMetaDataService.findAllByInstanceGroupAndInstanceStatusOrdered(gwInstanceGroup, com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceStatus.CREATED)).thenReturn(List.of(gwInstanceMetadata1, gwInstanceMetadata2));
when(instanceMetaDataService.findNotTerminatedForStack(1L)).thenReturn(Set.of(gwInstanceMetadata1, gwInstanceMetadata2, workerInstanceMetadata3));
underTest.saveInstanceMetaData(stack, cloudVmMetaDataStatuses, CREATED);
verify(instanceMetaDataService, times(4)).save(instanceMetaDataCaptor.capture());
List<InstanceMetaData> savedInstanceMetadatas = instanceMetaDataCaptor.getAllValues();
List<InstanceMetaData> primaryGWs = savedInstanceMetadatas.stream().filter(instanceMetaData -> GATEWAY_PRIMARY.equals(instanceMetaData.getInstanceMetadataType())).distinct().collect(Collectors.toList());
assertEquals(1, primaryGWs.size());
assertEquals(gw1DiscoveryFQDN, primaryGWs.get(0).getDiscoveryFQDN());
List<InstanceMetaData> gws = savedInstanceMetadatas.stream().filter(instanceMetaData -> GATEWAY.equals(instanceMetaData.getInstanceMetadataType())).collect(Collectors.toList());
assertEquals(1, gws.size());
assertEquals(gw2DiscoveryFQDN, gws.get(0).getDiscoveryFQDN());
}
Aggregations