Search in sources :

Example 1 with CompactionPolicyTupleTranslator

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

the class MetadataNode method getCompactionPolicy.

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

Example 2 with CompactionPolicyTupleTranslator

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

the class MetadataNode method addCompactionPolicy.

@Override
public void addCompactionPolicy(JobId jobId, CompactionPolicy compactionPolicy) throws MetadataException, RemoteException {
    try {
        // Insert into the 'CompactionPolicy' dataset.
        CompactionPolicyTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getCompactionPolicyTupleTranslator(true);
        ITupleReference compactionPolicyTuple = tupleReaderWriter.getTupleFromMetadataEntity(compactionPolicy);
        insertTupleIntoIndex(jobId, MetadataPrimaryIndexes.COMPACTION_POLICY_DATASET, compactionPolicyTuple);
    } catch (HyracksDataException e) {
        if (e.getComponent().equals(ErrorCode.HYRACKS) && e.getErrorCode() == ErrorCode.DUPLICATE_KEY) {
            throw new MetadataException("A compcation policy with this name " + compactionPolicy.getPolicyName() + " already exists in dataverse '" + compactionPolicy.getPolicyName() + "'.", e);
        } else {
            throw new MetadataException(e);
        }
    } catch (ACIDException e) {
        throw new MetadataException(e);
    }
}
Also used : CompactionPolicyTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.CompactionPolicyTupleTranslator) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Aggregations

CompactionPolicyTupleTranslator (org.apache.asterix.metadata.entitytupletranslators.CompactionPolicyTupleTranslator)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 CompactionPolicy (org.apache.asterix.metadata.entities.CompactionPolicy)1 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)1