Search in sources :

Example 11 with HostGroupAdjustmentJson

use of com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson in project cloudbreak by hortonworks.

the class ClusterContainerRunnerTest method runNewNodesClusterContainersWhenContainerRunnerCancelled.

@Test(expected = CancellationException.class)
public void runNewNodesClusterContainersWhenContainerRunnerCancelled() throws CloudbreakException {
    Stack stack = TestUtil.stack();
    Cluster cluster = TestUtil.cluster(TestUtil.blueprint(), stack, 1L);
    stack.setCluster(cluster);
    HostGroupAdjustmentJson hostGroupAdjustment = new HostGroupAdjustmentJson();
    hostGroupAdjustment.setHostGroup("agent");
    when(containerOrchestratorResolver.get(anyString())).thenReturn(new CancelledMockContainerOrchestrator());
    when(stackRepository.findOneWithLists(anyLong())).thenReturn(stack);
    when(tlsSecurityService.buildGatewayConfig(anyLong(), any(InstanceMetaData.class), anyInt(), any(), any())).thenReturn(new GatewayConfig("10.0.0.1", "198.0.0.1", "10.0.0.1", 8443, false));
    when(clusterService.retrieveClusterByStackId(anyLong())).thenReturn(cluster);
    when(hostGroupRepository.findHostGroupInClusterByName(anyLong(), anyString())).thenReturn(TestUtil.hostGroup());
    Set<Container> containers = new HashSet<>();
    Container ambariServer = new Container();
    ambariServer.setName("server");
    ambariServer.setImage(DockerContainer.AMBARI_SERVER.getName());
    ambariServer.setHost("hostname-1");
    ambariServer.setContainerId("1");
    Container ambariAgent = new Container();
    ambariAgent.setName("agent");
    ambariAgent.setImage(DockerContainer.AMBARI_AGENT.getName());
    ambariAgent.setHost("hostname-2");
    ambariAgent.setContainerId("1");
    containers.add(ambariAgent);
    containers.add(ambariServer);
    when(containerService.findContainersInCluster(anyLong())).thenReturn(containers);
    underTest.addClusterContainers(stack.getId(), hostGroupAdjustment.getHostGroup(), hostGroupAdjustment.getScalingAdjustment());
}
Also used : InstanceMetaData(com.sequenceiq.cloudbreak.domain.InstanceMetaData) DockerContainer(com.sequenceiq.cloudbreak.orchestrator.container.DockerContainer) Container(com.sequenceiq.cloudbreak.domain.Container) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) Stack(com.sequenceiq.cloudbreak.domain.Stack) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 12 with HostGroupAdjustmentJson

use of com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson in project cloudbreak by hortonworks.

the class ReactorFlowManagerTest method shouldReturnTheNextFailureTransition.

@Test
public void shouldReturnTheNextFailureTransition() {
    InstanceGroupAdjustmentJson instanceGroupAdjustment = new InstanceGroupAdjustmentJson();
    HostGroupAdjustmentJson hostGroupAdjustment = new HostGroupAdjustmentJson();
    underTest.triggerProvisioning(stackId);
    underTest.triggerClusterInstall(stackId);
    underTest.triggerClusterReInstall(stackId);
    underTest.triggerStackStop(stackId);
    underTest.triggerStackStart(stackId);
    underTest.triggerClusterStop(stackId);
    underTest.triggerClusterStart(stackId);
    underTest.triggerTermination(stackId, false, false);
    underTest.triggerTermination(stackId, false, true);
    underTest.triggerStackUpscale(stackId, instanceGroupAdjustment, true);
    underTest.triggerStackDownscale(stackId, instanceGroupAdjustment);
    underTest.triggerStackRemoveInstance(stackId, "hostgroup", "hostname");
    underTest.triggerClusterUpscale(stackId, hostGroupAdjustment);
    underTest.triggerClusterDownscale(stackId, hostGroupAdjustment);
    underTest.triggerClusterSync(stackId);
    underTest.triggerStackSync(stackId);
    underTest.triggerFullSync(stackId);
    underTest.triggerClusterCredentialReplace(stackId, "admin", "admin1");
    underTest.triggerClusterCredentialUpdate(stackId, "admin1");
    underTest.triggerClusterTermination(stackId, false, false);
    underTest.triggerClusterTermination(stackId, true, false);
    underTest.triggerClusterUpgrade(stackId);
    underTest.triggerManualRepairFlow(stackId);
    underTest.triggerStackRepairFlow(stackId, new UnhealthyInstances());
    underTest.triggerClusterRepairFlow(stackId, new HashMap<>(), true);
    underTest.triggerEphemeralUpdate(stackId);
    // Not start from 0 because flow cancellations
    int count = 5;
    for (Method method : underTest.getClass().getDeclaredMethods()) {
        if (method.getName().startsWith("trigger")) {
            count++;
        }
    }
    verify(reactor, times(count)).notify((Object) anyObject(), any(Event.class));
}
Also used : UnhealthyInstances(com.sequenceiq.cloudbreak.service.stack.repair.UnhealthyInstances) Event(reactor.bus.Event) ClusterTerminationEvent(com.sequenceiq.cloudbreak.core.flow2.cluster.termination.ClusterTerminationEvent) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 13 with HostGroupAdjustmentJson

use of com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson in project cloudbreak by hortonworks.

the class UpdateStackRequestV2ToUpdateClusterRequestConverter method convert.

@Override
public UpdateClusterJson convert(StackScaleRequestV2 source) {
    UpdateClusterJson updateStackJson = new UpdateClusterJson();
    Cluster oneByStackId = clusterRepository.findOneByStackId(source.getStackId());
    HostGroup hostGroup = hostGroupRepository.findHostGroupInClusterByName(oneByStackId.getId(), source.getGroup());
    if (hostGroup != null) {
        HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
        hostGroupAdjustmentJson.setWithStackUpdate(true);
        hostGroupAdjustmentJson.setValidateNodeCount(true);
        hostGroupAdjustmentJson.setHostGroup(source.getGroup());
        int scaleNumber = source.getDesiredCount() - hostGroup.getHostMetadata().size();
        hostGroupAdjustmentJson.setScalingAdjustment(scaleNumber);
        updateStackJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
    } else {
        throw new BadRequestException(String.format("Group '%s' not available on stack", source.getGroup()));
    }
    return updateStackJson;
}
Also used : Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) BadRequestException(com.sequenceiq.cloudbreak.controller.BadRequestException) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) UpdateClusterJson(com.sequenceiq.cloudbreak.api.model.UpdateClusterJson)

Example 14 with HostGroupAdjustmentJson

use of com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson in project cloudbreak by hortonworks.

the class MockClusterScalingTest method testScaling.

@SuppressWarnings("Duplicates")
@Test
@Parameters({ "instanceGroup", "scalingAdjustment", "mockPort" })
public void testScaling(@Optional("slave_1") String instanceGroup, @Optional("1") int scalingAdjustment, @Optional("9443") int mockPort) {
    // GIVEN
    IntegrationTestContext itContext = getItContext();
    String stackId = itContext.getContextParam(CloudbreakITContextConstants.STACK_ID);
    int stackIntId = Integer.parseInt(stackId);
    // WHEN
    if (scalingAdjustment < 0) {
        UpdateClusterJson updateClusterJson = new UpdateClusterJson();
        HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
        hostGroupAdjustmentJson.setHostGroup(instanceGroup);
        hostGroupAdjustmentJson.setWithStackUpdate(false);
        hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
        CloudbreakUtil.checkResponse("DownscaleCluster", getCloudbreakClient().clusterEndpoint().put((long) stackIntId, updateClusterJson));
        CloudbreakUtil.waitAndCheckClusterStatus(getCloudbreakClient(), stackId, "AVAILABLE");
        UpdateStackJson updateStackJson = new UpdateStackJson();
        updateStackJson.setWithClusterEvent(false);
        InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
        instanceGroupAdjustmentJson.setInstanceGroup(instanceGroup);
        instanceGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
        CloudbreakUtil.checkResponse("DownscaleStack", getCloudbreakClient().stackV1Endpoint().put((long) stackIntId, updateStackJson));
        CloudbreakUtil.waitAndCheckStackStatus(getCloudbreakClient(), stackId, "AVAILABLE");
    } else {
        UpdateStackJson updateStackJson = new UpdateStackJson();
        updateStackJson.setWithClusterEvent(false);
        InstanceGroupAdjustmentJson instanceGroupAdjustmentJson = new InstanceGroupAdjustmentJson();
        instanceGroupAdjustmentJson.setInstanceGroup(instanceGroup);
        instanceGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        updateStackJson.setInstanceGroupAdjustment(instanceGroupAdjustmentJson);
        CloudbreakUtil.checkResponse("UpscaleStack", getCloudbreakClient().stackV1Endpoint().put((long) stackIntId, updateStackJson));
        CloudbreakUtil.waitAndCheckStackStatus(getCloudbreakClient(), stackId, "AVAILABLE");
        UpdateClusterJson updateClusterJson = new UpdateClusterJson();
        HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
        hostGroupAdjustmentJson.setHostGroup(instanceGroup);
        hostGroupAdjustmentJson.setWithStackUpdate(false);
        hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
        updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
        CloudbreakUtil.checkResponse("UpscaleCluster", getCloudbreakClient().clusterEndpoint().put((long) stackIntId, updateClusterJson));
        CloudbreakUtil.waitAndCheckClusterStatus(getCloudbreakClient(), stackId, "AVAILABLE");
    }
    // THEN
    CloudbreakUtil.checkClusterAvailability(itContext.getContextParam(CloudbreakITContextConstants.CLOUDBREAK_CLIENT, CloudbreakClient.class).stackV1Endpoint(), "8080", stackId, itContext.getContextParam(CloudbreakITContextConstants.AMBARI_USER_ID), itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PASSWORD_ID), false);
    ScalingMock scalingMock = getItContext().getContextParam(CloudbreakV2Constants.MOCK_SERVER, ScalingMock.class);
    scalingMock.verifyV1Calls(CLUSTER_NAME, scalingAdjustment, false);
}
Also used : UpdateStackJson(com.sequenceiq.cloudbreak.api.model.UpdateStackJson) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) InstanceGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.InstanceGroupAdjustmentJson) ScalingMock(com.sequenceiq.it.cloudbreak.v2.mock.ScalingMock) UpdateClusterJson(com.sequenceiq.cloudbreak.api.model.UpdateClusterJson) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Example 15 with HostGroupAdjustmentJson

use of com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson in project cloudbreak by hortonworks.

the class ClusterAndStackDownscaleTest method testClusterAndStackDownscale.

@Test
@Parameters({ "instanceGroup", "scalingAdjustment" })
public void testClusterAndStackDownscale(@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();
    String ambariUser = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_USER_ID);
    String ambariPassword = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PASSWORD_ID);
    String ambariPort = itContext.getContextParam(CloudbreakITContextConstants.AMBARI_PORT_ID);
    int expectedNodeCountStack = ScalingUtil.getNodeCountStack(stackV1Endpoint, stackId) + scalingAdjustment;
    int expectedNodeCountCluster = ScalingUtil.getNodeCountAmbari(stackV1Endpoint, ambariPort, stackId, ambariUser, ambariPassword, itContext) + scalingAdjustment;
    // WHEN
    UpdateClusterJson updateClusterJson = new UpdateClusterJson();
    HostGroupAdjustmentJson hostGroupAdjustmentJson = new HostGroupAdjustmentJson();
    hostGroupAdjustmentJson.setHostGroup(instanceGroup);
    hostGroupAdjustmentJson.setWithStackUpdate(true);
    hostGroupAdjustmentJson.setScalingAdjustment(scalingAdjustment);
    updateClusterJson.setHostGroupAdjustment(hostGroupAdjustmentJson);
    CloudbreakUtil.checkResponse("DownscaleCluster", getCloudbreakClient().clusterEndpoint().put((long) stackIntId, updateClusterJson));
    CloudbreakUtil.waitAndCheckClusterStatus(getCloudbreakClient(), stackId, "AVAILABLE");
    CloudbreakUtil.waitAndCheckStackStatus(getCloudbreakClient(), stackId, "AVAILABLE");
    // THEN
    ScalingUtil.checkStackScaled(stackV1Endpoint, stackId, expectedNodeCountStack);
    ScalingUtil.checkClusterScaled(stackV1Endpoint, ambariPort, stackId, ambariUser, ambariPassword, expectedNodeCountCluster, itContext);
    ScalingUtil.putInstanceCountToContext(itContext, stackId);
}
Also used : StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) IntegrationTestContext(com.sequenceiq.it.IntegrationTestContext) CloudbreakClient(com.sequenceiq.cloudbreak.client.CloudbreakClient) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) StackV1Endpoint(com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint) UpdateClusterJson(com.sequenceiq.cloudbreak.api.model.UpdateClusterJson) Parameters(org.testng.annotations.Parameters) AbstractCloudbreakIntegrationTest(com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest) Test(org.testng.annotations.Test)

Aggregations

HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)16 Test (org.junit.Test)11 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)9 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)9 HashSet (java.util.HashSet)8 AmbariClient (com.sequenceiq.ambari.client.AmbariClient)6 Status (com.sequenceiq.cloudbreak.api.model.Status)6 HttpClientConfig (com.sequenceiq.cloudbreak.client.HttpClientConfig)6 HostMetadata (com.sequenceiq.cloudbreak.domain.HostMetadata)6 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)6 UpdateClusterJson (com.sequenceiq.cloudbreak.api.model.UpdateClusterJson)5 Collections.singletonMap (java.util.Collections.singletonMap)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Matchers.anyString (org.mockito.Matchers.anyString)4 IntegrationTestContext (com.sequenceiq.it.IntegrationTestContext)3 AbstractCloudbreakIntegrationTest (com.sequenceiq.it.cloudbreak.AbstractCloudbreakIntegrationTest)3 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 StackV1Endpoint (com.sequenceiq.cloudbreak.api.endpoint.v1.StackV1Endpoint)2