LOG.debug("Submitting task {}", task.getTaskId()); LOG.trace("Task {}", task); SchedulableTask schedulableTask = new SchedulableTask(task, taskConfig); LOG.trace("Schedulable task {}", schedulableTask);
private TakeTaskRequest getRequest() throws IOException { String tenantId = USER1_ACCOUNT.getTenantId(); ClusterTask clusterTask = new ClusterTask( ProvisionerAction.CREATE, TaskId.fromString("1-1-1"), "node_id", "service", ClusterAction.CLUSTER_CREATE, "test", USER1_ACCOUNT); clusterStore.writeClusterTask(clusterTask); ClusterJob clusterJob = new ClusterJob(JobId.fromString("1-1"), ClusterAction.CLUSTER_CREATE); clusterStore.writeClusterJob(clusterJob); TaskConfig taskConfig = new TaskConfig( NodeProperties.builder().build(), Entities.ProviderExample.JOYENT, ImmutableMap.<String, NodeProperties>of(), new TaskServiceAction("svcA", new ServiceAction("shell", ImmutableMap.<String, String>of())), new JsonObject(), new JsonObject() ); SchedulableTask schedulableTask= new SchedulableTask(clusterTask, taskConfig); provisionerQueues.add(tenantId, new Element(clusterTask.getTaskId(), gson.toJson(schedulableTask))); return new TakeTaskRequest("worker1", PROVISIONER_ID, TENANT_ID); }
@Test public void testTakeTask() throws Exception { String tenantId = USER1_ACCOUNT.getTenantId(); ClusterTask clusterTask = new ClusterTask( ProvisionerAction.CREATE, TaskId.fromString("1-1-1"), "node_id", "service", ClusterAction.CLUSTER_CREATE, "test", USER1_ACCOUNT); clusterStore.writeClusterTask(clusterTask); ClusterJob clusterJob = new ClusterJob(JobId.fromString("1-1"), ClusterAction.CLUSTER_CREATE); clusterStore.writeClusterJob(clusterJob); TaskConfig taskConfig = new TaskConfig( NodeProperties.builder().build(), Entities.ProviderExample.JOYENT, ImmutableMap.<String, NodeProperties>of(), new TaskServiceAction("svcA", new ServiceAction("shell", ImmutableMap.<String, String>of())), new JsonObject(), new JsonObject() ); SchedulableTask schedulableTask= new SchedulableTask(clusterTask, taskConfig); provisionerQueues.add(tenantId, new Element(clusterTask.getTaskId(), gson.toJson(schedulableTask))); TakeTaskRequest takeRequest = new TakeTaskRequest("worker1", PROVISIONER_ID, TENANT_ID); HttpResponse response = doPostInternalAPI("/tasks/take", gson.toJson(takeRequest)); assertResponseStatus(response, HttpResponseStatus.OK); JsonObject responseJson = getResponseJson(response); Assert.assertEquals(clusterTask.getTaskId(), responseJson.get("taskId").getAsString()); }
@Test public void testQueuedTaskMissingFromStoreIsRemovedFromQueue() { ClusterCleanup clusterCleanup = new ClusterCleanup(clusterStore, clusterService, nodeService, taskService, jobQueues, provisionerQueues, -10, 1, 1); String queueName = account.getTenantId(); ClusterTask task = new ClusterTask(ProvisionerAction.CREATE, TaskId.fromString("3-1-1"), "node1", "service", ClusterAction.CLUSTER_CREATE, "test", account); task.setStatus(ClusterTask.Status.IN_PROGRESS); Cluster cluster = Entities.ClusterExample.createCluster(); TaskConfig taskConfig = TaskConfig.from(cluster, Entities.ClusterExample.NODE1, Entities.ServiceExample.NAMENODE, cluster.getConfig(), ProvisionerAction.START, null); SchedulableTask schedulableTask = new SchedulableTask(task, taskConfig); // add a task to the queue without storing it.x provisionerQueues.add(queueName, new Element(task.getTaskId(), gson.toJson(schedulableTask))); provisionerQueues.takeIterator("0").next(); clusterCleanup.run(); Assert.assertEquals(0, Iterators.size(provisionerQueues.getBeingConsumed(queueName))); }
new JsonObject() ); SchedulableTask schedulableTask= new SchedulableTask(clusterTask, taskConfig); provisionerQueues.add(tenantId, new Element(clusterTask.getTaskId(), gson.toJson(schedulableTask)));
new JsonObject() ); SchedulableTask schedulableTask= new SchedulableTask(clusterTask, taskConfig); provisionerQueues.add(tenantId, new Element(clusterTask.getTaskId(), gson.toJson(schedulableTask)));