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);
}
}
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;
}
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;
}
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;
}
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);
}
});
}
Aggregations