Search in sources :

Example 1 with InstanceMetaDataResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse in project cloudbreak by hortonworks.

the class InstanceMetaDataToInstanceMetaDataResponseConverter method convert.

@Override
public InstanceMetaDataResponse convert(InstanceMetaData source) {
    InstanceMetaDataResponse metaDataJson = new InstanceMetaDataResponse();
    metaDataJson.setPrivateIp(source.getPrivateIp());
    if (source.getPublicIp() != null) {
        metaDataJson.setPublicIp(source.getPublicIp());
    } else if (source.getPrivateIp() != null) {
        metaDataJson.setPublicIp(NOT_AVAILABLE);
    }
    metaDataJson.setSshPort(source.getSshPort());
    metaDataJson.setInstanceId(source.getInstanceId());
    metaDataJson.setDiscoveryFQDN(source.getDiscoveryFQDN());
    metaDataJson.setInstanceGroup(source.getInstanceGroup().getGroupName());
    metaDataJson.setInstanceStatus(source.getInstanceStatus());
    metaDataJson.setInstanceType(source.getInstanceMetadataType());
    metaDataJson.setLifeCycle(source.getLifeCycle());
    metaDataJson.setAvailabilityZone(source.getAvailabilityZone());
    metaDataJson.setSubnetId(source.getSubnetId());
    return metaDataJson;
}
Also used : InstanceMetaDataResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse)

Example 2 with InstanceMetaDataResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse in project cloudbreak by hortonworks.

the class FreeIpaRepairAction method action.

public FreeIpaTestDto action(TestContext testContext, FreeIpaTestDto testDto, FreeIpaClient client) throws Exception {
    Log.when(LOGGER, format(" FreeIPA CRN: %s", testDto.getRequest().getEnvironmentCrn()));
    RepairInstancesRequest request = new RepairInstancesRequest();
    request.setForceRepair(true);
    request.setEnvironmentCrn(testDto.getRequest().getEnvironmentCrn());
    List<String> instanceIds = testDto.getResponse().getInstanceGroups().stream().map(InstanceGroupResponse::getMetaData).flatMap(Collection::stream).filter(im -> instanceMetadataType.equals(im.getInstanceType())).map(InstanceMetaDataResponse::getInstanceId).collect(Collectors.toList());
    request.setInstanceIds(instanceIds);
    Log.whenJson(LOGGER, format(" FreeIPA repair request: %n"), request);
    client.getDefaultClient().getFreeIpaV1Endpoint().repairInstances(request);
    return testDto;
}
Also used : InstanceGroupResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupResponse) RepairInstancesRequest(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest)

Example 3 with InstanceMetaDataResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse in project cloudbreak by hortonworks.

the class SshJClientActions method getFreeIpaInstanceGroupIps.

private List<String> getFreeIpaInstanceGroupIps(String environmentCrn, FreeIpaClient freeipaClient, boolean publicIp) {
    List<String> instanceIPs = new ArrayList<>();
    freeipaClient.getDefaultClient().getFreeIpaV1Endpoint().describe(environmentCrn).getInstanceGroups().forEach(ig -> {
        InstanceMetaDataResponse instanceMetaDataResponse = ig.getMetaData().stream().findFirst().orElse(null);
        assert instanceMetaDataResponse != null;
        LOGGER.info("The selected Instance Group [{}] and the available Private IP [{}] and Public IP [{}]]. {} ip will be used.", instanceMetaDataResponse.getInstanceGroup(), instanceMetaDataResponse.getPrivateIp(), instanceMetaDataResponse.getPublicIp(), publicIp ? "Public" : "Private");
        instanceIPs.add(publicIp ? instanceMetaDataResponse.getPublicIp() : instanceMetaDataResponse.getPrivateIp());
    });
    return instanceIPs;
}
Also used : ArrayList(java.util.ArrayList) InstanceMetaDataResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse)

Example 4 with InstanceMetaDataResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse in project cloudbreak by hortonworks.

the class FreeIpaInstanceUtil method getInstanceIds.

public List<String> getInstanceIds(FreeIpaTestDto freeIpaTestDto, FreeIpaClient freeIpaClient, String hostGroupName) {
    DescribeFreeIpaResponse describeFreeIpaResponse = freeIpaClient.getDefaultClient().getFreeIpaV1Endpoint().describe(freeIpaTestDto.getRequest().getEnvironmentCrn());
    List<InstanceGroupResponse> instanceGroupResponses = describeFreeIpaResponse.getInstanceGroups();
    InstanceGroupResponse instanceGroupResponse = instanceGroupResponses.stream().filter(instanceGroup -> instanceGroup.getName().equals(hostGroupName)).findFirst().orElse(null);
    return Objects.requireNonNull(instanceGroupResponse).getMetaData().stream().map(InstanceMetaDataResponse::getInstanceId).collect(Collectors.toList());
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) InstanceGroupResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupResponse)

Example 5 with InstanceMetaDataResponse

use of com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse in project cloudbreak by hortonworks.

the class FreeIpaConfigProviderTest method testPgwNotChosenIfNotCreated.

@Test
public void testPgwNotChosenIfNotCreated() {
    DescribeFreeIpaResponse freeIpaResponse = new DescribeFreeIpaResponse();
    InstanceGroupResponse instanceGroupResponse = new InstanceGroupResponse();
    InstanceMetaDataResponse pgw = createInstanceMetadata("d", TERMINATED);
    pgw.setInstanceType(InstanceMetadataType.GATEWAY_PRIMARY);
    instanceGroupResponse.setMetaData(Set.of(createInstanceMetadata("b", TERMINATED), createInstanceMetadata("a", REQUESTED), createInstanceMetadata("f", CREATED), pgw, createInstanceMetadata("c", CREATED)));
    freeIpaResponse.setInstanceGroups(List.of(instanceGroupResponse));
    when(freeipaClient.findByEnvironmentCrn(ENVIRONMENT_CRN)).thenReturn(Optional.of(freeIpaResponse));
    Map<String, Object> result = underTest.createFreeIpaConfig(ENVIRONMENT_CRN);
    assertEquals(1, result.size());
    assertEquals("c", result.get("host"));
}
Also used : DescribeFreeIpaResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse) InstanceGroupResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupResponse) InstanceMetaDataResponse(com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse) Test(org.junit.jupiter.api.Test)

Aggregations

InstanceMetaDataResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceMetaDataResponse)8 InstanceGroupResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.common.instance.InstanceGroupResponse)5 DescribeFreeIpaResponse (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.describe.DescribeFreeIpaResponse)4 Test (org.junit.jupiter.api.Test)2 RepairInstancesRequest (com.sequenceiq.freeipa.api.v1.freeipa.stack.model.repair.RepairInstancesRequest)1 InstanceMetaData (com.sequenceiq.freeipa.entity.InstanceMetaData)1 ArrayList (java.util.ArrayList)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1