Search in sources :

Example 1 with SpiDto

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);
}
Also used : CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) SpiDto(com.sequenceiq.mock.spi.SpiDto) Test(org.junit.jupiter.api.Test)

Example 2 with SpiDto

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);
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) SpiDto(com.sequenceiq.mock.spi.SpiDto) Test(org.junit.jupiter.api.Test)

Example 3 with SpiDto

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);
}
Also used : CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) CloudStack(com.sequenceiq.cloudbreak.cloud.model.CloudStack) SpiDto(com.sequenceiq.mock.spi.SpiDto) Test(org.junit.jupiter.api.Test)

Example 4 with SpiDto

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;
}
Also used : Logger(org.slf4j.Logger) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) LoggerFactory(org.slf4j.LoggerFactory) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) UUID(java.util.UUID) ArrayList(java.util.ArrayList) Value(org.springframework.beans.factory.annotation.Value) List(java.util.List) InstanceStatus(com.sequenceiq.cloudbreak.cloud.model.InstanceStatus) Service(org.springframework.stereotype.Service) Group(com.sequenceiq.cloudbreak.cloud.model.Group) SpiDto(com.sequenceiq.mock.spi.SpiDto) PostConstruct(javax.annotation.PostConstruct) Optional(java.util.Optional) InstanceTemplate(com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) Group(com.sequenceiq.cloudbreak.cloud.model.Group) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) ArrayList(java.util.ArrayList) NotFoundException(com.sequenceiq.cloudbreak.common.exception.NotFoundException) CloudInstance(com.sequenceiq.cloudbreak.cloud.model.CloudInstance) CloudInstanceMetaData(com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData) CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)

Example 5 with SpiDto

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();
}
Also used : CloudVmMetaDataStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus) CheckResult(com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult) SpiDto(com.sequenceiq.mock.spi.SpiDto) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

SpiDto (com.sequenceiq.mock.spi.SpiDto)9 CloudStack (com.sequenceiq.cloudbreak.cloud.model.CloudStack)6 Test (org.junit.jupiter.api.Test)6 CloudVmMetaDataStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmMetaDataStatus)5 CloudInstanceMetaData (com.sequenceiq.cloudbreak.cloud.model.CloudInstanceMetaData)4 CloudVmInstanceStatus (com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus)4 ArrayList (java.util.ArrayList)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 CloudInstance (com.sequenceiq.cloudbreak.cloud.model.CloudInstance)1 Group (com.sequenceiq.cloudbreak.cloud.model.Group)1 InstanceStatus (com.sequenceiq.cloudbreak.cloud.model.InstanceStatus)1 InstanceTemplate (com.sequenceiq.cloudbreak.cloud.model.InstanceTemplate)1 NotFoundException (com.sequenceiq.cloudbreak.common.exception.NotFoundException)1 ApplyResponse (com.sequenceiq.cloudbreak.orchestrator.salt.domain.ApplyResponse)1 CheckResult (com.sequenceiq.freeipa.client.healthcheckmodel.CheckResult)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Optional (java.util.Optional)1