use of com.sequenceiq.mock.spi.SpiDto in project cloudbreak by hortonworks.
the class DefaultModelServiceTest method testGenerateWithMoreThan255AndOneMissing.
@Test
public void testGenerateWithMoreThan255AndOneMissing() {
CloudStack cloudStack = mock(CloudStack.class);
SpiDto spiDto = new SpiDto("", cloudStack);
generate(spiDto, 256);
spiDto.getVmMetaDataStatuses().remove(10);
String actual = underTest.generateAddress("192", spiDto, 1, Collections.emptyList());
Assertions.assertEquals("192.1.0.10", actual);
}
use of com.sequenceiq.mock.spi.SpiDto in project cloudbreak by hortonworks.
the class DefaultModelServiceTest method testGenerateAddressWhenSpiDtoEmptyButListHasEntry.
@Test
public void testGenerateAddressWhenSpiDtoEmptyButListHasEntry() {
CloudStack cloudStack = mock(CloudStack.class);
SpiDto spiDto = new SpiDto("", cloudStack);
CloudVmInstanceStatus cloudVmInstanceStatus = mock(CloudVmInstanceStatus.class);
List<CloudVmMetaDataStatus> current = new ArrayList<>();
current.add(new CloudVmMetaDataStatus(cloudVmInstanceStatus, new CloudInstanceMetaData("192.1.0.0", "1.1.1.1")));
String actual = underTest.generateAddress("192", spiDto, 1, current);
Assertions.assertEquals("192.1.0.1", actual);
}
use of com.sequenceiq.mock.spi.SpiDto in project cloudbreak by hortonworks.
the class DefaultModelServiceTest method testGenerateAddressWhenOnExistsAndShouldGenerateNewOne.
@Test
public void testGenerateAddressWhenOnExistsAndShouldGenerateNewOne() {
CloudStack cloudStack = mock(CloudStack.class);
CloudVmInstanceStatus cloudVmInstanceStatus = mock(CloudVmInstanceStatus.class);
SpiDto spiDto = new SpiDto("", cloudStack);
spiDto.getVmMetaDataStatuses().add(new CloudVmMetaDataStatus(cloudVmInstanceStatus, new CloudInstanceMetaData("192.1.0.0", "1.1.1.1")));
String actual = underTest.generateAddress("192", spiDto, 1, Collections.emptyList());
Assertions.assertEquals("192.1.0.1", actual);
}
use of com.sequenceiq.mock.spi.SpiDto in project cloudbreak by hortonworks.
the class DefaultModelService method createInstances.
public List<CloudVmMetaDataStatus> createInstances(String name, SpiDto spiDto, List<Group> groups) {
List<CloudVmMetaDataStatus> ret = new ArrayList<>();
String prefix = "192";
for (int groupIndex = 0; groupIndex < groups.size(); groupIndex++) {
List<Group> existedGroups = spiDto.getCloudStack().getGroups();
Group group = groups.get(groupIndex);
Optional<Group> existedGroupOpt = existedGroups.stream().filter(g -> group.getName().equals(g.getName())).findFirst();
if (existedGroupOpt.isEmpty()) {
throw new NotFoundException("Cannot find group with name: " + group.getName());
}
Group existedGroup = existedGroupOpt.get();
int indexOfExistedGroup = existedGroups.indexOf(existedGroup);
for (int instanceIndex = 0; instanceIndex < group.getInstances().size(); instanceIndex++) {
CloudInstance cloudInstance = group.getInstances().get(instanceIndex);
String address = generateAddress(prefix, spiDto, indexOfExistedGroup, ret);
String instanceId = String.format("instance-%s", address + "-" + UUID.randomUUID());
CloudInstance cloudInstanceWithId = new CloudInstance(instanceId, getTemplateCreated(cloudInstance), cloudInstance.getAuthentication(), cloudInstance.getSubnetId(), cloudInstance.getAvailabilityZone());
CloudVmInstanceStatus cloudVmInstanceStatus = new CloudVmInstanceStatus(cloudInstanceWithId, InstanceStatus.STARTED);
String publicIp = mockInfrastructureHost + ":10090/" + name;
CloudInstanceMetaData cloudInstanceMetaData = new CloudInstanceMetaData(address, publicIp, SSH_PORT, "MOCK");
CloudVmMetaDataStatus cloudVmMetaDataStatus = new CloudVmMetaDataStatus(cloudVmInstanceStatus, cloudInstanceMetaData);
ret.add(cloudVmMetaDataStatus);
}
}
return ret;
}
use of com.sequenceiq.mock.spi.SpiDto in project cloudbreak by hortonworks.
the class FreeipaHealthCheckController method healthCheck.
@RequestMapping("/freeipahealthcheck")
public ResponseEntity<CheckResult> healthCheck(@PathVariable("mock_uuid") String mockUuid) {
SpiDto read = spiStoreService.read(mockUuid.replace(":9443", ""));
Optional<CloudVmMetaDataStatus> first = read.getVmMetaDataStatuses().stream().findFirst();
CheckResult checkResult = new CheckResult();
if (first.isPresent() && first.get().getCloudVmInstanceStatus().getStatus() == InstanceStatus.STARTED) {
checkResult.setHost(first.get().getMetaData().getPublicIp());
checkResult.setStatus("healthy");
return ResponseEntity.ok(checkResult);
}
return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();
}
Aggregations