Search in sources :

Example 46 with Resource

use of org.apache.heron.spi.packing.Resource in project heron by twitter.

the class NomadSchedulerTest method testGetTaskGroup.

@Test
public void testGetTaskGroup() {
    Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
    containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
    Resource resource = new Resource(CPU_RESOURCE, MEMORY_RESOURCE, DISK_RESOURCE);
    PackingPlan.ContainerPlan containerPlan = new PackingPlan.ContainerPlan(CONTAINER_INDEX, new HashSet<>(), Mockito.mock(Resource.class));
    scheduler.initialize(this.mockConfig, this.mockRuntime);
    Mockito.doReturn(new Task()).when(scheduler).getTask(Mockito.anyString(), Mockito.anyInt(), Mockito.any());
    TaskGroup taskGroup = scheduler.getTaskGroup(GROUP_NAME, CONTAINER_INDEX, resource);
    LOG.info("taskGroup: " + taskGroup);
    Assert.assertEquals(GROUP_NAME, taskGroup.getName());
    Assert.assertNotNull(taskGroup.getCount());
    Assert.assertNotNull(taskGroup.getTasks());
}
Also used : Task(com.hashicorp.nomad.apimodel.Task) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Resource(org.apache.heron.spi.packing.Resource) TaskGroup(com.hashicorp.nomad.apimodel.TaskGroup) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 47 with Resource

use of org.apache.heron.spi.packing.Resource in project heron by twitter.

the class NomadSchedulerTest method testServiceCheck.

@SuppressWarnings("unchecked")
@Test
public void testServiceCheck() {
    this.mockConfig = this.mockConfig.newBuilder().putAll(this.mockConfig).put(NomadContext.HERON_NOMAD_METRICS_SERVICE_ADDITIONAL_TAGS, "foo,bar").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_CHECK_TIMEOUT_SEC, "2").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_CHECK_INTERVAL_SEC, "10").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_REGISTER, true).build();
    this.mockRuntime = this.mockRuntime.newBuilder().putAll(this.mockConfig).put(NomadContext.HERON_NOMAD_METRICS_SERVICE_ADDITIONAL_TAGS, "foo,bar").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_CHECK_TIMEOUT_SEC, "2").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_CHECK_INTERVAL_SEC, "10").put(NomadContext.HERON_NOMAD_METRICS_SERVICE_REGISTER, true).build();
    Set<PackingPlan.ContainerPlan> containers = new HashSet<>();
    containers.add(Mockito.mock(PackingPlan.ContainerPlan.class));
    PowerMockito.mockStatic(SchedulerUtils.class);
    Resource resource = new Resource(CPU_RESOURCE, MEMORY_RESOURCE, DISK_RESOURCE);
    PowerMockito.when(SchedulerUtils.executorCommandArgs(Mockito.any(), Mockito.any(), Mockito.anyMap(), Mockito.anyString())).thenReturn(EXECUTOR_CMD_ARGS);
    PowerMockito.mockStatic(NomadScheduler.class);
    PowerMockito.when(NomadScheduler.getFetchCommand(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(TOPOLOGY_DOWNLOAD_CMD);
    PowerMockito.when(NomadScheduler.getHeronNomadScript(this.mockConfig)).thenReturn(HERON_NOMAD_SCRIPT);
    PowerMockito.when(NomadScheduler.longToInt(MEMORY_RESOURCE.asMegabytes())).thenReturn((int) MEMORY_RESOURCE.asMegabytes());
    PowerMockito.when(NomadScheduler.longToInt(DISK_RESOURCE.asMegabytes())).thenReturn((int) DISK_RESOURCE.asMegabytes());
    PowerMockito.when(NomadScheduler.getPrometheusMetricsFile(Mockito.any())).thenReturn(PORT_FILE);
    PowerMockito.when(NomadScheduler.getMetricsServiceName(Mockito.any(), Mockito.anyInt())).thenReturn(String.format("metrics-heron-%s-%s", TOPOLOGY_NAME, CONTAINER_INDEX));
    scheduler.initialize(this.mockConfig, this.mockRuntime);
    Task task = scheduler.getTask(TASK_NAME, CONTAINER_INDEX, resource);
    LOG.info("task: " + task);
    Assert.assertEquals(task.getServices().size(), 1);
    Assert.assertEquals(task.getServices().get(0).getName(), String.format("metrics-heron-%s-%s", TOPOLOGY_NAME, CONTAINER_INDEX));
    String[] tags = { String.format("%s-%s", TOPOLOGY_NAME, CONTAINER_INDEX), "foo", "bar" };
    Assert.assertEquals(task.getServices().get(0).getTags(), Arrays.asList(tags));
    Assert.assertEquals(task.getServices().get(0).getPortLabel(), NomadConstants.METRICS_PORT);
    Assert.assertEquals(task.getServices().get(0).getChecks().size(), 1);
    Assert.assertEquals(task.getServices().get(0).getChecks().get(0).getPortLabel(), NomadConstants.METRICS_PORT);
    Assert.assertEquals(task.getServices().get(0).getChecks().get(0).getType(), NomadConstants.NOMAD_SERVICE_CHECK_TYPE);
    TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS);
    Assert.assertEquals(task.getServices().get(0).getChecks().get(0).getInterval(), TimeUnit.NANOSECONDS.convert(10, TimeUnit.SECONDS));
    Assert.assertEquals(task.getServices().get(0).getChecks().get(0).getTimeout(), TimeUnit.NANOSECONDS.convert(2, TimeUnit.SECONDS));
    // if service registration is turned off
    this.mockConfig = this.mockConfig.newBuilder().putAll(this.mockConfig).put(NomadContext.HERON_NOMAD_METRICS_SERVICE_REGISTER, false).build();
    this.mockRuntime = this.mockRuntime.newBuilder().putAll(this.mockConfig).put(NomadContext.HERON_NOMAD_METRICS_SERVICE_REGISTER, false).build();
    scheduler.initialize(this.mockConfig, this.mockRuntime);
    task = scheduler.getTask(TASK_NAME, CONTAINER_INDEX, resource);
    LOG.info("task: " + task);
    Assert.assertTrue(task.getServices() == null);
}
Also used : Task(com.hashicorp.nomad.apimodel.Task) Resource(org.apache.heron.spi.packing.Resource) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Resource (org.apache.heron.spi.packing.Resource)47 PackingPlan (org.apache.heron.spi.packing.PackingPlan)25 Test (org.junit.Test)22 HashSet (java.util.HashSet)18 ByteAmount (org.apache.heron.common.basics.ByteAmount)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 HashMap (java.util.HashMap)6 Config (org.apache.heron.spi.common.Config)6 Task (com.hashicorp.nomad.apimodel.Task)4 ArrayList (java.util.ArrayList)4 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)4 InstanceId (org.apache.heron.spi.packing.InstanceId)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 Job (com.hashicorp.nomad.apimodel.Job)2 TaskGroup (com.hashicorp.nomad.apimodel.TaskGroup)2 Quantity (io.kubernetes.client.custom.Quantity)2 V1Container (io.kubernetes.client.openapi.models.V1Container)2 V1ContainerBuilder (io.kubernetes.client.openapi.models.V1ContainerBuilder)2 List (java.util.List)2