Search in sources :

Example 26 with StackResponse

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;
}
Also used : CloudbreakImageNotFoundException(com.sequenceiq.cloudbreak.core.CloudbreakImageNotFoundException) ArrayList(java.util.ArrayList) ClusterResponse(com.sequenceiq.cloudbreak.api.model.ClusterResponse) CredentialResponse(com.sequenceiq.cloudbreak.api.model.CredentialResponse) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) Image(com.sequenceiq.cloudbreak.cloud.model.Image) OrchestratorResponse(com.sequenceiq.cloudbreak.api.model.OrchestratorResponse) FailurePolicyResponse(com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse) ImageJson(com.sequenceiq.cloudbreak.api.model.ImageJson) NetworkResponse(com.sequenceiq.cloudbreak.api.model.NetworkResponse) StackAuthenticationResponse(com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse)

Example 27 with StackResponse

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)));
}
Also used : AfterClass(org.testng.annotations.AfterClass) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) BeforeClass(org.testng.annotations.BeforeClass) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.testng.annotations.Test) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudbreakITContextConstants(com.sequenceiq.it.cloudbreak.CloudbreakITContextConstants) MockServer(com.sequenceiq.it.cloudbreak.v2.mock.MockServer) InstanceGroupV2Request(com.sequenceiq.cloudbreak.api.model.v2.InstanceGroupV2Request) Optional(org.testng.annotations.Optional) Assert(org.testng.Assert) Map(java.util.Map) Parameters(org.testng.annotations.Parameters) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) InstanceMetaDataJson(com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson) CloudbreakUtil(com.sequenceiq.it.cloudbreak.CloudbreakUtil) CloudbreakV2Constants(com.sequenceiq.it.cloudbreak.v2.CloudbreakV2Constants) Collections(java.util.Collections) HashMap(java.util.HashMap) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Example 28 with StackResponse

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);
        }
    });
}
Also used : AfterClass(org.testng.annotations.AfterClass) BeforeClass(org.testng.annotations.BeforeClass) BeforeMethod(org.testng.annotations.BeforeMethod) Test(org.testng.annotations.Test) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudbreakITContextConstants(com.sequenceiq.it.cloudbreak.CloudbreakITContextConstants) Optional(org.testng.annotations.Optional) ScalingUtil(com.sequenceiq.it.cloudbreak.scaling.ScalingUtil) Assert(org.testng.Assert) Map(java.util.Map) Parameters(org.testng.annotations.Parameters) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) StackV2Request(com.sequenceiq.cloudbreak.api.model.v2.StackV2Request) CloudbreakV2Constants(com.sequenceiq.it.cloudbreak.v2.CloudbreakV2Constants) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) StackScalingV2Test(com.sequenceiq.it.cloudbreak.v2.StackScalingV2Test) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudVmInstanceStatus(com.sequenceiq.cloudbreak.cloud.model.CloudVmInstanceStatus) InstanceGroupResponse(com.sequenceiq.cloudbreak.api.model.InstanceGroupResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) BeforeClass(org.testng.annotations.BeforeClass) Parameters(org.testng.annotations.Parameters)

Example 29 with StackResponse

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));
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) UpdateStackJson(com.sequenceiq.cloudbreak.api.model.UpdateStackJson) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Example 30 with 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"));
}
Also used : InstanceGroupRequest(com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest) CloudbreakDetailsJson(com.sequenceiq.cloudbreak.api.model.CloudbreakDetailsJson) ClusterResponse(com.sequenceiq.cloudbreak.api.model.ClusterResponse) CredentialResponse(com.sequenceiq.cloudbreak.api.model.CredentialResponse) OrchestratorResponse(com.sequenceiq.cloudbreak.api.model.OrchestratorResponse) TypeDescriptor(org.springframework.core.convert.TypeDescriptor) ImageJson(com.sequenceiq.cloudbreak.api.model.ImageJson) NetworkResponse(com.sequenceiq.cloudbreak.api.model.NetworkResponse) StackAuthenticationResponse(com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse) StackResponse(com.sequenceiq.cloudbreak.api.model.StackResponse) Test(org.junit.Test)

Aggregations

StackResponse (com.sequenceiq.cloudbreak.api.model.StackResponse)32 Test (org.testng.annotations.Test)10 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)9 Parameters (org.testng.annotations.Parameters)9 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)8 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)7 Map (java.util.Map)7 CredentialResponse (com.sequenceiq.cloudbreak.api.model.CredentialResponse)6 ImageJson (com.sequenceiq.cloudbreak.api.model.ImageJson)6 OrchestratorResponse (com.sequenceiq.cloudbreak.api.model.OrchestratorResponse)6 StackAuthenticationResponse (com.sequenceiq.cloudbreak.api.model.StackAuthenticationResponse)6 HashMap (java.util.HashMap)6 CloudbreakDetailsJson (com.sequenceiq.cloudbreak.api.model.CloudbreakDetailsJson)5 ClusterResponse (com.sequenceiq.cloudbreak.api.model.ClusterResponse)5 FailurePolicyResponse (com.sequenceiq.cloudbreak.api.model.FailurePolicyResponse)5 InstanceGroupRequest (com.sequenceiq.cloudbreak.api.model.InstanceGroupRequest)5 InstanceMetaDataJson (com.sequenceiq.cloudbreak.api.model.InstanceMetaDataJson)5 NetworkResponse (com.sequenceiq.cloudbreak.api.model.NetworkResponse)5 CloudbreakClient (com.sequenceiq.cloudbreak.client.CloudbreakClient)5 Test (org.junit.Test)5