use of io.zulia.server.index.ZuliaIndexManager in project zuliasearch by zuliaio.
the class IndexController method get.
@Get
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public HttpResponse<?> get(@QueryValue(ZuliaConstants.INDEX) String index, @QueryValue(value = ZuliaConstants.PRETTY, defaultValue = "true") Boolean pretty) {
ZuliaIndexManager indexManager = ZuliaNodeProvider.getZuliaNode().getIndexManager();
try {
StringBuilder responseBuilder = new StringBuilder();
GetIndexSettingsResponse getIndexSettingsResponse = indexManager.getIndexSettings(ZuliaServiceOuterClass.GetIndexSettingsRequest.newBuilder().setIndexName(index).build());
responseBuilder.append("{");
responseBuilder.append("\"indexSettings\": ");
JsonFormat.Printer printer = JsonFormat.printer();
responseBuilder.append(printer.print(getIndexSettingsResponse.getIndexSettings()));
responseBuilder.append("}");
String docString = responseBuilder.toString();
if (pretty) {
docString = JsonWriter.formatJson(docString);
}
return HttpResponse.ok(docString).status(ZuliaConstants.SUCCESS);
} catch (Exception e) {
return HttpResponse.serverError("Failed to get index names: " + e.getMessage()).status(ZuliaConstants.INTERNAL_ERROR);
}
}
use of io.zulia.server.index.ZuliaIndexManager in project zuliasearch by zuliaio.
the class NodesController method get.
@Get
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public HttpResponse<?> get(@QueryValue(value = ZuliaConstants.PRETTY, defaultValue = "true") Boolean pretty, @QueryValue(value = ZuliaConstants.ACTIVE, defaultValue = "false") Boolean active) {
ZuliaIndexManager indexManager = ZuliaNodeProvider.getZuliaNode().getIndexManager();
try {
GetNodesResponse getNodesResponse = indexManager.getNodes(GetNodesRequest.newBuilder().setActiveOnly(active).build());
org.bson.Document mongoDocument = new org.bson.Document();
List<Document> memberObjList = new ArrayList<>();
for (Node node : getNodesResponse.getNodeList()) {
Document memberObj = new Document();
memberObj.put("serverAddress", node.getServerAddress());
memberObj.put("servicePort", node.getServicePort());
memberObj.put("restPort", node.getRestPort());
memberObj.put("heartbeat", node.getHeartbeat());
List<Document> indexMappingList = new ArrayList<>();
for (IndexMapping indexMapping : getNodesResponse.getIndexMappingList()) {
TreeSet<Integer> primaryShards = new TreeSet<>();
TreeSet<Integer> replicaShards = new TreeSet<>();
for (ShardMapping shardMapping : indexMapping.getShardMappingList()) {
if (ZuliaNode.isEqual(shardMapping.getPrimaryNode(), node)) {
primaryShards.add(shardMapping.getShardNumber());
}
for (Node replica : shardMapping.getReplicaNodeList()) {
if (ZuliaNode.isEqual(replica, node)) {
replicaShards.add(shardMapping.getShardNumber());
}
}
}
Document shards = new Document();
shards.put("name", indexMapping.getIndexName());
shards.put("size", indexMapping.getSerializedSize());
shards.put("primary", primaryShards);
shards.put("replica", replicaShards);
indexMappingList.add(shards);
}
memberObj.put("indexMappings", indexMappingList);
memberObjList.add(memberObj);
}
mongoDocument.put("members", memberObjList);
String docString = mongoDocument.toJson();
if (pretty) {
docString = JsonWriter.formatJson(docString);
}
return HttpResponse.ok(docString).status(ZuliaConstants.SUCCESS);
} catch (Exception e) {
return HttpResponse.serverError("Failed to get cluster membership: " + e.getMessage()).status(ZuliaConstants.INTERNAL_ERROR);
}
}
use of io.zulia.server.index.ZuliaIndexManager in project zuliasearch by zuliaio.
the class AssociatedController method post.
@Post(consumes = MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.TEXT_PLAIN)
public Publisher<HttpResponse<?>> post(StreamingFileUpload file, Map<String, Object> metadata) {
ZuliaIndexManager indexManager = ZuliaNodeProvider.getZuliaNode().getIndexManager();
String id = metadata.get("id").toString();
String fileName = metadata.get("fileName").toString();
String indexName = metadata.get("indexName").toString();
if (id != null && fileName != null && indexName != null) {
Document metaDoc;
if (metadata.containsKey("metaJson")) {
metaDoc = Document.parse(metadata.get("metaJson").toString());
} else {
metaDoc = new Document();
}
OutputStream associatedDocumentOutputStream;
try {
associatedDocumentOutputStream = indexManager.getAssociatedDocumentOutputStream(indexName, id, fileName, metaDoc);
Publisher<Boolean> uploadPublisher = transferToStream(ioExecutor, file, associatedDocumentOutputStream);
return Flux.from(uploadPublisher).map(success -> {
if (success) {
try {
associatedDocumentOutputStream.close();
} catch (IOException e) {
LOG.log(Level.SEVERE, "Failed to close stream: " + e.getMessage(), e);
}
return HttpResponse.ok("Stored associated document with uniqueId <" + id + "> and fileName <" + fileName + ">").status(ZuliaConstants.SUCCESS);
} else {
try {
associatedDocumentOutputStream.close();
} catch (IOException e) {
LOG.log(Level.SEVERE, "Failed to close stream: " + e.getMessage(), e);
}
return HttpResponse.serverError("Failed to store associated document with uniqueId <" + id + "> and filename <" + fileName + ">");
}
});
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage(), e);
return Mono.just(HttpResponse.serverError("Failed to store <" + id + "> in index <" + indexName + "> for file <" + fileName + ">"));
}
} else {
return Mono.just(HttpResponse.serverError(ZuliaConstants.ID + " and " + ZuliaConstants.FILE_NAME + " are required"));
}
}
use of io.zulia.server.index.ZuliaIndexManager in project zuliasearch by zuliaio.
the class AssociatedController method getAll.
@Get("/all")
@Produces(MediaType.APPLICATION_JSON)
public HttpResponse<?> getAll(@QueryValue(ZuliaConstants.INDEX) final String indexName, @Nullable @QueryValue(ZuliaConstants.QUERY) String query) {
ZuliaIndexManager indexManager = ZuliaNodeProvider.getZuliaNode().getIndexManager();
Writable writable = out -> {
Document filter;
if (query != null) {
filter = Document.parse(query);
} else {
filter = new Document();
}
try {
indexManager.getAssociatedFilenames(indexName, out, filter);
} catch (Exception e) {
LOG.log(Level.SEVERE, e.getMessage(), e);
HttpResponse.serverError(e.getMessage());
}
};
return HttpResponse.ok(writable).status(ZuliaConstants.SUCCESS);
}
use of io.zulia.server.index.ZuliaIndexManager in project zuliasearch by zuliaio.
the class IndexesController method get.
@Get
@Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public HttpResponse<?> get() {
ZuliaIndexManager indexManager = ZuliaNodeProvider.getZuliaNode().getIndexManager();
try {
GetIndexesResponse getIndexesResponse = indexManager.getIndexes(GetIndexesRequest.newBuilder().build());
Document mongoDocument = new org.bson.Document();
ProtocolStringList indexNameList = getIndexesResponse.getIndexNameList();
List<String> sorted = new ArrayList<>(indexNameList);
Collections.sort(sorted);
mongoDocument.put("indexes", sorted);
String docString = mongoDocument.toJson();
docString = JsonWriter.formatJson(docString);
return HttpResponse.ok(docString).status(ZuliaConstants.SUCCESS);
} catch (Exception e) {
return HttpResponse.serverError("Failed to get index names: " + e.getMessage()).status(ZuliaConstants.INTERNAL_ERROR);
}
}
Aggregations