Search in sources :

Example 6 with InstanceGroupResponse

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

the class AwsCheckSpotInstance method checkSpotInstance.

@Parameters({ "region", "hostGroupToCheck", "scalingAdjustment" })
@Test
public void checkSpotInstance(Regions region, String hostGroupToCheck, @Optional Integer scalingAdjustment) {
    // GIVEN
    Integer spotInstanceCount = 0;
    IntegrationTestContext itContext = getItContext();
    String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
    StackV1Endpoint stackV1Endpoint = getCloudbreakClient().stackV1Endpoint();
    StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
    List<InstanceGroupResponse> instanceGroups = stackResponse.getInstanceGroups();
    Collection<String> instanceIdList = new ArrayList<>();
    List<String> hostGroupList = Arrays.asList(hostGroupToCheck.split(","));
    for (InstanceGroupResponse instanceGroup : instanceGroups) {
        if (hostGroupList.contains(instanceGroup.getGroup())) {
            Set<InstanceMetaDataJson> instanceMetaData = instanceGroup.getMetadata();
            for (InstanceMetaDataJson metaData : instanceMetaData) {
                instanceIdList.add(metaData.getInstanceId());
            }
        }
    }
    // WHEN
    AmazonEC2 ec2 = AmazonEC2ClientBuilder.standard().withRegion(region).build();
    DescribeSpotInstanceRequestsResult describeSpotInstanceRequestsResult = ec2.describeSpotInstanceRequests();
    List<SpotInstanceRequest> spotInstanceRequests = describeSpotInstanceRequestsResult.getSpotInstanceRequests();
    // THEN
    Assert.assertFalse(spotInstanceRequests.isEmpty());
    Collection<String> spotInstanceIdList = new ArrayList<>();
    for (SpotInstanceRequest request : spotInstanceRequests) {
        spotInstanceIdList.add(request.getInstanceId());
    }
    for (String id : instanceIdList) {
        Assert.assertTrue(spotInstanceIdList.contains(id));
        if (spotInstanceIdList.contains(id)) {
            spotInstanceCount += 1;
        }
    }
    if (scalingAdjustment != null) {
        Assert.assertNotNull(itContext.getContextParam(CloudbreakITContextConstants.INSTANCE_COUNT, List.class));
        Integer instanceCountPrev = 0;
        for (String hostGroup : hostGroupList) {
            List<Map<String, Integer>> instanceList = itContext.getContextParam(CloudbreakITContextConstants.INSTANCE_COUNT, List.class);
            Assert.assertTrue(instanceList.size() >= 2);
            instanceCountPrev += instanceList.get(instanceList.size() - 2).get(hostGroup);
        }
        Assert.assertEquals(Integer.valueOf(instanceCountPrev + scalingAdjustment), spotInstanceCount);
    }
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) ArrayList(java.util.ArrayList) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) AmazonEC2(com.amazonaws.services.ec2.AmazonEC2) SpotInstanceRequest(com.amazonaws.services.ec2.model.SpotInstanceRequest) DescribeSpotInstanceRequestsResult(com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsResult) ArrayList(java.util.ArrayList) List(java.util.List) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Map(java.util.Map) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 7 with InstanceGroupResponse

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

the class CloudbreakUtil method getNodeCount.

private static int getNodeCount(StackResponse stackResponse) {
    List<InstanceGroupResponse> instanceGroups = stackResponse.getInstanceGroups();
    int nodeCount = 0;
    for (InstanceGroupResponse instanceGroup : instanceGroups) {
        if (!"cbgateway".equals(instanceGroup.getGroup())) {
            nodeCount += instanceGroup.getNodeCount();
        }
    }
    return nodeCount;
}
Also used : InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) StackEndpoint(com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint) HistoryEndpoint(com.sequenceiq.periscope.api.endpoint.v1.HistoryEndpoint) EventEndpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint)

Example 8 with InstanceGroupResponse

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

the class StackToStackResponseConverter method convert.

@Override
public StackResponse convert(Stack source) {
    StackResponse stackJson = new StackResponse();
    try {
        Image image = imageService.getImage(source.getId());
        stackJson.setImage(getConversionService().convert(image, ImageJson.class));
    } catch (CloudbreakImageNotFoundException exc) {
        LOGGER.info(exc.getMessage());
    }
    stackJson.setName(source.getName());
    stackJson.setOwner(source.getOwner());
    stackJson.setAccount(source.getAccount());
    stackJson.setPublicInAccount(source.isPublicInAccount());
    stackJson.setStackAuthentication(conversionService.convert(source.getStackAuthentication(), StackAuthenticationResponse.class));
    stackJson.setId(source.getId());
    if (source.getCredential() == null) {
        stackJson.setCloudPlatform(null);
        stackJson.setCredentialId(null);
    } else {
        stackJson.setCloudPlatform(source.cloudPlatform());
        stackJson.setCredentialId(source.getCredential().getId());
        stackJson.setCredential(getConversionService().convert(source.getCredential(), CredentialResponse.class));
    }
    stackJson.setStatus(source.getStatus());
    stackJson.setStatusReason(source.getStatusReason());
    stackJson.setRegion(source.getRegion());
    stackJson.setAvailabilityZone(source.getAvailabilityZone());
    stackJson.setOnFailureAction(source.getOnFailureActionAction());
    List<InstanceGroupResponse> templateGroups = new ArrayList<>(convertInstanceGroups(source.getInstanceGroups()));
    stackJson.setInstanceGroups(templateGroups);
    if (source.getCluster() != null) {
        stackJson.setCluster(getConversionService().convert(source.getCluster(), ClusterResponse.class));
    } else {
        stackJson.setCluster(new ClusterResponse());
    }
    if (source.getFailurePolicy() != null) {
        stackJson.setFailurePolicy(getConversionService().convert(source.getFailurePolicy(), FailurePolicyResponse.class));
    }
    if (source.getNetwork() == null) {
        stackJson.setNetworkId(null);
    } else {
        stackJson.setNetworkId(source.getNetwork().getId());
        stackJson.setNetwork(getConversionService().convert(source.getNetwork(), NetworkResponse.class));
    }
    stackJson.setParameters(Maps.newHashMap(source.getParameters()));
    stackJson.setPlatformVariant(source.getPlatformVariant());
    if (source.getOrchestrator() != null) {
        stackJson.setOrchestrator(getConversionService().convert(source.getOrchestrator(), OrchestratorResponse.class));
    }
    stackJson.setCreated(source.getCreated());
    stackJson.setGatewayPort(source.getGatewayPort());
    stackJson.setCustomDomain(source.getCustomDomain());
    stackJson.setCustomHostname(source.getCustomHostname());
    stackJson.setClusterNameAsSubdomain(source.isClusterNameAsSubdomain());
    stackJson.setHostgroupNameAsHostname(source.isHostgroupNameAsHostname());
    addNodeCount(source, stackJson);
    putSubnetIdIntoResponse(source, stackJson);
    putVpcIdIntoResponse(source, stackJson);
    putS3RoleIntoResponse(source, stackJson);
    convertComponentConfig(stackJson, source);
    convertTags(stackJson, source.getTags());
    addFlexSubscription(stackJson, source);
    return stackJson;
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) ArrayList(java.util.ArrayList) ClusterResponse(com.sequenceiq.cloudbreak.api.model.ClusterResponse) CredentialResponse(com.sequenceiq.cloudbreak.api.model.CredentialResponse) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) Image(com.sequenceiq.cloudbreak.cloud.model.Image) OrchestratorResponse(com.sequenceiq.cloudbreak.api.model.OrchestratorResponse) FailurePolicyResponse(com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse) ImageJson(com.sequenceiq.cloudbreak.api.model.ImageJson) NetworkResponse(com.sequenceiq.cloudbreak.api.model.NetworkResponse) StackAuthenticationResponse(com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse)

Example 9 with InstanceGroupResponse

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

the class InstanceGroupToInstanceGroupResponseConverter method convert.

@Override
public InstanceGroupResponse convert(InstanceGroup entity) {
    InstanceGroupResponse instanceGroupResponse = new InstanceGroupResponse();
    instanceGroupResponse.setGroup(entity.getGroupName());
    instanceGroupResponse.setId(entity.getId());
    instanceGroupResponse.setNodeCount(entity.getNodeCount());
    if (entity.getTemplate() != null) {
        instanceGroupResponse.setTemplateId(entity.getTemplate().getId());
        instanceGroupResponse.setTemplate(getConversionService().convert(entity.getTemplate(), TemplateResponse.class));
    }
    instanceGroupResponse.setType(entity.getInstanceGroupType());
    instanceGroupResponse.setMetadata(convertEntitiesToJson(entity.getInstanceMetaData()));
    if (entity.getSecurityGroup() != null) {
        instanceGroupResponse.setSecurityGroup(getConversionService().convert(entity.getSecurityGroup(), SecurityGroupResponse.class));
        instanceGroupResponse.setSecurityGroupId(entity.getSecurityGroup().getId());
    }
    Json attributes = entity.getAttributes();
    if (attributes != null) {
        instanceGroupResponse.setParameters(attributes.getMap());
    }
    return instanceGroupResponse;
}
Also used : SecurityGroupResponse(com.sequenceiq.cloudbreak.api.model.SecurityGroupResponse) TemplateResponse(com.sequenceiq.cloudbreak.api.model.TemplateResponse) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson) Json(com.sequenceiq.cloudbreak.domain.json.Json)

Example 10 with InstanceGroupResponse

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

the class MockScalingTest method configMockServer.

@BeforeClass
@Parameters({ "mockPort", "sshPort", "desiredCount", "hostGroup" })
public void configMockServer(@Optional("9443") int mockPort, @Optional("2020") int sshPort, int desiredCount, String hostGroup) {
    IntegrationTestContext itContext = getItContext();
    String clusterName = itContext.getContextParam(CloudbreakV2Constants.STACK_NAME);
    StackResponse response = getCloudbreakClient().stackV2Endpoint().getPrivate(clusterName, null);
    java.util.Optional<InstanceGroupResponse> igg = response.getInstanceGroups().stream().filter(ig -> ig.getGroup().equals(hostGroup)).findFirst();
    Map<String, CloudVmInstanceStatus> instanceMap = itContext.getContextParam(CloudbreakITContextConstants.MOCK_INSTANCE_MAP, Map.class);
    ScalingMock scalingMock = (ScalingMock) applicationContext.getBean(ScalingMock.NAME, mockPort, sshPort, instanceMap);
    scalingMock.addSPIEndpoints();
    scalingMock.addMockEndpoints();
    scalingMock.addAmbariMappings(clusterName);
    itContext.putContextParam(CloudbreakV2Constants.MOCK_SERVER, scalingMock);
    igg.ifPresent(ig -> {
        int scalingAdjustment = desiredCount - ig.getNodeCount();
        if (scalingAdjustment > 0) {
            scalingMock.addInstance(scalingAdjustment);
        }
    });
}
Also used : AfterClass(org.testng.annotations.AfterClass) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) Test(org.testng.annotations.Test) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudbreakITContextConstants(com.sequenceiq.it.cloudbreak.CloudbreakITContextConstants) Optional(org.testng.annotations.Optional) ScalingUtil(com.sequenceiq.it.cloudbreak.scaling.ScalingUtil) Assert(org.testng.Assert) Map(java.util.Map) Parameters(org.testng.annotations.Parameters) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) StackV2Request(com.sequenceiq.cloudbreak.api.model.v2.StackV2Request) CloudbreakV2Constants(com.sequenceiq.it.cloudbreak.v2.CloudbreakV2Constants) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) StackScalingV2Test(com.sequenceiq.it.cloudbreak.v2.StackScalingV2Test) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) BeforeClass(org.testng.annotations.BeforeClass) Parameters(org.testng.annotations.Parameters)

Aggregations

InstanceGroupResponse (com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse)11 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)5 ArrayList (java.util.ArrayList)4 StackEndpoint (com.sequenceiq.cloudbreak.api.endpoint.common.StackEndpoint)3 InstanceMetaDataJson (com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)3 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)3 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)3 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 Map (java.util.Map)2 AmazonEC2 (com.amazonaws.services.ec2.AmazonEC2)1 DescribeSpotInstanceRequestsResult (com.amazonaws.services.ec2.model.DescribeSpotInstanceRequestsResult)1 SpotInstanceRequest (com.amazonaws.services.ec2.model.SpotInstanceRequest)1 EventEndpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.EventEndpoint)1 ClusterResponse (com.sequenceiq.cloudbreak.api.model.ClusterResponse)1 CredentialResponse (com.sequenceiq.cloudbreak.api.model.CredentialResponse)1 FailurePolicyResponse (com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse)1 ImageJson (com.sequenceiq.cloudbreak.api.model.ImageJson)1 NetworkResponse (com.sequenceiq.cloudbreak.api.model.NetworkResponse)1 OrchestratorResponse (com.sequenceiq.cloudbreak.api.model.OrchestratorResponse)1