use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class MyCoreAPI method makeNode.
public long makeNode(String label) throws ProcedureException {
long result;
try (Transaction tx = graph.beginTransaction(KernelTransaction.Type.explicit, AnonymousContext.write())) {
Statement statement = this.txBridge.get();
long nodeId = statement.dataWriteOperations().nodeCreate();
int labelId = statement.tokenWriteOperations().labelGetOrCreateForName(label);
statement.dataWriteOperations().nodeAddLabel(nodeId, labelId);
result = nodeId;
tx.success();
} catch (Exception e) {
log.error("Failed to create node: " + e.getMessage());
throw new ProcedureException(Status.Procedure.ProcedureCallFailed, "Failed to create node: " + e.getMessage(), e);
}
return result;
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ClusterOverviewProcedure method apply.
@Override
public RawIterator<Object[], ProcedureException> apply(Context ctx, Object[] input) throws ProcedureException {
List<ReadWriteEndPoint> endpoints = new ArrayList<>();
CoreTopology coreTopology = topologyService.coreServers();
Set<MemberId> coreMembers = coreTopology.members().keySet();
MemberId leader = null;
try {
leader = leaderLocator.getLeader();
} catch (NoLeaderFoundException e) {
log.debug("No write server found. This can happen during a leader switch.");
}
for (MemberId memberId : coreMembers) {
Optional<CoreServerInfo> coreServerInfo = coreTopology.find(memberId);
if (coreServerInfo.isPresent()) {
Role role = memberId.equals(leader) ? Role.LEADER : Role.FOLLOWER;
endpoints.add(new ReadWriteEndPoint(coreServerInfo.get().connectors(), role, memberId.getUuid(), asList(coreServerInfo.get().groups())));
} else {
log.debug("No Address found for " + memberId);
}
}
for (Map.Entry<MemberId, ReadReplicaInfo> readReplica : topologyService.readReplicas().members().entrySet()) {
ReadReplicaInfo readReplicaInfo = readReplica.getValue();
endpoints.add(new ReadWriteEndPoint(readReplicaInfo.connectors(), Role.READ_REPLICA, readReplica.getKey().getUuid(), asList(readReplicaInfo.groups())));
}
endpoints.sort(comparing(o -> o.addresses().toString()));
return map((endpoint) -> new Object[] { endpoint.memberId().toString(), endpoint.addresses().uriList().stream().map(URI::toString).toArray(), endpoint.role().name(), endpoint.groups() }, asRawIterator(endpoints.iterator()));
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class ClusterOverviewIT method clusterOverview.
private List<MemberInfo> clusterOverview(GraphDatabaseFacade db) throws TransactionFailureException, ProcedureException {
KernelAPI kernel = db.getDependencyResolver().resolveDependency(KernelAPI.class);
KernelTransaction transaction = kernel.newTransaction(Type.implicit, AnonymousContext.read());
List<MemberInfo> infos = new ArrayList<>();
try (Statement statement = transaction.acquireStatement()) {
RawIterator<Object[], ProcedureException> itr = statement.procedureCallOperations().procedureCallRead(procedureName("dbms", "cluster", ClusterOverviewProcedure.PROCEDURE_NAME), null);
while (itr.hasNext()) {
Object[] row = itr.next();
Object[] addresses = (Object[]) row[1];
infos.add(new MemberInfo(Arrays.copyOf(addresses, addresses.length, String[].class), Role.valueOf((String) row[2])));
}
}
return infos;
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class BuiltInProcedures method listIndexes.
@Description("List all indexes in the database.")
@Procedure(name = "db.indexes", mode = READ)
public Stream<IndexResult> listIndexes() throws ProcedureException {
try (Statement statement = tx.acquireStatement()) {
ReadOperations operations = statement.readOperations();
TokenNameLookup tokens = new StatementTokenNameLookup(operations);
List<NewIndexDescriptor> indexes = asList(operations.indexesGetAll());
Set<NewIndexDescriptor> uniqueIndexes = asSet(operations.uniqueIndexesGetAll());
indexes.addAll(uniqueIndexes);
indexes.sort(Comparator.comparing(a -> a.userDescription(tokens)));
ArrayList<IndexResult> result = new ArrayList<>();
for (NewIndexDescriptor index : indexes) {
try {
String type;
if (uniqueIndexes.contains(index)) {
type = IndexType.NODE_UNIQUE_PROPERTY.typeName();
} else {
type = IndexType.NODE_LABEL_PROPERTY.typeName();
}
result.add(new IndexResult("INDEX ON " + index.schema().userDescription(tokens), operations.indexGetState(index).toString(), type));
} catch (IndexNotFoundKernelException e) {
throw new ProcedureException(Status.Schema.IndexNotFound, e, "No index on ", index.userDescription(tokens));
}
}
return result.stream();
}
}
use of org.neo4j.kernel.api.exceptions.ProcedureException in project neo4j by neo4j.
the class IndexProcedures method resampleIndex.
public void resampleIndex(String indexSpecification) throws ProcedureException {
IndexSpecifier index = parse(indexSpecification);
int labelId = getLabelId(index.label());
int propertyKeyId = getPropertyKeyId(index.property());
//TODO: Support composite indexes
try {
triggerSampling(getIndex(labelId, propertyKeyId, index));
} catch (IndexNotFoundKernelException e) {
throw new ProcedureException(e.status(), e.getMessage(), e);
}
}
Aggregations