Search in sources :

Example 61 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project flink by apache.

the class SubtasksTimesHandlerTest method compareSubtaskTimes.

private static void compareSubtaskTimes(AccessExecutionJobVertex originalTask, AccessExecution originalAttempt, String json) throws IOException {
    JsonNode result = ArchivedJobGenerationUtils.mapper.readTree(json);
    Assert.assertEquals(originalTask.getJobVertexId().toString(), result.get("id").asText());
    Assert.assertEquals(originalTask.getName(), result.get("name").asText());
    Assert.assertTrue(result.get("now").asLong() > 0L);
    ArrayNode subtasks = (ArrayNode) result.get("subtasks");
    JsonNode subtask = subtasks.get(0);
    Assert.assertEquals(0, subtask.get("subtask").asInt());
    Assert.assertEquals(originalAttempt.getAssignedResourceLocation().getHostname(), subtask.get("host").asText());
    Assert.assertEquals(originalAttempt.getStateTimestamp(originalAttempt.getState()) - originalAttempt.getStateTimestamp(ExecutionState.SCHEDULED), subtask.get("duration").asLong());
    JsonNode timestamps = subtask.get("timestamps");
    Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.CREATED), timestamps.get(ExecutionState.CREATED.name()).asLong());
    Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.SCHEDULED), timestamps.get(ExecutionState.SCHEDULED.name()).asLong());
    Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.DEPLOYING), timestamps.get(ExecutionState.DEPLOYING.name()).asLong());
    Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.RUNNING), timestamps.get(ExecutionState.RUNNING.name()).asLong());
    Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.FINISHED), timestamps.get(ExecutionState.FINISHED.name()).asLong());
    Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.CANCELING), timestamps.get(ExecutionState.CANCELING.name()).asLong());
    Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.CANCELED), timestamps.get(ExecutionState.CANCELED.name()).asLong());
    Assert.assertEquals(originalAttempt.getStateTimestamp(ExecutionState.FAILED), timestamps.get(ExecutionState.FAILED.name()).asLong());
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 62 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project flink by apache.

the class WebFrontendITCase method getTaskmanagers.

@Test
public void getTaskmanagers() {
    try {
        String json = getFromHTTP("http://localhost:" + port + "/taskmanagers/");
        ObjectMapper mapper = new ObjectMapper();
        JsonNode parsed = mapper.readTree(json);
        ArrayNode taskManagers = (ArrayNode) parsed.get("taskmanagers");
        assertNotNull(taskManagers);
        assertEquals(cluster.numTaskManagers(), taskManagers.size());
        JsonNode taskManager = taskManagers.get(0);
        assertNotNull(taskManager);
        assertEquals(NUM_SLOTS, taskManager.get("slotsNumber").asInt());
        assertTrue(taskManager.get("freeSlots").asInt() <= NUM_SLOTS);
    } catch (Exception e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 63 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project swagger-parser by swagger-api.

the class SwaggerJsonValidator method fillMessages.

private static boolean fillMessages(final ProcessingReport report, final MessageBuilder builder) {
    final Severity severity = LEVEL_MAP.get(report.getLogLevel());
    final ArrayNode node = JacksonUtils.nodeFactory().arrayNode();
    for (final ProcessingMessage processingMessage : report) {
        node.add(processingMessage.asJson());
    }
    final String reportAsString = JacksonUtils.prettyPrint(node);
    final Message message = new Message("", reportAsString, severity);
    builder.append(message);
    return report.isSuccess();
}
Also used : ProcessingMessage(com.github.fge.jsonschema.core.report.ProcessingMessage) Message(io.swagger.report.Message) ProcessingMessage(com.github.fge.jsonschema.core.report.ProcessingMessage) Severity(io.swagger.report.Severity) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 64 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project swagger-parser by swagger-api.

the class SwaggerCompatConverter method propertyFromTypedObject.

public Property propertyFromTypedObject(ExtendedTypedObject obj) {
    String type = obj.getType() == null ? null : obj.getType().toString();
    String format = obj.getFormat() == null ? null : obj.getFormat().toString();
    Property output = null;
    if ("array".equals(type)) {
        ArrayProperty am = new ArrayProperty();
        Items items = obj.getItems();
        if (items == null) {
            LOGGER.error("Error! Missing array type for property!  Assuming `object` -- please fix your spec");
            items = new Items();
            items.setType("object");
        }
        type = items.getType() == null ? null : items.getType().toString();
        format = items.getFormat() == null ? null : items.getFormat().toString();
        Map<PropertyBuilder.PropertyId, Object> args = new HashMap<>();
        if (items.getExtraFields().get("enum") != null && items.getExtraFields().get("enum").isArray()) {
            ArrayNode an = (ArrayNode) items.getExtraFields().get("enum");
            List<String> enumValues = new ArrayList<>();
            for (JsonNode jn : an) {
                enumValues.add(jn.textValue());
            }
            args.put(PropertyBuilder.PropertyId.ENUM, enumValues);
        }
        Property innerType = PropertyBuilder.build(type, format, args);
        if (innerType != null && !(innerType instanceof UntypedProperty)) {
            am.setItems(innerType);
        } else if (items.getRef() != null) {
            am.setItems(new RefProperty(items.getRef()));
        } else {
            am.setItems(new RefProperty(type));
        }
        output = am;
    } else {
        Map<PropertyBuilder.PropertyId, Object> args = new HashMap<PropertyBuilder.PropertyId, Object>();
        if (obj.getEnumValues() != null && obj.getEnumValues().size() > 0) {
            args.put(PropertyBuilder.PropertyId.ENUM, obj.getEnumValues());
        }
        if (obj.getMinimum() != null) {
            args.put(PropertyBuilder.PropertyId.MINIMUM, new BigDecimal(obj.getMinimum()));
        }
        if (obj.getMaximum() != null) {
            args.put(PropertyBuilder.PropertyId.MAXIMUM, new BigDecimal(obj.getMaximum()));
        }
        Property i = PropertyBuilder.build(type, format, args);
        if (i != null && !(i instanceof UntypedProperty)) {
            output = i;
        } else {
            if (obj.getRef() != null) {
                output = new RefProperty(obj.getRef());
            } else if (type != null && !type.equals("void")) {
                output = new RefProperty(type);
            }
        }
    }
    return output;
}
Also used : ArrayProperty(io.swagger.models.properties.ArrayProperty) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) UntypedProperty(io.swagger.models.properties.UntypedProperty) BigDecimal(java.math.BigDecimal) RefProperty(io.swagger.models.properties.RefProperty) Items(io.swagger.models.apideclaration.Items) ExtendedTypedObject(io.swagger.models.apideclaration.ExtendedTypedObject) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) StringProperty(io.swagger.models.properties.StringProperty) ArrayProperty(io.swagger.models.properties.ArrayProperty) Property(io.swagger.models.properties.Property) ModelProperty(io.swagger.models.apideclaration.ModelProperty) RefProperty(io.swagger.models.properties.RefProperty) UntypedProperty(io.swagger.models.properties.UntypedProperty) PropertyBuilder(io.swagger.models.properties.PropertyBuilder)

Example 65 with ArrayNode

use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project swagger-parser by swagger-api.

the class MutableJsonTree method applyMigratorToElements.

/**
 * Apply a migrator to all elements of the array at the current pointer
 *
 * <p>Note that if the migrator fails to apply to at least one element, the
 * original array is left untouched; its elements are replaced if and only
 * if the migrator applies successfully to <strong>all</strong> elements.
 * </p>
 *
 * @param migrator the migrator to apply
 * @throws SwaggerMigrationException current node is not a JSON Array, or
 *                                   migrator failed to apply to at least one array element
 */
public void applyMigratorToElements(final SwaggerMigrator migrator) throws SwaggerMigrationException {
    if (!currentNode.isArray()) {
        throw new SwaggerMigrationException();
    }
    final ArrayNode array = (ArrayNode) currentNode;
    final ArrayNode transformed = array.arrayNode();
    for (final JsonNode element : array) {
        transformed.add(migrator.migrate(element));
    }
    array.removeAll().addAll(transformed);
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Aggregations

ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)979 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)542 JsonNode (com.fasterxml.jackson.databind.JsonNode)402 Test (org.junit.Test)140 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)125 ArrayList (java.util.ArrayList)110 IOException (java.io.IOException)93 Map (java.util.Map)74 HashMap (java.util.HashMap)68 List (java.util.List)50 TextNode (com.fasterxml.jackson.databind.node.TextNode)38 Test (org.testng.annotations.Test)35 DefaultSerializerProvider (com.fasterxml.jackson.databind.ser.DefaultSerializerProvider)30 HashSet (java.util.HashSet)30 JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)25 Deployment (org.activiti.engine.test.Deployment)23 File (java.io.File)22 InputStream (java.io.InputStream)20 Iterator (java.util.Iterator)20 StringEntity (org.apache.http.entity.StringEntity)20