Search in sources :

Example 1 with NodeGroupTupleTranslator

use of org.apache.asterix.metadata.entitytupletranslators.NodeGroupTupleTranslator in project asterixdb by apache.

the class MetadataNode method getNodeGroup.

@Override
public NodeGroup getNodeGroup(JobId jobId, String nodeGroupName) throws MetadataException, RemoteException {
    try {
        ITupleReference searchKey = createTuple(nodeGroupName);
        NodeGroupTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getNodeGroupTupleTranslator(false);
        IValueExtractor<NodeGroup> valueExtractor = new MetadataEntityValueExtractor<>(tupleReaderWriter);
        List<NodeGroup> results = new ArrayList<>();
        searchIndex(jobId, MetadataPrimaryIndexes.NODEGROUP_DATASET, searchKey, valueExtractor, results);
        if (results.isEmpty()) {
            return null;
        }
        return results.get(0);
    } catch (HyracksDataException e) {
        throw new MetadataException(e);
    }
}
Also used : MetadataEntityValueExtractor(org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor) NodeGroupTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.NodeGroupTupleTranslator) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ArrayList(java.util.ArrayList) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) NodeGroup(org.apache.asterix.metadata.entities.NodeGroup)

Example 2 with NodeGroupTupleTranslator

use of org.apache.asterix.metadata.entitytupletranslators.NodeGroupTupleTranslator in project asterixdb by apache.

the class MetadataNode method addNodeGroup.

@Override
public void addNodeGroup(JobId jobId, NodeGroup nodeGroup) throws MetadataException, RemoteException {
    try {
        NodeGroupTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getNodeGroupTupleTranslator(true);
        ITupleReference tuple = tupleReaderWriter.getTupleFromMetadataEntity(nodeGroup);
        insertTupleIntoIndex(jobId, MetadataPrimaryIndexes.NODEGROUP_DATASET, tuple);
    } catch (HyracksDataException e) {
        if (e.getComponent().equals(ErrorCode.HYRACKS) && e.getErrorCode() == ErrorCode.DUPLICATE_KEY) {
            throw new MetadataException("A nodegroup with name '" + nodeGroup.getNodeGroupName() + "' already exists.", e);
        } else {
            throw new MetadataException(e);
        }
    } catch (ACIDException e) {
        throw new MetadataException(e);
    }
}
Also used : NodeGroupTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.NodeGroupTupleTranslator) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Aggregations

NodeGroupTupleTranslator (org.apache.asterix.metadata.entitytupletranslators.NodeGroupTupleTranslator)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)2 ArrayList (java.util.ArrayList)1 ACIDException (org.apache.asterix.common.exceptions.ACIDException)1 NodeGroup (org.apache.asterix.metadata.entities.NodeGroup)1 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)1