@Override public String uri() { return uri.toString(); }
URL url; try { url = UriBuilder.fromUri(uri.toURI()).path(REST.WebPath.KB).build().toURL(); } catch (MalformedURLException e) { throw CommonUtil.unreachableStatement(
URL url; try { url = UriBuilder.fromUri(uri.toURI()).path(REST.WebPath.KB).build().toURL(); } catch (MalformedURLException e) { throw CommonUtil.unreachableStatement(
public static ManagedChannel getEncryptedChannel(SimpleURI uri, Path trustedCertPath){ File trustedCert = new File(trustedCertPath.toString()); try { return NettyChannelBuilder .forAddress(uri.getHost(), uri.getPort()) .maxInboundMessageSize(GRPC_MAX_MESSAGE_SIZE_IN_BYTES) .sslContext(GrpcSslContexts.forClient().trustManager(trustedCert).build()) .build(); } catch (SSLException e) { throw new RuntimeException(e); } }
public SimpleURI getUri() { return command.hasOption("u") ? new SimpleURI(command.getOptionValue("u")) : DEFAULT_URI; }
@Override public List<QueryResponse> graqlExecute(List<Query<?>> queryList, Keyspace keyspace) throws GraknClientException { LOG.debug("Sending query list size {} to keyspace {}", queryList.size(), keyspace); String body = queryList.stream().map(Object::toString).reduce("; ", String::concat).substring(2); URI fullURI = UriBuilder.fromUri(uri.toURI()) .path(REST.resolveTemplate(REST.WebPath.KEYSPACE_GRAQL, keyspace.getValue())) .queryParam(ALLOW_MULTIPLE_QUERIES, true) .queryParam(EXECUTE_WITH_INFERENCE, false) //Making inference true could lead to non-deterministic loading of data .queryParam(LOADING_DATA, true) //Skip serialising responses for the sake of efficiency .queryParam(TX_TYPE, GraknTxType.BATCH) .build(); ClientResponse response = client.resource(fullURI) .accept(APPLICATION_JSON) .post(ClientResponse.class, body); try { Response.StatusType status = response.getStatusInfo(); String entity = response.getEntity(String.class); if (!status.getFamily().equals(Family.SUCCESSFUL)) { String queries = queryList.stream().map(Object::toString).collect(Collectors.joining("\n")); String error = Json.read(entity).at("exception").asString(); throw new GraknClientException("Failed graqlExecute. Error status: " + status.getStatusCode() + ", error info: " + error + "\nqueries: " + queries, response.getStatusInfo()); } LOG.debug("Received {}", status.getStatusCode()); return queryList.stream().map(q -> QueryResponse.INSTANCE).collect(Collectors.toList()); } finally { response.close(); } }
public SimpleURI uri() { return new SimpleURI(getProperty(GraknConfigKey.SERVER_HOST_NAME), getProperty(GraknConfigKey.SERVER_PORT)); }
@Override public List<QueryResponse> graqlExecute(List<Query<?>> queryList, Keyspace keyspace) throws GraknClientException { LOG.debug("Sending query list size {} to keyspace {}", queryList.size(), keyspace); String body = queryList.stream().map(Object::toString).reduce("; ", String::concat).substring(2); URI fullURI = UriBuilder.fromUri(uri.toURI()) .path(REST.resolveTemplate(REST.WebPath.KEYSPACE_GRAQL, keyspace.getValue())) .queryParam(ALLOW_MULTIPLE_QUERIES, true) .queryParam(EXECUTE_WITH_INFERENCE, false) //Making inference true could lead to non-deterministic loading of data .queryParam(LOADING_DATA, true) //Skip serialising responses for the sake of efficiency .queryParam(TX_TYPE, GraknTxType.BATCH) .build(); ClientResponse response = client.resource(fullURI) .accept(APPLICATION_JSON) .post(ClientResponse.class, body); try { Response.StatusType status = response.getStatusInfo(); String entity = response.getEntity(String.class); if (!status.getFamily().equals(Family.SUCCESSFUL)) { String queries = queryList.stream().map(Object::toString).collect(Collectors.joining("\n")); String error = Json.read(entity).at("exception").asString(); throw new GraknClientException("Failed graqlExecute. Error status: " + status.getStatusCode() + ", error info: " + error + "\nqueries: " + queries, response.getStatusInfo()); } LOG.debug("Received {}", status.getStatusCode()); return queryList.stream().map(q -> QueryResponse.INSTANCE).collect(Collectors.toList()); } finally { response.close(); } }
private static ManagedChannel getChannel(CommandLine cmd, GraknConfig config) { // Define contact point with Server SimpleURI contactPoint; if (cmd.hasOption('c')) { contactPoint = new SimpleURI(cmd.getOptionValue('c')); } else { contactPoint = new SimpleURI(config.getProperty(GraknConfigKey.SERVER_HOST_NAME) + ":" + config.getProperty(GraknConfigKey.GRPC_PORT)); } // Determine whether the connection needs to be encrypted boolean encryptionEnabled = Boolean.valueOf(cmd.getOptionValue(TLS)); // Load path to trust manager for self-signed certificates (this is optional) String trustManager = cmd.getOptionValue(TRUST_MANAGER); if (encryptionEnabled) { if (trustManager == null) { return GrpcChannelFactory.getEncryptedChannel(contactPoint); } else { return GrpcChannelFactory.getEncryptedChannel(contactPoint, Paths.get(trustManager)); } } else { return GrpcChannelFactory.getChannel(contactPoint); } }
@Override public Optional<Keyspace> keyspace(String keyspace) throws GraknClientException { URI fullURI = UriBuilder.fromUri(uri.toURI()) .path(REST.resolveTemplate(REST.WebPath.KB_KEYSPACE, keyspace)) .build(); ClientResponse response = client.resource(fullURI) .accept(APPLICATION_JSON) .get(ClientResponse.class); Response.StatusType status = response.getStatusInfo(); LOG.debug("Received {}", status.getStatusCode()); if (status.getStatusCode() == Status.NOT_FOUND.getStatusCode()) { return Optional.empty(); } String entity = response.getEntity(String.class); if (!status.getFamily().equals(Family.SUCCESSFUL)) { throw new GraknClientException("Failed keyspace. Error status: " + status.getStatusCode() + ", error info: " + entity, response.getStatusInfo()); } response.close(); return Optional.of(Keyspace.of(keyspace)); } }
public Grakn(SimpleURI uri) { channel = ManagedChannelBuilder.forAddress(uri.getHost(), uri.getPort()).usePlaintext(true).build(); keyspaceBlockingStub = KeyspaceServiceGrpc.newBlockingStub(channel); keyspace = new Keyspace(); openRequestBuilder = (type, keyspace) -> RequestBuilder.Transaction.open(keyspace, type); }
@Override public Optional<Keyspace> keyspace(String keyspace) throws GraknClientException { URI fullURI = UriBuilder.fromUri(uri.toURI()) .path(REST.resolveTemplate(REST.WebPath.KB_KEYSPACE, keyspace)) .build(); ClientResponse response = client.resource(fullURI) .accept(APPLICATION_JSON) .get(ClientResponse.class); Response.StatusType status = response.getStatusInfo(); LOG.debug("Received {}", status.getStatusCode()); if (status.getStatusCode() == Status.NOT_FOUND.getStatusCode()) { return Optional.empty(); } String entity = response.getEntity(String.class); if (!status.getFamily().equals(Family.SUCCESSFUL)) { throw new GraknClientException("Failed keyspace. Error status: " + status.getStatusCode() + ", error info: " + entity, response.getStatusInfo()); } response.close(); return Optional.of(Keyspace.of(keyspace)); } }