use of com.sequenceiq.cloudbreak.api.model.StackResponse 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.StackResponse in project cloudbreak by hortonworks.
the class MockInstanceTerminationReplicationTest method testInstanceTermination.
@Test
public void testInstanceTermination() throws Exception {
// GIVEN
// WHEN
Long stackId = Long.parseLong(getItContext().getContextParam(CloudbreakITContextConstants.STACK_ID));
StackResponse stackResponse = getStackResponse(stackId);
// THEN
String hostGroupName = "worker";
int before = getInstanceMetaData(stackResponse, hostGroupName).size();
String instanceId = getInstanceId(stackResponse, hostGroupName);
getCloudbreakClient().stackV2Endpoint().deleteInstance(stackResponse.getId(), instanceId);
Map<String, String> desiredStatuses = new HashMap<>();
desiredStatuses.put("status", "AVAILABLE");
desiredStatuses.put("clusterStatus", "AVAILABLE");
CloudbreakUtil.waitAndCheckStatuses(getCloudbreakClient(), stackId.toString(), desiredStatuses);
int after = getInstanceMetaData(getStackResponse(stackId), hostGroupName).size();
Assert.assertEquals(after, before - 1);
stackResponse = getStackResponse(stackId);
Assert.assertTrue(getInstanceMetaData(stackResponse, hostGroupName).stream().noneMatch(a -> a.getDiscoveryFQDN().equals(instanceId)));
}
use of com.sequenceiq.cloudbreak.api.model.StackResponse 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);
}
});
}
use of com.sequenceiq.cloudbreak.api.model.StackResponse in project cloudbreak by hortonworks.
the class StackScalingTest method testStackScaling.
@Test
@Parameters({ "instanceGroup", "scalingAdjustment" })
public void testStackScaling(@Optional("slave_1") String instanceGroup, int scalingAdjustment) {
// GIVEN
IntegrationTestContext itContext = getItContext();
String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
int stackIntId = Integer.parseInt(stackId);
StackV1Endpoint stackV1Endpoint = itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackV1Endpoint();
int expectedNodeCount = ScalingUtil.getNodeCountStack(stackV1Endpoint, stackId) + scalingAdjustment;
// WHEN
UpdateStackJson updateStackJson = new UpdateStackJson();
updateStackJson.setWithClusterEvent(false);
InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
instanceGroupAdjustmentJson.setInstanceGroup(instanceGroup);
instanceGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
CloudbreakUtil.checkResponse("ScalingStack", getCloudbreakClient().stackV1Endpoint().put((long) stackIntId, updateStackJson));
CloudbreakUtil.waitAndCheckStackStatus(getCloudbreakClient(), stackId, "AVAILABLE");
// THEN
ScalingUtil.checkStackScaled(stackV1Endpoint, stackId, expectedNodeCount);
StackResponse stackResponse = stackV1Endpoint.get(Long.valueOf(stackId), new HashSet<>());
itContext.putContextParam(CloudbreakITContextConstants.INSTANCE_COUNT, ScalingUtil.getNodeCountByHostgroup(stackResponse));
}
use of com.sequenceiq.cloudbreak.api.model.StackResponse in project cloudbreak by hortonworks.
the class StackToStackResponseConverterTest method testConvertWithoutFailurePolicy.
@Test
public void testConvertWithoutFailurePolicy() {
// GIVEN
getSource().setFailurePolicy(null);
given(conversionService.convert(any(Object.class), any(Class.class))).willReturn(new ImageJson()).willReturn(new StackAuthenticationResponse()).willReturn(new CredentialResponse()).willReturn(new ClusterResponse()).willReturn(new NetworkResponse()).willReturn(new OrchestratorResponse()).willReturn(new CloudbreakDetailsJson()).willReturn(new CredentialResponse()).willReturn(new NetworkResponse());
given(conversionService.convert(any(Object.class), any(TypeDescriptor.class), any(TypeDescriptor.class))).willReturn(new HashSet<InstanceGroupRequest>());
// WHEN
StackResponse result = underTest.convert(getSource());
// THEN
assertAllFieldsNotNull(result, Arrays.asList("failurePolicy", "platformVariant", "ambariVersion", "hdpVersion", "stackTemplate", "cloudbreakDetails", "flexSubscription"));
}
Aggregations