/** * Create a task config from the given input. * * @param cluster Cluster the task is operating on. * @param node Node the task should take place on. * @param service Service the task is operating on. * May be null for tasks that are on the node itself but not on a service. * @param clusterConfig Cluster config with expanded macros. * @param action Action to perform. * @param clusterNodes Collection of all nodes in the cluster. * @return Task config created from the given input. */ public static TaskConfig from(Cluster cluster, Node node, Service service, JsonObject clusterConfig, ProvisionerAction action, Collection<Node> clusterNodes) { Provider provider = cluster.getProvider(); // will be null if the config is for a node action like create, confirm, bootstrap, delete TaskServiceAction taskServiceAction = service == null ? null : new TaskServiceAction(service.getName(), service.getProvisionerActions().get(action)); ImmutableMap.Builder builder = ImmutableMap.<String, NodeProperties>builder(); if (clusterNodes != null) { for (Node clusterNode : clusterNodes) { builder.put(clusterNode.getId(), clusterNode.getProperties()); } } JsonObject provisionerResults = node.getProvisionerResults(); return new TaskConfig(node.getProperties(), provider, builder.build(), taskServiceAction, clusterConfig, provisionerResults); }
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()); }
Entities.ProviderExample.JOYENT, ImmutableMap.<String, NodeProperties>of(node.getId(), node.getProperties()), new TaskServiceAction("svcA", new ServiceAction("shell", ImmutableMap.<String, String>of())), new JsonObject(), new JsonObject()
Entities.ProviderExample.JOYENT, ImmutableMap.<String, NodeProperties>of(node.getId(), node.getProperties()), new TaskServiceAction("svcA", new ServiceAction("shell", ImmutableMap.<String, String>of())), new JsonObject(), new JsonObject()