@Test public void testLongHostname() { String clusterId = "00000123"; String domain = "dev.company.com"; String labelSuffix = "123-1002"; StringBuilder longName = new StringBuilder(); for (int i = 0; i < 63 - labelSuffix.length(); i++) { longName.append("a"); } String bigName = longName.toString(); Assert.assertEquals(bigName + labelSuffix + "." + domain, NodeService.createHostname(bigName + "bcde", clusterId, 1002, domain)); }
/** * Fail an action on a node with optional logs on what went wrong. Updates the node in the persistent store. * * @param node Node the action failed on. * @param stdout Stdout of failed action. * @param stderr Stderr of failed action. * @throws IOException */ public void failAction(Node node, String stdout, String stderr) throws IOException { Node.Action action = validateAndGetAction(node); action.setStatus(Node.Status.FAILED); action.setStatusTime(System.currentTimeMillis()); action.setStdout(truncateLog(stdout, maxLogLength)); action.setStderr(truncateLog(stderr, maxLogLength)); clusterStore.writeNode(node); }
@Test public void testTruncateLog1() throws Exception { conf.setInt(Constants.MAX_PER_NODE_NUM_ACTIONS, 3); conf.setInt(Constants.MAX_PER_NODE_LOG_LENGTH, 8); NodeService nodeService = injector.getInstance(NodeService.class); Node node = new Node("1", "1", ImmutableSet.<Service>of(), TestHelper.EMPTY_NODE_PROPERTIES); nodeService.startAction(node, "taskId", "service", "action"); nodeService.failAction(node, "1234567890", "0987654321"); Assert.assertEquals(1, node.getActions().size()); Assert.assertEquals("[snipped]34567890", node.getActions().get(0).getStdout()); Assert.assertEquals("[snipped]87654321", node.getActions().get(0).getStderr()); }
@Test public void testNodeMaxActions() throws Exception { conf.setInt(Constants.MAX_PER_NODE_NUM_ACTIONS, 3); conf.setInt(Constants.MAX_PER_NODE_LOG_LENGTH, 100); NodeService nodeService = injector.getInstance(NodeService.class); Node node = new Node("1", "1", ImmutableSet.<Service>of(), TestHelper.EMPTY_NODE_PROPERTIES); Assert.assertTrue(node.getActions().isEmpty()); for (int i = 0; i < 3; ++i) { Assert.assertEquals(i, node.getActions().size()); nodeService.startAction(node, "taskId", "service" + i, "action" + i); nodeService.completeAction(node); Assert.assertEquals(i + 1, node.getActions().size()); } nodeService.startAction(node, "taskId", "service3", "action3"); nodeService.completeAction(node); Assert.assertEquals(3, node.getActions().size()); Assert.assertEquals(Lists.newArrayList("service1", "service2", "service3"), Lists.newArrayList(Iterables.transform(node.getActions(), new Function<Node.Action, String>() { @Override public String apply(Node.Action input) { return input.getService(); } }))); }
node.getProperties().setHostname(hostname); nodeService.completeAction(node); } else { nodeService.failAction(node, finish.getStdout(), finish.getStderr());
void startNodeAction(ClusterTask clusterTask) throws IOException { // Update node properties if task is associated with a nodeId. // There are cases when we don't associate a nodeId with a task so that the node properties don't get overridden // by the task output. // Eg. deleting a box during a rollback operation since we reuse nodeIds. if (clusterTask.getNodeId() != null) { Node node = clusterStore.getNode(clusterTask.getNodeId()); if (node == null) { LOG.error("Cannot find node {} for task {} to update the properties", clusterTask.getNodeId(), clusterTask.getTaskId()); } else { nodeService.startAction(node, clusterTask.getTaskId(), clusterTask.getService(), clusterTask.getTaskName().name()); } } }
@Test public void testTruncate() throws Exception { String shortStr = "this is a short string"; Assert.assertEquals(shortStr, NodeService.truncateLog(shortStr, shortStr.length())); Assert.assertEquals("[snipped]short string", NodeService.truncateLog(shortStr, 12)); String newLineString = "this \nis a string \nwith newlines"; Assert.assertEquals(newLineString, NodeService.truncateLog(newLineString, newLineString.length() + 10)); Assert.assertEquals("[snipped]ing \nwith newlines", NodeService.truncateLog(newLineString, 18)); Assert.assertEquals("[snipped]is a string \nwith newlines", NodeService.truncateLog(newLineString, 26)); } }
nodeService.failAction(node, "", statusMessage);
/** * Complete an action on a node. Updates the node in the persistent store. * * @param node Node the completed action took place on. * @throws IOException */ public void completeAction(Node node) throws IOException { Node.Action action = validateAndGetAction(node); action.setStatus(Node.Status.COMPLETE); action.setStatusTime(System.currentTimeMillis()); clusterStore.writeNode(node); }
@Test public void testTruncateLog2() throws Exception { conf.setInt(Constants.MAX_PER_NODE_NUM_ACTIONS, 3); conf.setInt(Constants.MAX_PER_NODE_LOG_LENGTH, 10); NodeService nodeService = injector.getInstance(NodeService.class); Node node = new Node("1", "1", ImmutableSet.<Service>of(), TestHelper.EMPTY_NODE_PROPERTIES); nodeService.startAction(node, "taskId", "service", "action"); nodeService.failAction(node, "1234567890", "0987654321"); Assert.assertEquals(1, node.getActions().size()); Assert.assertEquals("1234567890", node.getActions().get(0).getStdout()); Assert.assertEquals("0987654321", node.getActions().get(0).getStderr()); }
nodeService.startAction(node1, task1.getTaskId(), "service", "action"); Assert.assertEquals(Node.Status.IN_PROGRESS, node1.getActions().get(0).getStatus()); nodeService.startAction(node2, task2.getTaskId(), "service", "action"); Assert.assertEquals(Node.Status.IN_PROGRESS, node2.getActions().get(0).getStatus()); nodeService.startAction(node3, task3.getTaskId(), "service", "action"); Assert.assertEquals(Node.Status.IN_PROGRESS, node3.getActions().get(0).getStatus()); nodeService.startAction(node4, task4.getTaskId(), "service", "action"); Assert.assertEquals(Node.Status.IN_PROGRESS, node4.getActions().get(0).getStatus());
@Test public void testCreateHostname() { String clusterId = "00000001"; Assert.assertEquals("i-am-a-cluster1-1002.local", NodeService.createHostname("123i.am-a_clusTer", clusterId, 1002, null)); }
String hostname = NodeService.createHostname(clusterName, clusterId, nodeNum, dnsSuffix); String flavor = hardwareTypeMap.get(hardwaretype);