use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.
the class GatewayTopologyV4RequestValidatorTest method testWithNoTopologyName.
@Test
public void testWithNoTopologyName() {
GatewayTopologyV4Request gatewayTopologyJson = new GatewayTopologyV4Request();
ValidationResult result = underTest.validate(gatewayTopologyJson);
assertEquals(1L, result.getErrors().size());
assertTrue(result.getErrors().get(0).contains("topologyName must be set in gateway topology."));
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.
the class NetworkV1ToNetworkV4Converter method convertToAwsStackRequest.
private AwsNetworkV4Parameters convertToAwsStackRequest(Pair<AwsNetworkV1Parameters, EnvironmentNetworkResponse> source) {
EnvironmentNetworkResponse value = source.getValue();
AwsNetworkV1Parameters key = source.getKey();
AwsNetworkV4Parameters response = new AwsNetworkV4Parameters();
if (key != null) {
response.setVpcId(value.getAws().getVpcId());
String subnetId = key.getSubnetId();
if (!Strings.isNullOrEmpty(subnetId)) {
response.setSubnetId(key.getSubnetId());
} else if (value != null) {
response.setSubnetId(value.getPreferedSubnetId());
}
if (PublicEndpointAccessGateway.ENABLED.equals(value.getPublicEndpointAccessGateway())) {
ValidationResult validationResult = endpointGatewayNetworkValidator.validate(new ImmutablePair<>(response.getSubnetId(), value));
if (validationResult.getState() == ValidationResult.State.ERROR || validationResult.hasError()) {
throw new BadRequestException("Endpoint gateway subnet validation failed: " + validationResult.getFormattedErrors());
}
Optional<CloudSubnet> endpointGatewaySubnet = subnetSelector.chooseSubnetForEndpointGateway(value, response.getSubnetId());
if (endpointGatewaySubnet.isPresent()) {
response.setEndpointGatewaySubnetId(endpointGatewaySubnet.get().getId());
}
}
}
return response;
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY in project cloudbreak by hortonworks.
the class HostMetadataSetupTest method testSetupNewHostMetadataWithMultipleNonPrimaryChange.
@Test
@DisplayName("when multiple non-primary gateways are repaired and scaled we should not make any changes in the primary gateway assignments")
public void testSetupNewHostMetadataWithMultipleNonPrimaryChange() throws CloudbreakException, CloudbreakOrchestratorException {
Stack stack = mock(Stack.class);
InstanceMetaData im1 = createInstanceMetadata("id1", InstanceMetadataType.GATEWAY, 1L, "10.0.0.1", "host1", false);
InstanceMetaData im2 = createInstanceMetadata("id2", InstanceMetadataType.GATEWAY, 2L, "10.0.0.2", "host2", false);
Set<InstanceMetaData> allNewInstances = Set.of(im1, im2);
when(instanceMetaDataService.getNotDeletedAndNotZombieInstanceMetadataByStackId(STACK_ID)).thenReturn(allNewInstances);
when(stackService.getByIdWithListsInTransaction(STACK_ID)).thenReturn(stack);
when(hostOrchestrator.getMembers(any(), any())).thenReturn(Map.of("10.0.0.1", "host1", "10.0.0.2", "host2"));
hostMetadataSetup.setupNewHostMetadata(STACK_ID, List.of("10.0.0.1", "10.0.0.2"));
verify(instanceMetaDataService, times(0)).getLastTerminatedPrimaryGatewayInstanceMetadata(STACK_ID);
verify(instanceMetaDataService, times(1)).saveAll(instanceMetadataCaptor.capture());
Set<InstanceMetaData> actualIm = instanceMetadataCaptor.getValue();
InstanceMetaData expectedIm1 = createInstanceMetadata("id1", InstanceMetadataType.GATEWAY, 1L, "10.0.0.1", "host1", false);
InstanceMetaData expectedIm2 = createInstanceMetadata("id2", InstanceMetadataType.GATEWAY, 2L, "10.0.0.2", "host2", false);
assertMetadataEquals(expectedIm1, actualIm.stream().filter(im -> im.getPrivateId() == 1L).findFirst().get());
assertMetadataEquals(expectedIm2, actualIm.stream().filter(im -> im.getPrivateId() == 2L).findFirst().get());
}
use of com.sequenceiq.cloudbreak.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY 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.api.endpoint.v4.stacks.base.InstanceMetadataType.GATEWAY 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