use of com.sequenceiq.cloudbreak.api.model.StackResponse 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.StackResponse in project cloudbreak by hortonworks.
the class CloudbreakUtil method getAmbariIp.
public static String getAmbariIp(StackEndpoint stackV1Endpoint, String stackId, IntegrationTestContext itContext) {
String ambariIp = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_IP_ID);
if (StringUtils.isEmpty(ambariIp)) {
StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
ambariIp = stackResponse.getCluster().getAmbariServerIp();
Assert.assertNotNull(ambariIp, "The Ambari IP is not available!");
itContext.putContextParam(CloudbreakITContextConstants.AMBARI_IP_ID, ambariIp);
}
return ambariIp;
}
use of com.sequenceiq.cloudbreak.api.model.StackResponse in project cloudbreak by hortonworks.
the class CloudbreakUtil method waitForHostStatusStack.
public static WaitResult waitForHostStatusStack(StackEndpoint stackV1Endpoint, String stackId, String hostGroup, String desiredStatus) {
WaitResult waitResult = WaitResult.SUCCESSFUL;
Boolean found = FALSE;
int retryCount = 0;
do {
LOGGER.info("Waiting for host status {} in hostgroup {} ...", desiredStatus, hostGroup);
sleep();
StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
Set<HostGroupResponse> hostGroupResponse = stackResponse.getCluster().getHostGroups();
for (HostGroupResponse hr : hostGroupResponse) {
if (hr.getName().equals(hostGroup)) {
Set<HostMetadataResponse> hostMetadataResponses = hr.getMetadata();
for (HostMetadataResponse hmr : hostMetadataResponses) {
if (hmr.getState().equals(desiredStatus)) {
found = Boolean.TRUE;
}
}
}
}
retryCount++;
} while (!found && (retryCount < MAX_RETRY));
if (retryCount == MAX_RETRY) {
waitResult = WaitResult.TIMEOUT;
}
return waitResult;
}
use of com.sequenceiq.cloudbreak.api.model.StackResponse in project cloudbreak by hortonworks.
the class CloudbreakUtil method checkClusterAvailability.
public static void checkClusterAvailability(StackEndpoint stackV1Endpoint, String port, String stackId, String ambariUser, String ambariPassowrd, boolean checkAmbari) {
StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
checkClusterAvailability(stackResponse, port, stackId, ambariUser, ambariPassowrd, checkAmbari);
}
use of com.sequenceiq.cloudbreak.api.model.StackResponse in project cloudbreak by hortonworks.
the class ClusterSecurityService method hasAccess.
private boolean hasAccess(String userId, String account, String ambariAddress, Long stackId) {
StackResponse stack;
if (stackId != null) {
stack = cloudbreakClient.stackV1Endpoint().get(stackId, new HashSet<>());
} else {
AmbariAddressJson ambariAddressJson = new AmbariAddressJson();
ambariAddressJson.setAmbariAddress(ambariAddress);
stack = cloudbreakClient.stackV1Endpoint().getStackForAmbari(ambariAddressJson);
}
return stack.getOwner().equals(userId) || (stack.isPublicInAccount() && stack.getAccount().equals(account));
}
Aggregations