Search in sources :

Example 61 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class SchedulerMain method createInstance.

public static SchedulerMain createInstance(String cluster, String role, String env, String topologyJar, String topologyName, int httpPort, Boolean verbose, Properties schedulerProperties) throws IOException, InvalidTopologyException {
    // Look up the topology def file location
    String topologyDefnFile = TopologyUtils.lookUpTopologyDefnFile(".", topologyName);
    // load the topology definition into topology proto
    TopologyAPI.Topology topology = TopologyUtils.getTopology(topologyDefnFile);
    // build the config by expanding all the variables
    Config schedulerConfig = SchedulerConfigUtils.loadConfig(cluster, role, env, topologyJar, topologyDefnFile, verbose, topology);
    // set up logging with complete Config
    setupLogging(schedulerConfig);
    // Create a new instance
    SchedulerMain schedulerMain = new SchedulerMain(schedulerConfig, topology, httpPort, schedulerProperties);
    LOG.log(Level.INFO, "Loaded scheduler config: {0}", schedulerMain.config);
    return schedulerMain;
}
Also used : Config(com.twitter.heron.spi.common.Config) SystemConfig(com.twitter.heron.common.config.SystemConfig) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI)

Example 62 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class AppsV1beta1Controller method getExecutorCommand.

protected List<String> getExecutorCommand(String containerId) {
    final Map<ExecutorPort, String> ports = KubernetesConstants.EXECUTOR_PORTS.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, e -> e.getValue().toString()));
    final Config configuration = getConfiguration();
    final Config runtimeConfiguration = getRuntimeConfiguration();
    final String[] executorCommand = SchedulerUtils.getExecutorCommand(configuration, runtimeConfiguration, containerId, ports);
    return Arrays.asList("sh", "-c", KubernetesUtils.getFetchCommand(configuration, runtimeConfiguration) + " && " + setShardIdEnvironmentVariableCommand() + " && " + String.join(" ", executorCommand));
}
Also used : IntStream(java.util.stream.IntStream) JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) ApiException(io.kubernetes.client.ApiException) V1Container(io.kubernetes.client.models.V1Container) Response(com.squareup.okhttp.Response) HashMap(java.util.HashMap) V1ObjectFieldSelector(io.kubernetes.client.models.V1ObjectFieldSelector) ApiClient(io.kubernetes.client.ApiClient) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) AppsV1beta1Api(io.kubernetes.client.apis.AppsV1beta1Api) JsonElement(com.google.gson.JsonElement) TopologySubmissionException(com.twitter.heron.scheduler.TopologySubmissionException) SchedulerUtils(com.twitter.heron.scheduler.utils.SchedulerUtils) Gson(com.google.gson.Gson) V1EnvVarSource(io.kubernetes.client.models.V1EnvVarSource) Map(java.util.Map) Runtime(com.twitter.heron.scheduler.utils.Runtime) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) ExecutorPort(com.twitter.heron.scheduler.utils.SchedulerUtils.ExecutorPort) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) Config(com.twitter.heron.spi.common.Config) V1ContainerPort(io.kubernetes.client.models.V1ContainerPort) V1EnvVar(io.kubernetes.client.models.V1EnvVar) V1PodTemplateSpec(io.kubernetes.client.models.V1PodTemplateSpec) V1Volume(io.kubernetes.client.models.V1Volume) Set(java.util.Set) IOException(java.io.IOException) TopologyRuntimeManagementException(com.twitter.heron.scheduler.TopologyRuntimeManagementException) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) V1LabelSelector(io.kubernetes.client.models.V1LabelSelector) V1ResourceRequirements(io.kubernetes.client.models.V1ResourceRequirements) List(java.util.List) Resource(com.twitter.heron.spi.packing.Resource) V1beta1StatefulSetSpec(io.kubernetes.client.models.V1beta1StatefulSetSpec) V1Toleration(io.kubernetes.client.models.V1Toleration) V1DeleteOptions(io.kubernetes.client.models.V1DeleteOptions) Collections(java.util.Collections) V1PodSpec(io.kubernetes.client.models.V1PodSpec) V1VolumeMount(io.kubernetes.client.models.V1VolumeMount) TopologyUtils(com.twitter.heron.api.utils.TopologyUtils) Config(com.twitter.heron.spi.common.Config) ExecutorPort(com.twitter.heron.scheduler.utils.SchedulerUtils.ExecutorPort) HashMap(java.util.HashMap) Map(java.util.Map)

Example 63 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class AppsV1beta1Controller method createStatefulSet.

private V1beta1StatefulSet createStatefulSet(Resource containerResource, int numberOfInstances) {
    final String topologyName = getTopologyName();
    final Config runtimeConfiguration = getRuntimeConfiguration();
    final V1beta1StatefulSet statefulSet = new V1beta1StatefulSet();
    // setup stateful set metadata
    final V1ObjectMeta objectMeta = new V1ObjectMeta();
    objectMeta.name(topologyName);
    statefulSet.metadata(objectMeta);
    // create the stateful set spec
    final V1beta1StatefulSetSpec statefulSetSpec = new V1beta1StatefulSetSpec();
    statefulSetSpec.serviceName(topologyName);
    statefulSetSpec.setReplicas(Runtime.numContainers(runtimeConfiguration).intValue());
    // Parallel pod management tells the StatefulSet controller to launch or terminate
    // all Pods in parallel, and not to wait for Pods to become Running and Ready or completely
    // terminated prior to launching or terminating another Pod.
    statefulSetSpec.setPodManagementPolicy("Parallel");
    // add selector match labels "app=heron" and "topology=topology-name"
    // so the we know which pods to manage
    final V1LabelSelector selector = new V1LabelSelector();
    selector.matchLabels(getMatchLabels(topologyName));
    statefulSetSpec.selector(selector);
    // create a pod template
    final V1PodTemplateSpec podTemplateSpec = new V1PodTemplateSpec();
    // set up pod meta
    final V1ObjectMeta templateMetaData = new V1ObjectMeta().labels(getLabels(topologyName));
    templateMetaData.annotations(getPrometheusAnnotations());
    podTemplateSpec.setMetadata(templateMetaData);
    final List<String> command = getExecutorCommand("$" + ENV_SHARD_ID);
    podTemplateSpec.spec(getPodSpec(command, containerResource, numberOfInstances));
    statefulSetSpec.setTemplate(podTemplateSpec);
    statefulSet.spec(statefulSetSpec);
    return statefulSet;
}
Also used : Config(com.twitter.heron.spi.common.Config) V1ObjectMeta(io.kubernetes.client.models.V1ObjectMeta) V1PodTemplateSpec(io.kubernetes.client.models.V1PodTemplateSpec) V1LabelSelector(io.kubernetes.client.models.V1LabelSelector) V1beta1StatefulSet(io.kubernetes.client.models.V1beta1StatefulSet) V1beta1StatefulSetSpec(io.kubernetes.client.models.V1beta1StatefulSetSpec)

Example 64 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class AppsV1beta1Controller method addVolumesIfPresent.

private void addVolumesIfPresent(V1PodSpec spec) {
    final Config config = getConfiguration();
    if (KubernetesContext.hasVolume(config)) {
        final V1Volume volume = Volumes.get().create(config);
        if (volume != null) {
            LOG.fine("Adding volume: " + volume.toString());
            spec.volumes(Collections.singletonList(volume));
        }
    }
}
Also used : V1Volume(io.kubernetes.client.models.V1Volume) Config(com.twitter.heron.spi.common.Config)

Example 65 with Config

use of com.twitter.heron.spi.common.Config in project incubator-heron by apache.

the class LauncherUtilsTest method constructsRuntimeWithPackingProperly.

@Test
public void constructsRuntimeWithPackingProperly() {
    Config runtime = Config.newBuilder().put("key-23", "value-34").build();
    Assert.assertNull(Runtime.componentRamMap(runtime));
    Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
    containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
    containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
    PackingPlan mockPacking = Mockito.mock(PackingPlan.class);
    Mockito.when(mockPacking.getComponentRamDistribution()).thenReturn("ramMap");
    Mockito.when(mockPacking.getContainers()).thenReturn(containers);
    Config newRuntime = LauncherUtils.getInstance().createConfigWithPackingDetails(runtime, mockPacking);
    Assert.assertNull(Runtime.componentRamMap(runtime));
    Assert.assertEquals("ramMap", Runtime.componentRamMap(newRuntime));
    Assert.assertEquals(3, Runtime.numContainers(newRuntime).longValue());
    Assert.assertEquals("value-34", newRuntime.getStringValue("key-23"));
}
Also used : Config(com.twitter.heron.spi.common.Config) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) HashSet(java.util.HashSet) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Config (com.twitter.heron.spi.common.Config)211 Test (org.junit.Test)125 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)60 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)53 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)43 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)35 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)19 IStateManager (com.twitter.heron.spi.statemgr.IStateManager)18 IScheduler (com.twitter.heron.spi.scheduler.IScheduler)17 HashMap (java.util.HashMap)16 Before (org.junit.Before)16 ILauncher (com.twitter.heron.spi.scheduler.ILauncher)14 IOException (java.io.IOException)13 Resource (com.twitter.heron.spi.packing.Resource)12 URI (java.net.URI)12 HashSet (java.util.HashSet)11 CommandLine (org.apache.commons.cli.CommandLine)10 ByteAmount (com.twitter.heron.common.basics.ByteAmount)9 ISchedulerClient (com.twitter.heron.scheduler.client.ISchedulerClient)9 File (java.io.File)9