Search in sources :

Example 1 with InstanceMetaDataJson

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;
}
Also used : InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)

Example 2 with InstanceMetaDataJson

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);
        }
    }
}
Also used : Logger(org.slf4j.Logger) Cluster(com.sequenceiq.periscope.domain.Cluster) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LoggerFactory(org.slf4j.LoggerFactory) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) ApplicationListener(org.springframework.context.ApplicationListener) UpdateFailedEvent(com.sequenceiq.periscope.monitor.event.UpdateFailedEvent) HashSet(java.util.HashSet) Inject(javax.inject.Inject) InstanceMetadataType(com.sequenceiq.cloudbreak.api.model.InstanceMetadataType) FailureReport(com.sequenceiq.cloudbreak.api.model.FailureReport) Component(org.springframework.stereotype.Component) Map(java.util.Map) InstanceStatus(com.sequenceiq.cloudbreak.api.model.InstanceStatus) MDCBuilder(com.sequenceiq.periscope.log.MDCBuilder) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) ClusterState(com.sequenceiq.periscope.api.model.ClusterState) Optional(java.util.Optional) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson) Collections(java.util.Collections) CloudbreakClientConfiguration(com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration) ClusterService(com.sequenceiq.periscope.service.ClusterService) FailureReport(com.sequenceiq.cloudbreak.api.model.FailureReport) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)

Example 3 with InstanceMetaDataJson

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);
    }
}
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 4 with InstanceMetaDataJson

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;
}
Also used : ArrayList(java.util.ArrayList) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)

Example 5 with InstanceMetaDataJson

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);
}
Also used : InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson) Test(org.junit.Test)

Aggregations

InstanceMetaDataJson (com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)5 InstanceGroupResponse (com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse)2 StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)2 ArrayList (java.util.ArrayList)2 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 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)1 FailureReport (com.sequenceiq.cloudbreak.api.model.FailureReport)1 InstanceMetadataType (com.sequenceiq.cloudbreak.api.model.InstanceMetadataType)1 InstanceStatus (com.sequenceiq.cloudbreak.api.model.InstanceStatus)1 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)1 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)1 ClusterState (com.sequenceiq.periscope.api.model.ClusterState)1 Cluster (com.sequenceiq.periscope.domain.Cluster)1 MDCBuilder (com.sequenceiq.periscope.log.MDCBuilder)1 UpdateFailedEvent (com.sequenceiq.periscope.monitor.event.UpdateFailedEvent)1 ClusterService (com.sequenceiq.periscope.service.ClusterService)1 CloudbreakClientConfiguration (com.sequenceiq.periscope.service.configuration.CloudbreakClientConfiguration)1