Search in sources :

Example 1 with Builder

use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint.Builder in project cloudbreak by hortonworks.

the class ContainerConstraintFactory method getAmbariAgentConstraint.

public ContainerConstraint getAmbariAgentConstraint(String ambariServerHost, String ambariAgentApp, String cloudPlatform, HostGroup hostGroup, Integer adjustment, List<String> hostBlackList, String identifier) {
    String containerInstanceName;
    containerInstanceName = YARN.equals(hostGroup.getCluster().getStack().getOrchestrator().getType()) ? createContainerInstanceNameForYarn(hostGroup, AMBARI_AGENT.getName(), identifier) : createContainerInstanceName(hostGroup, AMBARI_AGENT.getName(), identifier);
    Constraint hgConstraint = hostGroup.getConstraint();
    Builder builder = new Builder().withNamePrefix(containerInstanceName).withAppName(ambariAgentApp).networkMode(HOST_NETWORK_MODE);
    if (hgConstraint.getInstanceGroup() != null) {
        InstanceGroup instanceGroup = hgConstraint.getInstanceGroup();
        Map<String, String> dataVolumeBinds = new HashMap<>();
        dataVolumeBinds.put("/var/log/ambari-agent-container", CONTAINER_VOLUME_PATH);
        dataVolumeBinds.put(HADOOP_MOUNT_DIR, HADOOP_MOUNT_DIR);
        dataVolumeBinds.putAll(ImmutableMap.of("/data/jars", "/data/jars", HOST_VOLUME_PATH, CONTAINER_VOLUME_PATH));
        builder.addVolumeBindings(dataVolumeBinds);
        if (adjustment != null) {
            List<String> candidates = collectUpscaleCandidates(hostGroup.getCluster().getId(), hostGroup.getName(), adjustment);
            builder.addHosts(getHosts(candidates, instanceGroup));
        } else {
            builder.addHosts(getHosts(null, instanceGroup));
        }
        builder.cmd(new String[] { String.format("/usr/sbin/init systemd.setenv=AMBARI_SERVER_ADDR=%s systemd.setenv=CLOUD_PLATFORM=%s", ambariServerHost, cloudPlatform) });
    }
    if (hgConstraint.getConstraintTemplate() != null) {
        builder.cpus(hgConstraint.getConstraintTemplate().getCpu());
        builder.memory(hgConstraint.getConstraintTemplate().getMemory());
        builder.constraints(getConstraints(hostBlackList));
        if (adjustment != null) {
            builder.instances(adjustment);
        } else {
            builder.instances(hgConstraint.getHostCount());
        }
        builder.withDiskSize(hgConstraint.getConstraintTemplate().getDisk());
        Map<String, String> dataVolumeBinds = new HashMap<>();
        dataVolumeBinds.put("/var/log/ambari-agent-container", CONTAINER_VOLUME_PATH);
        builder.addVolumeBindings(dataVolumeBinds);
        builder.cmd(new String[] { String.format("/usr/sbin/init systemd.setenv=AMBARI_SERVER_ADDR=%s systemd.setenv=USE_CONSUL_DNS=false", ambariServerHost) });
    }
    return builder.build();
}
Also used : ContainerConstraint(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint) Constraint(com.sequenceiq.cloudbreak.domain.Constraint) HashMap(java.util.HashMap) Builder(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint.Builder) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup)

Example 2 with Builder

use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint.Builder in project cloudbreak by hortonworks.

the class ContainerConstraintFactory method getAmbariServerConstraint.

public ContainerConstraint getAmbariServerConstraint(String dbHostname, String gatewayHostname, String cloudPlatform, String clusterName, String identifier) {
    String env = String.format("/usr/sbin/init systemd.setenv=POSTGRES_DB=%s systemd.setenv=CLOUD_PLATFORM=%s", dbHostname, cloudPlatform);
    Builder builder = new Builder().withName(createContainerInstanceName(AMBARI_SERVER.getName(), clusterName, identifier)).instances(1).networkMode(HOST_NETWORK_MODE).tcpPortBinding(new TcpPortBinding(AMBARI_PORT, "0.0.0.0", AMBARI_PORT)).addVolumeBindings(ImmutableMap.of("/var/log/ambari-server-container", CONTAINER_VOLUME_PATH, "/etc/krb5.conf", "/etc/krb5.conf")).addEnv(ImmutableMap.of("SERVICE_NAME", "ambari-8080"));
    if (!StringUtils.isEmpty(gatewayHostname)) {
        builder.addHosts(ImmutableList.of(gatewayHostname));
    } else {
        env += " systemd.setenv=USE_CONSUL_DNS=false";
    }
    builder.cmd(new String[] { env });
    return builder.build();
}
Also used : TcpPortBinding(com.sequenceiq.cloudbreak.orchestrator.model.port.TcpPortBinding) Builder(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint.Builder)

Example 3 with Builder

use of com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint.Builder in project cloudbreak by hortonworks.

the class ClusterContainerRunnerTest method runNewNodesClusterContainersWhenContainerRunnerFailed.

@Test
public void runNewNodesClusterContainersWhenContainerRunnerFailed() 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 FailedMockContainerOrchestrator());
    when(clusterService.retrieveClusterByStackId(anyLong())).thenReturn(cluster);
    thrown.expect(CloudbreakException.class);
    thrown.expectMessage("com.sequenceiq.cloudbreak.orchestrator.exception.CloudbreakOrchestratorFailedException: failed");
    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);
    when(hostGroupRepository.findHostGroupInClusterByName(anyLong(), anyString())).thenReturn(TestUtil.hostGroup());
    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(instanceMetaDataRepository.findAliveInstancesInInstanceGroup(anyLong())).thenReturn(new ArrayList<>());
    when(containerService.save(anyList())).thenReturn(new ArrayList<>());
    when(constraintFactory.getAmbariAgentConstraint(ambariServer.getHost(), null, stack.cloudPlatform(), TestUtil.hostGroup(), hostGroupAdjustment.getScalingAdjustment(), new ArrayList<>(), "")).thenReturn(new Builder().build());
    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) Builder(com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint.Builder) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) HostGroupAdjustmentJson(com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson) Stack(com.sequenceiq.cloudbreak.domain.Stack) HashSet(java.util.HashSet) GatewayConfig(com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig) Test(org.junit.Test)

Aggregations

Builder (com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint.Builder)3 HostGroupAdjustmentJson (com.sequenceiq.cloudbreak.api.model.HostGroupAdjustmentJson)1 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)1 Constraint (com.sequenceiq.cloudbreak.domain.Constraint)1 Container (com.sequenceiq.cloudbreak.domain.Container)1 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)1 InstanceMetaData (com.sequenceiq.cloudbreak.domain.InstanceMetaData)1 Stack (com.sequenceiq.cloudbreak.domain.Stack)1 DockerContainer (com.sequenceiq.cloudbreak.orchestrator.container.DockerContainer)1 ContainerConstraint (com.sequenceiq.cloudbreak.orchestrator.model.ContainerConstraint)1 GatewayConfig (com.sequenceiq.cloudbreak.orchestrator.model.GatewayConfig)1 TcpPortBinding (com.sequenceiq.cloudbreak.orchestrator.model.port.TcpPortBinding)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Test (org.junit.Test)1