use of com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson in project cloudbreak by hortonworks.
the class InstanceMetaDataToInstanceMetaDataJsonConverter method convert.
@Override
public InstanceMetaDataJson convert(InstanceMetaData entity) {
InstanceMetaDataJson metaDataJson = new InstanceMetaDataJson();
metaDataJson.setPrivateIp(entity.getPrivateIp());
if (entity.getPublicIp() != null) {
metaDataJson.setPublicIp(entity.getPublicIp());
} else if (entity.getPrivateIp() != null) {
metaDataJson.setPublicIp(NOT_AVAILABLE);
}
metaDataJson.setSshPort(entity.getSshPort());
metaDataJson.setAmbariServer(entity.getAmbariServer());
metaDataJson.setInstanceId(entity.getInstanceId());
metaDataJson.setDiscoveryFQDN(entity.getDiscoveryFQDN());
metaDataJson.setInstanceGroup(entity.getInstanceGroup().getGroupName());
metaDataJson.setInstanceStatus(entity.getInstanceStatus());
metaDataJson.setInstanceType(entity.getInstanceMetadataType());
return metaDataJson;
}
use of com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson in project cloudbreak by hortonworks.
the class UpdateFailedHandler method reportAmbariServerFailure.
private void reportAmbariServerFailure(Cluster cluster, StackResponse stackResponse, CloudbreakClient cbClient) {
Optional<InstanceMetaDataJson> pgw = stackResponse.getInstanceGroups().stream().flatMap(ig -> ig.getMetadata().stream()).filter(im -> im.getInstanceType() == InstanceMetadataType.GATEWAY_PRIMARY && im.getInstanceStatus() != InstanceStatus.TERMINATED).findFirst();
if (pgw.isPresent()) {
FailureReport failureReport = new FailureReport();
failureReport.setFailedNodes(Collections.singletonList(pgw.get().getDiscoveryFQDN()));
try {
cbClient.clusterEndpoint().failureReport(cluster.getStackId(), failureReport);
} catch (Exception e) {
LOGGER.warn("Exception during failure report", e);
}
}
}
use of com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson 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.InstanceMetaDataJson in project cloudbreak by hortonworks.
the class TagsUtil method getInstancesList.
protected static List<String> getInstancesList(StackResponse stackResponse) {
List<InstanceGroupResponse> instanceGroups = stackResponse.getInstanceGroups();
List<String> instanceIdList = new ArrayList<>();
for (InstanceGroupResponse instanceGroup : instanceGroups) {
Set<InstanceMetaDataJson> instanceMetaData = instanceGroup.getMetadata();
for (InstanceMetaDataJson metaData : instanceMetaData) {
instanceIdList.add(metaData.getInstanceId());
}
}
return instanceIdList;
}
use of com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson in project cloudbreak by hortonworks.
the class InstanceMetaDataToInstanceMetaDataJsonConverterTest method testConvert.
@Test
public void testConvert() {
// GIVEN
// WHEN
InstanceMetaDataJson result = underTest.convert(getSource());
// THEN
assertEquals("test-1-1", result.getDiscoveryFQDN());
assertTrue(result.getAmbariServer());
assertAllFieldsNotNull(result);
}
Aggregations