Search in sources :

Example 26 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project docker-client by spotify.

the class DefaultDockerClient method copyContainer.

@Override
@Deprecated
public InputStream copyContainer(String containerId, String path) throws DockerException, InterruptedException {
    final String apiVersion = version().apiVersion();
    final int versionComparison = compareVersion(apiVersion, "1.24");
    // Version above 1.24
    if (versionComparison >= 0) {
        throw new UnsupportedApiVersionException(apiVersion);
    }
    final WebTarget resource = resource().path("containers").path(containerId).path("copy");
    // Internal JSON object; not worth it to create class for this
    final JsonNodeFactory nf = JsonNodeFactory.instance;
    final JsonNode params = nf.objectNode().set("Resource", nf.textNode(path));
    try {
        return request(POST, InputStream.class, resource, resource.request(APPLICATION_OCTET_STREAM_TYPE), Entity.json(params));
    } catch (DockerRequestException e) {
        switch(e.status()) {
            case 404:
                throw new ContainerNotFoundException(containerId, e);
            default:
                throw e;
        }
    }
}
Also used : UnsupportedApiVersionException(com.spotify.docker.client.exceptions.UnsupportedApiVersionException) DockerRequestException(com.spotify.docker.client.exceptions.DockerRequestException) JsonNode(com.fasterxml.jackson.databind.JsonNode) WebTarget(javax.ws.rs.client.WebTarget) ContainerNotFoundException(com.spotify.docker.client.exceptions.ContainerNotFoundException) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 27 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project snow-owl by b2ihealthcare.

the class CisClient method logout.

public void logout() {
    final String tokenBeforeLogout = token.getAndSet(BAD_TOKEN);
    // If this is already set to BAD_TOKEN, we are no longer logged in
    if (BAD_TOKEN.equals(tokenBeforeLogout)) {
        return;
    }
    LogUtils.logUserAccess(LOGGER, username, "Logging out from Component Identifier service.");
    HttpPost request = null;
    try {
        final JsonNodeFactory factory = JsonNodeFactory.instance;
        final JsonNode node = factory.objectNode().set("token", factory.textNode(tokenBeforeLogout));
        request = httpPost("logout", node);
        client.execute(request);
    } catch (IOException e) {
        throw new SnowowlRuntimeException("Exception while logging out.", e);
    } finally {
        if (null != request)
            release(request);
    }
}
Also used : HttpPost(org.apache.http.client.methods.HttpPost) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) SnowowlRuntimeException(com.b2international.snowowl.core.api.SnowowlRuntimeException) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 28 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project infoarchive-sip-sdk by Enterprise-Content-Management.

the class InfoArchiveRestClient method getValidJsonRequestForExport.

private String getValidJsonRequestForExport(String exportConfigurationUri, Collection<SearchResult> searchResults) {
    JsonNodeFactory jsonNodeFactory = new ObjectMapper().getNodeFactory();
    ObjectNode root = jsonNodeFactory.objectNode();
    root.set("exportConfiguration", jsonNodeFactory.textNode(exportConfigurationUri));
    root.set("includedRows", getIncludedRows(searchResults, jsonNodeFactory));
    return root.toString();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 29 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project rskj by rsksmart.

the class NetworkStateExporter method exportStatus.

public boolean exportStatus(String outputFile) {
    Repository frozenRepository = this.repository.getSnapshotTo(this.repository.getRoot());
    File dumpFile = new File(outputFile);
    try (FileWriter fw = new FileWriter(dumpFile.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw)) {
        JsonNodeFactory jsonFactory = new JsonNodeFactory(false);
        ObjectNode mainNode = jsonFactory.objectNode();
        for (RskAddress addr : frozenRepository.getAccountsKeys()) {
            if (!addr.equals(RskAddress.nullAddress())) {
                mainNode.set(addr.toString(), createAccountNode(mainNode, addr, frozenRepository));
            }
        }
        ObjectMapper mapper = new ObjectMapper();
        ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
        bw.write(writer.writeValueAsString(mainNode));
        return true;
    } catch (IOException e) {
        logger.error(e.getMessage(), e);
        panicProcessor.panic("dumpstate", e.getMessage());
        return false;
    }
}
Also used : Repository(org.ethereum.core.Repository) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) FileWriter(java.io.FileWriter) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IOException(java.io.IOException) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BufferedWriter(java.io.BufferedWriter) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory)

Example 30 with JsonNodeFactory

use of com.fasterxml.jackson.databind.node.JsonNodeFactory in project cloudbreak by hortonworks.

the class BlueprintValidatorTest method testKnoxWithKerberosAndEachGwHasKnox.

@Test
public void testKnoxWithKerberosAndEachGwHasKnox() throws IOException {
    // GIVEN
    Blueprint blueprint = createBlueprint();
    Set<InstanceGroup> instanceGroups = new HashSet<>();
    instanceGroups.add(createInstanceGroup("gateway1", 1, InstanceGroupType.GATEWAY));
    instanceGroups.add(createInstanceGroup("gateway2", 1, InstanceGroupType.GATEWAY));
    instanceGroups.add(createInstanceGroup("master", 1, InstanceGroupType.CORE));
    Set<HostGroup> hostGroups = createHostGroups(instanceGroups);
    JsonNodeFactory jsonNodeFactory = JsonNodeFactory.instance;
    ObjectNode rootNode = jsonNodeFactory.objectNode();
    ArrayNode hostGroupsNode = rootNode.putArray("host_groups");
    addHostGroup(hostGroupsNode, "gateway1", SL_MIN0_MAX3, KNOX);
    addHostGroup(hostGroupsNode, "gateway2", KNOX, MA_MIN1_MAX3);
    addHostGroup(hostGroupsNode, "master", SL_MIN0_MAX3, MA_MIN1_MAX5);
    BDDMockito.given(objectMapper.readTree(BLUEPRINT_STRING)).willReturn(rootNode);
    Cluster cluster = new Cluster();
    cluster.setSecure(true);
    Gateway gateway = new Gateway();
    gateway.setEnableGateway(true);
    cluster.setGateway(gateway);
    // WHEN
    underTest.validateBlueprintForStack(cluster, blueprint, hostGroups, instanceGroups);
// THEN no exception thrown
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Blueprint(com.sequenceiq.cloudbreak.domain.Blueprint) Gateway(com.sequenceiq.cloudbreak.domain.Gateway) HostGroup(com.sequenceiq.cloudbreak.domain.HostGroup) Cluster(com.sequenceiq.cloudbreak.domain.Cluster) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) InstanceGroup(com.sequenceiq.cloudbreak.domain.InstanceGroup) HashSet(java.util.HashSet) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) Test(org.junit.Test)

Aggregations

JsonNodeFactory (com.fasterxml.jackson.databind.node.JsonNodeFactory)35 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)28 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)17 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 Blueprint (com.sequenceiq.cloudbreak.domain.Blueprint)4 Cluster (com.sequenceiq.cloudbreak.domain.Cluster)4 Gateway (com.sequenceiq.cloudbreak.domain.Gateway)4 HostGroup (com.sequenceiq.cloudbreak.domain.HostGroup)4 InstanceGroup (com.sequenceiq.cloudbreak.domain.InstanceGroup)4 HashSet (java.util.HashSet)4 JsonNode (com.fasterxml.jackson.databind.JsonNode)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 EventEntity (io.gravitee.management.model.EventEntity)2 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 PersistenceException (javax.persistence.PersistenceException)2