Search in sources :

Example 1 with PlatformSshKeysResponse

use of com.sequenceiq.cloudbreak.api.model.PlatformSshKeysResponse in project cloudbreak by hortonworks.

the class CloudSshKeysToPlatformSshKeysResponseConverter method convert.

@Override
public PlatformSshKeysResponse convert(CloudSshKeys source) {
    Map<String, Set<PlatformSshKeyResponse>> result = new HashMap<>();
    for (Entry<String, Set<CloudSshKey>> entry : source.getCloudSshKeysResponses().entrySet()) {
        Set<PlatformSshKeyResponse> sshKeyResponses = new HashSet<>();
        for (CloudSshKey cloudSshKey : entry.getValue()) {
            PlatformSshKeyResponse actual = new PlatformSshKeyResponse(cloudSshKey.getName(), cloudSshKey.getProperties());
            sshKeyResponses.add(actual);
        }
        result.put(entry.getKey(), sshKeyResponses);
    }
    return new PlatformSshKeysResponse(result);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CloudSshKey(com.sequenceiq.cloudbreak.cloud.model.CloudSshKey) PlatformSshKeysResponse(com.sequenceiq.cloudbreak.api.model.PlatformSshKeysResponse) PlatformSshKeyResponse(com.sequenceiq.cloudbreak.api.model.PlatformSshKeyResponse) HashSet(java.util.HashSet)

Example 2 with PlatformSshKeysResponse

use of com.sequenceiq.cloudbreak.api.model.PlatformSshKeysResponse in project cloudbreak by hortonworks.

the class ExistingSshKeySelectionTest method testSshKeySelection.

@Test
@Parameters({ "credentialName", "region", "availabilityZone", "selectedKeyName" })
public void testSshKeySelection(@Optional("") String credentialName, @Optional("") String region, @Optional("") String availabilityZone, String selectedKeyName) {
    // GIVEN
    IntegrationTestContext itContext = getItContext();
    credentialName = StringUtils.hasText(credentialName) ? credentialName : itContext.getContextParam(CloudbreakV2Constants.CREDENTIAL_NAME);
    region = StringUtils.hasText(region) ? region : itContext.getContextParam(CloudbreakV2Constants.REGION);
    availabilityZone = StringUtils.hasText(availabilityZone) ? availabilityZone : itContext.getContextParam(CloudbreakV2Constants.AVAILABILTYZONE);
    PlatformResourceRequestJson resourceRequestJson = new PlatformResourceRequestJson();
    resourceRequestJson.setCredentialName(credentialName);
    resourceRequestJson.setRegion(region);
    resourceRequestJson.setAvailabilityZone(availabilityZone);
    // WHEN
    PlatformSshKeysResponse response = getCloudbreakClient().connectorV1Endpoint().getCloudSshKeys(resourceRequestJson);
    // THEN
    Set<PlatformSshKeyResponse> regionKeys = response.getSshKeys().get(region);
    Assert.assertNotNull(regionKeys, "keys cannot be null for " + region);
    java.util.Optional<PlatformSshKeyResponse> selected = regionKeys.stream().filter(rk -> rk.getName().equals(selectedKeyName)).findFirst();
    Assert.assertTrue(selected.isPresent(), "the sshkey list doesn't contain [" + selectedKeyName + ']');
    getItContext().putContextParam(CloudbreakV2Constants.SSH_PUBLICKEY_ID, selected.get().getName());
}
Also used : Optional(org.testng.annotations.Optional) PlatformResourceRequestJson(com.sequenceiq.cloudbreak.api.model.PlatformResourceRequestJson) Assert(org.testng.Assert) PlatformSshKeysResponse(com.sequenceiq.cloudbreak.api.model.PlatformSshKeysResponse) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Parameters(org.testng.annotations.Parameters) Set(java.util.Set) PlatformSshKeyResponse(com.sequenceiq.cloudbreak.api.model.PlatformSshKeyResponse) Test(org.testng.annotations.Test) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) StringUtils(org.springframework.util.StringUtils) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) PlatformSshKeysResponse(com.sequenceiq.cloudbreak.api.model.PlatformSshKeysResponse) PlatformResourceRequestJson(com.sequenceiq.cloudbreak.api.model.PlatformResourceRequestJson) PlatformSshKeyResponse(com.sequenceiq.cloudbreak.api.model.PlatformSshKeyResponse) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

PlatformSshKeyResponse (com.sequenceiq.cloudbreak.api.model.PlatformSshKeyResponse)2 PlatformSshKeysResponse (com.sequenceiq.cloudbreak.api.model.PlatformSshKeysResponse)2 Set (java.util.Set)2 PlatformResourceRequestJson (com.sequenceiq.cloudbreak.api.model.PlatformResourceRequestJson)1 CloudSshKey (com.sequenceiq.cloudbreak.cloud.model.CloudSshKey)1 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)1 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 StringUtils (org.springframework.util.StringUtils)1 Assert (org.testng.Assert)1 Optional (org.testng.annotations.Optional)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1